Browse Source

Fixed attribute section locations.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
0fb1105d05
  1. 17
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/AttributeSection.cs
  2. 24
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  3. 1337
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  4. 23
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay

17
ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/AttributeSection.cs

@ -85,8 +85,21 @@ namespace ICSharpCode.NRefactory.CSharp @@ -85,8 +85,21 @@ namespace ICSharpCode.NRefactory.CSharp
}
public string AttributeTarget {
get;
set;
get {
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (value, TextLocation.Empty));
}
}
public Identifier AttributeTargetToken {
get {
return GetChildByRole (Roles.Identifier);
}
set {
SetChildByRole (Roles.Identifier, value);
}
}
public AstNodeCollection<Attribute> Attributes {

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

@ -243,16 +243,30 @@ namespace ICSharpCode.NRefactory.CSharp @@ -243,16 +243,30 @@ namespace ICSharpCode.NRefactory.CSharp
return null;
AttributeSection result = new AttributeSection ();
var loc = LocationsBag.GetLocations (optAttributes);
int pos = 0;
if (loc != null)
result.AddChild (new CSharpTokenNode (Convert (loc [0]), 1), AttributeSection.Roles.LBracket);
result.AddChild (new CSharpTokenNode (Convert (loc [pos++]), 1), AttributeSection.Roles.LBracket);
string target = optAttributes.First ().ExplicitTarget;
if (!string.IsNullOrEmpty (target)) {
if (loc != null && pos < loc.Count - 1) {
result.AddChild (Identifier.Create (target, Convert (loc [pos++])), AttributeSection.Roles.Identifier);
} else {
result.AddChild (Identifier.Create (target), AttributeSection.Roles.Identifier);
}
if (loc != null && pos < loc.Count)
result.AddChild (new CSharpTokenNode (Convert (loc [pos++]), 1), AttributeSection.Roles.Colon);
}
result.AttributeTarget = optAttributes.First ().ExplicitTarget;
foreach (var attr in GetAttributes (optAttributes)) {
result.AddChild (attr, AttributeSection.AttributeRole);
}
if (loc != null)
result.AddChild (new CSharpTokenNode (Convert (loc [1]), 1), AttributeSection.Roles.RBracket);
// optional comma
if (loc != null && pos < loc.Count - 1 && !loc [pos].Equals (loc [pos + 1]))
result.AddChild (new CSharpTokenNode (Convert (loc [pos++]), 1), AttributeSection.Roles.Comma);
if (loc != null && pos < loc.Count)
result.AddChild (new CSharpTokenNode (Convert (loc [pos++]), 1), AttributeSection.Roles.RBracket);
return result;
}

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

File diff suppressed because it is too large Load Diff

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

@ -673,7 +673,8 @@ attribute_sections @@ -673,7 +673,8 @@ attribute_sections
{
var sect = (List<Attribute>) $1;
$$ = new Attributes (sect);
lbag.AddLocation (sect, savedOpenLocation, savedCloseLocation);
if (locationListStack.Count > 0)
lbag.AddLocation (sect, locationListStack.Pop ());
if (attributeCommas.Count > 0) {
lbag.AppendTo (sect, attributeCommas);
attributeCommas.Clear ();
@ -683,6 +684,9 @@ attribute_sections @@ -683,6 +684,9 @@ attribute_sections
{
Attributes attrs = $1 as Attributes;
var sect = (List<Attribute>) $2;
if (locationListStack.Count > 0)
lbag.AddLocation (sect, locationListStack.Pop ());
if (attrs == null)
attrs = new Attributes (sect);
else
@ -722,12 +726,20 @@ attribute_section_cont @@ -722,12 +726,20 @@ attribute_section_cont
current_attr_target = null;
lexer.parsing_attribute_section = false;
savedCloseLocation = GetLocation ($6);
if ($5 != null) {
locationListStack.Push (new List<Location>(new [] { savedOpenLocation, savedCloseLocation, GetLocation ($2), GetLocation ($5), GetLocation ($6) }));
} else {
locationListStack.Push (new List<Location>(new [] { savedOpenLocation, savedCloseLocation, GetLocation ($2), GetLocation ($6) }));
}
}
| attribute_list opt_comma CLOSE_BRACKET
{
$$ = $1;
savedCloseLocation = GetLocation ($3);
if ($2 != null) {
locationListStack.Push (new List<Location>(new [] { savedOpenLocation, GetLocation ($2), GetLocation ($3) }));
} else {
locationListStack.Push (new List<Location>(new [] { savedOpenLocation, GetLocation ($3) }));
}
}
;
@ -736,9 +748,10 @@ attribute_target @@ -736,9 +748,10 @@ attribute_target
{
var lt = (Tokenizer.LocatedToken) $1;
$$ = CheckAttributeTarget (lt.Value, lt.Location);
savedCloseLocation = GetLocation ($1);
}
| EVENT { $$ = "event"; }
| RETURN { $$ = "return"; }
| EVENT { $$ = "event"; savedCloseLocation = GetLocation ($1); }
| RETURN { $$ = "return"; savedCloseLocation = GetLocation ($1); }
| error
{
if (yyToken == Token.IDENTIFIER) {

Loading…
Cancel
Save