Permalink
Browse files

AST bugfixes.

  • Loading branch information...
1 parent 60d4fe9 commit defd42696dd5c6505f1290961192c09ab1af2fe0 @dgrunwald dgrunwald committed Feb 28, 2011
@@ -48,6 +48,12 @@ public class CSharpModifierToken : CSharpTokenNode
}
}
+ protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
+ {
+ CSharpModifierToken o = other as CSharpModifierToken;
+ return o != null && this.modifier == o.modifier;
+ }
+
// Not worth using a dictionary for such few elements.
// This table is sorted in the order that modifiers should be output when generating code.
static readonly List<KeyValuePair<Modifiers, int>> lengthTable = new List<KeyValuePair<Modifiers, int>> () {
@@ -88,7 +88,7 @@ public CSharpTokenNode (AstLocation location, int tokenLength)
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
CSharpTokenNode o = other as CSharpTokenNode;
- return o != null;
+ return o != null && !o.IsNull && !(o is CSharpModifierToken);
}
public override string ToString ()
@@ -45,7 +45,7 @@ protected internal override bool DoMatch(AstNode other, PatternMatching.Match ma
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
QueryExpression o = other as QueryExpression;
- return o != null && this.Clauses.DoMatch(o.Clauses, match);
+ return o != null && !o.IsNull && this.Clauses.DoMatch(o.Clauses, match);
}
}
@@ -64,6 +64,15 @@ protected internal override bool DoMatch(AstNode other, PatternMatching.Match ma
return o != null && this.AttributeTarget == o.AttributeTarget && this.Attributes.DoMatch(o.Attributes, match);
}
+ public AttributeSection()
+ {
+ }
+
+ public AttributeSection(Attribute attr)
+ {
+ this.Attributes.Add(attr);
+ }
+
public static string GetAttributeTargetName(AttributeTarget attributeTarget)
{
switch (attributeTarget) {
@@ -15,12 +15,17 @@ namespace ICSharpCode.NRefactory.CSharp
/// </summary>
public class TypeParameterDeclaration : AstNode
{
+ public static readonly Role<AttributeSection> AttributeRole = AttributedNode.AttributeRole;
public static readonly Role<CSharpTokenNode> VarianceRole = new Role<CSharpTokenNode>("Variance");
public override NodeType NodeType {
get { return NodeType.Unknown; }
}
+ public AstNodeCollection<AttributeSection> Attributes {
+ get { return GetChildrenByRole (AttributeRole); }
+ }
+
public VarianceModifier Variance {
get; set;
}
@@ -42,7 +47,7 @@ public class TypeParameterDeclaration : AstNode
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
TypeParameterDeclaration o = other as TypeParameterDeclaration;
- return o != null && this.Variance == o.Variance && MatchString(this.Name, o.Name);
+ return o != null && this.Variance == o.Variance && MatchString(this.Name, o.Name) && this.Attributes.DoMatch(o.Attributes, match);
}
}
}
@@ -43,6 +43,11 @@ class NullIdentifier : Identifier
{
return default (S);
}
+
+ protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
+ {
+ return other == null || other.IsNull;
+ }
}
public override NodeType NodeType {
@@ -95,7 +100,7 @@ public Identifier (string name, AstLocation location)
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
Identifier o = other as Identifier;
- return o != null && MatchString(this.Name, o.Name);
+ return o != null && !o.IsNull && MatchString(this.Name, o.Name);
}
}
}
@@ -77,7 +77,7 @@ protected internal override bool DoMatch(AstNode other, PatternMatching.Match ma
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
BlockStatement o = other as BlockStatement;
- return o != null && this.Statements.DoMatch(o.Statements, match);
+ return o != null && !o.IsNull && this.Statements.DoMatch(o.Statements, match);
}
#region Builder methods
@@ -65,7 +65,7 @@ sealed class NullAccessor : Accessor
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
Accessor o = other as Accessor;
- return o != null && this.MatchAttributesAndModifiers(o, match) && this.Body.DoMatch(o.Body, match);
+ return o != null && !o.IsNull && this.MatchAttributesAndModifiers(o, match) && this.Body.DoMatch(o.Body, match);
}
}
}
@@ -105,6 +105,11 @@ class NullConstructorInitializer : ConstructorInitializer
{
return default (S);
}
+
+ protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
+ {
+ return other == null || other.IsNull;
+ }
}
public override NodeType NodeType {
@@ -130,7 +135,7 @@ class NullConstructorInitializer : ConstructorInitializer
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
ConstructorInitializer o = other as ConstructorInitializer;
- return o != null && this.ConstructorInitializerType == o.ConstructorInitializerType && this.Arguments.DoMatch(o.Arguments, match);
+ return o != null && !o.IsNull && this.ConstructorInitializerType == o.ConstructorInitializerType && this.Arguments.DoMatch(o.Arguments, match);
}
}
}
@@ -28,8 +28,17 @@
namespace ICSharpCode.NRefactory.CSharp
{
- public class EventDeclaration : MemberDeclaration
+ public class EventDeclaration : AttributedNode
{
+ public override NodeType NodeType {
+ get { return NodeType.Member; }
+ }
+
+ public AstType ReturnType {
+ get { return GetChildByRole (Roles.Type); }
+ set { SetChildByRole(Roles.Type, value); }
+ }
+
public AstNodeCollection<VariableInitializer> Variables {
get { return GetChildrenByRole (Roles.Variable); }
}
@@ -42,7 +51,8 @@ public class EventDeclaration : MemberDeclaration
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
EventDeclaration o = other as EventDeclaration;
- return o != null && this.MatchMember(o, match) && this.Variables.DoMatch(o.Variables, match);
+ return o != null && this.MatchAttributesAndModifiers(o, match)
+ && this.ReturnType.DoMatch(o.ReturnType, match) && this.Variables.DoMatch(o.Variables, match);
}
}
@@ -1,6 +1,6 @@
//
// FieldDeclaration.cs
-//
+//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
@@ -29,9 +29,18 @@
namespace ICSharpCode.NRefactory.CSharp
{
- public class FieldDeclaration : MemberDeclaration
+ public class FieldDeclaration : AttributedNode
{
- public AstNodeCollection<VariableInitializer> Variables {
+ public override NodeType NodeType {
+ get { return NodeType.Member; }
+ }
+
+ public AstType ReturnType {
+ get { return GetChildByRole (Roles.Type); }
+ set { SetChildByRole(Roles.Type, value); }
+ }
+
+ public AstNodeCollection<VariableInitializer> Variables {
get { return GetChildrenByRole (Roles.Variable); }
}
@@ -43,7 +52,8 @@ public class FieldDeclaration : MemberDeclaration
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
FieldDeclaration o = other as FieldDeclaration;
- return o != null && this.MatchMember(o, match) && this.Variables.DoMatch(o.Variables, match);
+ return o != null && this.MatchAttributesAndModifiers(o, match)
+ && this.ReturnType.DoMatch(o.ReturnType, match) && this.Variables.DoMatch(o.Variables, match);
}
}
}
@@ -66,7 +66,7 @@ public enum OperatorType {
Explicit
}
- public class OperatorDeclaration : MemberDeclaration
+ public class OperatorDeclaration : AttributedNode
{
public static readonly Role<CSharpTokenNode> OperatorTypeRole = new Role<CSharpTokenNode>("OperatorType", CSharpTokenNode.Null);
public static readonly Role<CSharpTokenNode> OperatorKeywordRole = Roles.Keyword;
@@ -76,6 +76,11 @@ public class OperatorDeclaration : MemberDeclaration
set;
}
+ public AstType ReturnType {
+ get { return GetChildByRole (Roles.Type); }
+ set { SetChildByRole(Roles.Type, value); }
+ }
+
public CSharpTokenNode LParToken {
get { return GetChildByRole (Roles.LPar); }
}
@@ -103,15 +108,24 @@ public static string GetToken(OperatorType type)
return Mono.CSharp.Operator.GetName((Mono.CSharp.Operator.OpType)type);
}
+ public override NodeType NodeType {
+ get { return NodeType.Member; }
+ }
+
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitOperatorDeclaration (this, data);
}
+ public string Name {
+ get { return GetName(this.OperatorType); }
+ }
+
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
OperatorDeclaration o = other as OperatorDeclaration;
- return o != null && this.MatchMember(o, match) && this.OperatorType == o.OperatorType
+ return o != null && this.MatchAttributesAndModifiers(o, match) && this.OperatorType == o.OperatorType
+ && this.ReturnType.DoMatch(o.ReturnType, match)
&& this.Parameters.DoMatch(o.Parameters, match) && this.Body.DoMatch(o.Body, match);
}
}
@@ -89,6 +89,16 @@ protected internal override bool DoMatch(AstNode other, PatternMatching.Match ma
&& this.Type.DoMatch(o.Type, match) && MatchString(this.Name, o.Name)
&& this.DefaultExpression.DoMatch(o.DefaultExpression, match);
}
+
+ public ParameterDeclaration()
+ {
+ }
+
+ public ParameterDeclaration(AstType type, string name)
+ {
+ this.Type = type;
+ this.Name = name;
+ }
}
}
@@ -1946,6 +1946,7 @@ public object VisitComment(Comment comment, object data)
public object VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, object data)
{
StartNode(typeParameterDeclaration);
+ WriteAttributes(typeParameterDeclaration.Attributes);
switch (typeParameterDeclaration.Variance) {
case VarianceModifier.Invariant:
break;
@@ -224,11 +224,11 @@ public override ResolveResult VisitEventDeclaration(EventDeclaration eventDeclar
return VisitFieldOrEventDeclaration(eventDeclaration);
}
- ResolveResult VisitFieldOrEventDeclaration(MemberDeclaration fieldDeclaration)
+ ResolveResult VisitFieldOrEventDeclaration(AttributedNode fieldOrEventDeclaration)
{
- int initializerCount = fieldDeclaration.GetChildrenByRole(FieldDeclaration.Roles.Variable).Count();
+ int initializerCount = fieldOrEventDeclaration.GetChildrenByRole(FieldDeclaration.Roles.Variable).Count();
ResolveResult result = null;
- for (AstNode node = fieldDeclaration.FirstChild; node != null; node = node.NextSibling) {
+ for (AstNode node = fieldOrEventDeclaration.FirstChild; node != null; node = node.NextSibling) {
if (node.Role == FieldDeclaration.Roles.Variable) {
if (resolver.CurrentTypeDefinition != null) {
resolver.CurrentMember = resolver.CurrentTypeDefinition.Fields.FirstOrDefault(f => f.Region.IsInside(node.StartLocation));

0 comments on commit defd426

Please sign in to comment.