Browse Source

set location for AST elements (fixes unit tests)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3363 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Markus Palme 18 years ago
parent
commit
b96cbb193a
  1. 1955
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  2. 54
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  3. 13
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNetParser.cs

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

File diff suppressed because it is too large Load Diff

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

@ -590,7 +590,11 @@ EnumBody<TypeDeclaration newType>
(. FieldDeclaration f; .) = (. FieldDeclaration f; .) =
{ EndOfStmt } /* allow empty lines at begin of body */ { EndOfStmt } /* allow empty lines at begin of body */
{ {
EnumMemberDecl<out f> (. compilationUnit.AddChild(f); .) EnumMemberDecl<out f>
(.
SetParent(f.Fields, f);
compilationUnit.AddChild(f);
.)
{ EndOfStmt } /* allow empty lines in body */ { EndOfStmt } /* allow empty lines in body */
} }
"End" "Enum" (. newType.EndLocation = t.EndLocation; .) "End" "Enum" (. newType.EndLocation = t.EndLocation; .)
@ -1016,6 +1020,7 @@ 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 */
@ -1431,6 +1436,7 @@ VariableDeclaratorPartAfterIdentifier<List<VariableDeclaration> fieldDeclaration
type.RankSpecifier = (int[])rank.ToArray(typeof(int)); type.RankSpecifier = (int[])rank.ToArray(typeof(int));
} }
expr = new ArrayCreateExpression(type, dimension); expr = new ArrayCreateExpression(type, dimension);
SetParent(dimension, expr);
} }
} else if (rank != null) { } else if (rank != null) {
if(type.RankSpecifier != null) { if(type.RankSpecifier != null) {
@ -1693,11 +1699,17 @@ InvocationExpression<ref Expression pexpr>
| "(" | "("
ArgumentList<out parameters> ArgumentList<out parameters>
")" ")"
(. pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters); .) (.
pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters);
SetParent(parameters, pexpr);
.)
) )
| ArgumentList<out parameters> | ArgumentList<out parameters>
")" ")"
(. pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters); .) (.
pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters);
SetParent(parameters, pexpr);
.)
) )
(. pexpr.StartLocation = start; pexpr.EndLocation = t.Location; .) (. pexpr.StartLocation = start; pexpr.EndLocation = t.Location; .)
. .
@ -1904,12 +1916,14 @@ ObjectCreateExpression<out Expression oce>
if (type == null) type = new TypeReference("Object"); // fallback type on parser errors if (type == null) type = new TypeReference("Object"); // fallback type on parser errors
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;
} }
.) .)
@ -2108,7 +2122,11 @@ Attribute<out ASTAttribute attribute>
[ "Global" "." ] [ "Global" "." ]
Qualident<out name> Qualident<out name>
[ AttributeArguments<positional, named> ] [ AttributeArguments<positional, named> ]
(. attribute = new ASTAttribute(name, positional, named); .) (.
attribute = new ASTAttribute(name, positional, named);
SetParent(positional, attribute);
SetParent(named, attribute);
.)
. .
/* Spec, 5.2.2 */ /* Spec, 5.2.2 */
@ -2306,6 +2324,7 @@ LocalDeclarationStatement<out Statement statement>
VariableDeclarator<localVariableDeclaration.Variables> VariableDeclarator<localVariableDeclaration.Variables>
{ "," VariableDeclarator<localVariableDeclaration.Variables> } { "," VariableDeclarator<localVariableDeclaration.Variables> }
(. (.
SetParent(localVariableDeclaration.Variables, localVariableDeclaration);
statement = localVariableDeclaration; statement = localVariableDeclaration;
.) .)
. .
@ -2349,7 +2368,10 @@ EmbeddedStatement<out Statement statement>
| /* 10.5.1 */ | /* 10.5.1 */
"RaiseEvent" Identifier (. name = t.val; .) "RaiseEvent" Identifier (. name = t.val; .)
[ "(" [ 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>
| /* 10.5.2 */ | /* 10.5.2 */
@ -2428,11 +2450,16 @@ EmbeddedStatement<out Statement statement>
EndOfStmt Block<out embeddedStatement> EndOfStmt Block<out embeddedStatement>
"Next" "Next"
[ [
Expr<out nextExpr> (. nextExpressions = new List<Expression>(); nextExpressions.Add(nextExpr); .) Expr<out nextExpr>
(.
nextExpressions = new List<Expression>();
nextExpressions.Add(nextExpr);
.)
{ "," Expr<out nextExpr> (. nextExpressions.Add(nextExpr); .) } { "," Expr<out nextExpr> (. nextExpressions.Add(nextExpr); .) }
] ]
(. (.
statement = new ForNextStatement(typeReference, typeName, start, end, step, embeddedStatement, nextExpressions); statement = new ForNextStatement(typeReference, typeName, start, end, step, embeddedStatement, nextExpressions);
SetParent(nextExpressions, statement);
.) .)
) )
| /* 10.10.2.1 */ | /* 10.10.2.1 */
@ -2502,6 +2529,9 @@ 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> ]
@ -2518,6 +2548,7 @@ 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>
@ -2527,7 +2558,10 @@ EmbeddedStatement<out Statement statement>
selectSections.Add(selectSection); selectSections.Add(selectSection);
.) .)
} }
(. statement = new SwitchStatement(expr, selectSections); .) (.
statement = new SwitchStatement(expr, selectSections);
SetParent(selectSections, statement);
.)
"End" "Select" "End" "Select"
| (. OnErrorStatement onErrorStatement = null; .) | (. OnErrorStatement onErrorStatement = null; .)
OnErrorStatement<out onErrorStatement> (. statement = onErrorStatement; .) OnErrorStatement<out onErrorStatement> (. statement = onErrorStatement; .)
@ -2566,7 +2600,10 @@ EmbeddedStatement<out Statement statement>
VariableDeclarator<resourceAquisition.Variables> VariableDeclarator<resourceAquisition.Variables>
} }
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>
(. statement = new UsingStatement(new ExpressionStatement(expr), block); .) (. statement = new UsingStatement(new ExpressionStatement(expr), block); .)
@ -2684,6 +2721,7 @@ 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

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

@ -300,5 +300,18 @@ 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;
}
}
}
} }
} }

Loading…
Cancel
Save