Browse Source

* Src/Visitors/LookupTableVisitor.cs: Added IsQueryContinuation flag

to local lookup variables. This helps resolving the type of "from
  ... where ... into VAR" constructs.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3927 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Mike Krüger 17 years ago
parent
commit
5705bb78c5
  1. 35
      src/Libraries/NRefactory/Project/Src/Visitors/LookupTableVisitor.cs

35
src/Libraries/NRefactory/Project/Src/Visitors/LookupTableVisitor.cs

@ -22,8 +22,9 @@ namespace ICSharpCode.NRefactory.Visitors
public readonly bool IsLoopVariable; public readonly bool IsLoopVariable;
public readonly Expression Initializer; public readonly Expression Initializer;
public readonly LambdaExpression ParentLambdaExpression; public readonly LambdaExpression ParentLambdaExpression;
public readonly bool IsQueryContinuation;
public LocalLookupVariable(string name, TypeReference typeRef, Location startPos, Location endPos, bool isConst, bool isLoopVariable, Expression initializer, LambdaExpression parentLambdaExpression) public LocalLookupVariable(string name, TypeReference typeRef, Location startPos, Location endPos, bool isConst, bool isLoopVariable, Expression initializer, LambdaExpression parentLambdaExpression, bool isQueryContinuation)
{ {
this.Name = name; this.Name = name;
this.TypeRef = typeRef; this.TypeRef = typeRef;
@ -33,7 +34,9 @@ namespace ICSharpCode.NRefactory.Visitors
this.IsLoopVariable = isLoopVariable; this.IsLoopVariable = isLoopVariable;
this.Initializer = initializer; this.Initializer = initializer;
this.ParentLambdaExpression = parentLambdaExpression; this.ParentLambdaExpression = parentLambdaExpression;
this.IsQueryContinuation = isQueryContinuation;
} }
} }
public sealed class LookupTableVisitor : AbstractAstVisitor public sealed class LookupTableVisitor : AbstractAstVisitor
@ -69,7 +72,8 @@ namespace ICSharpCode.NRefactory.Visitors
public void AddVariable(TypeReference typeRef, string name, public void AddVariable(TypeReference typeRef, string name,
Location startPos, Location endPos, bool isConst, Location startPos, Location endPos, bool isConst,
bool isLoopVariable, Expression initializer, bool isLoopVariable, Expression initializer,
LambdaExpression parentLambdaExpression) LambdaExpression parentLambdaExpression,
bool isQueryContinuation)
{ {
if (name == null || name.Length == 0) { if (name == null || name.Length == 0) {
return; return;
@ -80,7 +84,7 @@ namespace ICSharpCode.NRefactory.Visitors
} else { } else {
list = (List<LocalLookupVariable>)variables[name]; list = (List<LocalLookupVariable>)variables[name];
} }
list.Add(new LocalLookupVariable(name, typeRef, startPos, endPos, isConst, isLoopVariable, initializer, parentLambdaExpression)); list.Add(new LocalLookupVariable(name, typeRef, startPos, endPos, isConst, isLoopVariable, initializer, parentLambdaExpression, isQueryContinuation));
} }
public override object VisitWithStatement(WithStatement withStatement, object data) public override object VisitWithStatement(WithStatement withStatement, object data)
@ -115,7 +119,7 @@ namespace ICSharpCode.NRefactory.Visitors
localVariableDeclaration.StartLocation, localVariableDeclaration.StartLocation,
CurrentEndLocation, CurrentEndLocation,
(localVariableDeclaration.Modifier & Modifiers.Const) == Modifiers.Const, (localVariableDeclaration.Modifier & Modifiers.Const) == Modifiers.Const,
false, varDecl.Initializer, null); false, varDecl.Initializer, null, false);
} }
return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); return base.VisitLocalVariableDeclaration(localVariableDeclaration, data);
} }
@ -125,7 +129,7 @@ namespace ICSharpCode.NRefactory.Visitors
foreach (ParameterDeclarationExpression p in anonymousMethodExpression.Parameters) { foreach (ParameterDeclarationExpression p in anonymousMethodExpression.Parameters) {
AddVariable(p.TypeReference, p.ParameterName, AddVariable(p.TypeReference, p.ParameterName,
anonymousMethodExpression.StartLocation, anonymousMethodExpression.EndLocation, anonymousMethodExpression.StartLocation, anonymousMethodExpression.EndLocation,
false, false, null, null); false, false, null, null, false);
} }
return base.VisitAnonymousMethodExpression(anonymousMethodExpression, data); return base.VisitAnonymousMethodExpression(anonymousMethodExpression, data);
} }
@ -135,7 +139,7 @@ namespace ICSharpCode.NRefactory.Visitors
foreach (ParameterDeclarationExpression p in lambdaExpression.Parameters) { foreach (ParameterDeclarationExpression p in lambdaExpression.Parameters) {
AddVariable(p.TypeReference, p.ParameterName, AddVariable(p.TypeReference, p.ParameterName,
lambdaExpression.StartLocation, lambdaExpression.ExtendedEndLocation, lambdaExpression.StartLocation, lambdaExpression.ExtendedEndLocation,
false, false, null, lambdaExpression); false, false, null, lambdaExpression, false);
} }
return base.VisitLambdaExpression(lambdaExpression, data); return base.VisitLambdaExpression(lambdaExpression, data);
} }
@ -155,9 +159,10 @@ namespace ICSharpCode.NRefactory.Visitors
public override object VisitQueryExpressionFromClause(QueryExpressionFromClause fromClause, object data) public override object VisitQueryExpressionFromClause(QueryExpressionFromClause fromClause, object data)
{ {
QueryExpression parent = fromClause.Parent as QueryExpression;
AddVariable(fromClause.Type, fromClause.Identifier, AddVariable(fromClause.Type, fromClause.Identifier,
fromClause.StartLocation, CurrentEndLocation, fromClause.StartLocation, CurrentEndLocation,
false, true, fromClause.InExpression, null); false, true, fromClause.InExpression, null, parent != null && parent.IsQueryContinuation);
return base.VisitQueryExpressionFromClause(fromClause, data); return base.VisitQueryExpressionFromClause(fromClause, data);
} }
@ -166,15 +171,15 @@ namespace ICSharpCode.NRefactory.Visitors
if (string.IsNullOrEmpty(joinClause.IntoIdentifier)) { if (string.IsNullOrEmpty(joinClause.IntoIdentifier)) {
AddVariable(joinClause.Type, joinClause.Identifier, AddVariable(joinClause.Type, joinClause.Identifier,
joinClause.StartLocation, CurrentEndLocation, joinClause.StartLocation, CurrentEndLocation,
false, true, joinClause.InExpression, null); false, true, joinClause.InExpression, null, false);
} else { } else {
AddVariable(joinClause.Type, joinClause.Identifier, AddVariable(joinClause.Type, joinClause.Identifier,
joinClause.StartLocation, joinClause.EndLocation, joinClause.StartLocation, joinClause.EndLocation,
false, true, joinClause.InExpression, null); false, true, joinClause.InExpression, null, false);
AddVariable(joinClause.Type, joinClause.IntoIdentifier, AddVariable(joinClause.Type, joinClause.IntoIdentifier,
joinClause.StartLocation, CurrentEndLocation, joinClause.StartLocation, CurrentEndLocation,
false, false, joinClause.InExpression, null); false, false, joinClause.InExpression, null, false);
} }
return base.VisitQueryExpressionJoinClause(joinClause, data); return base.VisitQueryExpressionJoinClause(joinClause, data);
} }
@ -183,7 +188,7 @@ namespace ICSharpCode.NRefactory.Visitors
{ {
AddVariable(null, letClause.Identifier, AddVariable(null, letClause.Identifier,
letClause.StartLocation, CurrentEndLocation, letClause.StartLocation, CurrentEndLocation,
false, false, letClause.Expression, null); false, false, letClause.Expression, null, false);
return base.VisitQueryExpressionLetClause(letClause, data); return base.VisitQueryExpressionLetClause(letClause, data);
} }
@ -199,7 +204,8 @@ namespace ICSharpCode.NRefactory.Visitors
forNextStatement.EndLocation, forNextStatement.EndLocation,
false, false, false, false,
forNextStatement.Start, forNextStatement.Start,
null); null,
false);
base.VisitForNextStatement(forNextStatement, data); base.VisitForNextStatement(forNextStatement, data);
@ -264,7 +270,8 @@ namespace ICSharpCode.NRefactory.Visitors
foreachStatement.EndLocation, foreachStatement.EndLocation,
false, true, false, true,
foreachStatement.Expression, foreachStatement.Expression,
null); null,
false);
if (foreachStatement.Expression != null) { if (foreachStatement.Expression != null) {
foreachStatement.Expression.AcceptVisitor(this, data); foreachStatement.Expression.AcceptVisitor(this, data);
@ -291,7 +298,7 @@ namespace ICSharpCode.NRefactory.Visitors
catchClause.VariableName, catchClause.VariableName,
catchClause.StatementBlock.StartLocation, catchClause.StatementBlock.StartLocation,
catchClause.StatementBlock.EndLocation, catchClause.StatementBlock.EndLocation,
false, false, null, null); false, false, null, null, false);
} }
catchClause.StatementBlock.AcceptVisitor(this, data); catchClause.StatementBlock.AcceptVisitor(this, data);
} }

Loading…
Cancel
Save