From c671230693619ee7607ace5a40e4c44ca0a9590b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Sun, 4 Sep 2011 12:02:47 +0200 Subject: [PATCH] Fixed type argument commas. --- .../Parser/CSharpParser.cs | 46 ++++--------------- .../Parser/mcs/cs-parser.cs | 4 +- .../Parser/mcs/cs-parser.jay | 4 +- 3 files changed, 14 insertions(+), 40 deletions(-) diff --git a/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs b/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs index d84eaf2747..226b9d039e 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs +++ b/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 (Identifier.Create (memberName.Name, Convert(memberName.Location)), MemberType.Roles.Identifier); - AddTypeArguments (t, (List)null, memberName.TypeArguments); + AddTypeArguments (t, memberName.TypeArguments); return t; } else { SimpleType t = new SimpleType(); t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), SimpleType.Roles.Identifier); - AddTypeArguments (t, (List)null, memberName.TypeArguments); + AddTypeArguments (t, memberName.TypeArguments); return t; } } @@ -1888,12 +1888,7 @@ namespace ICSharpCode.NRefactory.CSharp result.AddChild (Identifier.Create (memberAccess.Name, Convert (memberAccess.Location)), MemberReferenceExpression.Roles.Identifier); if (memberAccess.TypeArguments != null) { - 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); + AddTypeArguments (result, memberAccess.TypeArguments); } return result; } @@ -1930,12 +1925,7 @@ namespace ICSharpCode.NRefactory.CSharp var result = new IdentifierExpression (); result.AddChild (Identifier.Create (simpleName.Name, Convert (simpleName.Location)), IdentifierExpression.Roles.Identifier); if (simpleName.TypeArguments != null) { - var location = LocationsBag.GetLocations (simpleName); - 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); + AddTypeArguments (result, simpleName.TypeArguments); } return result; } @@ -2254,6 +2244,9 @@ namespace ICSharpCode.NRefactory.CSharp if (typeArguments == null || typeArguments.IsEmpty) return; var chevronLocs = LocationsBag.GetLocations (typeArguments); + if (chevronLocs != null) + foreach (var loc in chevronLocs) + Console.WriteLine (loc); if (chevronLocs != null) parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron); 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); } - void AddTypeArguments (AstNode parent, LocationsBag.MemberLocations location, Mono.CSharp.TypeArguments typeArguments) + void AddTypeArguments (AstNode parent, Mono.CSharp.TypeArguments typeArguments) { if (typeArguments == null || typeArguments.IsEmpty) return; @@ -2290,37 +2283,18 @@ namespace ICSharpCode.NRefactory.CSharp parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 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 && i < chevronLocs.Count - 2) + parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[i]), 1), InvocationExpression.Roles.Comma); } if (chevronLocs != null) parent.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 1]), 1), InvocationExpression.Roles.RChevron); } - void AddTypeArguments (AstNode parent, List 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) { if (d == null || d.Constraints == null) diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs index 7e0b431833..96e10d370c 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs @@ -5953,7 +5953,7 @@ void case_362() FeatureIsNotAvailable (GetLocation (yyVals[-2+yyTop]), "generics"); 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() @@ -5970,7 +5970,7 @@ void case_364() TypeArguments type_args = (TypeArguments) yyVals[-2+yyTop]; type_args.Add ((FullNamedExpression)yyVals[0+yyTop]); yyVal = type_args; - lbag.AddLocation (yyVals[0+yyTop], GetLocation (yyVals[0+yyTop])); + lbag.AppendTo (type_args, GetLocation (yyVals[-1+yyTop])); } void case_365() diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay b/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay index 5191cab54d..7ddebcb629 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay @@ -2880,7 +2880,7 @@ opt_type_parameter_list FeatureIsNotAvailable (GetLocation ($1), "generics"); $$ = $2; - lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3)); + lbag.AppendTo ($$, GetLocation ($1), GetLocation ($3)); } ; @@ -2896,7 +2896,7 @@ type_parameters TypeArguments type_args = (TypeArguments) $1; type_args.Add ((FullNamedExpression)$3); $$ = type_args; - lbag.AddLocation ($3, GetLocation ($3)); + lbag.AppendTo (type_args, GetLocation ($2)); } ;