Package it.unive.lisa.symbolic.value
Class OutOfScopeIdentifier
- java.lang.Object
-
- it.unive.lisa.symbolic.SymbolicExpression
-
- it.unive.lisa.symbolic.value.ValueExpression
-
- it.unive.lisa.symbolic.value.Identifier
-
- it.unive.lisa.symbolic.value.OutOfScopeIdentifier
-
- All Implemented Interfaces:
ScopedObject<SymbolicExpression>
public class OutOfScopeIdentifier extends Identifier
An identifier outside the current scope of the call, that is, in a method that is in the call stack but not the last one.
-
-
Constructor Summary
Constructors Constructor Description OutOfScopeIdentifier(Identifier id, ScopeToken scope, CodeLocation location)
Builds the identifier outside the scope.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
accept(ExpressionVisitor<T> visitor, java.lang.Object... params)
Accepts anExpressionVisitor
, visiting this expression recursively.boolean
canBeScoped()
Yieldstrue
if a call toSymbolicExpression.pushScope(ScopeToken)
on this identifier yields a newOutOfScopeIdentifier
associated with the given scope, that can then be removed bySymbolicExpression.popScope(ScopeToken)
.ScopeToken
getScope()
Returns the scope of the identifier.boolean
isScopedByCall()
Yieldstrue
if this is anOutOfScopeIdentifier
whose (i) scope was introduced by a call, or (ii) inner identifier is anOutOfScopeIdentifier
such thatinner.isScopedByCall()
holds.Identifier
popScope(ScopeToken token)
Pops the scope identified by the given token from the expression.SymbolicExpression
pushScope(ScopeToken token)
Pushes a new scope, identified by the give token, in the expression.java.lang.String
toString()
-
Methods inherited from class it.unive.lisa.symbolic.value.Identifier
addAnnotation, equals, getAnnotations, getName, hashCode, isWeak, lub, mightNeedRewriting
-
Methods inherited from class it.unive.lisa.symbolic.value.ValueExpression
removeNegations
-
Methods inherited from class it.unive.lisa.symbolic.SymbolicExpression
getCodeLocation, getStaticType
-
-
-
-
Constructor Detail
-
OutOfScopeIdentifier
public OutOfScopeIdentifier(Identifier id, ScopeToken scope, CodeLocation location)
Builds the identifier outside the scope.- Parameters:
id
- the current identifierscope
- the method call that caused the identifier to exit the scopelocation
- the code location of the statement that has generated this expression
-
-
Method Detail
-
canBeScoped
public boolean canBeScoped()
Description copied from class:Identifier
Yieldstrue
if a call toSymbolicExpression.pushScope(ScopeToken)
on this identifier yields a newOutOfScopeIdentifier
associated with the given scope, that can then be removed bySymbolicExpression.popScope(ScopeToken)
. If this method returnsfalse
, thenSymbolicExpression.pushScope(ScopeToken)
andSymbolicExpression.popScope(ScopeToken)
will always return this identifier instead.- Specified by:
canBeScoped
in classIdentifier
- Returns:
true
if that condition holds
-
pushScope
public SymbolicExpression pushScope(ScopeToken token)
Description copied from class:SymbolicExpression
Pushes a new scope, identified by the give token, in the expression. This causes allIdentifier
s whereIdentifier.canBeScoped()
holds to becomeOutOfScopeIdentifier
s associated with the given token.- Specified by:
pushScope
in interfaceScopedObject<SymbolicExpression>
- Specified by:
pushScope
in classSymbolicExpression
- Parameters:
token
- the token identifying the scope to push- Returns:
- a copy of this expression where the local variables have gone out of scope
-
popScope
public Identifier popScope(ScopeToken token) throws SemanticException
Description copied from class:SymbolicExpression
Pops the scope identified by the given token from the expression. This causes all the invisible variables (i.e.OutOfScopeIdentifier
s) mapped to the given scope to become visible (e.g.Variable
s) again. Note that invoking this method onIdentifier
s whereIdentifier.canBeScoped()
holds will returnnull
if (i) the identifier is not scoped, or (ii) the identifier is scoped by a different token.- Specified by:
popScope
in interfaceScopedObject<SymbolicExpression>
- Specified by:
popScope
in classSymbolicExpression
- Parameters:
token
- the token of the scope to be restored- Returns:
- a copy of this expression where the local variables associated with the given scope are visible again
- Throws:
SemanticException
- if an error occurs during the computation
-
isScopedByCall
public boolean isScopedByCall()
Description copied from class:Identifier
Yieldstrue
if this is anOutOfScopeIdentifier
whose (i) scope was introduced by a call, or (ii) inner identifier is anOutOfScopeIdentifier
such thatinner.isScopedByCall()
holds.- Overrides:
isScopedByCall
in classIdentifier
- Returns:
true
if that condition holds
-
getScope
public ScopeToken getScope()
Returns the scope of the identifier.- Returns:
- the scope of the identifier
-
toString
public java.lang.String toString()
- Specified by:
toString
in classSymbolicExpression
-
accept
public <T> T accept(ExpressionVisitor<T> visitor, java.lang.Object... params) throws SemanticException
Description copied from class:SymbolicExpression
Accepts anExpressionVisitor
, visiting this expression recursively.- Specified by:
accept
in classSymbolicExpression
- Type Parameters:
T
- the type of value produced by the visiting callbacks- Parameters:
visitor
- the visitorparams
- additional optional parameters to pass to each visiting callback- Returns:
- the value produced by the visiting operation
- Throws:
SemanticException
- if an error occurs during the visiting
-
-