use of org.apache.asterix.lang.common.context.Scope in project asterixdb by apache.
the class ScopeChecker method extendCurrentScope.
public final Scope extendCurrentScope(boolean maskParentScope) {
Scope scope = extendCurrentScopeNoPush(maskParentScope);
scopeStack.pop();
scopeStack.push(scope);
return scope;
}
use of org.apache.asterix.lang.common.context.Scope in project asterixdb by apache.
the class ScopeChecker method createNewScope.
// Forbidden scopes are used to disallow, in a limit clause, variables
// having the same name as a variable defined by the FLWOR in which that
// limit clause appears.
/**
* Create a new scope, using the top scope in scopeStack as parent scope
*
* @return new scope
*/
public final Scope createNewScope() {
Scope parent = scopeStack.peek();
// top one as parent
Scope scope = new Scope(this, parent);
scopeStack.push(scope);
return scope;
}
use of org.apache.asterix.lang.common.context.Scope in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method visit.
@Override
public Expression visit(IndependentSubquery independentSubquery, ILangExpression arg) throws CompilationException {
// Masks parent scopes so as that the subquery is independent of the environment.
// In this way, free variables defined in the subquery will not be resolved using
// variables defined in the parent scope.
Scope scope = new Scope(scopeChecker, scopeChecker.getCurrentScope(), true);
scopeChecker.pushExistingScope(scope);
independentSubquery.setExpr(visit(independentSubquery.getExpr(), independentSubquery));
scopeChecker.removeCurrentScope();
return independentSubquery;
}
use of org.apache.asterix.lang.common.context.Scope in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method visit.
@Override
public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws CompilationException {
Scope scopeBeforeSelectExpression = scopeChecker.getCurrentScope();
scopeChecker.createNewScope();
// visit let list
if (selectExpression.hasLetClauses()) {
for (LetClause letClause : selectExpression.getLetList()) {
// Variables defined in WITH clauses are considered as named access instead of real variables.
letClause.getVarExpr().getVar().setNamedValueAccess(true);
letClause.accept(this, selectExpression);
}
scopeChecker.createNewScope();
}
// visit the main select.
selectExpression.getSelectSetOperation().accept(this, selectExpression);
// visit order by
if (selectExpression.hasOrderby()) {
selectExpression.getOrderbyClause().accept(this, selectExpression);
}
// visit limit
if (selectExpression.hasLimit()) {
selectExpression.getLimitClause().accept(this, selectExpression);
}
// Exit scopes that were entered within this select expression
while (scopeChecker.getCurrentScope() != scopeBeforeSelectExpression) {
scopeChecker.removeCurrentScope();
}
return selectExpression;
}
use of org.apache.asterix.lang.common.context.Scope in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method visit.
@Override
public Expression visit(GroupbyClause gc, ILangExpression arg) throws CompilationException {
// After a GROUP BY, variables defined before the current SELECT BLOCK (e.g., in a WITH clause
// or an outer scope query) should still be visible.
Scope newScope = new Scope(scopeChecker, scopeChecker.getCurrentScope().getParentScope());
// Puts all group-by variables into the symbol set of the new scope.
for (GbyVariableExpressionPair gbyKeyVarExpr : gc.getGbyPairList()) {
gbyKeyVarExpr.setExpr(visit(gbyKeyVarExpr.getExpr(), gc));
VariableExpr gbyKeyVar = gbyKeyVarExpr.getVar();
if (gbyKeyVar != null) {
addNewVarSymbolToScope(newScope, gbyKeyVar.getVar());
}
}
if (gc.hasGroupFieldList()) {
for (Pair<Expression, Identifier> gbyField : gc.getGroupFieldList()) {
gbyField.first = visit(gbyField.first, arg);
}
}
if (gc.hasDecorList()) {
for (GbyVariableExpressionPair decorVarExpr : gc.getDecorPairList()) {
decorVarExpr.setExpr(visit(decorVarExpr.getExpr(), gc));
VariableExpr decorVar = decorVarExpr.getVar();
if (decorVar != null) {
addNewVarSymbolToScope(newScope, decorVar.getVar());
}
}
}
if (gc.hasGroupVar()) {
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), gc.getGroupVar().getVar());
}
if (gc.hasWithMap()) {
Map<Expression, VariableExpr> newWithMap = new HashMap<>();
for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) {
Expression expr = visit(entry.getKey(), arg);
Expression newKey = expr;
VariableExpr value = entry.getValue();
addNewVarSymbolToScope(newScope, value.getVar());
newWithMap.put(newKey, value);
}
gc.setWithVarMap(newWithMap);
}
// Replaces the current scope with the new scope.
scopeChecker.replaceCurrentScope(newScope);
return null;
}
Aggregations