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

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

@ -1515,6 +1515,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
addRegion = value ?? EventAddRegion.Null; addRegion = value ?? EventAddRegion.Null;
if (!addRegion.IsNull) addRegion.Parent = this;
} }
} }
@ -1524,6 +1525,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
removeRegion = value ?? EventRemoveRegion.Null; removeRegion = value ?? EventRemoveRegion.Null;
if (!removeRegion.IsNull) removeRegion.Parent = this;
} }
} }
@ -1533,6 +1535,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
raiseRegion = value ?? EventRaiseRegion.Null; raiseRegion = value ?? EventRaiseRegion.Null;
if (!raiseRegion.IsNull) raiseRegion.Parent = this;
} }
} }
@ -2404,6 +2407,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
getRegion = value ?? PropertyGetRegion.Null; getRegion = value ?? PropertyGetRegion.Null;
if (!getRegion.IsNull) getRegion.Parent = this;
} }
} }
@ -2413,6 +2417,7 @@ namespace ICSharpCode.NRefactory.Ast {
} }
set { set {
setRegion = value ?? PropertySetRegion.Null; setRegion = value ?? PropertySetRegion.Null;
if (!setRegion.IsNull) setRegion.Parent = this;
} }
} }
@ -3339,6 +3344,7 @@ public Location ExtendedEndLocation { get; set; }
} }
set { set {
getRegion = value ?? PropertyGetRegion.Null; getRegion = value ?? PropertyGetRegion.Null;
if (!getRegion.IsNull) getRegion.Parent = this;
} }
} }
@ -3348,6 +3354,7 @@ public Location ExtendedEndLocation { get; set; }
} }
set { set {
setRegion = value ?? PropertySetRegion.Null; 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
} }
} }
} }
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>
Identifier (. newType.Name = t.val; .) Identifier (. newType.Name = t.val; .)
/* .NET 2.0 */ /* .NET 2.0 */
[ TypeParameterList<templates> ] [ TypeParameterList<templates> ] (. SetParentNonNullable(templates, newType); .)
[ 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> ] [ TypeParameterList<templates> ] (. SetParentNonNullable(templates, newType); .)
[ 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> ] [ TypeParameterList<templates> ] (. SetParentNonNullable(templates, newType); .)
[ 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> ] [ TypeParameterList<templates> ] (. SetParentNonNullable(templates, delegateDeclr); .)
"(" [ FormalParameterList<p> (. delegateDeclr.Parameters = p; .) "(" [ FormalParameterList<p> (. delegateDeclr.Parameters = p; .)
] ")" ] ")"
@ -778,6 +778,7 @@ 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)); methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
compilationUnit.AddChild(methodDeclaration); compilationUnit.AddChild(methodDeclaration);
@ -983,6 +984,7 @@ 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> }
@ -1075,6 +1077,7 @@ 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);
.) .)
| ( | (
@ -1093,6 +1096,7 @@ 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: */

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>
newType.Type = ClassType.Class; newType.Type = ClassType.Class;
.) .)
Identifier (. newType.Name = t.val; .) Identifier (. newType.Name = t.val; .)
TypeParameterList<newType.Templates> TypeParameterList<newType.Templates> (. SetParent(newType.Templates, newType); .)
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> TypeParameterList<newType.Templates> (. SetParent(newType.Templates, newType); .)
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> TypeParameterList<newType.Templates> (. SetParent(newType.Templates, newType); .)
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> TypeParameterList<delegateDeclr.Templates> (. SetParent(delegateDeclr.Templates, delegateDeclr); .)
[ "(" [ 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> TypeParameterList<delegateDeclr.Templates> (. SetParent(delegateDeclr.Templates, delegateDeclr); .)
[ "(" [ 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; .)]
) )
@ -683,6 +683,7 @@ InterfaceMemberDecl
EndLocation = t.EndLocation, EndLocation = t.EndLocation,
Templates = templates Templates = templates
}; };
SetParent(templates, md);
compilationUnit.AddChild(md); compilationUnit.AddChild(md);
.) .)
| |
@ -710,6 +711,7 @@ 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
@ -822,6 +824,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause, HandlesClause = handlesClause,
InterfaceImplementations = implementsClause InterfaceImplementations = implementsClause
}; };
SetParent(templates, methodDeclaration);
compilationUnit.AddChild(methodDeclaration); compilationUnit.AddChild(methodDeclaration);
.) .)
| |
@ -835,6 +838,7 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
HandlesClause = handlesClause, HandlesClause = handlesClause,
InterfaceImplementations = implementsClause InterfaceImplementations = implementsClause
}; };
SetParent(templates, methodDeclaration);
compilationUnit.AddChild(methodDeclaration); compilationUnit.AddChild(methodDeclaration);
.) .)
@ -918,6 +922,7 @@ 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);
@ -936,6 +941,7 @@ 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);

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

@ -33,14 +33,13 @@ namespace ICSharpCode.NRefactory.Tests.Ast
protected override void EndVisit(INode node) protected override void EndVisit(INode node)
{ {
Assert.AreEqual(node, nodeStack.Pop(), "nodeStack was corrupted!"); Assert.AreSame(node, nodeStack.Pop(), "nodeStack was corrupted!");
if (StrictCheck if (StrictCheck
|| !(node is TypeReference) && !(node is InterfaceImplementation) || !(node is TypeReference) && !(node is InterfaceImplementation)
&& !(node is PropertyGetSetRegion) && !(node is ParameterDeclarationExpression) && !(node is ParameterDeclarationExpression)
&& !(node is TemplateDefinition) && !(node is EventAddRemoveRegion)
&& !(node is ICSharpCode.NRefactory.Ast.Attribute) && !(node is AttributeSection)) && !(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