Browse Source

Fixed colon / optional commas in type delcarations.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
9b28b2821d
  1. 76
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  2. 1361
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  3. 38
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay

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

@ -281,6 +281,15 @@ namespace ICSharpCode.NRefactory.CSharp
Identifier newIdent = Identifier.Create (memberName.Name, Convert (memberName.Location)); Identifier newIdent = Identifier.Create (memberName.Name, Convert (memberName.Location));
namespaceDecl.InsertChildBefore (insertPos, newIdent, NamespaceDeclaration.Roles.Identifier); namespaceDecl.InsertChildBefore (insertPos, newIdent, NamespaceDeclaration.Roles.Identifier);
insertPos = newIdent; insertPos = newIdent;
var location = LocationsBag.GetLocations (memberName);
if (location != null) {
var dotToken = new CSharpTokenNode (Convert (location[0]), 1);
namespaceDecl.InsertChildBefore (insertPos, dotToken, NamespaceDeclaration.Roles.Dot);
insertPos = dotToken;
}
memberName = memberName.Left; memberName = memberName.Left;
} }
} }
@ -349,8 +358,10 @@ namespace ICSharpCode.NRefactory.CSharp
var location = LocationsBag.GetMemberLocation (c); var location = LocationsBag.GetMemberLocation (c);
AddModifiers (newType, location); AddModifiers (newType, location);
int curLoc = 0;
if (location != null) if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location[0]), "class".Length), TypeDeclaration.Roles.Keyword); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), "class".Length), TypeDeclaration.Roles.Keyword);
newType.AddChild (Identifier.Create (c.MemberName.Name, Convert (c.MemberName.Location)), AstNode.Roles.Identifier); newType.AddChild (Identifier.Create (c.MemberName.Name, Convert (c.MemberName.Location)), AstNode.Roles.Identifier);
if (c.MemberName.TypeArguments != null) { if (c.MemberName.TypeArguments != null) {
var typeArgLocation = LocationsBag.GetLocations (c.MemberName); var typeArgLocation = LocationsBag.GetLocations (c.MemberName);
@ -362,16 +373,23 @@ namespace ICSharpCode.NRefactory.CSharp
AddConstraints (newType, c); AddConstraints (newType, c);
} }
if (c.TypeBaseExpressions != null) { if (c.TypeBaseExpressions != null) {
if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Colon);
foreach (var baseTypes in c.TypeBaseExpressions) { foreach (var baseTypes in c.TypeBaseExpressions) {
newType.AddChild (ConvertToType (baseTypes), TypeDeclaration.BaseTypeRole); newType.AddChild (ConvertToType (baseTypes), TypeDeclaration.BaseTypeRole);
} }
} }
if (location != null && location.Count > 1) if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AstNode.Roles.LBrace); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.LBrace);
typeStack.Push (newType); typeStack.Push (newType);
base.Visit (c); base.Visit (c);
if (location != null && location.Count > 2) { if (location != null && curLoc < location.Count) {
newType.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AstNode.Roles.RBrace); 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);
} 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);
@ -387,8 +405,9 @@ namespace ICSharpCode.NRefactory.CSharp
AddAttributeSection (newType, s); AddAttributeSection (newType, s);
var location = LocationsBag.GetMemberLocation (s); var location = LocationsBag.GetMemberLocation (s);
AddModifiers (newType, location); AddModifiers (newType, location);
int curLoc = 0;
if (location != null) if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location[0]), "struct".Length), TypeDeclaration.Roles.Keyword); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), "struct".Length), TypeDeclaration.Roles.Keyword);
newType.AddChild (Identifier.Create (s.MemberName.Name, Convert (s.MemberName.Location)), AstNode.Roles.Identifier); newType.AddChild (Identifier.Create (s.MemberName.Name, Convert (s.MemberName.Location)), AstNode.Roles.Identifier);
if (s.MemberName.TypeArguments != null) { if (s.MemberName.TypeArguments != null) {
var typeArgLocation = LocationsBag.GetLocations (s.MemberName); var typeArgLocation = LocationsBag.GetLocations (s.MemberName);
@ -401,17 +420,23 @@ namespace ICSharpCode.NRefactory.CSharp
} }
if (s.TypeBaseExpressions != null) { if (s.TypeBaseExpressions != null) {
if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Colon);
foreach (var baseTypes in s.TypeBaseExpressions) { foreach (var baseTypes in s.TypeBaseExpressions) {
newType.AddChild (ConvertToType (baseTypes), TypeDeclaration.BaseTypeRole); newType.AddChild (ConvertToType (baseTypes), TypeDeclaration.BaseTypeRole);
} }
} }
if (location != null && location.Count > 1) if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AstNode.Roles.LBrace); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.LBrace);
typeStack.Push (newType); typeStack.Push (newType);
base.Visit (s); base.Visit (s);
if (location != null && location.Count > 2) { if (location != null && location.Count > 2) {
newType.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AstNode.Roles.RBrace); 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);
} 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);
@ -427,8 +452,9 @@ namespace ICSharpCode.NRefactory.CSharp
AddAttributeSection (newType, i); AddAttributeSection (newType, i);
var location = LocationsBag.GetMemberLocation (i); var location = LocationsBag.GetMemberLocation (i);
AddModifiers (newType, location); AddModifiers (newType, location);
int curLoc = 0;
if (location != null) if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location[0]), "interface".Length), TypeDeclaration.Roles.Keyword); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), "interface".Length), TypeDeclaration.Roles.Keyword);
newType.AddChild (Identifier.Create (i.MemberName.Name, Convert (i.MemberName.Location)), AstNode.Roles.Identifier); newType.AddChild (Identifier.Create (i.MemberName.Name, Convert (i.MemberName.Location)), AstNode.Roles.Identifier);
if (i.MemberName.TypeArguments != null) { if (i.MemberName.TypeArguments != null) {
var typeArgLocation = LocationsBag.GetLocations (i.MemberName); var typeArgLocation = LocationsBag.GetLocations (i.MemberName);
@ -440,16 +466,22 @@ namespace ICSharpCode.NRefactory.CSharp
AddConstraints (newType, i); AddConstraints (newType, i);
} }
if (i.TypeBaseExpressions != null) { if (i.TypeBaseExpressions != null) {
if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Colon);
foreach (var baseTypes in i.TypeBaseExpressions) { foreach (var baseTypes in i.TypeBaseExpressions) {
newType.AddChild (ConvertToType (baseTypes), TypeDeclaration.BaseTypeRole); newType.AddChild (ConvertToType (baseTypes), TypeDeclaration.BaseTypeRole);
} }
} }
if (location != null && location.Count > 1) if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AstNode.Roles.LBrace); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.LBrace);
typeStack.Push (newType); typeStack.Push (newType);
base.Visit (i); base.Visit (i);
if (location != null && location.Count > 2) { if (location != null && location.Count > 2) {
newType.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AstNode.Roles.RBrace); 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);
} 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);
@ -514,19 +546,27 @@ namespace ICSharpCode.NRefactory.CSharp
var location = LocationsBag.GetMemberLocation (e); var location = LocationsBag.GetMemberLocation (e);
AddModifiers (newType, location); AddModifiers (newType, location);
int curLoc = 0;
if (location != null) if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location [0]), "enum".Length), TypeDeclaration.Roles.Keyword); newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++]), "enum".Length), TypeDeclaration.Roles.Keyword);
newType.AddChild (Identifier.Create (e.MemberName.Name, Convert (e.MemberName.Location)), AstNode.Roles.Identifier); newType.AddChild (Identifier.Create (e.MemberName.Name, Convert (e.MemberName.Location)), AstNode.Roles.Identifier);
if (e.BaseTypeExpression != null) if (e.BaseTypeExpression != null) {
if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Colon);
newType.AddChild (ConvertToType (e.BaseTypeExpression), TypeDeclaration.BaseTypeRole); newType.AddChild (ConvertToType (e.BaseTypeExpression), TypeDeclaration.BaseTypeRole);
}
if (location != null && location.Count > 1) if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AstNode.Roles.LBrace); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.LBrace);
typeStack.Push (newType); typeStack.Push (newType);
base.Visit (e); base.Visit (e);
if (location != null && location.Count > 2) { if (location != null && location.Count > 2) {
newType.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AstNode.Roles.RBrace); 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);
} 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);

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

File diff suppressed because it is too large Load Diff

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

@ -142,7 +142,7 @@ 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; Location parameterModifierLocation, savedLocation, savedOpenLocation, savedCloseLocation, savedEnumBaseTypeColonLocation;
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> ();
@ -564,6 +564,7 @@ qualified_identifier
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberName ((MemberName) $1, lt.Value, lt.Location); $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
lbag.AddLocation ($$, GetLocation ($2));
} }
| error | error
{ {
@ -932,6 +933,7 @@ struct_declaration
{ {
MemberName name = MakeName ((MemberName) $6); MemberName name = MakeName ((MemberName) $6);
push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3); push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
lbag.AddMember (current_class, GetModifierLocations (), GetLocation ($4));
} }
opt_class_base opt_class_base
opt_type_parameter_constraints_clauses opt_type_parameter_constraints_clauses
@ -943,7 +945,6 @@ struct_declaration
if (doc_support) if (doc_support)
current_container.DocComment = Lexer.consume_doc_comment (); current_container.DocComment = Lexer.consume_doc_comment ();
lbag.AddMember (current_class, GetModifierLocations (), GetLocation ($4));
} }
struct_body struct_body
{ {
@ -1973,7 +1974,11 @@ interface_declaration
} }
opt_semicolon opt_semicolon
{ {
lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13)); if ($15 != null) {
lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15));
} else {
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
@ -2580,8 +2585,19 @@ enum_declaration
// if (doc_support) // if (doc_support)
// em.DocComment = ev.DocComment; // em.DocComment = ev.DocComment;
if ($5 != null) {
lbag.AddMember (current_class, GetModifierLocations (), GetLocation ($3), GetLocation ($7), GetLocation ($11)); 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 ();
} }
; ;
@ -2595,6 +2611,7 @@ opt_enum_base
Enum.Error_1008 (GetLocation ($2), report); Enum.Error_1008 (GetLocation ($2), report);
$$ = null; $$ = null;
} else { } else {
savedEnumBaseTypeColonLocation = GetLocation ($1);
$$ = $2; $$ = $2;
} }
} }
@ -4322,7 +4339,8 @@ class_declaration
if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) { if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
FeatureIsNotAvailable (c.Location, "static classes"); FeatureIsNotAvailable (c.Location, "static classes");
} }
lbag.AddMember (current_class, GetModifierLocations (), GetLocation ($4));
push_current_class (c, $3); push_current_class (c, $3);
} }
opt_class_base opt_class_base
@ -4331,7 +4349,6 @@ class_declaration
lexer.ConstraintsParsing = false; lexer.ConstraintsParsing = false;
current_class.SetParameterInfo ((List<Constraints>) $9); current_class.SetParameterInfo ((List<Constraints>) $9);
lbag.AddMember (current_class, GetModifierLocations (), GetLocation ($4));
if (doc_support) { if (doc_support) {
current_container.DocComment = Lexer.consume_doc_comment (); current_container.DocComment = Lexer.consume_doc_comment ();
@ -4346,7 +4363,11 @@ class_declaration
} }
opt_semicolon opt_semicolon
{ {
lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15)); if ($15 != null) {
lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15));
} else {
lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13));
}
$$ = pop_current_class (); $$ = pop_current_class ();
} }
; ;
@ -4474,6 +4495,7 @@ opt_class_base
: /* empty */ : /* empty */
| COLON type_list | COLON type_list
{ {
lbag.AppendToMember (current_class, GetLocation ($1));
current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2); current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2);
} }
; ;

Loading…
Cancel
Save