Browse Source

Merge NRefactory '180a690f373354796520d9468138d95f193f8156' to ILSpy.

pull/348/head
Daniel Grunwald 14 years ago
parent
commit
4279979fd2
  1. 3
      NRefactory/ICSharpCode.NRefactory.CSharp.AstVerifier/.gitignore
  2. 27
      NRefactory/ICSharpCode.NRefactory.CSharp.AstVerifier/AssemblyInfo.cs
  3. 49
      NRefactory/ICSharpCode.NRefactory.CSharp.AstVerifier/ICSharpCode.NRefactory.CSharp.AstVerifier.csproj
  4. 83
      NRefactory/ICSharpCode.NRefactory.CSharp.AstVerifier/Main.cs
  5. 7
      NRefactory/ICSharpCode.NRefactory.CSharp/Analysis/ControlFlow.cs
  6. 73
      NRefactory/ICSharpCode.NRefactory.CSharp/Analysis/DefiniteAssignmentAnalysis.cs
  7. 386
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs
  8. 45
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/AstType.cs
  9. 20
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs
  10. 56
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/CSharpTokenNode.cs
  11. 4
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/CSharpUtil.cs
  12. 84
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs
  13. 34
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/ComposedType.cs
  14. 1215
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/DepthFirstAstVisitor.cs
  15. 149
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/DocumentationReference.cs
  16. 11
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/ErrorNode.cs
  17. 29
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AnonymousMethodExpression.cs
  18. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AnonymousTypeCreateExpression.cs
  19. 17
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayCreateExpression.cs
  20. 23
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayInitializerExpression.cs
  21. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AsExpression.cs
  22. 51
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AssignmentExpression.cs
  23. 12
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/BaseReferenceExpression.cs
  24. 77
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/BinaryOperatorExpression.cs
  25. 12
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/CastExpression.cs
  26. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/CheckedExpression.cs
  27. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ConditionalExpression.cs
  28. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/DefaultValueExpression.cs
  29. 17
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/DirectionExpression.cs
  30. 15
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/EmptyExpression.cs
  31. 14
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ErrorExpression.cs
  32. 23
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/Expression.cs
  33. 14
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/IdentifierExpression.cs
  34. 12
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/IndexerExpression.cs
  35. 12
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/InvocationExpression.cs
  36. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/IsExpression.cs
  37. 23
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/LambdaExpression.cs
  38. 14
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/MemberReferenceExpression.cs
  39. 14
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/NamedArgumentExpression.cs
  40. 14
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/NamedExpression.cs
  41. 12
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/NullReferenceExpression.cs
  42. 15
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ObjectCreateExpression.cs
  43. 14
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ParenthesizedExpression.cs
  44. 20
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/PointerReferenceExpression.cs
  45. 35
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/PrimitiveExpression.cs
  46. 183
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/QueryExpression.cs
  47. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/SizeOfExpression.cs
  48. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/StackAllocExpression.cs
  49. 14
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ThisReferenceExpression.cs
  50. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/TypeOfExpression.cs
  51. 12
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/TypeReferenceExpression.cs
  52. 44
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/UnaryOperatorExpression.cs
  53. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/UncheckedExpression.cs
  54. 32
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/UndocumentedExpression.cs
  55. 17
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Attribute.cs
  56. 31
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/AttributeSection.cs
  57. 43
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Comment.cs
  58. 23
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Constraint.cs
  59. 50
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/DelegateDeclaration.cs
  60. 20
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/ExternAliasDeclaration.cs
  61. 18
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NamespaceDeclaration.cs
  62. 132
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NewLineNode.cs
  63. 17
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/PreProcessorDirective.cs
  64. 94
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TextNode.cs
  65. 70
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TypeDeclaration.cs
  66. 46
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs
  67. 21
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs
  68. 15
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/UsingDeclaration.cs
  69. 91
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/WhitespaceNode.cs
  70. 266
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/IAstVisitor.cs
  71. 78
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Identifier.cs
  72. 2
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/IdentifierExpressionBackreference.cs
  73. 24
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/MemberType.cs
  74. 43
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/ObservableAstVisitor.cs
  75. 38
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/PrimitiveType.cs
  76. 96
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Roles.cs
  77. 25
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/SimpleType.cs
  78. 35
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/BlockStatement.cs
  79. 18
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/BreakStatement.cs
  80. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/CheckedStatement.cs
  81. 18
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/ContinueStatement.cs
  82. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/DoWhileStatement.cs
  83. 15
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/EmptyStatement.cs
  84. 12
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/ExpressionStatement.cs
  85. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/FixedStatement.cs
  86. 15
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/ForStatement.cs
  87. 21
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/ForeachStatement.cs
  88. 52
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/GotoStatement.cs
  89. 17
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/IfElseStatement.cs
  90. 19
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/LabelStatement.cs
  91. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/LockStatement.cs
  92. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/ReturnStatement.cs
  93. 23
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/Statement.cs
  94. 60
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/SwitchStatement.cs
  95. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/ThrowStatement.cs
  96. 46
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/TryCatchStatement.cs
  97. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/UncheckedStatement.cs
  98. 16
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/UnsafeStatement.cs
  99. 15
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/UsingStatement.cs
  100. 20
      NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/VariableDeclarationStatement.cs
  101. Some files were not shown because too many files have changed in this diff Show More

3
NRefactory/ICSharpCode.NRefactory.CSharp.AstVerifier/.gitignore vendored

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
bin/
obj/

27
NRefactory/ICSharpCode.NRefactory.CSharp.AstVerifier/AssemblyInfo.cs

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("ICSharpCode.NRefactory.CSharp.AstVerifier")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("mike")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

49
NRefactory/ICSharpCode.NRefactory.CSharp.AstVerifier/ICSharpCode.NRefactory.CSharp.AstVerifier.csproj

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{961DADFA-7CE6-429F-BC22-47630D6DB826}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ICSharpCode.NRefactory.CSharp.AstVerifier</RootNamespace>
<AssemblyName>AstVerifier</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
<Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project>
<Name>ICSharpCode.NRefactory.CSharp</Name>
</ProjectReference>
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
</ItemGroup>
</Project>

83
NRefactory/ICSharpCode.NRefactory.CSharp.AstVerifier/Main.cs

@ -0,0 +1,83 @@ @@ -0,0 +1,83 @@
using System;
using System.IO;
namespace ICSharpCode.NRefactory.CSharp.AstVerifier
{
class MainClass
{
static bool IsMatch (string src1, string src2, out int i, out int j)
{
i = 0;
j = 0;
while (i < src1.Length && j < src2.Length) {
char c1 = src1 [i];
char c2 = src2 [j];
if (char.IsWhiteSpace (c1)) {
i++;
continue;
}
if (char.IsWhiteSpace (c2)) {
j++;
continue;
}
if (c1 != c2)
return false;
i++;
j++;
}
while (i < src1.Length && char.IsWhiteSpace (src1[i])) {
i++;
}
while (j < src2.Length && char.IsWhiteSpace (src2[j])) {
j++;
}
return i == src1.Length && j == src2.Length;
}
public static void Main (string[] args)
{
if (args.Length == 0) {
Console.WriteLine ("Usage: AstVerifier [-v|-verbose] [Directory]");
return;
}
string directory = args[args.Length - 1];
bool verboseOutput = args.Length > 1 && (args[0] == "-v" || args[0] == "-verbose");
try {
if (!Directory.Exists (directory)) {
Console.WriteLine ("Directory not found.");
return;
}
} catch (IOException) {
Console.WriteLine ("Exception while trying to access the directory.");
return;
}
int failed = 0, passed = 0;
Console.WriteLine ("search in " + directory);
foreach (var file in Directory.GetFileSystemEntries (directory, "*", SearchOption.AllDirectories)) {
if (!file.EndsWith (".cs"))
continue;
string text = File.ReadAllText (file);
var unit = CompilationUnit.Parse (text, file);
if (unit == null)
continue;
string generated = unit.GetText ();
int i, j;
if (!IsMatch (text, generated, out i, out j)) {
if (i > 0 && j > 0 && verboseOutput) {
Console.WriteLine ("fail :" + file + "----original:");
Console.WriteLine (text.Substring (0, Math.Min (text.Length, i + 1)));
Console.WriteLine ("----generated:");
Console.WriteLine (generated.Substring (0, Math.Min (generated.Length, j + 1)));
}
failed++;
} else {
passed++;
}
}
Console.WriteLine ("{0} passed, {1} failed", passed, failed);
}
}
}

7
NRefactory/ICSharpCode.NRefactory.CSharp/Analysis/ControlFlow.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
/// Gets the try-finally statements that this control flow edge is leaving.
/// </summary>
public IEnumerable<TryCatchStatement> TryFinallyStatements {
get { return jumpOutOfTryFinally ?? EmptyList<TryCatchStatement>.Instance; }
get { return jumpOutOfTryFinally ?? Enumerable.Empty<TryCatchStatement>(); }
}
}
@ -420,7 +420,8 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -420,7 +420,8 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
falseEnd = ifElseStatement.FalseStatement.AcceptVisitor(this, falseBegin);
}
ControlFlowNode end = builder.CreateEndNode(ifElseStatement);
Connect(trueEnd, end);
if (trueEnd != null)
Connect(trueEnd, end);
if (falseEnd != null) {
Connect(falseEnd, end);
} else if (cond != true) {

73
NRefactory/ICSharpCode.NRefactory.CSharp/Analysis/DefiniteAssignmentAnalysis.cs

@ -304,54 +304,53 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis @@ -304,54 +304,53 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis
return DefiniteAssignmentStatus.PotentiallyAssigned;
}
void ChangeNodeStatus(DefiniteAssignmentNode node, DefiniteAssignmentStatus inputStatus)
void ChangeNodeStatus (DefiniteAssignmentNode node, DefiniteAssignmentStatus inputStatus)
{
if (node.NodeStatus == inputStatus)
return;
node.NodeStatus = inputStatus;
DefiniteAssignmentStatus outputStatus;
switch (node.Type) {
case ControlFlowNodeType.StartNode:
case ControlFlowNodeType.BetweenStatements:
if (node.NextStatement is IfElseStatement) {
// Handle if-else as a condition node
case ControlFlowNodeType.StartNode:
case ControlFlowNodeType.BetweenStatements:
if (node.NextStatement is IfElseStatement) {
// Handle if-else as a condition node
goto case ControlFlowNodeType.LoopCondition;
}
if (inputStatus == DefiniteAssignmentStatus.DefinitelyAssigned) {
// There isn't any way to un-assign variables, so we don't have to check the expression
// if the status already is definitely assigned.
outputStatus = DefiniteAssignmentStatus.DefinitelyAssigned;
} else {
outputStatus = CleanSpecialValues(node.NextStatement.AcceptVisitor(visitor, inputStatus));
}
break;
case ControlFlowNodeType.EndNode:
outputStatus = inputStatus;
if (node.PreviousStatement.Role == TryCatchStatement.FinallyBlockRole
&& (outputStatus == DefiniteAssignmentStatus.DefinitelyAssigned || outputStatus == DefiniteAssignmentStatus.PotentiallyAssigned))
{
TryCatchStatement tryFinally = (TryCatchStatement)node.PreviousStatement.Parent;
// Changing the status on a finally block potentially changes the status of all edges leaving that finally block:
foreach (ControlFlowEdge edge in allNodes.SelectMany(n => n.Outgoing)) {
if (edge.IsLeavingTryFinally && edge.TryFinallyStatements.Contains(tryFinally)) {
DefiniteAssignmentStatus s = edgeStatus[edge];
if (s == DefiniteAssignmentStatus.PotentiallyAssigned) {
ChangeEdgeStatus(edge, outputStatus);
}
}
if (inputStatus == DefiniteAssignmentStatus.DefinitelyAssigned) {
// There isn't any way to un-assign variables, so we don't have to check the expression
// if the status already is definitely assigned.
outputStatus = DefiniteAssignmentStatus.DefinitelyAssigned;
} else {
outputStatus = CleanSpecialValues (node.NextStatement.AcceptVisitor (visitor, inputStatus));
}
break;
case ControlFlowNodeType.EndNode:
outputStatus = inputStatus;
if (node.PreviousStatement.Role == TryCatchStatement.FinallyBlockRole
&& (outputStatus == DefiniteAssignmentStatus.DefinitelyAssigned || outputStatus == DefiniteAssignmentStatus.PotentiallyAssigned)) {
TryCatchStatement tryFinally = (TryCatchStatement)node.PreviousStatement.Parent;
// Changing the status on a finally block potentially changes the status of all edges leaving that finally block:
foreach (ControlFlowEdge edge in allNodes.SelectMany(n => n.Outgoing)) {
if (edge.IsLeavingTryFinally && edge.TryFinallyStatements.Contains (tryFinally)) {
DefiniteAssignmentStatus s = edgeStatus [edge];
if (s == DefiniteAssignmentStatus.PotentiallyAssigned) {
ChangeEdgeStatus (edge, outputStatus);
}
}
}
}
break;
case ControlFlowNodeType.LoopCondition:
ForeachStatement foreachStmt = node.NextStatement as ForeachStatement;
if (foreachStmt != null) {
outputStatus = CleanSpecialValues (foreachStmt.InExpression.AcceptVisitor (visitor, inputStatus));
if (foreachStmt.VariableName == this.variableName)
outputStatus = DefiniteAssignmentStatus.DefinitelyAssigned;
break;
case ControlFlowNodeType.LoopCondition:
ForeachStatement foreachStmt = node.NextStatement as ForeachStatement;
if (foreachStmt != null) {
outputStatus = CleanSpecialValues(foreachStmt.InExpression.AcceptVisitor(visitor, inputStatus));
if (foreachStmt.VariableName == this.variableName)
outputStatus = DefiniteAssignmentStatus.DefinitelyAssigned;
break;
} else {
Debug.Assert(node.NextStatement is IfElseStatement || node.NextStatement is WhileStatement || node.NextStatement is ForStatement || node.NextStatement is DoWhileStatement);
Expression condition = node.NextStatement.GetChildByRole(AstNode.Roles.Condition);
} else {
Debug.Assert (node.NextStatement is IfElseStatement || node.NextStatement is WhileStatement || node.NextStatement is ForStatement || node.NextStatement is DoWhileStatement);
Expression condition = node.NextStatement.GetChildByRole (Roles.Condition);
if (condition.IsNull)
outputStatus = inputStatus;
else

386
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// AstNode.cs
//
// Author:
@ -33,8 +33,11 @@ using System.Threading; @@ -33,8 +33,11 @@ using System.Threading;
namespace ICSharpCode.NRefactory.CSharp
{
public abstract class AstNode : AbstractAnnotatable, PatternMatching.INode
public abstract class AstNode : AbstractAnnotatable, ICSharpCode.NRefactory.TypeSystem.IFreezable, PatternMatching.INode
{
// the Root role must be available when creating the null nodes, so we can't put it in the Roles class
internal static readonly Role<AstNode> RootRole = new Role<AstNode> ("Root");
#region Null
public static readonly AstNode Null = new NullAstNode ();
@ -52,7 +55,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,7 +55,16 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return default (T);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return default (S);
}
@ -83,7 +95,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -83,7 +95,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder (this, child);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder (this, child);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder (this, child, data);
}
@ -105,7 +127,42 @@ namespace ICSharpCode.NRefactory.CSharp @@ -105,7 +127,42 @@ namespace ICSharpCode.NRefactory.CSharp
AstNode nextSibling;
AstNode firstChild;
AstNode lastChild;
Role role = RootRole;
// Flags, from least significant to most significant bits:
// - Role.RoleIndexBits: role index
// - 1 bit: IsFrozen
protected uint flags = RootRole.Index;
// Derived classes may also use a few bits,
// for example Identifier uses 1 bit for IsVerbatim
const uint roleIndexMask = (1u << Role.RoleIndexBits) - 1;
const uint frozenBit = 1u << Role.RoleIndexBits;
protected const int AstNodeFlagsUsedBits = Role.RoleIndexBits + 1;
protected AstNode()
{
if (IsNull)
Freeze();
}
public bool IsFrozen {
get { return (flags & frozenBit) != 0; }
}
public void Freeze()
{
if (!IsFrozen) {
for (AstNode child = firstChild; child != null; child = child.nextSibling)
child.Freeze();
flags |= frozenBit;
}
}
protected void ThrowIfFrozen()
{
if (IsFrozen)
throw new InvalidOperationException("Cannot mutate frozen " + GetType().Name);
}
public abstract NodeType NodeType {
get;
@ -135,22 +192,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -135,22 +192,6 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
/// <summary>
/// Returns true, if the given coordinates are in the node.
/// </summary>
public bool IsInside (TextLocation location)
{
return StartLocation <= location && location <= EndLocation;
}
/// <summary>
/// Returns true, if the given coordinates (line, column) are in the node.
/// </summary>
public bool IsInside(int line, int column)
{
return IsInside(new TextLocation (line, column));
}
/// <summary>
/// Gets the region from StartLocation to EndLocation for this node.
/// The file name of the region is set based on the parent CompilationUnit's file name.
@ -168,7 +209,22 @@ namespace ICSharpCode.NRefactory.CSharp @@ -168,7 +209,22 @@ namespace ICSharpCode.NRefactory.CSharp
}
public Role Role {
get { return role; }
get {
return Role.GetByIndex(flags & roleIndexMask);
}
set {
if (value == null)
throw new ArgumentNullException("value");
if (!value.IsValid(this))
throw new ArgumentException("This node is not valid in the new role.");
ThrowIfFrozen();
SetRole(value);
}
}
void SetRole(Role role)
{
flags = (flags & ~roleIndexMask) | role.Index;
}
public AstNode NextSibling {
@ -187,6 +243,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -187,6 +243,12 @@ namespace ICSharpCode.NRefactory.CSharp
get { return lastChild; }
}
public bool HasChildren {
get {
return firstChild != null;
}
}
public IEnumerable<AstNode> Children {
get {
AstNode next;
@ -211,6 +273,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -211,6 +273,17 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
/// <summary>
/// Gets the ancestors of this node (including this node itself)
/// </summary>
public IEnumerable<AstNode> AncestorsAndSelf {
get {
for (AstNode cur = this; cur != null; cur = cur.parent) {
yield return cur;
}
}
}
/// <summary>
/// Gets all descendants of this node (excluding this node itself).
/// </summary>
@ -233,17 +306,23 @@ namespace ICSharpCode.NRefactory.CSharp @@ -233,17 +306,23 @@ namespace ICSharpCode.NRefactory.CSharp
/// Gets the first child with the specified role.
/// Returns the role's null object if the child is not found.
/// </summary>
public T GetChildByRole<T> (Role<T> role) where T : AstNode
public T GetChildByRole<T>(Role<T> role) where T : AstNode
{
if (role == null)
throw new ArgumentNullException ("role");
uint roleIndex = role.Index;
for (var cur = firstChild; cur != null; cur = cur.nextSibling) {
if (cur.role == role)
if ((cur.flags & roleIndexMask) == roleIndex)
return (T)cur;
}
return role.NullObject;
}
public T GetParent<T>() where T : AstNode
{
return Ancestors.OfType<T>().FirstOrDefault();
}
public AstNodeCollection<T> GetChildrenByRole<T> (Role<T> role) where T : AstNode
{
return new AstNodeCollection<T> (this, role);
@ -264,10 +343,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -264,10 +343,11 @@ namespace ICSharpCode.NRefactory.CSharp
throw new ArgumentNullException ("role");
if (child == null || child.IsNull)
return;
if (this.IsNull)
throw new InvalidOperationException ("Cannot add children to null nodes");
ThrowIfFrozen();
if (child.parent != null)
throw new ArgumentException ("Node is already used in another tree.", "child");
if (child.IsFrozen)
throw new ArgumentException ("Cannot add a frozen node.", "child");
AddChildUnsafe (child, role);
}
@ -277,7 +357,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -277,7 +357,7 @@ namespace ICSharpCode.NRefactory.CSharp
void AddChildUnsafe (AstNode child, Role role)
{
child.parent = this;
child.role = role;
child.SetRole(role);
if (firstChild == null) {
lastChild = firstChild = child;
} else {
@ -286,6 +366,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -286,6 +366,13 @@ namespace ICSharpCode.NRefactory.CSharp
lastChild = child;
}
}
public void InsertChildsBefore<T>(AstNode nextSibling, Role<T> role, params T[] child) where T : AstNode
{
foreach (var cur in child) {
InsertChildBefore(nextSibling, cur, role);
}
}
public void InsertChildBefore<T> (AstNode nextSibling, T child, Role<T> role) where T : AstNode
{
@ -298,8 +385,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -298,8 +385,11 @@ namespace ICSharpCode.NRefactory.CSharp
if (child == null || child.IsNull)
return;
ThrowIfFrozen();
if (child.parent != null)
throw new ArgumentException ("Node is already used in another tree.", "child");
if (child.IsFrozen)
throw new ArgumentException ("Cannot add a frozen node.", "child");
if (nextSibling.parent != this)
throw new ArgumentException ("NextSibling is not a child of this node.", "nextSibling");
// No need to test for "Cannot add children to null nodes",
@ -310,7 +400,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -310,7 +400,7 @@ namespace ICSharpCode.NRefactory.CSharp
void InsertChildBeforeUnsafe (AstNode nextSibling, AstNode child, Role role)
{
child.parent = this;
child.role = role;
child.SetRole(role);
child.nextSibling = nextSibling;
child.prevSibling = nextSibling.prevSibling;
@ -335,6 +425,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -335,6 +425,7 @@ namespace ICSharpCode.NRefactory.CSharp
public void Remove ()
{
if (parent != null) {
ThrowIfFrozen();
if (prevSibling != null) {
Debug.Assert (prevSibling.nextSibling == this);
prevSibling.nextSibling = nextSibling;
@ -350,7 +441,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -350,7 +441,6 @@ namespace ICSharpCode.NRefactory.CSharp
parent.lastChild = prevSibling;
}
parent = null;
role = Roles.Root;
prevSibling = null;
nextSibling = null;
}
@ -370,10 +460,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -370,10 +460,11 @@ namespace ICSharpCode.NRefactory.CSharp
if (parent == null) {
throw new InvalidOperationException (this.IsNull ? "Cannot replace the null nodes" : "Cannot replace the root node");
}
ThrowIfFrozen();
// Because this method doesn't statically check the new node's type with the role,
// we perform a runtime test:
if (!role.IsValid (newNode)) {
throw new ArgumentException (string.Format ("The new node '{0}' is not valid in the role {1}", newNode.GetType ().Name, role.ToString ()), "newNode");
if (!this.Role.IsValid (newNode)) {
throw new ArgumentException (string.Format ("The new node '{0}' is not valid in the role {1}", newNode.GetType ().Name, this.Role.ToString ()), "newNode");
}
if (newNode.parent != null) {
// newNode is used within this tree?
@ -385,9 +476,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -385,9 +476,11 @@ namespace ICSharpCode.NRefactory.CSharp
throw new ArgumentException ("Node is already used in another tree.", "newNode");
}
}
if (newNode.IsFrozen)
throw new ArgumentException ("Cannot add a frozen node.", "newNode");
newNode.parent = parent;
newNode.role = role;
newNode.SetRole(this.Role);
newNode.prevSibling = prevSibling;
newNode.nextSibling = nextSibling;
if (parent != null) {
@ -408,7 +501,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -408,7 +501,6 @@ namespace ICSharpCode.NRefactory.CSharp
parent = null;
prevSibling = null;
nextSibling = null;
role = Roles.Root;
}
}
@ -421,7 +513,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -421,7 +513,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
AstNode oldParent = parent;
AstNode oldSuccessor = nextSibling;
Role oldRole = role;
Role oldRole = this.Role;
Remove ();
AstNode replacement = replaceFunction (this);
if (oldSuccessor != null && oldSuccessor.parent != oldParent)
@ -450,26 +542,28 @@ namespace ICSharpCode.NRefactory.CSharp @@ -450,26 +542,28 @@ namespace ICSharpCode.NRefactory.CSharp
AstNode copy = (AstNode)MemberwiseClone ();
// First, reset the shallow pointer copies
copy.parent = null;
copy.role = Roles.Root;
copy.firstChild = null;
copy.lastChild = null;
copy.prevSibling = null;
copy.nextSibling = null;
copy.flags &= ~frozenBit; // unfreeze the copy
// Then perform a deep copy:
for (AstNode cur = firstChild; cur != null; cur = cur.nextSibling) {
copy.AddChildUnsafe (cur.Clone (), cur.role);
copy.AddChildUnsafe (cur.Clone (), cur.Role);
}
// Finally, clone the annotation, if necessary
ICloneable copiedAnnotations = copy.annotations as ICloneable; // read from copy (for thread-safety)
if (copiedAnnotations != null)
copy.annotations = copiedAnnotations.Clone();
copy.CloneAnnotations();
return copy;
}
public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T));
public abstract void AcceptVisitor (IAstVisitor visitor);
public abstract T AcceptVisitor<T> (IAstVisitor<T> visitor);
public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data);
#region Pattern Matching
protected static bool MatchString (string pattern, string text)
@ -519,7 +613,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -519,7 +613,6 @@ namespace ICSharpCode.NRefactory.CSharp
return Parent.GetPrevNode ();
return null;
}
// filters all non c# nodes (comments, white spaces or pre processor directives)
public AstNode GetCSharpNodeBefore (AstNode node)
{
@ -532,11 +625,22 @@ namespace ICSharpCode.NRefactory.CSharp @@ -532,11 +625,22 @@ namespace ICSharpCode.NRefactory.CSharp
return null;
}
#region GetNodeAt
/// <summary>
/// Gets the node specified by T at the location line, column. This is useful for getting a specific node from the tree. For example searching
/// the current method declaration.
/// (End exclusive)
/// </summary>
public AstNode GetNodeAt (int line, int column, Predicate<AstNode> pred = null)
{
return GetNodeAt (new TextLocation (line, column), pred);
}
/// <summary>
/// Gets the node specified by pred at location. This is useful for getting a specific node from the tree. For example searching
/// the current method declaration.
/// (End exclusive)
/// </summary>
public AstNode GetNodeAt (TextLocation location, Predicate<AstNode> pred = null)
{
AstNode result = null;
@ -559,6 +663,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -559,6 +663,11 @@ namespace ICSharpCode.NRefactory.CSharp
return result;
}
/// <summary>
/// Gets the node specified by T at the location line, column. This is useful for getting a specific node from the tree. For example searching
/// the current method declaration.
/// (End exclusive)
/// </summary>
public T GetNodeAt<T> (int line, int column) where T : AstNode
{
return GetNodeAt<T> (new TextLocation (line, column));
@ -567,6 +676,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -567,6 +676,7 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>
/// Gets the node specified by T at location. This is useful for getting a specific node from the tree. For example searching
/// the current method declaration.
/// (End exclusive)
/// </summary>
public T GetNodeAt<T> (TextLocation location) where T : AstNode
{
@ -589,6 +699,97 @@ namespace ICSharpCode.NRefactory.CSharp @@ -589,6 +699,97 @@ namespace ICSharpCode.NRefactory.CSharp
}
return result;
}
#endregion
#region GetAdjacentNodeAt
/// <summary>
/// Gets the node specified by pred at the location line, column. This is useful for getting a specific node from the tree. For example searching
/// the current method declaration.
/// (End inclusive)
/// </summary>
public AstNode GetAdjacentNodeAt(int line, int column, Predicate<AstNode> pred = null)
{
return GetAdjacentNodeAt (new TextLocation (line, column), pred);
}
/// <summary>
/// Gets the node specified by pred at location. This is useful for getting a specific node from the tree. For example searching
/// the current method declaration.
/// (End inclusive)
/// </summary>
public AstNode GetAdjacentNodeAt (TextLocation location, Predicate<AstNode> pred = null)
{
AstNode result = null;
AstNode node = this;
while (node.FirstChild != null) {
var child = node.FirstChild;
while (child != null) {
if (child.StartLocation <= location && location <= child.EndLocation) {
if (pred == null || pred (child))
result = child;
node = child;
break;
}
child = child.NextSibling;
}
// found no better child node - therefore the parent is the right one.
if (child == null)
break;
}
return result;
}
/// <summary>
/// Gets the node specified by T at the location line, column. This is useful for getting a specific node from the tree. For example searching
/// the current method declaration.
/// (End inclusive)
/// </summary>
public T GetAdjacentNodeAt<T>(int line, int column) where T : AstNode
{
return GetAdjacentNodeAt<T> (new TextLocation (line, column));
}
/// <summary>
/// Gets the node specified by T at location. This is useful for getting a specific node from the tree. For example searching
/// the current method declaration.
/// (End inclusive)
/// </summary>
public T GetAdjacentNodeAt<T> (TextLocation location) where T : AstNode
{
T result = null;
AstNode node = this;
while (node.FirstChild != null) {
var child = node.FirstChild;
while (child != null) {
if (child.StartLocation <= location && location < child.EndLocation) {
if (child is T)
result = (T)child;
node = child;
break;
}
child = child.NextSibling;
}
// found no better child node - therefore the parent is the right one.
if (child == null)
break;
}
return result;
}
#endregion
/// <summary>
/// Gets the node that fully contains the range from startLocation to endLocation.
/// </summary>
public AstNode GetNodeContaining(TextLocation startLocation, TextLocation endLocation)
{
for (AstNode child = firstChild; child != null; child = child.nextSibling) {
if (child.StartLocation <= startLocation && endLocation <= child.EndLocation)
return child.GetNodeContaining(startLocation, endLocation);
}
return this;
}
public IEnumerable<AstNode> GetNodesBetween (int startLine, int startColumn, int endLine, int endColumn)
{
@ -619,16 +820,65 @@ namespace ICSharpCode.NRefactory.CSharp @@ -619,16 +820,65 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
/// <summary>
/// Gets the node as formatted C# output.
/// </summary>
/// <param name='formattingOptions'>
/// Formatting options.
/// </param>
public virtual string GetText (CSharpFormattingOptions formattingOptions = null)
{
if (IsNull)
return "";
var w = new StringWriter ();
AcceptVisitor (new CSharpOutputVisitor (w, formattingOptions ?? FormattingOptionsFactory.CreateMono ()));
return w.ToString ();
}
/// <summary>
/// Returns true, if the given coordinates (line, column) are in the node.
/// </summary>
/// <returns>
/// True, if the given coordinates are between StartLocation and EndLocation (exclusive); otherwise, false.
/// </returns>
public bool Contains (int line, int column)
{
return Contains (new TextLocation (line, column));
}
/// <summary>
/// Returns true, if the given coordinates are in the node.
/// </summary>
/// <returns>
/// True, if location is between StartLocation and EndLocation (exclusive); otherwise, false.
/// </returns>
public bool Contains (TextLocation location)
{
return this.StartLocation <= location && location < this.EndLocation;
}
/// <summary>
/// Returns true, if the given coordinates (line, column) are in the node.
/// </summary>
/// <returns>
/// True, if the given coordinates are between StartLocation and EndLocation (inclusive); otherwise, false.
/// </returns>
public bool IsInside (int line, int column)
{
return IsInside (new TextLocation (line, column));
}
/// <summary>
/// Returns true, if the given coordinates are in the node.
/// </summary>
/// <returns>
/// True, if location is between StartLocation and EndLocation (inclusive); otherwise, false.
/// </returns>
public bool IsInside (TextLocation location)
{
return this.StartLocation <= location && location <= this.EndLocation;
}
public override void AddAnnotation (object annotation)
{
if (this.IsNull)
@ -640,60 +890,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -640,60 +890,12 @@ namespace ICSharpCode.NRefactory.CSharp
{
if (IsNull)
return "Null";
StringWriter w = new StringWriter();
AcceptVisitor(new CSharpOutputVisitor(w, new CSharpFormattingOptions()), null);
string text = w.ToString().TrimEnd().Replace("\t", "").Replace(w.NewLine, " ");
string text = GetText();
text = text.TrimEnd().Replace("\t", "").Replace(Environment.NewLine, " ");
if (text.Length > 100)
return text.Substring(0, 97) + "...";
else
return text;
}
// the Root role must be available when creating the null nodes, so we can't put it in the Roles class
static readonly Role<AstNode> RootRole = new Role<AstNode> ("Root");
public static class Roles
{
/// <summary>
/// Root of an abstract syntax tree.
/// </summary>
public static readonly Role<AstNode> Root = RootRole;
// some pre defined constants for common roles
public static readonly Role<Identifier> Identifier = new Role<Identifier> ("Identifier", CSharp.Identifier.Null);
public static readonly Role<BlockStatement> Body = new Role<BlockStatement> ("Body", CSharp.BlockStatement.Null);
public static readonly Role<ParameterDeclaration> Parameter = new Role<ParameterDeclaration> ("Parameter");
public static readonly Role<Expression> Argument = new Role<Expression> ("Argument", CSharp.Expression.Null);
public static readonly Role<AstType> Type = new Role<AstType> ("Type", CSharp.AstType.Null);
public static readonly Role<Expression> Expression = new Role<Expression> ("Expression", CSharp.Expression.Null);
public static readonly Role<Expression> TargetExpression = new Role<Expression> ("Target", CSharp.Expression.Null);
public readonly static Role<Expression> Condition = new Role<Expression> ("Condition", CSharp.Expression.Null);
public static readonly Role<TypeParameterDeclaration> TypeParameter = new Role<TypeParameterDeclaration> ("TypeParameter");
public static readonly Role<AstType> TypeArgument = new Role<AstType> ("TypeArgument", CSharp.AstType.Null);
public readonly static Role<Constraint> Constraint = new Role<Constraint> ("Constraint");
public static readonly Role<VariableInitializer> Variable = new Role<VariableInitializer> ("Variable");
public static readonly Role<Statement> EmbeddedStatement = new Role<Statement> ("EmbeddedStatement", CSharp.Statement.Null);
public static readonly Role<CSharpTokenNode> Keyword = new Role<CSharpTokenNode> ("Keyword", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> InKeyword = new Role<CSharpTokenNode> ("InKeyword", CSharpTokenNode.Null);
// some pre defined constants for most used punctuation
public static readonly Role<CSharpTokenNode> LPar = new Role<CSharpTokenNode> ("LPar", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> RPar = new Role<CSharpTokenNode> ("RPar", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> LBracket = new Role<CSharpTokenNode> ("LBracket", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> RBracket = new Role<CSharpTokenNode> ("RBracket", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> LBrace = new Role<CSharpTokenNode> ("LBrace", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> RBrace = new Role<CSharpTokenNode> ("RBrace", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> LChevron = new Role<CSharpTokenNode> ("LChevron", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> RChevron = new Role<CSharpTokenNode> ("RChevron", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> Comma = new Role<CSharpTokenNode> ("Comma", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> Dot = new Role<CSharpTokenNode> ("Dot", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> Semicolon = new Role<CSharpTokenNode> ("Semicolon", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> Assign = new Role<CSharpTokenNode> ("Assign", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> Colon = new Role<CSharpTokenNode> ("Colon", CSharpTokenNode.Null);
public static readonly Role<Comment> Comment = new Role<Comment> ("Comment");
public static readonly Role<PreProcessorDirective> PreProcessorDirective = new Role<PreProcessorDirective> ("PreProcessorDirective");
public static readonly Role<ErrorNode> Error = new Role<ErrorNode> ("Error");
}
}
}

45
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/AstType.cs

@ -39,7 +39,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -39,7 +39,16 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return default (T);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return default (S);
}
@ -75,9 +84,19 @@ namespace ICSharpCode.NRefactory.CSharp @@ -75,9 +84,19 @@ namespace ICSharpCode.NRefactory.CSharp
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder (this, child);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder (this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
return visitor.VisitPatternPlaceholder (this, child, data);
}
public override ITypeReference ToTypeReference(SimpleNameLookupMode lookupMode)
@ -153,6 +172,26 @@ namespace ICSharpCode.NRefactory.CSharp @@ -153,6 +172,26 @@ namespace ICSharpCode.NRefactory.CSharp
return new TypeReferenceExpression { Type = this }.Member(memberName);
}
/// <summary>
/// Builds an expression that can be used to access a static member on this type.
/// </summary>
public MemberType MemberType(string memberName, params AstType[] typeArguments)
{
var memberType = new MemberType(this, memberName);
memberType.TypeArguments.AddRange(typeArguments);
return memberType;
}
/// <summary>
/// Builds an expression that can be used to access a static member on this type.
/// </summary>
public MemberType MemberType(string memberName, IEnumerable<AstType> typeArguments)
{
var memberType = new MemberType(this, memberName);
memberType.TypeArguments.AddRange(typeArguments);
return memberType;
}
/// <summary>
/// Builds an invocation expression using this type as target.
/// </summary>

20
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs

@ -29,19 +29,29 @@ using System.Linq; @@ -29,19 +29,29 @@ using System.Linq;
namespace ICSharpCode.NRefactory.CSharp
{
public class CSharpModifierToken : CSharpTokenNode
{
Modifiers modifier;
public Modifiers Modifier {
get { return modifier; }
set {
this.tokenLength = GetModifierName(value).Length;
this.modifier = value;
set {
ThrowIfFrozen();
this.modifier = value;
}
}
protected override int TokenLength {
get {
return GetModifierName (modifier).Length;
}
}
public override string GetText (CSharpFormattingOptions formattingOptions = null)
{
return GetModifierName (Modifier);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
CSharpModifierToken o = other as CSharpModifierToken;
@ -65,7 +75,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -65,7 +75,7 @@ namespace ICSharpCode.NRefactory.CSharp
get { return allModifiers; }
}
public CSharpModifierToken (TextLocation location, Modifiers modifier) : base (location, 0)
public CSharpModifierToken (TextLocation location, Modifiers modifier) : base (location)
{
this.Modifier = modifier;
}

56
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/CSharpTokenNode.cs

@ -27,7 +27,13 @@ using System; @@ -27,7 +27,13 @@ using System;
namespace ICSharpCode.NRefactory.CSharp
{
public class CSharpTokenNode : AstNode, IRelocatable
/// <summary>
/// Represents a token in C#. Note that the type of the token is defined through the TokenRole.
/// </summary>
/// <remarks>
/// In all non null c# token nodes the Role of a CSharpToken must be a TokenRole.
/// </remarks>
public class CSharpTokenNode : AstNode
{
public static new readonly CSharpTokenNode Null = new NullCSharpTokenNode ();
class NullCSharpTokenNode : CSharpTokenNode
@ -38,11 +44,20 @@ namespace ICSharpCode.NRefactory.CSharp @@ -38,11 +44,20 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public NullCSharpTokenNode () : base (TextLocation.Empty, 0)
public NullCSharpTokenNode () : base (TextLocation.Empty)
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return default (T);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return default (S);
}
@ -53,7 +68,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,7 +68,6 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override NodeType NodeType {
get {
return NodeType.Token;
@ -67,27 +81,43 @@ namespace ICSharpCode.NRefactory.CSharp @@ -67,27 +81,43 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
protected int tokenLength;
protected virtual int TokenLength {
get {
if (!(Role is TokenRole))
return 0;
return ((TokenRole)Role).Length;
}
}
public override TextLocation EndLocation {
get {
return new TextLocation (StartLocation.Line, StartLocation.Column + tokenLength);
return new TextLocation (StartLocation.Line, StartLocation.Column + TokenLength);
}
}
public CSharpTokenNode (TextLocation location, int tokenLength)
public CSharpTokenNode (TextLocation location)
{
this.startLocation = location;
this.tokenLength = tokenLength;
}
#region IRelocationable implementation
void IRelocatable.SetStartLocation (TextLocation startLocation)
public override string GetText (CSharpFormattingOptions formattingOptions = null)
{
if (!(Role is TokenRole))
return null;
return ((TokenRole)Role).Token;
}
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitCSharpTokenNode (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
this.startLocation = startLocation;
return visitor.VisitCSharpTokenNode (this);
}
#endregion
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitCSharpTokenNode (this, data);
}

4
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/CSharpUtil.cs

@ -74,7 +74,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -74,7 +74,6 @@ namespace ICSharpCode.NRefactory.CSharp
return new UnaryOperatorExpression (UnaryOperatorType.Not, new ParenthesizedExpression (condition));
}
}
if (condition is ConditionalExpression) {
var cEx = condition as ConditionalExpression;
cEx.Condition = InvertCondition (cEx.Condition);
@ -83,8 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -83,8 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (condition is PrimitiveExpression) {
var pex = condition as PrimitiveExpression;
if (pex.Value is bool) {
pex.Value = !((bool)pex.Value);
return pex;
return new PrimitiveExpression (!((bool)pex.Value));
}
}

84
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs

@ -28,6 +28,10 @@ using System.Collections.Generic; @@ -28,6 +28,10 @@ using System.Collections.Generic;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem;
using System.Threading;
using Mono.CSharp;
using System.IO;
using ICSharpCode.NRefactory.Editor;
namespace ICSharpCode.NRefactory.CSharp
{
@ -41,10 +45,22 @@ namespace ICSharpCode.NRefactory.CSharp @@ -41,10 +45,22 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
string fileName;
/// <summary>
/// Gets/Sets the file name of this compilation unit.
/// </summary>
public string FileName { get; set; }
public string FileName {
get { return fileName; }
set {
ThrowIfFrozen();
fileName = value;
}
}
public AstNodeCollection<AstNode> Members {
get { return GetChildrenByRole(MemberRole); }
}
List<Error> errors = new List<Error> ();
@ -68,17 +84,18 @@ namespace ICSharpCode.NRefactory.CSharp @@ -68,17 +84,18 @@ namespace ICSharpCode.NRefactory.CSharp
{
}
public IEnumerable<TypeDeclaration> GetTypes (bool includeInnerTypes = false)
public IEnumerable<TypeDeclaration> GetTypes(bool includeInnerTypes = false)
{
Stack<AstNode> nodeStack = new Stack<AstNode> ();
nodeStack.Push (this);
nodeStack.Push(this);
while (nodeStack.Count > 0) {
var curNode = nodeStack.Pop ();
if (curNode is TypeDeclaration)
var curNode = nodeStack.Pop();
if (curNode is TypeDeclaration) {
yield return (TypeDeclaration)curNode;
}
foreach (var child in curNode.Children) {
if (!(child is Statement || child is Expression) &&
(child.Role != TypeDeclaration.MemberRole || (child is TypeDeclaration && includeInnerTypes)))
(child.Role != Roles.TypeMemberRole || (child is TypeDeclaration && includeInnerTypes)))
nodeStack.Push (child);
}
}
@ -90,7 +107,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -90,7 +107,17 @@ namespace ICSharpCode.NRefactory.CSharp
return o != null && GetChildrenByRole(MemberRole).DoMatch(o.GetChildrenByRole(MemberRole), match);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitCompilationUnit (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitCompilationUnit (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitCompilationUnit (this, data);
}
@ -98,14 +125,45 @@ namespace ICSharpCode.NRefactory.CSharp @@ -98,14 +125,45 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>
/// Converts this compilation unit into a parsed file that can be stored in the type system.
/// </summary>
public CSharpParsedFile ToTypeSystem()
public CSharpParsedFile ToTypeSystem ()
{
if (string.IsNullOrEmpty(this.FileName))
throw new InvalidOperationException("Cannot use ToTypeSystem() on a compilation unit without file name.");
var v = new TypeSystemConvertVisitor(this.FileName);
v.VisitCompilationUnit(this, null);
if (string.IsNullOrEmpty (this.FileName))
throw new InvalidOperationException ("Cannot use ToTypeSystem() on a compilation unit without file name.");
var v = new TypeSystemConvertVisitor (this.FileName);
v.VisitCompilationUnit (this);
return v.ParsedFile;
}
public static CompilationUnit Parse (string text, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{
var parser = new CSharpParser ();
if (settings != null)
parser.CompilerSettings = settings;
return parser.Parse (text, fileName);
}
public static CompilationUnit Parse (TextReader reader, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{
var parser = new CSharpParser ();
if (settings != null)
parser.CompilerSettings = settings;
return parser.Parse (reader, fileName, 0);
}
public static CompilationUnit Parse (Stream stream, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{
var parser = new CSharpParser ();
if (settings != null)
parser.CompilerSettings = settings;
return parser.Parse (stream, fileName, 0);
}
public static CompilationUnit Parse (ITextSource textSource, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{
var parser = new CSharpParser ();
if (settings != null)
parser.CompilerSettings = settings;
return parser.Parse (textSource, fileName, 0);
}
}
}

34
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/ComposedType.cs

@ -33,8 +33,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -33,8 +33,8 @@ namespace ICSharpCode.NRefactory.CSharp
{
public class ComposedType : AstType
{
public static readonly Role<CSharpTokenNode> NullableRole = new Role<CSharpTokenNode>("Nullable", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> PointerRole = new Role<CSharpTokenNode>("Pointer", CSharpTokenNode.Null);
public static readonly TokenRole NullableRole = new TokenRole("?");
public static readonly TokenRole PointerRole = new TokenRole("*");
public static readonly Role<ArraySpecifier> ArraySpecifierRole = new Role<ArraySpecifier>("ArraySpecifier");
public AstType BaseType {
@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp
return !GetChildByRole(NullableRole).IsNull;
}
set {
SetChildByRole(NullableRole, value ? new CSharpTokenNode(TextLocation.Empty, 1) : null);
SetChildByRole(NullableRole, value ? new CSharpTokenNode(TextLocation.Empty) : null);
}
}
@ -64,7 +64,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -64,7 +64,7 @@ namespace ICSharpCode.NRefactory.CSharp
d--;
}
while (d < value) {
InsertChildBefore(GetChildByRole(PointerRole), new CSharpTokenNode(TextLocation.Empty, 1), PointerRole);
InsertChildBefore(GetChildByRole(PointerRole), new CSharpTokenNode(TextLocation.Empty), PointerRole);
d++;
}
}
@ -74,7 +74,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -74,7 +74,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildrenByRole (ArraySpecifierRole); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitComposedType (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitComposedType (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitComposedType (this, data);
}
@ -166,7 +176,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -166,7 +176,7 @@ namespace ICSharpCode.NRefactory.CSharp
d--;
}
while (d < value) {
InsertChildBefore(GetChildByRole(Roles.Comma), new CSharpTokenNode(TextLocation.Empty, 1), Roles.Comma);
InsertChildBefore(GetChildByRole(Roles.Comma), new CSharpTokenNode(TextLocation.Empty), Roles.Comma);
d++;
}
}
@ -176,7 +186,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -176,7 +186,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RBracket); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitArraySpecifier (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitArraySpecifier (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitArraySpecifier(this, data);
}

1215
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/DepthFirstAstVisitor.cs

File diff suppressed because it is too large Load Diff

149
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/DocumentationReference.cs

@ -0,0 +1,149 @@ @@ -0,0 +1,149 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// Represents a 'cref' reference in XML documentation.
/// </summary>
public class DocumentationReference : AstNode
{
public static readonly Role<AstType> DeclaringTypeRole = new Role<AstType>("DeclaringType", AstType.Null);
public static readonly Role<AstType> ConversionOperatorReturnTypeRole = new Role<AstType>("ConversionOperatorReturnType", AstType.Null);
EntityType entityType;
OperatorType operatorType;
bool hasParameterList;
/// <summary>
/// Gets/Sets the entity type.
/// Possible values are:
/// <c>EntityType.Operator</c> for operators,
/// <c>EntityType.Indexer</c> for indexers,
/// <c>EntityType.TypeDefinition</c> for references to primitive types,
/// and <c>EntityType.None</c> for everything else.
/// </summary>
public EntityType EntityType {
get { return entityType; }
set {
ThrowIfFrozen();
entityType = value;
}
}
/// <summary>
/// Gets/Sets the operator type.
/// This property is only used when EntityType==Operator.
/// </summary>
public OperatorType OperatorType {
get { return operatorType; }
set {
ThrowIfFrozen();
operatorType = value;
}
}
/// <summary>
/// Gets/Sets whether a parameter list was provided.
/// </summary>
public bool HasParameterList {
get { return hasParameterList; }
set {
ThrowIfFrozen();
hasParameterList = value;
}
}
public override NodeType NodeType {
get { return NodeType.Unknown; }
}
/// <summary>
/// Gets/Sets the declaring type.
/// </summary>
public AstType DeclaringType {
get { return GetChildByRole(DeclaringTypeRole); }
set { SetChildByRole(DeclaringTypeRole, value); }
}
/// <summary>
/// Gets/sets the member name.
/// This property is only used when EntityType==None.
/// </summary>
public string MemberName {
get { return GetChildByRole(Roles.Identifier).Name; }
set { SetChildByRole(Roles.Identifier, Identifier.Create(value)); }
}
/// <summary>
/// Gets/Sets the return type of conversion operators.
/// This property is only used when EntityType==Operator and OperatorType is explicit or implicit.
/// </summary>
public AstType ConversionOperatorReturnType {
get { return GetChildByRole(ConversionOperatorReturnTypeRole); }
set { SetChildByRole(ConversionOperatorReturnTypeRole, value); }
}
public AstNodeCollection<AstType> TypeArguments {
get { return GetChildrenByRole (Roles.TypeArgument); }
}
public AstNodeCollection<ParameterDeclaration> Parameters {
get { return GetChildrenByRole (Roles.Parameter); }
}
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
{
DocumentationReference o = other as DocumentationReference;
if (!(o != null && this.EntityType == o.EntityType && this.HasParameterList == o.HasParameterList))
return false;
if (this.EntityType == EntityType.Operator) {
if (this.OperatorType != o.OperatorType)
return false;
if (this.OperatorType == OperatorType.Implicit || this.OperatorType == OperatorType.Explicit) {
if (!this.ConversionOperatorReturnType.DoMatch(o.ConversionOperatorReturnType, match))
return false;
}
} else if (this.EntityType == EntityType.None) {
if (!MatchString(this.MemberName, o.MemberName))
return false;
if (!this.TypeArguments.DoMatch(o.TypeArguments, match))
return false;
}
return this.Parameters.DoMatch(o.Parameters, match);
}
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitDocumentationReference (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitDocumentationReference (this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitDocumentationReference (this, data);
}
}
}

11
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/ErrorNode.cs

@ -58,7 +58,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -58,7 +58,16 @@ namespace ICSharpCode.NRefactory.CSharp
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return default (T);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
// nothing
return default (S);

29
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AnonymousMethodExpression.cs

@ -34,17 +34,26 @@ namespace ICSharpCode.NRefactory.CSharp @@ -34,17 +34,26 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class AnonymousMethodExpression : Expression
{
public readonly static Role<CSharpTokenNode> AsyncModifierRole = LambdaExpression.AsyncModifierRole;
public readonly static TokenRole DelegateKeywordRole = new TokenRole ("delegate");
public readonly static TokenRole AsyncModifierRole = LambdaExpression.AsyncModifierRole;
public bool IsAsync { get; set; }
bool isAsync;
public bool IsAsync {
get { return isAsync; }
set { ThrowIfFrozen(); isAsync = value; }
}
// used to tell the difference between delegate {} and delegate () {}
bool hasParameterList;
public bool HasParameterList {
get; set;
get { return hasParameterList; }
set { ThrowIfFrozen(); hasParameterList = value; }
}
public CSharpTokenNode DelegateToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (DelegateKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -82,7 +91,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -82,7 +91,17 @@ namespace ICSharpCode.NRefactory.CSharp
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitAnonymousMethodExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitAnonymousMethodExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitAnonymousMethodExpression (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AnonymousTypeCreateExpression.cs

@ -33,8 +33,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -33,8 +33,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class AnonymousTypeCreateExpression : Expression
{
public readonly static TokenRole NewKeywordRole = new TokenRole ("new");
public CSharpTokenNode NewToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (NewKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -64,7 +66,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -64,7 +66,17 @@ namespace ICSharpCode.NRefactory.CSharp
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitAnonymousTypeCreateExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitAnonymousTypeCreateExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitAnonymousTypeCreateExpression (this, data);
}

17
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayCreateExpression.cs

@ -26,9 +26,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -26,9 +26,14 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class ArrayCreateExpression : Expression
{
public readonly static TokenRole NewKeywordRole = new TokenRole ("new");
public readonly static Role<ArraySpecifier> AdditionalArraySpecifierRole = new Role<ArraySpecifier>("AdditionalArraySpecifier");
public readonly static Role<ArrayInitializerExpression> InitializerRole = new Role<ArrayInitializerExpression>("Initializer", ArrayInitializerExpression.Null);
public CSharpTokenNode NewToken {
get { return GetChildByRole (NewKeywordRole); }
}
public AstType Type {
get { return GetChildByRole (Roles.Type); }
set { SetChildByRole (Roles.Type, value); }
@ -51,7 +56,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -51,7 +56,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (InitializerRole, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitArrayCreateExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitArrayCreateExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitArrayCreateExpression (this, data);
}

23
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayInitializerExpression.cs

@ -58,7 +58,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -58,7 +58,16 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return default (T);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return default (S);
}
@ -82,7 +91,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -82,7 +91,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RBrace); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitArrayInitializerExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitArrayInitializerExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitArrayInitializerExpression (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AsExpression.cs

@ -31,13 +31,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,13 +31,15 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class AsExpression : Expression
{
public readonly static TokenRole AsKeywordRole = new TokenRole ("as");
public Expression Expression {
get { return GetChildByRole (Roles.Expression); }
set { SetChildByRole(Roles.Expression, value); }
}
public CSharpTokenNode AsToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (AsKeywordRole); }
}
public AstType Type {
@ -55,7 +57,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -55,7 +57,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (type, Roles.Type);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitAsExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitAsExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitAsExpression (this, data);
}

51
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AssignmentExpression.cs

@ -36,9 +36,20 @@ namespace ICSharpCode.NRefactory.CSharp @@ -36,9 +36,20 @@ namespace ICSharpCode.NRefactory.CSharp
{
// reuse roles from BinaryOperatorExpression
public readonly static Role<Expression> LeftRole = BinaryOperatorExpression.LeftRole;
public readonly static Role<CSharpTokenNode> OperatorRole = BinaryOperatorExpression.OperatorRole;
public readonly static Role<Expression> RightRole = BinaryOperatorExpression.RightRole;
public readonly static TokenRole AssignRole = new TokenRole ("=");
public readonly static TokenRole AddRole = new TokenRole ("+=");
public readonly static TokenRole SubtractRole = new TokenRole ("-=");
public readonly static TokenRole MultiplyRole = new TokenRole ("*=");
public readonly static TokenRole DivideRole = new TokenRole ("/=");
public readonly static TokenRole ModulusRole = new TokenRole ("%=");
public readonly static TokenRole ShiftLeftRole = new TokenRole ("<<=");
public readonly static TokenRole ShiftRightRole = new TokenRole (">>=");
public readonly static TokenRole BitwiseAndRole = new TokenRole ("&=");
public readonly static TokenRole BitwiseOrRole = new TokenRole ("|=");
public readonly static TokenRole ExclusiveOrRole = new TokenRole ("^=");
public AssignmentExpression()
{
}
@ -67,7 +78,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -67,7 +78,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
public CSharpTokenNode OperatorToken {
get { return GetChildByRole (OperatorRole); }
get { return GetChildByRole (GetOperatorRole(Operator)); }
}
public Expression Right {
@ -75,7 +86,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -75,7 +86,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole(RightRole, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitAssignmentExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitAssignmentExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitAssignmentExpression (this, data);
}
@ -87,31 +108,31 @@ namespace ICSharpCode.NRefactory.CSharp @@ -87,31 +108,31 @@ namespace ICSharpCode.NRefactory.CSharp
&& this.Left.DoMatch(o.Left, match) && this.Right.DoMatch(o.Right, match);
}
public static string GetOperatorSymbol(AssignmentOperatorType op)
public static TokenRole GetOperatorRole(AssignmentOperatorType op)
{
switch (op) {
case AssignmentOperatorType.Assign:
return "=";
return AssignRole;
case AssignmentOperatorType.Add:
return "+=";
return AddRole;
case AssignmentOperatorType.Subtract:
return "-=";
return SubtractRole;
case AssignmentOperatorType.Multiply:
return "*=";
return MultiplyRole;
case AssignmentOperatorType.Divide:
return "/=";
return DivideRole;
case AssignmentOperatorType.Modulus:
return "%=";
return ModulusRole;
case AssignmentOperatorType.ShiftLeft:
return "<<=";
return ShiftLeftRole;
case AssignmentOperatorType.ShiftRight:
return ">>=";
return ShiftRightRole;
case AssignmentOperatorType.BitwiseAnd:
return "&=";
return BitwiseAndRole;
case AssignmentOperatorType.BitwiseOr:
return "|=";
return BitwiseOrRole;
case AssignmentOperatorType.ExclusiveOr:
return "^=";
return ExclusiveOrRole;
default:
throw new NotSupportedException("Invalid value for AssignmentOperatorType");
}

12
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/BaseReferenceExpression.cs

@ -47,7 +47,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -47,7 +47,17 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitBaseReferenceExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitBaseReferenceExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitBaseReferenceExpression (this, data);
}

77
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/BinaryOperatorExpression.cs

@ -34,8 +34,27 @@ namespace ICSharpCode.NRefactory.CSharp @@ -34,8 +34,27 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class BinaryOperatorExpression : Expression
{
public readonly static TokenRole BitwiseAndRole = new TokenRole ("&");
public readonly static TokenRole BitwiseOrRole = new TokenRole ("|");
public readonly static TokenRole ConditionalAndRole = new TokenRole ("&&");
public readonly static TokenRole ConditionalOrRole = new TokenRole ("||");
public readonly static TokenRole ExclusiveOrRole = new TokenRole ("^");
public readonly static TokenRole GreaterThanRole = new TokenRole (">");
public readonly static TokenRole GreaterThanOrEqualRole = new TokenRole (">=");
public readonly static TokenRole EqualityRole = new TokenRole ("==");
public readonly static TokenRole InEqualityRole = new TokenRole ("!=");
public readonly static TokenRole LessThanRole = new TokenRole ("<");
public readonly static TokenRole LessThanOrEqualRole = new TokenRole ("<=");
public readonly static TokenRole AddRole = new TokenRole ("+");
public readonly static TokenRole SubtractRole = new TokenRole ("-");
public readonly static TokenRole MultiplyRole = new TokenRole ("*");
public readonly static TokenRole DivideRole = new TokenRole ("/");
public readonly static TokenRole ModulusRole = new TokenRole ("%");
public readonly static TokenRole ShiftLeftRole = new TokenRole ("<<");
public readonly static TokenRole ShiftRightRole = new TokenRole (">>");
public readonly static TokenRole NullCoalescingRole = new TokenRole ("??");
public readonly static Role<Expression> LeftRole = new Role<Expression>("Left", Expression.Null);
public readonly static Role<CSharpTokenNode> OperatorRole = new Role<CSharpTokenNode>("Operator", CSharpTokenNode.Null);
public readonly static Role<Expression> RightRole = new Role<Expression>("Right", Expression.Null);
public BinaryOperatorExpression()
@ -60,15 +79,25 @@ namespace ICSharpCode.NRefactory.CSharp @@ -60,15 +79,25 @@ namespace ICSharpCode.NRefactory.CSharp
}
public CSharpTokenNode OperatorToken {
get { return GetChildByRole (OperatorRole); }
get { return GetChildByRole (GetOperatorRole (Operator)); }
}
public Expression Right {
get { return GetChildByRole (RightRole); }
set { SetChildByRole(RightRole, value); }
set { SetChildByRole (RightRole, value); }
}
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitBinaryOperatorExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitBinaryOperatorExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitBinaryOperatorExpression (this, data);
}
@ -80,47 +109,47 @@ namespace ICSharpCode.NRefactory.CSharp @@ -80,47 +109,47 @@ namespace ICSharpCode.NRefactory.CSharp
&& this.Left.DoMatch(o.Left, match) && this.Right.DoMatch(o.Right, match);
}
public static string GetOperatorSymbol(BinaryOperatorType op)
public static TokenRole GetOperatorRole (BinaryOperatorType op)
{
switch (op) {
case BinaryOperatorType.BitwiseAnd:
return "&";
return BitwiseAndRole;
case BinaryOperatorType.BitwiseOr:
return "|";
return BitwiseOrRole;
case BinaryOperatorType.ConditionalAnd:
return "&&";
return ConditionalAndRole;
case BinaryOperatorType.ConditionalOr:
return "||";
return ConditionalOrRole;
case BinaryOperatorType.ExclusiveOr:
return "^";
return ExclusiveOrRole;
case BinaryOperatorType.GreaterThan:
return ">";
return GreaterThanRole;
case BinaryOperatorType.GreaterThanOrEqual:
return ">=";
return GreaterThanOrEqualRole;
case BinaryOperatorType.Equality:
return "==";
return EqualityRole;
case BinaryOperatorType.InEquality:
return "!=";
return InEqualityRole;
case BinaryOperatorType.LessThan:
return "<";
return LessThanRole;
case BinaryOperatorType.LessThanOrEqual:
return "<=";
return LessThanOrEqualRole;
case BinaryOperatorType.Add:
return "+";
return AddRole;
case BinaryOperatorType.Subtract:
return "-";
return SubtractRole;
case BinaryOperatorType.Multiply:
return "*";
return MultiplyRole;
case BinaryOperatorType.Divide:
return "/";
return DivideRole;
case BinaryOperatorType.Modulus:
return "%";
return ModulusRole;
case BinaryOperatorType.ShiftLeft:
return "<<";
return ShiftLeftRole;
case BinaryOperatorType.ShiftRight:
return ">>";
return ShiftRightRole;
case BinaryOperatorType.NullCoalescing:
return "??";
return NullCoalescingRole;
default:
throw new NotSupportedException("Invalid value for BinaryOperatorType");
}

12
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/CastExpression.cs

@ -59,7 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -59,7 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (expression, Roles.Expression);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitCastExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitCastExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitCastExpression (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/CheckedExpression.cs

@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class CheckedExpression : Expression
{
public readonly static TokenRole CheckedKeywordRole = new TokenRole ("checked");
public CSharpTokenNode CheckedToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (CheckedKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -57,7 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -57,7 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (expression, Roles.Expression);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitCheckedExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitCheckedExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitCheckedExpression (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ConditionalExpression.cs

@ -32,9 +32,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -32,9 +32,9 @@ namespace ICSharpCode.NRefactory.CSharp
public class ConditionalExpression : Expression
{
public readonly static Role<Expression> ConditionRole = Roles.Condition;
public readonly static Role<CSharpTokenNode> QuestionMarkRole = new Role<CSharpTokenNode>("QuestionMark", CSharpTokenNode.Null);
public readonly static TokenRole QuestionMarkRole = new TokenRole("?");
public readonly static Role<Expression> TrueRole = new Role<Expression>("True", Expression.Null);
public readonly static Role<CSharpTokenNode> ColonRole = Roles.Colon;
public readonly static TokenRole ColonRole = Roles.Colon;
public readonly static Role<Expression> FalseRole = new Role<Expression>("False", Expression.Null);
public Expression Condition {
@ -71,7 +71,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -71,7 +71,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (falseExpression, FalseRole);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitConditionalExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitConditionalExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitConditionalExpression (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/DefaultValueExpression.cs

@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class DefaultValueExpression : Expression
{
public readonly static TokenRole DefaultKeywordRole = new TokenRole ("default");
public CSharpTokenNode DefaultToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (DefaultKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -57,7 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -57,7 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (type, Roles.Type);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitDefaultValueExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitDefaultValueExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitDefaultValueExpression (this, data);
}

17
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/DirectionExpression.cs

@ -38,13 +38,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -38,13 +38,16 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class DirectionExpression : Expression
{
public readonly static TokenRole RefKeywordRole = new TokenRole ("ref");
public readonly static TokenRole OutKeywordRole = new TokenRole ("out");
public FieldDirection FieldDirection {
get;
set;
}
public CSharpTokenNode FieldDirectionToken {
get { return GetChildByRole (Roles.Keyword); }
get { return FieldDirection == ICSharpCode.NRefactory.CSharp.FieldDirection.Ref ? GetChildByRole (RefKeywordRole) : GetChildByRole (OutKeywordRole); }
}
public Expression Expression {
@ -62,7 +65,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -62,7 +65,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (expression, Roles.Expression);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitDirectionExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitDirectionExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitDirectionExpression (this, data);
}

15
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/EmptyExpression.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -30,7 +30,7 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>
/// Type&lt;[EMPTY]&gt;
/// </summary>
public class EmptyExpression : Expression, IRelocatable
public class EmptyExpression : Expression
{
TextLocation location;
@ -55,14 +55,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -55,14 +55,17 @@ namespace ICSharpCode.NRefactory.CSharp
this.location = location;
}
#region IRelocationable implementation
void IRelocatable.SetStartLocation (TextLocation startLocation)
public override void AcceptVisitor (IAstVisitor visitor)
{
this.location = startLocation;
visitor.VisitEmptyExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitEmptyExpression (this);
}
#endregion
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitEmptyExpression (this, data);
}

14
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ErrorExpression.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// ErrorExpression.cs
//
// Author:
@ -52,8 +52,18 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,8 +52,18 @@ namespace ICSharpCode.NRefactory.CSharp
this.location = location;
}
public override void AcceptVisitor (IAstVisitor visitor)
{
// nothing
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
// nothing
return default (T);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
// nothing
return default(S);

23
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/Expression.cs

@ -41,7 +41,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -41,7 +41,16 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return default (T);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return default (S);
}
@ -72,7 +81,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -72,7 +81,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}

14
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/IdentifierExpression.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value, TextLocation.Empty));
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value));
}
}
@ -60,7 +60,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -60,7 +60,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildrenByRole (Roles.TypeArgument); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitIdentifierExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitIdentifierExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitIdentifierExpression (this, data);
}

12
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/IndexerExpression.cs

@ -68,7 +68,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -68,7 +68,17 @@ namespace ICSharpCode.NRefactory.CSharp
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitIndexerExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitIndexerExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitIndexerExpression (this, data);
}

12
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/InvocationExpression.cs

@ -50,7 +50,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -50,7 +50,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RPar); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitInvocationExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitInvocationExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitInvocationExpression (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/IsExpression.cs

@ -31,13 +31,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,13 +31,15 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class IsExpression : Expression
{
public readonly static TokenRole IsKeywordRole = new TokenRole ("is");
public Expression Expression {
get { return GetChildByRole(Roles.Expression); }
set { SetChildByRole(Roles.Expression, value); }
}
public CSharpTokenNode IsToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (IsKeywordRole); }
}
public AstType Type {
@ -45,7 +47,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -45,7 +47,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole(Roles.Type, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitIsExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitIsExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitIsExpression (this, data);
}

23
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/LambdaExpression.cs

@ -33,11 +33,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -33,11 +33,16 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class LambdaExpression : Expression
{
public readonly static Role<CSharpTokenNode> AsyncModifierRole = new Role<CSharpTokenNode>("AsyncModifier", CSharpTokenNode.Null);
public readonly static Role<CSharpTokenNode> ArrowRole = new Role<CSharpTokenNode>("Arrow", CSharpTokenNode.Null);
public readonly static TokenRole AsyncModifierRole = new TokenRole ("async");
public readonly static TokenRole ArrowRole = new TokenRole ("=>");
public static readonly Role<AstNode> BodyRole = new Role<AstNode>("Body", AstNode.Null);
public bool IsAsync { get; set; }
bool isAsync;
public bool IsAsync {
get { return isAsync; }
set { ThrowIfFrozen(); isAsync = value; }
}
public AstNodeCollection<ParameterDeclaration> Parameters {
get { return GetChildrenByRole (Roles.Parameter); }
@ -52,7 +57,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,7 +57,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (BodyRole, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitLambdaExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitLambdaExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitLambdaExpression (this, data);
}

14
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/MemberReferenceExpression.cs

@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole (Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
SetChildByRole (Roles.Identifier, Identifier.Create (value));
}
}
@ -87,7 +87,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -87,7 +87,17 @@ namespace ICSharpCode.NRefactory.CSharp
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitMemberReferenceExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitMemberReferenceExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitMemberReferenceExpression (this, data);
}

14
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/NamedArgumentExpression.cs

@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value, TextLocation.Empty));
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value));
}
}
@ -63,7 +63,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -63,7 +63,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Expression, value); }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitNamedArgumentExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitNamedArgumentExpression (this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitNamedArgumentExpression(this, data);
}

14
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/NamedExpression.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value, TextLocation.Empty));
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value));
}
}
@ -73,7 +73,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -73,7 +73,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Expression, value); }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitNamedExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitNamedExpression (this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitNamedExpression(this, data);
}

12
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/NullReferenceExpression.cs

@ -53,7 +53,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,7 +53,17 @@ namespace ICSharpCode.NRefactory.CSharp
this.location = location;
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitNullReferenceExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitNullReferenceExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitNullReferenceExpression (this, data);
}

15
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ObjectCreateExpression.cs

@ -33,10 +33,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -33,10 +33,11 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class ObjectCreateExpression : Expression
{
public readonly static TokenRole NewKeywordRole = new TokenRole ("new");
public readonly static Role<ArrayInitializerExpression> InitializerRole = ArrayCreateExpression.InitializerRole;
public CSharpTokenNode NewToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (NewKeywordRole); }
}
public AstType Type {
@ -79,7 +80,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -79,7 +80,17 @@ namespace ICSharpCode.NRefactory.CSharp
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitObjectCreateExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitObjectCreateExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitObjectCreateExpression (this, data);
}

14
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ParenthesizedExpression.cs

@ -53,7 +53,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,7 +53,17 @@ namespace ICSharpCode.NRefactory.CSharp
Expression = expr;
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitParenthesizedExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitParenthesizedExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitParenthesizedExpression (this, data);
}
@ -81,7 +91,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -81,7 +91,7 @@ namespace ICSharpCode.NRefactory.CSharp
public static Expression UnpackParenthesizedExpression(Expression expr)
{
while (ActsAsParenthesizedExpression(expr))
expr = expr.GetChildByRole(ParenthesizedExpression.Roles.Expression);
expr = expr.GetChildByRole(Roles.Expression);
return expr;
}
}

20
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/PointerReferenceExpression.cs

@ -33,19 +33,23 @@ namespace ICSharpCode.NRefactory.CSharp @@ -33,19 +33,23 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class PointerReferenceExpression : Expression
{
public readonly static Role<CSharpTokenNode> ArrowRole = new Role<CSharpTokenNode>("Arrow", CSharpTokenNode.Null);
public readonly static TokenRole ArrowRole = new TokenRole ("->");
public Expression Target {
get { return GetChildByRole (Roles.TargetExpression); }
set { SetChildByRole(Roles.TargetExpression, value); }
}
public CSharpTokenNode ArrowToken {
get { return GetChildByRole (ArrowRole); }
}
public string MemberName {
get {
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole(Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
SetChildByRole(Roles.Identifier, Identifier.Create (value));
}
}
@ -53,7 +57,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,7 +57,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildrenByRole (Roles.TypeArgument); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitPointerReferenceExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitPointerReferenceExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPointerReferenceExpression (this, data);
}

35
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/PrimitiveExpression.cs

@ -24,12 +24,14 @@ @@ -24,12 +24,14 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// Represents a literal value.
/// </summary>
public class PrimitiveExpression : Expression, IRelocatable
public class PrimitiveExpression : Expression
{
public static readonly object AnyValue = new object();
@ -47,20 +49,30 @@ namespace ICSharpCode.NRefactory.CSharp @@ -47,20 +49,30 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
object value;
public object Value {
get;
set;
get { return this.value; }
set {
ThrowIfFrozen();
this.value = value;
}
}
public string LiteralValue {
get {
return literalValue;
get { return literalValue; }
set {
if (value == null)
throw new ArgumentNullException();
ThrowIfFrozen();
literalValue = value;
}
}
public PrimitiveExpression (object value)
{
this.Value = value;
this.literalValue = "";
}
public PrimitiveExpression (object value, string literalValue)
@ -76,14 +88,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -76,14 +88,17 @@ namespace ICSharpCode.NRefactory.CSharp
this.literalValue = literalValue ?? "";
}
#region IRelocationable implementation
void IRelocatable.SetStartLocation (TextLocation startLocation)
public override void AcceptVisitor (IAstVisitor visitor)
{
this.startLocation = startLocation;
visitor.VisitPrimitiveExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitPrimitiveExpression (this);
}
#endregion
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPrimitiveExpression (this, data);
}

183
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/QueryExpression.cs

@ -36,7 +36,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -36,7 +36,16 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return default (T);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return default (S);
}
@ -52,7 +61,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,7 +61,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildrenByRole(ClauseRole); }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitQueryExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitQueryExpression (this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitQueryExpression (this, data);
}
@ -92,7 +111,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -92,7 +111,7 @@ namespace ICSharpCode.NRefactory.CSharp
public class QueryContinuationClause : QueryClause
{
public static readonly Role<QueryExpression> PrecedingQueryRole = new Role<QueryExpression>("PrecedingQuery", QueryExpression.Null);
public static readonly Role<CSharpTokenNode> IntoKeywordRole = Roles.Keyword;
public static readonly TokenRole IntoKeywordRole = new TokenRole ("into");
public QueryExpression PrecedingQuery {
get { return GetChildByRole(PrecedingQueryRole); }
@ -104,7 +123,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -104,7 +123,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value, TextLocation.Empty));
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value));
}
}
@ -112,7 +131,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -112,7 +131,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Identifier); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitQueryContinuationClause (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitQueryContinuationClause (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitQueryContinuationClause (this, data);
}
@ -126,8 +155,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -126,8 +155,8 @@ namespace ICSharpCode.NRefactory.CSharp
public class QueryFromClause : QueryClause
{
public static readonly Role<CSharpTokenNode> FromKeywordRole = Roles.Keyword;
public static readonly Role<CSharpTokenNode> InKeywordRole = Roles.InKeyword;
public static readonly TokenRole FromKeywordRole = new TokenRole ("from");
public static readonly TokenRole InKeywordRole = new TokenRole ("in");
public AstType Type {
get { return GetChildByRole (Roles.Type); }
@ -139,7 +168,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -139,7 +168,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value, TextLocation.Empty));
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value));
}
}
@ -152,7 +181,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -152,7 +181,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Expression, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitQueryFromClause (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitQueryFromClause (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitQueryFromClause (this, data);
}
@ -167,8 +206,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -167,8 +206,10 @@ namespace ICSharpCode.NRefactory.CSharp
public class QueryLetClause : QueryClause
{
public readonly static TokenRole LetKeywordRole = new TokenRole ("let");
public CSharpTokenNode LetKeyword {
get { return GetChildByRole(Roles.Keyword); }
get { return GetChildByRole(LetKeywordRole); }
}
public string Identifier {
@ -176,7 +217,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -176,7 +217,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole(Roles.Identifier).Name;
}
set {
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value, TextLocation.Empty));
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value));
}
}
@ -193,7 +234,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -193,7 +234,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole(Roles.Expression, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitQueryLetClause (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitQueryLetClause (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitQueryLetClause (this, data);
}
@ -208,8 +259,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -208,8 +259,10 @@ namespace ICSharpCode.NRefactory.CSharp
public class QueryWhereClause : QueryClause
{
public readonly static TokenRole WhereKeywordRole = new TokenRole ("where");
public CSharpTokenNode WhereKeyword {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (WhereKeywordRole); }
}
public Expression Condition {
@ -217,7 +270,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -217,7 +270,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Condition, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitQueryWhereClause (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitQueryWhereClause (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitQueryWhereClause (this, data);
}
@ -234,16 +297,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -234,16 +297,16 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class QueryJoinClause : QueryClause
{
public static readonly Role<CSharpTokenNode> JoinKeywordRole = Roles.Keyword;
public static readonly TokenRole JoinKeywordRole = new TokenRole ("join");
public static readonly Role<AstType> TypeRole = Roles.Type;
public static readonly Role<Identifier> JoinIdentifierRole = Roles.Identifier;
public static readonly Role<CSharpTokenNode> InKeywordRole = Roles.InKeyword;
public static readonly TokenRole InKeywordRole = new TokenRole ("in");
public static readonly Role<Expression> InExpressionRole = Roles.Expression;
public static readonly Role<CSharpTokenNode> OnKeywordRole = new Role<CSharpTokenNode>("OnKeyword", CSharpTokenNode.Null);
public static readonly TokenRole OnKeywordRole = new TokenRole ("on");
public static readonly Role<Expression> OnExpressionRole = new Role<Expression>("OnExpression", Expression.Null);
public static readonly Role<CSharpTokenNode> EqualsKeywordRole = new Role<CSharpTokenNode>("EqualsKeyword", CSharpTokenNode.Null);
public static readonly TokenRole EqualsKeywordRole = new TokenRole ("equals");
public static readonly Role<Expression> EqualsExpressionRole = new Role<Expression>("EqualsExpression", Expression.Null);
public static readonly Role<CSharpTokenNode> IntoKeywordRole = new Role<CSharpTokenNode>("IntoKeyword", CSharpTokenNode.Null);
public static readonly TokenRole IntoKeywordRole = new TokenRole ("into");
public static readonly Role<Identifier> IntoIdentifierRole = new Role<Identifier>("IntoIdentifier", Identifier.Null);
public bool IsGroupJoin {
@ -264,7 +327,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -264,7 +327,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole(JoinIdentifierRole).Name;
}
set {
SetChildByRole(JoinIdentifierRole, Identifier.Create (value, TextLocation.Empty));
SetChildByRole(JoinIdentifierRole, Identifier.Create (value));
}
}
@ -308,7 +371,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -308,7 +371,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (IntoIdentifierRole).Name;
}
set {
SetChildByRole(IntoIdentifierRole, Identifier.Create (value, TextLocation.Empty));
SetChildByRole(IntoIdentifierRole, Identifier.Create (value));
}
}
@ -316,7 +379,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -316,7 +379,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole(IntoIdentifierRole); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitQueryJoinClause (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitQueryJoinClause (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitQueryJoinClause (this, data);
}
@ -334,17 +407,28 @@ namespace ICSharpCode.NRefactory.CSharp @@ -334,17 +407,28 @@ namespace ICSharpCode.NRefactory.CSharp
public class QueryOrderClause : QueryClause
{
public static readonly TokenRole OrderbyKeywordRole = new TokenRole ("orderby");
public static readonly Role<QueryOrdering> OrderingRole = new Role<QueryOrdering>("Ordering");
public CSharpTokenNode Keyword {
get { return GetChildByRole (Roles.Keyword); }
public CSharpTokenNode OrderbyToken {
get { return GetChildByRole (OrderbyKeywordRole); }
}
public AstNodeCollection<QueryOrdering> Orderings {
get { return GetChildrenByRole (OrderingRole); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitQueryOrderClause (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitQueryOrderClause (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitQueryOrderClause (this, data);
}
@ -358,6 +442,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -358,6 +442,9 @@ namespace ICSharpCode.NRefactory.CSharp
public class QueryOrdering : AstNode
{
public readonly static TokenRole AscendingKeywordRole = new TokenRole ("ascending");
public readonly static TokenRole DescendingKeywordRole = new TokenRole ("descending");
public override NodeType NodeType {
get { return NodeType.Unknown; }
}
@ -373,10 +460,20 @@ namespace ICSharpCode.NRefactory.CSharp @@ -373,10 +460,20 @@ namespace ICSharpCode.NRefactory.CSharp
}
public CSharpTokenNode DirectionToken {
get { return GetChildByRole (Roles.Keyword); }
get { return Direction == QueryOrderingDirection.Ascending ? GetChildByRole (AscendingKeywordRole) : GetChildByRole (DescendingKeywordRole); }
}
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitQueryOrdering (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitQueryOrdering (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitQueryOrdering (this, data);
}
@ -397,8 +494,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -397,8 +494,10 @@ namespace ICSharpCode.NRefactory.CSharp
public class QuerySelectClause : QueryClause
{
public readonly static TokenRole SelectKeywordRole = new TokenRole ("select");
public CSharpTokenNode SelectKeyword {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (SelectKeywordRole); }
}
public Expression Expression {
@ -406,7 +505,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -406,7 +505,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Expression, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitQuerySelectClause (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitQuerySelectClause (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitQuerySelectClause (this, data);
}
@ -420,9 +529,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -420,9 +529,9 @@ namespace ICSharpCode.NRefactory.CSharp
public class QueryGroupClause : QueryClause
{
public static readonly Role<CSharpTokenNode> GroupKeywordRole = Roles.Keyword;
public static readonly TokenRole GroupKeywordRole = new TokenRole ("group");
public static readonly Role<Expression> ProjectionRole = new Role<Expression>("Projection", Expression.Null);
public static readonly Role<CSharpTokenNode> ByKeywordRole = new Role<CSharpTokenNode>("ByKeyword", CSharpTokenNode.Null);
public static readonly TokenRole ByKeywordRole = new TokenRole ("by");
public static readonly Role<Expression> KeyRole = new Role<Expression>("Key", Expression.Null);
public CSharpTokenNode GroupKeyword {
@ -443,7 +552,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -443,7 +552,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (KeyRole, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitQueryGroupClause (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitQueryGroupClause (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitQueryGroupClause (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/SizeOfExpression.cs

@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class SizeOfExpression : Expression
{
public readonly static TokenRole SizeofKeywordRole = new TokenRole ("sizeof");
public CSharpTokenNode SizeOfToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (SizeofKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -57,7 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -57,7 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (type, Roles.Type);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitSizeOfExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitSizeOfExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitSizeOfExpression (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/StackAllocExpression.cs

@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class StackAllocExpression : Expression
{
public readonly static TokenRole StackallocKeywordRole = new TokenRole ("stackalloc");
public CSharpTokenNode StackAllocToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (StackallocKeywordRole); }
}
public AstType Type {
@ -53,7 +55,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,7 +55,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RBracket); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitStackAllocExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitStackAllocExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitStackAllocExpression (this, data);
}

14
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ThisReferenceExpression.cs

@ -46,8 +46,18 @@ namespace ICSharpCode.NRefactory.CSharp @@ -46,8 +46,18 @@ namespace ICSharpCode.NRefactory.CSharp
return new TextLocation (Location.Line, Location.Column + "this".Length);
}
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitThisReferenceExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitThisReferenceExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitThisReferenceExpression (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/TypeOfExpression.cs

@ -32,8 +32,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -32,8 +32,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class TypeOfExpression : Expression
{
public readonly static TokenRole TypeofKeywordRole = new TokenRole ("typeof");
public CSharpTokenNode TypeOfToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (TypeofKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -58,7 +60,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -58,7 +60,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (type, Roles.Type);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitTypeOfExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitTypeOfExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitTypeOfExpression (this, data);
}

12
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/TypeReferenceExpression.cs

@ -31,7 +31,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,7 +31,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole(Roles.Type, value); }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitTypeReferenceExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitTypeReferenceExpression (this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitTypeReferenceExpression(this, data);
}

44
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/UnaryOperatorExpression.cs

@ -34,7 +34,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -34,7 +34,15 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class UnaryOperatorExpression : Expression
{
public readonly static Role<CSharpTokenNode> OperatorRole = BinaryOperatorExpression.OperatorRole;
public readonly static TokenRole NotRole = new TokenRole ("!");
public readonly static TokenRole BitNotRole = new TokenRole ("~");
public readonly static TokenRole MinusRole = new TokenRole ("-");
public readonly static TokenRole PlusRole = new TokenRole ("+");
public readonly static TokenRole IncrementRole = new TokenRole ("++");
public readonly static TokenRole DecrementRole = new TokenRole ("--");
public readonly static TokenRole DereferenceRole = new TokenRole ("*");
public readonly static TokenRole AddressOfRole = new TokenRole ("&");
public readonly static TokenRole AwaitRole = new TokenRole ("await");
public UnaryOperatorExpression()
{
@ -52,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
public CSharpTokenNode OperatorToken {
get { return GetChildByRole (OperatorRole); }
get { return GetChildByRole (GetOperatorRole (Operator)); }
}
public Expression Expression {
@ -60,7 +68,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -60,7 +68,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Expression, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitUnaryOperatorExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitUnaryOperatorExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitUnaryOperatorExpression (this, data);
}
@ -72,29 +90,29 @@ namespace ICSharpCode.NRefactory.CSharp @@ -72,29 +90,29 @@ namespace ICSharpCode.NRefactory.CSharp
&& this.Expression.DoMatch(o.Expression, match);
}
public static string GetOperatorSymbol(UnaryOperatorType op)
public static TokenRole GetOperatorRole(UnaryOperatorType op)
{
switch (op) {
case UnaryOperatorType.Not:
return "!";
return NotRole;
case UnaryOperatorType.BitNot:
return "~";
return BitNotRole;
case UnaryOperatorType.Minus:
return "-";
return MinusRole;
case UnaryOperatorType.Plus:
return "+";
return PlusRole;
case UnaryOperatorType.Increment:
case UnaryOperatorType.PostIncrement:
return "++";
return IncrementRole;
case UnaryOperatorType.PostDecrement:
case UnaryOperatorType.Decrement:
return "--";
return DecrementRole;
case UnaryOperatorType.Dereference:
return "*";
return DereferenceRole;
case UnaryOperatorType.AddressOf:
return "&";
return AddressOfRole;
case UnaryOperatorType.Await:
return "await";
return AwaitRole;
default:
throw new NotSupportedException("Invalid value for UnaryOperatorType");
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/UncheckedExpression.cs

@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class UncheckedExpression : Expression
{
public readonly static TokenRole UncheckedKeywordRole = new TokenRole ("unchecked");
public CSharpTokenNode UncheckedToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (UncheckedKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -57,7 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -57,7 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (expression, Roles.Expression);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitUncheckedExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitUncheckedExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitUncheckedExpression (this, data);
}

32
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/UndocumentedExpression.cs

@ -42,12 +42,30 @@ namespace ICSharpCode.NRefactory.CSharp @@ -42,12 +42,30 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class UndocumentedExpression : Expression
{
public readonly static TokenRole ArglistKeywordRole = new TokenRole ("__arglist");
public readonly static TokenRole RefvalueKeywordRole = new TokenRole ("__refvalue");
public readonly static TokenRole ReftypeKeywordRole = new TokenRole ("__reftype");
public readonly static TokenRole MakerefKeywordRole = new TokenRole ("__makeref");
public UndocumentedExpressionType UndocumentedExpressionType {
get; set;
}
public CSharpTokenNode UndocumentedToken {
get { return GetChildByRole (Roles.Keyword); }
get {
switch (UndocumentedExpressionType) {
case ICSharpCode.NRefactory.CSharp.UndocumentedExpressionType.ArgListAccess:
case ICSharpCode.NRefactory.CSharp.UndocumentedExpressionType.ArgList:
return GetChildByRole (ArglistKeywordRole);
case ICSharpCode.NRefactory.CSharp.UndocumentedExpressionType.RefValue:
return GetChildByRole (RefvalueKeywordRole);
case ICSharpCode.NRefactory.CSharp.UndocumentedExpressionType.RefType:
return GetChildByRole (ReftypeKeywordRole);
case ICSharpCode.NRefactory.CSharp.UndocumentedExpressionType.MakeRef:
return GetChildByRole (MakerefKeywordRole);
}
return CSharpTokenNode.Null;
}
}
public CSharpTokenNode LParToken {
@ -62,7 +80,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -62,7 +80,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RPar); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitUndocumentedExpression (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitUndocumentedExpression (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitUndocumentedExpression (this, data);
}

17
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Attribute.cs

@ -54,7 +54,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -54,7 +54,17 @@ namespace ICSharpCode.NRefactory.CSharp
set;
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitAttribute (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitAttribute (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitAttribute (this, data);
}
@ -69,9 +79,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -69,9 +79,8 @@ namespace ICSharpCode.NRefactory.CSharp
{
if (IsNull)
return "Null";
var w = new System.IO.StringWriter ();
AcceptVisitor (new CSharpOutputVisitor (w, new CSharpFormattingOptions ()), null);
return w.ToString ();
else
return GetText();
}
}
}

31
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/AttributeSection.cs

@ -54,7 +54,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -54,7 +54,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder (this, child);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder (this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
@ -71,9 +81,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -71,9 +81,6 @@ namespace ICSharpCode.NRefactory.CSharp
}
#endregion
public static readonly Role<Attribute> AttributeRole = new Role<Attribute>("Attribute");
public static readonly Role<CSharpTokenNode> TargetRole = new Role<CSharpTokenNode>("Target", CSharpTokenNode.Null);
public override NodeType NodeType {
get {
return NodeType.Unknown;
@ -89,7 +96,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -89,7 +96,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (value, TextLocation.Empty));
SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (value));
}
}
@ -103,14 +110,24 @@ namespace ICSharpCode.NRefactory.CSharp @@ -103,14 +110,24 @@ namespace ICSharpCode.NRefactory.CSharp
}
public AstNodeCollection<Attribute> Attributes {
get { return base.GetChildrenByRole (AttributeRole); }
get { return base.GetChildrenByRole (Roles.Attribute); }
}
public CSharpTokenNode RBracketToken {
get { return GetChildByRole (Roles.RBracket); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitAttributeSection (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitAttributeSection (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitAttributeSection (this, data);
}

43
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Comment.cs

@ -43,10 +43,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -43,10 +43,14 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>
/// Inactive code (code in non-taken "#if")
/// </summary>
InactiveCode
InactiveCode,
/// <summary>
/// "/** */" comment
/// </summary>
MultiLineDocumentation
}
public class Comment : AstNode, IRelocatable
public class Comment : AstNode
{
public override NodeType NodeType {
get {
@ -54,19 +58,25 @@ namespace ICSharpCode.NRefactory.CSharp @@ -54,19 +58,25 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
CommentType commentType;
public CommentType CommentType {
get;
set;
get { return commentType; }
set { ThrowIfFrozen(); commentType = value; }
}
bool startsLine;
public bool StartsLine {
get;
set;
get { return startsLine; }
set { ThrowIfFrozen(); startsLine = value; }
}
string content;
public string Content {
get;
set;
get { return content; }
set { ThrowIfFrozen(); content = value; }
}
TextLocation startLocation;
@ -96,16 +106,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -96,16 +106,17 @@ namespace ICSharpCode.NRefactory.CSharp
this.endLocation = endLocation;
}
#region IRelocationable implementation
void IRelocatable.SetStartLocation (TextLocation startLocation)
public override void AcceptVisitor (IAstVisitor visitor)
{
int lineDelta = startLocation.Line - this.startLocation.Line;
endLocation = new TextLocation (endLocation.Line + lineDelta, lineDelta != 0 ? endLocation.Column : endLocation.Column + startLocation.Column - this.startLocation.Column);
this.startLocation = startLocation;
visitor.VisitComment (this);
}
#endregion
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitComment (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitComment (this, data);
}

23
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Constraint.cs

@ -36,10 +36,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -36,10 +36,6 @@ namespace ICSharpCode.NRefactory.CSharp
/// </remarks>
public class Constraint : AstNode
{
public readonly static Role<CSharpTokenNode> ColonRole = TypeDeclaration.ColonRole;
public readonly static Role<AstType> BaseTypeRole = TypeDeclaration.BaseTypeRole;
public readonly static Role<SimpleType> TypeParameterRole = new Role<SimpleType> ("TypeParameter", SimpleType.Null);
public override NodeType NodeType {
get {
return NodeType.Unknown;
@ -48,18 +44,29 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,18 +44,29 @@ namespace ICSharpCode.NRefactory.CSharp
public SimpleType TypeParameter {
get {
return GetChildByRole (TypeParameterRole);
return GetChildByRole (Roles.ConstraintTypeParameter);
}
set {
SetChildByRole(TypeParameterRole, value);
SetChildByRole(Roles.ConstraintTypeParameter, value);
}
}
public AstNodeCollection<AstType> BaseTypes {
get { return GetChildrenByRole (BaseTypeRole); }
get {
return GetChildrenByRole(Roles.BaseType); }
}
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitConstraint (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitConstraint (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitConstraint (this, data);
}

50
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/DelegateDeclaration.cs

@ -24,45 +24,27 @@ @@ -24,45 +24,27 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// delegate ReturnType Name&lt;TypeParameters&gt;(Parameters) where Constraints;
/// </summary>
public class DelegateDeclaration : AttributedNode
public class DelegateDeclaration : EntityDeclaration
{
public override NodeType NodeType {
get {
return NodeType.TypeDeclaration;
}
get { return NodeType.TypeDeclaration; }
}
public AstType ReturnType {
get { return GetChildByRole (Roles.Type); }
set { SetChildByRole (Roles.Type, value); }
public override EntityType EntityType {
get { return EntityType.TypeDefinition; }
}
public string Name {
get {
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole (Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
}
public CSharpTokenNode DelegateToken {
get { return GetChildByRole(Roles.DelegateKeyword); }
}
public Identifier NameToken {
get {
return GetChildByRole (Roles.Identifier);
}
set {
SetChildByRole (Roles.Identifier, value);
}
}
public AstNodeCollection<TypeParameterDeclaration> TypeParameters {
get { return GetChildrenByRole (Roles.TypeParameter); }
}
@ -83,7 +65,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -83,7 +65,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildrenByRole (Roles.Constraint); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitDelegateDeclaration (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitDelegateDeclaration (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitDelegateDeclaration (this, data);
}
@ -91,8 +83,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -91,8 +83,8 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
DelegateDeclaration o = other as DelegateDeclaration;
return o != null && this.MatchAttributesAndModifiers(o, match)
&& this.ReturnType.DoMatch(o.ReturnType, match) && MatchString(this.Name, o.Name)
return o != null && MatchString(this.Name, o.Name)
&& this.MatchAttributesAndModifiers(o, match) && this.ReturnType.DoMatch(o.ReturnType, match)
&& this.TypeParameters.DoMatch(o.TypeParameters, match) && this.Parameters.DoMatch(o.Parameters, match)
&& this.Constraints.DoMatch(o.Constraints, match);
}

20
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/ExternAliasDeclaration.cs

@ -31,8 +31,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,6 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class ExternAliasDeclaration : AstNode
{
public static readonly Role<CSharpTokenNode> AliasRole = new Role<CSharpTokenNode> ("Alias", CSharpTokenNode.Null);
public override NodeType NodeType {
get {
return NodeType.Unknown;
@ -40,11 +38,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -40,11 +38,11 @@ namespace ICSharpCode.NRefactory.CSharp
}
public CSharpTokenNode ExternToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (Roles.ExternKeyword); }
}
public CSharpTokenNode AliasToken {
get { return GetChildByRole (AliasRole); }
get { return GetChildByRole (Roles.AliasKeyword); }
}
public string Name {
@ -52,7 +50,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,7 +50,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole (Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
SetChildByRole (Roles.Identifier, Identifier.Create (value));
}
}
@ -69,7 +67,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -69,7 +67,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Semicolon); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitExternAliasDeclaration (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitExternAliasDeclaration (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitExternAliasDeclaration (this, data);
}

18
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NamespaceDeclaration.cs

@ -43,6 +43,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -43,6 +43,10 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public CSharpTokenNode NamespaceToken {
get { return GetChildByRole (Roles.NamespaceKeyword); }
}
public string Name {
get {
StringBuilder builder = new StringBuilder ();
@ -54,7 +58,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -54,7 +58,7 @@ namespace ICSharpCode.NRefactory.CSharp
return builder.ToString ();
}
set {
GetChildrenByRole(Roles.Identifier).ReplaceWith(value.Split('.').Select(ident => Identifier.Create (ident, TextLocation.Empty)));
GetChildrenByRole(Roles.Identifier).ReplaceWith(value.Split('.').Select(ident => Identifier.Create (ident)));
}
}
@ -109,7 +113,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -109,7 +113,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (child, MemberRole);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitNamespaceDeclaration (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitNamespaceDeclaration (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitNamespaceDeclaration (this, data);
}

132
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NewLineNode.cs

@ -0,0 +1,132 @@ @@ -0,0 +1,132 @@
using System;
namespace ICSharpCode.NRefactory.CSharp
{
public enum NewLineType {
Unix,
Windows,
Mac
}
/// <summary>
/// A New line node represents a line break in the text.
/// </summary>
public abstract class NewLineNode : AstNode
{
public override NodeType NodeType {
get {
return NodeType.Whitespace;
}
}
public abstract NewLineType NewLineType {
get;
}
TextLocation startLocation;
public override TextLocation StartLocation {
get {
return startLocation;
}
}
public override TextLocation EndLocation {
get {
return new TextLocation (startLocation.Line + 1, 1);
}
}
public NewLineNode() : this (TextLocation.Empty)
{
}
public NewLineNode(TextLocation startLocation)
{
this.startLocation = startLocation;
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitNewLine (this);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitNewLine (this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitNewLine (this, data);
}
}
public class UnixNewLine : NewLineNode
{
public override NewLineType NewLineType {
get {
return NewLineType.Unix;
}
}
public UnixNewLine()
{
}
public UnixNewLine(TextLocation startLocation) : base (startLocation)
{
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
var o = other as UnixNewLine;
return o != null;
}
}
public class WindowsNewLine : NewLineNode
{
public override NewLineType NewLineType {
get {
return NewLineType.Windows;
}
}
public WindowsNewLine()
{
}
public WindowsNewLine(TextLocation startLocation) : base (startLocation)
{
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
var o = other as WindowsNewLine;
return o != null;
}
}
public class MacNewLine : NewLineNode
{
public override NewLineType NewLineType {
get {
return NewLineType.Mac;
}
}
public MacNewLine()
{
}
public MacNewLine(TextLocation startLocation) : base (startLocation)
{
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
var o = other as MacNewLine;
return o != null;
}
}
}

17
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/PreProcessorDirective.cs

@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp
Line = 12
}
public class PreProcessorDirective : AstNode, IRelocatable
public class PreProcessorDirective : AstNode
{
public override NodeType NodeType {
get {
@ -93,16 +93,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -93,16 +93,17 @@ namespace ICSharpCode.NRefactory.CSharp
this.endLocation = endLocation;
}
#region IRelocationable implementation
void IRelocatable.SetStartLocation (TextLocation startLocation)
public override void AcceptVisitor (IAstVisitor visitor)
{
int lineDelta = startLocation.Line - this.startLocation.Line;
endLocation = new TextLocation (endLocation.Line + lineDelta, lineDelta != 0 ? endLocation.Column : endLocation.Column + startLocation.Column - this.startLocation.Column);
this.startLocation = startLocation;
visitor.VisitPreProcessorDirective (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitPreProcessorDirective (this);
}
#endregion
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPreProcessorDirective (this, data);
}

94
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TextNode.cs

@ -0,0 +1,94 @@ @@ -0,0 +1,94 @@
//
// TextNode.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// A text node contains text without syntactic or semantic information.
/// (non parseable part of a text)
/// </summary>
public class TextNode : AstNode
{
public override NodeType NodeType {
get {
return NodeType.Whitespace;
}
}
public string Text {
get;
set;
}
TextLocation startLocation;
public override TextLocation StartLocation {
get {
return startLocation;
}
}
TextLocation endLocation;
public override TextLocation EndLocation {
get {
return endLocation;
}
}
public TextNode(string text) : this (text, TextLocation.Empty, TextLocation.Empty)
{
}
public TextNode(string text, TextLocation startLocation, TextLocation endLocation)
{
this.Text = text;
this.startLocation = startLocation;
this.endLocation = endLocation;
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitText (this);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitText (this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitText (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
var o = other as TextNode;
return o != null && o.Text == Text;
}
}
}

70
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TypeDeclaration.cs

@ -41,66 +41,78 @@ namespace ICSharpCode.NRefactory.CSharp @@ -41,66 +41,78 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>
/// class Name&lt;TypeParameters&gt; : BaseTypes where Constraints;
/// </summary>
public class TypeDeclaration : AttributedNode
public class TypeDeclaration : EntityDeclaration
{
public readonly static Role<CSharpTokenNode> ColonRole = Roles.Colon;
public readonly static Role<AstType> BaseTypeRole = new Role<AstType>("BaseType", AstType.Null);
public readonly static Role<AttributedNode> MemberRole = new Role<AttributedNode>("Member");
public override NodeType NodeType {
get {
return NodeType.TypeDeclaration;
}
get { return NodeType.TypeDeclaration; }
}
public ClassType ClassType {
get;
set;
public override EntityType EntityType {
get { return EntityType.TypeDefinition; }
}
public string Name {
ClassType classType;
public CSharpTokenNode TypeKeyword {
get {
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole (Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
switch (classType) {
case ClassType.Class:
return GetChildByRole(Roles.ClassKeyword);
case ClassType.Struct:
return GetChildByRole(Roles.StructKeyword);
case ClassType.Interface:
return GetChildByRole(Roles.InterfaceKeyword);
case ClassType.Enum:
return GetChildByRole(Roles.EnumKeyword);
default:
return CSharpTokenNode.Null;
}
}
}
public Identifier NameToken {
get {
return GetChildByRole (Roles.Identifier);
}
public ClassType ClassType {
get { return classType; }
set {
SetChildByRole (Roles.Identifier, value);
ThrowIfFrozen();
classType = value;
}
}
public AstNodeCollection<TypeParameterDeclaration> TypeParameters {
get { return GetChildrenByRole (Roles.TypeParameter); }
}
public AstNodeCollection<AstType> BaseTypes {
get { return GetChildrenByRole (BaseTypeRole); }
get { return GetChildrenByRole(Roles.BaseType); }
}
public AstNodeCollection<Constraint> Constraints {
get { return GetChildrenByRole (Roles.Constraint); }
get { return GetChildrenByRole(Roles.Constraint); }
}
public CSharpTokenNode LBraceToken {
get { return GetChildByRole (Roles.LBrace); }
}
public AstNodeCollection<AttributedNode> Members {
get { return GetChildrenByRole (MemberRole); }
public AstNodeCollection<EntityDeclaration> Members {
get { return GetChildrenByRole (Roles.TypeMemberRole); }
}
public CSharpTokenNode RBraceToken {
get { return GetChildByRole (Roles.RBrace); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitTypeDeclaration (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitTypeDeclaration (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitTypeDeclaration (this, data);
}
@ -108,8 +120,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -108,8 +120,8 @@ namespace ICSharpCode.NRefactory.CSharp
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
TypeDeclaration o = other as TypeDeclaration;
return o != null && this.ClassType == o.ClassType && this.MatchAttributesAndModifiers(o, match)
&& MatchString(this.Name, o.Name) && this.TypeParameters.DoMatch(o.TypeParameters, match)
return o != null && this.ClassType == o.ClassType && MatchString(this.Name, o.Name)
&& this.MatchAttributesAndModifiers(o, match) && this.TypeParameters.DoMatch(o.TypeParameters, match)
&& this.BaseTypes.DoMatch(o.BaseTypes, match) && this.Constraints.DoMatch(o.Constraints, match)
&& this.Members.DoMatch(o.Members, match);
}

46
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TypeParameterDeclaration.cs

@ -30,8 +30,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -30,8 +30,9 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class TypeParameterDeclaration : AstNode
{
public static readonly Role<AttributeSection> AttributeRole = AttributedNode.AttributeRole;
public static readonly Role<CSharpTokenNode> VarianceRole = new Role<CSharpTokenNode>("Variance", CSharpTokenNode.Null);
public static readonly Role<AttributeSection> AttributeRole = EntityDeclaration.AttributeRole;
public static readonly TokenRole OutVarianceKeywordRole = new TokenRole ("out");
public static readonly TokenRole InVarianceKeywordRole = new TokenRole ("in");
public override NodeType NodeType {
get { return NodeType.Unknown; }
@ -41,8 +42,24 @@ namespace ICSharpCode.NRefactory.CSharp @@ -41,8 +42,24 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildrenByRole (AttributeRole); }
}
VarianceModifier variance;
public VarianceModifier Variance {
get; set;
get { return variance; }
set { ThrowIfFrozen(); variance = value; }
}
public CSharpTokenNode VarianceToken {
get {
switch (Variance) {
case VarianceModifier.Covariant:
return GetChildByRole(OutVarianceKeywordRole);
case VarianceModifier.Contravariant:
return GetChildByRole(InVarianceKeywordRole);
default:
return CSharpTokenNode.Null;
}
}
}
public string Name {
@ -50,7 +67,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -50,7 +67,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole(Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
SetChildByRole(Roles.Identifier, Identifier.Create (value));
}
}
@ -62,8 +79,27 @@ namespace ICSharpCode.NRefactory.CSharp @@ -62,8 +79,27 @@ namespace ICSharpCode.NRefactory.CSharp
SetChildByRole (Roles.Identifier, value);
}
}
public TypeParameterDeclaration ()
{
}
public TypeParameterDeclaration (string name)
{
Name = name;
}
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitTypeParameterDeclaration (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitTypeParameterDeclaration (this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data = default(T))
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitTypeParameterDeclaration(this, data);
}

21
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/UsingAliasDeclaration.cs

@ -31,6 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,6 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class UsingAliasDeclaration : AstNode
{
public static readonly TokenRole UsingKeywordRole = new TokenRole ("using");
public static readonly Role<Identifier> AliasRole = new Role<Identifier>("Alias", Identifier.Null);
public static readonly Role<AstType> ImportRole = UsingDeclaration.ImportRole;
@ -41,7 +42,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -41,7 +42,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
public CSharpTokenNode UsingToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (UsingKeywordRole); }
}
public string Alias {
@ -49,7 +50,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -49,7 +50,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (AliasRole).Name;
}
set {
SetChildByRole(AliasRole, Identifier.Create (value, TextLocation.Empty));
SetChildByRole(AliasRole, Identifier.Create (value));
}
}
@ -72,17 +73,27 @@ namespace ICSharpCode.NRefactory.CSharp @@ -72,17 +73,27 @@ namespace ICSharpCode.NRefactory.CSharp
public UsingAliasDeclaration (string alias, string nameSpace)
{
AddChild (Identifier.Create (alias, TextLocation.Empty), AliasRole);
AddChild (Identifier.Create (alias), AliasRole);
AddChild (new SimpleType (nameSpace), ImportRole);
}
public UsingAliasDeclaration (string alias, AstType import)
{
AddChild (Identifier.Create (alias, TextLocation.Empty), AliasRole);
AddChild (Identifier.Create (alias), AliasRole);
AddChild (import, ImportRole);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitUsingAliasDeclaration (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitUsingAliasDeclaration (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitUsingAliasDeclaration (this, data);
}

15
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/UsingDeclaration.cs

@ -35,6 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -35,6 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class UsingDeclaration : AstNode
{
public static readonly TokenRole UsingKeywordRole = new TokenRole ("using");
public static readonly Role<AstType> ImportRole = new Role<AstType>("Import", AstType.Null);
public override NodeType NodeType {
@ -44,7 +45,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -44,7 +45,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
public CSharpTokenNode UsingToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (UsingKeywordRole); }
}
public AstType Import {
@ -74,7 +75,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -74,7 +75,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (import, ImportRole);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitUsingDeclaration (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitUsingDeclaration (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitUsingDeclaration (this, data);
}

91
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/WhitespaceNode.cs

@ -0,0 +1,91 @@ @@ -0,0 +1,91 @@
//
// WhitespaceNode.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// A Whitespace node contains only whitespaces.
/// </summary>
public class WhitespaceNode : AstNode
{
public override NodeType NodeType {
get {
return NodeType.Whitespace;
}
}
public string WhiteSpaceText {
get;
set;
}
TextLocation startLocation;
public override TextLocation StartLocation {
get {
return startLocation;
}
}
public override TextLocation EndLocation {
get {
return new TextLocation (startLocation.Line, startLocation.Column + WhiteSpaceText.Length);
}
}
public WhitespaceNode(string whiteSpaceText) : this (whiteSpaceText, TextLocation.Empty)
{
}
public WhitespaceNode(string whiteSpaceText, TextLocation startLocation)
{
this.WhiteSpaceText = WhiteSpaceText;
this.startLocation = startLocation;
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitWhitespace (this);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitWhitespace (this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitWhitespace (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
var o = other as WhitespaceNode;
return o != null && o.WhiteSpaceText == WhiteSpaceText;
}
}
}

266
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/IAstVisitor.cs

@ -20,6 +20,268 @@ using System; @@ -20,6 +20,268 @@ using System;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// AST visitor.
/// </summary>
public interface IAstVisitor
{
void VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression);
void VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression);
void VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression);
void VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression);
void VisitAsExpression(AsExpression asExpression);
void VisitAssignmentExpression(AssignmentExpression assignmentExpression);
void VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression);
void VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression);
void VisitCastExpression(CastExpression castExpression);
void VisitCheckedExpression(CheckedExpression checkedExpression);
void VisitConditionalExpression(ConditionalExpression conditionalExpression);
void VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression);
void VisitDirectionExpression(DirectionExpression directionExpression);
void VisitIdentifierExpression(IdentifierExpression identifierExpression);
void VisitIndexerExpression(IndexerExpression indexerExpression);
void VisitInvocationExpression(InvocationExpression invocationExpression);
void VisitIsExpression(IsExpression isExpression);
void VisitLambdaExpression(LambdaExpression lambdaExpression);
void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression);
void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression);
void VisitNamedExpression(NamedExpression namedExpression);
void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression);
void VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression);
void VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression);
void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression);
void VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression);
void VisitPrimitiveExpression(PrimitiveExpression primitiveExpression);
void VisitSizeOfExpression(SizeOfExpression sizeOfExpression);
void VisitStackAllocExpression(StackAllocExpression stackAllocExpression);
void VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression);
void VisitTypeOfExpression(TypeOfExpression typeOfExpression);
void VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression);
void VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression);
void VisitUncheckedExpression(UncheckedExpression uncheckedExpression);
void VisitEmptyExpression (EmptyExpression emptyExpression);
void VisitQueryExpression(QueryExpression queryExpression);
void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause);
void VisitQueryFromClause(QueryFromClause queryFromClause);
void VisitQueryLetClause(QueryLetClause queryLetClause);
void VisitQueryWhereClause(QueryWhereClause queryWhereClause);
void VisitQueryJoinClause(QueryJoinClause queryJoinClause);
void VisitQueryOrderClause(QueryOrderClause queryOrderClause);
void VisitQueryOrdering(QueryOrdering queryOrdering);
void VisitQuerySelectClause(QuerySelectClause querySelectClause);
void VisitQueryGroupClause(QueryGroupClause queryGroupClause);
void VisitAttribute(Attribute attribute);
void VisitAttributeSection(AttributeSection attributeSection);
void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration);
void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration);
void VisitTypeDeclaration(TypeDeclaration typeDeclaration);
void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration);
void VisitUsingDeclaration(UsingDeclaration usingDeclaration);
void VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration);
void VisitBlockStatement(BlockStatement blockStatement);
void VisitBreakStatement(BreakStatement breakStatement);
void VisitCheckedStatement(CheckedStatement checkedStatement);
void VisitContinueStatement(ContinueStatement continueStatement);
void VisitDoWhileStatement(DoWhileStatement doWhileStatement);
void VisitEmptyStatement(EmptyStatement emptyStatement);
void VisitExpressionStatement(ExpressionStatement expressionStatement);
void VisitFixedStatement(FixedStatement fixedStatement);
void VisitForeachStatement(ForeachStatement foreachStatement);
void VisitForStatement(ForStatement forStatement);
void VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement);
void VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement);
void VisitGotoStatement(GotoStatement gotoStatement);
void VisitIfElseStatement(IfElseStatement ifElseStatement);
void VisitLabelStatement(LabelStatement labelStatement);
void VisitLockStatement(LockStatement lockStatement);
void VisitReturnStatement(ReturnStatement returnStatement);
void VisitSwitchStatement(SwitchStatement switchStatement);
void VisitSwitchSection(SwitchSection switchSection);
void VisitCaseLabel(CaseLabel caseLabel);
void VisitThrowStatement(ThrowStatement throwStatement);
void VisitTryCatchStatement(TryCatchStatement tryCatchStatement);
void VisitCatchClause(CatchClause catchClause);
void VisitUncheckedStatement(UncheckedStatement uncheckedStatement);
void VisitUnsafeStatement(UnsafeStatement unsafeStatement);
void VisitUsingStatement(UsingStatement usingStatement);
void VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement);
void VisitWhileStatement(WhileStatement whileStatement);
void VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement);
void VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement);
void VisitAccessor(Accessor accessor);
void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration);
void VisitConstructorInitializer(ConstructorInitializer constructorInitializer);
void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration);
void VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration);
void VisitEventDeclaration(EventDeclaration eventDeclaration);
void VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration);
void VisitFieldDeclaration(FieldDeclaration fieldDeclaration);
void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration);
void VisitMethodDeclaration(MethodDeclaration methodDeclaration);
void VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration);
void VisitParameterDeclaration(ParameterDeclaration parameterDeclaration);
void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration);
void VisitVariableInitializer(VariableInitializer variableInitializer);
void VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration);
void VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer);
void VisitCompilationUnit(CompilationUnit compilationUnit);
void VisitSimpleType(SimpleType simpleType);
void VisitMemberType(MemberType memberType);
void VisitComposedType(ComposedType composedType);
void VisitArraySpecifier(ArraySpecifier arraySpecifier);
void VisitPrimitiveType(PrimitiveType primitiveType);
void VisitComment(Comment comment);
void VisitNewLine(NewLineNode newLineNode);
void VisitWhitespace(WhitespaceNode whitespaceNode);
void VisitText(TextNode textNode);
void VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective);
void VisitDocumentationReference(DocumentationReference documentationReference);
void VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration);
void VisitConstraint(Constraint constraint);
void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode);
void VisitIdentifier(Identifier identifier);
void VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern);
}
/// <summary>
/// AST visitor.
/// </summary>
public interface IAstVisitor<out S>
{
S VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression);
S VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression);
S VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression);
S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression);
S VisitAsExpression(AsExpression asExpression);
S VisitAssignmentExpression(AssignmentExpression assignmentExpression);
S VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression);
S VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression);
S VisitCastExpression(CastExpression castExpression);
S VisitCheckedExpression(CheckedExpression checkedExpression);
S VisitConditionalExpression(ConditionalExpression conditionalExpression);
S VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression);
S VisitDirectionExpression(DirectionExpression directionExpression);
S VisitIdentifierExpression(IdentifierExpression identifierExpression);
S VisitIndexerExpression(IndexerExpression indexerExpression);
S VisitInvocationExpression(InvocationExpression invocationExpression);
S VisitIsExpression(IsExpression isExpression);
S VisitLambdaExpression(LambdaExpression lambdaExpression);
S VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression);
S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression);
S VisitNamedExpression(NamedExpression namedExpression);
S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression);
S VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression);
S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression);
S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression);
S VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression);
S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression);
S VisitSizeOfExpression(SizeOfExpression sizeOfExpression);
S VisitStackAllocExpression(StackAllocExpression stackAllocExpression);
S VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression);
S VisitTypeOfExpression(TypeOfExpression typeOfExpression);
S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression);
S VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression);
S VisitUncheckedExpression(UncheckedExpression uncheckedExpression);
S VisitEmptyExpression (EmptyExpression emptyExpression);
S VisitQueryExpression(QueryExpression queryExpression);
S VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause);
S VisitQueryFromClause(QueryFromClause queryFromClause);
S VisitQueryLetClause(QueryLetClause queryLetClause);
S VisitQueryWhereClause(QueryWhereClause queryWhereClause);
S VisitQueryJoinClause(QueryJoinClause queryJoinClause);
S VisitQueryOrderClause(QueryOrderClause queryOrderClause);
S VisitQueryOrdering(QueryOrdering queryOrdering);
S VisitQuerySelectClause(QuerySelectClause querySelectClause);
S VisitQueryGroupClause(QueryGroupClause queryGroupClause);
S VisitAttribute(Attribute attribute);
S VisitAttributeSection(AttributeSection attributeSection);
S VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration);
S VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration);
S VisitTypeDeclaration(TypeDeclaration typeDeclaration);
S VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration);
S VisitUsingDeclaration(UsingDeclaration usingDeclaration);
S VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration);
S VisitBlockStatement(BlockStatement blockStatement);
S VisitBreakStatement(BreakStatement breakStatement);
S VisitCheckedStatement(CheckedStatement checkedStatement);
S VisitContinueStatement(ContinueStatement continueStatement);
S VisitDoWhileStatement(DoWhileStatement doWhileStatement);
S VisitEmptyStatement(EmptyStatement emptyStatement);
S VisitExpressionStatement(ExpressionStatement expressionStatement);
S VisitFixedStatement(FixedStatement fixedStatement);
S VisitForeachStatement(ForeachStatement foreachStatement);
S VisitForStatement(ForStatement forStatement);
S VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement);
S VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement);
S VisitGotoStatement(GotoStatement gotoStatement);
S VisitIfElseStatement(IfElseStatement ifElseStatement);
S VisitLabelStatement(LabelStatement labelStatement);
S VisitLockStatement(LockStatement lockStatement);
S VisitReturnStatement(ReturnStatement returnStatement);
S VisitSwitchStatement(SwitchStatement switchStatement);
S VisitSwitchSection(SwitchSection switchSection);
S VisitCaseLabel(CaseLabel caseLabel);
S VisitThrowStatement(ThrowStatement throwStatement);
S VisitTryCatchStatement(TryCatchStatement tryCatchStatement);
S VisitCatchClause(CatchClause catchClause);
S VisitUncheckedStatement(UncheckedStatement uncheckedStatement);
S VisitUnsafeStatement(UnsafeStatement unsafeStatement);
S VisitUsingStatement(UsingStatement usingStatement);
S VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement);
S VisitWhileStatement(WhileStatement whileStatement);
S VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement);
S VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement);
S VisitAccessor(Accessor accessor);
S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration);
S VisitConstructorInitializer(ConstructorInitializer constructorInitializer);
S VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration);
S VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration);
S VisitEventDeclaration(EventDeclaration eventDeclaration);
S VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration);
S VisitFieldDeclaration(FieldDeclaration fieldDeclaration);
S VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration);
S VisitMethodDeclaration(MethodDeclaration methodDeclaration);
S VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration);
S VisitParameterDeclaration(ParameterDeclaration parameterDeclaration);
S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration);
S VisitVariableInitializer(VariableInitializer variableInitializer);
S VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration);
S VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer);
S VisitCompilationUnit(CompilationUnit compilationUnit);
S VisitSimpleType(SimpleType simpleType);
S VisitMemberType(MemberType memberType);
S VisitComposedType(ComposedType composedType);
S VisitArraySpecifier(ArraySpecifier arraySpecifier);
S VisitPrimitiveType(PrimitiveType primitiveType);
S VisitComment(Comment comment);
S VisitWhitespace(WhitespaceNode whitespaceNode);
S VisitText(TextNode textNode);
S VisitNewLine(NewLineNode newLineNode);
S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective);
S VisitDocumentationReference(DocumentationReference documentationReference);
S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration);
S VisitConstraint(Constraint constraint);
S VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode);
S VisitIdentifier(Identifier identifier);
S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern);
}
/// <summary>
/// AST visitor.
/// </summary>
@ -137,7 +399,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -137,7 +399,11 @@ namespace ICSharpCode.NRefactory.CSharp
S VisitPrimitiveType(PrimitiveType primitiveType, T data);
S VisitComment(Comment comment, T data);
S VisitNewLine(NewLineNode newLineNode, T data);
S VisitWhitespace(WhitespaceNode whitespaceNode, T data);
S VisitText(TextNode textNode, T data);
S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective, T data);
S VisitDocumentationReference(DocumentationReference documentationReference, T data);
S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, T data);
S VisitConstraint(Constraint constraint, T data);

78
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Identifier.cs

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
//
// Identifier.cs
//
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
@ -28,7 +28,7 @@ using System; @@ -28,7 +28,7 @@ using System;
namespace ICSharpCode.NRefactory.CSharp
{
public class Identifier : AstNode, IRelocatable
public class Identifier : AstNode
{
public new static readonly Identifier Null = new NullIdentifier ();
sealed class NullIdentifier : Identifier
@ -39,7 +39,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -39,7 +39,16 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return default (T);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return default (S);
}
@ -59,9 +68,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -59,9 +68,10 @@ namespace ICSharpCode.NRefactory.CSharp
string name;
public string Name {
get { return this.name; }
set {
set {
if (value == null)
throw new ArgumentNullException("value");
ThrowIfFrozen();
this.name = value;
}
}
@ -71,25 +81,26 @@ namespace ICSharpCode.NRefactory.CSharp @@ -71,25 +81,26 @@ namespace ICSharpCode.NRefactory.CSharp
get {
return startLocation;
}
}
public virtual bool IsVerbatim {
const uint verbatimBit = 1u << AstNodeFlagsUsedBits;
public bool IsVerbatim {
get {
return false;
return (flags & verbatimBit) != 0;
}
set {
ThrowIfFrozen();
if (value)
flags |= verbatimBit;
else
flags &= ~verbatimBit;
}
}
#region IRelocationable implementation
void IRelocatable.SetStartLocation (TextLocation startLocation)
{
this.startLocation = startLocation;
}
#endregion
public override TextLocation EndLocation {
get {
return new TextLocation (StartLocation.Line, StartLocation.Column + (Name ?? "").Length);
return new TextLocation (StartLocation.Line, StartLocation.Column + (Name ?? "").Length + (IsVerbatim ? 1 : 0));
}
}
@ -116,22 +127,32 @@ namespace ICSharpCode.NRefactory.CSharp @@ -116,22 +127,32 @@ namespace ICSharpCode.NRefactory.CSharp
if (string.IsNullOrEmpty(name))
return Identifier.Null;
if (name[0] == '@')
return new VerbatimIdentifier(name.Substring (1), location);
return new Identifier (name.Substring (1), location) { IsVerbatim = true };
else
return new Identifier (name, location);
}
public static Identifier Create (string name, TextLocation location, bool isVerbatim)
{
if (string.IsNullOrEmpty(name))
if (string.IsNullOrEmpty (name))
return Identifier.Null;
if (isVerbatim)
return new VerbatimIdentifier(name, location);
return new Identifier (name, location) { IsVerbatim = true };
return new Identifier (name, location);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitIdentifier (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitIdentifier (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitIdentifier (this, data);
}
@ -141,24 +162,5 @@ namespace ICSharpCode.NRefactory.CSharp @@ -141,24 +162,5 @@ namespace ICSharpCode.NRefactory.CSharp
Identifier o = other as Identifier;
return o != null && !o.IsNull && MatchString(this.Name, o.Name);
}
class VerbatimIdentifier : Identifier
{
public override TextLocation EndLocation {
get {
return new TextLocation (StartLocation.Line, StartLocation.Column + (Name ?? "").Length + 1); // @"..."
}
}
public override bool IsVerbatim {
get {
return true;
}
}
public VerbatimIdentifier(string name, TextLocation location) : base (name, location)
{
}
}
}
}

2
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/IdentifierExpressionBackreference.cs

@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.CSharp
CSharp.AstNode referenced = (CSharp.AstNode)match.Get(referencedGroupName).Last();
if (referenced == null)
return false;
return ident.Identifier == referenced.GetChildByRole(CSharp.AstNode.Roles.Identifier).Name;
return ident.Identifier == referenced.GetChildByRole(CSharp.Roles.Identifier).Name;
}
}
}

24
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/MemberType.cs

@ -37,7 +37,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -37,7 +37,15 @@ namespace ICSharpCode.NRefactory.CSharp
{
public static readonly Role<AstType> TargetRole = new Role<AstType>("Target", AstType.Null);
public bool IsDoubleColon { get; set; }
bool isDoubleColon;
public bool IsDoubleColon {
get { return isDoubleColon; }
set {
ThrowIfFrozen();
isDoubleColon = value;
}
}
public AstType Target {
get { return GetChildByRole(TargetRole); }
@ -49,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -49,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole (Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
SetChildByRole (Roles.Identifier, Identifier.Create (value));
}
}
@ -89,7 +97,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -89,7 +97,17 @@ namespace ICSharpCode.NRefactory.CSharp
{
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitMemberType (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitMemberType (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitMemberType (this, data);
}

43
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/ObservableAstVisitor.cs

@ -60,9 +60,38 @@ namespace ICSharpCode.NRefactory.CSharp @@ -60,9 +60,38 @@ namespace ICSharpCode.NRefactory.CSharp
handler (comment, data);
return VisitChildren (comment, data);
}
public event Action<PreProcessorDirective, T> PreProcessorDirectiveVisited;
public event Action<NewLineNode, T> NewLineVisited;
S IAstVisitor<T, S>.VisitNewLine(NewLineNode newLineNode, T data)
{
var handler = NewLineVisited;
if (handler != null)
handler(newLineNode, data);
return VisitChildren(newLineNode, data);
}
public event Action<WhitespaceNode, T> WhitespaceVisited;
S IAstVisitor<T, S>.VisitWhitespace(WhitespaceNode whitespace, T data)
{
var handler = WhitespaceVisited;
if (handler != null)
handler(whitespace, data);
return VisitChildren(whitespace, data);
}
public event Action<TextNode, T> TextVisited;
S IAstVisitor<T, S>.VisitText(TextNode textNode, T data)
{
var handler = TextVisited;
if (handler != null)
handler(textNode, data);
return VisitChildren(textNode, data);
}
public event Action<PreProcessorDirective, T> PreProcessorDirectiveVisited;
S IAstVisitor<T, S>.VisitPreProcessorDirective (PreProcessorDirective preProcessorDirective, T data)
{
var handler = PreProcessorDirectiveVisited;
@ -71,6 +100,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -71,6 +100,16 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (preProcessorDirective, data);
}
public event Action<DocumentationReference, T> DocumentationReferenceVisited;
S IAstVisitor<T, S>.VisitDocumentationReference (DocumentationReference documentationReference, T data)
{
var handler = DocumentationReferenceVisited;
if (handler != null)
handler (documentationReference, data);
return VisitChildren (documentationReference, data);
}
public event Action<Identifier, T> IdentifierVisited;
S IAstVisitor<T, S>.VisitIdentifier (Identifier identifier, T data)

38
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/PrimitiveType.cs

@ -32,10 +32,20 @@ using ICSharpCode.NRefactory.TypeSystem.Implementation; @@ -32,10 +32,20 @@ using ICSharpCode.NRefactory.TypeSystem.Implementation;
namespace ICSharpCode.NRefactory.CSharp
{
public class PrimitiveType : AstType, IRelocatable
public class PrimitiveType : AstType
{
public string Keyword { get; set; }
public TextLocation Location { get; set; }
TextLocation location;
string keyword = string.Empty;
public string Keyword {
get { return keyword; }
set {
if (value == null)
throw new ArgumentNullException();
ThrowIfFrozen();
keyword = value;
}
}
public KnownTypeCode KnownTypeCode {
get { return GetTypeCodeForPrimitiveType(this.Keyword); }
@ -53,29 +63,31 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,29 +63,31 @@ namespace ICSharpCode.NRefactory.CSharp
public PrimitiveType(string keyword, TextLocation location)
{
this.Keyword = keyword;
this.Location = location;
this.location = location;
}
public override TextLocation StartLocation {
get {
return Location;
return location;
}
}
public override TextLocation EndLocation {
get {
return new TextLocation (Location.Line, Location.Column + (Keyword != null ? Keyword.Length : 0));
return new TextLocation (location.Line, location.Column + keyword.Length);
}
}
#region IRelocationable implementation
void IRelocatable.SetStartLocation (TextLocation startLocation)
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitPrimitiveType (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
this.Location = startLocation;
return visitor.VisitPrimitiveType (this);
}
#endregion
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPrimitiveType (this, data);
}
@ -88,7 +100,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -88,7 +100,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override string ToString()
{
return Keyword ?? base.ToString();
return Keyword;
}
public override ITypeReference ToTypeReference(SimpleNameLookupMode lookupMode = SimpleNameLookupMode.Type)

96
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Roles.cs

@ -0,0 +1,96 @@ @@ -0,0 +1,96 @@
//
// Roles.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin <http://xamarin.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp
{
public static class Roles
{
public static readonly Role<AstNode> Root = AstNode.RootRole;
// some pre defined constants for common roles
public static readonly Role<Identifier> Identifier = new Role<Identifier> ("Identifier", CSharp.Identifier.Null);
public static readonly Role<BlockStatement> Body = new Role<BlockStatement> ("Body", CSharp.BlockStatement.Null);
public static readonly Role<ParameterDeclaration> Parameter = new Role<ParameterDeclaration> ("Parameter");
public static readonly Role<Expression> Argument = new Role<Expression> ("Argument", CSharp.Expression.Null);
public static readonly Role<AstType> Type = new Role<AstType> ("Type", CSharp.AstType.Null);
public static readonly Role<Expression> Expression = new Role<Expression> ("Expression", CSharp.Expression.Null);
public static readonly Role<Expression> TargetExpression = new Role<Expression> ("Target", CSharp.Expression.Null);
public readonly static Role<Expression> Condition = new Role<Expression> ("Condition", CSharp.Expression.Null);
public static readonly Role<TypeParameterDeclaration> TypeParameter = new Role<TypeParameterDeclaration> ("TypeParameter");
public static readonly Role<AstType> TypeArgument = new Role<AstType> ("TypeArgument", CSharp.AstType.Null);
public readonly static Role<Constraint> Constraint = new Role<Constraint> ("Constraint");
public static readonly Role<VariableInitializer> Variable = new Role<VariableInitializer> ("Variable", VariableInitializer.Null);
public static readonly Role<Statement> EmbeddedStatement = new Role<Statement> ("EmbeddedStatement", CSharp.Statement.Null);
public readonly static Role<EntityDeclaration> TypeMemberRole = new Role<EntityDeclaration> ("TypeMember");
// public static readonly TokenRole Keyword = new TokenRole ("Keyword", CSharpTokenNode.Null);
// public static readonly TokenRole InKeyword = new TokenRole ("InKeyword", CSharpTokenNode.Null);
// some pre defined constants for most used punctuation
public static readonly TokenRole LPar = new TokenRole ("(");
public static readonly TokenRole RPar = new TokenRole (")");
public static readonly TokenRole LBracket = new TokenRole ("[");
public static readonly TokenRole RBracket = new TokenRole ("]");
public static readonly TokenRole LBrace = new TokenRole ("{");
public static readonly TokenRole RBrace = new TokenRole ("}");
public static readonly TokenRole LChevron = new TokenRole ("<");
public static readonly TokenRole RChevron = new TokenRole (">");
public static readonly TokenRole Comma = new TokenRole (",");
public static readonly TokenRole Dot = new TokenRole (".");
public static readonly TokenRole Semicolon = new TokenRole (";");
public static readonly TokenRole Assign = new TokenRole ("=");
public static readonly TokenRole Colon = new TokenRole (":");
public static readonly TokenRole DoubleColon = new TokenRole ("::");
public static readonly Role<Comment> Comment = new Role<Comment> ("Comment");
public static readonly Role<NewLineNode> NewLine = new Role<NewLineNode> ("NewLine");
public static readonly Role<WhitespaceNode> Whitespace = new Role<WhitespaceNode> ("Whitespace");
public static readonly Role<TextNode> Text = new Role<TextNode> ("Text");
public static readonly Role<PreProcessorDirective> PreProcessorDirective = new Role<PreProcessorDirective> ("PreProcessorDirective");
public static readonly Role<ErrorNode> Error = new Role<ErrorNode> ("Error");
public readonly static Role<AstType> BaseType = new Role<AstType> ("BaseType", AstType.Null);
public static readonly Role<Attribute> Attribute = new Role<Attribute> ("Attribute");
public static readonly Role<CSharpTokenNode> AttributeTargetRole = new Role<CSharpTokenNode> ("AttributeTarget", CSharpTokenNode.Null);
public readonly static TokenRole WhereKeyword = new TokenRole ("where");
public readonly static Role<SimpleType> ConstraintTypeParameter = new Role<SimpleType> ("TypeParameter", SimpleType.Null);
public readonly static TokenRole DelegateKeyword = new TokenRole ("delegate");
public static readonly TokenRole ExternKeyword = new TokenRole ("extern");
public static readonly TokenRole AliasKeyword = new TokenRole ("alias");
public static readonly TokenRole NamespaceKeyword = new TokenRole ("namespace");
public static readonly TokenRole EnumKeyword = new TokenRole ("enum");
public static readonly TokenRole InterfaceKeyword = new TokenRole ("interface");
public static readonly TokenRole StructKeyword = new TokenRole ("struct");
public static readonly TokenRole ClassKeyword = new TokenRole ("class");
}
}

25
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/SimpleType.cs

@ -47,7 +47,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -47,7 +47,16 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return default (T);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return default (S);
}
@ -100,7 +109,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -100,7 +109,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (value, TextLocation.Empty));
SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (value));
}
}
@ -117,7 +126,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -117,7 +126,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildrenByRole (Roles.TypeArgument); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitSimpleType (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitSimpleType (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitSimpleType (this, data);
}

35
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/BlockStatement.cs

@ -45,7 +45,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -45,7 +45,16 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return default (T);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return default (S);
}
@ -76,7 +85,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -76,7 +85,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
@ -105,7 +124,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -105,7 +124,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RBrace); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitBlockStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitBlockStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitBlockStatement (this, data);
}

18
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/BreakStatement.cs

@ -31,11 +31,27 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,11 +31,27 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class BreakStatement : Statement
{
public static readonly TokenRole BreakKeywordRole = new TokenRole ("break");
public CSharpTokenNode BreakToken {
get { return GetChildByRole (BreakKeywordRole); }
}
public CSharpTokenNode SemicolonToken {
get { return GetChildByRole (Roles.Semicolon); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitBreakStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitBreakStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitBreakStatement (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/CheckedStatement.cs

@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class CheckedStatement : Statement
{
public static readonly TokenRole CheckedKeywordRole = new TokenRole ("checked");
public CSharpTokenNode CheckedToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (CheckedKeywordRole); }
}
public BlockStatement Body {
@ -49,7 +51,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -49,7 +51,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (body, Roles.Body);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitCheckedStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitCheckedStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitCheckedStatement (this, data);
}

18
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/ContinueStatement.cs

@ -31,11 +31,27 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,11 +31,27 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class ContinueStatement : Statement
{
public static readonly TokenRole ContinueKeywordRole = new TokenRole ("continue");
public CSharpTokenNode ContinueToken {
get { return GetChildByRole (ContinueKeywordRole); }
}
public CSharpTokenNode SemicolonToken {
get { return GetChildByRole (Roles.Semicolon); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitContinueStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitContinueStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitContinueStatement (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/DoWhileStatement.cs

@ -31,8 +31,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,8 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class DoWhileStatement : Statement
{
public static readonly Role<CSharpTokenNode> DoKeywordRole = new Role<CSharpTokenNode>("DoKeyword", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> WhileKeywordRole = new Role<CSharpTokenNode>("WhileKeyword", CSharpTokenNode.Null);
public static readonly TokenRole DoKeywordRole = new TokenRole ("do");
public static readonly TokenRole WhileKeywordRole = new TokenRole ("while");
public CSharpTokenNode DoToken {
get { return GetChildByRole (DoKeywordRole); }
@ -64,7 +64,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -64,7 +64,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Semicolon); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitDoWhileStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitDoWhileStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitDoWhileStatement (this, data);
}

15
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/EmptyStatement.cs

@ -29,7 +29,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -29,7 +29,7 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>
/// ;
/// </summary>
public class EmptyStatement : Statement, IRelocatable
public class EmptyStatement : Statement
{
public TextLocation Location {
get;
@ -48,14 +48,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,14 +48,17 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
#region IRelocationable implementation
void IRelocatable.SetStartLocation (TextLocation startLocation)
public override void AcceptVisitor (IAstVisitor visitor)
{
this.Location = startLocation;
visitor.VisitEmptyStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitEmptyStatement (this);
}
#endregion
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitEmptyStatement (this, data);
}

12
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/ExpressionStatement.cs

@ -40,7 +40,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -40,7 +40,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Semicolon); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitExpressionStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitExpressionStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitExpressionStatement (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/FixedStatement.cs

@ -33,8 +33,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -33,8 +33,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class FixedStatement : Statement
{
public static readonly TokenRole FixedKeywordRole = new TokenRole ("fixed");
public CSharpTokenNode FixedToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (FixedKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -59,7 +61,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -59,7 +61,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.EmbeddedStatement, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitFixedStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitFixedStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitFixedStatement (this, data);
}

15
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/ForStatement.cs

@ -33,11 +33,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -33,11 +33,12 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class ForStatement : Statement
{
public static readonly TokenRole ForKeywordRole = new TokenRole ("for");
public readonly static Role<Statement> InitializerRole = new Role<Statement>("Initializer", Statement.Null);
public readonly static Role<Statement> IteratorRole = new Role<Statement>("Iterator", Statement.Null);
public CSharpTokenNode ForToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (ForKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -71,7 +72,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -71,7 +72,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.EmbeddedStatement, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitForStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitForStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitForStatement (this, data);
}

21
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/ForeachStatement.cs

@ -31,8 +31,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,11 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class ForeachStatement : Statement
{
public static readonly TokenRole ForeachKeywordRole = new TokenRole ("foreach");
public static readonly TokenRole InKeywordRole = new TokenRole ("in");
public CSharpTokenNode ForeachToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (ForeachKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -49,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -49,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole(Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
SetChildByRole(Roles.Identifier, Identifier.Create (value));
}
}
@ -63,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -63,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
public CSharpTokenNode InToken {
get { return GetChildByRole (Roles.InKeyword); }
get { return GetChildByRole (InKeywordRole); }
}
public Expression InExpression {
@ -80,7 +83,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -80,7 +83,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.EmbeddedStatement, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitForeachStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitForeachStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitForeachStatement (this, data);
}

52
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/GotoStatement.cs

@ -31,6 +31,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,6 +31,8 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class GotoStatement : Statement
{
public static readonly TokenRole GotoKeywordRole = new TokenRole ("goto");
public GotoStatement ()
{
}
@ -41,7 +43,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -41,7 +43,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
public CSharpTokenNode GotoToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (GotoKeywordRole); }
}
public string Label {
@ -52,7 +54,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,7 +54,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (string.IsNullOrEmpty(value))
SetChildByRole(Roles.Identifier, null);
else
SetChildByRole(Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
SetChildByRole(Roles.Identifier, Identifier.Create (value));
}
}
@ -60,7 +62,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -60,7 +62,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Semicolon); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitGotoStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitGotoStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitGotoStatement (this, data);
}
@ -77,10 +89,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -77,10 +89,11 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class GotoCaseStatement : Statement
{
public static readonly Role<CSharpTokenNode> CaseKeywordRole = new Role<CSharpTokenNode>("CaseKeyword", CSharpTokenNode.Null);
public static readonly TokenRole GotoKeywordRole = new TokenRole ("goto");
public static readonly TokenRole CaseKeywordRole = new TokenRole ("case");
public CSharpTokenNode GotoToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (GotoKeywordRole); }
}
public CSharpTokenNode CaseToken {
@ -99,7 +112,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -99,7 +112,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Semicolon); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitGotoCaseStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitGotoCaseStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitGotoCaseStatement (this, data);
}
@ -116,10 +139,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -116,10 +139,11 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class GotoDefaultStatement : Statement
{
public static readonly Role<CSharpTokenNode> DefaultKeywordRole = new Role<CSharpTokenNode>("DefaultKeyword", CSharpTokenNode.Null);
public static readonly TokenRole GotoKeywordRole = new TokenRole ("goto");
public static readonly TokenRole DefaultKeywordRole = new TokenRole ("default");
public CSharpTokenNode GotoToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (GotoKeywordRole); }
}
public CSharpTokenNode DefaultToken {
@ -130,7 +154,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -130,7 +154,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Semicolon); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitGotoDefaultStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitGotoDefaultStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitGotoDefaultStatement (this, data);
}

17
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/IfElseStatement.cs

@ -31,11 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,11 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class IfElseStatement : Statement
{
public readonly static Role<CSharpTokenNode> IfKeywordRole = Roles.Keyword;
public readonly static TokenRole IfKeywordRole = new TokenRole ("if");
public readonly static Role<Expression> ConditionRole = Roles.Condition;
public readonly static Role<CSharpTokenNode> QuestionMarkRole = new Role<CSharpTokenNode>("QuestionMark", CSharpTokenNode.Null);
public readonly static Role<Statement> TrueRole = new Role<Statement>("True", Statement.Null);
public readonly static Role<CSharpTokenNode> ElseKeywordRole = new Role<CSharpTokenNode>("ElseKeyword", CSharpTokenNode.Null);
public readonly static TokenRole ElseKeywordRole = new TokenRole ("else");
public readonly static Role<Statement> FalseRole = new Role<Statement>("False", Statement.Null);
public CSharpTokenNode IfToken {
@ -69,7 +68,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -69,7 +68,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (FalseRole, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitIfElseStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitIfElseStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitIfElseStatement (this, data);
}

19
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/LabelStatement.cs

@ -36,15 +36,30 @@ namespace ICSharpCode.NRefactory.CSharp @@ -36,15 +36,30 @@ namespace ICSharpCode.NRefactory.CSharp
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole(Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
SetChildByRole(Roles.Identifier, Identifier.Create (value));
}
}
public Identifier LabelToken {
get { return GetChildByRole (Roles.Identifier); }
set { SetChildByRole (Roles.Identifier, value); }
}
public CSharpTokenNode Colon {
get { return GetChildByRole (Roles.Colon); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitLabelStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitLabelStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitLabelStatement (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/LockStatement.cs

@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class LockStatement : Statement
{
public static readonly TokenRole LockKeywordRole = new TokenRole ("lock");
public CSharpTokenNode LockToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (LockKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -53,7 +55,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,7 +55,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.EmbeddedStatement, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitLockStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitLockStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitLockStatement (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/ReturnStatement.cs

@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class ReturnStatement : Statement
{
public static readonly TokenRole ReturnKeywordRole = new TokenRole ("return");
public CSharpTokenNode ReturnToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (ReturnKeywordRole); }
}
public Expression Expression {
@ -53,7 +55,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,7 +55,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (returnExpression, Roles.Expression);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitReturnStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitReturnStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitReturnStatement (this, data);
}

23
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/Statement.cs

@ -25,7 +25,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -25,7 +25,16 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return default (T);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return default (S);
}
@ -56,7 +65,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -56,7 +65,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}

60
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/SwitchStatement.cs

@ -34,10 +34,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -34,10 +34,11 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class SwitchStatement : Statement
{
public static readonly TokenRole SwitchKeywordRole = new TokenRole ("switch");
public static readonly Role<SwitchSection> SwitchSectionRole = new Role<SwitchSection>("SwitchSection");
public CSharpTokenNode SwitchToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (SwitchKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -65,7 +66,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -65,7 +66,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RBrace); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitSwitchStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitSwitchStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitSwitchStatement (this, data);
}
@ -98,7 +109,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -98,7 +109,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
@ -131,7 +152,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -131,7 +152,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildrenByRole (Roles.EmbeddedStatement); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitSwitchSection (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitSwitchSection (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitSwitchSection (this, data);
}
@ -145,6 +176,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -145,6 +176,9 @@ namespace ICSharpCode.NRefactory.CSharp
public class CaseLabel : AstNode
{
public static readonly TokenRole CaseKeywordRole = new TokenRole ("case");
public static readonly TokenRole DefaultKeywordRole = new TokenRole ("default");
public override NodeType NodeType {
get {
return NodeType.Unknown;
@ -158,7 +192,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -158,7 +192,11 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.Expression); }
set { SetChildByRole (Roles.Expression, value); }
}
public CSharpTokenNode ColonToken {
get { return GetChildByRole (Roles.Colon); }
}
public CaseLabel ()
{
}
@ -168,7 +206,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -168,7 +206,17 @@ namespace ICSharpCode.NRefactory.CSharp
this.Expression = expression;
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitCaseLabel (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitCaseLabel (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitCaseLabel (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/ThrowStatement.cs

@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class ThrowStatement : Statement
{
public static readonly TokenRole ThrowKeywordRole = new TokenRole ("throw");
public CSharpTokenNode ThrowToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (ThrowKeywordRole); }
}
public Expression Expression {
@ -53,7 +55,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -53,7 +55,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (expression, Roles.Expression);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitThrowStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitThrowStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitThrowStatement (this, data);
}

46
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/TryCatchStatement.cs

@ -34,10 +34,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -34,10 +34,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class TryCatchStatement : Statement
{
public static readonly Role<CSharpTokenNode> TryKeywordRole = new Role<CSharpTokenNode>("TryKeyword", CSharpTokenNode.Null);
public static readonly TokenRole TryKeywordRole = new TokenRole ("try");
public static readonly Role<BlockStatement> TryBlockRole = new Role<BlockStatement>("TryBlock", BlockStatement.Null);
public static readonly Role<CatchClause> CatchClauseRole = new Role<CatchClause>("CatchClause");
public static readonly Role<CSharpTokenNode> FinallyKeywordRole = new Role<CSharpTokenNode>("FinallyKeyword", CSharpTokenNode.Null);
public static readonly TokenRole FinallyKeywordRole = new TokenRole ("finally");
public static readonly Role<BlockStatement> FinallyBlockRole = new Role<BlockStatement>("FinallyBlock", BlockStatement.Null);
public CSharpTokenNode TryToken {
@ -62,7 +62,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -62,7 +62,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (FinallyBlockRole, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitTryCatchStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitTryCatchStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitTryCatchStatement (this, data);
}
@ -79,6 +89,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -79,6 +89,8 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class CatchClause : AstNode
{
public static readonly TokenRole CatchKeywordRole = new TokenRole ("catch");
#region PatternPlaceholder
public static implicit operator CatchClause(PatternMatching.Pattern pattern)
{
@ -98,7 +110,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -98,7 +110,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return NodeType.Pattern; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitPatternPlaceholder(this, child);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitPatternPlaceholder(this, child);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitPatternPlaceholder(this, child, data);
}
@ -122,7 +144,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -122,7 +144,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
public CSharpTokenNode CatchToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (CatchKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -140,7 +162,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -140,7 +162,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (string.IsNullOrEmpty(value))
SetChildByRole (Roles.Identifier, null);
else
SetChildByRole (Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
SetChildByRole (Roles.Identifier, Identifier.Create (value));
}
}
@ -162,7 +184,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -162,7 +184,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Body, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitCatchClause (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitCatchClause (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitCatchClause (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/UncheckedStatement.cs

@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class UncheckedStatement : Statement
{
public static readonly TokenRole UncheckedKeywordRole = new TokenRole ("unchecked");
public CSharpTokenNode UncheckedToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (UncheckedKeywordRole); }
}
public BlockStatement Body {
@ -49,7 +51,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -49,7 +51,17 @@ namespace ICSharpCode.NRefactory.CSharp
AddChild (body, Roles.Body);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitUncheckedStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitUncheckedStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitUncheckedStatement (this, data);
}

16
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/UnsafeStatement.cs

@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,8 +31,10 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class UnsafeStatement : Statement
{
public static readonly TokenRole UnsafeKeywordRole = new TokenRole ("unsafe");
public CSharpTokenNode UnsafeToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (UnsafeKeywordRole); }
}
public BlockStatement Body {
@ -40,7 +42,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -40,7 +42,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.Body, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitUnsafeStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitUnsafeStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitUnsafeStatement (this, data);
}

15
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/UsingStatement.cs

@ -31,10 +31,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,10 +31,11 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class UsingStatement : Statement
{
public static readonly TokenRole UsingKeywordRole = new TokenRole ("using");
public static readonly Role<AstNode> ResourceAcquisitionRole = new Role<AstNode>("ResourceAcquisition", AstNode.Null);
public CSharpTokenNode UsingToken {
get { return GetChildByRole (Roles.Keyword); }
get { return GetChildByRole (UsingKeywordRole); }
}
public CSharpTokenNode LParToken {
@ -58,7 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -58,7 +59,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole (Roles.EmbeddedStatement, value); }
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitUsingStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitUsingStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitUsingStatement (this, data);
}

20
NRefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/VariableDeclarationStatement.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,7 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp
{
public class VariableDeclarationStatement : Statement
{
public static readonly Role<CSharpModifierToken> ModifierRole = AttributedNode.ModifierRole;
public static readonly Role<CSharpModifierToken> ModifierRole = EntityDeclaration.ModifierRole;
public VariableDeclarationStatement()
{
@ -44,8 +44,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -44,8 +44,8 @@ namespace ICSharpCode.NRefactory.CSharp
}
public Modifiers Modifiers {
get { return AttributedNode.GetModifiers(this); }
set { AttributedNode.SetModifiers(this, value); }
get { return EntityDeclaration.GetModifiers(this); }
set { EntityDeclaration.SetModifiers(this, value); }
}
public AstType Type {
@ -63,10 +63,20 @@ namespace ICSharpCode.NRefactory.CSharp @@ -63,10 +63,20 @@ namespace ICSharpCode.NRefactory.CSharp
public VariableInitializer GetVariable (string name)
{
return Variables.FirstOrDefault (vi => vi.Name == name);
return Variables.FirstOrNullObject (vi => vi.Name == name);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
public override void AcceptVisitor (IAstVisitor visitor)
{
visitor.VisitVariableDeclarationStatement (this);
}
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
{
return visitor.VisitVariableDeclarationStatement (this);
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitVariableDeclarationStatement (this, data);
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save