Browse Source

NRefactory: set parent property on PropertyGetSetRegion, EventAddRemoveRegion, TemplateDefinition.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3682 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts 3.0-Beta3
Daniel Grunwald 17 years ago
parent
commit
7181ed1237
  1. 4
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs
  2. 7
      src/Libraries/NRefactory/Project/Src/Ast/Generated.cs
  3. 9
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs
  4. 1794
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  5. 12
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  6. 2219
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  7. 16
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  8. 7
      src/Libraries/NRefactory/Test/Parser/CheckParentVisitor.cs

4
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs

@ -51,7 +51,7 @@ namespace NRefactoryASTGenerator.Ast @@ -51,7 +51,7 @@ namespace NRefactoryASTGenerator.Ast
}
[ImplementNullable(NullableImplementation.Abstract)]
abstract class EventAddRemoveRegion : AttributedNode
abstract class EventAddRemoveRegion : AttributedNode, INullable
{
BlockStatement block;
List<ParameterDeclarationExpression> parameters;
@ -192,7 +192,7 @@ namespace NRefactoryASTGenerator.Ast @@ -192,7 +192,7 @@ namespace NRefactoryASTGenerator.Ast
}
[ImplementNullable(NullableImplementation.Abstract)]
abstract class PropertyGetSetRegion : AttributedNode
abstract class PropertyGetSetRegion : AttributedNode, INullable
{
// can be null if only the definition is there (interface declaration)
BlockStatement block;

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

@ -1515,6 +1515,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1515,6 +1515,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
addRegion = value ?? EventAddRegion.Null;
if (!addRegion.IsNull) addRegion.Parent = this;
}
}
@ -1524,6 +1525,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1524,6 +1525,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
removeRegion = value ?? EventRemoveRegion.Null;
if (!removeRegion.IsNull) removeRegion.Parent = this;
}
}
@ -1533,6 +1535,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1533,6 +1535,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
raiseRegion = value ?? EventRaiseRegion.Null;
if (!raiseRegion.IsNull) raiseRegion.Parent = this;
}
}
@ -2404,6 +2407,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2404,6 +2407,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
getRegion = value ?? PropertyGetRegion.Null;
if (!getRegion.IsNull) getRegion.Parent = this;
}
}
@ -2413,6 +2417,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2413,6 +2417,7 @@ namespace ICSharpCode.NRefactory.Ast {
}
set {
setRegion = value ?? PropertySetRegion.Null;
if (!setRegion.IsNull) setRegion.Parent = this;
}
}
@ -3339,6 +3344,7 @@ public Location ExtendedEndLocation { get; set; } @@ -3339,6 +3344,7 @@ public Location ExtendedEndLocation { get; set; }
}
set {
getRegion = value ?? PropertyGetRegion.Null;
if (!getRegion.IsNull) getRegion.Parent = this;
}
}
@ -3348,6 +3354,7 @@ public Location ExtendedEndLocation { get; set; } @@ -3348,6 +3354,7 @@ public Location ExtendedEndLocation { get; set; }
}
set {
setRegion = value ?? PropertySetRegion.Null;
if (!setRegion.IsNull) setRegion.Parent = this;
}
}

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

@ -600,5 +600,14 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -600,5 +600,14 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
}
}
}
static void SetParentNonNullable<T>(List<T> list, INode parent) where T : class, INode
{
if (list != null) {
foreach (T x in list) {
x.Parent = parent;
}
}
}
}
}

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

File diff suppressed because it is too large Load Diff

12
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> ]
[ TypeParameterList<templates> ] (. SetParentNonNullable(templates, newType); .)
[ 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> ]
[ TypeParameterList<templates> ] (. SetParentNonNullable(templates, newType); .)
[ 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> ]
[ TypeParameterList<templates> ] (. SetParentNonNullable(templates, newType); .)
[ 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> ]
[ TypeParameterList<templates> ] (. SetParentNonNullable(templates, delegateDeclr); .)
"(" [ FormalParameterList<p> (. delegateDeclr.Parameters = p; .)
] ")"
@ -778,6 +778,7 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -778,6 +778,7 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
Templates = templates,
IsExtensionMethod = isExtensionMethod
};
SetParentNonNullable(templates, methodDeclaration);
if (explicitInterface != null)
methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
compilationUnit.AddChild(methodDeclaration);
@ -983,6 +984,7 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -983,6 +984,7 @@ StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
methodDeclaration.EndLocation = t.EndLocation;
methodDeclaration.IsExtensionMethod = isExtensionMethod;
methodDeclaration.Templates = templates;
SetParentNonNullable(templates, methodDeclaration);
compilationUnit.AddChild(methodDeclaration);
.)
{ TypeParameterConstraintsClause<templates> }
@ -1075,6 +1077,7 @@ InterfaceMemberDecl @@ -1075,6 +1077,7 @@ InterfaceMemberDecl
Parameters = parameters, Attributes = attributes, Templates = templates,
StartLocation = startLocation, EndLocation = t.EndLocation
};
SetParentNonNullable(templates, md);
compilationUnit.AddChild(md);
.)
| (
@ -1093,6 +1096,7 @@ InterfaceMemberDecl @@ -1093,6 +1096,7 @@ InterfaceMemberDecl
Parameters = parameters, Attributes = attributes, Templates = templates,
StartLocation = startLocation, EndLocation = t.EndLocation
};
SetParentNonNullable(templates, md);
compilationUnit.AddChild(md);
.)
/*--- interface property declaration: */

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

File diff suppressed because it is too large Load Diff

16
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>
TypeParameterList<newType.Templates> (. SetParent(newType.Templates, newType); .)
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>
TypeParameterList<newType.Templates> (. SetParent(newType.Templates, newType); .)
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>
TypeParameterList<newType.Templates> (. SetParent(newType.Templates, newType); .)
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>
TypeParameterList<delegateDeclr.Templates> (. SetParent(delegateDeclr.Templates, delegateDeclr); .)
[ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ]
|
"Function" Identifier (. delegateDeclr.Name = t.val; .)
TypeParameterList<delegateDeclr.Templates>
TypeParameterList<delegateDeclr.Templates> (. SetParent(delegateDeclr.Templates, delegateDeclr); .)
[ "(" [ FormalParameterList<p> ] ")" (. delegateDeclr.Parameters = p; .) ]
[ "As" (. TypeReference type; .) TypeName<out type> (. delegateDeclr.ReturnType = type; .)]
)
@ -683,6 +683,7 @@ InterfaceMemberDecl @@ -683,6 +683,7 @@ InterfaceMemberDecl
EndLocation = t.EndLocation,
Templates = templates
};
SetParent(templates, md);
compilationUnit.AddChild(md);
.)
|
@ -710,6 +711,7 @@ InterfaceMemberDecl @@ -710,6 +711,7 @@ InterfaceMemberDecl
md.StartLocation = startLocation;
md.EndLocation = t.EndLocation;
md.Templates = templates;
SetParent(templates, md);
compilationUnit.AddChild(md);
.)
EndOfStmt
@ -822,6 +824,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -822,6 +824,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause,
InterfaceImplementations = implementsClause
};
SetParent(templates, methodDeclaration);
compilationUnit.AddChild(methodDeclaration);
.)
|
@ -835,6 +838,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -835,6 +838,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause,
InterfaceImplementations = implementsClause
};
SetParent(templates, methodDeclaration);
compilationUnit.AddChild(methodDeclaration);
.)
@ -918,6 +922,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -918,6 +922,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
Templates = templates,
InterfaceImplementations = implementsClause
};
SetParent(templates, methodDeclaration);
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection);
@ -936,6 +941,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -936,6 +941,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause,
InterfaceImplementations = implementsClause
};
SetParent(templates, methodDeclaration);
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection);

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

@ -33,14 +33,13 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -33,14 +33,13 @@ namespace ICSharpCode.NRefactory.Tests.Ast
protected override void EndVisit(INode node)
{
Assert.AreEqual(node, nodeStack.Pop(), "nodeStack was corrupted!");
Assert.AreSame(node, nodeStack.Pop(), "nodeStack was corrupted!");
if (StrictCheck
|| !(node is TypeReference) && !(node is InterfaceImplementation)
&& !(node is PropertyGetSetRegion) && !(node is ParameterDeclarationExpression)
&& !(node is TemplateDefinition) && !(node is EventAddRemoveRegion)
&& !(node is ParameterDeclarationExpression)
&& !(node is ICSharpCode.NRefactory.Ast.Attribute) && !(node is AttributeSection))
{
Assert.AreEqual(nodeStack.Peek(), node.Parent, "node " + node + " is missing parent: " + nodeStack.Peek());
Assert.AreSame(nodeStack.Peek(), node.Parent, "node " + node + " is missing parent: " + nodeStack.Peek());
}
}
}

Loading…
Cancel
Save