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 @@ -13,38 +13,38 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
/// </summary>
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();
CompilationUnit cu = parser.Parse(new StringReader(code));
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
INode node = cu.Children.Single();
DomNode node = cu.Children.Single();
Type type = typeof(T);
Assert.IsTrue(type.IsAssignableFrom(node.GetType()), String.Format("Parsed node was {0} instead of {1} ({2})", node.GetType(), type, 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();
var statements = parser.ParseStatements(new StringReader(stmt));
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");
INode statement = statements.Single();
DomNode statement = statements.Single();
Type type = typeof(T);
Assert.IsTrue(type.IsAssignableFrom(statement.GetType()), String.Format("Parsed statement was {0} instead of {1} ({2})", statement.GetType(), type, 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");
CSharpParser parser = new CSharpParser();
INode parsedExpression = parser.ParseExpression(new StringReader(expr));
DomNode parsedExpression = parser.ParseExpression(new StringReader(expr));
Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors");

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

@ -175,11 +175,11 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -175,11 +175,11 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
return (T)rr;
}
sealed class FindNodeVisitor : AbstractDomVisitor<object, object>
sealed class FindNodeVisitor : DomVisitor<object, object>
{
readonly DomLocation start;
readonly DomLocation end;
public INode ResultNode;
public DomNode ResultNode;
public FindNodeVisitor(DomLocation start, DomLocation end)
{
@ -187,7 +187,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -187,7 +187,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
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 (ResultNode != null)

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

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

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

@ -24,11 +24,36 @@ @@ -24,11 +24,36 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
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;
public override DomLocation StartLocation {
get {
@ -49,7 +74,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -49,7 +74,7 @@ namespace ICSharpCode.NRefactory.CSharp
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);
}

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

@ -24,16 +24,74 @@ @@ -24,16 +24,74 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class CompilationUnit : AbstractNode
public class CompilationUnit : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
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);
}

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

@ -27,15 +27,22 @@ using System; @@ -27,15 +27,22 @@ using System;
using System.Collections.Generic;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp
{
public class ComposedType : AbstractNode
public class ComposedType : DomNode
{
public const int NullableRole = 100;
public const int PointerRole = 101;
public const int ArraySpecRole = 102;
public INode BaseType {
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public DomNode BaseType {
get {
return GetChildByRole (Roles.ReturnType);
}
@ -45,13 +52,18 @@ namespace ICSharpCode.NRefactory.CSharp @@ -45,13 +52,18 @@ namespace ICSharpCode.NRefactory.CSharp
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);
}
public class ArraySpecifier : AbstractNode
public class ArraySpecifier : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public CSharpTokenNode LBracket {
get { return (CSharpTokenNode)GetChildByRole (Roles.LBracket); }
@ -62,7 +74,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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);
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
//
// AbstractNode.cs
//
// AstNode.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
@ -29,56 +29,42 @@ using System.Collections.Generic; @@ -29,56 +29,42 @@ using System.Collections.Generic;
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 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 override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public const int Assign = 63; // =
public override bool IsNull {
get {
return true;
}
}
public const int TypeArgument = 64;
public const int Constraint = 65;
public override S AcceptVisitor<T, S> (DomVisitor<T, S> visitor, T data)
{
return default (S);
}
}
public abstract NodeType NodeType {
get;
}
public virtual bool IsNull {
get {
return false;
}
}
public virtual DomLocation StartLocation {
get {
INode child = (INode)FirstChild;
var child = FirstChild;
if (child == null)
return DomLocation.Empty;
return child.StartLocation;
@ -87,14 +73,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -87,14 +73,14 @@ namespace ICSharpCode.NRefactory.CSharp
public virtual DomLocation EndLocation {
get {
INode child = (INode)LastChild;
var child = LastChild;
if (child == null)
return DomLocation.Empty;
return child.EndLocation;
}
}
public INode Parent {
public DomNode Parent {
get;
set;
}
@ -104,29 +90,29 @@ namespace ICSharpCode.NRefactory.CSharp @@ -104,29 +90,29 @@ namespace ICSharpCode.NRefactory.CSharp
set;
}
public INode NextSibling {
public DomNode NextSibling {
get;
set;
}
public INode PrevSibling {
public DomNode PrevSibling {
get;
set;
}
public INode FirstChild {
public DomNode FirstChild {
get;
set;
}
public INode LastChild {
public DomNode LastChild {
get;
set;
}
public IEnumerable<INode> Children {
public IEnumerable<DomNode> Children {
get {
INode cur = FirstChild;
var cur = FirstChild;
while (cur != null) {
yield return cur;
cur = cur.NextSibling;
@ -134,29 +120,31 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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) {
if (cur.Role == role)
return cur;
cur = (AbstractNode)cur.NextSibling;
cur = cur.NextSibling;
}
return null;
}
public IEnumerable<INode> GetChildrenByRole (int role)
public IEnumerable<DomNode> GetChildrenByRole (int role)
{
AbstractNode cur = (AbstractNode)FirstChild;
var cur = FirstChild;
while (cur != null) {
if (cur.Role == role)
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;
if (FirstChild == null) {
LastChild = FirstChild = child;
@ -167,15 +155,20 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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;
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);
return;
}
@ -187,16 +180,55 @@ namespace ICSharpCode.NRefactory.CSharp @@ -187,16 +180,55 @@ namespace ICSharpCode.NRefactory.CSharp
if (nextSibling.PrevSibling != null) {
child.PrevSibling = nextSibling.PrevSibling;
nextSibling.PrevSibling.NextSibling = child;
} else if (this.FirstChild == nextSibling) {
this.FirstChild = 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 @@ @@ -1,5 +1,5 @@
//
// IDomVisitor.cs
//
// DomVisitor.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
@ -28,11 +28,11 @@ using System; @@ -28,11 +28,11 @@ using System;
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) {
child.AcceptVisitor (this, data);
child = child.NextSibling;
@ -55,6 +55,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -55,6 +55,11 @@ namespace ICSharpCode.NRefactory.CSharp
return default (S);
}
public virtual S VisitComposedType (ComposedType composedType, T data)
{
return default (S);
}
public virtual S VisitAttribute (Attribute attribute, T data)
{
return VisitChildren (attribute, data);
@ -77,7 +82,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -77,7 +82,15 @@ namespace ICSharpCode.NRefactory.CSharp
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)
@ -345,6 +358,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -345,6 +358,11 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (invocationExpression, data);
}
public virtual S VisitDirectionExpression (DirectionExpression directionExpression, T data)
{
return VisitChildren (directionExpression, data);
}
public virtual S VisitMemberReferenceExpression (MemberReferenceExpression memberReferenceExpression, T data)
{
return VisitChildren (memberReferenceExpression, data);
@ -360,7 +378,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -360,7 +378,7 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (objectCreateExpression, data);
}
public virtual S VisitArrayObjectCreateExpression (ArrayObjectCreateExpression arrayObjectCreateExpression, T data)
public virtual S VisitArrayCreateExpression (ArrayCreateExpression arrayObjectCreateExpression, T data)
{
return VisitChildren (arrayObjectCreateExpression, data);
}
@ -470,14 +488,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -470,14 +488,9 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (argListExpression, data);
}
public virtual S VisitComposedType (ComposedType composedType, T data)
public S VisitArrayInitializerExpression (ArrayInitializerExpression arrayInitializerExpression, T data)
{
return VisitChildren (composedType, data);
}
public virtual S VisitDirectionExpression (DirectionExpression directionExpression, T data)
{
return VisitChildren (directionExpression, data);
return VisitChildren (arrayInitializerExpression, data);
}
}
}

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

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

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

@ -24,7 +24,6 @@ @@ -24,7 +24,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using ICSharpCode.NRefactory.TypeSystem;
using System;
using System.Collections.Generic;
using System.Linq;
@ -34,30 +33,36 @@ namespace ICSharpCode.NRefactory.CSharp @@ -34,30 +33,36 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>
/// Represents the undocumented __arglist keyword.
/// </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)
get;
set;
}
public CSharpTokenNode Keyword {
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); }
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword) ?? CSharpTokenNode.Null; }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
}
public IEnumerable<INode> Arguments {
get { return GetChildrenByRole (Roles.Argument).Cast<INode> (); }
public IEnumerable<DomNode> Arguments {
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);
}

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

@ -25,19 +25,25 @@ @@ -25,19 +25,25 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class ArrayObjectCreateExpression : ObjectCreateExpression
public class ArrayCreateExpression : ObjectCreateExpression
{
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
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 @@ @@ -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 @@ @@ -24,21 +24,26 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class AsExpression : AbstractNode
public class AsExpression : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public FullTypeName TypeReference {
get { return (FullTypeName)GetChildByRole (Roles.ReturnType); }
get { return (FullTypeName)GetChildByRole (Roles.ReturnType) ?? FullTypeName.Null; }
}
public INode Expression {
get { return GetChildByRole (Roles.Expression); }
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.VisitAsExpression (this, data);
}

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// AssignmentExpression.cs
//
// Author:
@ -25,12 +25,17 @@ @@ -25,12 +25,17 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
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 RightExpressionRole = 101;
public const int OperatorRole = 102;
@ -40,20 +45,20 @@ namespace ICSharpCode.NRefactory.CSharp @@ -40,20 +45,20 @@ namespace ICSharpCode.NRefactory.CSharp
set;
}
public INode Left {
get { return GetChildByRole (LeftExpressionRole); }
public DomNode Left {
get { return GetChildByRole (LeftExpressionRole) ?? DomNode.Null; }
}
public INode Right {
get { return GetChildByRole (RightExpressionRole); }
public DomNode Right {
get { return GetChildByRole (RightExpressionRole) ?? DomNode.Null; }
}
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);
}
@ -75,12 +80,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -75,12 +80,12 @@ namespace ICSharpCode.NRefactory.CSharp
/// <summary>left %= right</summary>
Modulus,
/// <summary>left &lt;&lt;= right</summary>
/// <summary>left <<= right</summary>
ShiftLeft,
/// <summary>left >>= right</summary>
ShiftRight,
/// <summary>left &amp;= right</summary>
/// <summary>left &= right</summary>
BitwiseAnd,
/// <summary>left |= right</summary>
BitwiseOr,

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

@ -25,12 +25,17 @@ @@ -25,12 +25,17 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class BaseReferenceExpression : AbstractNode
public class BaseReferenceExpression : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public DomLocation Location {
get;
set;
@ -47,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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);
}

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

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

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

@ -25,29 +25,34 @@ @@ -25,29 +25,34 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class CastExpression : AbstractNode
public class CastExpression : DomNode
{
public INode CastTo {
get { return (INode)GetChildByRole (Roles.ReturnType); }
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public DomNode CastTo {
get { return GetChildByRole (Roles.ReturnType) ?? DomNode.Null; }
}
public INode Expression {
get { return GetChildByRole (Roles.Expression); }
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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);
}

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

@ -25,25 +25,30 @@ @@ -25,25 +25,30 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class CheckedExpression : AbstractNode
public class CheckedExpression : DomNode
{
public INode Expression {
get { return GetChildByRole (Roles.Expression); }
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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);
}

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

@ -25,39 +25,44 @@ @@ -25,39 +25,44 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// cond ? true : false
/// </summary>
public class ConditionalExpression : AbstractNode
public class ConditionalExpression : DomNode
{
public const int TrueExpressionRole = 100;
public const int FalseExpressionRole = 101;
public INode TrueExpression {
get { return GetChildByRole (TrueExpressionRole); }
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public DomNode TrueExpression {
get { return GetChildByRole (TrueExpressionRole) ?? DomNode.Null; }
}
public INode FalseExpression {
get { return GetChildByRole (FalseExpressionRole); }
public DomNode FalseExpression {
get { return GetChildByRole (FalseExpressionRole) ?? DomNode.Null; }
}
public INode Condition {
get { return GetChildByRole (Roles.Condition); }
public DomNode Condition {
get { return GetChildByRole (Roles.Condition) ?? DomNode.Null; }
}
public CSharpTokenNode QuestionMark {
get { return (CSharpTokenNode)GetChildByRole (Roles.QuestionMark); }
get { return (CSharpTokenNode)GetChildByRole (Roles.QuestionMark) ?? CSharpTokenNode.Null; }
}
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);
}

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

@ -27,13 +27,19 @@ using System; @@ -27,13 +27,19 @@ using System;
namespace ICSharpCode.NRefactory.CSharp
{
public class DefaultValueExpression : AbstractNode
public class DefaultValueExpression : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
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);
}

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

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

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// IdentifierExpression.cs
//
// Author:
@ -25,26 +25,31 @@ @@ -25,26 +25,31 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
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 {
return (Identifier)GetChildByRole (Roles.Identifier);
return (Identifier)GetChildByRole (Roles.Identifier) ?? ICSharpCode.NRefactory.CSharp.Identifier.Null;
}
}
public string Identifier {
get {
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);
}

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

@ -26,34 +26,39 @@ @@ -26,34 +26,39 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class IndexerExpression : AbstractNode
public class IndexerExpression : DomNode
{
public INode Target {
get { return (INode)GetChildByRole (Roles.TargetExpression); }
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public DomNode Target {
get { return GetChildByRole (Roles.TargetExpression); }
}
public CSharpTokenNode LBracket {
get {
return (CSharpTokenNode)GetChildByRole (Roles.LBracket);
return (CSharpTokenNode)GetChildByRole (Roles.LBracket) ?? CSharpTokenNode.Null;
}
}
public CSharpTokenNode RBracket {
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); }
}
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);
}

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

@ -26,30 +26,36 @@ @@ -26,30 +26,36 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class InvocationExpression : AbstractNode
public class InvocationExpression : DomNode
{
public INode Target {
get { return GetChildByRole (Roles.TargetExpression); }
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public DomNode Target {
get { return GetChildByRole (Roles.TargetExpression) ?? DomNode.Null; }
}
public IEnumerable<INode> Arguments {
get { return GetChildrenByRole (Roles.Argument).Cast<INode> (); }
public IEnumerable<DomNode> Arguments {
get { return GetChildrenByRole (Roles.Argument); }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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);
}

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

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

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// LambdaExpression.cs
//
// Author:
@ -29,9 +29,15 @@ using System.Collections.Generic; @@ -29,9 +29,15 @@ using System.Collections.Generic;
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 {
return base.GetChildrenByRole (Roles.Argument).Cast <ParameterDeclaration>();
}
@ -39,23 +45,23 @@ namespace ICSharpCode.NRefactory.CSharp @@ -39,23 +45,23 @@ namespace ICSharpCode.NRefactory.CSharp
public BlockStatement Body {
get {
return (BlockStatement)GetChildByRole (Roles.Body);
return (BlockStatement)GetChildByRole (Roles.Body) ?? BlockStatement.Null;
}
}
public CSharpTokenNode Arrow {
get { return (CSharpTokenNode)GetChildByRole (Roles.Assign); }
get { return (CSharpTokenNode)GetChildByRole (Roles.Assign) ?? CSharpTokenNode.Null; }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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);
}

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

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

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

@ -25,13 +25,18 @@ @@ -25,13 +25,18 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
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);
}

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

@ -25,30 +25,35 @@ @@ -25,30 +25,35 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class ObjectCreateExpression : AbstractNode
public class ObjectCreateExpression : DomNode
{
public INode Type {
get { return (INode)GetChildByRole (Roles.ReturnType); }
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public DomNode Type {
get { return GetChildByRole (Roles.ReturnType) ?? DomNode.Null; }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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); }
}
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);
}

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

@ -25,25 +25,30 @@ @@ -25,25 +25,30 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class ParenthesizedExpression : AbstractNode
public class ParenthesizedExpression : DomNode
{
public INode Expression {
get { return GetChildByRole (Roles.Expression); }
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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);
}

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

@ -26,7 +26,6 @@ @@ -26,7 +26,6 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
@ -36,8 +35,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -36,8 +35,14 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class PointerReferenceExpression : MemberReferenceExpression
{
public INode Expression {
get { return GetChildByRole (Roles.TargetExpression); }
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.TargetExpression) ?? DomNode.Null; }
}
public string Dim {
@ -45,7 +50,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -45,7 +50,7 @@ namespace ICSharpCode.NRefactory.CSharp
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);
}

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

@ -25,12 +25,17 @@ @@ -25,12 +25,17 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class PrimitiveExpression : AbstractNode
public class PrimitiveExpression : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
DomLocation startLocation;
public override DomLocation StartLocation {
get {
@ -58,7 +63,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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);
}

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

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

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

@ -24,27 +24,32 @@ @@ -24,27 +24,32 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class SizeOfExpression : AbstractNode
public class SizeOfExpression : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public FullTypeName Type {
get {
return (FullTypeName)GetChildByRole (Roles.ReturnType);
return (FullTypeName)GetChildByRole (Roles.ReturnType) ?? FullTypeName.Null;
}
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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);
}

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

@ -25,43 +25,48 @@ @@ -25,43 +25,48 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class StackAllocExpression : AbstractNode
public class StackAllocExpression : DomNode
{
public const int StackAllocKeywordRole = 100;
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public FullTypeName Type {
get {
return (FullTypeName)GetChildByRole (Roles.ReturnType);
return (FullTypeName)GetChildByRole (Roles.ReturnType) ?? FullTypeName.Null;
}
}
public INode CountExpression {
get { return (INode)GetChildByRole (Roles.Expression); }
public DomNode CountExpression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
}
public CSharpTokenNode StackAllocKeyword {
get {
return (CSharpTokenNode)GetChildByRole (StackAllocKeywordRole);
return (CSharpTokenNode)GetChildByRole (StackAllocKeywordRole) ?? CSharpTokenNode.Null;
}
}
public CSharpTokenNode LBracket {
get {
return (CSharpTokenNode)GetChildByRole (Roles.LBracket);
return (CSharpTokenNode)GetChildByRole (Roles.LBracket) ?? CSharpTokenNode.Null;
}
}
public CSharpTokenNode RBracket {
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);
}

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

@ -25,17 +25,22 @@ @@ -25,17 +25,22 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class ThisReferenceExpression : AbstractNode
public class ThisReferenceExpression : DomNode
{
public DomLocation Location {
get;
set;
}
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public override DomLocation StartLocation {
get {
return Location;
@ -48,7 +53,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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);
}

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

@ -25,27 +25,32 @@ @@ -25,27 +25,32 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class TypeOfExpression : AbstractNode
public class TypeOfExpression : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public FullTypeName Type {
get {
return (FullTypeName)GetChildByRole (Roles.ReturnType);
return (FullTypeName)GetChildByRole (Roles.ReturnType) ?? FullTypeName.Null;
}
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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);
}

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

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

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

@ -25,24 +25,30 @@ @@ -25,24 +25,30 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class UncheckedExpression : AbstractNode
public class UncheckedExpression : DomNode
{
public INode Expression {
get { return GetChildByRole (Roles.Expression); }
public override NodeType NodeType {
get {
return NodeType.Expression;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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);
}

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

@ -24,25 +24,45 @@ @@ -24,25 +24,45 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
using System.Linq;
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 {
get {
return (Identifier)GetChildByRole (Roles.Identifier);
}
}
public IEnumerable<INode> TypeArguments {
get { return GetChildrenByRole (Roles.TypeArgument).Cast<INode> (); }
public IEnumerable<DomNode> TypeArguments {
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);
}

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

@ -26,13 +26,18 @@ @@ -26,13 +26,18 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class Attribute : AbstractNode
public class Attribute : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string Name {
get {
return NameIdentifier.QualifiedName;
@ -46,13 +51,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -46,13 +51,13 @@ namespace ICSharpCode.NRefactory.CSharp
}
// 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 {
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);
}

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// AttributeSection.cs
//
// Author:
@ -26,29 +26,34 @@ @@ -26,29 +26,34 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class AttributeSection : AbstractNode
public class AttributeSection : DomNode
{
const int TargetRole = 101;
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public AttributeTarget AttributeTarget {
get;
set;
}
public Identifier TargetIdentifier {
get { return (Identifier)GetChildByRole (TargetRole); }
get { return (Identifier)GetChildByRole (TargetRole) ?? Identifier.Null; }
}
public IEnumerable<Attribute> Attributes {
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);
}

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

@ -26,30 +26,36 @@ @@ -26,30 +26,36 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class Constraint : AbstractNode
public class Constraint : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public CSharpTokenNode WhereKeyword {
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword); }
get { return (CSharpTokenNode)GetChildByRole (Roles.Keyword) ?? CSharpTokenNode.Null; }
}
public Identifier TypeParameter {
get { return (Identifier)GetChildByRole (Roles.Identifier); }
get { return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null; }
}
public CSharpTokenNode Colon {
get { return (CSharpTokenNode)GetChildByRole (Roles.Colon); }
get { return (CSharpTokenNode)GetChildByRole (Roles.Colon) ?? CSharpTokenNode.Null; }
}
public IEnumerable<INode> TypeArguments {
get { return GetChildrenByRole (Roles.TypeArgument).Cast<INode> (); }
public IEnumerable<DomNode> TypeParameters {
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);
}

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// DelegateDeclaration.cs
//
// Author:
@ -26,13 +26,18 @@ @@ -26,13 +26,18 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class DelegateDeclaration : AbstractMemberBase
{
public override NodeType NodeType {
get {
return NodeType.Type;
}
}
public string Name {
get {
return NameIdentifier.Name;
@ -41,28 +46,37 @@ namespace ICSharpCode.NRefactory.CSharp @@ -41,28 +46,37 @@ namespace ICSharpCode.NRefactory.CSharp
public Identifier NameIdentifier {
get {
return (Identifier)GetChildByRole (Roles.Identifier);
return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null;
}
}
public INode ReturnType {
public DomNode ReturnType {
get {
return (INode)GetChildByRole (Roles.ReturnType);
return GetChildByRole (Roles.ReturnType) ?? DomNode.Null;
}
}
// TODO: call this Parameters or Arguments?
public IEnumerable<ParameterDeclaration> Parameters {
get { return this.Arguments; }
public IEnumerable<ParameterDeclaration> Parameters {
get {
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 {
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);
}

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// EnumDeclaration.cs
//
// Author:
@ -26,13 +26,53 @@ @@ -26,13 +26,53 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
using ICSharpCode.NRefactory.TypeSystem;
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 {
get {
return NameIdentifier.Name;
@ -41,17 +81,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -41,17 +81,17 @@ namespace ICSharpCode.NRefactory.CSharp
public Identifier NameIdentifier {
get {
return (Identifier)GetChildByRole (Roles.Identifier);
return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null;
}
}
public INode Initializer {
public DomNode Initializer {
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);
}

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// NamespaceDeclaration.cs
//
// Author:
@ -26,12 +26,17 @@ @@ -26,12 +26,17 @@
using System;
using System.Collections.Generic;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class NamespaceDeclaration : AbstractNode
public class NamespaceDeclaration : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string Name {
get {
return NameIdentifier.QualifiedName;
@ -47,13 +52,25 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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 {
get {
return (QualifiedIdentifier)GetChildByRole (Roles.Identifier);
}
}
public IEnumerable<INode> Members {
public IEnumerable<DomNode> Members {
get { return GetChildrenByRole(Roles.Member); }
}
@ -66,7 +83,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -66,7 +83,7 @@ namespace ICSharpCode.NRefactory.CSharp
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);
}

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

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

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// UsingAliasDeclaration.cs
//
// Author:
@ -30,22 +30,27 @@ namespace ICSharpCode.NRefactory.CSharp @@ -30,22 +30,27 @@ namespace ICSharpCode.NRefactory.CSharp
{
public class UsingAliasDeclaration : UsingDeclaration
{
public const int Assignment = 103;
public const int AliasRole = 104;
public const int AliasRole = 100;
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string Alias {
get {
return AliasIdentifier.Name;
return AliasIdentifier.QualifiedName;
}
}
public Identifier AliasIdentifier {
public QualifiedIdentifier AliasIdentifier {
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);
}

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

@ -25,12 +25,17 @@ @@ -25,12 +25,17 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class UsingDeclaration : AbstractNode
public class UsingDeclaration : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string Namespace {
get {
return NameIdentifier.QualifiedName;
@ -43,7 +48,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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);
}

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

@ -1,140 +0,0 @@ @@ -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 @@ @@ -25,12 +25,32 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
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 {
get;
set;
@ -65,7 +85,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -65,7 +85,7 @@ namespace ICSharpCode.NRefactory.CSharp
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);
}

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

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

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// QualifiedIdentifier.cs
//
// Author:
@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
// THE SOFTWARE.
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ICSharpCode.NRefactory.CSharp
{
public class QualifiedIdentifier : AbstractNode
public class QualifiedIdentifier : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string QualifiedName {
get {
StringBuilder builder = new StringBuilder ();
int i = 0;
foreach (Identifier identifier in GetChildrenByRole (Roles.Identifier)) {
if (i > 0) {
if (i == 1 && HasDoubleColon)
builder.Append ("::");
else
builder.Append ('.');
}
if (builder.Length > 0)
builder.Append ('.');
builder.Append (identifier.Name);
i++;
}
return builder.ToString ();
}
@ -64,5 +64,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -64,5 +64,10 @@ namespace ICSharpCode.NRefactory.CSharp
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 @@ @@ -25,32 +25,53 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
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 {
get {
return (CSharpTokenNode)GetChildByRole (Roles.LBrace);
return (CSharpTokenNode)GetChildByRole (Roles.LBrace) ?? CSharpTokenNode.Null;
}
}
public CSharpTokenNode RBrace {
get {
return (CSharpTokenNode)GetChildByRole (Roles.RBrace);
return (CSharpTokenNode)GetChildByRole (Roles.RBrace) ?? CSharpTokenNode.Null;
}
}
public IEnumerable<INode> Statements {
public IEnumerable<DomNode> Statements {
get {
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);
}

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

@ -25,19 +25,24 @@ @@ -25,19 +25,24 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class BreakStatement : AbstractNode
public class BreakStatement : DomNode
{
public INode BreakKeyword {
public override NodeType NodeType {
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);
}

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// CheckedStatement.cs
//
// Author:
@ -25,17 +25,22 @@ @@ -25,17 +25,22 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class CheckedStatement : AbstractNode
public class CheckedStatement : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
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);
}

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

@ -25,17 +25,22 @@ @@ -25,17 +25,22 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class ContinueStatement : AbstractNode
public class ContinueStatement : DomNode
{
public INode ContinueKeyword {
get { return GetChildByRole (Roles.Keyword); }
public override NodeType NodeType {
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);
}

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

@ -25,12 +25,17 @@ @@ -25,12 +25,17 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class EmptyStatement : AbstractNode
public class EmptyStatement : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public DomLocation Location {
get;
set;
@ -41,13 +46,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -41,13 +46,14 @@ namespace ICSharpCode.NRefactory.CSharp
return Location;
}
}
public override DomLocation EndLocation {
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);
}

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// ExpressionStatement.cs
//
// Author:
@ -25,19 +25,24 @@ @@ -25,19 +25,24 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class ExpressionStatement : AbstractNode
public class ExpressionStatement : DomNode
{
public INode Expression {
public override NodeType NodeType {
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);
}

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

@ -25,25 +25,30 @@ @@ -25,25 +25,30 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class FixedStatement : AbstractNode
public class FixedStatement : DomNode
{
public const int PointerDeclarationRole = 100;
public const int FixedKeywordRole = 101;
public const int DeclaratorRole = 102;
public INode EmbeddedStatement {
get { return (INode)GetChildByRole (Roles.EmbeddedStatement); }
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public DomNode EmbeddedStatement {
get { return GetChildByRole (Roles.EmbeddedStatement) ?? DomNode.Null; }
}
public INode PointerDeclaration {
get { return GetChildByRole (PointerDeclarationRole); }
public DomNode PointerDeclaration {
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);
}

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

@ -25,38 +25,43 @@ @@ -25,38 +25,43 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class ForStatement : AbstractNode
public class ForStatement : DomNode
{
public INode EmbeddedStatement {
get { return (INode)GetChildByRole (Roles.EmbeddedStatement); }
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public DomNode EmbeddedStatement {
get { return GetChildByRole (Roles.EmbeddedStatement) ?? DomNode.Null; }
}
public INode Condition {
get { return GetChildByRole (Roles.Condition); }
public DomNode Condition {
get { return GetChildByRole (Roles.Condition) ?? DomNode.Null; }
}
public IEnumerable<INode> Initializers {
public IEnumerable<DomNode> Initializers {
get { return GetChildrenByRole (Roles.Initializer); }
}
public IEnumerable<INode> Iterators {
public IEnumerable<DomNode> Iterators {
get { return GetChildrenByRole (Roles.Iterator); }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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);
}

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

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

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

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

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

@ -25,46 +25,51 @@ @@ -25,46 +25,51 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class IfElseStatement : AbstractNode
public class IfElseStatement : DomNode
{
public const int TrueEmbeddedStatementRole = 100;
public const int FalseEmbeddedStatementRole = 101;
public const int IfKeywordRole = 102;
public const int ElseKeywordRole = 103;
public INode TrueEmbeddedStatement {
get { return (INode)GetChildByRole (TrueEmbeddedStatementRole); }
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public DomNode TrueEmbeddedStatement {
get { return GetChildByRole (TrueEmbeddedStatementRole) ?? DomNode.Null; }
}
public INode FalseEmbeddedStatement {
get { return (INode)GetChildByRole (FalseEmbeddedStatementRole); }
public DomNode FalseEmbeddedStatement {
get { return GetChildByRole (FalseEmbeddedStatementRole) ?? DomNode.Null; }
}
public INode Condition {
get { return (INode)GetChildByRole (Roles.Condition); }
public DomNode Condition {
get { return GetChildByRole (Roles.Condition) ?? DomNode.Null; }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
}
public CSharpTokenNode IfKeyword {
get { return (CSharpTokenNode)GetChildByRole (IfKeywordRole); }
get { return (CSharpTokenNode)GetChildByRole (IfKeywordRole) ?? CSharpTokenNode.Null; }
}
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);
}

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

@ -25,21 +25,26 @@ @@ -25,21 +25,26 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class LabelStatement : AbstractNode
public class LabelStatement : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public string Label {
get { return LabelIdentifier.Name; }
}
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);
}

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

@ -25,29 +25,34 @@ @@ -25,29 +25,34 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class LockStatement : AbstractNode
public class LockStatement : DomNode
{
public INode Expression {
get { return GetChildByRole (Roles.Expression); }
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
}
public INode EmbeddedStatement {
get { return (INode)GetChildByRole (Roles.EmbeddedStatement); }
public DomNode EmbeddedStatement {
get { return GetChildByRole (Roles.EmbeddedStatement) ?? DomNode.Null; }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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);
}

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

@ -25,17 +25,22 @@ @@ -25,17 +25,22 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class ReturnStatement : AbstractNode
public class ReturnStatement : DomNode
{
public INode Expression {
get { return GetChildByRole (Roles.Expression); }
public override NodeType NodeType {
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);
}

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

@ -26,17 +26,22 @@ @@ -26,17 +26,22 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class SwitchStatement : AbstractNode
public class SwitchStatement : DomNode
{
public const int SwitchSectionRole = 100;
public INode Expression {
get { return GetChildByRole (Roles.Expression); }
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public DomNode Expression {
get { return GetChildByRole (Roles.Expression) ?? DomNode.Null; }
}
public IEnumerable<SwitchSection> SwitchSections {
@ -44,54 +49,69 @@ namespace ICSharpCode.NRefactory.CSharp @@ -44,54 +49,69 @@ namespace ICSharpCode.NRefactory.CSharp
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
}
public CSharpTokenNode LBrace {
get { return (CSharpTokenNode)GetChildByRole (Roles.LBrace); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LBrace) ?? CSharpTokenNode.Null; }
}
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);
}
}
public class SwitchSection : AbstractNode
public class SwitchSection : DomNode
{
public const int CaseLabelRole = 100;
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public IEnumerable<CaseLabel> CaseLabels {
get { return GetChildrenByRole (CaseLabelRole).Cast<CaseLabel> (); }
}
public IEnumerable<INode> Statements {
public IEnumerable<DomNode> Statements {
get {
BlockStatement block = (BlockStatement)GetChildByRole (Roles.Body);
return block.Statements;
var body = GetChildByRole (Roles.Body);
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);
}
}
public class CaseLabel : AbstractNode
public class CaseLabel : DomNode
{
public INode Expression {
get { return GetChildByRole (Roles.Expression); }
public override NodeType NodeType {
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);
}

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

@ -25,17 +25,22 @@ @@ -25,17 +25,22 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class ThrowStatement : AbstractNode
public class ThrowStatement : DomNode
{
public INode Expression {
get { return GetChildByRole (Roles.Expression); }
public override NodeType NodeType {
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);
}

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

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

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// UncheckedStatement.cs
//
// Author:
@ -25,17 +25,23 @@ @@ -25,17 +25,23 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class UncheckedStatement : AbstractNode
public class UncheckedStatement : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
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);
}

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

@ -25,17 +25,22 @@ @@ -25,17 +25,22 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class UnsafeStatement : AbstractNode
public class UnsafeStatement : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
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);
}

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

@ -25,30 +25,35 @@ @@ -25,30 +25,35 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class UsingStatement : AbstractNode
public class UsingStatement : DomNode
{
public INode Statement {
get { return GetChildByRole (Roles.Statement); }
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public DomNode Statement {
get { return GetChildByRole (Roles.Statement) ?? DomNode.Null; }
}
public INode EmbeddedStatement {
get { return (INode)GetChildByRole (Roles.EmbeddedStatement); }
public DomNode EmbeddedStatement {
get { return GetChildByRole (Roles.EmbeddedStatement) ?? DomNode.Null; }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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);
}

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

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
//
//
// VariableDeclarationStatement.cs
//
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
@ -26,15 +26,22 @@ @@ -26,15 +26,22 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
{
public class VariableDeclarationStatement : AbstractNode
public class VariableDeclarationStatement : DomNode
{
public IEnumerable<INode> ModifierTokens {
get { return base.GetChildrenByRole (Roles.Modifier); }
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public IEnumerable<CSharpModifierToken> ModifierTokens {
get {
return base.GetChildrenByRole (Roles.Modifier).Cast <CSharpModifierToken>();
}
}
public Modifiers Modifiers {
@ -47,15 +54,19 @@ namespace ICSharpCode.NRefactory.CSharp @@ -47,15 +54,19 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public INode ReturnType {
get { return (INode)GetChildByRole (Roles.ReturnType); }
public DomNode ReturnType {
get { return GetChildByRole (Roles.ReturnType) ?? DomNode.Null; }
}
public IEnumerable<VariableInitializer> Variables {
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);
}

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

@ -25,45 +25,50 @@ @@ -25,45 +25,50 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class WhileStatement : AbstractNode
public class WhileStatement : DomNode
{
public const int DoKeywordRole = 101;
public const int WhileKeywordRole = 102;
public override NodeType NodeType {
get {
return NodeType.Statement;
}
}
public WhilePosition WhilePosition {
get;
set;
}
public INode EmbeddedStatement {
get { return (INode)GetChildByRole (Roles.EmbeddedStatement); }
public DomNode EmbeddedStatement {
get { return GetChildByRole (Roles.EmbeddedStatement) ?? DomNode.Null; }
}
public INode Condition {
get { return GetChildByRole (Roles.Condition); }
public DomNode Condition {
get { return GetChildByRole (Roles.Condition) ?? DomNode.Null; }
}
public CSharpTokenNode DoKeyword {
get { return (CSharpTokenNode)GetChildByRole (DoKeywordRole); }
get { return (CSharpTokenNode)GetChildByRole (DoKeywordRole) ?? CSharpTokenNode.Null; }
}
public CSharpTokenNode WhileKeyword {
get { return (CSharpTokenNode)GetChildByRole (WhileKeywordRole); }
get { return (CSharpTokenNode)GetChildByRole (WhileKeywordRole) ?? CSharpTokenNode.Null; }
}
public CSharpTokenNode LPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
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);
}

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// YieldStatement.cs
//
// Author:
@ -25,21 +25,26 @@ @@ -25,21 +25,26 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class YieldStatement : AbstractNode
public class YieldStatement : DomNode
{
public const int YieldKeywordRole = 100;
public const int ReturnKeywordRole = 101;
public const int BreakKeywordRole = 102;
public INode Expression {
get { return GetChildByRole (Roles.Expression); }
public override NodeType NodeType {
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);
}

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

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

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// AbstractMemberBase.cs
//
// Author:
@ -26,14 +26,19 @@ @@ -26,14 +26,19 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
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 {
return base.GetChildrenByRole (Roles.Modifier).Cast <CSharpModifierToken>();
}

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

@ -0,0 +1,64 @@ @@ -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 @@ @@ -1,4 +1,4 @@
//
//
// ConstructorDeclaration.cs
//
// Author:
@ -26,7 +26,6 @@ @@ -26,7 +26,6 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
@ -35,26 +34,34 @@ namespace ICSharpCode.NRefactory.CSharp @@ -35,26 +34,34 @@ namespace ICSharpCode.NRefactory.CSharp
{
public BlockStatement Body {
get {
return (BlockStatement)GetChildByRole (Roles.Body);
return (BlockStatement)GetChildByRole (Roles.Body) ?? BlockStatement.Null;
}
}
public ConstructorInitializer Initializer {
public IEnumerable<ParameterDeclaration> Parameters {
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)
{
return visitor.VisitConstructorDeclaration (this, data);
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> Parameters {
public ConstructorInitializer Initializer {
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 {
@ -62,20 +69,47 @@ namespace ICSharpCode.NRefactory.CSharp @@ -62,20 +69,47 @@ namespace ICSharpCode.NRefactory.CSharp
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 {
get;
set;
}
public IEnumerable<INode> Arguments {
public IEnumerable<DomNode> Arguments {
get {
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);
}

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

@ -26,7 +26,6 @@ @@ -26,7 +26,6 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
@ -37,11 +36,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -37,11 +36,11 @@ namespace ICSharpCode.NRefactory.CSharp
public BlockStatement Body {
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);
}

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

@ -25,7 +25,6 @@ @@ -25,7 +25,6 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
@ -36,29 +35,29 @@ namespace ICSharpCode.NRefactory.CSharp @@ -36,29 +35,29 @@ namespace ICSharpCode.NRefactory.CSharp
public CSharpTokenNode LBrace {
get {
return (CSharpTokenNode)GetChildByRole (Roles.LBrace);
return (CSharpTokenNode)GetChildByRole (Roles.LBrace) ?? CSharpTokenNode.Null;
}
}
public CSharpTokenNode RBrace {
get {
return (CSharpTokenNode)GetChildByRole (Roles.RBrace);
return (CSharpTokenNode)GetChildByRole (Roles.RBrace) ?? CSharpTokenNode.Null;
}
}
public Accessor AddAccessor {
get {
return (Accessor)GetChildByRole (EventAddRole);
return (Accessor)GetChildByRole (EventAddRole) ?? Accessor.Null;
}
}
public Accessor RemoveAccessor {
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);
}

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

@ -26,7 +26,6 @@ @@ -26,7 +26,6 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp
@ -34,7 +33,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -34,7 +33,7 @@ namespace ICSharpCode.NRefactory.CSharp
public class FieldDeclaration : AbstractMember
{
public CSharpTokenNode Semicolon {
get { return (CSharpTokenNode)GetChildByRole (Roles.Semicolon); }
get { return (CSharpTokenNode)GetChildByRole (Roles.Semicolon) ?? CSharpTokenNode.Null; }
}
public IEnumerable<VariableInitializer> Variables {
@ -43,7 +42,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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);
}

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

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

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// MethodDeclaration.cs
//
// Author:
@ -32,13 +32,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -32,13 +32,8 @@ namespace ICSharpCode.NRefactory.CSharp
{
public class MethodDeclaration : AbstractMember
{
// TODO: Parameters or Arguments?
public IEnumerable<INode> TypeParameters {
get { return this.TypeArguments; }
}
public IEnumerable<INode> TypeArguments {
get { return GetChildrenByRole (Roles.TypeArgument).Cast<INode> (); }
public IEnumerable<DomNode> TypeParameters {
get { return GetChildrenByRole (Roles.TypeArgument); }
}
public IEnumerable<Constraint> Constraints {
@ -48,41 +43,34 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,41 +43,34 @@ namespace ICSharpCode.NRefactory.CSharp
}
public IEnumerable<ParameterDeclaration> Parameters {
get {
return this.Arguments;
}
}
public IEnumerable<ParameterDeclaration> Arguments {
get {
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 {
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.LPar) ?? CSharpTokenNode.Null; }
}
public CSharpTokenNode RPar {
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar); }
get { return (CSharpTokenNode)GetChildByRole (Roles.RPar) ?? CSharpTokenNode.Null; }
}
public BlockStatement Body {
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);
}

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// OperatorDeclaration.cs
//
// Author:
@ -29,8 +29,6 @@ using System; @@ -29,8 +29,6 @@ using System;
namespace ICSharpCode.NRefactory.CSharp
{
public enum OperatorType {
// Numeric values must match those in Mono.CSharp.Operator.OpType !!
// Unary operators
LogicalNot,
OnesComplement,
@ -77,6 +75,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -77,6 +75,11 @@ namespace ICSharpCode.NRefactory.CSharp
set;
}
public string OverloadOperator {
get;
set;
}
public CSharpTokenNode OperatorKeyword {
get { return (CSharpTokenNode)GetChildByRole (OperatorKeywordRole); }
}
@ -85,14 +88,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -85,14 +88,14 @@ namespace ICSharpCode.NRefactory.CSharp
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 @@ -38,8 +38,14 @@ namespace ICSharpCode.NRefactory.CSharp
This
}
public class ParameterDeclaration : AbstractNode
public class ParameterDeclaration : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public ParameterModifier ParameterModifier {
get;
set;
@ -47,7 +53,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -47,7 +53,7 @@ namespace ICSharpCode.NRefactory.CSharp
public Identifier Identifier {
get {
return (Identifier)GetChildByRole (Roles.Identifier);
return (Identifier)GetChildByRole (Roles.Identifier) ?? Identifier.Null;
}
}
@ -58,14 +64,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -58,14 +64,14 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public INode DefaultExpression {
public DomNode DefaultExpression {
get {
return (INode)GetChildByRole (Roles.Expression);
return GetChildByRole (Roles.Expression) ?? DomNode.Null;
}
}
public INode Type {
get { return GetChildByRole (Roles.ReturnType); }
public DomNode Type {
get { return GetChildByRole (Roles.ReturnType) ?? DomNode.Null; }
}
public IEnumerable<AttributeSection> Attributes {
@ -74,7 +80,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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);
}

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// PropertyDeclaration.cs
//
// Author:
@ -25,30 +25,9 @@ @@ -25,30 +25,9 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
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 const int PropertyGetRole = 100;
@ -56,29 +35,29 @@ namespace ICSharpCode.NRefactory.CSharp @@ -56,29 +35,29 @@ namespace ICSharpCode.NRefactory.CSharp
public CSharpTokenNode LBrace {
get {
return (CSharpTokenNode)GetChildByRole (Roles.LBrace);
return (CSharpTokenNode)GetChildByRole (Roles.LBrace) ?? CSharpTokenNode.Null;
}
}
public CSharpTokenNode RBrace {
get {
return (CSharpTokenNode)GetChildByRole (Roles.RBrace);
return (CSharpTokenNode)GetChildByRole (Roles.RBrace) ?? CSharpTokenNode.Null;
}
}
public Accessor GetAccessor {
get {
return (Accessor)GetChildByRole (PropertyGetRole);
return (Accessor)GetChildByRole (PropertyGetRole) ?? Accessor.Null;
}
}
public Accessor SetAccessor {
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);
}

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

@ -25,12 +25,17 @@ @@ -25,12 +25,17 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
public class VariableInitializer : AbstractNode
public class VariableInitializer : DomNode
{
public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}
public string Name {
get {
return NameIdentifier.Name;
@ -39,17 +44,22 @@ namespace ICSharpCode.NRefactory.CSharp @@ -39,17 +44,22 @@ namespace ICSharpCode.NRefactory.CSharp
public Identifier NameIdentifier {
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 {
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);
}

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

@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
// THE SOFTWARE.
/*
using System;
using MonoDevelop.CSharp.Dom;
using ICSharpCode.NRefactory.CSharp;
using System.Text;
using MonoDevelop.Projects.Dom;
using Mono.TextEditor;
@ -70,7 +70,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -70,7 +70,7 @@ namespace ICSharpCode.NRefactory.CSharp
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);
if (AutoAcceptChanges)

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

@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
// THE SOFTWARE.
/*
using System;
using MonoDevelop.CSharp.Dom;
using ICSharpCode.NRefactory.CSharp;
using System.Text;
using MonoDevelop.Projects.Dom;
using Mono.TextEditor;
@ -72,7 +72,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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);
if (AutoAcceptChanges)
@ -436,7 +436,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -436,7 +436,7 @@ namespace ICSharpCode.NRefactory.CSharp
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);

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

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

@ -443,18 +443,22 @@ namespace Mono.CompilerServices.SymbolWriter @@ -443,18 +443,22 @@ namespace Mono.CompilerServices.SymbolWriter
}
#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";
return new MonoSymbolFile (name, assembly);
return new MonoSymbolFile (name, module);
}
#else
protected MonoSymbolFile (string filename, Assembly assembly) : this (filename)

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

@ -80,8 +80,21 @@ namespace Mono.CSharp { @@ -80,8 +80,21 @@ namespace Mono.CSharp {
{
if (tparams != null) {
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) {
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 { @@ -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;
}
@ -1588,6 +1607,9 @@ namespace Mono.CSharp { @@ -1588,6 +1607,9 @@ namespace Mono.CSharp {
ec.Emit (OpCodes.Ldftn, TypeBuilder.GetMethod (t.GetMetaInfo (), (MethodInfo) delegate_method.GetMetaInfo ()));
} else {
if (delegate_method.IsGeneric)
delegate_method = delegate_method.MakeGenericMethod (method.TypeParameters);
ec.Emit (OpCodes.Ldftn, delegate_method);
}

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

@ -10,7 +10,6 @@ @@ -10,7 +10,6 @@
//
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Collections.Generic;
@ -48,8 +47,14 @@ namespace Mono.CSharp @@ -48,8 +47,14 @@ namespace Mono.CSharp
this.Expr = expr;
}
public TypeSpec Type {
get { return Expr.Type; }
#region Properties
public bool IsByRef {
get { return ArgType == AType.Ref || ArgType == AType.Out; }
}
public bool IsDefaultArgument {
get { return ArgType == AType.Default; }
}
public Parameter.Modifier Modifier {
@ -67,6 +72,24 @@ namespace Mono.CSharp @@ -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)
{
if (ArgType == AType.Default)
@ -83,14 +106,6 @@ namespace Mono.CSharp @@ -83,14 +106,6 @@ namespace Mono.CSharp
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)
{
SimpleName sn = Expr as SimpleName;
@ -139,13 +154,6 @@ namespace Mono.CSharp @@ -139,13 +154,6 @@ namespace Mono.CSharp
IMemoryLocation ml = (IMemoryLocation) Expr;
ml.AddressOf (ec, mode);
}
public Argument Clone (CloneContext clonectx)
{
Argument a = (Argument) MemberwiseClone ();
a.Expr = Expr.Clone (clonectx);
return a;
}
}
public class NamedArgument : Argument
@ -395,7 +403,7 @@ namespace Mono.CSharp @@ -395,7 +403,7 @@ namespace Mono.CSharp
if (!dup_args)
continue;
if (a.Expr is Constant) {
if (a.Expr is Constant || a.Expr is This) {
//
// 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 @@ @@ -12,7 +12,6 @@
// Copyright 2004-2008 Novell, Inc
//
using System;
using System.Reflection;
using System.Reflection.Emit;
namespace Mono.CSharp {
@ -361,7 +360,13 @@ namespace Mono.CSharp { @@ -361,7 +360,13 @@ namespace Mono.CSharp {
if (target_object.NodeType == System.Linq.Expressions.ExpressionType.Block)
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);
}
#endif
@ -449,11 +454,8 @@ namespace Mono.CSharp { @@ -449,11 +454,8 @@ namespace Mono.CSharp {
protected override Expression ResolveConversions (ResolveContext ec)
{
source = Convert.ExplicitConversion (ec, source, target.Type, loc);
if (source != null)
return this;
return base.ResolveConversions (ec);
source = EmptyCast.Create (source, target.Type);
return this;
}
}
@ -673,8 +675,18 @@ namespace Mono.CSharp { @@ -673,8 +675,18 @@ namespace Mono.CSharp {
Arguments args = new Arguments (targs.Count + 1);
args.AddRange (targs);
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) {
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
if (op == Binary.Operator.Addition || op == Binary.Operator.Subtraction) {
@ -693,7 +705,7 @@ namespace Mono.CSharp { @@ -693,7 +705,7 @@ namespace Mono.CSharp {
(ExpressionStatement) source, (ExpressionStatement) invoke, loc).Resolve (ec);
}
} else {
source = new DynamicIndexBinder (CSharpBinderFlags.ValueFromCompoundAssignment, args, loc).Resolve (ec);
source = new DynamicIndexBinder (binder_flags, args, loc).Resolve (ec);
}
return source;

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

@ -80,8 +80,8 @@ namespace Mono.CSharp { @@ -80,8 +80,8 @@ namespace Mono.CSharp {
public AttributeTargets Target;
readonly ATypeNameExpression expression;
Arguments PosArguments;
Arguments NamedArguments;
public Arguments PosArguments;
public Arguments NamedArguments;
bool resolve_error;
bool arg_resolved;
@ -102,7 +102,7 @@ namespace Mono.CSharp { @@ -102,7 +102,7 @@ namespace Mono.CSharp {
static Assembly orig_sec_assembly;
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
static Dictionary<TypeSpec, MethodSpec> att_cache;
@ -142,7 +142,7 @@ namespace Mono.CSharp { @@ -142,7 +142,7 @@ namespace Mono.CSharp {
// we use @target field as a list of targets. The attribute
// 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) {
this.targets = new Attributable[] { target };
@ -340,7 +340,7 @@ namespace Mono.CSharp { @@ -340,7 +340,7 @@ namespace Mono.CSharp {
if (Type != context.Compiler.PredefinedAttributes.DllImport)
return;
if (!RootContext.ToplevelTypes.HasDefaultCharSet)
if (!rc.CurrentMemberDefinition.Module.HasDefaultCharSet)
return;
const string CharSetEnumMember = "CharSet";
@ -355,7 +355,7 @@ namespace Mono.CSharp { @@ -355,7 +355,7 @@ namespace Mono.CSharp {
var char_set = rc.Compiler.MetaImporter.ImportType (typeof (CharSet)); // TODO: typeof
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 {
@ -584,11 +584,11 @@ namespace Mono.CSharp { @@ -584,11 +584,11 @@ namespace Mono.CSharp {
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)
usage_attribute.AllowMultiple = field.Value;
field = GetPropertyValue ("Inherited") as BoolConstant;
field = GetNamedValue ("Inherited") as BoolConstant;
if (field != null)
usage_attribute.Inherited = field.Value;
@ -701,6 +701,7 @@ namespace Mono.CSharp { @@ -701,6 +701,7 @@ namespace Mono.CSharp {
case "field": Target = AttributeTargets.Field; return true;
case "method": Target = AttributeTargets.Method; return true;
case "property": Target = AttributeTargets.Property; return true;
case "module": Target = AttributeTargets.Module; return true;
}
throw new InternalErrorException ("Unknown explicit target: " + ExplicitTarget);
}
@ -857,7 +858,7 @@ namespace Mono.CSharp { @@ -857,7 +858,7 @@ namespace Mono.CSharp {
ps.AddPermission (perm);
}
public Constant GetPropertyValue (string name)
public Constant GetNamedValue (string name)
{
if (named_values == null)
return null;
@ -1110,7 +1111,7 @@ namespace Mono.CSharp { @@ -1110,7 +1111,7 @@ namespace Mono.CSharp {
na.Value.Expr.EncodeAttributeValue (context, encoder, na.Key.Type);
}
} else {
encoder.Stream.Write ((ushort) 0);
encoder.EncodeEmptyNamedArguments ();
}
byte[] cdata = encoder.ToArray ();
@ -1214,21 +1215,6 @@ namespace Mono.CSharp { @@ -1214,21 +1215,6 @@ namespace Mono.CSharp {
{
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 ()
{
@ -1336,8 +1322,16 @@ namespace Mono.CSharp { @@ -1336,8 +1322,16 @@ namespace Mono.CSharp {
}
public Attribute Search (PredefinedAttribute t)
{
return Search (null, t);
}
public Attribute Search (string explicitTarget, PredefinedAttribute t)
{
foreach (Attribute a in Attrs) {
if (explicitTarget != null && a.ExplicitTarget != explicitTarget)
continue;
if (a.ResolveType () == t)
return a;
}
@ -1404,8 +1398,18 @@ namespace Mono.CSharp { @@ -1404,8 +1398,18 @@ namespace Mono.CSharp {
TypeParameter = 1 << 1
}
const ushort Version = 1;
public static readonly byte[] Empty;
public readonly BinaryWriter Stream;
static AttributeEncoder ()
{
Empty = new byte[4];
Array.Copy (BitConverter.GetBytes (Version), Empty, 2);
}
public AttributeEncoder (bool empty)
{
if (empty) {
@ -1414,8 +1418,27 @@ namespace Mono.CSharp { @@ -1414,8 +1418,27 @@ namespace Mono.CSharp {
}
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)
@ -1480,6 +1503,56 @@ namespace Mono.CSharp { @@ -1480,6 +1503,56 @@ namespace Mono.CSharp {
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)
{
if (value < 0x80) {
@ -1558,23 +1631,6 @@ namespace Mono.CSharp { @@ -1558,23 +1631,6 @@ namespace Mono.CSharp {
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)
{
object[] cls_attr = attribute_provider.GetCustomAttributes (typeof (CLSCompliantAttribute), false);
@ -1633,6 +1689,7 @@ namespace Mono.CSharp { @@ -1633,6 +1689,7 @@ namespace Mono.CSharp {
public readonly PredefinedAttribute AttributeUsage;
public readonly PredefinedAttribute DefaultParameterValue;
public readonly PredefinedAttribute OptionalParameter;
public readonly PredefinedAttribute UnverifiableCode;
// New in .NET 2.0
public readonly PredefinedAttribute DefaultCharset;
@ -1654,7 +1711,7 @@ namespace Mono.CSharp { @@ -1654,7 +1711,7 @@ namespace Mono.CSharp {
// Optional types which are used as types and for member lookup
//
public readonly PredefinedAttribute DefaultMember;
public readonly PredefinedAttribute DecimalConstant;
public readonly PredefinedDecimalAttribute DecimalConstant;
public readonly PredefinedAttribute StructLayout;
public readonly PredefinedAttribute FieldOffset;
@ -1683,6 +1740,7 @@ namespace Mono.CSharp { @@ -1683,6 +1740,7 @@ namespace Mono.CSharp {
AttributeUsage = new PredefinedAttribute ("System", "AttributeUsageAttribute");
DefaultParameterValue = new PredefinedAttribute ("System.Runtime.InteropServices", "DefaultParameterValueAttribute");
OptionalParameter = new PredefinedAttribute ("System.Runtime.InteropServices", "OptionalAttribute");
UnverifiableCode = new PredefinedAttribute ("System.Security", "UnverifiableCodeAttribute");
DefaultCharset = new PredefinedAttribute ("System.Runtime.InteropServices", "DefaultCharSetAttribute");
TypeForwarder = new PredefinedAttribute ("System.Runtime.CompilerServices", "TypeForwardedToAttribute");
@ -1698,7 +1756,7 @@ namespace Mono.CSharp { @@ -1698,7 +1756,7 @@ namespace Mono.CSharp {
Dynamic = new PredefinedDynamicAttribute ("System.Runtime.CompilerServices", "DynamicAttribute");
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");
FieldOffset = new PredefinedAttribute ("System.Runtime.InteropServices", "FieldOffsetAttribute");
}
@ -1714,10 +1772,11 @@ namespace Mono.CSharp { @@ -1714,10 +1772,11 @@ namespace Mono.CSharp {
public class PredefinedAttribute
{
protected TypeSpec type;
CustomAttributeBuilder cab;
MethodSpec ctor;
protected MethodSpec ctor;
readonly string ns, name;
CompilerContext compiler;
List<FieldSpec> fields;
List<PropertySpec> properties;
static readonly TypeSpec NotFound = InternalType.Null;
@ -1727,6 +1786,29 @@ namespace Mono.CSharp { @@ -1727,6 +1786,29 @@ namespace Mono.CSharp {
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)
{
return type == pa.type;
@ -1737,10 +1819,6 @@ namespace Mono.CSharp { @@ -1737,10 +1819,6 @@ namespace Mono.CSharp {
return type != pa.type;
}
public ConstructorInfo Constructor {
get { return ctor == null ? null : (ConstructorInfo) ctor.GetMetaInfo (); }
}
public override int GetHashCode ()
{
return base.GetHashCode ();
@ -1759,47 +1837,118 @@ namespace Mono.CSharp { @@ -1759,47 +1837,118 @@ namespace Mono.CSharp {
public void EmitAttribute (ConstructorBuilder builder)
{
if (ResolveBuilder ())
builder.SetCustomAttribute (cab);
builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
}
public void EmitAttribute (MethodBuilder builder)
{
if (ResolveBuilder ())
builder.SetCustomAttribute (cab);
builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
}
public void EmitAttribute (PropertyBuilder builder)
{
if (ResolveBuilder ())
builder.SetCustomAttribute (cab);
builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
}
public void EmitAttribute (FieldBuilder builder)
{
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)
{
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)
{
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)
{
if (ResolveBuilder ())
builder.SetCustomAttribute (cab);
builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
}
public bool IsDefined {
get { return type != null && type != NotFound; }
public void EmitAttribute (ParameterBuilder builder, AttributeEncoder argsEncoded)
{
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)
@ -1826,9 +1975,9 @@ namespace Mono.CSharp { @@ -1826,9 +1975,9 @@ namespace Mono.CSharp {
return true;
}
bool ResolveBuilder ()
public bool ResolveBuilder ()
{
if (cab != null)
if (ctor != null)
return true;
//
@ -1837,12 +1986,8 @@ namespace Mono.CSharp { @@ -1837,12 +1986,8 @@ namespace Mono.CSharp {
if (!Resolve (true))
return false;
var ci = TypeManager.GetPredefinedConstructor (type, Location.Null, TypeSpec.EmptyTypes);
if (ci == null)
return false;
cab = new CustomAttributeBuilder ((ConstructorInfo) ci.GetMetaInfo (), new object[0]);
return true;
ctor = TypeManager.GetPredefinedConstructor (type, Location.Null, TypeSpec.EmptyTypes);
return ctor != null;
}
public bool ResolveConstructor (Location loc, params TypeSpec[] argType)
@ -1856,9 +2001,53 @@ namespace Mono.CSharp { @@ -1856,9 +2001,53 @@ namespace Mono.CSharp {
ctor = TypeManager.GetPredefinedConstructor (type, loc, argType);
return ctor != null;
}
}
public TypeSpec Type {
get { return type; }
public class PredefinedDecimalAttribute : PredefinedAttribute
{
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 { @@ -169,7 +169,7 @@ namespace Mono.CSharp {
case Binary.Operator.Subtraction:
result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
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;
///
@ -477,6 +477,11 @@ namespace Mono.CSharp { @@ -477,6 +477,11 @@ namespace Mono.CSharp {
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))
return null;
@ -568,6 +573,11 @@ namespace Mono.CSharp { @@ -568,6 +573,11 @@ namespace Mono.CSharp {
return result;
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))
return null;
@ -658,6 +668,11 @@ namespace Mono.CSharp { @@ -658,6 +668,11 @@ namespace Mono.CSharp {
break;
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))
return null;
@ -752,6 +767,11 @@ namespace Mono.CSharp { @@ -752,6 +767,11 @@ namespace Mono.CSharp {
break;
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))
return null;
@ -836,6 +856,11 @@ namespace Mono.CSharp { @@ -836,6 +856,11 @@ namespace Mono.CSharp {
// There is no overflow checking on left shift
//
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;
if (ic == null){
Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
@ -850,6 +875,10 @@ namespace Mono.CSharp { @@ -850,6 +875,10 @@ namespace Mono.CSharp {
if (left.Type == TypeManager.uint32_type)
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);
if (left.Type == TypeManager.int32_type)
return new IntConstant (((IntConstant)left).Value << lshift_val, left.Location);
@ -861,6 +890,11 @@ namespace Mono.CSharp { @@ -861,6 +890,11 @@ namespace Mono.CSharp {
// There is no overflow checking on right shift
//
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;
if (sic == null){
Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc); ;
@ -874,6 +908,10 @@ namespace Mono.CSharp { @@ -874,6 +908,10 @@ namespace Mono.CSharp {
if (left.Type == TypeManager.uint32_type)
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);
if (left.Type == TypeManager.int32_type)
return new IntConstant (((IntConstant)left).Value >> rshift_val, left.Location);
@ -970,6 +1008,17 @@ namespace Mono.CSharp { @@ -970,6 +1008,17 @@ namespace Mono.CSharp {
return new BoolConstant (bool_res, left.Location);
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))
return null;
@ -998,6 +1047,17 @@ namespace Mono.CSharp { @@ -998,6 +1047,17 @@ namespace Mono.CSharp {
return new BoolConstant (bool_res, left.Location);
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))
return null;
@ -1026,6 +1086,17 @@ namespace Mono.CSharp { @@ -1026,6 +1086,17 @@ namespace Mono.CSharp {
return new BoolConstant (bool_res, left.Location);
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))
return null;
@ -1054,6 +1125,17 @@ namespace Mono.CSharp { @@ -1054,6 +1125,17 @@ namespace Mono.CSharp {
return new BoolConstant (bool_res, left.Location);
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))
return null;

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

Loading…
Cancel
Save