Browse Source

Fixed enum member commas.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
eddd015987
  1. 44
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  2. 1246
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  3. 48
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
  4. 15
      ICSharpCode.NRefactory.CSharp/Parser/mcs/decl.cs

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

@ -392,9 +392,8 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && curLoc < location.Count) { if (location != null && curLoc < location.Count) {
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace);
// optional semicolon if (c.HasOptionalSemicolon)
if (location != null && curLoc < location.Count) newType.AddChild (new CSharpTokenNode (Convert (c.OptionalSemicolon), 1), AstNode.Roles.Semicolon);
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Semicolon);
} else { } else {
// parser error, set end node to max value. // parser error, set end node to max value.
@ -446,9 +445,8 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && location.Count > 2) { if (location != null && location.Count > 2) {
if (location != null && curLoc < location.Count) if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace);
// optional semicolon if (s.HasOptionalSemicolon)
if (location != null && curLoc < location.Count) newType.AddChild (new CSharpTokenNode (Convert (s.OptionalSemicolon), 1), AstNode.Roles.Semicolon);
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Semicolon);
} else { } else {
// parser error, set end node to max value. // parser error, set end node to max value.
newType.AddChild (new ErrorNode (), AstNode.Roles.Error); newType.AddChild (new ErrorNode (), AstNode.Roles.Error);
@ -497,9 +495,8 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && location.Count > 2) { if (location != null && location.Count > 2) {
if (location != null && curLoc < location.Count) if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace);
// optional semicolon if (i.HasOptionalSemicolon)
if (location != null && curLoc < location.Count) newType.AddChild (new CSharpTokenNode (Convert (i.OptionalSemicolon), 1), AstNode.Roles.Semicolon);
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Semicolon);
} else { } else {
// parser error, set end node to max value. // parser error, set end node to max value.
newType.AddChild (new ErrorNode (), AstNode.Roles.Error); newType.AddChild (new ErrorNode (), AstNode.Roles.Error);
@ -578,13 +575,19 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && curLoc < location.Count) if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.LBrace); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.LBrace);
typeStack.Push (newType); typeStack.Push (newType);
base.Visit (e);
foreach (EnumMember member in e.OrderedAllMembers) {
Visit (member);
if (location != null && curLoc < location.Count - 1) //last one is closing brace
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Comma);
}
if (location != null && location.Count > 2) { if (location != null && location.Count > 2) {
if (location != null && curLoc < location.Count) if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace);
// optional semicolon
if (location != null && curLoc < location.Count) if (e.HasOptionalSemicolon)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Semicolon); newType.AddChild (new CSharpTokenNode (Convert (e.OptionalSemicolon), 1), AstNode.Roles.Semicolon);
} else { } else {
// parser error, set end node to max value. // parser error, set end node to max value.
newType.AddChild (new ErrorNode (), AstNode.Roles.Error); newType.AddChild (new ErrorNode (), AstNode.Roles.Error);
@ -1884,16 +1887,19 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild ((Expression)leftExpr, MemberReferenceExpression.Roles.TargetExpression); result.AddChild ((Expression)leftExpr, MemberReferenceExpression.Roles.TargetExpression);
} }
} }
var location = LocationsBag.GetLocations (memberAccess);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MemberReferenceExpression.Roles.Dot);
result.AddChild (Identifier.Create (memberAccess.Name, Convert (memberAccess.Location)), MemberReferenceExpression.Roles.Identifier); result.AddChild (Identifier.Create (memberAccess.Name, Convert (memberAccess.Location)), MemberReferenceExpression.Roles.Identifier);
if (memberAccess.TypeArguments != null) { if (memberAccess.TypeArguments != null) {
var location = LocationsBag.GetLocations (memberAccess); var locationTypeArgs = LocationsBag.GetLocations (memberAccess.TypeArguments);
if (location != null) if (locationTypeArgs != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MemberReferenceExpression.Roles.LChevron); result.AddChild (new CSharpTokenNode (Convert (locationTypeArgs[0]), 1), MemberReferenceExpression.Roles.LChevron);
AddTypeArguments (result, location, memberAccess.TypeArguments); AddTypeArguments (result, locationTypeArgs, memberAccess.TypeArguments);
if (location != null && location.Count > 1) if (locationTypeArgs != null && locationTypeArgs.Count > 1)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MemberReferenceExpression.Roles.RChevron); result.AddChild (new CSharpTokenNode (Convert (locationTypeArgs[1]), 1), MemberReferenceExpression.Roles.RChevron);
} }
return result; return result;
} }

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

File diff suppressed because it is too large Load Diff

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

@ -142,11 +142,12 @@ namespace Mono.CSharp
LocationsBag lbag; LocationsBag lbag;
UsingsBag ubag; UsingsBag ubag;
List<Tuple<Modifiers, Location>> mod_locations; List<Tuple<Modifiers, Location>> mod_locations;
Location parameterModifierLocation, savedLocation, savedOpenLocation, savedCloseLocation, savedEnumBaseTypeColonLocation; Location parameterModifierLocation, savedLocation, savedOpenLocation, savedCloseLocation;
Location savedAttrParenOpenLocation, savedAttrParenCloseLocation; Location savedAttrParenOpenLocation, savedAttrParenCloseLocation;
Stack<List<Location>> locationListStack = new Stack<List<Location>> (); // used for type parameters Stack<List<Location>> locationListStack = new Stack<List<Location>> (); // used for type parameters
List<Location> attributeCommas = new List<Location> (); List<Location> attributeCommas = new List<Location> ();
List<Location> parameterListCommas = new List<Location> (); List<Location> parameterListCommas = new List<Location> ();
List<Location> enumCommas = new List<Location> ();
object lastYYVal; object lastYYVal;
@ -954,7 +955,8 @@ struct_declaration
} }
opt_semicolon opt_semicolon
{ {
lbag.AppendToMember (current_class, GetLocation ($13)); if ($13 != null)
current_class.OptionalSemicolon = GetLocation ($13);
$$ = pop_current_class (); $$ = pop_current_class ();
} }
| opt_attributes opt_modifiers opt_partial STRUCT error | opt_attributes opt_modifiers opt_partial STRUCT error
@ -1974,11 +1976,9 @@ interface_declaration
} }
opt_semicolon opt_semicolon
{ {
if ($15 != null) { if ($15 != null)
lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15)); current_class.OptionalSemicolon = GetLocation ($15);
} else {
lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13)); lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13));
}
$$ = pop_current_class (); $$ = pop_current_class ();
} }
| opt_attributes opt_modifiers opt_partial INTERFACE error | opt_attributes opt_modifiers opt_partial INTERFACE error
@ -2558,6 +2558,7 @@ enum_declaration
ENUM type_declaration_name ENUM type_declaration_name
opt_enum_base opt_enum_base
{ {
enumCommas.Add (GetLocation ($3));
if (doc_support) if (doc_support)
enumTypeComment = Lexer.consume_doc_comment (); enumTypeComment = Lexer.consume_doc_comment ();
} }
@ -2565,6 +2566,7 @@ enum_declaration
{ {
if (doc_support) if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed; Lexer.doc_state = XmlCommentState.Allowed;
enumCommas.Add (GetLocation ($7));
MemberName name = (MemberName) $4; MemberName name = (MemberName) $4;
if (name.IsGeneric) { if (name.IsGeneric) {
@ -2581,26 +2583,16 @@ enum_declaration
} }
CLOSE_BRACE opt_semicolon CLOSE_BRACE opt_semicolon
{ {
enumCommas.Add (GetLocation ($11));
if ($12 != null)
current_class.OptionalSemicolon = GetLocation ($12);
if (doc_support) if (doc_support)
current_class.DocComment = enumTypeComment; current_class.DocComment = enumTypeComment;
--lexer.parsing_declaration; --lexer.parsing_declaration;
// if (doc_support) lbag.AddMember (current_class, GetModifierLocations (), enumCommas);
// em.DocComment = ev.DocComment; enumCommas.Clear ();
if ($5 != null) {
if ($12 != null) {
lbag.AddMember (current_class, GetModifierLocations (), GetLocation ($3), savedEnumBaseTypeColonLocation, GetLocation ($7), GetLocation ($11), GetLocation ($12));
} else {
lbag.AddMember (current_class, GetModifierLocations (), GetLocation ($3), savedEnumBaseTypeColonLocation, GetLocation ($7), GetLocation ($11));
}
} else {
if ($12 != null) {
lbag.AddMember (current_class, GetModifierLocations (), GetLocation ($3), GetLocation ($7), GetLocation ($11), GetLocation ($12));
} else {
lbag.AddMember (current_class, GetModifierLocations (), GetLocation ($3), GetLocation ($7), GetLocation ($11));
}
}
$$ = pop_current_class (); $$ = pop_current_class ();
} }
; ;
@ -2614,7 +2606,7 @@ opt_enum_base
Enum.Error_1008 (GetLocation ($2), report); Enum.Error_1008 (GetLocation ($2), report);
$$ = null; $$ = null;
} else { } else {
savedEnumBaseTypeColonLocation = GetLocation ($1); enumCommas.Add (GetLocation ($1));
$$ = $2; $$ = $2;
} }
} }
@ -2630,7 +2622,7 @@ opt_enum_member_declarations
| enum_member_declarations | enum_member_declarations
| enum_member_declarations COMMA | enum_member_declarations COMMA
{ {
lbag.AddLocation ($1, GetLocation ($2)); enumCommas.Add (GetLocation ($2));
} }
; ;
@ -2638,7 +2630,7 @@ enum_member_declarations
: enum_member_declaration : enum_member_declaration
| enum_member_declarations COMMA enum_member_declaration | enum_member_declarations COMMA enum_member_declaration
{ {
lbag.AddLocation ($1, GetLocation ($2)); enumCommas.Add (GetLocation ($2));
$$ = $3; $$ = $3;
} }
; ;
@ -4343,8 +4335,8 @@ class_declaration
FeatureIsNotAvailable (c.Location, "static classes"); FeatureIsNotAvailable (c.Location, "static classes");
} }
lbag.AddMember (current_class, GetModifierLocations ());
push_current_class (c, $3); push_current_class (c, $3);
lbag.AddMember (current_class, GetModifierLocations ());
} }
opt_class_base opt_class_base
opt_type_parameter_constraints_clauses opt_type_parameter_constraints_clauses
@ -4366,11 +4358,9 @@ class_declaration
} }
opt_semicolon opt_semicolon
{ {
if ($15 != null) {
lbag.AppendToMember (current_class, GetLocation ($4), GetLocation ($11), GetLocation ($13), GetLocation ($15));
} else {
lbag.AppendToMember (current_class, GetLocation ($4), GetLocation ($11), GetLocation ($13)); lbag.AppendToMember (current_class, GetLocation ($4), GetLocation ($11), GetLocation ($13));
} if ($15 != null)
current_class.OptionalSemicolon = GetLocation ($15);
$$ = pop_current_class (); $$ = pop_current_class ();
} }
; ;

15
ICSharpCode.NRefactory.CSharp/Parser/mcs/decl.cs

@ -1440,6 +1440,21 @@ namespace Mono.CSharp {
get; get;
private set; private set;
} }
public bool HasOptionalSemicolon {
get;
private set;
}
Location optionalSemicolon;
public Location OptionalSemicolon {
get {
return optionalSemicolon;
}
set {
optionalSemicolon = value;
HasOptionalSemicolon = true;
}
}
#endif #endif
public List<Constraints> Constraints { public List<Constraints> Constraints {

Loading…
Cancel
Save