Browse Source

Fixed enum member commas.

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

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

@ -392,9 +392,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -392,9 +392,8 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && curLoc < location.Count) {
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace);
// optional semicolon
if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Semicolon);
if (c.HasOptionalSemicolon)
newType.AddChild (new CSharpTokenNode (Convert (c.OptionalSemicolon), 1), AstNode.Roles.Semicolon);
} else {
// parser error, set end node to max value.
@ -446,9 +445,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -446,9 +445,8 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && location.Count > 2) {
if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace);
// optional semicolon
if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Semicolon);
if (s.HasOptionalSemicolon)
newType.AddChild (new CSharpTokenNode (Convert (s.OptionalSemicolon), 1), AstNode.Roles.Semicolon);
} else {
// parser error, set end node to max value.
newType.AddChild (new ErrorNode (), AstNode.Roles.Error);
@ -497,9 +495,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -497,9 +495,8 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && location.Count > 2) {
if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace);
// optional semicolon
if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Semicolon);
if (i.HasOptionalSemicolon)
newType.AddChild (new CSharpTokenNode (Convert (i.OptionalSemicolon), 1), AstNode.Roles.Semicolon);
} else {
// parser error, set end node to max value.
newType.AddChild (new ErrorNode (), AstNode.Roles.Error);
@ -578,13 +575,19 @@ namespace ICSharpCode.NRefactory.CSharp @@ -578,13 +575,19 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.LBrace);
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 && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace);
// optional semicolon
if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Semicolon);
if (e.HasOptionalSemicolon)
newType.AddChild (new CSharpTokenNode (Convert (e.OptionalSemicolon), 1), AstNode.Roles.Semicolon);
} else {
// parser error, set end node to max value.
newType.AddChild (new ErrorNode (), AstNode.Roles.Error);
@ -1884,16 +1887,19 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1884,16 +1887,19 @@ namespace ICSharpCode.NRefactory.CSharp
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);
if (memberAccess.TypeArguments != null) {
var location = LocationsBag.GetLocations (memberAccess);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MemberReferenceExpression.Roles.LChevron);
AddTypeArguments (result, location, memberAccess.TypeArguments);
if (location != null && location.Count > 1)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MemberReferenceExpression.Roles.RChevron);
var locationTypeArgs = LocationsBag.GetLocations (memberAccess.TypeArguments);
if (locationTypeArgs != null)
result.AddChild (new CSharpTokenNode (Convert (locationTypeArgs[0]), 1), MemberReferenceExpression.Roles.LChevron);
AddTypeArguments (result, locationTypeArgs, memberAccess.TypeArguments);
if (locationTypeArgs != null && locationTypeArgs.Count > 1)
result.AddChild (new CSharpTokenNode (Convert (locationTypeArgs[1]), 1), MemberReferenceExpression.Roles.RChevron);
}
return result;
}

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

File diff suppressed because it is too large Load Diff

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

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

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

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

Loading…
Cancel
Save