Class BasicLocalVariableMap
- All Implemented Interfaces:
LocalVariableMap,VariableMap
- Direct Known Subclasses:
MixedBasicVariableMap
public class BasicLocalVariableMap extends java.lang.Object implements LocalVariableMap
- Author:
- Peter Verhas date June 22, 2012
-
Constructor Summary
Constructors Constructor Description BasicLocalVariableMap() -
Method Summary
Modifier and Type Method Description protected java.lang.Stringconverted(java.lang.String name)Converts the name of a variable in a way that if the name 'a' and name 'b' results the same string converted then 'a' and 'b' are treated from some aspects as the same variable name.booleancurrentScopeIsGlobal()Returns true if the current scope is global, there no no any local stack frame open.voiddropFrame()Drop the current frame and pop off the map from the top of the stack.java.util.Set<java.lang.String>getVariableNameSet()Get the set of the variables stored in the variable map so that the caller can iterate through the variables.RightValuegetVariableValue(java.lang.String variableName)Get the value of a variable.booleanisGlobal(java.lang.String variableName)booleanisLocal(java.lang.String variableName)voidnewFrame()Push the actual Map onto the stack of maps and create a new empty stack.voidregisterGlobalVariable(java.lang.String variableName)Register a variable as a global variable.voidregisterLocalVariable(java.lang.String variableName)Define the variable as a local variable in a local environment.voidsetCaseFreak()Tell the object that the variable names has to be cased only one way.voidsetCaseIgnorant()Tell the object that the variable handling is case insensitive.voidsetCaseSensitive()Tell the object that the variable names are handled in a case sensitive way.voidsetVariable(java.lang.String variableName, RightValue rightValue)Set the value of the variable.java.lang.BooleanvariableDefined(java.lang.String variableName)Checks that a variable exists and has a defined value in this map.java.lang.BooleanvariableExists(java.lang.String variableName)Checks that a variable exists in this map.
-
Constructor Details
-
BasicLocalVariableMap
public BasicLocalVariableMap()
-
-
Method Details
-
getVariableValue
Description copied from interface:VariableMapGet the value of a variable.- Specified by:
getVariableValuein interfaceVariableMap- Parameters:
variableName- parameter- Returns:
- the right value the variable has or
nullif the variable is not defined or does not exists. - Throws:
ScriptBasicException- in case there is an exception
-
variableExists
Description copied from interface:VariableMapChecks that a variable exists in this map.- Specified by:
variableExistsin interfaceVariableMap- Parameters:
variableName- parameter- Returns:
trueif the variable exists, even if the variable has undefined value.falseif the variable does not exist in this map.- Throws:
ScriptBasicException- in case there is an exception
-
variableDefined
public java.lang.Boolean variableDefined(java.lang.String variableName) throws ScriptBasicExceptionDescription copied from interface:VariableMapChecks that a variable exists and has a defined value in this map. Undefined value is represented bynull.- Specified by:
variableDefinedin interfaceVariableMap- Parameters:
variableName- parameter- Returns:
trueif the variable exists and has a defined value.- Throws:
ScriptBasicException- in case there is an exception
-
setVariable
public void setVariable(java.lang.String variableName, RightValue rightValue) throws ScriptBasicExceptionDescription copied from interface:VariableMapSet the value of the variable. If the variable did not exist then the variable is automatically created. If the variable had undefined value then the new value will be the one defined by the argument.You can set a variable to undefined passing
nullto this method asrightValue.- Specified by:
setVariablein interfaceVariableMap- Parameters:
variableName- parameterrightValue- the new value of the variable- Throws:
ScriptBasicException- in case there is an exception
-
newFrame
public void newFrame()Description copied from interface:LocalVariableMapPush the actual Map onto the stack of maps and create a new empty stack. This is what a program has to do when a function is called. The local variables (if any) are pushed on the stack and a new stack frame is opened.- Specified by:
newFramein interfaceLocalVariableMap
-
dropFrame
public void dropFrame()Description copied from interface:LocalVariableMapDrop the current frame and pop off the map from the top of the stack. This is what programs have to do when a RETURN is executed from a function.- Specified by:
dropFramein interfaceLocalVariableMap
-
currentScopeIsGlobal
public boolean currentScopeIsGlobal()Returns true if the current scope is global, there no no any local stack frame open.- Returns:
- return value
-
registerGlobalVariable
Description copied from interface:LocalVariableMapRegister a variable as a global variable. This is needed when an implementing class manages the global as well as the local variables.Interpreters may handle variables differently. When a variable is not defined using some keyword as 'LOCAL' or 'GLOBAL' then the interpreter may treat the variable default local, may treat default global or may raise error. This is configurable in ScriptBasic.
This method can be used to declare that a variable is used in the local environment referring to the global variable.
- Specified by:
registerGlobalVariablein interfaceLocalVariableMap- Parameters:
variableName- parameter- Throws:
ScriptBasicException- in case of exception
-
registerLocalVariable
Description copied from interface:LocalVariableMapDefine the variable as a local variable in a local environment. For more information see the documentation of the methodLocalVariableMap.registerGlobalVariable(String)- Specified by:
registerLocalVariablein interfaceLocalVariableMap- Parameters:
variableName- parameter- Throws:
ScriptBasicException- in case of exception
-
isGlobal
- Throws:
ScriptBasicException
-
isLocal
- Throws:
ScriptBasicException
-
getVariableNameSet
public java.util.Set<java.lang.String> getVariableNameSet()Description copied from interface:VariableMapGet the set of the variables stored in the variable map so that the caller can iterate through the variables.- Specified by:
getVariableNameSetin interfaceVariableMap- Returns:
- return value
-
setCaseSensitive
public void setCaseSensitive()Tell the object that the variable names are handled in a case sensitive way. It means that the variables 'vaRIable' and 'variABLE' are two different variables and can live in the global or the actual local variable name space along with each other in peace.It is not recommended to use this mode, however most modern programming languages do this.
-
setCaseFreak
public void setCaseFreak()Tell the object that the variable names has to be cased only one way. It means that there can not be a variable named "vaRIable' and 'variABLE' at the same time.It is the recommended behavior, however BASIC implementations rarely exhibit such variable name handling this is not the default.
-
setCaseIgnorant
public void setCaseIgnorant()Tell the object that the variable handling is case insensitive. It means that the variables 'vaRIable' and 'variABLE' denote the same variable.It is not recommended to use this mode, however most BASIC implementation do this. This is the default behavior.
-
converted
protected java.lang.String converted(java.lang.String name)Converts the name of a variable in a way that if the name 'a' and name 'b' results the same string converted then 'a' and 'b' are treated from some aspects as the same variable name. The generic approach is simply upper casing.- Parameters:
name- parameter- Returns:
- return value
-