Package org.ek9lang.compiler.common
Class ScopeStack
java.lang.Object
org.ek9lang.compiler.common.ScopeStack
This stack object is only designed to be used when first parsing.
The idea is to actually associate the scope with the specific contexts by
putting them in a ParseTreeProperty of Scope, this tree is held in the
ParsedModule. So why do we need this stack? That is because as we
listen/visit the parse tree we need to both create the scope and record it in
the parsed module. But also put it on to a stack so that when we return for
each level of the parse tree we can get back to the right scope. I don't want
to use a 'getEnclosingScope' method on each scope as the very top level has
to be thread safe. Plus it exposes information that should only be available
to the scope itself - not any other bit of code.
This class also has logic and code to be able to traverse back up the 'structure stack'.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
isEmpty()
True if stack has no contents.peek()
Take a look at the top of the stack.pop()
Pop a scope of the stack (exception is empty.Push a scope on to this stack.traverseBackUpStack
(IScope.ScopeType scopeType) Navigates back up the scope stack to find the first match of the scope type passed in.Navigate back up the scope stack to find the first enclosing method (there may not be one).Locates the outer function or method (if possible, not always possible Applications for example).
-
Constructor Details
-
ScopeStack
-
-
Method Details
-
getVeryBaseScope
-
push
Push a scope on to this stack. -
peek
Take a look at the top of the stack. -
pop
Pop a scope of the stack (exception is empty. -
isEmpty
public boolean isEmpty()True if stack has no contents. -
traverseBackUpStack
Navigates back up the scope stack to find the first match of the scope type passed in. This is useful because dynamic classes and functions do not use an enclosing scope of the scope they are in. They get pulled out to module level (by design). -
traverseBackUpStackToMethodOrFunction
Locates the outer function or method (if possible, not always possible Applications for example). -
traverseBackUpStackToEnclosingMethod
Navigate back up the scope stack to find the first enclosing method (there may not be one). So if this were called in a function or an application for example - there will not be an enclosing method.- Returns:
- The Optional method located.
-