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

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

@ -377,8 +377,12 @@ namespace NRefactoryASTGenerator @@ -377,8 +377,12 @@ namespace NRefactoryASTGenerator
else
ex = GetDefaultValue("value", field);
p.Setter.Assign(Easy.Var(field.Name), ex);
if (typeof(INode).IsAssignableFrom(field.FieldType) && typeof(INullable).IsAssignableFrom(field.FieldType)) {
p.SetStatements.Add(new CodeSnippetStatement("\t\t\t\tif (!" +field.Name+".IsNull) "+field.Name+".Parent = this;"));
if (typeof(INode).IsAssignableFrom(field.FieldType)) {
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)) {

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

@ -109,6 +109,7 @@ @@ -109,6 +109,7 @@
<Compile Include="Src\Visitors\LookupTableVisitor.cs" />
<Compile Include="Src\Visitors\PrefixFieldsVisitor.cs" />
<Compile Include="Src\Visitors\RenameIdentifierVisitor.cs" />
<Compile Include="Src\Visitors\SetParentVisitor.cs" />
<Compile Include="Src\Visitors\ToCSharpConvertVisitor.cs" />
<Compile Include="Src\Visitors\ToVBNetConvertVisitor.cs" />
<Compile Include="Src\Visitors\ToVBNetRenameConflictingVariables.cs" />
@ -138,7 +139,6 @@ @@ -138,7 +139,6 @@
<Folder Include="Src\Parser" />
<Folder Include="Src\Parser\CSharp" />
<Content Include="Src\Parser\CSharp\cs.ATG" />
<Content Include="Src\Parser\CSharp\trace.txt" />
<Folder Include="Src\Parser\Frames" />
<Content Include="Src\Parser\Frames\Parser.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 @@ -22,6 +22,7 @@ namespace ICSharpCode.NRefactory.Ast
}
set {
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 { @@ -144,6 +144,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
createType = value ?? TypeReference.Null;
if (!createType.IsNull) createType.Parent = this;
}
}
@ -555,6 +556,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -555,6 +556,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
castTo = value ?? TypeReference.Null;
if (!castTo.IsNull) castTo.Parent = this;
}
}
@ -613,6 +615,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -613,6 +615,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -1052,6 +1055,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1052,6 +1055,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -1086,6 +1090,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1086,6 +1090,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -1127,6 +1132,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1127,6 +1132,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
returnType = value ?? TypeReference.Null;
if (!returnType.IsNull) returnType.Parent = this;
}
}
@ -1752,6 +1758,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1752,6 +1758,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
type = value ?? TypeReference.Null;
if (!type.IsNull) type.Parent = this;
}
}
@ -1840,6 +1847,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1840,6 +1847,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -1938,6 +1946,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1938,6 +1946,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -2057,6 +2066,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2057,6 +2066,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -2380,6 +2390,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2380,6 +2390,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -2531,6 +2542,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2531,6 +2542,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
interfaceType = value ?? TypeReference.Null;
if (!interfaceType.IsNull) interfaceType.Parent = this;
}
}
@ -2730,6 +2742,7 @@ public Location ExtendedEndLocation { get; set; } @@ -2730,6 +2742,7 @@ public Location ExtendedEndLocation { get; set; }
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -2949,6 +2962,7 @@ public Location ExtendedEndLocation { get; set; } @@ -2949,6 +2962,7 @@ public Location ExtendedEndLocation { get; set; }
}
set {
createType = value ?? TypeReference.Null;
if (!createType.IsNull) createType.Parent = this;
}
}
@ -3138,6 +3152,7 @@ public Location ExtendedEndLocation { get; set; } @@ -3138,6 +3152,7 @@ public Location ExtendedEndLocation { get; set; }
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -3787,6 +3802,7 @@ public Location ExtendedEndLocation { get; set; } @@ -3787,6 +3802,7 @@ public Location ExtendedEndLocation { get; set; }
}
set {
type = value ?? TypeReference.Null;
if (!type.IsNull) type.Parent = this;
}
}
@ -4558,6 +4574,7 @@ public Location ExtendedEndLocation { get; set; } @@ -4558,6 +4574,7 @@ public Location ExtendedEndLocation { get; set; }
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -4586,6 +4603,7 @@ public Location ExtendedEndLocation { get; set; } @@ -4586,6 +4603,7 @@ public Location ExtendedEndLocation { get; set; }
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -4914,6 +4932,7 @@ public Location ExtendedEndLocation { get; set; } @@ -4914,6 +4932,7 @@ public Location ExtendedEndLocation { get; set; }
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -4952,6 +4971,7 @@ public Location ExtendedEndLocation { get; set; } @@ -4952,6 +4971,7 @@ public Location ExtendedEndLocation { get; set; }
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -4979,6 +4999,7 @@ public Location ExtendedEndLocation { get; set; } @@ -4979,6 +4999,7 @@ public Location ExtendedEndLocation { get; set; }
}
set {
typeReference = value ?? TypeReference.Null;
if (!typeReference.IsNull) typeReference.Parent = this;
}
}
@ -5143,6 +5164,7 @@ public Location ExtendedEndLocation { get; set; } @@ -5143,6 +5164,7 @@ public Location ExtendedEndLocation { get; set; }
}
set {
alias = value ?? TypeReference.Null;
if (!alias.IsNull) alias.Parent = this;
}
}
@ -5264,6 +5286,7 @@ public UsingDeclaration(string @namespace, TypeReference alias) { usings = new L @@ -5264,6 +5286,7 @@ public UsingDeclaration(string @namespace, TypeReference alias) { usings = new L
}
set {
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 @@ -374,6 +374,10 @@ namespace ICSharpCode.NRefactory.Ast
return true;
}
}
public override TypeReference Clone()
{
return this;
}
public override object AcceptVisitor(IAstVisitor visitor, object data)
{
return null;
@ -402,7 +406,7 @@ namespace ICSharpCode.NRefactory.Ast @@ -402,7 +406,7 @@ namespace ICSharpCode.NRefactory.Ast
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);
return c;
}

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

@ -507,7 +507,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -507,7 +507,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
Location start = new Location(Col - 1, Line);
string directive = ReadIdent('#');
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()

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

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

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

@ -5,11 +5,11 @@ @@ -5,11 +5,11 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.NRefactory.Visitors;
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Text;
using ICSharpCode.NRefactory.Ast;
namespace ICSharpCode.NRefactory.Parser.CSharp
@ -50,6 +50,12 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -50,6 +50,12 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
errDist = 0;
}
public override void Parse()
{
ParseRoot();
compilationUnit.AcceptVisitor(new SetParentVisitor(), null);
}
public override Expression ParseExpression()
{
lexer.NextToken();
@ -61,6 +67,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -61,6 +67,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
if (expr != null) {
expr.StartLocation = startLocation;
expr.EndLocation = t.EndLocation;
expr.AcceptVisitor(new SetParentVisitor(), null);
}
Expect(Tokens.EOF);
return expr;
@ -87,6 +94,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -87,6 +94,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
compilationUnit.BlockEnd();
blockStmt.EndLocation = t.EndLocation;
Expect(Tokens.EOF);
blockStmt.AcceptVisitor(new SetParentVisitor(), null);
return blockStmt;
}
@ -100,6 +108,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -100,6 +108,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
ClassBody();
compilationUnit.BlockEnd();
Expect(Tokens.EOF);
newType.AcceptVisitor(new SetParentVisitor(), null);
return newType.Children;
}
@ -590,24 +599,5 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -590,24 +599,5 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
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> @@ -364,7 +364,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
Identifier (. newType.Name = t.val; .)
/* .NET 2.0 */
[ TypeParameterList<templates> ] (. SetParentNonNullable(templates, newType); .)
[ TypeParameterList<templates> ]
[ ClassBase<out names> (. newType.BaseTypes = names; .) ]
@ -389,7 +389,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes> @@ -389,7 +389,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
Identifier (. newType.Name = t.val; .)
/* .NET 2.0 */
[ TypeParameterList<templates> ] (. SetParentNonNullable(templates, newType); .)
[ TypeParameterList<templates> ]
[ StructInterfaces<out names> (. newType.BaseTypes = names; .) ]
@ -413,7 +413,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes> @@ -413,7 +413,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
Identifier (. newType.Name = t.val; .)
/* .NET 2.0 */
[ TypeParameterList<templates> ] (. SetParentNonNullable(templates, newType); .)
[ TypeParameterList<templates> ]
[ InterfaceBase<out names> (. newType.BaseTypes = names; .) ]
@ -451,7 +451,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes> @@ -451,7 +451,7 @@ TypeDecl<ModifierList m, List<AttributeSection> attributes>
Identifier (. delegateDeclr.Name = t.val; .)
/* .NET 2.0 */
[ TypeParameterList<templates> ] (. SetParentNonNullable(templates, delegateDeclr); .)
[ TypeParameterList<templates> ]
"(" [ FormalParameterList<p> (. delegateDeclr.Parameters = p; .)
] ")"
@ -778,9 +778,8 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -778,9 +778,8 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
Templates = templates,
IsExtensionMethod = isExtensionMethod
};
SetParentNonNullable(templates, methodDeclaration);
if (explicitInterface != null)
methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
SafeAdd(methodDeclaration, methodDeclaration.InterfaceImplementations, new InterfaceImplementation(explicitInterface, qualident));
compilationUnit.AddChild(methodDeclaration);
compilationUnit.BlockStart(methodDeclaration);
.)
@ -833,7 +832,7 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -833,7 +832,7 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
[ (. m.Check(Modifiers.Constructors); .)
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.EndLocation = t.EndLocation;
.)
@ -865,7 +864,6 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -865,7 +864,6 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
StartLocation = m.GetDeclarationLocation(startPos),
EndLocation = endPos
};
SetParent(parameters, operatorDeclaration);
compilationUnit.AddChild(operatorDeclaration);
.)
@ -892,22 +890,19 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -892,22 +890,19 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
(. Location endPos = t.Location; .)
")" ( 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 {
Modifier = m.Modifier,
Attributes = attributes,
Parameters = parameters,
TypeReference = type,
OverloadableOperator = op,
Body = (BlockStatement)stmt,
StartLocation = m.GetDeclarationLocation(startPos),
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);
.)
@ -984,7 +979,6 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -984,7 +979,6 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
methodDeclaration.EndLocation = t.EndLocation;
methodDeclaration.IsExtensionMethod = isExtensionMethod;
methodDeclaration.Templates = templates;
SetParentNonNullable(templates, methodDeclaration);
compilationUnit.AddChild(methodDeclaration);
.)
{ TypeParameterConstraintsClause<templates> }
@ -1016,7 +1010,7 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1016,7 +1010,7 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
indexer.StartLocation = m.GetDeclarationLocation(startPos);
indexer.EndLocation = t.EndLocation;
if (explicitInterface != null)
indexer.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, "this"));
SafeAdd(indexer, indexer.InterfaceImplementations, new InterfaceImplementation(explicitInterface, "this"));
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
.)
@ -1066,7 +1060,7 @@ InterfaceMemberDecl @@ -1066,7 +1060,7 @@ InterfaceMemberDecl
[ "new" (. mod = Modifiers.New; startLocation = t.Location; .) ]
(
/*--- 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; .)
[ TypeParameterList<templates> ]
"(" [ FormalParameterList<parameters> ] ")"
@ -1077,11 +1071,10 @@ InterfaceMemberDecl @@ -1077,11 +1071,10 @@ InterfaceMemberDecl
Parameters = parameters, Attributes = attributes, Templates = templates,
StartLocation = startLocation, EndLocation = t.EndLocation
};
SetParentNonNullable(templates, 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; .)
(
@ -1096,26 +1089,37 @@ InterfaceMemberDecl @@ -1096,26 +1089,37 @@ InterfaceMemberDecl
Parameters = parameters, Attributes = attributes, Templates = templates,
StartLocation = startLocation, EndLocation = t.EndLocation
};
SetParentNonNullable(templates, md);
compilationUnit.AddChild(md);
.)
/*--- 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: */
| "this" "[" FormalParameterList<parameters> "]" (.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;.)
| "this" "[" FormalParameterList<parameters> "]"
(. 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: */
| "event" (. if (startLocation.X == -1) startLocation = t.Location; .)
| "event" (. if (startLocation.IsEmpty) startLocation = t.Location; .)
Type<out type> Identifier
(. EventDeclaration ed = new EventDeclaration {
TypeReference = type, Name = t.val, Modifier = mod, Attributes = attributes
};
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> @@ -1507,7 +1511,6 @@ EmbeddedStatement<out Statement statement>
"{" SwitchSections<switchSections>
"}"
(. statement = new SwitchStatement(expr, switchSections); .)
(. SetParent(switchSections, statement); .)
/*--- iteration statements (while, do, for, foreach): */
| "while" "(" Expr<out expr> ")"
@ -1523,10 +1526,7 @@ EmbeddedStatement<out Statement statement> @@ -1523,10 +1526,7 @@ EmbeddedStatement<out Statement statement>
[ Expr<out expr> ] ";"
[ ForIterator<out iterator> ] ")"
EmbeddedStatement<out embeddedStatement>
(. statement = new ForStatement(initializer, expr, iterator, embeddedStatement);
SetParent(initializer, statement);
SetParent(iterator, statement);
.)
(. statement = new ForStatement(initializer, expr, iterator, embeddedStatement); .)
| "foreach" "(" Type<out type> Identifier (. string varName = t.val; .)
"in" Expr<out expr> ")"
@ -1597,8 +1597,6 @@ IfStatement<out Statement statement> @@ -1597,8 +1597,6 @@ IfStatement<out Statement statement>
(elseStatement as IfElseStatement).TrueStatement[0]));
(statement as IfElseStatement).ElseIfSections.AddRange((elseStatement as IfElseStatement).ElseIfSections);
(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> @@ -2049,7 +2047,7 @@ ShortedLambdaExpression<IdentifierExpression ident, out Expression pexpr>
/* not an IdentifierExpression, but a short lambda expression*/
(.
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].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 @@ -22,7 +22,7 @@ partial class Parser : AbstractParser
-->productions
public override void Parse()
void ParseRoot()
{
-->parseRoot
}

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

@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.Parser @@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.Parser
public Location GetDeclarationLocation(Location keywordLocation)
{
if(location.X == -1 && location.Y == -1) {
if(location.IsEmpty) {
return keywordLocation;
}
return location;
@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.Parser @@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.Parser
public void Add(Modifiers m, Location tokenLocation)
{
if(location.X == -1 && location.Y == -1) {
if(location.IsEmpty) {
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> @@ -437,7 +437,7 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
newType.Type = ClassType.Class;
.)
Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates> (. SetParent(newType.Templates, newType); .)
TypeParameterList<newType.Templates>
EndOfStmt
(. newType.BodyStartLocation = t.Location; .)
[ ClassBaseType<out typeRef> (. newType.BaseTypes.Add(typeRef); .) ]
@ -474,7 +474,7 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes> @@ -474,7 +474,7 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
newType.Type = ClassType.Struct;
.)
Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates> (. SetParent(newType.Templates, newType); .)
TypeParameterList<newType.Templates>
EndOfStmt
(. newType.BodyStartLocation = t.Location; .)
{ TypeImplementsClause<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces);.) }
@ -512,7 +512,7 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes> @@ -512,7 +512,7 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
newType.Type = ClassType.Interface;
.)
Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates> (. SetParent(newType.Templates, newType); .)
TypeParameterList<newType.Templates>
EndOfStmt
(. newType.BodyStartLocation = t.Location; .)
{ InterfaceBase<out baseInterfaces> (. newType.BaseTypes.AddRange(baseInterfaces); .) }
@ -531,11 +531,11 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes> @@ -531,11 +531,11 @@ NonModuleDeclaration<ModifierList m, List<AttributeSection> attributes>
.)
(
"Sub" Identifier (. delegateDeclr.Name = t.val; .)
TypeParameterList<delegateDeclr.Templates> (. SetParent(delegateDeclr.Templates, delegateDeclr); .)
TypeParameterList<delegateDeclr.Templates>
[ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ]
|
"Function" Identifier (. delegateDeclr.Name = t.val; .)
TypeParameterList<delegateDeclr.Templates> (. SetParent(delegateDeclr.Templates, delegateDeclr); .)
TypeParameterList<delegateDeclr.Templates>
[ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ]
[ "As" (. TypeReference type; .) TypeName<out type> (. delegateDeclr.ReturnType = type; .)]
)
@ -609,7 +609,6 @@ EnumBody<TypeDeclaration newType> @@ -609,7 +609,6 @@ EnumBody<TypeDeclaration newType>
{
EnumMemberDecl<out f>
(.
SetParent(f.Fields, f);
compilationUnit.AddChild(f);
.)
{ EndOfStmt } /* allow empty lines in body */
@ -683,7 +682,6 @@ InterfaceMemberDecl @@ -683,7 +682,6 @@ InterfaceMemberDecl
EndLocation = t.EndLocation,
Templates = templates
};
SetParent(templates, md);
compilationUnit.AddChild(md);
.)
|
@ -711,7 +709,6 @@ InterfaceMemberDecl @@ -711,7 +709,6 @@ InterfaceMemberDecl
md.StartLocation = startLocation;
md.EndLocation = t.EndLocation;
md.Templates = templates;
SetParent(templates, md);
compilationUnit.AddChild(md);
.)
EndOfStmt
@ -824,7 +821,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -824,7 +821,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause,
InterfaceImplementations = implementsClause
};
SetParent(templates, methodDeclaration);
compilationUnit.AddChild(methodDeclaration);
.)
|
@ -838,7 +834,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -838,7 +834,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause,
InterfaceImplementations = implementsClause
};
SetParent(templates, methodDeclaration);
compilationUnit.AddChild(methodDeclaration);
.)
@ -873,7 +868,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -873,7 +868,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
(. Location endLocation = t.EndLocation; .)
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.EndLocation = constructorEndLocation;
cd.Body = (BlockStatement)stmt;
@ -922,7 +917,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -922,7 +917,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
Templates = templates,
InterfaceImplementations = implementsClause
};
SetParent(templates, methodDeclaration);
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection);
@ -941,7 +935,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -941,7 +935,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause,
InterfaceImplementations = implementsClause
};
SetParent(templates, methodDeclaration);
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection);
@ -1043,7 +1036,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1043,7 +1036,6 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
(.
fd.EndLocation = t.EndLocation;
fd.Fields = variableDeclarators;
SetParent(variableDeclarators, fd);
compilationUnit.AddChild(fd);
.)
| /* 9.4 */
@ -1425,9 +1417,9 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration @@ -1425,9 +1417,9 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration
IF (IsObjectCreation()) "As" ObjectCreateExpression<out expr>
(.
if (expr is ObjectCreateExpression) {
type = ((ObjectCreateExpression)expr).CreateType;
type = ((ObjectCreateExpression)expr).CreateType.Clone();
} else {
type = ((ArrayCreateExpression)expr).CreateType;
type = ((ArrayCreateExpression)expr).CreateType.Clone();
}
.)
|
@ -1458,8 +1450,7 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration @@ -1458,8 +1450,7 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration
rank.Insert(0, dimension.Count - 1);
type.RankSpecifier = (int[])rank.ToArray(typeof(int));
}
expr = new ArrayCreateExpression(type, dimension);
SetParent(dimension, expr);
expr = new ArrayCreateExpression(type.Clone(), dimension);
}
} else if (rank != null) {
if(type.RankSpecifier != null) {
@ -1757,7 +1748,6 @@ InvocationExpression<ref Expression pexpr> @@ -1757,7 +1748,6 @@ InvocationExpression<ref Expression pexpr>
")"
(.
pexpr = new InvocationExpression(pexpr, parameters);
SetParent(parameters, pexpr);
.)
(. pexpr.StartLocation = start; pexpr.EndLocation = t.Location; .)
.
@ -1965,14 +1955,12 @@ ObjectCreateExpression<out Expression oce> @@ -1965,14 +1955,12 @@ ObjectCreateExpression<out Expression oce>
(.
if (initializer == null) {
oce = new ObjectCreateExpression(type, arguments);
SetParent(arguments, oce);
} else {
if (dimensions == null) dimensions = new ArrayList();
dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0));
type.RankSpecifier = (int[])dimensions.ToArray(typeof(int));
ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as CollectionInitializerExpression);
ace.Arguments = arguments;
SetParent(arguments, ace);
oce = ace;
}
.)
@ -2119,10 +2107,6 @@ GroupByQueryOperator<out QueryExpressionGroupVBClause groupByClause> @@ -2119,10 +2107,6 @@ GroupByQueryOperator<out QueryExpressionGroupVBClause groupByClause>
"By" ExpressionRangeVariableDeclarationList<groupByClause.ByVariables>
"Into" ExpressionRangeVariableDeclarationList<groupByClause.IntoVariables>
(.
SetParent(groupByClause.GroupVariables, groupByClause);
SetParent(groupByClause.ByVariables, groupByClause);
SetParent(groupByClause.IntoVariables, groupByClause);
groupByClause.EndLocation = t.EndLocation;
.)
.
@ -2154,7 +2138,6 @@ SelectQueryOperator<List<QueryExpressionClause> middleClauses> @@ -2154,7 +2138,6 @@ SelectQueryOperator<List<QueryExpressionClause> middleClauses>
.) =
"Select" ExpressionRangeVariableDeclarationList<selectClause.Variables>
(.
SetParent(selectClause.Variables, selectClause);
selectClause.EndLocation = t.Location;
middleClauses.Add(selectClause);
.)
@ -2219,10 +2202,8 @@ AggregateQueryOperator<List<QueryExpressionClause> middleClauses> @@ -2219,10 +2202,8 @@ AggregateQueryOperator<List<QueryExpressionClause> middleClauses>
{
QueryOperator<aggregateClause.MiddleClauses>
}
(. SetParent(aggregateClause.MiddleClauses, aggregateClause); .)
"Into" ExpressionRangeVariableDeclarationList<aggregateClause.IntoVariables>
(.
SetParent(aggregateClause.IntoVariables, aggregateClause);
aggregateClause.EndLocation = t.EndLocation;
middleClauses.Add(aggregateClause);
.)
@ -2570,8 +2551,6 @@ Attribute<out ASTAttribute attribute> @@ -2570,8 +2551,6 @@ Attribute<out ASTAttribute attribute>
[ AttributeArguments<positional, named> ]
(.
attribute = new ASTAttribute(name, positional, named);
SetParent(positional, attribute);
SetParent(named, attribute);
.)
.
@ -2769,7 +2748,6 @@ LocalDeclarationStatement<out Statement statement> @@ -2769,7 +2748,6 @@ LocalDeclarationStatement<out Statement statement>
VariableDeclarator<localVariableDeclaration.Variables>
{ "," VariableDeclarator<localVariableDeclaration.Variables> }
(.
SetParent(localVariableDeclaration.Variables, localVariableDeclaration);
statement = localVariableDeclaration;
.)
.
@ -2815,7 +2793,6 @@ EmbeddedStatement<out Statement statement> @@ -2815,7 +2793,6 @@ EmbeddedStatement<out Statement statement>
[ "(" [ ArgumentList<out p> ] ")" ]
(.
statement = new RaiseEventStatement(name, p);
SetParent(p, statement);
.)
| /* 10.3 */
WithStatement<out statement>
@ -2920,7 +2897,6 @@ EmbeddedStatement<out Statement statement> @@ -2920,7 +2897,6 @@ EmbeddedStatement<out Statement statement>
EmbeddedStatement = embeddedStatement,
NextExpressions = nextExpressions
};
SetParent(nextExpressions, statement);
.)
)
| /* 10.10.2.1 */
@ -2991,9 +2967,6 @@ EmbeddedStatement<out Statement statement> @@ -2991,9 +2967,6 @@ EmbeddedStatement<out Statement statement>
ifStatement.StartLocation = ifStartLocation;
.)
SingleLineStatementList<ifStatement.TrueStatement>
(.
SetParent(ifStatement.TrueStatement, ifStatement);
.)
[
"Else"
[ SingleLineStatementList<ifStatement.FalseStatement> ]
@ -3010,7 +2983,6 @@ EmbeddedStatement<out Statement statement> @@ -3010,7 +2983,6 @@ EmbeddedStatement<out Statement statement>
"Case" CaseClauses<out caseClauses> [ IF(IsNotStatementSeparator()) ":" ] EndOfStmt
(.
SwitchSection selectSection = new SwitchSection(caseClauses);
SetParent(caseClauses, selectSection);
selectSection.StartLocation = caseLocation;
.)
Block<out block>
@ -3022,7 +2994,6 @@ EmbeddedStatement<out Statement statement> @@ -3022,7 +2994,6 @@ EmbeddedStatement<out Statement statement>
}
(.
statement = new SwitchStatement(expr, selectSections);
SetParent(selectSections, statement);
.)
"End" "Select"
| (. OnErrorStatement onErrorStatement = null; .)
@ -3064,7 +3035,6 @@ EmbeddedStatement<out Statement statement> @@ -3064,7 +3035,6 @@ EmbeddedStatement<out Statement statement>
Block<out block>
(.
statement = new UsingStatement(resourceAquisition, block);
SetParent(resourceAquisition.Variables, resourceAquisition);
.)
| Expr<out expr>
Block<out block>
@ -3184,7 +3154,6 @@ ReDimClauseInternal<ref Expression expr> @@ -3184,7 +3154,6 @@ ReDimClauseInternal<ref Expression expr>
NormalOrReDimArgumentList<out arguments, out canBeNormal, out canBeRedim>
")"
(. expr = new InvocationExpression(expr, arguments);
SetParent(arguments, expr);
if (canBeRedim == false || canBeNormal && (la.kind == Tokens.Dot || la.kind == Tokens.OpenParenthesis)) {
if (this.Errors.Count == 0) {
// 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 @@ @@ -5,11 +5,11 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.NRefactory.Visitors;
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Text;
using ICSharpCode.NRefactory.Ast;
namespace ICSharpCode.NRefactory.Parser.VB
@ -59,6 +59,12 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -59,6 +59,12 @@ namespace ICSharpCode.NRefactory.Parser.VB
errDist = 0;
}
public override void Parse()
{
ParseRoot();
compilationUnit.AcceptVisitor(new SetParentVisitor(), null);
}
public override Expression ParseExpression()
{
lexer.NextToken();
@ -69,6 +75,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -69,6 +75,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
if (expr != null) {
expr.StartLocation = startLocation;
expr.EndLocation = t.EndLocation;
expr.AcceptVisitor(new SetParentVisitor(), null);
}
Expect(Tokens.EOF);
return expr;
@ -88,6 +95,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -88,6 +95,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
st.EndLocation = t.EndLocation;
else
st.EndLocation = la.Location;
st.AcceptVisitor(new SetParentVisitor(), null);
}
Expect(Tokens.EOF);
return st as BlockStatement;
@ -103,6 +111,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -103,6 +111,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
ClassBody(newType);
compilationUnit.BlockEnd();
Expect(Tokens.EOF);
newType.AcceptVisitor(new SetParentVisitor(), null);
return newType.Children;
}
@ -306,18 +315,5 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -306,18 +315,5 @@ namespace ICSharpCode.NRefactory.Parser.VB
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 @@ -78,7 +78,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
void Error(INode node, string message)
{
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)

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

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

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

@ -0,0 +1,37 @@ @@ -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 @@ -19,8 +19,6 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
Stack<INode> nodeStack = new Stack<INode>();
public bool StrictCheck;
public CheckParentVisitor()
{
nodeStack.Push(null);
@ -34,13 +32,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -34,13 +32,7 @@ namespace ICSharpCode.NRefactory.Tests.Ast
protected override void EndVisit(INode node)
{
Assert.AreSame(node, nodeStack.Pop(), "nodeStack was corrupted!");
if (StrictCheck
|| !(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());
}
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 @@ -31,11 +31,11 @@ namespace ICSharpCode.NRefactory.Tests.Ast
{
const string program = "class MyClass\n{\n}\n";
TypeDeclaration td = ParseUtilCSharp.ParseGlobal<TypeDeclaration>(program);
Assert.AreEqual(1, td.StartLocation.Y, "StartLocation.Y");
Assert.AreEqual(1, td.StartLocation.X, "StartLocation.X");
Assert.AreEqual(1, td.BodyStartLocation.Y, "BodyStartLocation.Y");
Assert.AreEqual(14, td.BodyStartLocation.X, "BodyStartLocation.X");
Assert.AreEqual(3, td.EndLocation.Y, "EndLocation.Y");
Assert.AreEqual(1, td.StartLocation.Line, "StartLocation.Y");
Assert.AreEqual(1, td.StartLocation.Column, "StartLocation.X");
Assert.AreEqual(1, td.BodyStartLocation.Line, "BodyStartLocation.Y");
Assert.AreEqual(14, td.BodyStartLocation.Column, "BodyStartLocation.X");
Assert.AreEqual(3, td.EndLocation.Line, "EndLocation.Y");
}
[Test]
@ -190,10 +190,10 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -190,10 +190,10 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual("TestClass", td.Name);
Assert.AreEqual(ClassType.Class, td.Type);
Assert.AreEqual(1, td.StartLocation.Y, "start line");
Assert.AreEqual(1, td.BodyStartLocation.Y, "bodystart line");
Assert.AreEqual(16, td.BodyStartLocation.X, "bodystart col");
Assert.AreEqual(2, td.EndLocation.Y, "end line");
Assert.AreEqual(1, td.StartLocation.Line, "start line");
Assert.AreEqual(1, td.BodyStartLocation.Line, "bodystart line");
Assert.AreEqual(16, td.BodyStartLocation.Column, "bodystart col");
Assert.AreEqual(2, td.EndLocation.Line, "end line");
}
[Test]
@ -254,8 +254,8 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 @@ -254,8 +254,8 @@ public abstract class MyClass : MyBase, Interface1, My.Test.Interface2
Assert.AreEqual("TestClass", td.Name);
Assert.AreEqual(ClassType.Class, td.Type);
Assert.AreEqual(1, td.StartLocation.Y, "start line");
Assert.AreEqual(2, td.EndLocation.Y, "end line");
Assert.AreEqual(1, td.StartLocation.Line, "start line");
Assert.AreEqual(2, td.EndLocation.Line, "end line");
}
[Test]

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

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

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

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

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

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

Loading…
Cancel
Save