diff --git a/ICSharpCode.NRefactory.CSharp.AstVerifier/.gitignore b/ICSharpCode.NRefactory.CSharp.AstVerifier/.gitignore
new file mode 100644
index 000000000..9ce745d95
--- /dev/null
+++ b/ICSharpCode.NRefactory.CSharp.AstVerifier/.gitignore
@@ -0,0 +1,3 @@
+
+bin/
+obj/
\ No newline at end of file
diff --git a/ICSharpCode.NRefactory.CSharp.AstVerifier/AssemblyInfo.cs b/ICSharpCode.NRefactory.CSharp.AstVerifier/AssemblyInfo.cs
new file mode 100644
index 000000000..7bd701bed
--- /dev/null
+++ b/ICSharpCode.NRefactory.CSharp.AstVerifier/AssemblyInfo.cs
@@ -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("")]
+
diff --git a/ICSharpCode.NRefactory.CSharp.AstVerifier/ICSharpCode.NRefactory.CSharp.AstVerifier.csproj b/ICSharpCode.NRefactory.CSharp.AstVerifier/ICSharpCode.NRefactory.CSharp.AstVerifier.csproj
new file mode 100644
index 000000000..bd6e1e823
--- /dev/null
+++ b/ICSharpCode.NRefactory.CSharp.AstVerifier/ICSharpCode.NRefactory.CSharp.AstVerifier.csproj
@@ -0,0 +1,49 @@
+
+
+
+ Debug
+ AnyCPU
+ 10.0.0
+ 2.0
+ {961DADFA-7CE6-429F-BC22-47630D6DB826}
+ Exe
+ ICSharpCode.NRefactory.CSharp.AstVerifier
+ AstVerifier
+
+
+ true
+ full
+ false
+ bin\Debug
+ DEBUG;
+ prompt
+ 4
+ true
+
+
+ none
+ false
+ bin\Release
+ prompt
+ 4
+ true
+
+
+
+
+
+
+
+
+
+
+
+ {53DCA265-3C3C-42F9-B647-F72BA678122B}
+ ICSharpCode.NRefactory.CSharp
+
+
+ {3B2A5653-EC97-4001-BB9B-D90F1AF2C371}
+ ICSharpCode.NRefactory
+
+
+
\ No newline at end of file
diff --git a/ICSharpCode.NRefactory.CSharp.AstVerifier/Main.cs b/ICSharpCode.NRefactory.CSharp.AstVerifier/Main.cs
new file mode 100644
index 000000000..43d3531b7
--- /dev/null
+++ b/ICSharpCode.NRefactory.CSharp.AstVerifier/Main.cs
@@ -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);
+ }
+ }
+}
diff --git a/ICSharpCode.NRefactory.CSharp/Analysis/ControlFlow.cs b/ICSharpCode.NRefactory.CSharp/Analysis/ControlFlow.cs
index 4bf4e8bd7..2812375b1 100644
--- a/ICSharpCode.NRefactory.CSharp/Analysis/ControlFlow.cs
+++ b/ICSharpCode.NRefactory.CSharp/Analysis/ControlFlow.cs
@@ -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
/// Gets the try-finally statements that this control flow edge is leaving.
///
public IEnumerable TryFinallyStatements {
- get { return jumpOutOfTryFinally ?? EmptyList.Instance; }
+ get { return jumpOutOfTryFinally ?? Enumerable.Empty(); }
}
}
@@ -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) {
diff --git a/ICSharpCode.NRefactory.CSharp/Analysis/DefiniteAssignmentAnalysis.cs b/ICSharpCode.NRefactory.CSharp/Analysis/DefiniteAssignmentAnalysis.cs
index 8d0832bed..fdcc4d717 100644
--- a/ICSharpCode.NRefactory.CSharp/Analysis/DefiniteAssignmentAnalysis.cs
+++ b/ICSharpCode.NRefactory.CSharp/Analysis/DefiniteAssignmentAnalysis.cs
@@ -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
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs b/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs
index 8e6d05a2d..bc4d27de0 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs
@@ -1,4 +1,4 @@
-//
+//
// AstNode.cs
//
// Author:
@@ -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 RootRole = new Role ("Root");
+
#region Null
public static readonly AstNode Null = new NullAstNode ();
@@ -52,7 +55,16 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return default (T);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return default (S);
}
@@ -83,7 +95,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return NodeType.Pattern; }
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ visitor.VisitPatternPlaceholder (this, child);
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return visitor.VisitPatternPlaceholder (this, child);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitPatternPlaceholder (this, child, data);
}
@@ -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
}
}
- ///
- /// Returns true, if the given coordinates are in the node.
- ///
- public bool IsInside (TextLocation location)
- {
- return StartLocation <= location && location <= EndLocation;
- }
-
- ///
- /// Returns true, if the given coordinates (line, column) are in the node.
- ///
- public bool IsInside(int line, int column)
- {
- return IsInside(new TextLocation (line, column));
- }
-
///
/// 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
}
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
get { return lastChild; }
}
+ public bool HasChildren {
+ get {
+ return firstChild != null;
+ }
+ }
+
public IEnumerable Children {
get {
AstNode next;
@@ -211,6 +273,17 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
+ ///
+ /// Gets the ancestors of this node (including this node itself)
+ ///
+ public IEnumerable AncestorsAndSelf {
+ get {
+ for (AstNode cur = this; cur != null; cur = cur.parent) {
+ yield return cur;
+ }
+ }
+ }
+
///
/// Gets all descendants of this node (excluding this node itself).
///
@@ -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.
///
- public T GetChildByRole (Role role) where T : AstNode
+ public T GetChildByRole(Role 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() where T : AstNode
+ {
+ return Ancestors.OfType().FirstOrDefault();
+ }
+
public AstNodeCollection GetChildrenByRole (Role role) where T : AstNode
{
return new AstNodeCollection (this, role);
@@ -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
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
lastChild = child;
}
}
+
+ public void InsertChildsBefore(AstNode nextSibling, Role role, params T[] child) where T : AstNode
+ {
+ foreach (var cur in child) {
+ InsertChildBefore(nextSibling, cur, role);
+ }
+ }
public void InsertChildBefore (AstNode nextSibling, T child, Role role) where T : AstNode
{
@@ -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
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
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
parent.lastChild = prevSibling;
}
parent = null;
- role = Roles.Root;
prevSibling = null;
nextSibling = null;
}
@@ -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
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
parent = null;
prevSibling = null;
nextSibling = null;
- role = Roles.Root;
}
}
@@ -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
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 (IAstVisitor visitor, T data = default(T));
+ public abstract void AcceptVisitor (IAstVisitor visitor);
+
+ public abstract T AcceptVisitor (IAstVisitor visitor);
+
+ public abstract S AcceptVisitor (IAstVisitor visitor, T data);
#region Pattern Matching
protected static bool MatchString (string pattern, string text)
@@ -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
return null;
}
+ #region GetNodeAt
+ ///
+ /// 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)
+ ///
public AstNode GetNodeAt (int line, int column, Predicate pred = null)
{
return GetNodeAt (new TextLocation (line, column), pred);
}
+ ///
+ /// 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)
+ ///
public AstNode GetNodeAt (TextLocation location, Predicate pred = null)
{
AstNode result = null;
@@ -559,6 +663,11 @@ namespace ICSharpCode.NRefactory.CSharp
return result;
}
+ ///
+ /// 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)
+ ///
public T GetNodeAt (int line, int column) where T : AstNode
{
return GetNodeAt (new TextLocation (line, column));
@@ -567,6 +676,7 @@ namespace ICSharpCode.NRefactory.CSharp
///
/// 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)
///
public T GetNodeAt (TextLocation location) where T : AstNode
{
@@ -589,6 +699,97 @@ namespace ICSharpCode.NRefactory.CSharp
}
return result;
}
+
+ #endregion
+
+ #region GetAdjacentNodeAt
+ ///
+ /// 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)
+ ///
+ public AstNode GetAdjacentNodeAt(int line, int column, Predicate pred = null)
+ {
+ return GetAdjacentNodeAt (new TextLocation (line, column), pred);
+ }
+
+ ///
+ /// 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)
+ ///
+ public AstNode GetAdjacentNodeAt (TextLocation location, Predicate 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;
+ }
+
+ ///
+ /// 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)
+ ///
+ public T GetAdjacentNodeAt(int line, int column) where T : AstNode
+ {
+ return GetAdjacentNodeAt (new TextLocation (line, column));
+ }
+
+ ///
+ /// 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)
+ ///
+ public T GetAdjacentNodeAt (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
+
+
+ ///
+ /// Gets the node that fully contains the range from startLocation to endLocation.
+ ///
+ 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 GetNodesBetween (int startLine, int startColumn, int endLine, int endColumn)
{
@@ -619,16 +820,65 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
+ ///
+ /// Gets the node as formatted C# output.
+ ///
+ ///
+ /// Formatting options.
+ ///
+ public virtual string GetText (CSharpFormattingOptions formattingOptions = null)
+ {
+ if (IsNull)
+ return "";
+ var w = new StringWriter ();
+ AcceptVisitor (new CSharpOutputVisitor (w, formattingOptions ?? FormattingOptionsFactory.CreateMono ()));
+ return w.ToString ();
+ }
+
+ ///
+ /// Returns true, if the given coordinates (line, column) are in the node.
+ ///
+ ///
+ /// True, if the given coordinates are between StartLocation and EndLocation (exclusive); otherwise, false.
+ ///
public bool Contains (int line, int column)
{
return Contains (new TextLocation (line, column));
}
-
+
+ ///
+ /// Returns true, if the given coordinates are in the node.
+ ///
+ ///
+ /// True, if location is between StartLocation and EndLocation (exclusive); otherwise, false.
+ ///
public bool Contains (TextLocation location)
{
return this.StartLocation <= location && location < this.EndLocation;
}
+ ///
+ /// Returns true, if the given coordinates (line, column) are in the node.
+ ///
+ ///
+ /// True, if the given coordinates are between StartLocation and EndLocation (inclusive); otherwise, false.
+ ///
+ public bool IsInside (int line, int column)
+ {
+ return IsInside (new TextLocation (line, column));
+ }
+
+ ///
+ /// Returns true, if the given coordinates are in the node.
+ ///
+ ///
+ /// True, if location is between StartLocation and EndLocation (inclusive); otherwise, false.
+ ///
+ 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
{
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 RootRole = new Role ("Root");
-
- public static class Roles
- {
- ///
- /// Root of an abstract syntax tree.
- ///
- public static readonly Role Root = RootRole;
-
- // some pre defined constants for common roles
- public static readonly Role Identifier = new Role ("Identifier", CSharp.Identifier.Null);
- public static readonly Role Body = new Role ("Body", CSharp.BlockStatement.Null);
- public static readonly Role Parameter = new Role ("Parameter");
- public static readonly Role Argument = new Role ("Argument", CSharp.Expression.Null);
- public static readonly Role Type = new Role ("Type", CSharp.AstType.Null);
- public static readonly Role Expression = new Role ("Expression", CSharp.Expression.Null);
- public static readonly Role TargetExpression = new Role ("Target", CSharp.Expression.Null);
- public readonly static Role Condition = new Role ("Condition", CSharp.Expression.Null);
- public static readonly Role TypeParameter = new Role ("TypeParameter");
- public static readonly Role TypeArgument = new Role ("TypeArgument", CSharp.AstType.Null);
- public readonly static Role Constraint = new Role ("Constraint");
- public static readonly Role Variable = new Role ("Variable");
- public static readonly Role EmbeddedStatement = new Role ("EmbeddedStatement", CSharp.Statement.Null);
- public static readonly Role Keyword = new Role ("Keyword", CSharpTokenNode.Null);
- public static readonly Role InKeyword = new Role ("InKeyword", CSharpTokenNode.Null);
-
- // some pre defined constants for most used punctuation
- public static readonly Role LPar = new Role ("LPar", CSharpTokenNode.Null);
- public static readonly Role RPar = new Role ("RPar", CSharpTokenNode.Null);
- public static readonly Role LBracket = new Role ("LBracket", CSharpTokenNode.Null);
- public static readonly Role RBracket = new Role ("RBracket", CSharpTokenNode.Null);
- public static readonly Role LBrace = new Role ("LBrace", CSharpTokenNode.Null);
- public static readonly Role RBrace = new Role ("RBrace", CSharpTokenNode.Null);
- public static readonly Role LChevron = new Role ("LChevron", CSharpTokenNode.Null);
- public static readonly Role RChevron = new Role ("RChevron", CSharpTokenNode.Null);
- public static readonly Role Comma = new Role ("Comma", CSharpTokenNode.Null);
- public static readonly Role Dot = new Role ("Dot", CSharpTokenNode.Null);
- public static readonly Role Semicolon = new Role ("Semicolon", CSharpTokenNode.Null);
- public static readonly Role Assign = new Role ("Assign", CSharpTokenNode.Null);
- public static readonly Role Colon = new Role ("Colon", CSharpTokenNode.Null);
- public static readonly Role Comment = new Role ("Comment");
- public static readonly Role PreProcessorDirective = new Role ("PreProcessorDirective");
- public static readonly Role Error = new Role ("Error");
-
- }
}
}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/AstType.cs b/ICSharpCode.NRefactory.CSharp/Ast/AstType.cs
index 205a76884..71d835709 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/AstType.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/AstType.cs
@@ -39,7 +39,16 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return default (T);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return default (S);
}
@@ -75,9 +84,19 @@ namespace ICSharpCode.NRefactory.CSharp
get { return NodeType.Pattern; }
}
- public override S AcceptVisitor(IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ visitor.VisitPatternPlaceholder (this, child);
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return visitor.VisitPatternPlaceholder (this, child);
+ }
+
+ public override S AcceptVisitor(IAstVisitor 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
return new TypeReferenceExpression { Type = this }.Member(memberName);
}
+ ///
+ /// Builds an expression that can be used to access a static member on this type.
+ ///
+ public MemberType MemberType(string memberName, params AstType[] typeArguments)
+ {
+ var memberType = new MemberType(this, memberName);
+ memberType.TypeArguments.AddRange(typeArguments);
+ return memberType;
+ }
+
+ ///
+ /// Builds an expression that can be used to access a static member on this type.
+ ///
+ public MemberType MemberType(string memberName, IEnumerable typeArguments)
+ {
+ var memberType = new MemberType(this, memberName);
+ memberType.TypeArguments.AddRange(typeArguments);
+ return memberType;
+ }
+
///
/// Builds an invocation expression using this type as target.
///
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs b/ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs
index e9cc00ebe..ac59c7246 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/CSharpModifierToken.cs
@@ -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
get { return allModifiers; }
}
- public CSharpModifierToken (TextLocation location, Modifiers modifier) : base (location, 0)
+ public CSharpModifierToken (TextLocation location, Modifiers modifier) : base (location)
{
this.Modifier = modifier;
}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/CSharpTokenNode.cs b/ICSharpCode.NRefactory.CSharp/Ast/CSharpTokenNode.cs
index 00bf53dfd..04910ae18 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/CSharpTokenNode.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/CSharpTokenNode.cs
@@ -27,7 +27,13 @@ using System;
namespace ICSharpCode.NRefactory.CSharp
{
- public class CSharpTokenNode : AstNode, IRelocatable
+ ///
+ /// Represents a token in C#. Note that the type of the token is defined through the TokenRole.
+ ///
+ ///
+ /// In all non null c# token nodes the Role of a CSharpToken must be a TokenRole.
+ ///
+ public class CSharpTokenNode : AstNode
{
public static new readonly CSharpTokenNode Null = new NullCSharpTokenNode ();
class NullCSharpTokenNode : CSharpTokenNode
@@ -38,11 +44,20 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
- public NullCSharpTokenNode () : base (TextLocation.Empty, 0)
+ public NullCSharpTokenNode () : base (TextLocation.Empty)
{
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return default (T);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return default (S);
}
@@ -53,7 +68,6 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
-
public override NodeType NodeType {
get {
return NodeType.Token;
@@ -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 (IAstVisitor visitor)
{
- this.startLocation = startLocation;
+ return visitor.VisitCSharpTokenNode (this);
}
- #endregion
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitCSharpTokenNode (this, data);
}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/CSharpUtil.cs b/ICSharpCode.NRefactory.CSharp/Ast/CSharpUtil.cs
index 46f528d46..e13bf334c 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/CSharpUtil.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/CSharpUtil.cs
@@ -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
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));
}
}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs b/ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs
index 3f3f0d08e..04dec11e7 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs
@@ -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
}
}
+ string fileName;
+
///
/// Gets/Sets the file name of this compilation unit.
///
- public string FileName { get; set; }
+ public string FileName {
+ get { return fileName; }
+ set {
+ ThrowIfFrozen();
+ fileName = value;
+ }
+ }
+
+ public AstNodeCollection Members {
+ get { return GetChildrenByRole(MemberRole); }
+ }
List errors = new List ();
@@ -68,17 +84,18 @@ namespace ICSharpCode.NRefactory.CSharp
{
}
- public IEnumerable GetTypes (bool includeInnerTypes = false)
+ public IEnumerable GetTypes(bool includeInnerTypes = false)
{
Stack nodeStack = new Stack ();
- 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
return o != null && GetChildrenByRole(MemberRole).DoMatch(o.GetChildrenByRole(MemberRole), match);
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ visitor.VisitCompilationUnit (this);
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return visitor.VisitCompilationUnit (this);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitCompilationUnit (this, data);
}
@@ -98,14 +125,45 @@ namespace ICSharpCode.NRefactory.CSharp
///
/// Converts this compilation unit into a parsed file that can be stored in the type system.
///
- 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);
+ }
}
}
-
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/ComposedType.cs b/ICSharpCode.NRefactory.CSharp/Ast/ComposedType.cs
index 0ac460547..845f189d7 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/ComposedType.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/ComposedType.cs
@@ -33,8 +33,8 @@ namespace ICSharpCode.NRefactory.CSharp
{
public class ComposedType : AstType
{
- public static readonly Role NullableRole = new Role("Nullable", CSharpTokenNode.Null);
- public static readonly Role PointerRole = new Role("Pointer", CSharpTokenNode.Null);
+ public static readonly TokenRole NullableRole = new TokenRole("?");
+ public static readonly TokenRole PointerRole = new TokenRole("*");
public static readonly Role ArraySpecifierRole = new Role("ArraySpecifier");
public AstType BaseType {
@@ -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
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
get { return GetChildrenByRole (ArraySpecifierRole); }
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ visitor.VisitComposedType (this);
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return visitor.VisitComposedType (this);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitComposedType (this, data);
}
@@ -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
get { return GetChildByRole (Roles.RBracket); }
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ visitor.VisitArraySpecifier (this);
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return visitor.VisitArraySpecifier (this);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitArraySpecifier(this, data);
}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/DepthFirstAstVisitor.cs b/ICSharpCode.NRefactory.CSharp/Ast/DepthFirstAstVisitor.cs
index ac04c5111..68bce6c35 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/DepthFirstAstVisitor.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/DepthFirstAstVisitor.cs
@@ -28,6 +28,1201 @@ using System;
namespace ICSharpCode.NRefactory.CSharp
{
+ ///
+ /// AST visitor with a default implementation that visits all node depth-first.
+ ///
+ public abstract class DepthFirstAstVisitor : IAstVisitor
+ {
+ protected virtual void VisitChildren (AstNode node)
+ {
+ AstNode next;
+ for (var child = node.FirstChild; child != null; child = next) {
+ // Store next to allow the loop to continue
+ // if the visitor removes/replaces child.
+ next = child.NextSibling;
+ child.AcceptVisitor (this);
+ }
+ }
+
+ public virtual void VisitCompilationUnit (CompilationUnit unit)
+ {
+ VisitChildren (unit);
+ }
+
+ public virtual void VisitComment(Comment comment)
+ {
+ VisitChildren(comment);
+ }
+
+ public virtual void VisitNewLine(NewLineNode newLineNode)
+ {
+ VisitChildren(newLineNode);
+ }
+
+ public virtual void VisitWhitespace(WhitespaceNode whitespaceNode)
+ {
+ VisitChildren(whitespaceNode);
+ }
+
+ public virtual void VisitText(TextNode textNode)
+ {
+ VisitChildren(textNode);
+ }
+
+ public virtual void VisitDocumentationReference (DocumentationReference documentationReference)
+ {
+ VisitChildren (documentationReference);
+ }
+
+ public virtual void VisitPreProcessorDirective (PreProcessorDirective preProcessorDirective)
+ {
+ VisitChildren (preProcessorDirective);
+ }
+
+ public virtual void VisitIdentifier (Identifier identifier)
+ {
+ VisitChildren (identifier);
+ }
+
+ public virtual void VisitCSharpTokenNode (CSharpTokenNode token)
+ {
+ VisitChildren (token);
+ }
+
+ public virtual void VisitPrimitiveType (PrimitiveType primitiveType)
+ {
+ VisitChildren (primitiveType);
+ }
+
+ public virtual void VisitComposedType (ComposedType composedType)
+ {
+ VisitChildren (composedType);
+ }
+
+ public virtual void VisitSimpleType(SimpleType simpleType)
+ {
+ VisitChildren (simpleType);
+ }
+
+ public virtual void VisitMemberType(MemberType memberType)
+ {
+ VisitChildren (memberType);
+ }
+
+ public virtual void VisitAttribute (Attribute attribute)
+ {
+ VisitChildren (attribute);
+ }
+
+ public virtual void VisitAttributeSection (AttributeSection attributeSection)
+ {
+ VisitChildren (attributeSection);
+ }
+
+ public virtual void VisitDelegateDeclaration (DelegateDeclaration delegateDeclaration)
+ {
+ VisitChildren (delegateDeclaration);
+ }
+
+ public virtual void VisitNamespaceDeclaration (NamespaceDeclaration namespaceDeclaration)
+ {
+ VisitChildren (namespaceDeclaration);
+ }
+
+ public virtual void VisitTypeDeclaration (TypeDeclaration typeDeclaration)
+ {
+ VisitChildren (typeDeclaration);
+ }
+
+ public virtual void VisitTypeParameterDeclaration (TypeParameterDeclaration typeParameterDeclaration)
+ {
+ VisitChildren (typeParameterDeclaration);
+ }
+
+ public virtual void VisitEnumMemberDeclaration (EnumMemberDeclaration enumMemberDeclaration)
+ {
+ VisitChildren (enumMemberDeclaration);
+ }
+
+ public virtual void VisitUsingDeclaration (UsingDeclaration usingDeclaration)
+ {
+ VisitChildren (usingDeclaration);
+ }
+
+ public virtual void VisitUsingAliasDeclaration (UsingAliasDeclaration usingDeclaration)
+ {
+ VisitChildren (usingDeclaration);
+ }
+
+ public virtual void VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration)
+ {
+ VisitChildren (externAliasDeclaration);
+ }
+
+ public virtual void VisitConstructorDeclaration (ConstructorDeclaration constructorDeclaration)
+ {
+ VisitChildren (constructorDeclaration);
+ }
+
+ public virtual void VisitConstructorInitializer (ConstructorInitializer constructorInitializer)
+ {
+ VisitChildren (constructorInitializer);
+ }
+
+ public virtual void VisitDestructorDeclaration (DestructorDeclaration destructorDeclaration)
+ {
+ VisitChildren (destructorDeclaration);
+ }
+
+ public virtual void VisitEventDeclaration (EventDeclaration eventDeclaration)
+ {
+ VisitChildren (eventDeclaration);
+ }
+
+ public virtual void VisitCustomEventDeclaration (CustomEventDeclaration eventDeclaration)
+ {
+ VisitChildren (eventDeclaration);
+ }
+
+ public virtual void VisitFieldDeclaration (FieldDeclaration fieldDeclaration)
+ {
+ VisitChildren (fieldDeclaration);
+ }
+
+ public virtual void VisitFixedFieldDeclaration (FixedFieldDeclaration fixedFieldDeclaration)
+ {
+ VisitChildren (fixedFieldDeclaration);
+ }
+
+ public virtual void VisitFixedVariableInitializer (FixedVariableInitializer fixedVariableInitializer)
+ {
+ VisitChildren (fixedVariableInitializer);
+ }
+
+ public virtual void VisitIndexerDeclaration (IndexerDeclaration indexerDeclaration)
+ {
+ VisitChildren (indexerDeclaration);
+ }
+
+ public virtual void VisitMethodDeclaration (MethodDeclaration methodDeclaration)
+ {
+ VisitChildren (methodDeclaration);
+ }
+
+ public virtual void VisitOperatorDeclaration (OperatorDeclaration operatorDeclaration)
+ {
+ VisitChildren (operatorDeclaration);
+ }
+
+ public virtual void VisitPropertyDeclaration (PropertyDeclaration propertyDeclaration)
+ {
+ VisitChildren (propertyDeclaration);
+ }
+
+ public virtual void VisitAccessor (Accessor accessor)
+ {
+ VisitChildren (accessor);
+ }
+
+ public virtual void VisitVariableInitializer (VariableInitializer variableInitializer)
+ {
+ VisitChildren (variableInitializer);
+ }
+
+ public virtual void VisitParameterDeclaration (ParameterDeclaration parameterDeclaration)
+ {
+ VisitChildren (parameterDeclaration);
+ }
+
+ public virtual void VisitConstraint (Constraint constraint)
+ {
+ VisitChildren (constraint);
+ }
+
+ public virtual void VisitBlockStatement (BlockStatement blockStatement)
+ {
+ VisitChildren (blockStatement);
+ }
+
+ public virtual void VisitExpressionStatement (ExpressionStatement expressionStatement)
+ {
+ VisitChildren (expressionStatement);
+ }
+
+ public virtual void VisitBreakStatement (BreakStatement breakStatement)
+ {
+ VisitChildren (breakStatement);
+ }
+
+ public virtual void VisitCheckedStatement (CheckedStatement checkedStatement)
+ {
+ VisitChildren (checkedStatement);
+ }
+
+ public virtual void VisitContinueStatement (ContinueStatement continueStatement)
+ {
+ VisitChildren (continueStatement);
+ }
+
+ public virtual void VisitDoWhileStatement (DoWhileStatement doWhileStatement)
+ {
+ VisitChildren (doWhileStatement);
+ }
+
+ public virtual void VisitEmptyStatement (EmptyStatement emptyStatement)
+ {
+ VisitChildren (emptyStatement);
+ }
+
+ public virtual void VisitFixedStatement (FixedStatement fixedStatement)
+ {
+ VisitChildren (fixedStatement);
+ }
+
+ public virtual void VisitForeachStatement (ForeachStatement foreachStatement)
+ {
+ VisitChildren (foreachStatement);
+ }
+
+ public virtual void VisitForStatement (ForStatement forStatement)
+ {
+ VisitChildren (forStatement);
+ }
+
+ public virtual void VisitGotoCaseStatement (GotoCaseStatement gotoCaseStatement)
+ {
+ VisitChildren (gotoCaseStatement);
+ }
+
+ public virtual void VisitGotoDefaultStatement (GotoDefaultStatement gotoDefaultStatement)
+ {
+ VisitChildren (gotoDefaultStatement);
+ }
+
+ public virtual void VisitGotoStatement (GotoStatement gotoStatement)
+ {
+ VisitChildren (gotoStatement);
+ }
+
+ public virtual void VisitIfElseStatement (IfElseStatement ifElseStatement)
+ {
+ VisitChildren (ifElseStatement);
+ }
+
+ public virtual void VisitLabelStatement (LabelStatement labelStatement)
+ {
+ VisitChildren (labelStatement);
+ }
+
+ public virtual void VisitLockStatement (LockStatement lockStatement)
+ {
+ VisitChildren (lockStatement);
+ }
+
+ public virtual void VisitReturnStatement (ReturnStatement returnStatement)
+ {
+ VisitChildren (returnStatement);
+ }
+
+ public virtual void VisitSwitchStatement (SwitchStatement switchStatement)
+ {
+ VisitChildren (switchStatement);
+ }
+
+ public virtual void VisitSwitchSection (SwitchSection switchSection)
+ {
+ VisitChildren (switchSection);
+ }
+
+ public virtual void VisitCaseLabel (CaseLabel caseLabel)
+ {
+ VisitChildren (caseLabel);
+ }
+
+ public virtual void VisitThrowStatement (ThrowStatement throwStatement)
+ {
+ VisitChildren (throwStatement);
+ }
+
+ public virtual void VisitTryCatchStatement (TryCatchStatement tryCatchStatement)
+ {
+ VisitChildren (tryCatchStatement);
+ }
+
+ public virtual void VisitCatchClause (CatchClause catchClause)
+ {
+ VisitChildren (catchClause);
+ }
+
+ public virtual void VisitUncheckedStatement (UncheckedStatement uncheckedStatement)
+ {
+ VisitChildren (uncheckedStatement);
+ }
+
+ public virtual void VisitUnsafeStatement (UnsafeStatement unsafeStatement)
+ {
+ VisitChildren (unsafeStatement);
+ }
+
+ public virtual void VisitUsingStatement (UsingStatement usingStatement)
+ {
+ VisitChildren (usingStatement);
+ }
+
+ public virtual void VisitVariableDeclarationStatement (VariableDeclarationStatement variableDeclarationStatement)
+ {
+ VisitChildren (variableDeclarationStatement);
+ }
+
+ public virtual void VisitWhileStatement (WhileStatement whileStatement)
+ {
+ VisitChildren (whileStatement);
+ }
+
+ public virtual void VisitYieldBreakStatement (YieldBreakStatement yieldBreakStatement)
+ {
+ VisitChildren (yieldBreakStatement);
+ }
+
+ public virtual void VisitYieldReturnStatement (YieldReturnStatement yieldReturnStatement)
+ {
+ VisitChildren (yieldReturnStatement);
+ }
+
+ public virtual void VisitAnonymousMethodExpression (AnonymousMethodExpression anonymousMethodExpression)
+ {
+ VisitChildren (anonymousMethodExpression);
+ }
+
+ public virtual void VisitLambdaExpression (LambdaExpression lambdaExpression)
+ {
+ VisitChildren (lambdaExpression);
+ }
+
+ public virtual void VisitAssignmentExpression (AssignmentExpression assignmentExpression)
+ {
+ VisitChildren (assignmentExpression);
+ }
+
+ public virtual void VisitBaseReferenceExpression (BaseReferenceExpression baseReferenceExpression)
+ {
+ VisitChildren (baseReferenceExpression);
+ }
+
+ public virtual void VisitBinaryOperatorExpression (BinaryOperatorExpression binaryOperatorExpression)
+ {
+ VisitChildren (binaryOperatorExpression);
+ }
+
+ public virtual void VisitCastExpression (CastExpression castExpression)
+ {
+ VisitChildren (castExpression);
+ }
+
+ public virtual void VisitCheckedExpression (CheckedExpression checkedExpression)
+ {
+ VisitChildren (checkedExpression);
+ }
+
+ public virtual void VisitConditionalExpression (ConditionalExpression conditionalExpression)
+ {
+ VisitChildren (conditionalExpression);
+ }
+
+ public virtual void VisitIdentifierExpression (IdentifierExpression identifierExpression)
+ {
+ VisitChildren (identifierExpression);
+ }
+
+ public virtual void VisitIndexerExpression (IndexerExpression indexerExpression)
+ {
+ VisitChildren (indexerExpression);
+ }
+
+ public virtual void VisitInvocationExpression (InvocationExpression invocationExpression)
+ {
+ VisitChildren (invocationExpression);
+ }
+
+ public virtual void VisitDirectionExpression (DirectionExpression directionExpression)
+ {
+ VisitChildren (directionExpression);
+ }
+
+ public virtual void VisitMemberReferenceExpression (MemberReferenceExpression memberReferenceExpression)
+ {
+ VisitChildren (memberReferenceExpression);
+ }
+
+ public virtual void VisitNullReferenceExpression (NullReferenceExpression nullReferenceExpression)
+ {
+ VisitChildren (nullReferenceExpression);
+ }
+
+ public virtual void VisitObjectCreateExpression (ObjectCreateExpression objectCreateExpression)
+ {
+ VisitChildren (objectCreateExpression);
+ }
+
+ public virtual void VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression)
+ {
+ VisitChildren (anonymousTypeCreateExpression);
+ }
+
+ public virtual void VisitArrayCreateExpression (ArrayCreateExpression arrayCreateExpression)
+ {
+ VisitChildren (arrayCreateExpression);
+ }
+
+ public virtual void VisitParenthesizedExpression (ParenthesizedExpression parenthesizedExpression)
+ {
+ VisitChildren (parenthesizedExpression);
+ }
+
+ public virtual void VisitPointerReferenceExpression (PointerReferenceExpression pointerReferenceExpression)
+ {
+ VisitChildren (pointerReferenceExpression);
+ }
+
+ public virtual void VisitPrimitiveExpression(PrimitiveExpression primitiveExpression)
+ {
+ VisitChildren (primitiveExpression);
+ }
+
+ public virtual void VisitSizeOfExpression (SizeOfExpression sizeOfExpression)
+ {
+ VisitChildren (sizeOfExpression);
+ }
+
+ public virtual void VisitStackAllocExpression (StackAllocExpression stackAllocExpression)
+ {
+ VisitChildren (stackAllocExpression);
+ }
+
+ public virtual void VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression)
+ {
+ VisitChildren (thisReferenceExpression);
+ }
+
+ public virtual void VisitTypeOfExpression (TypeOfExpression typeOfExpression)
+ {
+ VisitChildren (typeOfExpression);
+ }
+
+ public virtual void VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression)
+ {
+ VisitChildren (typeReferenceExpression);
+ }
+
+ public virtual void VisitUnaryOperatorExpression (UnaryOperatorExpression unaryOperatorExpression)
+ {
+ VisitChildren (unaryOperatorExpression);
+ }
+
+ public virtual void VisitUncheckedExpression (UncheckedExpression uncheckedExpression)
+ {
+ VisitChildren (uncheckedExpression);
+ }
+
+ public virtual void VisitQueryExpression(QueryExpression queryExpression)
+ {
+ VisitChildren (queryExpression);
+ }
+
+ public virtual void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
+ {
+ VisitChildren (queryContinuationClause);
+ }
+
+ public virtual void VisitQueryFromClause(QueryFromClause queryFromClause)
+ {
+ VisitChildren (queryFromClause);
+ }
+
+ public virtual void VisitQueryLetClause(QueryLetClause queryLetClause)
+ {
+ VisitChildren (queryLetClause);
+ }
+
+ public virtual void VisitQueryWhereClause(QueryWhereClause queryWhereClause)
+ {
+ VisitChildren (queryWhereClause);
+ }
+
+ public virtual void VisitQueryJoinClause(QueryJoinClause queryJoinClause)
+ {
+ VisitChildren (queryJoinClause);
+ }
+
+ public virtual void VisitQueryOrderClause(QueryOrderClause queryOrderClause)
+ {
+ VisitChildren (queryOrderClause);
+ }
+
+ public virtual void VisitQueryOrdering(QueryOrdering queryOrdering)
+ {
+ VisitChildren (queryOrdering);
+ }
+
+ public virtual void VisitQuerySelectClause(QuerySelectClause querySelectClause)
+ {
+ VisitChildren (querySelectClause);
+ }
+
+ public virtual void VisitQueryGroupClause(QueryGroupClause queryGroupClause)
+ {
+ VisitChildren (queryGroupClause);
+ }
+
+ public virtual void VisitAsExpression (AsExpression asExpression)
+ {
+ VisitChildren (asExpression);
+ }
+
+ public virtual void VisitIsExpression (IsExpression isExpression)
+ {
+ VisitChildren (isExpression);
+ }
+
+ public virtual void VisitDefaultValueExpression (DefaultValueExpression defaultValueExpression)
+ {
+ VisitChildren (defaultValueExpression);
+ }
+
+ public virtual void VisitUndocumentedExpression (UndocumentedExpression undocumentedExpression)
+ {
+ VisitChildren (undocumentedExpression);
+ }
+
+ public virtual void VisitArrayInitializerExpression (ArrayInitializerExpression arrayInitializerExpression)
+ {
+ VisitChildren (arrayInitializerExpression);
+ }
+
+ public virtual void VisitArraySpecifier (ArraySpecifier arraySpecifier)
+ {
+ VisitChildren (arraySpecifier);
+ }
+
+ public virtual void VisitNamedArgumentExpression (NamedArgumentExpression namedArgumentExpression)
+ {
+ VisitChildren (namedArgumentExpression);
+ }
+
+ public virtual void VisitNamedExpression (NamedExpression namedExpression)
+ {
+ VisitChildren (namedExpression);
+ }
+
+ public virtual void VisitEmptyExpression (EmptyExpression emptyExpression)
+ {
+ VisitChildren (emptyExpression);
+ }
+
+ public virtual void VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern)
+ {
+ VisitChildren (placeholder);
+ }
+ }
+
+ ///
+ /// AST visitor with a default implementation that visits all node depth-first.
+ ///
+ public abstract class DepthFirstAstVisitor : IAstVisitor
+ {
+ protected virtual T VisitChildren (AstNode node)
+ {
+ AstNode next;
+ for (var child = node.FirstChild; child != null; child = next) {
+ // Store next to allow the loop to continue
+ // if the visitor removes/replaces child.
+ next = child.NextSibling;
+ child.AcceptVisitor (this);
+ }
+ return default (T);
+ }
+
+ public virtual T VisitCompilationUnit (CompilationUnit unit)
+ {
+ return VisitChildren (unit);
+ }
+
+ public virtual T VisitComment (Comment comment)
+ {
+ return VisitChildren (comment);
+ }
+
+ public virtual T VisitNewLine(NewLineNode newLineNode)
+ {
+ return VisitChildren(newLineNode);
+ }
+
+ public virtual T VisitWhitespace(WhitespaceNode whitespaceNode)
+ {
+ return VisitChildren(whitespaceNode);
+ }
+
+ public virtual T VisitText(TextNode textNode)
+ {
+ return VisitChildren(textNode);
+ }
+
+ public virtual T VisitDocumentationReference (DocumentationReference documentationReference)
+ {
+ return VisitChildren (documentationReference);
+ }
+
+ public virtual T VisitPreProcessorDirective (PreProcessorDirective preProcessorDirective)
+ {
+ return VisitChildren (preProcessorDirective);
+ }
+
+ public virtual T VisitIdentifier (Identifier identifier)
+ {
+ return VisitChildren (identifier);
+ }
+
+ public virtual T VisitCSharpTokenNode (CSharpTokenNode token)
+ {
+ return VisitChildren (token);
+ }
+
+ public virtual T VisitPrimitiveType (PrimitiveType primitiveType)
+ {
+ return VisitChildren (primitiveType);
+ }
+
+ public virtual T VisitComposedType (ComposedType composedType)
+ {
+ return VisitChildren (composedType);
+ }
+
+ public virtual T VisitSimpleType(SimpleType simpleType)
+ {
+ return VisitChildren (simpleType);
+ }
+
+ public virtual T VisitMemberType(MemberType memberType)
+ {
+ return VisitChildren (memberType);
+ }
+
+ public virtual T VisitAttribute (Attribute attribute)
+ {
+ return VisitChildren (attribute);
+ }
+
+ public virtual T VisitAttributeSection (AttributeSection attributeSection)
+ {
+ return VisitChildren (attributeSection);
+ }
+
+ public virtual T VisitDelegateDeclaration (DelegateDeclaration delegateDeclaration)
+ {
+ return VisitChildren (delegateDeclaration);
+ }
+
+ public virtual T VisitNamespaceDeclaration (NamespaceDeclaration namespaceDeclaration)
+ {
+ return VisitChildren (namespaceDeclaration);
+ }
+
+ public virtual T VisitTypeDeclaration (TypeDeclaration typeDeclaration)
+ {
+ return VisitChildren (typeDeclaration);
+ }
+
+ public virtual T VisitTypeParameterDeclaration (TypeParameterDeclaration typeParameterDeclaration)
+ {
+ return VisitChildren (typeParameterDeclaration);
+ }
+
+ public virtual T VisitEnumMemberDeclaration (EnumMemberDeclaration enumMemberDeclaration)
+ {
+ return VisitChildren (enumMemberDeclaration);
+ }
+
+ public virtual T VisitUsingDeclaration (UsingDeclaration usingDeclaration)
+ {
+ return VisitChildren (usingDeclaration);
+ }
+
+ public virtual T VisitUsingAliasDeclaration (UsingAliasDeclaration usingDeclaration)
+ {
+ return VisitChildren (usingDeclaration);
+ }
+
+ public virtual T VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration)
+ {
+ return VisitChildren (externAliasDeclaration);
+ }
+
+ public virtual T VisitConstructorDeclaration (ConstructorDeclaration constructorDeclaration)
+ {
+ return VisitChildren (constructorDeclaration);
+ }
+
+ public virtual T VisitConstructorInitializer (ConstructorInitializer constructorInitializer)
+ {
+ return VisitChildren (constructorInitializer);
+ }
+
+ public virtual T VisitDestructorDeclaration (DestructorDeclaration destructorDeclaration)
+ {
+ return VisitChildren (destructorDeclaration);
+ }
+
+ public virtual T VisitEventDeclaration (EventDeclaration eventDeclaration)
+ {
+ return VisitChildren (eventDeclaration);
+ }
+
+ public virtual T VisitCustomEventDeclaration (CustomEventDeclaration eventDeclaration)
+ {
+ return VisitChildren (eventDeclaration);
+ }
+
+ public virtual T VisitFieldDeclaration (FieldDeclaration fieldDeclaration)
+ {
+ return VisitChildren (fieldDeclaration);
+ }
+
+ public virtual T VisitFixedFieldDeclaration (FixedFieldDeclaration fixedFieldDeclaration)
+ {
+ return VisitChildren (fixedFieldDeclaration);
+ }
+
+ public virtual T VisitFixedVariableInitializer (FixedVariableInitializer fixedVariableInitializer)
+ {
+ return VisitChildren (fixedVariableInitializer);
+ }
+
+ public virtual T VisitIndexerDeclaration (IndexerDeclaration indexerDeclaration)
+ {
+ return VisitChildren (indexerDeclaration);
+ }
+
+ public virtual T VisitMethodDeclaration (MethodDeclaration methodDeclaration)
+ {
+ return VisitChildren (methodDeclaration);
+ }
+
+ public virtual T VisitOperatorDeclaration (OperatorDeclaration operatorDeclaration)
+ {
+ return VisitChildren (operatorDeclaration);
+ }
+
+ public virtual T VisitPropertyDeclaration (PropertyDeclaration propertyDeclaration)
+ {
+ return VisitChildren (propertyDeclaration);
+ }
+
+ public virtual T VisitAccessor (Accessor accessor)
+ {
+ return VisitChildren (accessor);
+ }
+
+ public virtual T VisitVariableInitializer (VariableInitializer variableInitializer)
+ {
+ return VisitChildren (variableInitializer);
+ }
+
+ public virtual T VisitParameterDeclaration (ParameterDeclaration parameterDeclaration)
+ {
+ return VisitChildren (parameterDeclaration);
+ }
+
+ public virtual T VisitConstraint (Constraint constraint)
+ {
+ return VisitChildren (constraint);
+ }
+
+ public virtual T VisitBlockStatement (BlockStatement blockStatement)
+ {
+ return VisitChildren (blockStatement);
+ }
+
+ public virtual T VisitExpressionStatement (ExpressionStatement expressionStatement)
+ {
+ return VisitChildren (expressionStatement);
+ }
+
+ public virtual T VisitBreakStatement (BreakStatement breakStatement)
+ {
+ return VisitChildren (breakStatement);
+ }
+
+ public virtual T VisitCheckedStatement (CheckedStatement checkedStatement)
+ {
+ return VisitChildren (checkedStatement);
+ }
+
+ public virtual T VisitContinueStatement (ContinueStatement continueStatement)
+ {
+ return VisitChildren (continueStatement);
+ }
+
+ public virtual T VisitDoWhileStatement (DoWhileStatement doWhileStatement)
+ {
+ return VisitChildren (doWhileStatement);
+ }
+
+ public virtual T VisitEmptyStatement (EmptyStatement emptyStatement)
+ {
+ return VisitChildren (emptyStatement);
+ }
+
+ public virtual T VisitFixedStatement (FixedStatement fixedStatement)
+ {
+ return VisitChildren (fixedStatement);
+ }
+
+ public virtual T VisitForeachStatement (ForeachStatement foreachStatement)
+ {
+ return VisitChildren (foreachStatement);
+ }
+
+ public virtual T VisitForStatement (ForStatement forStatement)
+ {
+ return VisitChildren (forStatement);
+ }
+
+ public virtual T VisitGotoCaseStatement (GotoCaseStatement gotoCaseStatement)
+ {
+ return VisitChildren (gotoCaseStatement);
+ }
+
+ public virtual T VisitGotoDefaultStatement (GotoDefaultStatement gotoDefaultStatement)
+ {
+ return VisitChildren (gotoDefaultStatement);
+ }
+
+ public virtual T VisitGotoStatement (GotoStatement gotoStatement)
+ {
+ return VisitChildren (gotoStatement);
+ }
+
+ public virtual T VisitIfElseStatement (IfElseStatement ifElseStatement)
+ {
+ return VisitChildren (ifElseStatement);
+ }
+
+ public virtual T VisitLabelStatement (LabelStatement labelStatement)
+ {
+ return VisitChildren (labelStatement);
+ }
+
+ public virtual T VisitLockStatement (LockStatement lockStatement)
+ {
+ return VisitChildren (lockStatement);
+ }
+
+ public virtual T VisitReturnStatement (ReturnStatement returnStatement)
+ {
+ return VisitChildren (returnStatement);
+ }
+
+ public virtual T VisitSwitchStatement (SwitchStatement switchStatement)
+ {
+ return VisitChildren (switchStatement);
+ }
+
+ public virtual T VisitSwitchSection (SwitchSection switchSection)
+ {
+ return VisitChildren (switchSection);
+ }
+
+ public virtual T VisitCaseLabel (CaseLabel caseLabel)
+ {
+ return VisitChildren (caseLabel);
+ }
+
+ public virtual T VisitThrowStatement (ThrowStatement throwStatement)
+ {
+ return VisitChildren (throwStatement);
+ }
+
+ public virtual T VisitTryCatchStatement (TryCatchStatement tryCatchStatement)
+ {
+ return VisitChildren (tryCatchStatement);
+ }
+
+ public virtual T VisitCatchClause (CatchClause catchClause)
+ {
+ return VisitChildren (catchClause);
+ }
+
+ public virtual T VisitUncheckedStatement (UncheckedStatement uncheckedStatement)
+ {
+ return VisitChildren (uncheckedStatement);
+ }
+
+ public virtual T VisitUnsafeStatement (UnsafeStatement unsafeStatement)
+ {
+ return VisitChildren (unsafeStatement);
+ }
+
+ public virtual T VisitUsingStatement (UsingStatement usingStatement)
+ {
+ return VisitChildren (usingStatement);
+ }
+
+ public virtual T VisitVariableDeclarationStatement (VariableDeclarationStatement variableDeclarationStatement)
+ {
+ return VisitChildren (variableDeclarationStatement);
+ }
+
+ public virtual T VisitWhileStatement (WhileStatement whileStatement)
+ {
+ return VisitChildren (whileStatement);
+ }
+
+ public virtual T VisitYieldBreakStatement (YieldBreakStatement yieldBreakStatement)
+ {
+ return VisitChildren (yieldBreakStatement);
+ }
+
+ public virtual T VisitYieldReturnStatement (YieldReturnStatement yieldReturnStatement)
+ {
+ return VisitChildren (yieldReturnStatement);
+ }
+
+ public virtual T VisitAnonymousMethodExpression (AnonymousMethodExpression anonymousMethodExpression)
+ {
+ return VisitChildren (anonymousMethodExpression);
+ }
+
+ public virtual T VisitLambdaExpression (LambdaExpression lambdaExpression)
+ {
+ return VisitChildren (lambdaExpression);
+ }
+
+ public virtual T VisitAssignmentExpression (AssignmentExpression assignmentExpression)
+ {
+ return VisitChildren (assignmentExpression);
+ }
+
+ public virtual T VisitBaseReferenceExpression (BaseReferenceExpression baseReferenceExpression)
+ {
+ return VisitChildren (baseReferenceExpression);
+ }
+
+ public virtual T VisitBinaryOperatorExpression (BinaryOperatorExpression binaryOperatorExpression)
+ {
+ return VisitChildren (binaryOperatorExpression);
+ }
+
+ public virtual T VisitCastExpression (CastExpression castExpression)
+ {
+ return VisitChildren (castExpression);
+ }
+
+ public virtual T VisitCheckedExpression (CheckedExpression checkedExpression)
+ {
+ return VisitChildren (checkedExpression);
+ }
+
+ public virtual T VisitConditionalExpression (ConditionalExpression conditionalExpression)
+ {
+ return VisitChildren (conditionalExpression);
+ }
+
+ public virtual T VisitIdentifierExpression (IdentifierExpression identifierExpression)
+ {
+ return VisitChildren (identifierExpression);
+ }
+
+ public virtual T VisitIndexerExpression (IndexerExpression indexerExpression)
+ {
+ return VisitChildren (indexerExpression);
+ }
+
+ public virtual T VisitInvocationExpression (InvocationExpression invocationExpression)
+ {
+ return VisitChildren (invocationExpression);
+ }
+
+ public virtual T VisitDirectionExpression (DirectionExpression directionExpression)
+ {
+ return VisitChildren (directionExpression);
+ }
+
+ public virtual T VisitMemberReferenceExpression (MemberReferenceExpression memberReferenceExpression)
+ {
+ return VisitChildren (memberReferenceExpression);
+ }
+
+ public virtual T VisitNullReferenceExpression (NullReferenceExpression nullReferenceExpression)
+ {
+ return VisitChildren (nullReferenceExpression);
+ }
+
+ public virtual T VisitObjectCreateExpression (ObjectCreateExpression objectCreateExpression)
+ {
+ return VisitChildren (objectCreateExpression);
+ }
+
+ public virtual T VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression)
+ {
+ return VisitChildren (anonymousTypeCreateExpression);
+ }
+
+ public virtual T VisitArrayCreateExpression (ArrayCreateExpression arrayCreateExpression)
+ {
+ return VisitChildren (arrayCreateExpression);
+ }
+
+ public virtual T VisitParenthesizedExpression (ParenthesizedExpression parenthesizedExpression)
+ {
+ return VisitChildren (parenthesizedExpression);
+ }
+
+ public virtual T VisitPointerReferenceExpression (PointerReferenceExpression pointerReferenceExpression)
+ {
+ return VisitChildren (pointerReferenceExpression);
+ }
+
+ public virtual T VisitPrimitiveExpression(PrimitiveExpression primitiveExpression)
+ {
+ return VisitChildren (primitiveExpression);
+ }
+
+ public virtual T VisitSizeOfExpression (SizeOfExpression sizeOfExpression)
+ {
+ return VisitChildren (sizeOfExpression);
+ }
+
+ public virtual T VisitStackAllocExpression (StackAllocExpression stackAllocExpression)
+ {
+ return VisitChildren (stackAllocExpression);
+ }
+
+ public virtual T VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression)
+ {
+ return VisitChildren (thisReferenceExpression);
+ }
+
+ public virtual T VisitTypeOfExpression (TypeOfExpression typeOfExpression)
+ {
+ return VisitChildren (typeOfExpression);
+ }
+
+ public virtual T VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression)
+ {
+ return VisitChildren (typeReferenceExpression);
+ }
+
+ public virtual T VisitUnaryOperatorExpression (UnaryOperatorExpression unaryOperatorExpression)
+ {
+ return VisitChildren (unaryOperatorExpression);
+ }
+
+ public virtual T VisitUncheckedExpression (UncheckedExpression uncheckedExpression)
+ {
+ return VisitChildren (uncheckedExpression);
+ }
+
+ public virtual T VisitQueryExpression(QueryExpression queryExpression)
+ {
+ return VisitChildren (queryExpression);
+ }
+
+ public virtual T VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
+ {
+ return VisitChildren (queryContinuationClause);
+ }
+
+ public virtual T VisitQueryFromClause(QueryFromClause queryFromClause)
+ {
+ return VisitChildren (queryFromClause);
+ }
+
+ public virtual T VisitQueryLetClause(QueryLetClause queryLetClause)
+ {
+ return VisitChildren (queryLetClause);
+ }
+
+ public virtual T VisitQueryWhereClause(QueryWhereClause queryWhereClause)
+ {
+ return VisitChildren (queryWhereClause);
+ }
+
+ public virtual T VisitQueryJoinClause(QueryJoinClause queryJoinClause)
+ {
+ return VisitChildren (queryJoinClause);
+ }
+
+ public virtual T VisitQueryOrderClause(QueryOrderClause queryOrderClause)
+ {
+ return VisitChildren (queryOrderClause);
+ }
+
+ public virtual T VisitQueryOrdering(QueryOrdering queryOrdering)
+ {
+ return VisitChildren (queryOrdering);
+ }
+
+ public virtual T VisitQuerySelectClause(QuerySelectClause querySelectClause)
+ {
+ return VisitChildren (querySelectClause);
+ }
+
+ public virtual T VisitQueryGroupClause(QueryGroupClause queryGroupClause)
+ {
+ return VisitChildren (queryGroupClause);
+ }
+
+ public virtual T VisitAsExpression (AsExpression asExpression)
+ {
+ return VisitChildren (asExpression);
+ }
+
+ public virtual T VisitIsExpression (IsExpression isExpression)
+ {
+ return VisitChildren (isExpression);
+ }
+
+ public virtual T VisitDefaultValueExpression (DefaultValueExpression defaultValueExpression)
+ {
+ return VisitChildren (defaultValueExpression);
+ }
+
+ public virtual T VisitUndocumentedExpression (UndocumentedExpression undocumentedExpression)
+ {
+ return VisitChildren (undocumentedExpression);
+ }
+
+ public virtual T VisitArrayInitializerExpression (ArrayInitializerExpression arrayInitializerExpression)
+ {
+ return VisitChildren (arrayInitializerExpression);
+ }
+
+ public virtual T VisitArraySpecifier (ArraySpecifier arraySpecifier)
+ {
+ return VisitChildren (arraySpecifier);
+ }
+
+ public virtual T VisitNamedArgumentExpression (NamedArgumentExpression namedArgumentExpression)
+ {
+ return VisitChildren (namedArgumentExpression);
+ }
+
+ public virtual T VisitNamedExpression (NamedExpression namedExpression)
+ {
+ return VisitChildren (namedExpression);
+ }
+
+ public virtual T VisitEmptyExpression (EmptyExpression emptyExpression)
+ {
+ return VisitChildren (emptyExpression);
+ }
+
+ public virtual T VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern)
+ {
+ return VisitChildren (placeholder);
+ }
+ }
+
///
/// AST visitor with a default implementation that visits all node depth-first.
///
@@ -55,6 +1250,26 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (comment, data);
}
+ public virtual S VisitNewLine(NewLineNode newLineNode, T data)
+ {
+ return VisitChildren(newLineNode, data);
+ }
+
+ public virtual S VisitWhitespace(WhitespaceNode whitespaceNode, T data)
+ {
+ return VisitChildren(whitespaceNode, data);
+ }
+
+ public virtual S VisitText(TextNode textNode, T data)
+ {
+ return VisitChildren(textNode, data);
+ }
+
+ public virtual S VisitDocumentationReference (DocumentationReference documentationReference, T data)
+ {
+ return VisitChildren (documentationReference, data);
+ }
+
public virtual S VisitPreProcessorDirective (PreProcessorDirective preProcessorDirective, T data)
{
return VisitChildren (preProcessorDirective, data);
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/DocumentationReference.cs b/ICSharpCode.NRefactory.CSharp/Ast/DocumentationReference.cs
new file mode 100644
index 000000000..9c599ce6b
--- /dev/null
+++ b/ICSharpCode.NRefactory.CSharp/Ast/DocumentationReference.cs
@@ -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
+{
+ ///
+ /// Represents a 'cref' reference in XML documentation.
+ ///
+ public class DocumentationReference : AstNode
+ {
+ public static readonly Role DeclaringTypeRole = new Role("DeclaringType", AstType.Null);
+ public static readonly Role ConversionOperatorReturnTypeRole = new Role("ConversionOperatorReturnType", AstType.Null);
+
+ EntityType entityType;
+ OperatorType operatorType;
+ bool hasParameterList;
+
+ ///
+ /// Gets/Sets the entity type.
+ /// Possible values are:
+ /// EntityType.Operator for operators,
+ /// EntityType.Indexer for indexers,
+ /// EntityType.TypeDefinition for references to primitive types,
+ /// and EntityType.None for everything else.
+ ///
+ public EntityType EntityType {
+ get { return entityType; }
+ set {
+ ThrowIfFrozen();
+ entityType = value;
+ }
+ }
+
+ ///
+ /// Gets/Sets the operator type.
+ /// This property is only used when EntityType==Operator.
+ ///
+ public OperatorType OperatorType {
+ get { return operatorType; }
+ set {
+ ThrowIfFrozen();
+ operatorType = value;
+ }
+ }
+
+ ///
+ /// Gets/Sets whether a parameter list was provided.
+ ///
+ public bool HasParameterList {
+ get { return hasParameterList; }
+ set {
+ ThrowIfFrozen();
+ hasParameterList = value;
+ }
+ }
+
+ public override NodeType NodeType {
+ get { return NodeType.Unknown; }
+ }
+
+ ///
+ /// Gets/Sets the declaring type.
+ ///
+ public AstType DeclaringType {
+ get { return GetChildByRole(DeclaringTypeRole); }
+ set { SetChildByRole(DeclaringTypeRole, value); }
+ }
+
+ ///
+ /// Gets/sets the member name.
+ /// This property is only used when EntityType==None.
+ ///
+ public string MemberName {
+ get { return GetChildByRole(Roles.Identifier).Name; }
+ set { SetChildByRole(Roles.Identifier, Identifier.Create(value)); }
+ }
+
+ ///
+ /// Gets/Sets the return type of conversion operators.
+ /// This property is only used when EntityType==Operator and OperatorType is explicit or implicit.
+ ///
+ public AstType ConversionOperatorReturnType {
+ get { return GetChildByRole(ConversionOperatorReturnTypeRole); }
+ set { SetChildByRole(ConversionOperatorReturnTypeRole, value); }
+ }
+
+ public AstNodeCollection TypeArguments {
+ get { return GetChildrenByRole (Roles.TypeArgument); }
+ }
+
+ public AstNodeCollection 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 (IAstVisitor visitor)
+ {
+ return visitor.VisitDocumentationReference (this);
+ }
+
+ public override S AcceptVisitor(IAstVisitor visitor, T data)
+ {
+ return visitor.VisitDocumentationReference (this, data);
+ }
+ }
+}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/ErrorNode.cs b/ICSharpCode.NRefactory.CSharp/Ast/ErrorNode.cs
index 53dfd7126..ee5f88521 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/ErrorNode.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/ErrorNode.cs
@@ -58,7 +58,16 @@ namespace ICSharpCode.NRefactory.CSharp
{
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return default (T);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
// nothing
return default (S);
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AnonymousMethodExpression.cs b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AnonymousMethodExpression.cs
index 91fc0c417..07de16197 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AnonymousMethodExpression.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AnonymousMethodExpression.cs
@@ -34,17 +34,26 @@ namespace ICSharpCode.NRefactory.CSharp
///
public class AnonymousMethodExpression : Expression
{
- public readonly static Role 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
{
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ visitor.VisitAnonymousMethodExpression (this);
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return visitor.VisitAnonymousMethodExpression (this);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitAnonymousMethodExpression (this, data);
}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AnonymousTypeCreateExpression.cs b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AnonymousTypeCreateExpression.cs
index 496a2cfdb..944bf61f5 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AnonymousTypeCreateExpression.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AnonymousTypeCreateExpression.cs
@@ -33,8 +33,10 @@ namespace ICSharpCode.NRefactory.CSharp
///
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
{
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ visitor.VisitAnonymousTypeCreateExpression (this);
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return visitor.VisitAnonymousTypeCreateExpression (this);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitAnonymousTypeCreateExpression (this, data);
}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayCreateExpression.cs b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayCreateExpression.cs
index f9bee2a68..c9f1b2a62 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayCreateExpression.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayCreateExpression.cs
@@ -26,9 +26,14 @@ namespace ICSharpCode.NRefactory.CSharp
///
public class ArrayCreateExpression : Expression
{
+ public readonly static TokenRole NewKeywordRole = new TokenRole ("new");
public readonly static Role AdditionalArraySpecifierRole = new Role("AdditionalArraySpecifier");
public readonly static Role InitializerRole = new Role("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
set { SetChildByRole (InitializerRole, value); }
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ visitor.VisitArrayCreateExpression (this);
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return visitor.VisitArrayCreateExpression (this);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitArrayCreateExpression (this, data);
}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayInitializerExpression.cs b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayInitializerExpression.cs
index d4858d8b2..ffb3712f2 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayInitializerExpression.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayInitializerExpression.cs
@@ -58,7 +58,16 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return default (T);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return default (S);
}
@@ -82,7 +91,17 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildByRole (Roles.RBrace); }
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ visitor.VisitArrayInitializerExpression (this);
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return visitor.VisitArrayInitializerExpression (this);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitArrayInitializerExpression (this, data);
}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AsExpression.cs b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AsExpression.cs
index 59f4652da..cf9cfb4f9 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AsExpression.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AsExpression.cs
@@ -31,13 +31,15 @@ namespace ICSharpCode.NRefactory.CSharp
///
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
AddChild (type, Roles.Type);
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ visitor.VisitAsExpression (this);
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return visitor.VisitAsExpression (this);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitAsExpression (this, data);
}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AssignmentExpression.cs b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AssignmentExpression.cs
index c214eedc1..14021d323 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AssignmentExpression.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/AssignmentExpression.cs
@@ -36,9 +36,20 @@ namespace ICSharpCode.NRefactory.CSharp
{
// reuse roles from BinaryOperatorExpression
public readonly static Role LeftRole = BinaryOperatorExpression.LeftRole;
- public readonly static Role OperatorRole = BinaryOperatorExpression.OperatorRole;
public readonly static Role 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
}
public CSharpTokenNode OperatorToken {
- get { return GetChildByRole (OperatorRole); }
+ get { return GetChildByRole (GetOperatorRole(Operator)); }
}
public Expression Right {
@@ -75,7 +86,17 @@ namespace ICSharpCode.NRefactory.CSharp
set { SetChildByRole(RightRole, value); }
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ visitor.VisitAssignmentExpression (this);
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return visitor.VisitAssignmentExpression (this);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitAssignmentExpression (this, data);
}
@@ -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");
}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/BaseReferenceExpression.cs b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/BaseReferenceExpression.cs
index 2214e3eaa..399c36c22 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/BaseReferenceExpression.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/BaseReferenceExpression.cs
@@ -47,7 +47,17 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override void AcceptVisitor (IAstVisitor visitor)
+ {
+ visitor.VisitBaseReferenceExpression (this);
+ }
+
+ public override T AcceptVisitor (IAstVisitor visitor)
+ {
+ return visitor.VisitBaseReferenceExpression (this);
+ }
+
+ public override S AcceptVisitor (IAstVisitor visitor, T data)
{
return visitor.VisitBaseReferenceExpression (this, data);
}
diff --git a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/BinaryOperatorExpression.cs b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/BinaryOperatorExpression.cs
index 6a2d94ed7..819d90f53 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/Expressions/BinaryOperatorExpression.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/Expressions/BinaryOperatorExpression.cs
@@ -34,8 +34,27 @@ namespace ICSharpCode.NRefactory.CSharp
///
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 LeftRole = new Role("Left", Expression.Null);
- public readonly static Role OperatorRole = new Role("Operator", CSharpTokenNode.Null);
public readonly static Role RightRole = new Role("Right", Expression.Null);
public BinaryOperatorExpression()
@@ -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 (IAstVisitor visitor)
+ {
+ return visitor.VisitBinaryOperatorExpression (this);
}
- public override S AcceptVisitor (IAstVisitor visitor, T data = default(T))
+ public override S AcceptVisitor (IAstVisitor