Browse Source

Fixed object create expression tests /remove named expression lists

(was an obsolete node).
I tried out the node, but choosed to go with namedexpression +
arrayinitializerexpression because it's semantically the same.
newNRvisualizers
Mike Krüger 14 years ago
parent
commit
3e99fabb2e
  1. 48
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ObjectCreateExpressionTests.cs
  2. 5
      ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs
  3. 91
      ICSharpCode.NRefactory/CSharp/Ast/Expressions/NamedExpressionList.cs
  4. 1
      ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs
  5. 10
      ICSharpCode.NRefactory/CSharp/Ast/ObservableAstVisitor.cs
  6. 11
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
  7. 41
      ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs
  8. 1
      ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-parser.cs
  9. 1
      ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-parser.jay
  10. 1
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

48
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ObjectCreateExpressionTests.cs

@ -58,8 +58,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -58,8 +58,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Type = new SimpleType("Point"),
Initializer = new ArrayInitializerExpression {
Elements = {
new AssignmentExpression("X", new PrimitiveExpression(0)),
new AssignmentExpression("Y", new PrimitiveExpression(1))
new NamedExpression("X", new PrimitiveExpression(0)),
new NamedExpression("Y", new PrimitiveExpression(1))
}
}});
}
@ -73,8 +73,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -73,8 +73,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Type = new SimpleType("Point"),
Initializer = new ArrayInitializerExpression {
Elements = {
new AssignmentExpression("X", new PrimitiveExpression(0)),
new AssignmentExpression("Y", new PrimitiveExpression(1))
new NamedExpression("X", new PrimitiveExpression(0)),
new NamedExpression("Y", new PrimitiveExpression(1))
}
}});
}
@ -88,8 +88,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -88,8 +88,8 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Type = new SimpleType("Point"),
Initializer = new ArrayInitializerExpression {
Elements = {
new AssignmentExpression("X", new PrimitiveExpression(0)),
new AssignmentExpression("Y", new PrimitiveExpression(1))
new NamedExpression("X", new PrimitiveExpression(0)),
new NamedExpression("Y", new PrimitiveExpression(1))
}
}});
}
@ -103,24 +103,24 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -103,24 +103,24 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Type = new SimpleType("Rectangle"),
Initializer = new ArrayInitializerExpression {
Elements = {
new AssignmentExpression(
new NamedExpression(
"P1",
new ObjectCreateExpression {
Type = new SimpleType("Point"),
Initializer = new ArrayInitializerExpression {
Elements = {
new AssignmentExpression("X", new PrimitiveExpression(0)),
new AssignmentExpression("Y", new PrimitiveExpression(1))
new NamedExpression("X", new PrimitiveExpression(0)),
new NamedExpression("Y", new PrimitiveExpression(1))
}
}}),
new AssignmentExpression(
new NamedExpression(
"P2",
new ObjectCreateExpression {
Type = new SimpleType("Point"),
Initializer = new ArrayInitializerExpression {
Elements = {
new AssignmentExpression("X", new PrimitiveExpression(2)),
new AssignmentExpression("Y", new PrimitiveExpression(3))
new NamedExpression("X", new PrimitiveExpression(2)),
new NamedExpression("Y", new PrimitiveExpression(3))
}
}})
}}});
@ -135,20 +135,20 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -135,20 +135,20 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Type = new SimpleType("Rectangle"),
Initializer = new ArrayInitializerExpression {
Elements = {
new AssignmentExpression(
new NamedExpression(
"P1",
new ArrayInitializerExpression {
Elements = {
new AssignmentExpression("X", new PrimitiveExpression(0)),
new AssignmentExpression("Y", new PrimitiveExpression(1))
new NamedExpression("X", new PrimitiveExpression(0)),
new NamedExpression("Y", new PrimitiveExpression(1))
}
}),
new AssignmentExpression(
new NamedExpression(
"P2",
new ArrayInitializerExpression {
Elements = {
new AssignmentExpression("X", new PrimitiveExpression(2)),
new AssignmentExpression("Y", new PrimitiveExpression(3))
new NamedExpression("X", new PrimitiveExpression(2)),
new NamedExpression("Y", new PrimitiveExpression(3))
}
})
}}});
@ -211,9 +211,9 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -211,9 +211,9 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Initializer = new ArrayInitializerExpression {
Elements = {
new NamedExpression("Name", new PrimitiveExpression("Chris")),
new NamedExpressionList("PhoneNumbers") {
Expressions = { new PrimitiveExpression("206-555-0101") }
}
new NamedExpression("PhoneNumbers", new ArrayInitializerExpression () {
Elements = { new PrimitiveExpression("206-555-0101") }
})
}}},
new ObjectCreateExpression {
Type = new SimpleType("Contact"),
@ -221,12 +221,12 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -221,12 +221,12 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Initializer = new ArrayInitializerExpression {
Elements = {
new NamedExpression("Name", new PrimitiveExpression("Bob")),
new NamedExpressionList("PhoneNumbers") {
Expressions = {
new NamedExpression("PhoneNumbers", new ArrayInitializerExpression () {
Elements = {
new PrimitiveExpression("650-555-0199"),
new PrimitiveExpression("425-882-8080")
}
}
})
}}}
}}});
}

5
ICSharpCode.NRefactory/CSharp/Ast/DepthFirstAstVisitor.cs

@ -590,11 +590,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -590,11 +590,6 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (namedExpression, data);
}
public virtual S VisitNamedExpressionList (NamedExpressionList namedExpressionList, T data)
{
return VisitChildren (namedExpressionList, data);
}
public virtual S VisitEmptyExpression (EmptyExpression emptyExpression, T data)
{
return VisitChildren (emptyExpression, data);

91
ICSharpCode.NRefactory/CSharp/Ast/Expressions/NamedExpressionList.cs

@ -1,91 +0,0 @@ @@ -1,91 +0,0 @@
//
// NamedExpressionList.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2011 Xamarin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Collections.Generic;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// name = { expression1, ... , expressionN }
/// </summary>
public class NamedExpressionList : Expression
{
public NamedExpressionList()
{
}
public NamedExpressionList (string identifier)
{
this.Identifier = identifier;
}
public string Identifier {
get {
return GetChildByRole (Roles.Identifier).Name;
}
set {
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value, AstLocation.Empty));
}
}
public Identifier IdentifierToken {
get {
return GetChildByRole (Roles.Identifier);
}
set {
SetChildByRole(Roles.Identifier, value);
}
}
public CSharpTokenNode AssignToken {
get { return GetChildByRole (Roles.Assign); }
}
public CSharpTokenNode LBraceToken {
get { return GetChildByRole (Roles.LBrace); }
}
public AstNodeCollection<Expression> Expressions {
get { return GetChildrenByRole (Roles.Expression); }
}
public CSharpTokenNode RBraceToken {
get { return GetChildByRole (Roles.RBrace); }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitNamedExpressionList(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
var o = other as NamedExpressionList;
return o != null && MatchString(this.Identifier, o.Identifier) && this.Expressions.DoMatch(o.Expressions, match);
}
}
}

1
ICSharpCode.NRefactory/CSharp/Ast/IAstVisitor.cs

@ -46,7 +46,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -46,7 +46,6 @@ namespace ICSharpCode.NRefactory.CSharp
S VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, T data);
S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data);
S VisitNamedExpression(NamedExpression namedExpression, T data);
S VisitNamedExpressionList(NamedExpressionList namedExpressionList, T data);
S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, T data);
S VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, T data);
S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, T data);

10
ICSharpCode.NRefactory/CSharp/Ast/ObservableAstVisitor.cs

@ -1131,16 +1131,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1131,16 +1131,6 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren (namedExpression, data);
}
public event Action<NamedExpressionList, T> NamedExpressionListVisited;
S IAstVisitor<T, S>.VisitNamedExpressionList (NamedExpressionList namedExpressionList, T data)
{
var handler = NamedExpressionListVisited;
if (handler != null)
handler (namedExpressionList, data);
return VisitChildren (namedExpressionList, data);
}
public event Action<EmptyExpression, T> EmptyExpressionVisited;
S IAstVisitor<T, S>.VisitEmptyExpression (EmptyExpression emptyExpression, T data)

11
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -841,17 +841,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -841,17 +841,6 @@ namespace ICSharpCode.NRefactory.CSharp
return EndNode (namedExpression);
}
public object VisitNamedExpressionList (NamedExpressionList namedExpressionList, object data)
{
StartNode (namedExpressionList);
WriteIdentifier (namedExpressionList.Identifier);
Space();
WriteToken("=", NamedArgumentExpression.Roles.Assign);
Space ();
PrintInitializerElements(namedExpressionList.Expressions);
return EndNode (namedExpressionList);
}
public object VisitNullReferenceExpression (NullReferenceExpression nullReferenceExpression, object data)
{
StartNode (nullReferenceExpression);

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

@ -2333,11 +2333,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2333,11 +2333,16 @@ namespace ICSharpCode.NRefactory.CSharp
if (minit == null)
return null;
var init = new ArrayInitializerExpression ();
var braceLocs = LocationsBag.GetLocations (minit);
if (braceLocs != null)
init.AddChild (new CSharpTokenNode (Convert (braceLocs[0]), 1), ArrayInitializerExpression.Roles.LBrace);
AddConvertCollectionOrObjectInitializers (init, minit);
if (braceLocs != null)
init.AddChild (new CSharpTokenNode (Convert (braceLocs[1]), 1), ArrayInitializerExpression.Roles.RBrace);
return init;
}
void AddConvertCollectionOrObjectInitializers (AstNode init, CollectionOrObjectInitializers minit)
void AddConvertCollectionOrObjectInitializers (Expression init, CollectionOrObjectInitializers minit)
{
var initLoc = LocationsBag.GetLocations (minit);
var commaLoc = LocationsBag.GetLocations (minit.Initializers);
@ -2345,27 +2350,43 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2345,27 +2350,43 @@ namespace ICSharpCode.NRefactory.CSharp
foreach (var expr in minit.Initializers) {
var collectionInit = expr as CollectionElementInitializer;
if (collectionInit != null) {
for (int i = 0; i < collectionInit.Arguments.Count; i++) {
var arg = collectionInit.Arguments[i] as CollectionElementInitializer.ElementInitializerArgument;
if (arg == null)
continue;
init.AddChild ((ICSharpCode.NRefactory.CSharp.Expression)arg.Expr.Accept (this), ArrayInitializerExpression.Roles.Expression);
if (curComma >= 0)
init.AddChild (new CSharpTokenNode (Convert (commaLoc[curComma--]), 1), ArrayInitializerExpression.Roles.Comma);
if (collectionInit.Arguments.Count != 1) {
var parent = new ArrayInitializerExpression ();
var braceLocs = LocationsBag.GetLocations (expr);
if (braceLocs != null)
parent.AddChild (new CSharpTokenNode (Convert (braceLocs[0]), 1), ArrayInitializerExpression.Roles.LBrace);
for (int i = 0; i < collectionInit.Arguments.Count; i++) {
var arg = collectionInit.Arguments[i] as CollectionElementInitializer.ElementInitializerArgument;
if (arg == null)
continue;
parent.AddChild ((ICSharpCode.NRefactory.CSharp.Expression)arg.Expr.Accept (this), ArrayInitializerExpression.Roles.Expression);
if (curComma >= 0)
parent.AddChild (new CSharpTokenNode (Convert (commaLoc[curComma--]), 1), ArrayInitializerExpression.Roles.Comma);
}
if (braceLocs != null)
parent.AddChild (new CSharpTokenNode (Convert (braceLocs[1]), 1), ArrayInitializerExpression.Roles.RBrace);
init.AddChild (parent, ArrayInitializerExpression.Roles.Expression);
} else {
var arg = collectionInit.Arguments[0] as CollectionElementInitializer.ElementInitializerArgument;
if (arg != null)
init.AddChild ((ICSharpCode.NRefactory.CSharp.Expression)arg.Expr.Accept (this), ArrayInitializerExpression.Roles.Expression);
}
continue;
}
var eleInit = expr as ElementInitializer;
if (eleInit != null) {
var nexpr = eleInit.Source is CollectionOrObjectInitializers ? (ICSharpCode.NRefactory.CSharp.Expression)new NamedExpressionList () : new NamedExpression ();
var nexpr = new NamedExpression ();
nexpr.AddChild (Identifier.Create (eleInit.Name, Convert(eleInit.Location)), NamedArgumentExpression.Roles.Identifier);
var assignLoc = LocationsBag.GetLocations (eleInit);
if (assignLoc != null)
nexpr.AddChild (new CSharpTokenNode (Convert (assignLoc[0]), 1), NamedArgumentExpression.Roles.Assign);
if (eleInit.Source != null) {
if (eleInit.Source is CollectionOrObjectInitializers) {
AddConvertCollectionOrObjectInitializers (nexpr, eleInit.Source as CollectionOrObjectInitializers);
var arrInit = new ArrayInitializerExpression ();
AddConvertCollectionOrObjectInitializers (arrInit, eleInit.Source as CollectionOrObjectInitializers);
nexpr.AddChild (arrInit, NamedArgumentExpression.Roles.Expression);
} else {
nexpr.AddChild ((Expression)eleInit.Source.Accept (this), NamedArgumentExpression.Roles.Expression);
}

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

@ -5851,7 +5851,6 @@ void case_350() @@ -5851,7 +5851,6 @@ void case_350()
{
TypeArguments type_args = (TypeArguments) yyVals[-2+yyTop];
type_args.Add ((FullNamedExpression) yyVals[0+yyTop]);
lbag.AppendTo (type_args, GetLocation (yyVals[-1+yyTop]));
yyVal = type_args;
locationListStack.Peek ().Add (GetLocation (yyVals[-1+yyTop]));
}

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

@ -2763,7 +2763,6 @@ type_arguments @@ -2763,7 +2763,6 @@ type_arguments
{
TypeArguments type_args = (TypeArguments) $1;
type_args.Add ((FullNamedExpression) $3);
lbag.AppendTo (type_args, GetLocation ($2));
$$ = type_args;
locationListStack.Peek ().Add (GetLocation ($2));
}

1
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -410,7 +410,6 @@ @@ -410,7 +410,6 @@
<Compile Include="TypeSystem\IAnnotatable.cs" />
<Compile Include="CSharp\Ast\ErrorNode.cs" />
<Compile Include="CSharp\Ast\Expressions\NamedExpression.cs" />
<Compile Include="CSharp\Ast\Expressions\NamedExpressionList.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="CSharp\" />

Loading…
Cancel
Save