Browse Source

Worked on type parsing.

newNRvisualizers
Mike Krüger 15 years ago
parent
commit
59da5a28db
  1. 6
      ICSharpCode.NRefactory/CSharp/Ast/PrimitiveType.cs
  2. 5
      ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs
  3. 126
      ICSharpCode.NRefactory/CSharp/Parser/CSharpParser.cs

6
ICSharpCode.NRefactory/CSharp/Ast/PrimitiveType.cs

@ -43,6 +43,12 @@ namespace ICSharpCode.NRefactory.CSharp
this.Keyword = keyword; this.Keyword = keyword;
} }
public PrimitiveType(string keyword, AstLocation location)
{
this.Keyword = keyword;
this.Location = location;
}
public override AstLocation StartLocation { public override AstLocation StartLocation {
get { get {
return Location; return Location;

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

@ -42,6 +42,11 @@ namespace ICSharpCode.NRefactory.CSharp
this.Identifier = identifier; this.Identifier = identifier;
} }
public SimpleType(string identifier, AstLocation location)
{
SetChildByRole (Roles.Identifier, new Identifier(identifier, location));
}
public string Identifier { public string Identifier {
get { get {
return GetChildByRole (Roles.Identifier).Name; return GetChildByRole (Roles.Identifier).Name;

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

@ -67,6 +67,68 @@ namespace ICSharpCode.NRefactory.CSharp
#region Global #region Global
Stack<NamespaceDeclaration> namespaceStack = new Stack<NamespaceDeclaration> (); Stack<NamespaceDeclaration> namespaceStack = new Stack<NamespaceDeclaration> ();
void AddTypeArguments (ATypeNameExpression texpr, AstType result)
{
if (!texpr.HasTypeArguments)
return;
foreach (var arg in texpr.TypeArguments.Args) {
result.AddChild (ConvertToType (arg), AstType.Roles.TypeArgument);
}
}
AstType ConvertToType (Mono.CSharp.Expression typeName)
{
if (typeName is TypeExpression) {
var typeExpr = (Mono.CSharp.TypeExpression)typeName;
return new PrimitiveType (typeExpr.GetSignatureForError (), Convert (typeExpr.Location));
}
if (typeName is Mono.CSharp.QualifiedAliasMember) {
var qam = (Mono.CSharp.QualifiedAliasMember)typeName;
return new SimpleType (qam.Name, Convert (qam.Location));
}
if (typeName is MemberAccess) {
MemberAccess ma = (MemberAccess)typeName;
var memberType = new MemberType ();
memberType.AddChild (ConvertToType (ma.LeftExpression), MemberType.TargetRole);
memberType.MemberName = ma.Name;
AddTypeArguments (ma, memberType);
return memberType;
}
if (typeName is SimpleName) {
var sn = (SimpleName)typeName;
var result = new SimpleType (sn.Name, Convert (sn.Location));
AddTypeArguments (sn, result);
return result;
}
if (typeName is ComposedCast) {
var cc = (ComposedCast)typeName;
var baseType = ConvertToType (cc.Left);
var result = new ComposedType () { BaseType = baseType };
if (cc.Spec.IsNullable) {
result.HasNullableSpecifier = true;
} else if (cc.Spec.IsPointer) {
result.PointerRank++;
} else {
result.ArraySpecifiers = new ArraySpecifier[] {
new ArraySpecifier () {
Dimensions = cc.Spec.Dimension - 1
}
};
}
return result;
}
System.Console.WriteLine ("Error while converting :" + typeName + " - unknown type name");
return new SimpleType ("unknown");
}
public override void Visit (UsingsBag.Namespace nspace) public override void Visit (UsingsBag.Namespace nspace)
{ {
NamespaceDeclaration nDecl = null; NamespaceDeclaration nDecl = null;
@ -242,7 +304,7 @@ namespace ICSharpCode.NRefactory.CSharp
AddModifiers (newDelegate, location); AddModifiers (newDelegate, location);
if (location != null) if (location != null)
newDelegate.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), TypeDeclaration.Roles.Keyword); newDelegate.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), TypeDeclaration.Roles.Keyword);
newDelegate.AddChild ((AstType)d.ReturnType.Accept (this), AstNode.Roles.Type); newDelegate.AddChild (ConvertToType (d.ReturnType), AstNode.Roles.Type);
newDelegate.AddChild (new Identifier (d.Name, Convert (d.MemberName.Location)), AstNode.Roles.Identifier); newDelegate.AddChild (new Identifier (d.Name, Convert (d.MemberName.Location)), AstNode.Roles.Identifier);
if (d.MemberName.TypeArguments != null) { if (d.MemberName.TypeArguments != null) {
var typeArgLocation = LocationsBag.GetLocations (d.MemberName); var typeArgLocation = LocationsBag.GetLocations (d.MemberName);
@ -347,7 +409,7 @@ namespace ICSharpCode.NRefactory.CSharp
AddModifiers (newField, location); AddModifiers (newField, location);
if (location != null) if (location != null)
newField.AddChild (new CSharpTokenNode (Convert (location[0]), "fixed".Length), FieldDeclaration.Roles.Keyword); newField.AddChild (new CSharpTokenNode (Convert (location[0]), "fixed".Length), FieldDeclaration.Roles.Keyword);
newField.AddChild ((AstType)f.TypeName.Accept (this), FieldDeclaration.Roles.Type); newField.AddChild (ConvertToType (f.TypeName), FieldDeclaration.Roles.Type);
VariableInitializer variable = new VariableInitializer (); VariableInitializer variable = new VariableInitializer ();
variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), FieldDeclaration.Roles.Identifier); variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), FieldDeclaration.Roles.Identifier);
@ -379,7 +441,7 @@ namespace ICSharpCode.NRefactory.CSharp
FieldDeclaration newField = new FieldDeclaration (); FieldDeclaration newField = new FieldDeclaration ();
AddModifiers (newField, location); AddModifiers (newField, location);
newField.AddChild ((AstType)f.TypeName.Accept (this), FieldDeclaration.Roles.Type); newField.AddChild (ConvertToType (f.TypeName), FieldDeclaration.Roles.Type);
VariableInitializer variable = new VariableInitializer (); VariableInitializer variable = new VariableInitializer ();
variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), FieldDeclaration.Roles.Identifier); variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), FieldDeclaration.Roles.Identifier);
@ -420,7 +482,7 @@ namespace ICSharpCode.NRefactory.CSharp
AddModifiers (newField, location); AddModifiers (newField, location);
if (location != null) if (location != null)
newField.AddChild (new CSharpTokenNode (Convert (location[0]), "const".Length), FieldDeclaration.Roles.Keyword); newField.AddChild (new CSharpTokenNode (Convert (location[0]), "const".Length), FieldDeclaration.Roles.Keyword);
newField.AddChild ((AstType)f.TypeName.Accept (this), FieldDeclaration.Roles.Type); newField.AddChild (ConvertToType (f.TypeName), FieldDeclaration.Roles.Type);
VariableInitializer variable = new VariableInitializer (); VariableInitializer variable = new VariableInitializer ();
variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), VariableInitializer.Roles.Identifier); variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), VariableInitializer.Roles.Identifier);
@ -462,7 +524,7 @@ namespace ICSharpCode.NRefactory.CSharp
AddModifiers (newOperator, location); AddModifiers (newOperator, location);
newOperator.AddChild ((AstType)o.TypeName.Accept (this), AstNode.Roles.Type); newOperator.AddChild (ConvertToType (o.TypeName), AstNode.Roles.Type);
if (o.OperatorType == Operator.OpType.Implicit) { if (o.OperatorType == Operator.OpType.Implicit) {
if (location != null) { if (location != null) {
@ -519,7 +581,7 @@ namespace ICSharpCode.NRefactory.CSharp
var location = LocationsBag.GetMemberLocation (indexer); var location = LocationsBag.GetMemberLocation (indexer);
AddModifiers (newIndexer, location); AddModifiers (newIndexer, location);
newIndexer.AddChild ((AstType)indexer.TypeName.Accept (this), AstNode.Roles.Type); newIndexer.AddChild (ConvertToType (indexer.TypeName), AstNode.Roles.Type);
if (location != null) if (location != null)
newIndexer.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IndexerDeclaration.Roles.LBracket); newIndexer.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IndexerDeclaration.Roles.LBracket);
@ -573,7 +635,7 @@ namespace ICSharpCode.NRefactory.CSharp
var location = LocationsBag.GetMemberLocation (m); var location = LocationsBag.GetMemberLocation (m);
AddModifiers (newMethod, location); AddModifiers (newMethod, location);
newMethod.AddChild ((AstType)m.TypeName.Accept (this), AstNode.Roles.Type); newMethod.AddChild (ConvertToType (m.TypeName), AstNode.Roles.Type);
newMethod.AddChild (new Identifier (m.Name, Convert (m.Location)), AstNode.Roles.Identifier); newMethod.AddChild (new Identifier (m.Name, Convert (m.Location)), AstNode.Roles.Identifier);
if (m.MemberName.TypeArguments != null) { if (m.MemberName.TypeArguments != null) {
@ -641,7 +703,7 @@ namespace ICSharpCode.NRefactory.CSharp
var location = LocationsBag.GetMemberLocation (p); var location = LocationsBag.GetMemberLocation (p);
AddModifiers (newProperty, location); AddModifiers (newProperty, location);
newProperty.AddChild ((AstType)p.TypeName.Accept (this), AstNode.Roles.Type); newProperty.AddChild (ConvertToType (p.TypeName), AstNode.Roles.Type);
newProperty.AddChild (new Identifier (p.MemberName.Name, Convert (p.MemberName.Location)), AstNode.Roles.Identifier); newProperty.AddChild (new Identifier (p.MemberName.Name, Convert (p.MemberName.Location)), AstNode.Roles.Identifier);
if (location != null) if (location != null)
newProperty.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LBrace); newProperty.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LBrace);
@ -729,7 +791,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null) if (location != null)
newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), EventDeclaration.Roles.Keyword); newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), EventDeclaration.Roles.Keyword);
newEvent.AddChild ((AstType)e.TypeName.Accept (this), AstNode.Roles.Type); newEvent.AddChild (ConvertToType (e.TypeName), AstNode.Roles.Type);
newEvent.AddChild (new Identifier (e.MemberName.Name, Convert (e.MemberName.Location)), EventDeclaration.Roles.Identifier); newEvent.AddChild (new Identifier (e.MemberName.Name, Convert (e.MemberName.Location)), EventDeclaration.Roles.Identifier);
if (location != null) if (location != null)
newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), ";".Length), EventDeclaration.Roles.Semicolon); newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), ";".Length), EventDeclaration.Roles.Semicolon);
@ -746,7 +808,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null) if (location != null)
newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), CustomEventDeclaration.Roles.Keyword); newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), CustomEventDeclaration.Roles.Keyword);
newEvent.AddChild ((AstType)ep.TypeName.Accept (this), CustomEventDeclaration.Roles.Type); newEvent.AddChild (ConvertToType (ep.TypeName), CustomEventDeclaration.Roles.Type);
newEvent.AddChild (new Identifier (ep.MemberName.Name, Convert (ep.MemberName.Location)), CustomEventDeclaration.Roles.Identifier); newEvent.AddChild (new Identifier (ep.MemberName.Name, Convert (ep.MemberName.Location)), CustomEventDeclaration.Roles.Identifier);
if (location != null && location.Count >= 2) if (location != null && location.Count >= 2)
newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), CustomEventDeclaration.Roles.LBrace); newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), CustomEventDeclaration.Roles.LBrace);
@ -789,7 +851,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override object Visit (BlockVariableDeclaration blockVariableDeclaration) public override object Visit (BlockVariableDeclaration blockVariableDeclaration)
{ {
var result = new VariableDeclarationStatement (); var result = new VariableDeclarationStatement ();
result.AddChild ((AstType)blockVariableDeclaration.TypeExpression.Accept (this), VariableDeclarationStatement.Roles.Type); result.AddChild (ConvertToType (blockVariableDeclaration.TypeExpression), VariableDeclarationStatement.Roles.Type);
var varInit = new VariableInitializer (); var varInit = new VariableInitializer ();
var location = LocationsBag.GetLocations (blockVariableDeclaration); var location = LocationsBag.GetLocations (blockVariableDeclaration);
@ -828,7 +890,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override object Visit (BlockConstantDeclaration blockVariableDeclaration) public override object Visit (BlockConstantDeclaration blockVariableDeclaration)
{ {
var result = new VariableDeclarationStatement (); var result = new VariableDeclarationStatement ();
result.AddChild ((AstType)blockVariableDeclaration.TypeExpression.Accept (this), VariableDeclarationStatement.Roles.Type); result.AddChild (ConvertToType (blockVariableDeclaration.TypeExpression), VariableDeclarationStatement.Roles.Type);
var varInit = new VariableInitializer (); var varInit = new VariableInitializer ();
var location = LocationsBag.GetLocations (blockVariableDeclaration); var location = LocationsBag.GetLocations (blockVariableDeclaration);
@ -1101,13 +1163,13 @@ namespace ICSharpCode.NRefactory.CSharp
usingResult.AddChild (new CSharpTokenNode (Convert (u.loc), "using".Length), UsingStatement.Roles.Keyword); usingResult.AddChild (new CSharpTokenNode (Convert (u.loc), "using".Length), UsingStatement.Roles.Keyword);
usingResult.AddChild (new CSharpTokenNode (Convert (blockStatement.StartLocation), 1), UsingStatement.Roles.LPar); usingResult.AddChild (new CSharpTokenNode (Convert (blockStatement.StartLocation), 1), UsingStatement.Roles.LPar);
if (u.Variables != null) { if (u.Variables != null) {
usingResult.AddChild ((AstType)u.Variables.TypeExpression.Accept (this), UsingStatement.Roles.Type); usingResult.AddChild (ConvertToType (u.Variables.TypeExpression), UsingStatement.Roles.Type);
usingResult.AddChild (new Identifier (u.Variables.Variable.Name, Convert (u.Variables.Variable.Location)), UsingStatement.Roles.Identifier); usingResult.AddChild (new Identifier (u.Variables.Variable.Name, Convert (u.Variables.Variable.Location)), UsingStatement.Roles.Identifier);
var loc = LocationsBag.GetLocations (u.Variables); var loc = LocationsBag.GetLocations (u.Variables);
if (loc != null) if (loc != null)
usingResult.AddChild (new CSharpTokenNode (Convert (loc[1]), 1), ContinueStatement.Roles.Assign); usingResult.AddChild (new CSharpTokenNode (Convert (loc[1]), 1), ContinueStatement.Roles.Assign);
if (u.Variables.Initializer != null) if (u.Variables.Initializer != null)
usingResult.AddChild ((AstType)u.Variables.Initializer.Accept (this), UsingStatement.ResourceAcquisitionRole); usingResult.AddChild (ConvertToType (u.Variables.Initializer), UsingStatement.ResourceAcquisitionRole);
} }
cur = u.Statement; cur = u.Statement;
@ -1241,7 +1303,7 @@ namespace ICSharpCode.NRefactory.CSharp
/* /*
if (fixedStatement.Variables != null) { if (fixedStatement.Variables != null) {
result.AddChild ((AstType)fixedStatement.Variables.TypeExpression.Accept (this), UsingStatement.Roles.Type); result.AddChild (ConvertToType (fixedStatement.Variables.TypeExpression.Accept (this), UsingStatement.Roles.Type);
result.AddChild (new Identifier (fixedStatement.Variables.Variable.Name, Convert (fixedStatement.Variables.Variable.Location)), UsingStatement.Roles.Identifier); result.AddChild (new Identifier (fixedStatement.Variables.Variable.Name, Convert (fixedStatement.Variables.Variable.Location)), UsingStatement.Roles.Identifier);
var loc = LocationsBag.GetLocations (fixedStatement.Variables); var loc = LocationsBag.GetLocations (fixedStatement.Variables);
if (loc != null) if (loc != null)
@ -1285,7 +1347,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), CatchClause.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), CatchClause.Roles.LPar);
result.AddChild ((AstType)ctch.TypeExpression.Accept (this), CatchClause.Roles.Type); result.AddChild (ConvertToType (ctch.TypeExpression), CatchClause.Roles.Type);
if (ctch.Variable != null && !string.IsNullOrEmpty (ctch.Variable.Name)) if (ctch.Variable != null && !string.IsNullOrEmpty (ctch.Variable.Name))
result.AddChild (new Identifier (ctch.Variable.Name, Convert (ctch.Variable.Location)), CatchClause.Roles.Identifier); result.AddChild (new Identifier (ctch.Variable.Name, Convert (ctch.Variable.Location)), CatchClause.Roles.Identifier);
@ -1341,7 +1403,7 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ForeachStatement.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ForeachStatement.Roles.LPar);
if (foreachStatement.TypeExpr == null) if (foreachStatement.TypeExpr == null)
result.AddChild ((AstType)foreachStatement.TypeExpr.Accept (this), ForeachStatement.Roles.Type); result.AddChild (ConvertToType (foreachStatement.TypeExpr), ForeachStatement.Roles.Type);
if (foreachStatement.Variable != null) if (foreachStatement.Variable != null)
result.AddChild (new Identifier (foreachStatement.Variable.Name, Convert (foreachStatement.Variable.Location)), ForeachStatement.Roles.Identifier); result.AddChild (new Identifier (foreachStatement.Variable.Name, Convert (foreachStatement.Variable.Location)), ForeachStatement.Roles.Identifier);
@ -1567,7 +1629,7 @@ namespace ICSharpCode.NRefactory.CSharp
var result = new IsExpression (); var result = new IsExpression ();
result.AddChild ((Expression)isExpression.Expr.Accept (this), IsExpression.Roles.Expression); result.AddChild ((Expression)isExpression.Expr.Accept (this), IsExpression.Roles.Expression);
result.AddChild (new CSharpTokenNode (Convert (isExpression.Location), "is".Length), IsExpression.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (isExpression.Location), "is".Length), IsExpression.Roles.Keyword);
result.AddChild ((AstType)isExpression.ProbeType.Accept (this), IsExpression.Roles.Type); result.AddChild (ConvertToType (isExpression.ProbeType), IsExpression.Roles.Type);
return result; return result;
} }
@ -1576,7 +1638,7 @@ namespace ICSharpCode.NRefactory.CSharp
var result = new AsExpression (); var result = new AsExpression ();
result.AddChild ((Expression)asExpression.Expr.Accept (this), AsExpression.Roles.Expression); result.AddChild ((Expression)asExpression.Expr.Accept (this), AsExpression.Roles.Expression);
result.AddChild (new CSharpTokenNode (Convert (asExpression.Location), "as".Length), AsExpression.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (asExpression.Location), "as".Length), AsExpression.Roles.Keyword);
result.AddChild ((AstType)asExpression.ProbeType.Accept (this), AsExpression.Roles.Type); result.AddChild (ConvertToType (asExpression.ProbeType), AsExpression.Roles.Type);
return result; return result;
} }
@ -1587,7 +1649,7 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (castExpression.Location), 1), CastExpression.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (castExpression.Location), 1), CastExpression.Roles.LPar);
if (castExpression.TargetType != null) if (castExpression.TargetType != null)
result.AddChild ((AstType)castExpression.TargetType.Accept (this), CastExpression.Roles.Type); result.AddChild (ConvertToType (castExpression.TargetType), CastExpression.Roles.Type);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), CastExpression.Roles.RPar); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), CastExpression.Roles.RPar);
if (castExpression.Expr != null) if (castExpression.Expr != null)
@ -1598,7 +1660,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override object Visit (ComposedCast composedCast) public override object Visit (ComposedCast composedCast)
{ {
var result = new ComposedType (); var result = new ComposedType ();
result.AddChild ((AstType)composedCast.Left.Accept (this), ComposedType.Roles.Type); result.AddChild (ConvertToType (composedCast.Left), ComposedType.Roles.Type);
var spec = composedCast.Spec; var spec = composedCast.Spec;
while (spec != null) { while (spec != null) {
@ -1627,7 +1689,7 @@ namespace ICSharpCode.NRefactory.CSharp
var location = LocationsBag.GetLocations (defaultValueExpression); var location = LocationsBag.GetLocations (defaultValueExpression);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), CastExpression.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), CastExpression.Roles.LPar);
result.AddChild ((AstType)defaultValueExpression.Expr.Accept (this), CastExpression.Roles.Type); result.AddChild (ConvertToType (defaultValueExpression.Expr), CastExpression.Roles.Type);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), CastExpression.Roles.RPar); result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), CastExpression.Roles.RPar);
return result; return result;
@ -1770,7 +1832,7 @@ namespace ICSharpCode.NRefactory.CSharp
break; break;
} }
if (p.TypeExpression != null) // lambdas may have no types (a, b) => ... if (p.TypeExpression != null) // lambdas may have no types (a, b) => ...
parameterDeclarationExpression.AddChild ((AstType)p.TypeExpression.Accept (this), ParameterDeclaration.Roles.Type); parameterDeclarationExpression.AddChild (ConvertToType (p.TypeExpression), ParameterDeclaration.Roles.Type);
parameterDeclarationExpression.AddChild (new Identifier (p.Name, Convert (p.Location)), ParameterDeclaration.Roles.Identifier); parameterDeclarationExpression.AddChild (new Identifier (p.Name, Convert (p.Location)), ParameterDeclaration.Roles.Identifier);
if (p.HasDefaultValue) { if (p.HasDefaultValue) {
if (location != null) if (location != null)
@ -1791,7 +1853,7 @@ namespace ICSharpCode.NRefactory.CSharp
var arg = typeArguments.Args[i]; var arg = typeArguments.Args[i];
if (arg == null) if (arg == null)
continue; continue;
parent.AddChild ((AstType)arg.Accept (this), InvocationExpression.Roles.TypeArgument); parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument);
} }
} }
@ -1805,7 +1867,7 @@ namespace ICSharpCode.NRefactory.CSharp
var arg = typeArguments.Args[i]; var arg = typeArguments.Args[i];
if (arg == null) if (arg == null)
continue; continue;
parent.AddChild ((AstType)arg.Accept (this), InvocationExpression.Roles.TypeArgument); parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument);
} }
} }
@ -1821,7 +1883,7 @@ namespace ICSharpCode.NRefactory.CSharp
parent.AddChild (new Identifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier); parent.AddChild (new Identifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier);
parent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), Constraint.ColonRole); parent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), Constraint.ColonRole);
foreach (var expr in c.ConstraintExpressions) foreach (var expr in c.ConstraintExpressions)
parent.AddChild ((AstType)expr.Accept (this), Constraint.BaseTypeRole); parent.AddChild (ConvertToType (expr), Constraint.BaseTypeRole);
} }
} }
@ -1878,7 +1940,7 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (newExpression.Location), "new".Length), ObjectCreateExpression.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (newExpression.Location), "new".Length), ObjectCreateExpression.Roles.Keyword);
if (newExpression.TypeRequested != null) if (newExpression.TypeRequested != null)
result.AddChild ((AstType)newExpression.TypeRequested.Accept (this), ObjectCreateExpression.Roles.Type); result.AddChild (ConvertToType (newExpression.TypeRequested), ObjectCreateExpression.Roles.Type);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ObjectCreateExpression.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ObjectCreateExpression.Roles.LPar);
AddArguments (result, location, newExpression.Arguments); AddArguments (result, location, newExpression.Arguments);
@ -1898,7 +1960,7 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (newInitializeExpression.Location), "new".Length), ObjectCreateExpression.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (newInitializeExpression.Location), "new".Length), ObjectCreateExpression.Roles.Keyword);
if (newInitializeExpression.TypeRequested != null) if (newInitializeExpression.TypeRequested != null)
result.AddChild ((AstType)newInitializeExpression.TypeRequested.Accept (this), ObjectCreateExpression.Roles.Type); result.AddChild (ConvertToType (newInitializeExpression.TypeRequested), ObjectCreateExpression.Roles.Type);
var location = LocationsBag.GetLocations (newInitializeExpression); var location = LocationsBag.GetLocations (newInitializeExpression);
if (location != null) if (location != null)
@ -1919,7 +1981,7 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (arrayCreationExpression.Location), "new".Length), ArrayCreateExpression.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (arrayCreationExpression.Location), "new".Length), ArrayCreateExpression.Roles.Keyword);
if (arrayCreationExpression.NewType != null) if (arrayCreationExpression.NewType != null)
result.AddChild ((AstType)arrayCreationExpression.NewType.Accept (this), ArrayCreateExpression.Roles.Type); result.AddChild (ConvertToType (arrayCreationExpression.NewType), ArrayCreateExpression.Roles.Type);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ArrayCreateExpression.Roles.LBracket); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ArrayCreateExpression.Roles.LBracket);
if (arrayCreationExpression.Arguments != null) { if (arrayCreationExpression.Arguments != null) {
@ -1989,7 +2051,7 @@ namespace ICSharpCode.NRefactory.CSharp
var location = LocationsBag.GetLocations (typeOfExpression); var location = LocationsBag.GetLocations (typeOfExpression);
result.AddChild (new CSharpTokenNode (Convert (typeOfExpression.Location), "typeof".Length), TypeOfExpression.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (typeOfExpression.Location), "typeof".Length), TypeOfExpression.Roles.Keyword);
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), TypeOfExpression.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), TypeOfExpression.Roles.LPar);
result.AddChild ((AstType)typeOfExpression.TypeExpression.Accept (this), TypeOfExpression.Roles.Type); result.AddChild (ConvertToType (typeOfExpression.TypeExpression), TypeOfExpression.Roles.Type);
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), TypeOfExpression.Roles.RPar); result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), TypeOfExpression.Roles.RPar);
return result; return result;
} }
@ -2001,7 +2063,7 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (sizeOfExpression.Location), "sizeof".Length), TypeOfExpression.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (sizeOfExpression.Location), "sizeof".Length), TypeOfExpression.Roles.Keyword);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), TypeOfExpression.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), TypeOfExpression.Roles.LPar);
result.AddChild ((AstType)sizeOfExpression.QueriedType.Accept (this), TypeOfExpression.Roles.Type); result.AddChild (ConvertToType (sizeOfExpression.QueriedType), TypeOfExpression.Roles.Type);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), TypeOfExpression.Roles.RPar); result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), TypeOfExpression.Roles.RPar);
return result; return result;
@ -2060,7 +2122,7 @@ namespace ICSharpCode.NRefactory.CSharp
var location = LocationsBag.GetLocations (stackAllocExpression); var location = LocationsBag.GetLocations (stackAllocExpression);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), "stackalloc".Length), StackAllocExpression.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (location[0]), "stackalloc".Length), StackAllocExpression.Roles.Keyword);
result.AddChild ((AstType)stackAllocExpression.TypeExpression.Accept (this), StackAllocExpression.Roles.Type); result.AddChild (ConvertToType (stackAllocExpression.TypeExpression), StackAllocExpression.Roles.Type);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), StackAllocExpression.Roles.LBracket); result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), StackAllocExpression.Roles.LBracket);
result.AddChild ((Expression)stackAllocExpression.CountExpression.Accept (this), StackAllocExpression.Roles.Expression); result.AddChild ((Expression)stackAllocExpression.CountExpression.Accept (this), StackAllocExpression.Roles.Expression);

Loading…
Cancel
Save