Browse Source

Fixed type argument commas.

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

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

@ -342,12 +342,12 @@ namespace ICSharpCode.NRefactory.CSharp
t.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MemberType.Roles.Dot); t.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MemberType.Roles.Dot);
t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), MemberType.Roles.Identifier); t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), MemberType.Roles.Identifier);
AddTypeArguments (t, (List<Location>)null, memberName.TypeArguments); AddTypeArguments (t, memberName.TypeArguments);
return t; return t;
} else { } else {
SimpleType t = new SimpleType(); SimpleType t = new SimpleType();
t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), SimpleType.Roles.Identifier); t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), SimpleType.Roles.Identifier);
AddTypeArguments (t, (List<Location>)null, memberName.TypeArguments); AddTypeArguments (t, memberName.TypeArguments);
return t; return t;
} }
} }
@ -1888,12 +1888,7 @@ namespace ICSharpCode.NRefactory.CSharp
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 locationTypeArgs = LocationsBag.GetLocations (memberAccess.TypeArguments); AddTypeArguments (result, 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; return result;
} }
@ -1930,12 +1925,7 @@ namespace ICSharpCode.NRefactory.CSharp
var result = new IdentifierExpression (); var result = new IdentifierExpression ();
result.AddChild (Identifier.Create (simpleName.Name, Convert (simpleName.Location)), IdentifierExpression.Roles.Identifier); result.AddChild (Identifier.Create (simpleName.Name, Convert (simpleName.Location)), IdentifierExpression.Roles.Identifier);
if (simpleName.TypeArguments != null) { if (simpleName.TypeArguments != null) {
var location = LocationsBag.GetLocations (simpleName); AddTypeArguments (result, simpleName.TypeArguments);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IdentifierExpression.Roles.LChevron);
AddTypeArguments (result, location, simpleName.TypeArguments);
if (location != null && location.Count > 1)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), IdentifierExpression.Roles.RChevron);
} }
return result; return result;
} }
@ -2254,6 +2244,9 @@ namespace ICSharpCode.NRefactory.CSharp
if (typeArguments == null || typeArguments.IsEmpty) if (typeArguments == null || typeArguments.IsEmpty)
return; return;
var chevronLocs = LocationsBag.GetLocations (typeArguments); var chevronLocs = LocationsBag.GetLocations (typeArguments);
if (chevronLocs != null)
foreach (var loc in chevronLocs)
Console.WriteLine (loc);
if (chevronLocs != null) if (chevronLocs != null)
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron); parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron);
for (int i = 0; i < typeArguments.Count; i++) { for (int i = 0; i < typeArguments.Count; i++) {
@ -2281,7 +2274,7 @@ namespace ICSharpCode.NRefactory.CSharp
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 1]), 1), InvocationExpression.Roles.RChevron); parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 1]), 1), InvocationExpression.Roles.RChevron);
} }
void AddTypeArguments (AstNode parent, LocationsBag.MemberLocations location, Mono.CSharp.TypeArguments typeArguments) void AddTypeArguments (AstNode parent, Mono.CSharp.TypeArguments typeArguments)
{ {
if (typeArguments == null || typeArguments.IsEmpty) if (typeArguments == null || typeArguments.IsEmpty)
return; return;
@ -2290,37 +2283,18 @@ namespace ICSharpCode.NRefactory.CSharp
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron); parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron);
for (int i = 0; i < typeArguments.Count; i++) { for (int i = 0; i < typeArguments.Count; i++) {
if (location != null && i > 0 && i - 1 < location.Count)
parent.AddChild (new CSharpTokenNode (Convert (location[i - 1]), 1), InvocationExpression.Roles.Comma);
var arg = typeArguments.Args[i]; var arg = typeArguments.Args[i];
if (arg == null) if (arg == null)
continue; continue;
parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument); parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument);
if (chevronLocs != null && i < chevronLocs.Count - 2)
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[i]), 1), InvocationExpression.Roles.Comma);
} }
if (chevronLocs != null) if (chevronLocs != null)
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 1]), 1), InvocationExpression.Roles.RChevron); parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 1]), 1), InvocationExpression.Roles.RChevron);
} }
void AddTypeArguments (AstNode parent, List<Location> location, Mono.CSharp.TypeArguments typeArguments)
{
if (typeArguments == null || typeArguments.IsEmpty)
return;
var chevronLocs = LocationsBag.GetLocations (typeArguments);
if (chevronLocs != null)
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[0]), 1), InvocationExpression.Roles.LChevron);
for (int i = 0; i < typeArguments.Count; i++) {
if (location != null && i > 0 && i - 1 < location.Count)
parent.AddChild (new CSharpTokenNode (Convert (location[i - 1]), 1), InvocationExpression.Roles.Comma);
var arg = typeArguments.Args[i];
if (arg == null)
continue;
parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument);
}
if (chevronLocs != null)
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[1]), 1), InvocationExpression.Roles.RChevron);
}
void AddConstraints (AstNode parent, DeclSpace d) void AddConstraints (AstNode parent, DeclSpace d)
{ {
if (d == null || d.Constraints == null) if (d == null || d.Constraints == null)

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

@ -5953,7 +5953,7 @@ void case_362()
FeatureIsNotAvailable (GetLocation (yyVals[-2+yyTop]), "generics"); FeatureIsNotAvailable (GetLocation (yyVals[-2+yyTop]), "generics");
yyVal = yyVals[-1+yyTop]; yyVal = yyVals[-1+yyTop];
lbag.AddLocation (yyVal, GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop])); lbag.AppendTo (yyVal, GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop]));
} }
void case_363() void case_363()
@ -5970,7 +5970,7 @@ void case_364()
TypeArguments type_args = (TypeArguments) yyVals[-2+yyTop]; TypeArguments type_args = (TypeArguments) yyVals[-2+yyTop];
type_args.Add ((FullNamedExpression)yyVals[0+yyTop]); type_args.Add ((FullNamedExpression)yyVals[0+yyTop]);
yyVal = type_args; yyVal = type_args;
lbag.AddLocation (yyVals[0+yyTop], GetLocation (yyVals[0+yyTop])); lbag.AppendTo (type_args, GetLocation (yyVals[-1+yyTop]));
} }
void case_365() void case_365()

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

@ -2880,7 +2880,7 @@ opt_type_parameter_list
FeatureIsNotAvailable (GetLocation ($1), "generics"); FeatureIsNotAvailable (GetLocation ($1), "generics");
$$ = $2; $$ = $2;
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3)); lbag.AppendTo ($$, GetLocation ($1), GetLocation ($3));
} }
; ;
@ -2896,7 +2896,7 @@ type_parameters
TypeArguments type_args = (TypeArguments) $1; TypeArguments type_args = (TypeArguments) $1;
type_args.Add ((FullNamedExpression)$3); type_args.Add ((FullNamedExpression)$3);
$$ = type_args; $$ = type_args;
lbag.AddLocation ($3, GetLocation ($3)); lbag.AppendTo (type_args, GetLocation ($2));
} }
; ;

Loading…
Cancel
Save