Browse Source

Updated AST & mcs.

newNRvisualizers
Mike Krüger 15 years ago
parent
commit
396c2b3931
  1. 12
      ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs
  2. 6
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs
  3. 5
      ICSharpCode.NRefactory/CSharp/Dom/CSharpModifierToken.cs
  4. 31
      ICSharpCode.NRefactory/CSharp/Dom/CSharpTokenNode.cs
  5. 62
      ICSharpCode.NRefactory/CSharp/Dom/CompilationUnit.cs
  6. 22
      ICSharpCode.NRefactory/CSharp/Dom/ComposedType.cs
  7. 166
      ICSharpCode.NRefactory/CSharp/Dom/DomNode.cs
  8. 41
      ICSharpCode.NRefactory/CSharp/Dom/DomVisitor.cs
  9. 32
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/AnonymousMethodExpression.cs
  10. 21
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/ArgListExpression.cs
  11. 16
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/ArrayCreateExpression.cs
  12. 45
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/ArrayInitializerExpression.cs
  13. 17
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/AsExpression.cs
  14. 27
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/AssignmentExpression.cs
  15. 11
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/BaseReferenceExpression.cs
  16. 28
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/BinaryOperatorExpression.cs
  17. 23
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/CastExpression.cs
  18. 19
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/CheckedExpression.cs
  19. 27
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/ConditionalExpression.cs
  20. 12
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/DefaultValueExpression.cs
  21. 18
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/DirectionExpression.cs
  22. 19
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/IdentifierExpression.cs
  23. 21
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/IndexerExpression.cs
  24. 24
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/InvocationExpression.cs
  25. 21
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/IsExpression.cs
  26. 22
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/LambdaExpression.cs
  27. 25
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/MemberReferenceExpression.cs
  28. 11
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/NullReferenceExpression.cs
  29. 21
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/ObjectCreateExpression.cs
  30. 19
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/ParenthesizedExpression.cs
  31. 13
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/PointerReferenceExpression.cs
  32. 11
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/PrimitiveExpression.cs
  33. 116
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/QueryExpression.cs
  34. 17
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/SizeOfExpression.cs
  35. 23
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/StackAllocExpression.cs
  36. 11
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/ThisReferenceExpression.cs
  37. 17
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/TypeOfExpression.cs
  38. 19
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/UnaryOperatorExpression.cs
  39. 20
      ICSharpCode.NRefactory/CSharp/Dom/Expressions/UncheckedExpression.cs
  40. 30
      ICSharpCode.NRefactory/CSharp/Dom/FullTypeName.cs
  41. 15
      ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/Attribute.cs
  42. 15
      ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/AttributeSection.cs
  43. 22
      ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/Constraint.cs
  44. 36
      ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/DelegateDeclaration.cs
  45. 54
      ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/EnumDeclaration.cs
  46. 27
      ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/NamespaceDeclaration.cs
  47. 31
      ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/TypeDeclaration.cs
  48. 19
      ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/UsingAliasDeclaration.cs
  49. 11
      ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/UsingDeclaration.cs
  50. 140
      ICSharpCode.NRefactory/CSharp/Dom/IDomVisitor.cs
  51. 26
      ICSharpCode.NRefactory/CSharp/Dom/Identifier.cs
  52. 60
      ICSharpCode.NRefactory/CSharp/Dom/NodeType.cs
  53. 27
      ICSharpCode.NRefactory/CSharp/Dom/QualifiedIdentifier.cs
  54. 33
      ICSharpCode.NRefactory/CSharp/Dom/Statements/BlockStatement.cs
  55. 15
      ICSharpCode.NRefactory/CSharp/Dom/Statements/BreakStatement.cs
  56. 15
      ICSharpCode.NRefactory/CSharp/Dom/Statements/CheckedStatement.cs
  57. 15
      ICSharpCode.NRefactory/CSharp/Dom/Statements/ContinueStatement.cs
  58. 14
      ICSharpCode.NRefactory/CSharp/Dom/Statements/EmptyStatement.cs
  59. 17
      ICSharpCode.NRefactory/CSharp/Dom/Statements/ExpressionStatement.cs
  60. 19
      ICSharpCode.NRefactory/CSharp/Dom/Statements/FixedStatement.cs
  61. 27
      ICSharpCode.NRefactory/CSharp/Dom/Statements/ForStatement.cs
  62. 31
      ICSharpCode.NRefactory/CSharp/Dom/Statements/ForeachStatement.cs
  63. 22
      ICSharpCode.NRefactory/CSharp/Dom/Statements/GotoStatement.cs
  64. 31
      ICSharpCode.NRefactory/CSharp/Dom/Statements/IfElseStatement.cs
  65. 13
      ICSharpCode.NRefactory/CSharp/Dom/Statements/LabelStatement.cs
  66. 23
      ICSharpCode.NRefactory/CSharp/Dom/Statements/LockStatement.cs
  67. 15
      ICSharpCode.NRefactory/CSharp/Dom/Statements/ReturnStatement.cs
  68. 56
      ICSharpCode.NRefactory/CSharp/Dom/Statements/SwitchStatement.cs
  69. 15
      ICSharpCode.NRefactory/CSharp/Dom/Statements/ThrowStatement.cs
  70. 33
      ICSharpCode.NRefactory/CSharp/Dom/Statements/TryCatchStatement.cs
  71. 16
      ICSharpCode.NRefactory/CSharp/Dom/Statements/UncheckedStatement.cs
  72. 13
      ICSharpCode.NRefactory/CSharp/Dom/Statements/UnsafeStatement.cs
  73. 23
      ICSharpCode.NRefactory/CSharp/Dom/Statements/UsingStatement.cs
  74. 29
      ICSharpCode.NRefactory/CSharp/Dom/Statements/VariableDeclarationStatement.cs
  75. 27
      ICSharpCode.NRefactory/CSharp/Dom/Statements/WhileStatement.cs
  76. 17
      ICSharpCode.NRefactory/CSharp/Dom/Statements/YieldStatement.cs
  77. 16
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/AbstractMember.cs
  78. 13
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/AbstractMemberBase.cs
  79. 64
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/Accessor.cs
  80. 60
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/ConstructorDeclaration.cs
  81. 5
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/DestructorDeclaration.cs
  82. 11
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/EventDeclaration.cs
  83. 5
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/FieldDeclaration.cs
  84. 14
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/IndexerDeclaration.cs
  85. 38
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/MethodDeclaration.cs
  86. 17
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/OperatorDeclaration.cs
  87. 20
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/ParameterDeclaration.cs
  88. 33
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/PropertyDeclaration.cs
  89. 22
      ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/VariableInitializer.cs
  90. 4
      ICSharpCode.NRefactory/CSharp/Formatter/DomIndentationVisitor.cs
  91. 6
      ICSharpCode.NRefactory/CSharp/Formatter/DomSpacingVisitor.cs
  92. 437
      ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
  93. 10
      ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs
  94. 14
      ICSharpCode.NRefactory/CSharp/Parser/mcs/MonoSymbolFile.cs
  95. 22
      ICSharpCode.NRefactory/CSharp/Parser/mcs/anonymous.cs
  96. 46
      ICSharpCode.NRefactory/CSharp/Parser/mcs/argument.cs
  97. 1080
      ICSharpCode.NRefactory/CSharp/Parser/mcs/assembly.cs
  98. 30
      ICSharpCode.NRefactory/CSharp/Parser/mcs/assign.cs
  99. 331
      ICSharpCode.NRefactory/CSharp/Parser/mcs/attribute.cs
  100. 84
      ICSharpCode.NRefactory/CSharp/Parser/mcs/cfold.cs
  101. Some files were not shown because too many files have changed in this diff Show More

12
ICSharpCode.NRefactory.Tests/CSharp/Parser/ParseUtil.cs

@ -13,38 +13,38 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
/// </summary> /// </summary>
public class ParseUtilCSharp public class ParseUtilCSharp
{ {
public static T ParseGlobal<T>(string code, bool expectErrors = false) where T : INode public static T ParseGlobal<T>(string code, bool expectErrors = false) where T : DomNode
{ {
CSharpParser parser = new CSharpParser(); CSharpParser parser = new CSharpParser();
CompilationUnit cu = parser.Parse(new StringReader(code)); CompilationUnit cu = parser.Parse(new StringReader(code));
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
INode node = cu.Children.Single(); DomNode node = cu.Children.Single();
Type type = typeof(T); Type type = typeof(T);
Assert.IsTrue(type.IsAssignableFrom(node.GetType()), String.Format("Parsed node was {0} instead of {1} ({2})", node.GetType(), type, node)); Assert.IsTrue(type.IsAssignableFrom(node.GetType()), String.Format("Parsed node was {0} instead of {1} ({2})", node.GetType(), type, node));
return (T)node; return (T)node;
} }
public static T ParseStatement<T>(string stmt, bool expectErrors = false) where T : INode public static T ParseStatement<T>(string stmt, bool expectErrors = false) where T : DomNode
{ {
CSharpParser parser = new CSharpParser(); CSharpParser parser = new CSharpParser();
var statements = parser.ParseStatements(new StringReader(stmt)); var statements = parser.ParseStatements(new StringReader(stmt));
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
INode statement = statements.Single(); DomNode statement = statements.Single();
Type type = typeof(T); Type type = typeof(T);
Assert.IsTrue(type.IsAssignableFrom(statement.GetType()), String.Format("Parsed statement was {0} instead of {1} ({2})", statement.GetType(), type, statement)); Assert.IsTrue(type.IsAssignableFrom(statement.GetType()), String.Format("Parsed statement was {0} instead of {1} ({2})", statement.GetType(), type, statement));
return (T)statement; return (T)statement;
} }
public static T ParseExpression<T>(string expr, bool expectErrors = false) where T : INode public static T ParseExpression<T>(string expr, bool expectErrors = false) where T : DomNode
{ {
if (expectErrors) Assert.Ignore("errors not yet implemented"); if (expectErrors) Assert.Ignore("errors not yet implemented");
CSharpParser parser = new CSharpParser(); CSharpParser parser = new CSharpParser();
INode parsedExpression = parser.ParseExpression(new StringReader(expr)); DomNode parsedExpression = parser.ParseExpression(new StringReader(expr));
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");

6
ICSharpCode.NRefactory.Tests/CSharp/Resolver/ResolverTestBase.cs

@ -175,11 +175,11 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
return (T)rr; return (T)rr;
} }
sealed class FindNodeVisitor : AbstractDomVisitor<object, object> sealed class FindNodeVisitor : DomVisitor<object, object>
{ {
readonly DomLocation start; readonly DomLocation start;
readonly DomLocation end; readonly DomLocation end;
public INode ResultNode; public DomNode ResultNode;
public FindNodeVisitor(DomLocation start, DomLocation end) public FindNodeVisitor(DomLocation start, DomLocation end)
{ {
@ -187,7 +187,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
this.end = end; this.end = end;
} }
protected override object VisitChildren(INode node, object data) protected override object VisitChildren(DomNode node, object data)
{ {
if (node.StartLocation == start && node.EndLocation == end) { if (node.StartLocation == start && node.EndLocation == end) {
if (ResultNode != null) if (ResultNode != null)

5
ICSharpCode.NRefactory/CSharp/Dom/CSharpModifierToken.cs

@ -1,4 +1,4 @@
// //
// CSharpModifierToken.cs // CSharpModifierToken.cs
// //
// Author: // Author:
@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp
static CSharpModifierToken () static CSharpModifierToken ()
{ {
lengthTable[Modifiers.New] = "new".Length; lengthTable[Modifiers.New] = "new".Length;
lengthTable[Modifiers.Public] = "public".Length; lengthTable[Modifiers.Public] = "new".Length;
lengthTable[Modifiers.Protected] = "protected".Length; lengthTable[Modifiers.Protected] = "protected".Length;
lengthTable[Modifiers.Private] = "private".Length; lengthTable[Modifiers.Private] = "private".Length;
lengthTable[Modifiers.Internal] = "internal".Length; lengthTable[Modifiers.Internal] = "internal".Length;
@ -61,6 +61,7 @@ namespace ICSharpCode.NRefactory.CSharp
lengthTable[Modifiers.Extern] = "extern".Length; lengthTable[Modifiers.Extern] = "extern".Length;
lengthTable[Modifiers.Volatile] = "volatile".Length; lengthTable[Modifiers.Volatile] = "volatile".Length;
lengthTable[Modifiers.Unsafe] = "unsafe".Length; lengthTable[Modifiers.Unsafe] = "unsafe".Length;
lengthTable[Modifiers.Override] = "override".Length;
} }
public CSharpModifierToken (DomLocation location, Modifiers modifier) : base (location, 0) public CSharpModifierToken (DomLocation location, Modifiers modifier) : base (location, 0)

31
ICSharpCode.NRefactory/CSharp/Dom/CSharpTokenNode.cs

@ -24,11 +24,36 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class CSharpTokenNode : AbstractNode public class CSharpTokenNode : DomNode
{ {
public static new readonly CSharpTokenNode Null = new NullCSharpTokenNode ();
class NullCSharpTokenNode : CSharpTokenNode
{
public override bool IsNull {
get {
return true;
}
}
public NullCSharpTokenNode () : base (DomLocation.Empty, 0)
{
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{
return default (S);
}
}
public override NodeType NodeType {
get {
return NodeType.Token;
}
}
DomLocation startLocation; DomLocation startLocation;
public override DomLocation StartLocation { public override DomLocation StartLocation {
get { get {
@ -49,7 +74,7 @@ namespace ICSharpCode.NRefactory.CSharp
this.tokenLength = tokenLength; this.tokenLength = tokenLength;
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return default (S); return default (S);
} }

62
ICSharpCode.NRefactory/CSharp/Dom/CompilationUnit.cs

@ -24,16 +24,74 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class CompilationUnit : AbstractNode public class CompilationUnit : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public CompilationUnit () public CompilationUnit ()
{ {
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public DomNode GetNodeAt (int line, int column)
{
return GetNodeAt (new DomLocation (line, column));
}
public DomNode GetNodeAt (DomLocation location)
{
DomNode node = this;
while (node.FirstChild != null) {
var child = node.FirstChild;
while (child != null) {
if (child.StartLocation <= location && location < child.EndLocation) {
node = child;
break;
}
child = child.NextSibling;
}
// found no better child node - therefore the parent is the right one.
if (child == null)
break;
}
return node;
}
public IEnumerable<DomNode> GetNodesBetween (int startLine, int startColumn, int endLine, int endColumn)
{
return GetNodesBetween (new DomLocation (startLine, startColumn), new DomLocation (endLine, endColumn));
}
public IEnumerable<DomNode> GetNodesBetween (DomLocation start, DomLocation end)
{
DomNode node = this;
while (node != null) {
DomNode next;
if (start <= node.StartLocation && node.EndLocation < end) {
yield return node;
next = node.NextSibling;
} else {
if (node.EndLocation < start) {
next = node.NextSibling;
} else {
next = node.FirstChild;
}
}
if (next != null && next.StartLocation > end)
yield break;
node = next;
}
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitCompilationUnit (this, data); return visitor.VisitCompilationUnit (this, data);
} }

22
ICSharpCode.NRefactory/CSharp/Dom/ComposedType.cs

@ -27,15 +27,22 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class ComposedType : AbstractNode public class ComposedType : DomNode
{ {
public const int NullableRole = 100; public const int NullableRole = 100;
public const int PointerRole = 101; public const int PointerRole = 101;
public const int ArraySpecRole = 102; public const int ArraySpecRole = 102;
public INode BaseType { public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public DomNode BaseType {
get { get {
return GetChildByRole (Roles.ReturnType); return GetChildByRole (Roles.ReturnType);
} }
@ -45,13 +52,18 @@ namespace ICSharpCode.NRefactory.CSharp
get { return GetChildrenByRole (ArraySpecRole).Cast<ArraySpecifier> () ?? new ArraySpecifier[0]; } get { return GetChildrenByRole (ArraySpecRole).Cast<ArraySpecifier> () ?? new ArraySpecifier[0]; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitComposedType (this, data); return visitor.VisitComposedType (this, data);
} }
public class ArraySpecifier : AbstractNode public class ArraySpecifier : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public CSharpTokenNode LBracket { public CSharpTokenNode LBracket {
get { return (CSharpTokenNode)GetChildByRole (Roles.LBracket); } get { return (CSharpTokenNode)GetChildByRole (Roles.LBracket); }
@ -62,7 +74,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return default (S); return default (S);
} }

166
ICSharpCode.NRefactory/CSharp/Dom/AbstractNode.cs → ICSharpCode.NRefactory/CSharp/Dom/DomNode.cs

@ -1,5 +1,5 @@
// //
// AbstractNode.cs // AstNode.cs
// //
// Author: // Author:
// Mike Krüger <mkrueger@novell.com> // Mike Krüger <mkrueger@novell.com>
@ -29,56 +29,42 @@ using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public abstract class AbstractNode : INode public abstract class DomNode
{ {
public static class Roles public static readonly DomNode Null = new NullAstNode ();
class NullAstNode : DomNode
{ {
// some pre defined constants for common roles public override NodeType NodeType {
public const int Identifier = 1; get {
public const int Keyword = 2; return NodeType.Unknown;
public const int Argument = 3; }
public const int Attribute = 4; }
public const int ReturnType = 5;
public const int Modifier = 6;
public const int Body = 7;
public const int Initializer = 8;
public const int Condition = 9;
public const int EmbeddedStatement = 10;
public const int Iterator = 11;
public const int Expression = 12;
public const int Statement = 13;
public const int TargetExpression = 14;
public const int Member = 15;
// some pre defined constants for most used punctuation
public const int LPar = 50; // (
public const int RPar = 51; // )
public const int LBrace = 52; // {
public const int RBrace = 53; // }
public const int LBracket = 54; // [
public const int RBracket = 55; // ]
public const int LChevron = 56; // <
public const int RChevron = 57; // >
public const int Dot = 58; // ,
public const int Comma = 59; // ,
public const int Colon = 60; // :
public const int Semicolon = 61; // ;
public const int QuestionMark = 62; // ?
public const int Assign = 63; // = public override bool IsNull {
get {
return true;
}
}
public const int TypeArgument = 64; public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
public const int Constraint = 65; {
return default (S);
}
}
public abstract NodeType NodeType {
get;
}
public virtual bool IsNull {
get {
return false;
}
} }
public virtual DomLocation StartLocation { public virtual DomLocation StartLocation {
get { get {
INode child = (INode)FirstChild; var child = FirstChild;
if (child == null) if (child == null)
return DomLocation.Empty; return DomLocation.Empty;
return child.StartLocation; return child.StartLocation;
@ -87,14 +73,14 @@ namespace ICSharpCode.NRefactory.CSharp
public virtual DomLocation EndLocation { public virtual DomLocation EndLocation {
get { get {
INode child = (INode)LastChild; var child = LastChild;
if (child == null) if (child == null)
return DomLocation.Empty; return DomLocation.Empty;
return child.EndLocation; return child.EndLocation;
} }
} }
public INode Parent { public DomNode Parent {
get; get;
set; set;
} }
@ -104,29 +90,29 @@ namespace ICSharpCode.NRefactory.CSharp
set; set;
} }
public INode NextSibling { public DomNode NextSibling {
get; get;
set; set;
} }
public INode PrevSibling { public DomNode PrevSibling {
get; get;
set; set;
} }
public INode FirstChild { public DomNode FirstChild {
get; get;
set; set;
} }
public INode LastChild { public DomNode LastChild {
get; get;
set; set;
} }
public IEnumerable<INode> Children { public IEnumerable<DomNode> Children {
get { get {
INode cur = FirstChild; var cur = FirstChild;
while (cur != null) { while (cur != null) {
yield return cur; yield return cur;
cur = cur.NextSibling; cur = cur.NextSibling;
@ -134,29 +120,31 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public INode GetChildByRole (int role) public DomNode GetChildByRole (int role)
{ {
AbstractNode cur = (AbstractNode)FirstChild; var cur = FirstChild;
while (cur != null) { while (cur != null) {
if (cur.Role == role) if (cur.Role == role)
return cur; return cur;
cur = (AbstractNode)cur.NextSibling; cur = cur.NextSibling;
} }
return null; return null;
} }
public IEnumerable<INode> GetChildrenByRole (int role) public IEnumerable<DomNode> GetChildrenByRole (int role)
{ {
AbstractNode cur = (AbstractNode)FirstChild; var cur = FirstChild;
while (cur != null) { while (cur != null) {
if (cur.Role == role) if (cur.Role == role)
yield return cur; yield return cur;
cur = (AbstractNode)cur.NextSibling; cur = cur.NextSibling;
} }
} }
public void AddChild (INode child) public void AddChild (DomNode child)
{ {
if (child == null)
return;
child.Parent = this; child.Parent = this;
if (FirstChild == null) { if (FirstChild == null) {
LastChild = FirstChild = child; LastChild = FirstChild = child;
@ -167,15 +155,20 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public void AddChild (INode child, int role) public void AddChild (DomNode child, int role)
{ {
if (child == null)
return;
child.Role = role; child.Role = role;
AddChild (child); AddChild (child);
} }
public void InsertChildBefore (INode nextSibling, INode child, int role) public void InsertChildBefore (DomNode nextSibling, DomNode child, int role)
{ {
if (nextSibling == null) { if (child == null)
return;
if (FirstChild == null || nextSibling == null) {
AddChild (child, role); AddChild (child, role);
return; return;
} }
@ -187,16 +180,55 @@ namespace ICSharpCode.NRefactory.CSharp
if (nextSibling.PrevSibling != null) { if (nextSibling.PrevSibling != null) {
child.PrevSibling = nextSibling.PrevSibling; child.PrevSibling = nextSibling.PrevSibling;
nextSibling.PrevSibling.NextSibling = child; nextSibling.PrevSibling.NextSibling = child;
} else if (this.FirstChild == nextSibling) {
this.FirstChild = child;
} }
nextSibling.PrevSibling = child; nextSibling.PrevSibling = child;
} }
public virtual S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public abstract S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data);
public static class Roles
{ {
return default(S); // some pre defined constants for common roles
public const int Identifier = 1;
public const int Keyword = 2;
public const int Argument = 3;
public const int Attribute = 4;
public const int ReturnType = 5;
public const int Modifier = 6;
public const int Body = 7;
public const int Initializer = 8;
public const int Condition = 9;
public const int EmbeddedStatement = 10;
public const int Iterator = 11;
public const int Expression = 12;
public const int Statement = 13;
public const int TargetExpression = 14;
public const int Member = 15;
// some pre defined constants for most used punctuation
public const int LPar = 50; // (
public const int RPar = 51; // )
public const int LBrace = 52; // {
public const int RBrace = 53; // }
public const int LBracket = 54; // [
public const int RBracket = 55; // ]
public const int LChevron = 56; // <
public const int RChevron = 57; // >
public const int Dot = 58; // ,
public const int Comma = 59; // ,
public const int Colon = 60; // :
public const int Semicolon = 61; // ;
public const int QuestionMark = 62; // ?
public const int Assign = 63; // =
public const int TypeArgument = 64;
public const int Constraint = 65;
} }
} }
} }

41
ICSharpCode.NRefactory/CSharp/Dom/AbstractDomVisitor.cs → ICSharpCode.NRefactory/CSharp/Dom/DomVisitor.cs

@ -1,5 +1,5 @@
// //
// IDomVisitor.cs // DomVisitor.cs
// //
// Author: // Author:
// Mike Krüger <mkrueger@novell.com> // Mike Krüger <mkrueger@novell.com>
@ -28,11 +28,11 @@ using System;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public abstract class AbstractDomVisitor<T, S> : IDomVisitor<T, S> public abstract class DomVisitor<T, S>
{ {
protected virtual S VisitChildren (INode node, T data) protected virtual S VisitChildren (DomNode node, T data)
{ {
INode child = node.FirstChild; var child = node.FirstChild;
while (child != null) { while (child != null) {
child.AcceptVisitor (this, data); child.AcceptVisitor (this, data);
child = child.NextSibling; child = child.NextSibling;
@ -55,6 +55,11 @@ namespace ICSharpCode.NRefactory.CSharp
return default (S); return default (S);
} }
public virtual S VisitComposedType (ComposedType composedType, T data)
{
return default (S);
}
public virtual S VisitAttribute (Attribute attribute, T data) public virtual S VisitAttribute (Attribute attribute, T data)
{ {
return VisitChildren (attribute, data); return VisitChildren (attribute, data);
@ -77,7 +82,15 @@ namespace ICSharpCode.NRefactory.CSharp
public virtual S VisitTypeDeclaration (TypeDeclaration typeDeclaration, T data) public virtual S VisitTypeDeclaration (TypeDeclaration typeDeclaration, T data)
{ {
return VisitChildren (typeDeclaration, data); foreach (var node in typeDeclaration.GetChildrenByRole (TypeDeclaration.Roles.Member)) {
node.AcceptVisitor (this, data);
}
return default (S);
}
public virtual S VisitEnumDeclaration (EnumDeclaration enumDeclaration, T data)
{
return VisitChildren (enumDeclaration, data);
} }
public virtual S VisitEnumMemberDeclaration (EnumMemberDeclaration enumMemberDeclaration, T data) public virtual S VisitEnumMemberDeclaration (EnumMemberDeclaration enumMemberDeclaration, T data)
@ -345,6 +358,11 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (invocationExpression, data); return VisitChildren (invocationExpression, data);
} }
public virtual S VisitDirectionExpression (DirectionExpression directionExpression, T data)
{
return VisitChildren (directionExpression, data);
}
public virtual S VisitMemberReferenceExpression (MemberReferenceExpression memberReferenceExpression, T data) public virtual S VisitMemberReferenceExpression (MemberReferenceExpression memberReferenceExpression, T data)
{ {
return VisitChildren (memberReferenceExpression, data); return VisitChildren (memberReferenceExpression, data);
@ -360,7 +378,7 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (objectCreateExpression, data); return VisitChildren (objectCreateExpression, data);
} }
public virtual S VisitArrayObjectCreateExpression (ArrayObjectCreateExpression arrayObjectCreateExpression, T data) public virtual S VisitArrayCreateExpression (ArrayCreateExpression arrayObjectCreateExpression, T data)
{ {
return VisitChildren (arrayObjectCreateExpression, data); return VisitChildren (arrayObjectCreateExpression, data);
} }
@ -470,14 +488,9 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (argListExpression, data); return VisitChildren (argListExpression, data);
} }
public virtual S VisitComposedType (ComposedType composedType, T data) public S VisitArrayInitializerExpression (ArrayInitializerExpression arrayInitializerExpression, T data)
{ {
return VisitChildren (composedType, data); return VisitChildren (arrayInitializerExpression, data);
}
public virtual S VisitDirectionExpression (DirectionExpression directionExpression, T data)
{
return VisitChildren (directionExpression, data);
} }
} }
} }

32
ICSharpCode.NRefactory/CSharp/Dom/Expressions/AnonymousMethodExpression.cs

@ -1,4 +1,4 @@
// //
// AnonymousMethodExpression.cs // AnonymousMethodExpression.cs
// //
// Author: // Author:
@ -30,32 +30,42 @@ using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class AnonymousMethodExpression : AbstractNode public class AnonymousMethodExpression : DomNode
{ {
public IEnumerable<ParameterDeclaration> Arguments { public override NodeType NodeType {
get { get {
return base.GetChildrenByRole (Roles.Argument).Cast <ParameterDeclaration>(); return NodeType.Expression;
} }
} }
public IEnumerable<ParameterDeclaration> Parameters { // used to make a difference between delegate {} and delegate () {}
// TODO: Arguments or Parameters ??? public bool HasParameterList {
get { get {
return this.Arguments; return GetChildByRole (Roles.LPar) != null;
} }
} }
public bool HasParameterList { public CSharpTokenNode LPar {
get { return GetChildByRole (Roles.LPar) != null; } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
}
public IEnumerable<ParameterDeclaration> Parameters {
get {
return base.GetChildrenByRole (Roles.Argument).Cast <ParameterDeclaration> ();
}
} }
public BlockStatement Body { public BlockStatement Body {
get { get {
return (BlockStatement)GetChildByRole (Roles.Body); return (BlockStatement)GetChildByRole (Roles.Body) ?? BlockStatement.Null;
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitAnonymousMethodExpression (this, data); return visitor.VisitAnonymousMethodExpression (this, data);
} }

21
ICSharpCode.NRefactory/CSharp/Dom/Expressions/ArgListExpression.cs

@ -24,7 +24,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using ICSharpCode.NRefactory.TypeSystem;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -34,30 +33,36 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary> /// <summary>
/// Represents the undocumented __arglist keyword. /// Represents the undocumented __arglist keyword.
/// </summary> /// </summary>
public class ArgListExpression : AbstractNode public class ArgListExpression : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public bool IsAccess { // access is __arglist, otherwise it's __arlist (a1, a2, ..., an) public bool IsAccess { // access is __arglist, otherwise it's __arlist (a1, a2, ..., an)
get; get;
set; set;
} }
public CSharpTokenNode Keyword { public CSharpTokenNode Keyword {
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); } get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public IEnumerable<INode> Arguments { public IEnumerable<DomNode> Arguments {
get { return GetChildrenByRole (Roles.Argument).Cast<INode> (); } get { return GetChildrenByRole (Roles.Argument); }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitArgListExpression (this, data); return visitor.VisitArgListExpression (this, data);
} }

16
ICSharpCode.NRefactory/CSharp/Dom/Expressions/ArrayObjectCreateExpression.cs → ICSharpCode.NRefactory/CSharp/Dom/Expressions/ArrayCreateExpression.cs

@ -25,19 +25,25 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class ArrayObjectCreateExpression : ObjectCreateExpression public class ArrayCreateExpression : ObjectCreateExpression
{ {
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public CSharpTokenNode Rank { public CSharpTokenNode Rank {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitArrayObjectCreateExpression (this, data); return visitor.VisitArrayCreateExpression (this, data);
} }
} }
} }

45
ICSharpCode.NRefactory/CSharp/Dom/Expressions/ArrayInitializerExpression.cs

@ -0,0 +1,45 @@
//
// ArrayInitializerExpression.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp
{
public class ArrayInitializerExpression : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{
return visitor.VisitArrayInitializerExpression (this, data);
}
}
}

17
ICSharpCode.NRefactory/CSharp/Dom/Expressions/AsExpression.cs

@ -24,21 +24,26 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class AsExpression : AbstractNode public class AsExpression : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public FullTypeName TypeReference { public FullTypeName TypeReference {
get { return (FullTypeName)GetChildByRole (Roles.ReturnType); } get { return (FullTypeName)GetChildByRole (Roles.ReturnType) ?? FullTypeName.Null; }
} }
public INode Expression { public DomNode Expression {
get { return GetChildByRole (Roles.Expression); } get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitAsExpression (this, data); return visitor.VisitAsExpression (this, data);
} }

27
ICSharpCode.NRefactory/CSharp/Dom/Expressions/AssignmentExpression.cs

@ -1,4 +1,4 @@
// //
// AssignmentExpression.cs // AssignmentExpression.cs
// //
// Author: // Author:
@ -25,12 +25,17 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class AssignmentExpression : AbstractNode public class AssignmentExpression : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public const int LeftExpressionRole = 100; public const int LeftExpressionRole = 100;
public const int RightExpressionRole = 101; public const int RightExpressionRole = 101;
public const int OperatorRole = 102; public const int OperatorRole = 102;
@ -40,20 +45,20 @@ namespace ICSharpCode.NRefactory.CSharp
set; set;
} }
public INode Left { public DomNode Left {
get { return GetChildByRole (LeftExpressionRole); } get { return GetChildByRole (LeftExpressionRole) ?? DomNode.Null; }
} }
public INode Right { public DomNode Right {
get { return GetChildByRole (RightExpressionRole); } get { return GetChildByRole (RightExpressionRole) ?? DomNode.Null; }
} }
public CSharpTokenNode Operator { public CSharpTokenNode Operator {
get { return (CSharpTokenNode)GetChildByRole (OperatorRole); } get { return (CSharpTokenNode)GetChildByRole (OperatorRole) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitAssignmentExpression (this, data); return visitor.VisitAssignmentExpression (this, data);
} }
@ -75,12 +80,12 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>left %= right</summary> /// <summary>left %= right</summary>
Modulus, Modulus,
/// <summary>left &lt;&lt;= right</summary> /// <summary>left <<= right</summary>
ShiftLeft, ShiftLeft,
/// <summary>left >>= right</summary> /// <summary>left >>= right</summary>
ShiftRight, ShiftRight,
/// <summary>left &amp;= right</summary> /// <summary>left &= right</summary>
BitwiseAnd, BitwiseAnd,
/// <summary>left |= right</summary> /// <summary>left |= right</summary>
BitwiseOr, BitwiseOr,

11
ICSharpCode.NRefactory/CSharp/Dom/Expressions/BaseReferenceExpression.cs

@ -25,12 +25,17 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class BaseReferenceExpression : AbstractNode public class BaseReferenceExpression : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public DomLocation Location { public DomLocation Location {
get; get;
set; set;
@ -47,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitBaseReferenceExpression (this, data); return visitor.VisitBaseReferenceExpression (this, data);
} }

28
ICSharpCode.NRefactory/CSharp/Dom/Expressions/BinaryOperatorExpression.cs

@ -1,4 +1,4 @@
// //
// BinaryOperatorExpression.cs // BinaryOperatorExpression.cs
// //
// Author: // Author:
@ -25,39 +25,39 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class BinaryOperatorExpression : AbstractNode public class BinaryOperatorExpression : DomNode
{ {
public const int LeftExpressionRole = 100; public const int LeftExpressionRole = 100;
public const int RightExpressionRole = 101; public const int RightExpressionRole = 101;
public const int OperatorRole = 102; public const int OperatorRole = 102;
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public BinaryOperatorType BinaryOperatorType { public BinaryOperatorType BinaryOperatorType {
get; get;
set; set;
} }
[ObsoleteAttribute]
public BinaryOperatorType Op {
get { return this.BinaryOperatorType; }
}
public CSharpTokenNode Operator { public CSharpTokenNode Operator {
get { return (CSharpTokenNode)GetChildByRole (OperatorRole); } get { return (CSharpTokenNode)GetChildByRole (OperatorRole) ?? CSharpTokenNode.Null; }
} }
public INode Left { public DomNode Left {
get { return GetChildByRole (LeftExpressionRole); } get { return GetChildByRole (LeftExpressionRole) ?? DomNode.Null; }
} }
public INode Right { public DomNode Right {
get { return GetChildByRole (RightExpressionRole); } get { return GetChildByRole (RightExpressionRole) ?? DomNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitBinaryOperatorExpression (this, data); return visitor.VisitBinaryOperatorExpression (this, data);
} }

23
ICSharpCode.NRefactory/CSharp/Dom/Expressions/CastExpression.cs

@ -25,29 +25,34 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class CastExpression : AbstractNode public class CastExpression : DomNode
{ {
public INode CastTo { public override NodeType NodeType {
get { return (INode)GetChildByRole (Roles.ReturnType); } get {
return NodeType.Expression;
}
}
public DomNode CastTo {
get { return GetChildByRole (Roles.ReturnType) ?? DomNode.Null; }
} }
public INode Expression { public DomNode Expression {
get { return GetChildByRole (Roles.Expression); } get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitCastExpression (this, data); return visitor.VisitCastExpression (this, data);
} }

19
ICSharpCode.NRefactory/CSharp/Dom/Expressions/CheckedExpression.cs

@ -25,25 +25,30 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class CheckedExpression : AbstractNode public class CheckedExpression : DomNode
{ {
public INode Expression { public override NodeType NodeType {
get { return GetChildByRole (Roles.Expression); } get {
return NodeType.Expression;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitCheckedExpression (this, data); return visitor.VisitCheckedExpression (this, data);
} }

27
ICSharpCode.NRefactory/CSharp/Dom/Expressions/ConditionalExpression.cs

@ -25,39 +25,44 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
/// <summary> /// <summary>
/// cond ? true : false /// cond ? true : false
/// </summary> /// </summary>
public class ConditionalExpression : AbstractNode public class ConditionalExpression : DomNode
{ {
public const int TrueExpressionRole = 100; public const int TrueExpressionRole = 100;
public const int FalseExpressionRole = 101; public const int FalseExpressionRole = 101;
public INode TrueExpression { public override NodeType NodeType {
get { return GetChildByRole (TrueExpressionRole); } get {
return NodeType.Expression;
}
}
public DomNode TrueExpression {
get { return GetChildByRole (TrueExpressionRole) ?? DomNode.Null; }
} }
public INode FalseExpression { public DomNode FalseExpression {
get { return GetChildByRole (FalseExpressionRole); } get { return GetChildByRole (FalseExpressionRole) ?? DomNode.Null; }
} }
public INode Condition { public DomNode Condition {
get { return GetChildByRole (Roles.Condition); } get { return GetChildByRole (Roles.Condition) ?? DomNode.Null; }
} }
public CSharpTokenNode QuestionMark { public CSharpTokenNode QuestionMark {
get { return (CSharpTokenNode)GetChildByRole (Roles.QuestionMark); } get { return (CSharpTokenNode)GetChildByRole (Roles.QuestionMark) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode Colon { public CSharpTokenNode Colon {
get { return (CSharpTokenNode)GetChildByRole (Roles.Colon); } get { return (CSharpTokenNode)GetChildByRole (Roles.Colon) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitConditionalExpression (this, data); return visitor.VisitConditionalExpression (this, data);
} }

12
ICSharpCode.NRefactory/CSharp/Dom/Expressions/DefaultValueExpression.cs

@ -27,13 +27,19 @@ using System;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class DefaultValueExpression : AbstractNode public class DefaultValueExpression : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public FullTypeName TypeReference { public FullTypeName TypeReference {
get { return (FullTypeName)GetChildByRole (Roles.ReturnType); } get { return (FullTypeName)GetChildByRole (Roles.ReturnType) ?? FullTypeName.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitDefaultValueExpression (this, data); return visitor.VisitDefaultValueExpression (this, data);
} }

18
ICSharpCode.NRefactory/CSharp/Dom/Expressions/DirectionExpression.cs

@ -35,8 +35,14 @@ namespace ICSharpCode.NRefactory.CSharp
Ref Ref
} }
public class DirectionExpression : AbstractNode public class DirectionExpression : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public FieldDirection FieldDirection { public FieldDirection FieldDirection {
get; get;
set; set;
@ -44,14 +50,14 @@ namespace ICSharpCode.NRefactory.CSharp
public CSharpTokenNode Keyword { public CSharpTokenNode Keyword {
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); } get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword) ?? CSharpTokenNode.Null; }
} }
public INode Expression { public DomNode Expression {
get { return GetChildByRole (Roles.Expression); } get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitDirectionExpression (this, data); return visitor.VisitDirectionExpression (this, data);
} }

19
ICSharpCode.NRefactory/CSharp/Dom/Expressions/IdentifierExpression.cs

@ -1,4 +1,4 @@
// //
// IdentifierExpression.cs // IdentifierExpression.cs
// //
// Author: // Author:
@ -25,26 +25,31 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class IdentifierExpression : AbstractNode public class IdentifierExpression : DomNode
{ {
public Identifier IdentifierToken { public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public Identifier IdentifierToken {
get { get {
return (Identifier)GetChildByRole (Roles.Identifier); return (Identifier)GetChildByRole (Roles.Identifier) ?? ICSharpCode.NRefactory.CSharp.Identifier.Null;
} }
} }
public string Identifier { public string Identifier {
get { get {
Identifier i = this.IdentifierToken; Identifier i = this.IdentifierToken;
return i != null ? i.Name : null; return !i.IsNull ? i.Name : null;
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitIdentifierExpression (this, data); return visitor.VisitIdentifierExpression (this, data);
} }

21
ICSharpCode.NRefactory/CSharp/Dom/Expressions/IndexerExpression.cs

@ -26,34 +26,39 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class IndexerExpression : AbstractNode public class IndexerExpression : DomNode
{ {
public INode Target { public override NodeType NodeType {
get { return (INode)GetChildByRole (Roles.TargetExpression); } get {
return NodeType.Expression;
}
}
public DomNode Target {
get { return GetChildByRole (Roles.TargetExpression); }
} }
public CSharpTokenNode LBracket { public CSharpTokenNode LBracket {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.LBracket); return (CSharpTokenNode)GetChildByRole (Roles.LBracket) ?? CSharpTokenNode.Null;
} }
} }
public CSharpTokenNode RBracket { public CSharpTokenNode RBracket {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.RBracket); return (CSharpTokenNode)GetChildByRole (Roles.RBracket) ?? CSharpTokenNode.Null;
} }
} }
public IEnumerable<INode> Arguments { public IEnumerable<DomNode> Arguments {
get { return GetChildrenByRole (Roles.Argument); } get { return GetChildrenByRole (Roles.Argument); }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitIndexerExpression (this, data); return visitor.VisitIndexerExpression (this, data);
} }

24
ICSharpCode.NRefactory/CSharp/Dom/Expressions/InvocationExpression.cs

@ -26,30 +26,36 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class InvocationExpression : AbstractNode public class InvocationExpression : DomNode
{ {
public INode Target { public override NodeType NodeType {
get { return GetChildByRole (Roles.TargetExpression); } get {
return NodeType.Expression;
}
}
public DomNode Target {
get { return GetChildByRole (Roles.TargetExpression) ?? DomNode.Null; }
} }
public IEnumerable<INode> Arguments { public IEnumerable<DomNode> Arguments {
get { return GetChildrenByRole (Roles.Argument).Cast<INode> (); } get { return GetChildrenByRole (Roles.Argument); }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitInvocationExpression (this, data); return visitor.VisitInvocationExpression (this, data);
} }

21
ICSharpCode.NRefactory/CSharp/Dom/Expressions/IsExpression.cs

@ -1,4 +1,4 @@
// //
// TypeOfIsExpression.cs // TypeOfIsExpression.cs
// //
// Author: // Author:
@ -24,21 +24,26 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class IsExpression : AbstractNode public class IsExpression : DomNode
{ {
public INode TypeReference { public override NodeType NodeType {
get { return GetChildByRole (Roles.ReturnType); } get {
return NodeType.Expression;
}
}
public FullTypeName TypeReference {
get { return (FullTypeName)GetChildByRole (Roles.ReturnType) ?? FullTypeName.Null; }
} }
public INode Expression { public DomNode Expression {
get { return GetChildByRole (Roles.Expression); } get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitIsExpression (this, data); return visitor.VisitIsExpression (this, data);
} }

22
ICSharpCode.NRefactory/CSharp/Dom/Expressions/LambdaExpression.cs

@ -1,4 +1,4 @@
// //
// LambdaExpression.cs // LambdaExpression.cs
// //
// Author: // Author:
@ -29,9 +29,15 @@ using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class LambdaExpression : AbstractNode public class LambdaExpression : DomNode
{ {
public IEnumerable<ParameterDeclaration> Arguments { public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public IEnumerable<ParameterDeclaration> Parameters {
get { get {
return base.GetChildrenByRole (Roles.Argument).Cast <ParameterDeclaration>(); return base.GetChildrenByRole (Roles.Argument).Cast <ParameterDeclaration>();
} }
@ -39,23 +45,23 @@ namespace ICSharpCode.NRefactory.CSharp
public BlockStatement Body { public BlockStatement Body {
get { get {
return (BlockStatement)GetChildByRole (Roles.Body); return (BlockStatement)GetChildByRole (Roles.Body) ?? BlockStatement.Null;
} }
} }
public CSharpTokenNode Arrow { public CSharpTokenNode Arrow {
get { return (CSharpTokenNode)GetChildByRole (Roles.Assign); } get { return (CSharpTokenNode)GetChildByRole (Roles.Assign) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitLambdaExpression (this, data); return visitor.VisitLambdaExpression (this, data);
} }

25
ICSharpCode.NRefactory/CSharp/Dom/Expressions/MemberReferenceExpression.cs

@ -1,4 +1,4 @@
// //
// MemberReferenceExpression.cs // MemberReferenceExpression.cs
// //
// Author: // Author:
@ -26,34 +26,39 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class MemberReferenceExpression : AbstractNode public class MemberReferenceExpression : DomNode
{ {
public INode Target { public override NodeType NodeType {
get { return GetChildByRole (Roles.TargetExpression); } get {
return NodeType.Expression;
}
}
public DomNode Target {
get { return GetChildByRole (Roles.TargetExpression) ?? DomNode.Null; }
} }
public Identifier Identifier { public Identifier Identifier {
get { get {
return (Identifier)GetChildByRole (Roles.Identifier); return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null;
} }
} }
public string MemberName { public string MemberName {
get { get {
return this.Identifier.Name; return this.Identifier.Name;
} }
} }
public IEnumerable<INode> TypeArguments { public IEnumerable<DomNode> TypeArguments {
get { return GetChildrenByRole (Roles.TypeArgument).Cast<INode> (); } get { return GetChildrenByRole (Roles.TypeArgument); }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitMemberReferenceExpression (this, data); return visitor.VisitMemberReferenceExpression (this, data);
} }

11
ICSharpCode.NRefactory/CSharp/Dom/Expressions/NullReferenceExpression.cs

@ -25,13 +25,18 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class NullReferenceExpression : AbstractNode public class NullReferenceExpression : DomNode
{ {
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitNullReferenceExpression (this, data); return visitor.VisitNullReferenceExpression (this, data);
} }

21
ICSharpCode.NRefactory/CSharp/Dom/Expressions/ObjectCreateExpression.cs

@ -25,30 +25,35 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class ObjectCreateExpression : AbstractNode public class ObjectCreateExpression : DomNode
{ {
public INode Type { public override NodeType NodeType {
get { return (INode)GetChildByRole (Roles.ReturnType); } get {
return NodeType.Expression;
}
}
public DomNode Type {
get { return GetChildByRole (Roles.ReturnType) ?? DomNode.Null; }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public IEnumerable<INode> Arguments { public IEnumerable<DomNode> Arguments {
get { return GetChildrenByRole (Roles.Argument); } get { return GetChildrenByRole (Roles.Argument); }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitObjectCreateExpression (this, data); return visitor.VisitObjectCreateExpression (this, data);
} }

19
ICSharpCode.NRefactory/CSharp/Dom/Expressions/ParenthesizedExpression.cs

@ -25,25 +25,30 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class ParenthesizedExpression : AbstractNode public class ParenthesizedExpression : DomNode
{ {
public INode Expression { public override NodeType NodeType {
get { return GetChildByRole (Roles.Expression); } get {
return NodeType.Expression;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitParenthesizedExpression (this, data); return visitor.VisitParenthesizedExpression (this, data);
} }

13
ICSharpCode.NRefactory/CSharp/Dom/Expressions/PointerReferenceExpression.cs

@ -26,7 +26,6 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
@ -36,8 +35,14 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary> /// </summary>
public class PointerReferenceExpression : MemberReferenceExpression public class PointerReferenceExpression : MemberReferenceExpression
{ {
public INode Expression { public override NodeType NodeType {
get { return GetChildByRole (Roles.TargetExpression); } get {
return NodeType.Expression;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.TargetExpression) ?? DomNode.Null; }
} }
public string Dim { public string Dim {
@ -45,7 +50,7 @@ namespace ICSharpCode.NRefactory.CSharp
set; set;
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitPointerReferenceExpression (this, data); return visitor.VisitPointerReferenceExpression (this, data);
} }

11
ICSharpCode.NRefactory/CSharp/Dom/Expressions/PrimitiveExpression.cs

@ -25,12 +25,17 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class PrimitiveExpression : AbstractNode public class PrimitiveExpression : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
DomLocation startLocation; DomLocation startLocation;
public override DomLocation StartLocation { public override DomLocation StartLocation {
get { get {
@ -58,7 +63,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitPrimitiveExpression (this, data); return visitor.VisitPrimitiveExpression (this, data);
} }

116
ICSharpCode.NRefactory/CSharp/Dom/Expressions/QueryExpression.cs

@ -27,18 +27,23 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class QueryExpressionFromClause : AbstractNode public class QueryExpressionFromClause : DomNode
{ {
public const int FromKeywordRole = 100; public const int FromKeywordRole = 100;
public const int InKeywordRole = 101; public const int InKeywordRole = 101;
public INode Type { public override NodeType NodeType {
get { get {
return (INode)GetChildByRole (Roles.ReturnType); return NodeType.Expression;
}
}
public DomNode Type {
get {
return GetChildByRole (Roles.ReturnType) ?? DomNode.Null;
} }
} }
@ -50,15 +55,15 @@ namespace ICSharpCode.NRefactory.CSharp
public Identifier QueryIdentifier { public Identifier QueryIdentifier {
get { get {
return (Identifier)GetChildByRole (Roles.Identifier); return (Identifier)GetChildByRole (Roles.Identifier) ?? ICSharpCode.NRefactory.CSharp.Identifier.Null;
} }
} }
public INode Expression { public DomNode Expression {
get { return GetChildByRole (Roles.Expression); } get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitQueryExpressionFromClause (this, data); return visitor.VisitQueryExpressionFromClause (this, data);
} }
@ -93,13 +98,13 @@ namespace ICSharpCode.NRefactory.CSharp
} }
public INode OnExpression { public DomNode OnExpression {
get { get {
return GetChildByRole (OnExpressionRole); return GetChildByRole (OnExpressionRole);
} }
} }
public INode EqualsExpression { public DomNode EqualsExpression {
get { get {
return GetChildByRole (EqualsExpressionRole); return GetChildByRole (EqualsExpressionRole);
} }
@ -117,21 +122,26 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public INode InExpression { public DomNode InExpression {
get { get {
return (INode)GetChildByRole (Roles.Expression); return GetChildByRole (Roles.Expression);
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitQueryExpressionJoinClause (this, data); return visitor.VisitQueryExpressionJoinClause (this, data);
} }
} }
public class QueryExpressionGroupClause : AbstractNode public class QueryExpressionGroupClause : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public const int ProjectionExpressionRole = 100; public const int ProjectionExpressionRole = 100;
public const int GroupByExpressionRole = 101; public const int GroupByExpressionRole = 101;
@ -146,26 +156,32 @@ namespace ICSharpCode.NRefactory.CSharp
get { return (CSharpTokenNode)GetChildByRole (ByKeywordRole); } get { return (CSharpTokenNode)GetChildByRole (ByKeywordRole); }
} }
public INode Projection { public DomNode Projection {
get { get {
return GetChildByRole (ProjectionExpressionRole); return GetChildByRole (ProjectionExpressionRole);
} }
} }
public INode GroupBy { public DomNode GroupBy {
get { get {
return GetChildByRole (GroupByExpressionRole); return GetChildByRole (GroupByExpressionRole);
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitQueryExpressionGroupClause (this, data); return visitor.VisitQueryExpressionGroupClause (this, data);
} }
} }
public class QueryExpressionLetClause : AbstractNode public class QueryExpressionLetClause : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string Identifier { public string Identifier {
get { get {
return QueryIdentifier.Name; return QueryIdentifier.Name;
@ -178,7 +194,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public INode Expression { public DomNode Expression {
get { get {
return GetChildByRole (Roles.Expression); return GetChildByRole (Roles.Expression);
} }
@ -188,28 +204,34 @@ namespace ICSharpCode.NRefactory.CSharp
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); } get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); }
} }
public INode Assign { public DomNode Assign {
get { get {
return (INode)GetChildByRole (Roles.Assign); return GetChildByRole (Roles.Assign);
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitQueryExpressionLetClause (this, data); return visitor.VisitQueryExpressionLetClause (this, data);
} }
} }
public class QueryExpressionOrderClause : AbstractNode public class QueryExpressionOrderClause : DomNode
{ {
public const int OrderingRole = 100; public const int OrderingRole = 100;
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public bool OrderAscending { public bool OrderAscending {
get; get;
set; set;
} }
public INode Expression { public DomNode Expression {
get { get {
return GetChildByRole (Roles.Expression); return GetChildByRole (Roles.Expression);
} }
@ -219,27 +241,32 @@ namespace ICSharpCode.NRefactory.CSharp
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); } get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); }
} }
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitQueryExpressionOrderClause (this, data); return visitor.VisitQueryExpressionOrderClause (this, data);
} }
} }
public class QueryExpressionOrdering : AbstractNode public class QueryExpressionOrdering : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public QueryExpressionOrderingDirection Direction { public QueryExpressionOrderingDirection Direction {
get; get;
set; set;
} }
public INode Criteria { public DomNode Criteria {
get { get {
return GetChildByRole (Roles.Expression); return GetChildByRole (Roles.Expression);
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitQueryExpressionOrdering (this, data); return visitor.VisitQueryExpressionOrdering (this, data);
} }
@ -252,40 +279,53 @@ namespace ICSharpCode.NRefactory.CSharp
Descending Descending
} }
public class QueryExpressionSelectClause : AbstractNode public class QueryExpressionSelectClause : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public CSharpTokenNode SelectKeyword { public CSharpTokenNode SelectKeyword {
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); } get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); }
} }
public INode Projection { public DomNode Projection {
get { get {
return (INode)GetChildByRole (Roles.Expression); return GetChildByRole (Roles.Expression);
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitQueryExpressionSelectClause (this, data); return visitor.VisitQueryExpressionSelectClause (this, data);
} }
} }
public class QueryExpressionWhereClause : AbstractNode public class QueryExpressionWhereClause : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public CSharpTokenNode WhereKeyword { public CSharpTokenNode WhereKeyword {
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); } get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); }
} }
public INode Condition { public DomNode Condition {
get { get {
return (INode)GetChildByRole (Roles.Condition); return GetChildByRole (Roles.Condition);
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitQueryExpressionWhereClause (this, data); return visitor.VisitQueryExpressionWhereClause (this, data);
} }
} }
} }

17
ICSharpCode.NRefactory/CSharp/Dom/Expressions/SizeOfExpression.cs

@ -24,27 +24,32 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class SizeOfExpression : AbstractNode public class SizeOfExpression : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public FullTypeName Type { public FullTypeName Type {
get { get {
return (FullTypeName)GetChildByRole (Roles.ReturnType); return (FullTypeName)GetChildByRole (Roles.ReturnType) ?? FullTypeName.Null;
} }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitSizeOfExpression (this, data); return visitor.VisitSizeOfExpression (this, data);
} }

23
ICSharpCode.NRefactory/CSharp/Dom/Expressions/StackAllocExpression.cs

@ -25,43 +25,48 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class StackAllocExpression : AbstractNode public class StackAllocExpression : DomNode
{ {
public const int StackAllocKeywordRole = 100; public const int StackAllocKeywordRole = 100;
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public FullTypeName Type { public FullTypeName Type {
get { get {
return (FullTypeName)GetChildByRole (Roles.ReturnType); return (FullTypeName)GetChildByRole (Roles.ReturnType) ?? FullTypeName.Null;
} }
} }
public INode CountExpression { public DomNode CountExpression {
get { return (INode)GetChildByRole (Roles.Expression); } get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public CSharpTokenNode StackAllocKeyword { public CSharpTokenNode StackAllocKeyword {
get { get {
return (CSharpTokenNode)GetChildByRole (StackAllocKeywordRole); return (CSharpTokenNode)GetChildByRole (StackAllocKeywordRole) ?? CSharpTokenNode.Null;
} }
} }
public CSharpTokenNode LBracket { public CSharpTokenNode LBracket {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.LBracket); return (CSharpTokenNode)GetChildByRole (Roles.LBracket) ?? CSharpTokenNode.Null;
} }
} }
public CSharpTokenNode RBracket { public CSharpTokenNode RBracket {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.RBracket); return (CSharpTokenNode)GetChildByRole (Roles.RBracket) ?? CSharpTokenNode.Null;
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitStackAllocExpression (this, data); return visitor.VisitStackAllocExpression (this, data);
} }

11
ICSharpCode.NRefactory/CSharp/Dom/Expressions/ThisReferenceExpression.cs

@ -25,17 +25,22 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class ThisReferenceExpression : AbstractNode public class ThisReferenceExpression : DomNode
{ {
public DomLocation Location { public DomLocation Location {
get; get;
set; set;
} }
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public override DomLocation StartLocation { public override DomLocation StartLocation {
get { get {
return Location; return Location;
@ -48,7 +53,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitThisReferenceExpression (this, data); return visitor.VisitThisReferenceExpression (this, data);
} }

17
ICSharpCode.NRefactory/CSharp/Dom/Expressions/TypeOfExpression.cs

@ -25,27 +25,32 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class TypeOfExpression : AbstractNode public class TypeOfExpression : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public FullTypeName Type { public FullTypeName Type {
get { get {
return (FullTypeName)GetChildByRole (Roles.ReturnType); return (FullTypeName)GetChildByRole (Roles.ReturnType) ?? FullTypeName.Null;
} }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitTypeOfExpression (this, data); return visitor.VisitTypeOfExpression (this, data);
} }

19
ICSharpCode.NRefactory/CSharp/Dom/Expressions/UnaryOperatorExpression.cs

@ -1,4 +1,4 @@
// //
// UnaryOperatorExpression.cs // UnaryOperatorExpression.cs
// //
// Author: // Author:
@ -25,24 +25,29 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class UnaryOperatorExpression : AbstractNode public class UnaryOperatorExpression : DomNode
{ {
public const int Operator = 100; public const int Operator = 100;
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public UnaryOperatorType UnaryOperatorType { public UnaryOperatorType UnaryOperatorType {
get; get;
set; set;
} }
public INode Expression { public DomNode Expression {
get { return GetChildByRole (Roles.Expression); } get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitUnaryOperatorExpression (this, data); return visitor.VisitUnaryOperatorExpression (this, data);
} }
@ -68,7 +73,7 @@ namespace ICSharpCode.NRefactory.CSharp
PostDecrement, PostDecrement,
/// <summary>Dereferencing (*a)</summary> /// <summary>Dereferencing (*a)</summary>
Dereference, Dereference,
/// <summary>Get address (&amp;a)</summary> /// <summary>Get address (&a)</summary>
AddressOf AddressOf
} }

20
ICSharpCode.NRefactory/CSharp/Dom/Expressions/UncheckedExpression.cs

@ -25,24 +25,30 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class UncheckedExpression : AbstractNode public class UncheckedExpression : DomNode
{ {
public INode Expression { public override NodeType NodeType {
get { return GetChildByRole (Roles.Expression); } get {
return NodeType.Expression;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data)
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitUncheckedExpression (this, data); return visitor.VisitUncheckedExpression (this, data);
} }

30
ICSharpCode.NRefactory/CSharp/Dom/FullTypeName.cs

@ -24,25 +24,45 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class FullTypeName : AbstractNode public class FullTypeName : DomNode
{ {
public static readonly new FullTypeName Null = new NullFullTypeName ();
class NullFullTypeName : FullTypeName
{
public override bool IsNull {
get {
return true;
}
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{
return default (S);
}
}
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public Identifier Identifier { public Identifier Identifier {
get { get {
return (Identifier)GetChildByRole (Roles.Identifier); return (Identifier)GetChildByRole (Roles.Identifier);
} }
} }
public IEnumerable<INode> TypeArguments { public IEnumerable<DomNode> TypeArguments {
get { return GetChildrenByRole (Roles.TypeArgument).Cast<INode> (); } get { return GetChildrenByRole (Roles.TypeArgument) ?? new DomNode[0]; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitFullTypeName (this, data); return visitor.VisitFullTypeName (this, data);
} }

15
ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/Attribute.cs

@ -26,13 +26,18 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class Attribute : AbstractNode public class Attribute : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string Name { public string Name {
get { get {
return NameIdentifier.QualifiedName; return NameIdentifier.QualifiedName;
@ -46,13 +51,13 @@ namespace ICSharpCode.NRefactory.CSharp
} }
// Todo: Arguments should not be nodes, instead it should be expressions, change when it's implemented. // Todo: Arguments should not be nodes, instead it should be expressions, change when it's implemented.
public IEnumerable<INode> Arguments { public IEnumerable<DomNode> Arguments {
get { get {
return base.GetChildrenByRole (Roles.Argument).Cast <INode>(); return base.GetChildrenByRole (Roles.Argument);
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitAttribute (this, data); return visitor.VisitAttribute (this, data);
} }

15
ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/AttributeSection.cs

@ -1,4 +1,4 @@
// //
// AttributeSection.cs // AttributeSection.cs
// //
// Author: // Author:
@ -26,29 +26,34 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class AttributeSection : AbstractNode public class AttributeSection : DomNode
{ {
const int TargetRole = 101; const int TargetRole = 101;
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public AttributeTarget AttributeTarget { public AttributeTarget AttributeTarget {
get; get;
set; set;
} }
public Identifier TargetIdentifier { public Identifier TargetIdentifier {
get { return (Identifier)GetChildByRole (TargetRole); } get { return (Identifier)GetChildByRole (TargetRole) ?? Identifier.Null; }
} }
public IEnumerable<Attribute> Attributes { public IEnumerable<Attribute> Attributes {
get { return base.GetChildrenByRole (Roles.Attribute).Cast<Attribute> (); } get { return base.GetChildrenByRole (Roles.Attribute).Cast<Attribute> (); }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitAttributeSection (this, data); return visitor.VisitAttributeSection (this, data);
} }

22
ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/Constraint.cs

@ -26,30 +26,36 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class Constraint : AbstractNode public class Constraint : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public CSharpTokenNode WhereKeyword { public CSharpTokenNode WhereKeyword {
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); } get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword) ?? CSharpTokenNode.Null; }
} }
public Identifier TypeParameter { public Identifier TypeParameter {
get { return (Identifier)GetChildByRole (Roles.Identifier); } get { return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null; }
} }
public CSharpTokenNode Colon { public CSharpTokenNode Colon {
get { return (CSharpTokenNode)GetChildByRole (Roles.Colon); } get { return (CSharpTokenNode)GetChildByRole (Roles.Colon) ?? CSharpTokenNode.Null; }
} }
public IEnumerable<INode> TypeArguments { public IEnumerable<DomNode> TypeParameters {
get { return GetChildrenByRole (Roles.TypeArgument).Cast<INode> (); } get { return GetChildrenByRole (Roles.TypeArgument); }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitConstraint (this, data); return visitor.VisitConstraint (this, data);
} }

36
ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/DelegateDeclaration.cs

@ -1,4 +1,4 @@
// //
// DelegateDeclaration.cs // DelegateDeclaration.cs
// //
// Author: // Author:
@ -26,13 +26,18 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class DelegateDeclaration : AbstractMemberBase public class DelegateDeclaration : AbstractMemberBase
{ {
public override NodeType NodeType {
get {
return NodeType.Type;
}
}
public string Name { public string Name {
get { get {
return NameIdentifier.Name; return NameIdentifier.Name;
@ -41,28 +46,37 @@ namespace ICSharpCode.NRefactory.CSharp
public Identifier NameIdentifier { public Identifier NameIdentifier {
get { get {
return (Identifier)GetChildByRole (Roles.Identifier); return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null;
} }
} }
public INode ReturnType { public DomNode ReturnType {
get { get {
return (INode)GetChildByRole (Roles.ReturnType); return GetChildByRole (Roles.ReturnType) ?? DomNode.Null;
} }
} }
// TODO: call this Parameters or Arguments? public IEnumerable<ParameterDeclaration> Parameters {
public IEnumerable<ParameterDeclaration> Parameters { get {
get { return this.Arguments; } return base.GetChildrenByRole (Roles.Argument).Cast <ParameterDeclaration> ();
}
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public IEnumerable<ParameterDeclaration> Arguments { public IEnumerable<AttributeSection> Attributes {
get { get {
return base.GetChildrenByRole (Roles.Argument).Cast <ParameterDeclaration>(); return base.GetChildrenByRole (Roles.Attribute).Cast <AttributeSection>();
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitDelegateDeclaration (this, data); return visitor.VisitDelegateDeclaration (this, data);
} }

54
ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/EnumDeclaration.cs

@ -1,4 +1,4 @@
// //
// EnumDeclaration.cs // EnumDeclaration.cs
// //
// Author: // Author:
@ -26,13 +26,53 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class EnumMemberDeclaration : AbstractMemberBase public class EnumDeclaration : TypeDeclaration
{
public override NodeType NodeType {
get {
return NodeType.Type;
}
}
const int EnumMemberDeclarationRole = 100;
public IEnumerable<EnumMemberDeclaration> Members {
get {
return base.GetChildrenByRole (EnumMemberDeclarationRole).Cast <EnumMemberDeclaration>();
}
}
public override ClassType ClassType {
get {
return ClassType.Enum;
}
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{
return visitor.VisitEnumDeclaration (this, data);
}
}
public class EnumMemberDeclaration : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Member;
}
}
public IEnumerable<AttributeSection> Attributes {
get {
return base.GetChildrenByRole (Roles.Attribute).Cast <AttributeSection>();
}
}
public string Name { public string Name {
get { get {
return NameIdentifier.Name; return NameIdentifier.Name;
@ -41,17 +81,17 @@ namespace ICSharpCode.NRefactory.CSharp
public Identifier NameIdentifier { public Identifier NameIdentifier {
get { get {
return (Identifier)GetChildByRole (Roles.Identifier); return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null;
} }
} }
public INode Initializer { public DomNode Initializer {
get { get {
return GetChildByRole (Roles.Initializer); return GetChildByRole (Roles.Initializer) ?? DomNode.Null;
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitEnumMemberDeclaration (this, data); return visitor.VisitEnumMemberDeclaration (this, data);
} }

27
ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/NamespaceDeclaration.cs

@ -1,4 +1,4 @@
// //
// NamespaceDeclaration.cs // NamespaceDeclaration.cs
// //
// Author: // Author:
@ -26,12 +26,17 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class NamespaceDeclaration : AbstractNode public class NamespaceDeclaration : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string Name { public string Name {
get { get {
return NameIdentifier.QualifiedName; return NameIdentifier.QualifiedName;
@ -47,13 +52,25 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public CSharpTokenNode LBrace {
get {
return (CSharpTokenNode)GetChildByRole (Roles.LBrace) ?? CSharpTokenNode.Null;
}
}
public CSharpTokenNode RBrace {
get {
return (CSharpTokenNode)GetChildByRole (Roles.RBrace) ?? CSharpTokenNode.Null;
}
}
public QualifiedIdentifier NameIdentifier { public QualifiedIdentifier NameIdentifier {
get { get {
return (QualifiedIdentifier)GetChildByRole (Roles.Identifier); return (QualifiedIdentifier)GetChildByRole (Roles.Identifier);
} }
} }
public IEnumerable<INode> Members { public IEnumerable<DomNode> Members {
get { return GetChildrenByRole(Roles.Member); } get { return GetChildrenByRole(Roles.Member); }
} }
@ -66,7 +83,7 @@ namespace ICSharpCode.NRefactory.CSharp
return name1 + "." + name2; return name1 + "." + name2;
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitNamespaceDeclaration (this, data); return visitor.VisitNamespaceDeclaration (this, data);
} }

31
ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/TypeDeclaration.cs

@ -1,4 +1,4 @@
// //
// TypeDeclaration.cs // TypeDeclaration.cs
// //
// Author: // Author:
@ -35,28 +35,27 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
public const int TypeKeyword = 100; public const int TypeKeyword = 100;
public Identifier NameIdentifier { public override NodeType NodeType {
get { get {
return (Identifier)GetChildByRole (Roles.Identifier); return NodeType.Type;
} }
} }
public string Name { public Identifier NameIdentifier {
get { get {
return NameIdentifier.Name; return (Identifier)GetChildByRole (Roles.Identifier);
} }
} }
public IEnumerable<AbstractMemberBase> Members { public string Name {
get { get {
return GetChildrenByRole (Roles.Member).Cast<AbstractMemberBase> (); return NameIdentifier.Name;
} }
} }
// TODO: rename to TypeParameters, more specific return type public IEnumerable<DomNode> TypeParameters {
public IEnumerable<INode> TypeArguments {
get { get {
return GetChildrenByRole (Roles.TypeArgument).Cast<INode> (); return GetChildrenByRole (Roles.TypeArgument);
} }
} }
@ -68,13 +67,13 @@ namespace ICSharpCode.NRefactory.CSharp
public CSharpTokenNode LBrace { public CSharpTokenNode LBrace {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.LBrace); return (CSharpTokenNode)GetChildByRole (Roles.LBrace) ?? CSharpTokenNode.Null;
} }
} }
public CSharpTokenNode RBrace { public CSharpTokenNode RBrace {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.RBrace); return (CSharpTokenNode)GetChildByRole (Roles.RBrace) ?? CSharpTokenNode.Null;
} }
} }
@ -83,7 +82,13 @@ namespace ICSharpCode.NRefactory.CSharp
set; set;
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public IEnumerable<AbstractMemberBase> Members {
get {
return GetChildrenByRole (Roles.Member).Cast<AbstractMemberBase> ();
}
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitTypeDeclaration (this, data); return visitor.VisitTypeDeclaration (this, data);
} }

19
ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/UsingAliasDeclaration.cs

@ -1,4 +1,4 @@
// //
// UsingAliasDeclaration.cs // UsingAliasDeclaration.cs
// //
// Author: // Author:
@ -30,22 +30,27 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
public class UsingAliasDeclaration : UsingDeclaration public class UsingAliasDeclaration : UsingDeclaration
{ {
public const int Assignment = 103; public const int AliasRole = 100;
public const int AliasRole = 104;
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string Alias { public string Alias {
get { get {
return AliasIdentifier.Name; return AliasIdentifier.QualifiedName;
} }
} }
public Identifier AliasIdentifier { public QualifiedIdentifier AliasIdentifier {
get { get {
return (Identifier)GetChildByRole (AliasRole); return (QualifiedIdentifier)GetChildByRole (AliasRole);
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitUsingAliasDeclaration (this, data); return visitor.VisitUsingAliasDeclaration (this, data);
} }

11
ICSharpCode.NRefactory/CSharp/Dom/GeneralScope/UsingDeclaration.cs

@ -25,12 +25,17 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class UsingDeclaration : AbstractNode public class UsingDeclaration : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string Namespace { public string Namespace {
get { get {
return NameIdentifier.QualifiedName; return NameIdentifier.QualifiedName;
@ -43,7 +48,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitUsingDeclaration (this, data); return visitor.VisitUsingDeclaration (this, data);
} }

140
ICSharpCode.NRefactory/CSharp/Dom/IDomVisitor.cs

@ -1,140 +0,0 @@
//
// IDomVisitor.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp
{
public interface IDomVisitor<T, S>
{
S VisitCompilationUnit (CompilationUnit unit, T data);
#region General scope
S VisitAttribute (Attribute attribute, T data);
S VisitAttributeSection (AttributeSection attributeSection, T data);
S VisitDelegateDeclaration (DelegateDeclaration delegateDeclaration, T data);
S VisitNamespaceDeclaration (NamespaceDeclaration namespaceDeclaration, T data);
S VisitTypeDeclaration (TypeDeclaration typeDeclaration, T data);
S VisitEnumMemberDeclaration (EnumMemberDeclaration enumMemberDeclaration, T data);
S VisitUsingDeclaration (UsingDeclaration usingDeclaration, T data);
S VisitUsingAliasDeclaration (UsingAliasDeclaration usingDeclaration, T data);
S VisitFullTypeName (FullTypeName fullTypeName, T data);
S VisitIdentifier (Identifier identifier, T data);
S VisitParameterDeclaration (ParameterDeclaration parameterDeclaration, T data);
S VisitConstraint (Constraint constraint, T data);
S VisitComposedType (ComposedType composedType, T data);
#endregion
#region Type members
S VisitConstructorDeclaration (ConstructorDeclaration constructorDeclaration, T data);
S VisitConstructorInitializer (ConstructorInitializer constructorInitializer, T data);
S VisitDestructorDeclaration (DestructorDeclaration destructorDeclaration, T data);
S VisitEventDeclaration (EventDeclaration eventDeclaration, T data);
S VisitFieldDeclaration (FieldDeclaration fieldDeclaration, T data);
S VisitIndexerDeclaration (IndexerDeclaration indexerDeclaration, T data);
S VisitMethodDeclaration (MethodDeclaration methodDeclaration, T data);
S VisitOperatorDeclaration (OperatorDeclaration operatorDeclaration, T data);
S VisitPropertyDeclaration (PropertyDeclaration propertyDeclaration, T data);
S VisitAccessorDeclaration (Accessor accessorDeclaration, T data);
S VisitVariableInitializer (VariableInitializer variableInitializer, T data);
#endregion
#region Statements
S VisitBlockStatement (BlockStatement blockStatement, T data);
S VisitExpressionStatement (ExpressionStatement expressionStatement, T data);
S VisitBreakStatement (BreakStatement breakStatement, T data);
S VisitCheckedStatement (CheckedStatement checkedStatement, T data);
S VisitContinueStatement (ContinueStatement continueStatement, T data);
S VisitEmptyStatement (EmptyStatement emptyStatement, T data);
S VisitFixedStatement (FixedStatement fixedStatement, T data);
S VisitForeachStatement (ForeachStatement foreachStatement, T data);
S VisitForStatement (ForStatement forStatement, T data);
S VisitGotoStatement (GotoStatement gotoStatement, T data);
S VisitIfElseStatement (IfElseStatement ifElseStatement, T data);
S VisitLabelStatement (LabelStatement labelStatement, T data);
S VisitLockStatement (LockStatement lockStatement, T data);
S VisitReturnStatement (ReturnStatement returnStatement, T data);
S VisitSwitchStatement (SwitchStatement switchStatement, T data);
S VisitSwitchSection (SwitchSection switchSection, T data);
S VisitCaseLabel (CaseLabel caseLabel, T data);
S VisitThrowStatement (ThrowStatement throwStatement, T data);
S VisitTryCatchStatement (TryCatchStatement tryCatchStatement, T data);
S VisitCatchClause (CatchClause catchClause, T data);
S VisitUncheckedStatement (UncheckedStatement uncheckedStatement, T data);
S VisitUnsafeStatement (UnsafeStatement unsafeStatement, T data);
S VisitUsingStatement (UsingStatement usingStatement, T data);
S VisitVariableDeclarationStatement (VariableDeclarationStatement variableDeclarationStatement, T data);
S VisitWhileStatement (WhileStatement whileStatement, T data);
S VisitYieldStatement (YieldStatement yieldStatement, T data);
#endregion
#region Expressions
S VisitAnonymousMethodExpression (AnonymousMethodExpression anonymousMethodExpression, T data);
S VisitLambdaExpression (LambdaExpression lambdaExpression, T data);
S VisitAssignmentExpression (AssignmentExpression assignmentExpression, T data);
S VisitBaseReferenceExpression (BaseReferenceExpression baseReferenceExpression, T data);
S VisitBinaryOperatorExpression (BinaryOperatorExpression binaryOperatorExpression, T data);
S VisitCastExpression (CastExpression castExpression, T data);
S VisitCheckedExpression (CheckedExpression checkedExpression, T data);
S VisitConditionalExpression (ConditionalExpression conditionalExpression, T data);
S VisitIdentifierExpression (IdentifierExpression identifierExpression, T data);
S VisitIndexerExpression (IndexerExpression indexerExpression, T data);
S VisitInvocationExpression (InvocationExpression invocationExpression, T data);
S VisitDirectionExpression (DirectionExpression directionExpression, T data);
S VisitMemberReferenceExpression (MemberReferenceExpression memberReferenceExpression, T data);
S VisitNullReferenceExpression (NullReferenceExpression nullReferenceExpression, T data);
S VisitObjectCreateExpression (ObjectCreateExpression objectCreateExpression, T data);
S VisitArrayObjectCreateExpression (ArrayObjectCreateExpression arrayObjectCreateExpression, T data);
S VisitParenthesizedExpression (ParenthesizedExpression parenthesizedExpression, T data);
S VisitPointerReferenceExpression (PointerReferenceExpression pointerReferenceExpression, T data);
S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data);
S VisitSizeOfExpression (SizeOfExpression sizeOfExpression, T data);
S VisitStackAllocExpression (StackAllocExpression stackAllocExpression, T data);
S VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, T data);
S VisitTypeOfExpression (TypeOfExpression typeOfExpression, T data);
S VisitUnaryOperatorExpression (UnaryOperatorExpression unaryOperatorExpression, T data);
S VisitUncheckedExpression (UncheckedExpression uncheckedExpression, T data);
S VisitAsExpression (AsExpression asExpression, T data);
S VisitIsExpression (IsExpression isExpression, T data);
S VisitDefaultValueExpression (DefaultValueExpression defaultValueExpression, T data);
S VisitArgListExpression (ArgListExpression argListExpression, T data);
#endregion
#region Query Expressions
S VisitQueryExpressionFromClause (QueryExpressionFromClause queryExpressionFromClause, T data);
S VisitQueryExpressionWhereClause (QueryExpressionWhereClause queryExpressionWhereClause, T data);
S VisitQueryExpressionJoinClause (QueryExpressionJoinClause queryExpressionJoinClause, T data);
S VisitQueryExpressionGroupClause (QueryExpressionGroupClause queryExpressionGroupClause, T data);
S VisitQueryExpressionLetClause (QueryExpressionLetClause queryExpressionLetClause, T data);
S VisitQueryExpressionOrderClause (QueryExpressionOrderClause queryExpressionOrderClause, T data);
S VisitQueryExpressionOrdering (QueryExpressionOrdering queryExpressionOrdering, T data);
S VisitQueryExpressionSelectClause (QueryExpressionSelectClause queryExpressionSelectClause, T data);
#endregion
}
}

26
ICSharpCode.NRefactory/CSharp/Dom/Identifier.cs

@ -25,12 +25,32 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class Identifier : AbstractNode public class Identifier : DomNode
{ {
public static readonly new Identifier Null = new NullIdentifier ();
class NullIdentifier : Identifier
{
public override bool IsNull {
get {
return true;
}
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{
return default (S);
}
}
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string Name { public string Name {
get; get;
set; set;
@ -65,7 +85,7 @@ namespace ICSharpCode.NRefactory.CSharp
this.startLocation = location; this.startLocation = location;
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitIdentifier (this, data); return visitor.VisitIdentifier (this, data);
} }

60
ICSharpCode.NRefactory/CSharp/Dom/INode.cs → ICSharpCode.NRefactory/CSharp/Dom/NodeType.cs

@ -1,5 +1,5 @@
// //
// INode.cs // NodeType.cs
// //
// Author: // Author:
// Mike Krüger <mkrueger@novell.com> // Mike Krüger <mkrueger@novell.com>
@ -25,58 +25,18 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public interface INode public enum NodeType
{ {
INode Parent { Unknown,
get;
set;
}
IEnumerable<INode> Children {
get;
}
INode GetChildByRole (int role);
int Role {
get;
set;
}
INode NextSibling {
get;
set;
}
INode PrevSibling {
get;
set;
}
INode FirstChild { Type,
get; Member,
set; Statement,
} Expression,
Token
INode LastChild {
get;
set;
}
DomLocation StartLocation {
get;
}
DomLocation EndLocation {
get;
}
S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data);
} }
} }

27
ICSharpCode.NRefactory/CSharp/Dom/QualifiedIdentifier.cs

@ -1,4 +1,4 @@
// //
// QualifiedIdentifier.cs // QualifiedIdentifier.cs
// //
// Author: // Author:
@ -25,27 +25,27 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using System.Text;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class QualifiedIdentifier : AbstractNode public class QualifiedIdentifier : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string QualifiedName { public string QualifiedName {
get { get {
StringBuilder builder = new StringBuilder (); StringBuilder builder = new StringBuilder ();
int i = 0;
foreach (Identifier identifier in GetChildrenByRole (Roles.Identifier)) { foreach (Identifier identifier in GetChildrenByRole (Roles.Identifier)) {
if (i > 0) { if (builder.Length > 0)
if (i == 1 && HasDoubleColon) builder.Append ('.');
builder.Append ("::");
else
builder.Append ('.');
}
builder.Append (identifier.Name); builder.Append (identifier.Name);
i++;
} }
return builder.ToString (); return builder.ToString ();
} }
@ -64,5 +64,10 @@ namespace ICSharpCode.NRefactory.CSharp
public QualifiedIdentifier () public QualifiedIdentifier ()
{ {
} }
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{
return default (S);
}
} }
} }

33
ICSharpCode.NRefactory/CSharp/Dom/Statements/BlockStatement.cs

@ -25,32 +25,53 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class BlockStatement : AbstractNode public class BlockStatement : DomNode
{ {
public static readonly new BlockStatement Null = new NullBlockStatement ();
class NullBlockStatement : BlockStatement
{
public override bool IsNull {
get {
return true;
}
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{
return default (S);
}
}
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public CSharpTokenNode LBrace { public CSharpTokenNode LBrace {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.LBrace); return (CSharpTokenNode)GetChildByRole (Roles.LBrace) ?? CSharpTokenNode.Null;
} }
} }
public CSharpTokenNode RBrace { public CSharpTokenNode RBrace {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.RBrace); return (CSharpTokenNode)GetChildByRole (Roles.RBrace) ?? CSharpTokenNode.Null;
} }
} }
public IEnumerable<INode> Statements { public IEnumerable<DomNode> Statements {
get { get {
return GetChildrenByRole (Roles.Statement); return GetChildrenByRole (Roles.Statement);
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitBlockStatement (this, data); return visitor.VisitBlockStatement (this, data);
} }

15
ICSharpCode.NRefactory/CSharp/Dom/Statements/BreakStatement.cs

@ -25,19 +25,24 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class BreakStatement : AbstractNode public class BreakStatement : DomNode
{ {
public INode BreakKeyword { public override NodeType NodeType {
get { get {
return GetChildByRole (Roles.Keyword); return NodeType.Statement;
}
}
public CSharpTokenNode BreakKeyword {
get {
return (CSharpTokenNode)GetChildByRole (Roles.Keyword) ?? CSharpTokenNode.Null;
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitBreakStatement (this, data); return visitor.VisitBreakStatement (this, data);
} }

15
ICSharpCode.NRefactory/CSharp/Dom/Statements/CheckedStatement.cs

@ -1,4 +1,4 @@
// //
// CheckedStatement.cs // CheckedStatement.cs
// //
// Author: // Author:
@ -25,17 +25,22 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class CheckedStatement : AbstractNode public class CheckedStatement : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public BlockStatement Block { public BlockStatement Block {
get { return (BlockStatement)GetChildByRole (Roles.Body); } get { return (BlockStatement)GetChildByRole (Roles.Body) ?? BlockStatement.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitCheckedStatement (this, data); return visitor.VisitCheckedStatement (this, data);
} }

15
ICSharpCode.NRefactory/CSharp/Dom/Statements/ContinueStatement.cs

@ -25,17 +25,22 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class ContinueStatement : AbstractNode public class ContinueStatement : DomNode
{ {
public INode ContinueKeyword { public override NodeType NodeType {
get { return GetChildByRole (Roles.Keyword); } get {
return NodeType.Statement;
}
}
public CSharpTokenNode ContinueKeyword {
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitContinueStatement (this, data); return visitor.VisitContinueStatement (this, data);
} }

14
ICSharpCode.NRefactory/CSharp/Dom/Statements/EmptyStatement.cs

@ -25,12 +25,17 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class EmptyStatement : AbstractNode public class EmptyStatement : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public DomLocation Location { public DomLocation Location {
get; get;
set; set;
@ -41,13 +46,14 @@ namespace ICSharpCode.NRefactory.CSharp
return Location; return Location;
} }
} }
public override DomLocation EndLocation { public override DomLocation EndLocation {
get { get {
return new DomLocation (Location.Line, Location.Column + 1); return new DomLocation (Location.Line, Location.Column);
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitEmptyStatement (this, data); return visitor.VisitEmptyStatement (this, data);
} }

17
ICSharpCode.NRefactory/CSharp/Dom/Statements/ExpressionStatement.cs

@ -1,4 +1,4 @@
// //
// ExpressionStatement.cs // ExpressionStatement.cs
// //
// Author: // Author:
@ -25,19 +25,24 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class ExpressionStatement : AbstractNode public class ExpressionStatement : DomNode
{ {
public INode Expression { public override NodeType NodeType {
get { get {
return GetChildByRole(Roles.Expression); return NodeType.Statement;
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public DomNode Expression {
get {
return GetChildByRole (Roles.Expression);
}
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitExpressionStatement (this, data); return visitor.VisitExpressionStatement (this, data);
} }

19
ICSharpCode.NRefactory/CSharp/Dom/Statements/FixedStatement.cs

@ -25,25 +25,30 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class FixedStatement : AbstractNode public class FixedStatement : DomNode
{ {
public const int PointerDeclarationRole = 100; public const int PointerDeclarationRole = 100;
public const int FixedKeywordRole = 101; public const int FixedKeywordRole = 101;
public const int DeclaratorRole = 102; public const int DeclaratorRole = 102;
public INode EmbeddedStatement { public override NodeType NodeType {
get { return (INode)GetChildByRole (Roles.EmbeddedStatement); } get {
return NodeType.Statement;
}
}
public DomNode EmbeddedStatement {
get { return GetChildByRole (Roles.EmbeddedStatement) ?? DomNode.Null; }
} }
public INode PointerDeclaration { public DomNode PointerDeclaration {
get { return GetChildByRole (PointerDeclarationRole); } get { return GetChildByRole (PointerDeclarationRole) ?? DomNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitFixedStatement (this, data); return visitor.VisitFixedStatement (this, data);
} }

27
ICSharpCode.NRefactory/CSharp/Dom/Statements/ForStatement.cs

@ -25,38 +25,43 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class ForStatement : AbstractNode public class ForStatement : DomNode
{ {
public INode EmbeddedStatement { public override NodeType NodeType {
get { return (INode)GetChildByRole (Roles.EmbeddedStatement); } get {
return NodeType.Statement;
}
}
public DomNode EmbeddedStatement {
get { return GetChildByRole (Roles.EmbeddedStatement) ?? DomNode.Null; }
} }
public INode Condition { public DomNode Condition {
get { return GetChildByRole (Roles.Condition); } get { return GetChildByRole (Roles.Condition) ?? DomNode.Null; }
} }
public IEnumerable<INode> Initializers { public IEnumerable<DomNode> Initializers {
get { return GetChildrenByRole (Roles.Initializer); } get { return GetChildrenByRole (Roles.Initializer); }
} }
public IEnumerable<INode> Iterators { public IEnumerable<DomNode> Iterators {
get { return GetChildrenByRole (Roles.Iterator); } get { return GetChildrenByRole (Roles.Iterator); }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitForStatement (this, data); return visitor.VisitForStatement (this, data);
} }

31
ICSharpCode.NRefactory/CSharp/Dom/Statements/ForeachStatement.cs

@ -25,33 +25,38 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class ForeachStatement : AbstractNode public class ForeachStatement : DomNode
{ {
public const int ForEachKeywordRole = 100; public const int ForEachKeywordRole = 100;
public const int InKeywordRole = 101; public const int InKeywordRole = 101;
public INode EmbeddedStatement { public override NodeType NodeType {
get { return (INode)GetChildByRole (Roles.EmbeddedStatement); } get {
return NodeType.Statement;
}
}
public DomNode EmbeddedStatement {
get { return GetChildByRole (Roles.EmbeddedStatement) ?? DomNode.Null; }
} }
public INode Expression { public DomNode Expression {
get { return GetChildByRole (Roles.Initializer); } get { return GetChildByRole (Roles.Initializer) ?? DomNode.Null; }
} }
public INode VariableType { public DomNode VariableType {
get { return (INode)GetChildByRole (Roles.ReturnType); } get { return GetChildByRole (Roles.ReturnType) ?? DomNode.Null; }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public string VariableName { public string VariableName {
@ -62,11 +67,11 @@ namespace ICSharpCode.NRefactory.CSharp
public Identifier VariableNameIdentifier { public Identifier VariableNameIdentifier {
get { get {
return (Identifier)GetChildByRole (Roles.Identifier); return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null;
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitForeachStatement (this, data); return visitor.VisitForeachStatement (this, data);
} }

22
ICSharpCode.NRefactory/CSharp/Dom/Statements/GotoStatement.cs

@ -1,4 +1,4 @@
// //
// GotoStatement.cs // GotoStatement.cs
// //
// Author: // Author:
@ -25,32 +25,34 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class GotoStatement : AbstractNode public class GotoStatement : DomNode
{ {
public const int DefaultKeywordRole = 100; public const int DefaultKeywordRole = 100;
public const int CaseKeywordRole = 101; public const int CaseKeywordRole = 101;
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public GotoType GotoType { public GotoType GotoType {
get; get;
set; set;
} }
public string Label { public string Label {
get { get { return ((Identifier)LabelExpression).Name; }
Identifier i = this.LabelExpression as Identifier;
return i != null ? i.Name : null;
}
} }
public INode LabelExpression { public DomNode LabelExpression {
get { return GetChildByRole (Roles.Expression); } get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitGotoStatement (this, data); return visitor.VisitGotoStatement (this, data);
} }

31
ICSharpCode.NRefactory/CSharp/Dom/Statements/IfElseStatement.cs

@ -25,46 +25,51 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class IfElseStatement : AbstractNode public class IfElseStatement : DomNode
{ {
public const int TrueEmbeddedStatementRole = 100; public const int TrueEmbeddedStatementRole = 100;
public const int FalseEmbeddedStatementRole = 101; public const int FalseEmbeddedStatementRole = 101;
public const int IfKeywordRole = 102; public const int IfKeywordRole = 102;
public const int ElseKeywordRole = 103; public const int ElseKeywordRole = 103;
public INode TrueEmbeddedStatement { public override NodeType NodeType {
get { return (INode)GetChildByRole (TrueEmbeddedStatementRole); } get {
return NodeType.Statement;
}
}
public DomNode TrueEmbeddedStatement {
get { return GetChildByRole (TrueEmbeddedStatementRole) ?? DomNode.Null; }
} }
public INode FalseEmbeddedStatement { public DomNode FalseEmbeddedStatement {
get { return (INode)GetChildByRole (FalseEmbeddedStatementRole); } get { return GetChildByRole (FalseEmbeddedStatementRole) ?? DomNode.Null; }
} }
public INode Condition { public DomNode Condition {
get { return (INode)GetChildByRole (Roles.Condition); } get { return GetChildByRole (Roles.Condition) ?? DomNode.Null; }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode IfKeyword { public CSharpTokenNode IfKeyword {
get { return (CSharpTokenNode)GetChildByRole (IfKeywordRole); } get { return (CSharpTokenNode)GetChildByRole (IfKeywordRole) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode ElseKeyword { public CSharpTokenNode ElseKeyword {
get { return (CSharpTokenNode)GetChildByRole (ElseKeywordRole); } get { return (CSharpTokenNode)GetChildByRole (ElseKeywordRole) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitIfElseStatement (this, data); return visitor.VisitIfElseStatement (this, data);
} }

13
ICSharpCode.NRefactory/CSharp/Dom/Statements/LabelStatement.cs

@ -25,21 +25,26 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class LabelStatement : AbstractNode public class LabelStatement : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public string Label { public string Label {
get { return LabelIdentifier.Name; } get { return LabelIdentifier.Name; }
} }
public Identifier LabelIdentifier { public Identifier LabelIdentifier {
get { return (Identifier)GetChildByRole (Roles.Identifier); } get { return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitLabelStatement (this, data); return visitor.VisitLabelStatement (this, data);
} }

23
ICSharpCode.NRefactory/CSharp/Dom/Statements/LockStatement.cs

@ -25,29 +25,34 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class LockStatement : AbstractNode public class LockStatement : DomNode
{ {
public INode Expression { public override NodeType NodeType {
get { return GetChildByRole (Roles.Expression); } get {
return NodeType.Statement;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public INode EmbeddedStatement { public DomNode EmbeddedStatement {
get { return (INode)GetChildByRole (Roles.EmbeddedStatement); } get { return GetChildByRole (Roles.EmbeddedStatement) ?? DomNode.Null; }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitLockStatement (this, data); return visitor.VisitLockStatement (this, data);
} }

15
ICSharpCode.NRefactory/CSharp/Dom/Statements/ReturnStatement.cs

@ -25,17 +25,22 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class ReturnStatement : AbstractNode public class ReturnStatement : DomNode
{ {
public INode Expression { public override NodeType NodeType {
get { return GetChildByRole (Roles.Expression); } get {
return NodeType.Statement;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitReturnStatement (this, data); return visitor.VisitReturnStatement (this, data);
} }

56
ICSharpCode.NRefactory/CSharp/Dom/Statements/SwitchStatement.cs

@ -26,17 +26,22 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class SwitchStatement : AbstractNode public class SwitchStatement : DomNode
{ {
public const int SwitchSectionRole = 100; public const int SwitchSectionRole = 100;
public INode Expression { public override NodeType NodeType {
get { return GetChildByRole (Roles.Expression); } get {
return NodeType.Statement;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public IEnumerable<SwitchSection> SwitchSections { public IEnumerable<SwitchSection> SwitchSections {
@ -44,54 +49,69 @@ namespace ICSharpCode.NRefactory.CSharp
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode LBrace { public CSharpTokenNode LBrace {
get { return (CSharpTokenNode)GetChildByRole (Roles.LBrace); } get { return (CSharpTokenNode)GetChildByRole (Roles.LBrace) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RBrace { public CSharpTokenNode RBrace {
get { return (CSharpTokenNode)GetChildByRole (Roles.RBrace); } get { return (CSharpTokenNode)GetChildByRole (Roles.RBrace) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitSwitchStatement (this, data); return visitor.VisitSwitchStatement (this, data);
} }
} }
public class SwitchSection : AbstractNode public class SwitchSection : DomNode
{ {
public const int CaseLabelRole = 100; public const int CaseLabelRole = 100;
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public IEnumerable<CaseLabel> CaseLabels { public IEnumerable<CaseLabel> CaseLabels {
get { return GetChildrenByRole (CaseLabelRole).Cast<CaseLabel> (); } get { return GetChildrenByRole (CaseLabelRole).Cast<CaseLabel> (); }
} }
public IEnumerable<INode> Statements { public IEnumerable<DomNode> Statements {
get { get {
BlockStatement block = (BlockStatement)GetChildByRole (Roles.Body); var body = GetChildByRole (Roles.Body);
return block.Statements; if (body is BlockStatement)
return ((BlockStatement)body).Statements;
return new DomNode[] { body };
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitSwitchSection (this, data); return visitor.VisitSwitchSection (this, data);
} }
} }
public class CaseLabel : AbstractNode public class CaseLabel : DomNode
{ {
public INode Expression { public override NodeType NodeType {
get { return GetChildByRole (Roles.Expression); } get {
return NodeType.Unknown;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitCaseLabel (this, data); return visitor.VisitCaseLabel (this, data);
} }

15
ICSharpCode.NRefactory/CSharp/Dom/Statements/ThrowStatement.cs

@ -25,17 +25,22 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class ThrowStatement : AbstractNode public class ThrowStatement : DomNode
{ {
public INode Expression { public override NodeType NodeType {
get { return GetChildByRole (Roles.Expression); } get {
return NodeType.Statement;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitThrowStatement (this, data); return visitor.VisitThrowStatement (this, data);
} }

33
ICSharpCode.NRefactory/CSharp/Dom/Statements/TryCatchStatement.cs

@ -26,12 +26,11 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class TryCatchStatement : AbstractNode public class TryCatchStatement : DomNode
{ {
public const int TryKeywordRole = 100; public const int TryKeywordRole = 100;
public const int FinallyKeywordRole = 101; public const int FinallyKeywordRole = 101;
@ -39,36 +38,48 @@ namespace ICSharpCode.NRefactory.CSharp
public const int FinallyBlockRole = 103; public const int FinallyBlockRole = 103;
public const int CatchClauseRole = 104; public const int CatchClauseRole = 104;
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public CSharpTokenNode TryKeyword { public CSharpTokenNode TryKeyword {
get { return (CSharpTokenNode)GetChildByRole (TryKeywordRole); } get { return (CSharpTokenNode)GetChildByRole (TryKeywordRole) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode FinallyKeyword { public CSharpTokenNode FinallyKeyword {
get { return (CSharpTokenNode)GetChildByRole (FinallyKeywordRole); } get { return (CSharpTokenNode)GetChildByRole (FinallyKeywordRole) ?? CSharpTokenNode.Null; }
} }
public BlockStatement TryBlock { public BlockStatement TryBlock {
get { return (BlockStatement)GetChildByRole (TryBlockRole); } get { return (BlockStatement)GetChildByRole (TryBlockRole) ?? BlockStatement.Null; }
} }
public BlockStatement FinallyBlock { public BlockStatement FinallyBlock {
get { return (BlockStatement)GetChildByRole (FinallyBlockRole); } get { return (BlockStatement)GetChildByRole (FinallyBlockRole) ?? BlockStatement.Null; }
} }
public IEnumerable<CatchClause> CatchClauses { public IEnumerable<CatchClause> CatchClauses {
get { return GetChildrenByRole (CatchClauseRole).Cast<CatchClause> (); } get { return GetChildrenByRole (CatchClauseRole).Cast<CatchClause> (); }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitTryCatchStatement (this, data); return visitor.VisitTryCatchStatement (this, data);
} }
} }
public class CatchClause : AbstractNode public class CatchClause : DomNode
{ {
public INode ReturnType { public override NodeType NodeType {
get { return (INode)GetChildByRole (Roles.ReturnType); } get {
return NodeType.Unknown;
}
}
public DomNode ReturnType {
get { return GetChildByRole (Roles.ReturnType); }
} }
public string VariableName { public string VariableName {
@ -95,7 +106,7 @@ namespace ICSharpCode.NRefactory.CSharp
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); } get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitCatchClause (this, data); return visitor.VisitCatchClause (this, data);
} }

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

@ -1,4 +1,4 @@
// //
// UncheckedStatement.cs // UncheckedStatement.cs
// //
// Author: // Author:
@ -25,17 +25,23 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class UncheckedStatement : AbstractNode public class UncheckedStatement : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public BlockStatement Block { public BlockStatement Block {
get { return (BlockStatement)GetChildByRole (Roles.Body); } get { return (BlockStatement)GetChildByRole (Roles.Body) ?? BlockStatement.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data)
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitUncheckedStatement (this, data); return visitor.VisitUncheckedStatement (this, data);
} }

13
ICSharpCode.NRefactory/CSharp/Dom/Statements/UnsafeStatement.cs

@ -25,17 +25,22 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class UnsafeStatement : AbstractNode public class UnsafeStatement : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public BlockStatement Block { public BlockStatement Block {
get { return (BlockStatement)GetChildByRole (Roles.Body); } get { return (BlockStatement)GetChildByRole (Roles.Body) ?? BlockStatement.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitUnsafeStatement (this, data); return visitor.VisitUnsafeStatement (this, data);
} }

23
ICSharpCode.NRefactory/CSharp/Dom/Statements/UsingStatement.cs

@ -25,30 +25,35 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class UsingStatement : AbstractNode public class UsingStatement : DomNode
{ {
public INode Statement { public override NodeType NodeType {
get { return GetChildByRole (Roles.Statement); } get {
return NodeType.Statement;
}
}
public DomNode Statement {
get { return GetChildByRole (Roles.Statement) ?? DomNode.Null; }
} }
public INode EmbeddedStatement { public DomNode EmbeddedStatement {
get { return (INode)GetChildByRole (Roles.EmbeddedStatement); } get { return GetChildByRole (Roles.EmbeddedStatement) ?? DomNode.Null; }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitUsingStatement (this, data); return visitor.VisitUsingStatement (this, data);
} }

29
ICSharpCode.NRefactory/CSharp/Dom/Statements/VariableDeclarationStatement.cs

@ -1,6 +1,6 @@
// //
// VariableDeclarationStatement.cs // VariableDeclarationStatement.cs
// //
// Author: // Author:
// Mike Krüger <mkrueger@novell.com> // Mike Krüger <mkrueger@novell.com>
// //
@ -26,15 +26,22 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class VariableDeclarationStatement : AbstractNode public class VariableDeclarationStatement : DomNode
{ {
public IEnumerable<INode> ModifierTokens { public override NodeType NodeType {
get { return base.GetChildrenByRole (Roles.Modifier); } get {
return NodeType.Statement;
}
}
public IEnumerable<CSharpModifierToken> ModifierTokens {
get {
return base.GetChildrenByRole (Roles.Modifier).Cast <CSharpModifierToken>();
}
} }
public Modifiers Modifiers { public Modifiers Modifiers {
@ -47,15 +54,19 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public INode ReturnType { public DomNode ReturnType {
get { return (INode)GetChildByRole (Roles.ReturnType); } get { return GetChildByRole (Roles.ReturnType) ?? DomNode.Null; }
} }
public IEnumerable<VariableInitializer> Variables { public IEnumerable<VariableInitializer> Variables {
get { return base.GetChildrenByRole (Roles.Initializer).Cast<VariableInitializer> (); } get { return base.GetChildrenByRole (Roles.Initializer).Cast<VariableInitializer> (); }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public CSharpTokenNode Semicolon {
get { return (CSharpTokenNode)GetChildByRole (Roles.Semicolon) ?? CSharpTokenNode.Null; }
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitVariableDeclarationStatement (this, data); return visitor.VisitVariableDeclarationStatement (this, data);
} }

27
ICSharpCode.NRefactory/CSharp/Dom/Statements/WhileStatement.cs

@ -25,45 +25,50 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class WhileStatement : AbstractNode public class WhileStatement : DomNode
{ {
public const int DoKeywordRole = 101; public const int DoKeywordRole = 101;
public const int WhileKeywordRole = 102; public const int WhileKeywordRole = 102;
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public WhilePosition WhilePosition { public WhilePosition WhilePosition {
get; get;
set; set;
} }
public INode EmbeddedStatement { public DomNode EmbeddedStatement {
get { return (INode)GetChildByRole (Roles.EmbeddedStatement); } get { return GetChildByRole (Roles.EmbeddedStatement) ?? DomNode.Null; }
} }
public INode Condition { public DomNode Condition {
get { return GetChildByRole (Roles.Condition); } get { return GetChildByRole (Roles.Condition) ?? DomNode.Null; }
} }
public CSharpTokenNode DoKeyword { public CSharpTokenNode DoKeyword {
get { return (CSharpTokenNode)GetChildByRole (DoKeywordRole); } get { return (CSharpTokenNode)GetChildByRole (DoKeywordRole) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode WhileKeyword { public CSharpTokenNode WhileKeyword {
get { return (CSharpTokenNode)GetChildByRole (WhileKeywordRole); } get { return (CSharpTokenNode)GetChildByRole (WhileKeywordRole) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitWhileStatement (this, data); return visitor.VisitWhileStatement (this, data);
} }

17
ICSharpCode.NRefactory/CSharp/Dom/Statements/YieldStatement.cs

@ -1,4 +1,4 @@
// //
// YieldStatement.cs // YieldStatement.cs
// //
// Author: // Author:
@ -25,21 +25,26 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class YieldStatement : AbstractNode public class YieldStatement : DomNode
{ {
public const int YieldKeywordRole = 100; public const int YieldKeywordRole = 100;
public const int ReturnKeywordRole = 101; public const int ReturnKeywordRole = 101;
public const int BreakKeywordRole = 102; public const int BreakKeywordRole = 102;
public INode Expression { public override NodeType NodeType {
get { return GetChildByRole (Roles.Expression); } get {
return NodeType.Statement;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitYieldStatement (this, data); return visitor.VisitYieldStatement (this, data);
} }

16
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/AbstractMember.cs

@ -1,4 +1,4 @@
// //
// AbstractMember.cs // AbstractMember.cs
// //
// Author: // Author:
@ -25,7 +25,6 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
@ -33,31 +32,30 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
const int PrivateImplementationTypeRole = 100; const int PrivateImplementationTypeRole = 100;
public INode ReturnType { public DomNode ReturnType {
get { get {
return (INode)GetChildByRole (Roles.ReturnType); return GetChildByRole (Roles.ReturnType) ?? DomNode.Null;
} }
} }
/// <summary> /// <summary>
/// Only supported on members that can be declared in an interface. /// Only supported on members that can be declared in an interface.
/// </summary> /// </summary>
public INode PrivateImplementationType { public DomNode PrivateImplementationType {
get { get {
return (INode)GetChildByRole (PrivateImplementationTypeRole); return GetChildByRole (PrivateImplementationTypeRole) ?? DomNode.Null;
} }
} }
public Identifier NameIdentifier { public Identifier NameIdentifier {
get { get {
return (Identifier)GetChildByRole (Roles.Identifier); return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null;
} }
} }
public string Name { public string Name {
get { get {
Identifier nameIdentifier = this.NameIdentifier; return NameIdentifier.Name;
return nameIdentifier != null ? nameIdentifier.Name : null;
} }
} }
} }

13
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/AbstractMemberBase.cs

@ -1,4 +1,4 @@
// //
// AbstractMemberBase.cs // AbstractMemberBase.cs
// //
// Author: // Author:
@ -26,14 +26,19 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public abstract class AbstractMemberBase : AbstractNode public abstract class AbstractMemberBase : DomNode
{ {
public IEnumerable<CSharpModifierToken> ModifierTokens { public override NodeType NodeType {
get {
return NodeType.Member;
}
}
public IEnumerable<CSharpModifierToken> ModifierTokens {
get { get {
return base.GetChildrenByRole (Roles.Modifier).Cast <CSharpModifierToken>(); return base.GetChildrenByRole (Roles.Modifier).Cast <CSharpModifierToken>();
} }

64
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/Accessor.cs

@ -0,0 +1,64 @@
//
// PropertyDeclaration.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp
{
public class Accessor : AbstractMember
{
public static readonly new Accessor Null = new NullAccessor ();
class NullAccessor : Accessor
{
public override bool IsNull {
get {
return true;
}
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{
return default (S);
}
}
public DomLocation Location {
get;
set;
}
public BlockStatement Body {
get {
return (BlockStatement)GetChildByRole (Roles.Body) ?? BlockStatement.Null;
}
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{
return visitor.VisitAccessorDeclaration (this, data);
}
}
}

60
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/ConstructorDeclaration.cs

@ -1,4 +1,4 @@
// //
// ConstructorDeclaration.cs // ConstructorDeclaration.cs
// //
// Author: // Author:
@ -26,7 +26,6 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
@ -35,26 +34,34 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
public BlockStatement Body { public BlockStatement Body {
get { get {
return (BlockStatement)GetChildByRole (Roles.Body); return (BlockStatement)GetChildByRole (Roles.Body) ?? BlockStatement.Null;
} }
} }
public ConstructorInitializer Initializer { public IEnumerable<ParameterDeclaration> Parameters {
get { get {
return (ConstructorInitializer)base.GetChildByRole (Roles.Initializer); return base.GetChildrenByRole (Roles.Argument).Cast <ParameterDeclaration> ();
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public CSharpTokenNode LPar {
{ get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
return visitor.VisitConstructorDeclaration (this, data); }
public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public IEnumerable<ParameterDeclaration> Parameters { public ConstructorInitializer Initializer {
get { get {
return GetChildrenByRole (Roles.Argument).Cast<ParameterDeclaration>(); return (ConstructorInitializer)base.GetChildByRole (Roles.Initializer) ?? ConstructorInitializer.Null;
} }
} }
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{
return visitor.VisitConstructorDeclaration (this, data);
}
} }
public enum ConstructorInitializerType { public enum ConstructorInitializerType {
@ -62,20 +69,47 @@ namespace ICSharpCode.NRefactory.CSharp
This This
} }
public class ConstructorInitializer : AbstractNode public class ConstructorInitializer : DomNode
{ {
public static readonly new ConstructorInitializer Null = new NullConstructorInitializer ();
class NullConstructorInitializer : ConstructorInitializer
{
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public override bool IsNull {
get {
return true;
}
}
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{
return default (S);
}
}
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public ConstructorInitializerType ConstructorInitializerType { public ConstructorInitializerType ConstructorInitializerType {
get; get;
set; set;
} }
public IEnumerable<INode> Arguments { public IEnumerable<DomNode> Arguments {
get { get {
return base.GetChildrenByRole (Roles.Argument); return base.GetChildrenByRole (Roles.Argument);
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitConstructorInitializer (this, data); return visitor.VisitConstructorInitializer (this, data);
} }

5
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/DestructorDeclaration.cs

@ -26,7 +26,6 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
@ -37,11 +36,11 @@ namespace ICSharpCode.NRefactory.CSharp
public BlockStatement Body { public BlockStatement Body {
get { get {
return (BlockStatement)GetChildByRole (Roles.Body); return (BlockStatement)GetChildByRole (Roles.Body) ?? BlockStatement.Null;
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitDestructorDeclaration (this, data); return visitor.VisitDestructorDeclaration (this, data);
} }

11
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/EventDeclaration.cs

@ -25,7 +25,6 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
@ -36,29 +35,29 @@ namespace ICSharpCode.NRefactory.CSharp
public CSharpTokenNode LBrace { public CSharpTokenNode LBrace {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.LBrace); return (CSharpTokenNode)GetChildByRole (Roles.LBrace) ?? CSharpTokenNode.Null;
} }
} }
public CSharpTokenNode RBrace { public CSharpTokenNode RBrace {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.RBrace); return (CSharpTokenNode)GetChildByRole (Roles.RBrace) ?? CSharpTokenNode.Null;
} }
} }
public Accessor AddAccessor { public Accessor AddAccessor {
get { get {
return (Accessor)GetChildByRole (EventAddRole); return (Accessor)GetChildByRole (EventAddRole) ?? Accessor.Null;
} }
} }
public Accessor RemoveAccessor { public Accessor RemoveAccessor {
get { get {
return (Accessor)GetChildByRole (EventRemoveRole); return (Accessor)GetChildByRole (EventRemoveRole) ?? Accessor.Null;
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitEventDeclaration (this, data); return visitor.VisitEventDeclaration (this, data);
} }

5
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/FieldDeclaration.cs

@ -26,7 +26,6 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
@ -34,7 +33,7 @@ namespace ICSharpCode.NRefactory.CSharp
public class FieldDeclaration : AbstractMember public class FieldDeclaration : AbstractMember
{ {
public CSharpTokenNode Semicolon { public CSharpTokenNode Semicolon {
get { return (CSharpTokenNode)GetChildByRole (Roles.Semicolon); } get { return (CSharpTokenNode)GetChildByRole (Roles.Semicolon) ?? CSharpTokenNode.Null; }
} }
public IEnumerable<VariableInitializer> Variables { public IEnumerable<VariableInitializer> Variables {
@ -43,7 +42,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitFieldDeclaration (this, data); return visitor.VisitFieldDeclaration (this, data);
} }

14
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/IndexerDeclaration.cs

@ -1,4 +1,4 @@
// //
// IndexerDeclaration.cs // IndexerDeclaration.cs
// //
// Author: // Author:
@ -26,19 +26,13 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class IndexerDeclaration : PropertyDeclaration public class IndexerDeclaration : PropertyDeclaration
{ {
// TODO: Parameters or Arguments?
public IEnumerable<ParameterDeclaration> Parameters { public IEnumerable<ParameterDeclaration> Parameters {
get { return this.Arguments; }
}
public IEnumerable<ParameterDeclaration> Arguments {
get { get {
return base.GetChildrenByRole (Roles.Argument).Cast <ParameterDeclaration>(); return base.GetChildrenByRole (Roles.Argument).Cast <ParameterDeclaration>();
} }
@ -46,18 +40,18 @@ namespace ICSharpCode.NRefactory.CSharp
public CSharpTokenNode LBracket { public CSharpTokenNode LBracket {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.LBracket); return (CSharpTokenNode)GetChildByRole (Roles.LBracket) ?? CSharpTokenNode.Null;
} }
} }
public CSharpTokenNode RBracket { public CSharpTokenNode RBracket {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.RBracket); return (CSharpTokenNode)GetChildByRole (Roles.RBracket) ?? CSharpTokenNode.Null;
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitIndexerDeclaration (this, data); return visitor.VisitIndexerDeclaration (this, data);
} }

38
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/MethodDeclaration.cs

@ -1,4 +1,4 @@
// //
// MethodDeclaration.cs // MethodDeclaration.cs
// //
// Author: // Author:
@ -32,13 +32,8 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
public class MethodDeclaration : AbstractMember public class MethodDeclaration : AbstractMember
{ {
// TODO: Parameters or Arguments? public IEnumerable<DomNode> TypeParameters {
public IEnumerable<INode> TypeParameters { get { return GetChildrenByRole (Roles.TypeArgument); }
get { return this.TypeArguments; }
}
public IEnumerable<INode> TypeArguments {
get { return GetChildrenByRole (Roles.TypeArgument).Cast<INode> (); }
} }
public IEnumerable<Constraint> Constraints { public IEnumerable<Constraint> Constraints {
@ -48,41 +43,34 @@ namespace ICSharpCode.NRefactory.CSharp
} }
public IEnumerable<ParameterDeclaration> Parameters { public IEnumerable<ParameterDeclaration> Parameters {
get {
return this.Arguments;
}
}
public IEnumerable<ParameterDeclaration> Arguments {
get { get {
return base.GetChildrenByRole (Roles.Argument).Cast <ParameterDeclaration> (); return base.GetChildrenByRole (Roles.Argument).Cast <ParameterDeclaration> ();
} }
} }
public bool IsExtensionMethod {
get {
ParameterDeclaration pd = (ParameterDeclaration)GetChildByRole (Roles.Argument);
return pd != null && pd.ParameterModifier == ParameterModifier.This;
}
}
public CSharpTokenNode LPar { public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
} }
public CSharpTokenNode RPar { public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); } get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
} }
public BlockStatement Body { public BlockStatement Body {
get { get {
return (BlockStatement)GetChildByRole (Roles.Body); return (BlockStatement)GetChildByRole (Roles.Body) ?? BlockStatement.Null;
} }
} }
public bool IsExtensionMethod {
get {
ParameterDeclaration pd = (ParameterDeclaration)GetChildByRole (Roles.Argument);
return pd != null && pd.ParameterModifier == ParameterModifier.This;
}
}
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitMethodDeclaration (this, data); return visitor.VisitMethodDeclaration (this, data);
} }

17
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/OperatorDeclaration.cs

@ -1,4 +1,4 @@
// //
// OperatorDeclaration.cs // OperatorDeclaration.cs
// //
// Author: // Author:
@ -29,8 +29,6 @@ using System;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public enum OperatorType { public enum OperatorType {
// Numeric values must match those in Mono.CSharp.Operator.OpType !!
// Unary operators // Unary operators
LogicalNot, LogicalNot,
OnesComplement, OnesComplement,
@ -77,6 +75,11 @@ namespace ICSharpCode.NRefactory.CSharp
set; set;
} }
public string OverloadOperator {
get;
set;
}
public CSharpTokenNode OperatorKeyword { public CSharpTokenNode OperatorKeyword {
get { return (CSharpTokenNode)GetChildByRole (OperatorKeywordRole); } get { return (CSharpTokenNode)GetChildByRole (OperatorKeywordRole); }
} }
@ -85,14 +88,14 @@ namespace ICSharpCode.NRefactory.CSharp
get { return (CSharpTokenNode)GetChildByRole (OperatorTypeRole); } get { return (CSharpTokenNode)GetChildByRole (OperatorTypeRole); }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public static string GetName(OperatorType type)
{ {
return visitor.VisitOperatorDeclaration (this, data); return Mono.CSharp.Operator.GetMetadataName((Mono.CSharp.Operator.OpType)type);
} }
public static string GetName(OperatorType type) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return Mono.CSharp.Operator.GetMetadataName((Mono.CSharp.Operator.OpType)type); return visitor.VisitOperatorDeclaration (this, data);
} }
} }
} }

20
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/ParameterDeclaration.cs

@ -38,8 +38,14 @@ namespace ICSharpCode.NRefactory.CSharp
This This
} }
public class ParameterDeclaration : AbstractNode public class ParameterDeclaration : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public ParameterModifier ParameterModifier { public ParameterModifier ParameterModifier {
get; get;
set; set;
@ -47,7 +53,7 @@ namespace ICSharpCode.NRefactory.CSharp
public Identifier Identifier { public Identifier Identifier {
get { get {
return (Identifier)GetChildByRole (Roles.Identifier); return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null;
} }
} }
@ -58,14 +64,14 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public INode DefaultExpression { public DomNode DefaultExpression {
get { get {
return (INode)GetChildByRole (Roles.Expression); return GetChildByRole (Roles.Expression) ?? DomNode.Null;
} }
} }
public INode Type { public DomNode Type {
get { return GetChildByRole (Roles.ReturnType); } get { return GetChildByRole (Roles.ReturnType) ?? DomNode.Null; }
} }
public IEnumerable<AttributeSection> Attributes { public IEnumerable<AttributeSection> Attributes {
@ -74,7 +80,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitParameterDeclaration (this, data); return visitor.VisitParameterDeclaration (this, data);
} }

33
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/PropertyDeclaration.cs

@ -1,4 +1,4 @@
// //
// PropertyDeclaration.cs // PropertyDeclaration.cs
// //
// Author: // Author:
@ -25,30 +25,9 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class Accessor : AbstractMemberBase
{
public DomLocation Location {
get;
set;
}
public BlockStatement Body {
get {
return (BlockStatement)GetChildByRole (Roles.Body);
}
}
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data)
{
return visitor.VisitAccessorDeclaration (this, data);
}
}
public class PropertyDeclaration : AbstractMember public class PropertyDeclaration : AbstractMember
{ {
public const int PropertyGetRole = 100; public const int PropertyGetRole = 100;
@ -56,29 +35,29 @@ namespace ICSharpCode.NRefactory.CSharp
public CSharpTokenNode LBrace { public CSharpTokenNode LBrace {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.LBrace); return (CSharpTokenNode)GetChildByRole (Roles.LBrace) ?? CSharpTokenNode.Null;
} }
} }
public CSharpTokenNode RBrace { public CSharpTokenNode RBrace {
get { get {
return (CSharpTokenNode)GetChildByRole (Roles.RBrace); return (CSharpTokenNode)GetChildByRole (Roles.RBrace) ?? CSharpTokenNode.Null;
} }
} }
public Accessor GetAccessor { public Accessor GetAccessor {
get { get {
return (Accessor)GetChildByRole (PropertyGetRole); return (Accessor)GetChildByRole (PropertyGetRole) ?? Accessor.Null;
} }
} }
public Accessor SetAccessor { public Accessor SetAccessor {
get { get {
return (Accessor)GetChildByRole (PropertySetRole); return (Accessor)GetChildByRole (PropertySetRole) ?? Accessor.Null;
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitPropertyDeclaration (this, data); return visitor.VisitPropertyDeclaration (this, data);
} }

22
ICSharpCode.NRefactory/CSharp/Dom/TypeMembers/VariableInitializer.cs

@ -25,12 +25,17 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp namespace ICSharpCode.NRefactory.CSharp
{ {
public class VariableInitializer : AbstractNode public class VariableInitializer : DomNode
{ {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string Name { public string Name {
get { get {
return NameIdentifier.Name; return NameIdentifier.Name;
@ -39,17 +44,22 @@ namespace ICSharpCode.NRefactory.CSharp
public Identifier NameIdentifier { public Identifier NameIdentifier {
get { get {
return (Identifier)GetChildByRole (Roles.Identifier); return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null;
} }
} }
public INode Initializer { public CSharpTokenNode Assign {
get { return (CSharpTokenNode)GetChildByRole (Roles.Assign) ?? CSharpTokenNode.Null; }
}
public DomNode Initializer {
get { get {
return GetChildByRole (Roles.Initializer); return GetChildByRole (Roles.Initializer) ?? DomNode.Null;
} }
} }
public override S AcceptVisitor<T, S> (IDomVisitor<T, S> visitor, T data) public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{ {
return visitor.VisitVariableInitializer (this, data); return visitor.VisitVariableInitializer (this, data);
} }

4
ICSharpCode.NRefactory/CSharp/Formatter/DomIndentationVisitor.cs

@ -25,7 +25,7 @@
// THE SOFTWARE. // THE SOFTWARE.
/* /*
using System; using System;
using MonoDevelop.CSharp.Dom; using ICSharpCode.NRefactory.CSharp;
using System.Text; using System.Text;
using MonoDevelop.Projects.Dom; using MonoDevelop.Projects.Dom;
using Mono.TextEditor; using Mono.TextEditor;
@ -70,7 +70,7 @@ namespace ICSharpCode.NRefactory.CSharp
AutoAcceptChanges = true; AutoAcceptChanges = true;
} }
public override object VisitCompilationUnit (MonoDevelop.CSharp.Dom.CompilationUnit unit, object data) public override object VisitCompilatioICSharpCode.NRefactory.CSharparp.Dom.CompilationUnit unit, object data)
{ {
base.VisitCompilationUnit (unit, data); base.VisitCompilationUnit (unit, data);
if (AutoAcceptChanges) if (AutoAcceptChanges)

6
ICSharpCode.NRefactory/CSharp/Formatter/DomSpacingVisitor.cs

@ -25,7 +25,7 @@
// THE SOFTWARE. // THE SOFTWARE.
/* /*
using System; using System;
using MonoDevelop.CSharp.Dom; using ICSharpCode.NRefactory.CSharp;
using System.Text; using System.Text;
using MonoDevelop.Projects.Dom; using MonoDevelop.Projects.Dom;
using Mono.TextEditor; using Mono.TextEditor;
@ -72,7 +72,7 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
public override object VisitCompilationUnit (MonoDevelop.CSharp.Dom.CompilationUnit unit, object data) public override object VisitCompilatioICSharpCode.NRefactory.CSharparp.Dom.CompilationUnit unit, object data)
{ {
base.VisitCompilationUnit (unit, data); base.VisitCompilationUnit (unit, data);
if (AutoAcceptChanges) if (AutoAcceptChanges)
@ -436,7 +436,7 @@ namespace ICSharpCode.NRefactory.CSharp
return base.VisitUsingStatement (usingStatement, data); return base.VisitUsingStatement (usingStatement, data);
} }
public override object VisitSwitchStatement (MonoDevelop.CSharp.Dom.SwitchStatement switchStatement, object data) public override object VisitSwiICSharpCode.NRefactory.CSharplop.CSharp.Dom.SwitchStatement switchStatement, object data)
{ {
ForceSpacesBefore (switchStatement.LPar, policy.SwitchParentheses); ForceSpacesBefore (switchStatement.LPar, policy.SwitchParentheses);

437
ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs

File diff suppressed because it is too large Load Diff

10
ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs

@ -15,7 +15,7 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary> /// <summary>
/// Produces type and member definitions from the DOM. /// Produces type and member definitions from the DOM.
/// </summary> /// </summary>
public class TypeSystemConvertVisitor : AbstractDomVisitor<object, IEntity> public class TypeSystemConvertVisitor : DomVisitor<object, IEntity>
{ {
readonly ParsedFile parsedFile; readonly ParsedFile parsedFile;
UsingScope usingScope; UsingScope usingScope;
@ -61,7 +61,7 @@ namespace ICSharpCode.NRefactory.CSharp
return new DomRegion(parsedFile.FileName, start.Line, start.Column, end.Line, end.Column); return new DomRegion(parsedFile.FileName, start.Line, start.Column, end.Line, end.Column);
} }
DomRegion MakeRegion(INode node) DomRegion MakeRegion(DomNode node)
{ {
if (node == null) if (node == null)
return DomRegion.Empty; return DomRegion.Empty;
@ -314,7 +314,7 @@ namespace ICSharpCode.NRefactory.CSharp
return m; return m;
} }
DefaultExplicitInterfaceImplementation ConvertInterfaceImplementation(INode interfaceType, string memberName) DefaultExplicitInterfaceImplementation ConvertInterfaceImplementation(DomNode interfaceType, string memberName)
{ {
return new DefaultExplicitInterfaceImplementation(ConvertType(interfaceType), memberName); return new DefaultExplicitInterfaceImplementation(ConvertType(interfaceType), memberName);
} }
@ -505,7 +505,7 @@ namespace ICSharpCode.NRefactory.CSharp
#region Types #region Types
static readonly GetClassTypeReference voidReference = new GetClassTypeReference("System.Void", 0); static readonly GetClassTypeReference voidReference = new GetClassTypeReference("System.Void", 0);
internal static ITypeReference ConvertType(INode node) internal static ITypeReference ConvertType(DomNode node)
{ {
FullTypeName f = node as FullTypeName; FullTypeName f = node as FullTypeName;
if (f != null) { if (f != null) {
@ -523,7 +523,7 @@ namespace ICSharpCode.NRefactory.CSharp
#endregion #endregion
#region Constant Values #region Constant Values
IConstantValue ConvertConstantValue(ITypeReference targetType, INode expression) IConstantValue ConvertConstantValue(ITypeReference targetType, DomNode expression)
{ {
return new SimpleConstantValue(targetType, null); return new SimpleConstantValue(targetType, null);
} }

14
ICSharpCode.NRefactory/CSharp/Parser/mcs/MonoSymbolFile.cs

@ -443,18 +443,22 @@ namespace Mono.CompilerServices.SymbolWriter
} }
#if CECIL #if CECIL
protected MonoSymbolFile (string filename, Mono.Cecil.AssemblyDefinition assembly) : this (filename) protected MonoSymbolFile (string filename, Mono.Cecil.ModuleDefinition module)
: this (filename)
{ {
Guid mvid = assembly.MainModule.Mvid; CheckGuidMatch (module.Mvid, filename, module.FullyQualifiedName);
}
CheckGuidMatch (mvid, filename, assembly.MainModule.Image.FileInformation.FullName); public static MonoSymbolFile ReadSymbolFile (Mono.Cecil.ModuleDefinition module)
{
return ReadSymbolFile (module, module.FullyQualifiedName);
} }
public static MonoSymbolFile ReadSymbolFile (Mono.Cecil.AssemblyDefinition assembly, string filename) public static MonoSymbolFile ReadSymbolFile (Mono.Cecil.ModuleDefinition module, string filename)
{ {
string name = filename + ".mdb"; string name = filename + ".mdb";
return new MonoSymbolFile (name, assembly); return new MonoSymbolFile (name, module);
} }
#else #else
protected MonoSymbolFile (string filename, Assembly assembly) : this (filename) protected MonoSymbolFile (string filename, Assembly assembly) : this (filename)

22
ICSharpCode.NRefactory/CSharp/Parser/mcs/anonymous.cs

@ -80,8 +80,21 @@ namespace Mono.CSharp {
{ {
if (tparams != null) { if (tparams != null) {
type_params = new TypeParameter[tparams.Length]; type_params = new TypeParameter[tparams.Length];
var src = new TypeParameterSpec[tparams.Length];
var dst = new TypeParameterSpec[tparams.Length];
for (int i = 0; i < type_params.Length; ++i) { for (int i = 0; i < type_params.Length; ++i) {
type_params[i] = tparams[i].CreateHoistedCopy (this, spec); type_params[i] = tparams[i].CreateHoistedCopy (this, spec);
src[i] = tparams[i].Type;
dst[i] = type_params[i].Type;
}
// A copy is not enough, inflate any type parameter constraints
// using a new type parameters
var inflator = new TypeParameterInflator (null, src, dst);
for (int i = 0; i < type_params.Length; ++i) {
src[i].InflateConstraints (inflator, dst[i]);
} }
} }
} }
@ -351,6 +364,12 @@ namespace Mono.CSharp {
} }
} }
//
// Update parent cache as we most likely passed the point
// where the cache was constructed
//
Parent.CurrentType.MemberCache.AddMember (this.spec);
return true; return true;
} }
@ -1588,6 +1607,9 @@ namespace Mono.CSharp {
ec.Emit (OpCodes.Ldftn, TypeBuilder.GetMethod (t.GetMetaInfo (), (MethodInfo) delegate_method.GetMetaInfo ())); ec.Emit (OpCodes.Ldftn, TypeBuilder.GetMethod (t.GetMetaInfo (), (MethodInfo) delegate_method.GetMetaInfo ()));
} else { } else {
if (delegate_method.IsGeneric)
delegate_method = delegate_method.MakeGenericMethod (method.TypeParameters);
ec.Emit (OpCodes.Ldftn, delegate_method); ec.Emit (OpCodes.Ldftn, delegate_method);
} }

46
ICSharpCode.NRefactory/CSharp/Parser/mcs/argument.cs

@ -10,7 +10,6 @@
// //
using System; using System;
using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
using System.Collections.Generic; using System.Collections.Generic;
@ -48,8 +47,14 @@ namespace Mono.CSharp
this.Expr = expr; this.Expr = expr;
} }
public TypeSpec Type { #region Properties
get { return Expr.Type; }
public bool IsByRef {
get { return ArgType == AType.Ref || ArgType == AType.Out; }
}
public bool IsDefaultArgument {
get { return ArgType == AType.Default; }
} }
public Parameter.Modifier Modifier { public Parameter.Modifier Modifier {
@ -67,6 +72,24 @@ namespace Mono.CSharp
} }
} }
public TypeSpec Type {
get { return Expr.Type; }
}
#endregion
public Argument Clone (Expression expr)
{
Argument a = (Argument) MemberwiseClone ();
a.Expr = expr;
return a;
}
public Argument Clone (CloneContext clonectx)
{
return Clone (Expr.Clone (clonectx));
}
public virtual Expression CreateExpressionTree (ResolveContext ec) public virtual Expression CreateExpressionTree (ResolveContext ec)
{ {
if (ArgType == AType.Default) if (ArgType == AType.Default)
@ -83,14 +106,6 @@ namespace Mono.CSharp
return TypeManager.CSharpName (Expr.Type); return TypeManager.CSharpName (Expr.Type);
} }
public bool IsByRef {
get { return ArgType == AType.Ref || ArgType == AType.Out; }
}
public bool IsDefaultArgument {
get { return ArgType == AType.Default; }
}
public bool ResolveMethodGroup (ResolveContext ec) public bool ResolveMethodGroup (ResolveContext ec)
{ {
SimpleName sn = Expr as SimpleName; SimpleName sn = Expr as SimpleName;
@ -139,13 +154,6 @@ namespace Mono.CSharp
IMemoryLocation ml = (IMemoryLocation) Expr; IMemoryLocation ml = (IMemoryLocation) Expr;
ml.AddressOf (ec, mode); ml.AddressOf (ec, mode);
} }
public Argument Clone (CloneContext clonectx)
{
Argument a = (Argument) MemberwiseClone ();
a.Expr = Expr.Clone (clonectx);
return a;
}
} }
public class NamedArgument : Argument public class NamedArgument : Argument
@ -395,7 +403,7 @@ namespace Mono.CSharp
if (!dup_args) if (!dup_args)
continue; continue;
if (a.Expr is Constant) { if (a.Expr is Constant || a.Expr is This) {
// //
// No need to create a temporary variable for constants // No need to create a temporary variable for constants
// //

1080
ICSharpCode.NRefactory/CSharp/Parser/mcs/assembly.cs

File diff suppressed because it is too large Load Diff

30
ICSharpCode.NRefactory/CSharp/Parser/mcs/assign.cs

@ -12,7 +12,6 @@
// Copyright 2004-2008 Novell, Inc // Copyright 2004-2008 Novell, Inc
// //
using System; using System;
using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
namespace Mono.CSharp { namespace Mono.CSharp {
@ -361,7 +360,13 @@ namespace Mono.CSharp {
if (target_object.NodeType == System.Linq.Expressions.ExpressionType.Block) if (target_object.NodeType == System.Linq.Expressions.ExpressionType.Block)
return target_object; return target_object;
var source_object = System.Linq.Expressions.Expression.Convert (source.MakeExpression (ctx), target_object.Type); System.Linq.Expressions.UnaryExpression source_object;
if (ctx.HasSet (BuilderContext.Options.CheckedScope)) {
source_object = System.Linq.Expressions.Expression.ConvertChecked (source.MakeExpression (ctx), target_object.Type);
} else {
source_object = System.Linq.Expressions.Expression.Convert (source.MakeExpression (ctx), target_object.Type);
}
return System.Linq.Expressions.Expression.Assign (target_object, source_object); return System.Linq.Expressions.Expression.Assign (target_object, source_object);
} }
#endif #endif
@ -449,11 +454,8 @@ namespace Mono.CSharp {
protected override Expression ResolveConversions (ResolveContext ec) protected override Expression ResolveConversions (ResolveContext ec)
{ {
source = Convert.ExplicitConversion (ec, source, target.Type, loc); source = EmptyCast.Create (source, target.Type);
if (source != null) return this;
return this;
return base.ResolveConversions (ec);
} }
} }
@ -673,8 +675,18 @@ namespace Mono.CSharp {
Arguments args = new Arguments (targs.Count + 1); Arguments args = new Arguments (targs.Count + 1);
args.AddRange (targs); args.AddRange (targs);
args.Add (new Argument (source)); args.Add (new Argument (source));
var binder_flags = CSharpBinderFlags.ValueFromCompoundAssignment;
//
// Compound assignment does target conversion using additional method
// call, set checked context as the binary operation can overflow
//
if (ec.HasSet (ResolveContext.Options.CheckedScope))
binder_flags |= CSharpBinderFlags.CheckedContext;
if (target is DynamicMemberBinder) { if (target is DynamicMemberBinder) {
source = new DynamicMemberBinder (ma.Name, CSharpBinderFlags.ValueFromCompoundAssignment, args, loc).Resolve (ec); source = new DynamicMemberBinder (ma.Name, binder_flags, args, loc).Resolve (ec);
// Handles possible event addition/subtraction // Handles possible event addition/subtraction
if (op == Binary.Operator.Addition || op == Binary.Operator.Subtraction) { if (op == Binary.Operator.Addition || op == Binary.Operator.Subtraction) {
@ -693,7 +705,7 @@ namespace Mono.CSharp {
(ExpressionStatement) source, (ExpressionStatement) invoke, loc).Resolve (ec); (ExpressionStatement) source, (ExpressionStatement) invoke, loc).Resolve (ec);
} }
} else { } else {
source = new DynamicIndexBinder (CSharpBinderFlags.ValueFromCompoundAssignment, args, loc).Resolve (ec); source = new DynamicIndexBinder (binder_flags, args, loc).Resolve (ec);
} }
return source; return source;

331
ICSharpCode.NRefactory/CSharp/Parser/mcs/attribute.cs

@ -80,8 +80,8 @@ namespace Mono.CSharp {
public AttributeTargets Target; public AttributeTargets Target;
readonly ATypeNameExpression expression; readonly ATypeNameExpression expression;
Arguments PosArguments; public Arguments PosArguments;
Arguments NamedArguments; public Arguments NamedArguments;
bool resolve_error; bool resolve_error;
bool arg_resolved; bool arg_resolved;
@ -102,7 +102,7 @@ namespace Mono.CSharp {
static Assembly orig_sec_assembly; static Assembly orig_sec_assembly;
public static readonly object[] EmptyObject = new object [0]; public static readonly object[] EmptyObject = new object [0];
IList<KeyValuePair<MemberExpr, NamedArgument>> named_values; List<KeyValuePair<MemberExpr, NamedArgument>> named_values;
// Cache for parameter-less attributes // Cache for parameter-less attributes
static Dictionary<TypeSpec, MethodSpec> att_cache; static Dictionary<TypeSpec, MethodSpec> att_cache;
@ -142,7 +142,7 @@ namespace Mono.CSharp {
// we use @target field as a list of targets. The attribute // we use @target field as a list of targets. The attribute
// has to be resolved only once but emitted for each target. // has to be resolved only once but emitted for each target.
// //
public virtual void AttachTo (Attributable target, IMemberContext context) public void AttachTo (Attributable target, IMemberContext context)
{ {
if (this.targets == null) { if (this.targets == null) {
this.targets = new Attributable[] { target }; this.targets = new Attributable[] { target };
@ -340,7 +340,7 @@ namespace Mono.CSharp {
if (Type != context.Compiler.PredefinedAttributes.DllImport) if (Type != context.Compiler.PredefinedAttributes.DllImport)
return; return;
if (!RootContext.ToplevelTypes.HasDefaultCharSet) if (!rc.CurrentMemberDefinition.Module.HasDefaultCharSet)
return; return;
const string CharSetEnumMember = "CharSet"; const string CharSetEnumMember = "CharSet";
@ -355,7 +355,7 @@ namespace Mono.CSharp {
var char_set = rc.Compiler.MetaImporter.ImportType (typeof (CharSet)); // TODO: typeof var char_set = rc.Compiler.MetaImporter.ImportType (typeof (CharSet)); // TODO: typeof
NamedArguments.Add (new NamedArgument (CharSetEnumMember, loc, NamedArguments.Add (new NamedArgument (CharSetEnumMember, loc,
Constant.CreateConstant (rc, char_set, RootContext.ToplevelTypes.DefaultCharSet, Location))); Constant.CreateConstant (rc, char_set, rc.CurrentMemberDefinition.Module.DefaultCharSet, Location)));
} }
public Report Report { public Report Report {
@ -584,11 +584,11 @@ namespace Mono.CSharp {
AttributeUsageAttribute usage_attribute = new AttributeUsageAttribute ((AttributeTargets)((Constant) PosArguments [0].Expr).GetValue ()); AttributeUsageAttribute usage_attribute = new AttributeUsageAttribute ((AttributeTargets)((Constant) PosArguments [0].Expr).GetValue ());
var field = GetPropertyValue ("AllowMultiple") as BoolConstant; var field = GetNamedValue ("AllowMultiple") as BoolConstant;
if (field != null) if (field != null)
usage_attribute.AllowMultiple = field.Value; usage_attribute.AllowMultiple = field.Value;
field = GetPropertyValue ("Inherited") as BoolConstant; field = GetNamedValue ("Inherited") as BoolConstant;
if (field != null) if (field != null)
usage_attribute.Inherited = field.Value; usage_attribute.Inherited = field.Value;
@ -701,6 +701,7 @@ namespace Mono.CSharp {
case "field": Target = AttributeTargets.Field; return true; case "field": Target = AttributeTargets.Field; return true;
case "method": Target = AttributeTargets.Method; return true; case "method": Target = AttributeTargets.Method; return true;
case "property": Target = AttributeTargets.Property; return true; case "property": Target = AttributeTargets.Property; return true;
case "module": Target = AttributeTargets.Module; return true;
} }
throw new InternalErrorException ("Unknown explicit target: " + ExplicitTarget); throw new InternalErrorException ("Unknown explicit target: " + ExplicitTarget);
} }
@ -857,7 +858,7 @@ namespace Mono.CSharp {
ps.AddPermission (perm); ps.AddPermission (perm);
} }
public Constant GetPropertyValue (string name) public Constant GetNamedValue (string name)
{ {
if (named_values == null) if (named_values == null)
return null; return null;
@ -1110,7 +1111,7 @@ namespace Mono.CSharp {
na.Value.Expr.EncodeAttributeValue (context, encoder, na.Key.Type); na.Value.Expr.EncodeAttributeValue (context, encoder, na.Key.Type);
} }
} else { } else {
encoder.Stream.Write ((ushort) 0); encoder.EncodeEmptyNamedArguments ();
} }
byte[] cdata = encoder.ToArray (); byte[] cdata = encoder.ToArray ();
@ -1214,21 +1215,6 @@ namespace Mono.CSharp {
{ {
this.ns = ns; this.ns = ns;
} }
public override void AttachTo (Attributable target, IMemberContext context)
{
if (ExplicitTarget == "assembly") {
base.AttachTo (CodeGen.Assembly, context);
return;
}
if (ExplicitTarget == "module") {
base.AttachTo (RootContext.ToplevelTypes, context);
return;
}
throw new NotImplementedException ("Unknown global explicit target " + ExplicitTarget);
}
void Enter () void Enter ()
{ {
@ -1336,8 +1322,16 @@ namespace Mono.CSharp {
} }
public Attribute Search (PredefinedAttribute t) public Attribute Search (PredefinedAttribute t)
{
return Search (null, t);
}
public Attribute Search (string explicitTarget, PredefinedAttribute t)
{ {
foreach (Attribute a in Attrs) { foreach (Attribute a in Attrs) {
if (explicitTarget != null && a.ExplicitTarget != explicitTarget)
continue;
if (a.ResolveType () == t) if (a.ResolveType () == t)
return a; return a;
} }
@ -1404,8 +1398,18 @@ namespace Mono.CSharp {
TypeParameter = 1 << 1 TypeParameter = 1 << 1
} }
const ushort Version = 1;
public static readonly byte[] Empty;
public readonly BinaryWriter Stream; public readonly BinaryWriter Stream;
static AttributeEncoder ()
{
Empty = new byte[4];
Array.Copy (BitConverter.GetBytes (Version), Empty, 2);
}
public AttributeEncoder (bool empty) public AttributeEncoder (bool empty)
{ {
if (empty) { if (empty) {
@ -1414,8 +1418,27 @@ namespace Mono.CSharp {
} }
Stream = new BinaryWriter (new MemoryStream ()); Stream = new BinaryWriter (new MemoryStream ());
const ushort version = 1; Stream.Write (Version);
Stream.Write (version); }
public void Encode (byte value)
{
Stream.Write (value);
}
public void Encode (short value)
{
Stream.Write (value);
}
public void Encode (int value)
{
Stream.Write (value);
}
public void Encode (uint value)
{
Stream.Write (value);
} }
public void Encode (string value) public void Encode (string value)
@ -1480,6 +1503,56 @@ namespace Mono.CSharp {
Encode (type.MemberDefinition.IsImported ? old_type.AssemblyQualifiedName : old_type.FullName); Encode (type.MemberDefinition.IsImported ? old_type.AssemblyQualifiedName : old_type.FullName);
} }
//
// Encodes single property named argument per call
//
public void EncodeNamedPropertyArgument (PropertySpec property, Constant value)
{
Stream.Write ((ushort) 1); // length
Stream.Write ((byte) 0x54); // property
Encode (property.MemberType);
Encode (property.Name);
value.EncodeAttributeValue (null, this, property.MemberType);
}
//
// Encodes single field named argument per call
//
public void EncodeNamedFieldArgument (FieldSpec field, Constant value)
{
Stream.Write ((ushort) 1); // length
Stream.Write ((byte) 0x53); // field
Encode (field.MemberType);
Encode (field.Name);
value.EncodeAttributeValue (null, this, field.MemberType);
}
public void EncodeNamedArguments<T> (T[] members, Constant[] values) where T : MemberSpec, IInterfaceMemberSpec
{
Stream.Write ((ushort) members.Length);
for (int i = 0; i < members.Length; ++i)
{
var member = members[i];
if (member.Kind == MemberKind.Field)
Stream.Write ((byte) 0x53);
else if (member.Kind == MemberKind.Property)
Stream.Write ((byte) 0x54);
else
throw new NotImplementedException (member.Kind.ToString ());
Encode (member.MemberType);
Encode (member.Name);
values [i].EncodeAttributeValue (null, this, member.MemberType);
}
}
public void EncodeEmptyNamedArguments ()
{
Stream.Write ((ushort) 0);
}
void WriteCompressedValue (int value) void WriteCompressedValue (int value)
{ {
if (value < 0x80) { if (value < 0x80) {
@ -1558,23 +1631,6 @@ namespace Mono.CSharp {
return result; return result;
} }
public static void VerifyModulesClsCompliance (CompilerContext ctx)
{
Module[] modules = ctx.GlobalRootNamespace.Modules;
if (modules == null)
return;
// The first module is generated assembly
for (int i = 1; i < modules.Length; ++i) {
Module module = modules [i];
if (!GetClsCompliantAttributeValue (module, null)) {
ctx.Report.Error (3013, "Added modules must be marked with the CLSCompliant attribute " +
"to match the assembly", module.Name);
return;
}
}
}
static bool GetClsCompliantAttributeValue (ICustomAttributeProvider attribute_provider, Assembly a) static bool GetClsCompliantAttributeValue (ICustomAttributeProvider attribute_provider, Assembly a)
{ {
object[] cls_attr = attribute_provider.GetCustomAttributes (typeof (CLSCompliantAttribute), false); object[] cls_attr = attribute_provider.GetCustomAttributes (typeof (CLSCompliantAttribute), false);
@ -1633,6 +1689,7 @@ namespace Mono.CSharp {
public readonly PredefinedAttribute AttributeUsage; public readonly PredefinedAttribute AttributeUsage;
public readonly PredefinedAttribute DefaultParameterValue; public readonly PredefinedAttribute DefaultParameterValue;
public readonly PredefinedAttribute OptionalParameter; public readonly PredefinedAttribute OptionalParameter;
public readonly PredefinedAttribute UnverifiableCode;
// New in .NET 2.0 // New in .NET 2.0
public readonly PredefinedAttribute DefaultCharset; public readonly PredefinedAttribute DefaultCharset;
@ -1654,7 +1711,7 @@ namespace Mono.CSharp {
// Optional types which are used as types and for member lookup // Optional types which are used as types and for member lookup
// //
public readonly PredefinedAttribute DefaultMember; public readonly PredefinedAttribute DefaultMember;
public readonly PredefinedAttribute DecimalConstant; public readonly PredefinedDecimalAttribute DecimalConstant;
public readonly PredefinedAttribute StructLayout; public readonly PredefinedAttribute StructLayout;
public readonly PredefinedAttribute FieldOffset; public readonly PredefinedAttribute FieldOffset;
@ -1683,6 +1740,7 @@ namespace Mono.CSharp {
AttributeUsage = new PredefinedAttribute ("System", "AttributeUsageAttribute"); AttributeUsage = new PredefinedAttribute ("System", "AttributeUsageAttribute");
DefaultParameterValue = new PredefinedAttribute ("System.Runtime.InteropServices", "DefaultParameterValueAttribute"); DefaultParameterValue = new PredefinedAttribute ("System.Runtime.InteropServices", "DefaultParameterValueAttribute");
OptionalParameter = new PredefinedAttribute ("System.Runtime.InteropServices", "OptionalAttribute"); OptionalParameter = new PredefinedAttribute ("System.Runtime.InteropServices", "OptionalAttribute");
UnverifiableCode = new PredefinedAttribute ("System.Security", "UnverifiableCodeAttribute");
DefaultCharset = new PredefinedAttribute ("System.Runtime.InteropServices", "DefaultCharSetAttribute"); DefaultCharset = new PredefinedAttribute ("System.Runtime.InteropServices", "DefaultCharSetAttribute");
TypeForwarder = new PredefinedAttribute ("System.Runtime.CompilerServices", "TypeForwardedToAttribute"); TypeForwarder = new PredefinedAttribute ("System.Runtime.CompilerServices", "TypeForwardedToAttribute");
@ -1698,7 +1756,7 @@ namespace Mono.CSharp {
Dynamic = new PredefinedDynamicAttribute ("System.Runtime.CompilerServices", "DynamicAttribute"); Dynamic = new PredefinedDynamicAttribute ("System.Runtime.CompilerServices", "DynamicAttribute");
DefaultMember = new PredefinedAttribute ("System.Reflection", "DefaultMemberAttribute"); DefaultMember = new PredefinedAttribute ("System.Reflection", "DefaultMemberAttribute");
DecimalConstant = new PredefinedAttribute ("System.Runtime.CompilerServices", "DecimalConstantAttribute"); DecimalConstant = new PredefinedDecimalAttribute ("System.Runtime.CompilerServices", "DecimalConstantAttribute");
StructLayout = new PredefinedAttribute ("System.Runtime.InteropServices", "StructLayoutAttribute"); StructLayout = new PredefinedAttribute ("System.Runtime.InteropServices", "StructLayoutAttribute");
FieldOffset = new PredefinedAttribute ("System.Runtime.InteropServices", "FieldOffsetAttribute"); FieldOffset = new PredefinedAttribute ("System.Runtime.InteropServices", "FieldOffsetAttribute");
} }
@ -1714,10 +1772,11 @@ namespace Mono.CSharp {
public class PredefinedAttribute public class PredefinedAttribute
{ {
protected TypeSpec type; protected TypeSpec type;
CustomAttributeBuilder cab; protected MethodSpec ctor;
MethodSpec ctor;
readonly string ns, name; readonly string ns, name;
CompilerContext compiler; CompilerContext compiler;
List<FieldSpec> fields;
List<PropertySpec> properties;
static readonly TypeSpec NotFound = InternalType.Null; static readonly TypeSpec NotFound = InternalType.Null;
@ -1727,6 +1786,29 @@ namespace Mono.CSharp {
this.name = name; this.name = name;
} }
#region Properties
public MethodSpec Constructor {
get {
return ctor;
}
}
public bool IsDefined {
get {
return type != null && type != NotFound;
}
}
public TypeSpec Type {
get {
return type;
}
}
#endregion
public static bool operator == (TypeSpec type, PredefinedAttribute pa) public static bool operator == (TypeSpec type, PredefinedAttribute pa)
{ {
return type == pa.type; return type == pa.type;
@ -1737,10 +1819,6 @@ namespace Mono.CSharp {
return type != pa.type; return type != pa.type;
} }
public ConstructorInfo Constructor {
get { return ctor == null ? null : (ConstructorInfo) ctor.GetMetaInfo (); }
}
public override int GetHashCode () public override int GetHashCode ()
{ {
return base.GetHashCode (); return base.GetHashCode ();
@ -1759,47 +1837,118 @@ namespace Mono.CSharp {
public void EmitAttribute (ConstructorBuilder builder) public void EmitAttribute (ConstructorBuilder builder)
{ {
if (ResolveBuilder ()) if (ResolveBuilder ())
builder.SetCustomAttribute (cab); builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
} }
public void EmitAttribute (MethodBuilder builder) public void EmitAttribute (MethodBuilder builder)
{ {
if (ResolveBuilder ()) if (ResolveBuilder ())
builder.SetCustomAttribute (cab); builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
} }
public void EmitAttribute (PropertyBuilder builder) public void EmitAttribute (PropertyBuilder builder)
{ {
if (ResolveBuilder ()) if (ResolveBuilder ())
builder.SetCustomAttribute (cab); builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
} }
public void EmitAttribute (FieldBuilder builder) public void EmitAttribute (FieldBuilder builder)
{ {
if (ResolveBuilder ()) if (ResolveBuilder ())
builder.SetCustomAttribute (cab); builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
}
public void EmitAttribute (FieldBuilder builder, AttributeEncoder argsEncoded)
{
builder.SetCustomAttribute (GetCtorMetaInfo (), argsEncoded.ToArray ());
} }
public void EmitAttribute (TypeBuilder builder) public void EmitAttribute (TypeBuilder builder)
{ {
if (ResolveBuilder ()) if (ResolveBuilder ())
builder.SetCustomAttribute (cab); builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
}
public void EmitAttribute (TypeBuilder builder, AttributeEncoder argsEncoded)
{
builder.SetCustomAttribute (GetCtorMetaInfo (), argsEncoded.ToArray ());
} }
public void EmitAttribute (AssemblyBuilder builder) public void EmitAttribute (AssemblyBuilder builder)
{ {
if (ResolveBuilder ()) if (ResolveBuilder ())
builder.SetCustomAttribute (cab); builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
}
public void EmitAttribute (ModuleBuilder builder)
{
if (ResolveBuilder ())
builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
} }
public void EmitAttribute (ParameterBuilder builder) public void EmitAttribute (ParameterBuilder builder)
{ {
if (ResolveBuilder ()) if (ResolveBuilder ())
builder.SetCustomAttribute (cab); builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
} }
public bool IsDefined { public void EmitAttribute (ParameterBuilder builder, AttributeEncoder argsEncoded)
get { return type != null && type != NotFound; } {
builder.SetCustomAttribute (GetCtorMetaInfo (), argsEncoded.ToArray ());
}
ConstructorInfo GetCtorMetaInfo ()
{
return (ConstructorInfo) ctor.GetMetaInfo ();
}
public FieldSpec GetField (string name, TypeSpec memberType, Location loc)
{
FieldSpec spec;
if (fields != null) {
spec = fields.Find (l => l.Name == name);
} else {
spec = null;
}
if (spec == null) {
spec = TypeManager.GetPredefinedField (type, name, loc, memberType);
if (spec != null) {
if (fields == null) {
fields = new List<FieldSpec> ();
}
fields.Add (spec);
}
}
return spec;
}
public PropertySpec GetProperty (string name, TypeSpec memberType, Location loc)
{
PropertySpec spec;
if (properties != null) {
spec = properties.Find (l => l.Name == name);
} else {
spec = null;
}
if (spec == null) {
spec = TypeManager.GetPredefinedProperty (type, name, loc, memberType);
if (spec != null) {
if (properties == null) {
properties = new List<PropertySpec> ();
}
properties.Add (spec);
}
}
return spec;
} }
public void Initialize (CompilerContext ctx, bool canFail) public void Initialize (CompilerContext ctx, bool canFail)
@ -1826,9 +1975,9 @@ namespace Mono.CSharp {
return true; return true;
} }
bool ResolveBuilder () public bool ResolveBuilder ()
{ {
if (cab != null) if (ctor != null)
return true; return true;
// //
@ -1837,12 +1986,8 @@ namespace Mono.CSharp {
if (!Resolve (true)) if (!Resolve (true))
return false; return false;
var ci = TypeManager.GetPredefinedConstructor (type, Location.Null, TypeSpec.EmptyTypes); ctor = TypeManager.GetPredefinedConstructor (type, Location.Null, TypeSpec.EmptyTypes);
if (ci == null) return ctor != null;
return false;
cab = new CustomAttributeBuilder ((ConstructorInfo) ci.GetMetaInfo (), new object[0]);
return true;
} }
public bool ResolveConstructor (Location loc, params TypeSpec[] argType) public bool ResolveConstructor (Location loc, params TypeSpec[] argType)
@ -1856,9 +2001,53 @@ namespace Mono.CSharp {
ctor = TypeManager.GetPredefinedConstructor (type, loc, argType); ctor = TypeManager.GetPredefinedConstructor (type, loc, argType);
return ctor != null; return ctor != null;
} }
}
public TypeSpec Type { public class PredefinedDecimalAttribute : PredefinedAttribute
get { return type; } {
public PredefinedDecimalAttribute (string ns, string name)
: base (ns, name)
{
}
public void EmitAttribute (ParameterBuilder builder, decimal value, Location loc)
{
if (!Resolve (false))
return;
if (ctor == null && !ResolveConstructor (loc, TypeManager.byte_type, TypeManager.byte_type, TypeManager.uint32_type, TypeManager.uint32_type, TypeManager.uint32_type))
return;
int[] bits = decimal.GetBits (value);
AttributeEncoder encoder = new AttributeEncoder (false);
encoder.Encode ((byte) (bits[3] >> 16));
encoder.Encode ((byte) (bits[3] >> 31));
encoder.Encode ((uint) bits[2]);
encoder.Encode ((uint) bits[1]);
encoder.Encode ((uint) bits[0]);
encoder.EncodeEmptyNamedArguments ();
EmitAttribute (builder, encoder);
}
public void EmitAttribute (FieldBuilder builder, decimal value, Location loc)
{
if (!Resolve (false))
return;
if (ctor == null && !ResolveConstructor (loc, TypeManager.byte_type, TypeManager.byte_type, TypeManager.uint32_type, TypeManager.uint32_type, TypeManager.uint32_type))
return;
int[] bits = decimal.GetBits (value);
AttributeEncoder encoder = new AttributeEncoder (false);
encoder.Encode ((byte) (bits[3] >> 16));
encoder.Encode ((byte) (bits[3] >> 31));
encoder.Encode ((uint) bits[2]);
encoder.Encode ((uint) bits[1]);
encoder.Encode ((uint) bits[0]);
encoder.EncodeEmptyNamedArguments ();
EmitAttribute (builder, encoder);
} }
} }

84
ICSharpCode.NRefactory/CSharp/Parser/mcs/cfold.cs

@ -169,7 +169,7 @@ namespace Mono.CSharp {
case Binary.Operator.Subtraction: case Binary.Operator.Subtraction:
result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc); result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
if (result != null) if (result != null)
result = result.Resolve (ec).TryReduce (ec, ((EnumConstant)left).Child.Type, loc); result = result.Resolve (ec).TryReduce (ec, EnumSpec.GetUnderlyingType (lt), loc);
return result; return result;
/// ///
@ -477,6 +477,11 @@ namespace Mono.CSharp {
return new EnumConstant (result, lt); return new EnumConstant (result, lt);
} }
if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (TypeManager.int32_type, loc).ResolveAsTypeTerminal (ec, false);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right)) if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return null; return null;
@ -568,6 +573,11 @@ namespace Mono.CSharp {
return result; return result;
case Binary.Operator.Multiply: case Binary.Operator.Multiply:
if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (TypeManager.int32_type, loc).ResolveAsTypeTerminal (ec, false);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right)) if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return null; return null;
@ -658,6 +668,11 @@ namespace Mono.CSharp {
break; break;
case Binary.Operator.Division: case Binary.Operator.Division:
if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (TypeManager.int32_type, loc).ResolveAsTypeTerminal (ec, false);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right)) if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return null; return null;
@ -752,6 +767,11 @@ namespace Mono.CSharp {
break; break;
case Binary.Operator.Modulus: case Binary.Operator.Modulus:
if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (TypeManager.int32_type, loc).ResolveAsTypeTerminal (ec, false);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right)) if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return null; return null;
@ -836,6 +856,11 @@ namespace Mono.CSharp {
// There is no overflow checking on left shift // There is no overflow checking on left shift
// //
case Binary.Operator.LeftShift: case Binary.Operator.LeftShift:
if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (TypeManager.int32_type, loc).ResolveAsTypeTerminal (ec, false);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
}
IntConstant ic = right.ConvertImplicitly (ec, TypeManager.int32_type) as IntConstant; IntConstant ic = right.ConvertImplicitly (ec, TypeManager.int32_type) as IntConstant;
if (ic == null){ if (ic == null){
Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc); Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
@ -850,6 +875,10 @@ namespace Mono.CSharp {
if (left.Type == TypeManager.uint32_type) if (left.Type == TypeManager.uint32_type)
return new UIntConstant (((UIntConstant)left).Value << lshift_val, left.Location); return new UIntConstant (((UIntConstant)left).Value << lshift_val, left.Location);
// null << value => null
if (left is NullLiteral)
return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
left = left.ConvertImplicitly (ec, TypeManager.int32_type); left = left.ConvertImplicitly (ec, TypeManager.int32_type);
if (left.Type == TypeManager.int32_type) if (left.Type == TypeManager.int32_type)
return new IntConstant (((IntConstant)left).Value << lshift_val, left.Location); return new IntConstant (((IntConstant)left).Value << lshift_val, left.Location);
@ -861,6 +890,11 @@ namespace Mono.CSharp {
// There is no overflow checking on right shift // There is no overflow checking on right shift
// //
case Binary.Operator.RightShift: case Binary.Operator.RightShift:
if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (TypeManager.int32_type, loc).ResolveAsTypeTerminal (ec, false);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
}
IntConstant sic = right.ConvertImplicitly (ec, TypeManager.int32_type) as IntConstant; IntConstant sic = right.ConvertImplicitly (ec, TypeManager.int32_type) as IntConstant;
if (sic == null){ if (sic == null){
Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc); ; Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc); ;
@ -874,6 +908,10 @@ namespace Mono.CSharp {
if (left.Type == TypeManager.uint32_type) if (left.Type == TypeManager.uint32_type)
return new UIntConstant (((UIntConstant)left).Value >> rshift_val, left.Location); return new UIntConstant (((UIntConstant)left).Value >> rshift_val, left.Location);
// null >> value => null
if (left is NullLiteral)
return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
left = left.ConvertImplicitly (ec, TypeManager.int32_type); left = left.ConvertImplicitly (ec, TypeManager.int32_type);
if (left.Type == TypeManager.int32_type) if (left.Type == TypeManager.int32_type)
return new IntConstant (((IntConstant)left).Value >> rshift_val, left.Location); return new IntConstant (((IntConstant)left).Value >> rshift_val, left.Location);
@ -970,6 +1008,17 @@ namespace Mono.CSharp {
return new BoolConstant (bool_res, left.Location); return new BoolConstant (bool_res, left.Location);
case Binary.Operator.LessThan: case Binary.Operator.LessThan:
if (right is NullLiteral) {
if (left is NullLiteral) {
var lifted_int = new Nullable.NullableType (TypeManager.int32_type, loc).ResolveAsTypeTerminal (ec, false);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
}
if (left is Nullable.LiftedNull) {
return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
}
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right)) if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return null; return null;
@ -998,6 +1047,17 @@ namespace Mono.CSharp {
return new BoolConstant (bool_res, left.Location); return new BoolConstant (bool_res, left.Location);
case Binary.Operator.GreaterThan: case Binary.Operator.GreaterThan:
if (right is NullLiteral) {
if (left is NullLiteral) {
var lifted_int = new Nullable.NullableType (TypeManager.int32_type, loc).ResolveAsTypeTerminal (ec, false);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
}
if (left is Nullable.LiftedNull) {
return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
}
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right)) if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return null; return null;
@ -1026,6 +1086,17 @@ namespace Mono.CSharp {
return new BoolConstant (bool_res, left.Location); return new BoolConstant (bool_res, left.Location);
case Binary.Operator.GreaterThanOrEqual: case Binary.Operator.GreaterThanOrEqual:
if (right is NullLiteral) {
if (left is NullLiteral) {
var lifted_int = new Nullable.NullableType (TypeManager.int32_type, loc).ResolveAsTypeTerminal (ec, false);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
}
if (left is Nullable.LiftedNull) {
return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
}
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right)) if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return null; return null;
@ -1054,6 +1125,17 @@ namespace Mono.CSharp {
return new BoolConstant (bool_res, left.Location); return new BoolConstant (bool_res, left.Location);
case Binary.Operator.LessThanOrEqual: case Binary.Operator.LessThanOrEqual:
if (right is NullLiteral) {
if (left is NullLiteral) {
var lifted_int = new Nullable.NullableType (TypeManager.int32_type, loc).ResolveAsTypeTerminal (ec, false);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
}
if (left is Nullable.LiftedNull) {
return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
}
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right)) if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return null; return null;

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

Loading…
Cancel
Save