Browse Source

Fixed 'GlobalAttributeCSharp' test.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
0398fd691a
  1. 2
      ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs
  2. 13
      ICSharpCode.NRefactory/CSharp/Ast/GeneralScope/Attribute.cs
  3. 37
      ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
  4. 17
      ICSharpCode.NRefactory/CSharp/Parser/mcs/attribute.cs
  5. 1289
      ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-parser.cs
  6. 3
      ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-parser.jay

2
ICSharpCode.NRefactory.Tests/CSharp/Parser/GeneralScope/AttributeSectionTests.cs

@ -12,7 +12,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.GeneralScope
[TestFixture] [TestFixture]
public class AttributeSectionTests public class AttributeSectionTests
{ {
[Test, Ignore("Parser crash")] [Test]
public void GlobalAttributeCSharp() public void GlobalAttributeCSharp()
{ {
string program = @"[global::Microsoft.VisualBasic.CompilerServices.DesignerGenerated()] string program = @"[global::Microsoft.VisualBasic.CompilerServices.DesignerGenerated()]

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

@ -53,10 +53,19 @@ namespace ICSharpCode.NRefactory.CSharp
return visitor.VisitAttribute (this, data); return visitor.VisitAttribute (this, data);
} }
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) protected internal override bool DoMatch (AstNode other, PatternMatching.Match match)
{ {
Attribute o = other as Attribute; Attribute o = other as Attribute;
return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match); return o != null && this.Type.DoMatch (o.Type, match) && this.Arguments.DoMatch (o.Arguments, match);
}
public override string ToString ()
{
if (IsNull)
return "Null";
var w = new System.IO.StringWriter ();
AcceptVisitor (new OutputVisitor (w, new CSharpFormattingOptions ()), null);
return w.ToString ();
} }
} }
} }

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

@ -114,11 +114,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (typeName is Mono.CSharp.QualifiedAliasMember) { if (typeName is Mono.CSharp.QualifiedAliasMember) {
var qam = (Mono.CSharp.QualifiedAliasMember)typeName; var qam = (Mono.CSharp.QualifiedAliasMember)typeName;
var memberType = new MemberType (); var memberType = new MemberType ();
if (qam.LeftExpression == null) { memberType.Target = new SimpleType (qam.alias, Convert (qam.Location));
memberType.Target = new SimpleType ("global", Convert (qam.Location));
} else {
memberType.Target = ConvertToType (qam.LeftExpression);
}
memberType.IsDoubleColon = true; memberType.IsDoubleColon = true;
memberType.MemberName = qam.Name; memberType.MemberName = qam.Name;
return memberType; return memberType;
@ -182,12 +178,11 @@ namespace ICSharpCode.NRefactory.CSharp
return new SimpleType ("unknown"); return new SimpleType ("unknown");
} }
IEnumerable<Attribute> GetAttributes (Attributes optAttributes) IEnumerable<Attribute> GetAttributes (List<Mono.CSharp.Attribute> optAttributes)
{ {
if (optAttributes == null || optAttributes.Attrs == null) if (optAttributes == null)
yield break; yield break;
foreach (var attr in optAttributes) {
foreach (var attr in optAttributes.Attrs) {
Attribute result = new Attribute (); Attribute result = new Attribute ();
result.Type = ConvertToType (attr.TypeNameExpression); result.Type = ConvertToType (attr.TypeNameExpression);
@ -198,13 +193,14 @@ namespace ICSharpCode.NRefactory.CSharp
} }
if (attr.NamedArguments != null) { if (attr.NamedArguments != null) {
foreach (NamedArgument na in attr.NamedArguments) { foreach (NamedArgument na in attr.NamedArguments) {
NamedArgumentExpression newArg = new NamedArgumentExpression(); var newArg = new AssignmentExpression ();
newArg.AddChild (new Identifier (na.Name, Convert (na.Location)), NamedArgumentExpression.Roles.Identifier); newArg.Operator = AssignmentOperatorType.Assign;
newArg.AddChild (new IdentifierExpression (na.Name, Convert (na.Location)), AssignmentExpression.LeftRole);
var loc = LocationsBag.GetLocations (na); var loc = LocationsBag.GetLocations (na);
if (loc != null) if (loc != null)
newArg.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), NamedArgumentExpression.Roles.Assign); newArg.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), AssignmentExpression.Roles.Assign);
newArg.AddChild ((Expression)na.Expr.Accept (this), NamedArgumentExpression.Roles.Expression); newArg.AddChild ((Expression)na.Expr.Accept (this), AssignmentExpression.RightRole);
result.AddChild (newArg, Attribute.Roles.Argument); result.AddChild (newArg, Attribute.Roles.Argument);
} }
} }
@ -212,17 +208,17 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
AttributeSection ConvertAttributeSection (Attributes optAttributes) AttributeSection ConvertAttributeSection (List<Mono.CSharp.Attribute> optAttributes)
{ {
if (optAttributes == null || optAttributes.Attrs == null) if (optAttributes == null)
return null; return null;
AttributeSection result = new AttributeSection (); AttributeSection result = new AttributeSection ();
var loc = LocationsBag.GetLocations (optAttributes); var loc = LocationsBag.GetLocations (optAttributes);
if (loc != null) if (loc != null)
result.AddChild (new CSharpTokenNode (Convert (loc [0]), 1), AttributeSection.Roles.LBracket); result.AddChild (new CSharpTokenNode (Convert (loc [0]), 1), AttributeSection.Roles.LBracket);
result.AttributeTarget = optAttributes.Attrs.First ().ExplicitTarget; result.AttributeTarget = optAttributes.First ().ExplicitTarget;
foreach (var attr in GetAttributes (optAttributes)) { foreach (var attr in GetAttributes (optAttributes)) {
result.AddChild (attr, AttributeSection.AttributeRole); result.AddChild (attr, AttributeSection.AttributeRole);
} }
@ -691,8 +687,11 @@ namespace ICSharpCode.NRefactory.CSharp
public void AddAttributeSection (AttributedNode parent, Attributable a) public void AddAttributeSection (AttributedNode parent, Attributable a)
{ {
if (a.OptAttributes != null && a.OptAttributes.Attrs != null) if (a.OptAttributes == null)
parent.AddChild (ConvertAttributeSection (a.OptAttributes), AttributedNode.AttributeRole); return;
foreach (var attr in a.OptAttributes.Sections) {
parent.AddChild (ConvertAttributeSection (attr), AttributedNode.AttributeRole);
}
} }
public override void Visit (Indexer indexer) public override void Visit (Indexer indexer)

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

@ -46,12 +46,11 @@ namespace Mono.CSharp {
{ {
if (attrs == null) if (attrs == null)
return; return;
if (attributes == null) if (attributes == null)
attributes = attrs; attributes = attrs;
else else
attributes.AddAttributes (attrs.Attrs); attributes.AddAttributes (attrs.Attrs);
attrs.AttachTo (this, context); attrs.AttachTo (this, context);
} }
@ -1108,16 +1107,26 @@ namespace Mono.CSharp {
public class Attributes public class Attributes
{ {
public readonly List<Attribute> Attrs; public readonly List<Attribute> Attrs;
#if FULL_AST
public readonly List<List<Attribute>> Sections = new List<List<Attribute>> ();
#endif
public Attributes (Attribute a) public Attributes (Attribute a)
{ {
Attrs = new List<Attribute> (); Attrs = new List<Attribute> ();
Attrs.Add (a); Attrs.Add (a);
#if FULL_AST
Sections.Add (Attrs);
#endif
} }
public Attributes (List<Attribute> attrs) public Attributes (List<Attribute> attrs)
{ {
Attrs = attrs; Attrs = attrs;
#if FULL_AST
Sections.Add (attrs);
#endif
} }
public void AddAttribute (Attribute attr) public void AddAttribute (Attribute attr)
@ -1127,7 +1136,11 @@ namespace Mono.CSharp {
public void AddAttributes (List<Attribute> attrs) public void AddAttributes (List<Attribute> attrs)
{ {
#if FULL_AST
Sections.Add (attrs);
#else
Attrs.AddRange (attrs); Attrs.AddRange (attrs);
#endif
} }
public void AttachTo (Attributable attributable, IMemberContext context) public void AttachTo (Attributable attributable, IMemberContext context)

1289
ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-parser.cs

File diff suppressed because it is too large Load Diff

3
ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-parser.jay

@ -655,7 +655,7 @@ attribute_sections
{ {
var sect = (List<Attribute>) $1; var sect = (List<Attribute>) $1;
$$ = new Attributes (sect); $$ = new Attributes (sect);
lbag.AddLocation ($$, savedOpenLocation, savedCloseLocation); lbag.AddLocation (sect, savedOpenLocation, savedCloseLocation);
} }
| attribute_sections attribute_section | attribute_sections attribute_section
{ {
@ -665,6 +665,7 @@ attribute_sections
attrs = new Attributes (sect); attrs = new Attributes (sect);
else else
attrs.AddAttributes (sect); attrs.AddAttributes (sect);
lbag.AddLocation (sect, savedOpenLocation, savedCloseLocation);
$$ = attrs; $$ = attrs;
} }
; ;

Loading…
Cancel
Save