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

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

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

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

@ -46,12 +46,11 @@ namespace Mono.CSharp { @@ -46,12 +46,11 @@ namespace Mono.CSharp {
{
if (attrs == null)
return;
if (attributes == null)
attributes = attrs;
else
attributes.AddAttributes (attrs.Attrs);
attrs.AttachTo (this, context);
}
@ -1108,16 +1107,26 @@ namespace Mono.CSharp { @@ -1108,16 +1107,26 @@ namespace Mono.CSharp {
public class Attributes
{
public readonly List<Attribute> Attrs;
#if FULL_AST
public readonly List<List<Attribute>> Sections = new List<List<Attribute>> ();
#endif
public Attributes (Attribute a)
{
Attrs = new List<Attribute> ();
Attrs.Add (a);
#if FULL_AST
Sections.Add (Attrs);
#endif
}
public Attributes (List<Attribute> attrs)
{
Attrs = attrs;
#if FULL_AST
Sections.Add (attrs);
#endif
}
public void AddAttribute (Attribute attr)
@ -1127,7 +1136,11 @@ namespace Mono.CSharp { @@ -1127,7 +1136,11 @@ namespace Mono.CSharp {
public void AddAttributes (List<Attribute> attrs)
{
#if FULL_AST
Sections.Add (attrs);
#else
Attrs.AddRange (attrs);
#endif
}
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 @@ -655,7 +655,7 @@ attribute_sections
{
var sect = (List<Attribute>) $1;
$$ = new Attributes (sect);
lbag.AddLocation ($$, savedOpenLocation, savedCloseLocation);
lbag.AddLocation (sect, savedOpenLocation, savedCloseLocation);
}
| attribute_sections attribute_section
{
@ -665,6 +665,7 @@ attribute_sections @@ -665,6 +665,7 @@ attribute_sections
attrs = new Attributes (sect);
else
attrs.AddAttributes (sect);
lbag.AddLocation (sect, savedOpenLocation, savedCloseLocation);
$$ = attrs;
}
;

Loading…
Cancel
Save