Browse Source

NRefactory: ensure Parent property is correctly set for all nodes

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3717 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
2921e6f48b
  1. 2
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Node.cs
  2. 8
      src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs
  3. 2
      src/Libraries/NRefactory/Project/NRefactory.csproj
  4. 1
      src/Libraries/NRefactory/Project/Src/Ast/General/LocalVariableDeclaration.cs
  5. 23
      src/Libraries/NRefactory/Project/Src/Ast/Generated.cs
  6. 6
      src/Libraries/NRefactory/Project/Src/Ast/TypeReference.cs
  7. 2
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs
  8. 2
      src/Libraries/NRefactory/Project/Src/Location.cs
  9. 32
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs
  10. 1766
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  11. 68
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  12. 0
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/trace.txt
  13. 2
      src/Libraries/NRefactory/Project/Src/Parser/Frames/Parser.frame
  14. 4
      src/Libraries/NRefactory/Project/Src/Parser/ModifierList.cs
  15. 2285
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  16. 49
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  17. 26
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs
  18. 2
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  19. 2
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  20. 37
      src/Libraries/NRefactory/Project/Src/Visitors/SetParentVisitor.cs
  21. 10
      src/Libraries/NRefactory/Test/Parser/CheckParentVisitor.cs
  22. 22
      src/Libraries/NRefactory/Test/Parser/GlobalScope/TypeDeclarationTests.cs
  23. 8
      src/Libraries/NRefactory/Test/Parser/Statements/BlockStatementTests.cs
  24. 8
      src/Libraries/NRefactory/Test/Parser/Statements/IfElseStatementTests.cs
  25. 18
      src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs

2
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Node.cs

@ -43,7 +43,7 @@ namespace NRefactoryASTGenerator.Ast
} }
[CustomImplementation] [CustomImplementation]
class TypeReference : AbstractNode class TypeReference : AbstractNode, INullable
{ {
List<TypeReference> genericTypes; List<TypeReference> genericTypes;
} }

8
src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs

@ -377,8 +377,12 @@ namespace NRefactoryASTGenerator
else else
ex = GetDefaultValue("value", field); ex = GetDefaultValue("value", field);
p.Setter.Assign(Easy.Var(field.Name), ex); p.Setter.Assign(Easy.Var(field.Name), ex);
if (typeof(INode).IsAssignableFrom(field.FieldType) && typeof(INullable).IsAssignableFrom(field.FieldType)) { if (typeof(INode).IsAssignableFrom(field.FieldType)) {
p.SetStatements.Add(new CodeSnippetStatement("\t\t\t\tif (!" +field.Name+".IsNull) "+field.Name+".Parent = this;")); if (typeof(INullable).IsAssignableFrom(field.FieldType)) {
p.SetStatements.Add(new CodeSnippetStatement("\t\t\t\tif (!" +field.Name+".IsNull) "+field.Name+".Parent = this;"));
} else {
p.SetStatements.Add(new CodeSnippetStatement("\t\t\t\t"+field.Name+".Parent = this;"));
}
} }
} }
foreach (ConstructorInfo ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { foreach (ConstructorInfo ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {

2
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -109,6 +109,7 @@
<Compile Include="Src\Visitors\LookupTableVisitor.cs" /> <Compile Include="Src\Visitors\LookupTableVisitor.cs" />
<Compile Include="Src\Visitors\PrefixFieldsVisitor.cs" /> <Compile Include="Src\Visitors\PrefixFieldsVisitor.cs" />
<Compile Include="Src\Visitors\RenameIdentifierVisitor.cs" /> <Compile Include="Src\Visitors\RenameIdentifierVisitor.cs" />
<Compile Include="Src\Visitors\SetParentVisitor.cs" />
<Compile Include="Src\Visitors\ToCSharpConvertVisitor.cs" /> <Compile Include="Src\Visitors\ToCSharpConvertVisitor.cs" />
<Compile Include="Src\Visitors\ToVBNetConvertVisitor.cs" /> <Compile Include="Src\Visitors\ToVBNetConvertVisitor.cs" />
<Compile Include="Src\Visitors\ToVBNetRenameConflictingVariables.cs" /> <Compile Include="Src\Visitors\ToVBNetRenameConflictingVariables.cs" />
@ -138,7 +139,6 @@
<Folder Include="Src\Parser" /> <Folder Include="Src\Parser" />
<Folder Include="Src\Parser\CSharp" /> <Folder Include="Src\Parser\CSharp" />
<Content Include="Src\Parser\CSharp\cs.ATG" /> <Content Include="Src\Parser\CSharp\cs.ATG" />
<Content Include="Src\Parser\CSharp\trace.txt" />
<Folder Include="Src\Parser\Frames" /> <Folder Include="Src\Parser\Frames" />
<Content Include="Src\Parser\Frames\Parser.frame" /> <Content Include="Src\Parser\Frames\Parser.frame" />
<Content Include="Src\Parser\Frames\Scanner.frame" /> <Content Include="Src\Parser\Frames\Scanner.frame" />

1
src/Libraries/NRefactory/Project/Src/Ast/General/LocalVariableDeclaration.cs

@ -22,6 +22,7 @@ namespace ICSharpCode.NRefactory.Ast
} }
set { set {
typeReference = TypeReference.CheckNull(value); typeReference = TypeReference.CheckNull(value);
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }

23
src/Libraries/NRefactory/Project/Src/Ast/Generated.cs

@ -144,6 +144,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
createType = value ?? TypeReference.Null; createType = value ?? TypeReference.Null;
if (!createType.IsNull) createType.Parent = this;
} }
} }
@ -555,6 +556,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
castTo = value ?? TypeReference.Null; castTo = value ?? TypeReference.Null;
if (!castTo.IsNull) castTo.Parent = this;
} }
} }
@ -613,6 +615,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -1052,6 +1055,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -1086,6 +1090,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -1127,6 +1132,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
returnType = value ?? TypeReference.Null; returnType = value ?? TypeReference.Null;
if (!returnType.IsNull) returnType.Parent = this;
} }
} }
@ -1752,6 +1758,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
type = value ?? TypeReference.Null; type = value ?? TypeReference.Null;
if (!type.IsNull) type.Parent = this;
} }
} }
@ -1840,6 +1847,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -1938,6 +1946,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -2057,6 +2066,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -2380,6 +2390,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -2531,6 +2542,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
interfaceType = value ?? TypeReference.Null; interfaceType = value ?? TypeReference.Null;
if (!interfaceType.IsNull) interfaceType.Parent = this;
} }
} }
@ -2730,6 +2742,7 @@ public Location ExtendedEndLocation { get; set; }
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -2949,6 +2962,7 @@ public Location ExtendedEndLocation { get; set; }
} }
set { set {
createType = value ?? TypeReference.Null; createType = value ?? TypeReference.Null;
if (!createType.IsNull) createType.Parent = this;
} }
} }
@ -3138,6 +3152,7 @@ public Location ExtendedEndLocation { get; set; }
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -3787,6 +3802,7 @@ public Location ExtendedEndLocation { get; set; }
} }
set { set {
type = value ?? TypeReference.Null; type = value ?? TypeReference.Null;
if (!type.IsNull) type.Parent = this;
} }
} }
@ -4558,6 +4574,7 @@ public Location ExtendedEndLocation { get; set; }
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -4586,6 +4603,7 @@ public Location ExtendedEndLocation { get; set; }
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -4914,6 +4932,7 @@ public Location ExtendedEndLocation { get; set; }
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -4952,6 +4971,7 @@ public Location ExtendedEndLocation { get; set; }
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -4979,6 +4999,7 @@ public Location ExtendedEndLocation { get; set; }
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }
@ -5143,6 +5164,7 @@ public Location ExtendedEndLocation { get; set; }
} }
set { set {
alias = value ?? TypeReference.Null; alias = value ?? TypeReference.Null;
if (!alias.IsNull) alias.Parent = this;
} }
} }
@ -5264,6 +5286,7 @@ public UsingDeclaration(string @namespace, TypeReference alias) { usings = new L
} }
set { set {
typeReference = value ?? TypeReference.Null; typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
} }
} }

6
src/Libraries/NRefactory/Project/Src/Ast/TypeReference.cs

@ -374,6 +374,10 @@ namespace ICSharpCode.NRefactory.Ast
return true; return true;
} }
} }
public override TypeReference Clone()
{
return this;
}
public override object AcceptVisitor(IAstVisitor visitor, object data) public override object AcceptVisitor(IAstVisitor visitor, object data)
{ {
return null; return null;
@ -402,7 +406,7 @@ namespace ICSharpCode.NRefactory.Ast
public override TypeReference Clone() public override TypeReference Clone()
{ {
InnerClassTypeReference c = new InnerClassTypeReference(baseType.Clone(), Type, GenericTypes); InnerClassTypeReference c = new InnerClassTypeReference(baseType.Clone(), Type, new List<TypeReference>());
CopyFields(this, c); CopyFields(this, c);
return c; return c;
} }

2
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs

@ -507,7 +507,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
Location start = new Location(Col - 1, Line); Location start = new Location(Col - 1, Line);
string directive = ReadIdent('#'); string directive = ReadIdent('#');
string argument = ReadToEndOfLine(); string argument = ReadToEndOfLine();
this.specialTracker.AddPreprocessingDirective(new PreprocessingDirective(directive, argument.Trim(), start, new Location(start.X + directive.Length + argument.Length, start.Y))); this.specialTracker.AddPreprocessingDirective(new PreprocessingDirective(directive, argument.Trim(), start, new Location(start.Column + directive.Length + argument.Length, start.Line)));
} }
string ReadDate() string ReadDate()

2
src/Libraries/NRefactory/Project/Src/Location.cs

@ -25,11 +25,13 @@ namespace ICSharpCode.NRefactory
int x, y; int x, y;
[Obsolete("Use Column instead")]
public int X { public int X {
get { return x; } get { return x; }
set { x = value; } set { x = value; }
} }
[Obsolete("Use Line instead")]
public int Y { public int Y {
get { return y; } get { return y; }
set { y = value; } set { y = value; }

32
src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs

@ -5,11 +5,11 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using ICSharpCode.NRefactory.Visitors;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using System.Diagnostics; using System.Diagnostics;
using System.Text;
using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Ast;
namespace ICSharpCode.NRefactory.Parser.CSharp namespace ICSharpCode.NRefactory.Parser.CSharp
@ -50,6 +50,12 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
errDist = 0; errDist = 0;
} }
public override void Parse()
{
ParseRoot();
compilationUnit.AcceptVisitor(new SetParentVisitor(), null);
}
public override Expression ParseExpression() public override Expression ParseExpression()
{ {
lexer.NextToken(); lexer.NextToken();
@ -61,6 +67,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
if (expr != null) { if (expr != null) {
expr.StartLocation = startLocation; expr.StartLocation = startLocation;
expr.EndLocation = t.EndLocation; expr.EndLocation = t.EndLocation;
expr.AcceptVisitor(new SetParentVisitor(), null);
} }
Expect(Tokens.EOF); Expect(Tokens.EOF);
return expr; return expr;
@ -87,6 +94,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
compilationUnit.BlockEnd(); compilationUnit.BlockEnd();
blockStmt.EndLocation = t.EndLocation; blockStmt.EndLocation = t.EndLocation;
Expect(Tokens.EOF); Expect(Tokens.EOF);
blockStmt.AcceptVisitor(new SetParentVisitor(), null);
return blockStmt; return blockStmt;
} }
@ -100,6 +108,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
ClassBody(); ClassBody();
compilationUnit.BlockEnd(); compilationUnit.BlockEnd();
Expect(Tokens.EOF); Expect(Tokens.EOF);
newType.AcceptVisitor(new SetParentVisitor(), null);
return newType.Children; return newType.Children;
} }
@ -590,24 +599,5 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
item.Parent = parent; item.Parent = parent;
} }
} }
static void SetParent<T>(List<T> list, INode parent) where T : class, INode, INullable
{
if (list != null) {
foreach (T x in list) {
if (!x.IsNull)
x.Parent = parent;
}
}
}
static void SetParentNonNullable<T>(List<T> list, INode parent) where T : class, INode
{
if (list != null) {
foreach (T x in list) {
x.Parent = parent;
}
}
}
} }
} }

1766
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

File diff suppressed because it is too large Load Diff

68
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -364,7 +364,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
Identifier (. newType.Name = t.val; .) Identifier (. newType.Name = t.val; .)
/* .NET 2.0 */ /* .NET 2.0 */
[ TypeParameterList<templates> ] (. SetParentNonNullable(templates, newType); .) [ TypeParameterList<templates> ]
[ ClassBase<out names> (. newType.BaseTypes = names; .) ] [ ClassBase<out names> (. newType.BaseTypes = names; .) ]
@ -389,7 +389,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
Identifier (. newType.Name = t.val; .) Identifier (. newType.Name = t.val; .)
/* .NET 2.0 */ /* .NET 2.0 */
[ TypeParameterList<templates> ] (. SetParentNonNullable(templates, newType); .) [ TypeParameterList<templates> ]
[ StructInterfaces<out names> (. newType.BaseTypes = names; .) ] [ StructInterfaces<out names> (. newType.BaseTypes = names; .) ]
@ -413,7 +413,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
Identifier (. newType.Name = t.val; .) Identifier (. newType.Name = t.val; .)
/* .NET 2.0 */ /* .NET 2.0 */
[ TypeParameterList<templates> ] (. SetParentNonNullable(templates, newType); .) [ TypeParameterList<templates> ]
[ InterfaceBase<out names> (. newType.BaseTypes = names; .) ] [ InterfaceBase<out names> (. newType.BaseTypes = names; .) ]
@ -451,7 +451,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
Identifier (. delegateDeclr.Name = t.val; .) Identifier (. delegateDeclr.Name = t.val; .)
/* .NET 2.0 */ /* .NET 2.0 */
[ TypeParameterList<templates> ] (. SetParentNonNullable(templates, delegateDeclr); .) [ TypeParameterList<templates> ]
"(" [ FormalParameterList<p> (. delegateDeclr.Parameters = p; .) "(" [ FormalParameterList<p> (. delegateDeclr.Parameters = p; .)
] ")" ] ")"
@ -778,9 +778,8 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
Templates = templates, Templates = templates,
IsExtensionMethod = isExtensionMethod IsExtensionMethod = isExtensionMethod
}; };
SetParentNonNullable(templates, methodDeclaration);
if (explicitInterface != null) if (explicitInterface != null)
methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); SafeAdd(methodDeclaration, methodDeclaration.InterfaceImplementations, new InterfaceImplementation(explicitInterface, qualident));
compilationUnit.AddChild(methodDeclaration); compilationUnit.AddChild(methodDeclaration);
compilationUnit.BlockStart(methodDeclaration); compilationUnit.BlockStart(methodDeclaration);
.) .)
@ -833,7 +832,7 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
[ (. m.Check(Modifiers.Constructors); .) [ (. m.Check(Modifiers.Constructors); .)
ConstructorInitializer<out init> ConstructorInitializer<out init>
] (. ] (.
ConstructorDeclaration cd = new ConstructorDeclaration(name, m.Modifier, p, init, attributes); ConstructorDeclaration cd = new ConstructorDeclaration(name, m.Modifier, p, init, attributes);
cd.StartLocation = startPos; cd.StartLocation = startPos;
cd.EndLocation = t.EndLocation; cd.EndLocation = t.EndLocation;
.) .)
@ -865,7 +864,6 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
StartLocation = m.GetDeclarationLocation(startPos), StartLocation = m.GetDeclarationLocation(startPos),
EndLocation = endPos EndLocation = endPos
}; };
SetParent(parameters, operatorDeclaration);
compilationUnit.AddChild(operatorDeclaration); compilationUnit.AddChild(operatorDeclaration);
.) .)
@ -892,22 +890,19 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
(. Location endPos = t.Location; .) (. Location endPos = t.Location; .)
")" ( Block<out stmt> | ";" ) ")" ( Block<out stmt> | ";" )
(. (.
List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
parameters.Add(new ParameterDeclarationExpression(firstType, firstName));
if (secondType != null) {
parameters.Add(new ParameterDeclarationExpression(secondType, secondName));
}
OperatorDeclaration operatorDeclaration = new OperatorDeclaration { OperatorDeclaration operatorDeclaration = new OperatorDeclaration {
Modifier = m.Modifier, Modifier = m.Modifier,
Attributes = attributes, Attributes = attributes,
Parameters = parameters,
TypeReference = type, TypeReference = type,
OverloadableOperator = op, OverloadableOperator = op,
Body = (BlockStatement)stmt, Body = (BlockStatement)stmt,
StartLocation = m.GetDeclarationLocation(startPos), StartLocation = m.GetDeclarationLocation(startPos),
EndLocation = endPos EndLocation = endPos
}; };
SetParent(parameters, operatorDeclaration); SafeAdd(operatorDeclaration, operatorDeclaration.Parameters, new ParameterDeclarationExpression(firstType, firstName));
if (secondType != null) {
SafeAdd(operatorDeclaration, operatorDeclaration.Parameters, new ParameterDeclarationExpression(secondType, secondName));
}
compilationUnit.AddChild(operatorDeclaration); compilationUnit.AddChild(operatorDeclaration);
.) .)
@ -984,7 +979,6 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
methodDeclaration.EndLocation = t.EndLocation; methodDeclaration.EndLocation = t.EndLocation;
methodDeclaration.IsExtensionMethod = isExtensionMethod; methodDeclaration.IsExtensionMethod = isExtensionMethod;
methodDeclaration.Templates = templates; methodDeclaration.Templates = templates;
SetParentNonNullable(templates, methodDeclaration);
compilationUnit.AddChild(methodDeclaration); compilationUnit.AddChild(methodDeclaration);
.) .)
{ TypeParameterConstraintsClause<templates> } { TypeParameterConstraintsClause<templates> }
@ -1016,7 +1010,7 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
indexer.StartLocation = m.GetDeclarationLocation(startPos); indexer.StartLocation = m.GetDeclarationLocation(startPos);
indexer.EndLocation = t.EndLocation; indexer.EndLocation = t.EndLocation;
if (explicitInterface != null) if (explicitInterface != null)
indexer.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, "this")); SafeAdd(indexer, indexer.InterfaceImplementations, new InterfaceImplementation(explicitInterface, "this"));
PropertyGetRegion getRegion; PropertyGetRegion getRegion;
PropertySetRegion setRegion; PropertySetRegion setRegion;
.) .)
@ -1066,7 +1060,7 @@ InterfaceMemberDecl
[ "new" (. mod = Modifiers.New; startLocation = t.Location; .) ] [ "new" (. mod = Modifiers.New; startLocation = t.Location; .) ]
( (
/*--- interface void method (procedure) declaration: */ /*--- interface void method (procedure) declaration: */
IF (NotVoidPointer()) "void" (. if (startLocation.X == -1) startLocation = t.Location; .) IF (NotVoidPointer()) "void" (. if (startLocation.IsEmpty) startLocation = t.Location; .)
Identifier (. name = t.val; .) Identifier (. name = t.val; .)
[ TypeParameterList<templates> ] [ TypeParameterList<templates> ]
"(" [ FormalParameterList<parameters> ] ")" "(" [ FormalParameterList<parameters> ] ")"
@ -1077,11 +1071,10 @@ InterfaceMemberDecl
Parameters = parameters, Attributes = attributes, Templates = templates, Parameters = parameters, Attributes = attributes, Templates = templates,
StartLocation = startLocation, EndLocation = t.EndLocation StartLocation = startLocation, EndLocation = t.EndLocation
}; };
SetParentNonNullable(templates, md);
compilationUnit.AddChild(md); compilationUnit.AddChild(md);
.) .)
| ( | (
Type<out type> (. if (startLocation.X == -1) startLocation = t.Location; .) Type<out type> (. if (startLocation.IsEmpty) startLocation = t.Location; .)
( (
Identifier (. name = t.val; Location qualIdentEndLocation = t.EndLocation; .) Identifier (. name = t.val; Location qualIdentEndLocation = t.EndLocation; .)
( (
@ -1096,26 +1089,37 @@ InterfaceMemberDecl
Parameters = parameters, Attributes = attributes, Templates = templates, Parameters = parameters, Attributes = attributes, Templates = templates,
StartLocation = startLocation, EndLocation = t.EndLocation StartLocation = startLocation, EndLocation = t.EndLocation
}; };
SetParentNonNullable(templates, md);
compilationUnit.AddChild(md); compilationUnit.AddChild(md);
.) .)
/*--- interface property declaration: */ /*--- interface property declaration: */
| (. PropertyDeclaration pd = new PropertyDeclaration(name, type, mod, attributes); compilationUnit.AddChild(pd); .) |
"{" (. Location bodyStart = t.Location;.) InterfaceAccessors<out getBlock, out setBlock> "}" (. pd.GetRegion = getBlock; pd.SetRegion = setBlock; pd.StartLocation = startLocation; pd.EndLocation = qualIdentEndLocation; pd.BodyStart = bodyStart; pd.BodyEnd = t.EndLocation; .) (. PropertyDeclaration pd = new PropertyDeclaration(name, type, mod, attributes);
compilationUnit.AddChild(pd); .)
"{"
(. Location bodyStart = t.Location;.)
InterfaceAccessors<out getBlock, out setBlock>
"}" (. pd.GetRegion = getBlock; pd.SetRegion = setBlock; pd.StartLocation = startLocation; pd.EndLocation = qualIdentEndLocation; pd.BodyStart = bodyStart; pd.BodyEnd = t.EndLocation; .)
) )
/*--- interface indexer declaration: */ /*--- interface indexer declaration: */
| "this" "[" FormalParameterList<parameters> "]" (.Location bracketEndLocation = t.EndLocation; .) (. IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes); compilationUnit.AddChild(id); .) | "this" "[" FormalParameterList<parameters> "]"
"{" (. Location bodyStart = t.Location;.) InterfaceAccessors<out getBlock, out setBlock> "}" (. id.GetRegion = getBlock; id.SetRegion = setBlock; id.StartLocation = startLocation; id.EndLocation = bracketEndLocation; id.BodyStart = bodyStart; id.BodyEnd = t.EndLocation;.) (. Location bracketEndLocation = t.EndLocation; .)
(. IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes);
compilationUnit.AddChild(id); .)
"{" (. Location bodyStart = t.Location;.)
InterfaceAccessors<out getBlock, out setBlock>
"}"
(. id.GetRegion = getBlock; id.SetRegion = setBlock; id.StartLocation = startLocation; id.EndLocation = bracketEndLocation; id.BodyStart = bodyStart; id.BodyEnd = t.EndLocation;.)
) )
/*--- interface event declaration: */ /*--- interface event declaration: */
| "event" (. if (startLocation.X == -1) startLocation = t.Location; .) | "event" (. if (startLocation.IsEmpty) startLocation = t.Location; .)
Type<out type> Identifier Type<out type> Identifier
(. EventDeclaration ed = new EventDeclaration { (. EventDeclaration ed = new EventDeclaration {
TypeReference = type, Name = t.val, Modifier = mod, Attributes = attributes TypeReference = type, Name = t.val, Modifier = mod, Attributes = attributes
}; };
compilationUnit.AddChild(ed); compilationUnit.AddChild(ed);
.) .)
";" (. ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; .) ";"
(. ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; .)
) )
) )
. .
@ -1507,7 +1511,6 @@ EmbeddedStatement<out Statement statement>
"{" SwitchSections<switchSections> "{" SwitchSections<switchSections>
"}" "}"
(. statement = new SwitchStatement(expr, switchSections); .) (. statement = new SwitchStatement(expr, switchSections); .)
(. SetParent(switchSections, statement); .)
/*--- iteration statements (while, do, for, foreach): */ /*--- iteration statements (while, do, for, foreach): */
| "while" "(" Expr<out expr> ")" | "while" "(" Expr<out expr> ")"
@ -1523,10 +1526,7 @@ EmbeddedStatement<out Statement statement>
[ Expr<out expr> ] ";" [ Expr<out expr> ] ";"
[ ForIterator<out iterator> ] ")" [ ForIterator<out iterator> ] ")"
EmbeddedStatement<out embeddedStatement> EmbeddedStatement<out embeddedStatement>
(. statement = new ForStatement(initializer, expr, iterator, embeddedStatement); (. statement = new ForStatement(initializer, expr, iterator, embeddedStatement); .)
SetParent(initializer, statement);
SetParent(iterator, statement);
.)
| "foreach" "(" Type<out type> Identifier (. string varName = t.val; .) | "foreach" "(" Type<out type> Identifier (. string varName = t.val; .)
"in" Expr<out expr> ")" "in" Expr<out expr> ")"
@ -1597,8 +1597,6 @@ IfStatement<out Statement statement>
(elseStatement as IfElseStatement).TrueStatement[0])); (elseStatement as IfElseStatement).TrueStatement[0]));
(statement as IfElseStatement).ElseIfSections.AddRange((elseStatement as IfElseStatement).ElseIfSections); (statement as IfElseStatement).ElseIfSections.AddRange((elseStatement as IfElseStatement).ElseIfSections);
(statement as IfElseStatement).FalseStatement = (elseStatement as IfElseStatement).FalseStatement; (statement as IfElseStatement).FalseStatement = (elseStatement as IfElseStatement).FalseStatement;
SetParent((statement as IfElseStatement).FalseStatement, statement);
SetParent((statement as IfElseStatement).ElseIfSections, statement);
} }
.) .)
. .
@ -2049,7 +2047,7 @@ ShortedLambdaExpression<IdentifierExpression ident, out Expression pexpr>
/* not an IdentifierExpression, but a short lambda expression*/ /* not an IdentifierExpression, but a short lambda expression*/
(. (.
lambda.StartLocation = ident.StartLocation; lambda.StartLocation = ident.StartLocation;
lambda.Parameters.Add(new ParameterDeclarationExpression(null, ident.Identifier)); SafeAdd(lambda, lambda.Parameters, new ParameterDeclarationExpression(null, ident.Identifier));
lambda.Parameters[0].StartLocation = ident.StartLocation; lambda.Parameters[0].StartLocation = ident.StartLocation;
lambda.Parameters[0].EndLocation = ident.EndLocation; lambda.Parameters[0].EndLocation = ident.EndLocation;
.) .)

0
src/Libraries/NRefactory/Project/Src/Parser/CSharp/trace.txt

2
src/Libraries/NRefactory/Project/Src/Parser/Frames/Parser.frame

@ -22,7 +22,7 @@ partial class Parser : AbstractParser
-->productions -->productions
public override void Parse() void ParseRoot()
{ {
-->parseRoot -->parseRoot
} }

4
src/Libraries/NRefactory/Project/Src/Parser/ModifierList.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.Parser
public Location GetDeclarationLocation(Location keywordLocation) public Location GetDeclarationLocation(Location keywordLocation)
{ {
if(location.X == -1 && location.Y == -1) { if(location.IsEmpty) {
return keywordLocation; return keywordLocation;
} }
return location; return location;
@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.Parser
public void Add(Modifiers m, Location tokenLocation) public void Add(Modifiers m, Location tokenLocation)
{ {
if(location.X == -1 && location.Y == -1) { if(location.IsEmpty) {
location = tokenLocation; location = tokenLocation;
} }

2285
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

49
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -437,7 +437,7 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
newType.Type = ClassType.Class; newType.Type = ClassType.Class;
.) .)
Identifier (. newType.Name = t.val; .) Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates> (. SetParent(newType.Templates, newType); .) TypeParameterList<newType.Templates>
EndOfStmt EndOfStmt
(. newType.BodyStartLocation = t.Location; .) (. newType.BodyStartLocation = t.Location; .)
[ ClassBaseType<out typeRef> (. newType.BaseTypes.Add(typeRef); .) ] [ ClassBaseType<out typeRef> (. newType.BaseTypes.Add(typeRef); .) ]
@ -474,7 +474,7 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
newType.Type = ClassType.Struct; newType.Type = ClassType.Struct;
.) .)
Identifier (. newType.Name = t.val; .) Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates> (. SetParent(newType.Templates, newType); .) TypeParameterList<newType.Templates>
EndOfStmt EndOfStmt
(. newType.BodyStartLocation = t.Location; .) (. newType.BodyStartLocation = t.Location; .)
{ TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces);.) } { TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces);.) }
@ -512,7 +512,7 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
newType.Type = ClassType.Interface; newType.Type = ClassType.Interface;
.) .)
Identifier (. newType.Name = t.val; .) Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates> (. SetParent(newType.Templates, newType); .) TypeParameterList<newType.Templates>
EndOfStmt EndOfStmt
(. newType.BodyStartLocation = t.Location; .) (. newType.BodyStartLocation = t.Location; .)
{ InterfaceBase<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) } { InterfaceBase<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
@ -531,11 +531,11 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
.) .)
( (
"Sub" Identifier (. delegateDeclr.Name = t.val; .) "Sub" Identifier (. delegateDeclr.Name = t.val; .)
TypeParameterList<delegateDeclr.Templates> (. SetParent(delegateDeclr.Templates, delegateDeclr); .) TypeParameterList<delegateDeclr.Templates>
[ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ] [ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ]
| |
"Function" Identifier (. delegateDeclr.Name = t.val; .) "Function" Identifier (. delegateDeclr.Name = t.val; .)
TypeParameterList<delegateDeclr.Templates> (. SetParent(delegateDeclr.Templates, delegateDeclr); .) TypeParameterList<delegateDeclr.Templates>
[ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ] [ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ]
[ "As" (. TypeReference type; .) TypeName<out type> (. delegateDeclr.ReturnType = type; .)] [ "As" (. TypeReference type; .) TypeName<out type> (. delegateDeclr.ReturnType = type; .)]
) )
@ -609,7 +609,6 @@ EnumBody<TypeDeclaration newType>
{ {
EnumMemberDecl<out f> EnumMemberDecl<out f>
(. (.
SetParent(f.Fields, f);
compilationUnit.AddChild(f); compilationUnit.AddChild(f);
.) .)
{ EndOfStmt } /* allow empty lines in body */ { EndOfStmt } /* allow empty lines in body */
@ -683,7 +682,6 @@ InterfaceMemberDecl
EndLocation = t.EndLocation, EndLocation = t.EndLocation,
Templates = templates Templates = templates
}; };
SetParent(templates, md);
compilationUnit.AddChild(md); compilationUnit.AddChild(md);
.) .)
| |
@ -711,7 +709,6 @@ InterfaceMemberDecl
md.StartLocation = startLocation; md.StartLocation = startLocation;
md.EndLocation = t.EndLocation; md.EndLocation = t.EndLocation;
md.Templates = templates; md.Templates = templates;
SetParent(templates, md);
compilationUnit.AddChild(md); compilationUnit.AddChild(md);
.) .)
EndOfStmt EndOfStmt
@ -824,7 +821,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause, HandlesClause = handlesClause,
InterfaceImplementations = implementsClause InterfaceImplementations = implementsClause
}; };
SetParent(templates, methodDeclaration);
compilationUnit.AddChild(methodDeclaration); compilationUnit.AddChild(methodDeclaration);
.) .)
| |
@ -838,7 +834,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause, HandlesClause = handlesClause,
InterfaceImplementations = implementsClause InterfaceImplementations = implementsClause
}; };
SetParent(templates, methodDeclaration);
compilationUnit.AddChild(methodDeclaration); compilationUnit.AddChild(methodDeclaration);
.) .)
@ -873,7 +868,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
(. Location endLocation = t.EndLocation; .) (. Location endLocation = t.EndLocation; .)
EndOfStmt EndOfStmt
(. (.
ConstructorDeclaration cd = new ConstructorDeclaration("New", m.Modifier, p, attributes); ConstructorDeclaration cd = new ConstructorDeclaration("New", m.Modifier, p, attributes);
cd.StartLocation = m.GetDeclarationLocation(startPos); cd.StartLocation = m.GetDeclarationLocation(startPos);
cd.EndLocation = constructorEndLocation; cd.EndLocation = constructorEndLocation;
cd.Body = (BlockStatement)stmt; cd.Body = (BlockStatement)stmt;
@ -922,7 +917,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
Templates = templates, Templates = templates,
InterfaceImplementations = implementsClause InterfaceImplementations = implementsClause
}; };
SetParent(templates, methodDeclaration);
if (returnTypeAttributeSection != null) { if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return"; returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection); methodDeclaration.Attributes.Add(returnTypeAttributeSection);
@ -941,7 +935,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause, HandlesClause = handlesClause,
InterfaceImplementations = implementsClause InterfaceImplementations = implementsClause
}; };
SetParent(templates, methodDeclaration);
if (returnTypeAttributeSection != null) { if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return"; returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection); methodDeclaration.Attributes.Add(returnTypeAttributeSection);
@ -1043,7 +1036,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
(. (.
fd.EndLocation = t.EndLocation; fd.EndLocation = t.EndLocation;
fd.Fields = variableDeclarators; fd.Fields = variableDeclarators;
SetParent(variableDeclarators, fd);
compilationUnit.AddChild(fd); compilationUnit.AddChild(fd);
.) .)
| /* 9.4 */ | /* 9.4 */
@ -1425,9 +1417,9 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration
IF (IsObjectCreation()) "As" ObjectCreateExpression<out expr> IF (IsObjectCreation()) "As" ObjectCreateExpression<out expr>
(. (.
if (expr is ObjectCreateExpression) { if (expr is ObjectCreateExpression) {
type = ((ObjectCreateExpression)expr).CreateType; type = ((ObjectCreateExpression)expr).CreateType.Clone();
} else { } else {
type = ((ArrayCreateExpression)expr).CreateType; type = ((ArrayCreateExpression)expr).CreateType.Clone();
} }
.) .)
| |
@ -1458,8 +1450,7 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration
rank.Insert(0, dimension.Count - 1); rank.Insert(0, dimension.Count - 1);
type.RankSpecifier = (int[])rank.ToArray(typeof(int)); type.RankSpecifier = (int[])rank.ToArray(typeof(int));
} }
expr = new ArrayCreateExpression(type, dimension); expr = new ArrayCreateExpression(type.Clone(), dimension);
SetParent(dimension, expr);
} }
} else if (rank != null) { } else if (rank != null) {
if(type.RankSpecifier != null) { if(type.RankSpecifier != null) {
@ -1757,7 +1748,6 @@ InvocationExpression<ref Expression pexpr>
")" ")"
(. (.
pexpr = new InvocationExpression(pexpr, parameters); pexpr = new InvocationExpression(pexpr, parameters);
SetParent(parameters, pexpr);
.) .)
(. pexpr.StartLocation = start; pexpr.EndLocation = t.Location; .) (. pexpr.StartLocation = start; pexpr.EndLocation = t.Location; .)
. .
@ -1965,14 +1955,12 @@ ObjectCreateExpression<out Expression oce>
(. (.
if (initializer == null) { if (initializer == null) {
oce = new ObjectCreateExpression(type, arguments); oce = new ObjectCreateExpression(type, arguments);
SetParent(arguments, oce);
} else { } else {
if (dimensions == null) dimensions = new ArrayList(); if (dimensions == null) dimensions = new ArrayList();
dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0)); dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0));
type.RankSpecifier = (int[])dimensions.ToArray(typeof(int)); type.RankSpecifier = (int[])dimensions.ToArray(typeof(int));
ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as CollectionInitializerExpression); ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as CollectionInitializerExpression);
ace.Arguments = arguments; ace.Arguments = arguments;
SetParent(arguments, ace);
oce = ace; oce = ace;
} }
.) .)
@ -2119,10 +2107,6 @@ GroupByQueryOperator<out QueryExpressionGroupVBClause groupByClause>
"By" ExpressionRangeVariableDeclarationList<groupByClause.ByVariables> "By" ExpressionRangeVariableDeclarationList<groupByClause.ByVariables>
"Into" ExpressionRangeVariableDeclarationList<groupByClause.IntoVariables> "Into" ExpressionRangeVariableDeclarationList<groupByClause.IntoVariables>
(. (.
SetParent(groupByClause.GroupVariables, groupByClause);
SetParent(groupByClause.ByVariables, groupByClause);
SetParent(groupByClause.IntoVariables, groupByClause);
groupByClause.EndLocation = t.EndLocation; groupByClause.EndLocation = t.EndLocation;
.) .)
. .
@ -2154,7 +2138,6 @@ SelectQueryOperator<List<QueryExpressionClause> middleClauses>
.) = .) =
"Select" ExpressionRangeVariableDeclarationList<selectClause.Variables> "Select" ExpressionRangeVariableDeclarationList<selectClause.Variables>
(. (.
SetParent(selectClause.Variables, selectClause);
selectClause.EndLocation = t.Location; selectClause.EndLocation = t.Location;
middleClauses.Add(selectClause); middleClauses.Add(selectClause);
.) .)
@ -2219,10 +2202,8 @@ AggregateQueryOperator<List<QueryExpressionClause> middleClauses>
{ {
QueryOperator<aggregateClause.MiddleClauses> QueryOperator<aggregateClause.MiddleClauses>
} }
(. SetParent(aggregateClause.MiddleClauses, aggregateClause); .)
"Into" ExpressionRangeVariableDeclarationList<aggregateClause.IntoVariables> "Into" ExpressionRangeVariableDeclarationList<aggregateClause.IntoVariables>
(. (.
SetParent(aggregateClause.IntoVariables, aggregateClause);
aggregateClause.EndLocation = t.EndLocation; aggregateClause.EndLocation = t.EndLocation;
middleClauses.Add(aggregateClause); middleClauses.Add(aggregateClause);
.) .)
@ -2570,8 +2551,6 @@ Attribute<out ASTAttribute attribute>
[ AttributeArguments<positional, named> ] [ AttributeArguments<positional, named> ]
(. (.
attribute = new ASTAttribute(name, positional, named); attribute = new ASTAttribute(name, positional, named);
SetParent(positional, attribute);
SetParent(named, attribute);
.) .)
. .
@ -2769,7 +2748,6 @@ LocalDeclarationStatement<out Statement statement>
VariableDeclarator<localVariableDeclaration.Variables> VariableDeclarator<localVariableDeclaration.Variables>
{ "," VariableDeclarator<localVariableDeclaration.Variables> } { "," VariableDeclarator<localVariableDeclaration.Variables> }
(. (.
SetParent(localVariableDeclaration.Variables, localVariableDeclaration);
statement = localVariableDeclaration; statement = localVariableDeclaration;
.) .)
. .
@ -2815,7 +2793,6 @@ EmbeddedStatement<out Statement statement>
[ "(" [ ArgumentList<out p> ] ")" ] [ "(" [ ArgumentList<out p> ] ")" ]
(. (.
statement = new RaiseEventStatement(name, p); statement = new RaiseEventStatement(name, p);
SetParent(p, statement);
.) .)
| /* 10.3 */ | /* 10.3 */
WithStatement<out statement> WithStatement<out statement>
@ -2920,7 +2897,6 @@ EmbeddedStatement<out Statement statement>
EmbeddedStatement = embeddedStatement, EmbeddedStatement = embeddedStatement,
NextExpressions = nextExpressions NextExpressions = nextExpressions
}; };
SetParent(nextExpressions, statement);
.) .)
) )
| /* 10.10.2.1 */ | /* 10.10.2.1 */
@ -2991,9 +2967,6 @@ EmbeddedStatement<out Statement statement>
ifStatement.StartLocation = ifStartLocation; ifStatement.StartLocation = ifStartLocation;
.) .)
SingleLineStatementList<ifStatement.TrueStatement> SingleLineStatementList<ifStatement.TrueStatement>
(.
SetParent(ifStatement.TrueStatement, ifStatement);
.)
[ [
"Else" "Else"
[ SingleLineStatementList<ifStatement.FalseStatement> ] [ SingleLineStatementList<ifStatement.FalseStatement> ]
@ -3010,7 +2983,6 @@ EmbeddedStatement<out Statement statement>
"Case" CaseClauses<out caseClauses> [ IF(IsNotStatementSeparator()) ":" ] EndOfStmt "Case" CaseClauses<out caseClauses> [ IF(IsNotStatementSeparator()) ":" ] EndOfStmt
(. (.
SwitchSection selectSection = new SwitchSection(caseClauses); SwitchSection selectSection = new SwitchSection(caseClauses);
SetParent(caseClauses, selectSection);
selectSection.StartLocation = caseLocation; selectSection.StartLocation = caseLocation;
.) .)
Block<out block> Block<out block>
@ -3022,7 +2994,6 @@ EmbeddedStatement<out Statement statement>
} }
(. (.
statement = new SwitchStatement(expr, selectSections); statement = new SwitchStatement(expr, selectSections);
SetParent(selectSections, statement);
.) .)
"End" "Select" "End" "Select"
| (. OnErrorStatement onErrorStatement = null; .) | (. OnErrorStatement onErrorStatement = null; .)
@ -3064,7 +3035,6 @@ EmbeddedStatement<out Statement statement>
Block<out block> Block<out block>
(. (.
statement = new UsingStatement(resourceAquisition, block); statement = new UsingStatement(resourceAquisition, block);
SetParent(resourceAquisition.Variables, resourceAquisition);
.) .)
| Expr<out expr> | Expr<out expr>
Block<out block> Block<out block>
@ -3184,7 +3154,6 @@ ReDimClauseInternal<ref Expression expr>
NormalOrReDimArgumentList<out arguments, out canBeNormal, out canBeRedim> NormalOrReDimArgumentList<out arguments, out canBeNormal, out canBeRedim>
")" ")"
(. expr = new InvocationExpression(expr, arguments); (. expr = new InvocationExpression(expr, arguments);
SetParent(arguments, expr);
if (canBeRedim == false || canBeNormal && (la.kind == Tokens.Dot || la.kind == Tokens.OpenParenthesis)) { if (canBeRedim == false || canBeNormal && (la.kind == Tokens.Dot || la.kind == Tokens.OpenParenthesis)) {
if (this.Errors.Count == 0) { if (this.Errors.Count == 0) {
// don't recurse on parse errors - could result in endless recursion // don't recurse on parse errors - could result in endless recursion

26
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs

@ -5,11 +5,11 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using ICSharpCode.NRefactory.Visitors;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using System.Diagnostics; using System.Diagnostics;
using System.Text;
using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Ast;
namespace ICSharpCode.NRefactory.Parser.VB namespace ICSharpCode.NRefactory.Parser.VB
@ -59,6 +59,12 @@ namespace ICSharpCode.NRefactory.Parser.VB
errDist = 0; errDist = 0;
} }
public override void Parse()
{
ParseRoot();
compilationUnit.AcceptVisitor(new SetParentVisitor(), null);
}
public override Expression ParseExpression() public override Expression ParseExpression()
{ {
lexer.NextToken(); lexer.NextToken();
@ -69,6 +75,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
if (expr != null) { if (expr != null) {
expr.StartLocation = startLocation; expr.StartLocation = startLocation;
expr.EndLocation = t.EndLocation; expr.EndLocation = t.EndLocation;
expr.AcceptVisitor(new SetParentVisitor(), null);
} }
Expect(Tokens.EOF); Expect(Tokens.EOF);
return expr; return expr;
@ -88,6 +95,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
st.EndLocation = t.EndLocation; st.EndLocation = t.EndLocation;
else else
st.EndLocation = la.Location; st.EndLocation = la.Location;
st.AcceptVisitor(new SetParentVisitor(), null);
} }
Expect(Tokens.EOF); Expect(Tokens.EOF);
return st as BlockStatement; return st as BlockStatement;
@ -103,6 +111,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
ClassBody(newType); ClassBody(newType);
compilationUnit.BlockEnd(); compilationUnit.BlockEnd();
Expect(Tokens.EOF); Expect(Tokens.EOF);
newType.AcceptVisitor(new SetParentVisitor(), null);
return newType.Children; return newType.Children;
} }
@ -306,18 +315,5 @@ namespace ICSharpCode.NRefactory.Parser.VB
item.Parent = parent; item.Parent = parent;
} }
} }
static void SetParent<T>(List<T> list, INode parent) where T : class, INode
{
if (list != null) {
foreach (T x in list) {
INullable xNull = x as INullable;
if (xNull == null || !xNull.IsNull)
x.Parent = parent;
}
}
}
} }
} }

2
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -78,7 +78,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
void Error(INode node, string message) void Error(INode node, string message)
{ {
outputFormatter.PrintText(" // ERROR: " + message + Environment.NewLine); outputFormatter.PrintText(" // ERROR: " + message + Environment.NewLine);
errors.Error(node.StartLocation.Y, node.StartLocation.X, message); errors.Error(node.StartLocation.Line, node.StartLocation.Column, message);
} }
void NotSupported(INode node) void NotSupported(INode node)

2
src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs

@ -85,7 +85,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
void Error(string text, Location position) void Error(string text, Location position)
{ {
errors.Error(position.Y, position.X, text); errors.Error(position.Line, position.Column, text);
} }
void UnsupportedNode(INode node) void UnsupportedNode(INode node)

37
src/Libraries/NRefactory/Project/Src/Visitors/SetParentVisitor.cs

@ -0,0 +1,37 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.NRefactory.Ast;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.Visitors
{
/// <summary>
/// Sets the parent property on all nodes in the tree.
/// </summary>
public class SetParentVisitor : NodeTrackingAstVisitor
{
Stack<INode> nodeStack = new Stack<INode>();
public SetParentVisitor()
{
nodeStack.Push(null);
}
protected override void BeginVisit(INode node)
{
node.Parent = nodeStack.Peek();
nodeStack.Push(node);
}
protected override void EndVisit(INode node)
{
nodeStack.Pop();
}
}
}

10
src/Libraries/NRefactory/Test/Parser/CheckParentVisitor.cs

@ -19,8 +19,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{ {
Stack<INode> nodeStack = new Stack<INode>(); Stack<INode> nodeStack = new Stack<INode>();
public bool StrictCheck;
public CheckParentVisitor() public CheckParentVisitor()
{ {
nodeStack.Push(null); nodeStack.Push(null);
@ -34,13 +32,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
protected override void EndVisit(INode node) protected override void EndVisit(INode node)
{ {
Assert.AreSame(node, nodeStack.Pop(), "nodeStack was corrupted!"); Assert.AreSame(node, nodeStack.Pop(), "nodeStack was corrupted!");
if (StrictCheck Assert.AreSame(nodeStack.Peek(), node.Parent, "node " + node + " is missing parent: " + nodeStack.Peek());
|| !(node is TypeReference) && !(node is InterfaceImplementation)
&& !(node is ParameterDeclarationExpression)
&& !(node is ICSharpCode.NRefactory.Ast.Attribute) && !(node is AttributeSection))
{
Assert.AreSame(nodeStack.Peek(), node.Parent, "node " + node + " is missing parent: " + nodeStack.Peek());
}
} }
} }
} }

22
src/Libraries/NRefactory/Test/Parser/GlobalScope/TypeDeclarationTests.cs

@ -31,11 +31,11 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{ {
const string program = "class MyClass\n{\n}\n"; const string program = "class MyClass\n{\n}\n";
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program); TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
Assert.AreEqual(1, td.StartLocation.Y, "StartLocation.Y"); Assert.AreEqual(1, td.StartLocation.Line, "StartLocation.Y");
Assert.AreEqual(1, td.StartLocation.X, "StartLocation.X"); Assert.AreEqual(1, td.StartLocation.Column, "StartLocation.X");
Assert.AreEqual(1, td.BodyStartLocation.Y, "BodyStartLocation.Y"); Assert.AreEqual(1, td.BodyStartLocation.Line, "BodyStartLocation.Y");
Assert.AreEqual(14, td.BodyStartLocation.X, "BodyStartLocation.X"); Assert.AreEqual(14, td.BodyStartLocation.Column, "BodyStartLocation.X");
Assert.AreEqual(3, td.EndLocation.Y, "EndLocation.Y"); Assert.AreEqual(3, td.EndLocation.Line, "EndLocation.Y");
} }
[Test] [Test]
@ -190,10 +190,10 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual("TestClass", td.Name); Assert.AreEqual("TestClass", td.Name);
Assert.AreEqual(ClassType.Class, td.Type); Assert.AreEqual(ClassType.Class, td.Type);
Assert.AreEqual(1, td.StartLocation.Y, "start line"); Assert.AreEqual(1, td.StartLocation.Line, "start line");
Assert.AreEqual(1, td.BodyStartLocation.Y, "bodystart line"); Assert.AreEqual(1, td.BodyStartLocation.Line, "bodystart line");
Assert.AreEqual(16, td.BodyStartLocation.X, "bodystart col"); Assert.AreEqual(16, td.BodyStartLocation.Column, "bodystart col");
Assert.AreEqual(2, td.EndLocation.Y, "end line"); Assert.AreEqual(2, td.EndLocation.Line, "end line");
} }
[Test] [Test]
@ -254,8 +254,8 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual("TestClass", td.Name); Assert.AreEqual("TestClass", td.Name);
Assert.AreEqual(ClassType.Class, td.Type); Assert.AreEqual(ClassType.Class, td.Type);
Assert.AreEqual(1, td.StartLocation.Y, "start line"); Assert.AreEqual(1, td.StartLocation.Line, "start line");
Assert.AreEqual(2, td.EndLocation.Y, "end line"); Assert.AreEqual(2, td.EndLocation.Line, "end line");
} }
[Test] [Test]

8
src/Libraries/NRefactory/Test/Parser/Statements/BlockStatementTests.cs

@ -36,10 +36,10 @@ namespace ICSharpCode.NRefactory.Tests.Ast
}; };
}"; }";
BlockStatement blockStmt = ParseUtilCSharp.ParseStatement<BlockStatement>(code); BlockStatement blockStmt = ParseUtilCSharp.ParseStatement<BlockStatement>(code);
//Assert.AreEqual(1, blockStmt.StartLocation.X); // does not work because ParseStatement inserts special code //Assert.AreEqual(1, blockStmt.StartLocation.Column); // does not work because ParseStatement inserts special code
Assert.AreEqual(1, blockStmt.StartLocation.Y); Assert.AreEqual(1, blockStmt.StartLocation.Line);
Assert.AreEqual(2, blockStmt.EndLocation.X); Assert.AreEqual(2, blockStmt.EndLocation.Column);
Assert.AreEqual(9, blockStmt.EndLocation.Y); Assert.AreEqual(9, blockStmt.EndLocation.Line);
} }
#endregion #endregion

8
src/Libraries/NRefactory/Test/Parser/Statements/IfElseStatementTests.cs

@ -90,10 +90,10 @@ namespace ICSharpCode.NRefactory.Tests.Ast
"ElseIf False Then\n" + "ElseIf False Then\n" +
"DoIt()\n" + "DoIt()\n" +
"End If"); "End If");
Assert.AreEqual(3, (ifElseStatement.StartLocation).Y); Assert.AreEqual(3, (ifElseStatement.StartLocation).Line);
Assert.AreEqual(7, (ifElseStatement.EndLocation).Y); Assert.AreEqual(7, (ifElseStatement.EndLocation).Line);
Assert.AreEqual(5, (ifElseStatement.ElseIfSections[0].StartLocation).Y); Assert.AreEqual(5, (ifElseStatement.ElseIfSections[0].StartLocation).Line);
Assert.AreEqual(6, (ifElseStatement.ElseIfSections[0].EndLocation).Y); Assert.AreEqual(6, (ifElseStatement.ElseIfSections[0].EndLocation).Line);
Assert.IsNotNull(ifElseStatement.ElseIfSections[0].Parent); Assert.IsNotNull(ifElseStatement.ElseIfSections[0].Parent);
} }

18
src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs

@ -67,9 +67,9 @@ namespace ICSharpCode.NRefactory.Tests.Ast
} }
"; ";
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>(program); MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>(program);
Assert.AreEqual(2, md.StartLocation.Y, "StartLocation.Y"); Assert.AreEqual(2, md.StartLocation.Line, "StartLocation.Y");
Assert.AreEqual(2, md.EndLocation.Y, "EndLocation.Y"); Assert.AreEqual(2, md.EndLocation.Line, "EndLocation.Y");
Assert.AreEqual(3, md.StartLocation.X, "StartLocation.X"); Assert.AreEqual(3, md.StartLocation.Column, "StartLocation.X");
// endLocation.X is currently 20. It should be 18, but that error is not critical // endLocation.X is currently 20. It should be 18, but that error is not critical
//Assert.AreEqual(18, md.EndLocation.X, "EndLocation.X"); //Assert.AreEqual(18, md.EndLocation.X, "EndLocation.X");
@ -85,9 +85,9 @@ namespace ICSharpCode.NRefactory.Tests.Ast
} }
"; ";
MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>(program); MethodDeclaration md = ParseUtilCSharp.ParseTypeMember<MethodDeclaration>(program);
Assert.AreEqual(2, md.StartLocation.Y, "StartLocation.Y"); Assert.AreEqual(2, md.StartLocation.Line, "StartLocation.Y");
Assert.AreEqual(2, md.EndLocation.Y, "EndLocation.Y"); Assert.AreEqual(2, md.EndLocation.Line, "EndLocation.Y");
Assert.AreEqual(3, md.StartLocation.X, "StartLocation.X"); Assert.AreEqual(3, md.StartLocation.Column, "StartLocation.X");
} }
[Test] [Test]
@ -307,9 +307,9 @@ namespace ICSharpCode.NRefactory.Tests.Ast
MethodDeclaration md = ParseUtilVBNet.ParseTypeMember<MethodDeclaration>(program); MethodDeclaration md = ParseUtilVBNet.ParseTypeMember<MethodDeclaration>(program);
Assert.AreEqual(Modifiers.Public | Modifiers.Static, md.Modifier); Assert.AreEqual(Modifiers.Public | Modifiers.Static, md.Modifier);
Assert.AreEqual(2, md.StartLocation.Y, "StartLocation.Y"); Assert.AreEqual(2, md.StartLocation.Line, "StartLocation.Y");
Assert.AreEqual(2, md.EndLocation.Y, "EndLocation.Y"); Assert.AreEqual(2, md.EndLocation.Line, "EndLocation.Y");
Assert.AreEqual(2, md.StartLocation.X, "StartLocation.X"); Assert.AreEqual(2, md.StartLocation.Column, "StartLocation.X");
} }
[Test] [Test]

Loading…
Cancel
Save