org.hawk.module.script
Class ScriptInterpreter

java.lang.Object
  extended by org.hawk.module.script.ScriptInterpreter

public class ScriptInterpreter
extends java.lang.Object

This parses the hawk script and runs the same. This reads through the hawk file and parses the function definition and hence creates the function script out of them. The function script contains all the scripts written inside the function definition.

This is the place where all the global variables and aliases are stored.

This parses through target application's IModule implementations to cache all the modules IModule and subtask SubTaskContainer Note: The developer has to annotate the tasks with SubTask to register with Hawk framework as subtask failing to which Hawk will ignore the same.

See Also:
ScriptUsage, IModule, SubTaskContainer, SubTask

Field Summary
protected  java.util.Map<Variable,IScript> globalVariableTable
          Global map containing global var and its value
 
Method Summary
 boolean cacheAliases()
           
 java.util.Map<java.lang.String,FunctionScript> cacheFunctionScriptMap()
          This caches the function script map
 java.util.Map<java.lang.String,FunctionScript> cacheFunctionScriptMap(boolean shouldParseDetails)
          This caches the function script map
 boolean cacheGlobalVariable()
          This caches all the global variables declared
 java.util.Map<java.lang.String,StructureDefnScript> cacheStructureDefnMap()
          This caches the structure definition
 java.util.Map<IModule,java.util.Map<java.lang.String,SubTaskContainer>> cacheSubTasks()
          This caches the subtasks implemented by the user using SubTask.
 FunctionScript cloneFunctionScript(FunctionScript functionScript)
          This clones input FunctionScript.
 boolean compile(java.lang.String scriptFile)
          This parses the hawk script file for syntax check.
 boolean createFunctionScript(java.lang.String functionName, FunctionScript functionScript)
           
 boolean doesStructExist(java.lang.String structName)
          This checks if structName is defined in the hawk script
 boolean doesStructMemberExist(java.lang.String structName, java.lang.String structMember)
          This checks if a structName and it's member structMember are defined in the hawk script
 FunctionScript findFunctionScript(java.lang.String mangledFunctionName)
          This finds the FunctionScript for the input mangled function name When invoked in threads other than main thread, this method clones the function script and returns the same.
 java.util.Map<java.lang.String,FunctionScript> getFunctionScriptMap()
          This returns the cached function->FunctionScript map.
 IScript getGlobalValue(java.lang.String globalVar)
          Getter for global variable
static ScriptInterpreter getInstance()
          SingleTon accessor method of ScriptInterpreter
 java.util.Map<java.lang.Integer,java.lang.String> getScriptMap()
           
 java.util.Set<SubTaskContainer> getSortedSubTasks(IModule module)
          This returns Set the subtasks of a module sorted on the sequence number.
 java.util.Map<java.lang.String,StructureDefnScript> getStructureDefnMap()
          This returns the cached structure->StructureDefnScript map.
 java.util.Map<IModule,java.util.Map<java.lang.String,SubTaskContainer>> getSubTasks()
          This returns the cached module->subtask map.
 boolean interpret()
          This interprets the hawk script file.
 boolean isGlobalVarDeclared(Variable globalVar)
          Checks whether this global variable is declared.
 boolean isInsideMultiLineScript(int i)
           
static void main(java.lang.String[] args)
          Entry point of hawk script interpretation
 java.util.Map<java.lang.String,FunctionScript> parseFunctionScriptMap()
           
 void setGlobalValue(Variable globalVar, IScript globalValue)
          Setter for global variable
 void setScriptMap(java.util.Map<java.lang.Integer,java.lang.String> scriptMap)
           
 void unsetGlobalValue(java.lang.String globalVar)
          Removes the global variable from the global variable map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

globalVariableTable

protected java.util.Map<Variable,IScript> globalVariableTable
Global map containing global var and its value

See Also:
VariableDeclScript
Method Detail

getInstance

public static ScriptInterpreter getInstance()
SingleTon accessor method of ScriptInterpreter

Returns:

getScriptMap

public java.util.Map<java.lang.Integer,java.lang.String> getScriptMap()

setScriptMap

public void setScriptMap(java.util.Map<java.lang.Integer,java.lang.String> scriptMap)

getGlobalValue

public IScript getGlobalValue(java.lang.String globalVar)
Getter for global variable

Parameters:
globalVar -
Returns:
getter for global variable

setGlobalValue

public void setGlobalValue(Variable globalVar,
                           IScript globalValue)
Setter for global variable

Parameters:
globalVar -
globalValue -

unsetGlobalValue

public void unsetGlobalValue(java.lang.String globalVar)
Removes the global variable from the global variable map.

Parameters:
globalVar - the variable to be removed.

isGlobalVarDeclared

public boolean isGlobalVarDeclared(Variable globalVar)
Checks whether this global variable is declared.

Parameters:
globalVar -
Returns:
true on success false on failure

cacheSubTasks

public java.util.Map<IModule,java.util.Map<java.lang.String,SubTaskContainer>> cacheSubTasks()
This caches the subtasks implemented by the user using SubTask.

Returns:
a map containing key as IModule and value as another map which contains task name and SubTaskContainer

getSubTasks

public java.util.Map<IModule,java.util.Map<java.lang.String,SubTaskContainer>> getSubTasks()
This returns the cached module->subtask map. If it is not cached it invokes cacheSubTasks()

Returns:
a map containing key as IModule and value as another map which contains task name and SubTaskContainer

getSortedSubTasks

public java.util.Set<SubTaskContainer> getSortedSubTasks(IModule module)
                                                  throws HawkException
This returns Set the subtasks of a module sorted on the sequence number.

Parameters:
module - for which sorted tasks are required.
Returns:
returns Set the subtasks of a module sorted on the sequence number.
Throws:
HawkException

cacheStructureDefnMap

public java.util.Map<java.lang.String,StructureDefnScript> cacheStructureDefnMap()
                                                                          throws HawkException
This caches the structure definition

Returns:
a map containing key as structure name and value as StructureDefnScript
Throws:
HawkException
See Also:
StructureDefnScript

doesStructExist

public boolean doesStructExist(java.lang.String structName)
                        throws HawkException
This checks if structName is defined in the hawk script

Parameters:
structName -
Returns:
true if structName is defined otherwise false
Throws:
HawkException

doesStructMemberExist

public boolean doesStructMemberExist(java.lang.String structName,
                                     java.lang.String structMember)
                              throws HawkException
This checks if a structName and it's member structMember are defined in the hawk script

Parameters:
structName -
structMember -
Returns:
Throws:
HawkException

getStructureDefnMap

public java.util.Map<java.lang.String,StructureDefnScript> getStructureDefnMap()
                                                                        throws HawkException
This returns the cached structure->StructureDefnScript map. If it is not cached it invokes cacheStructureDefnMap()

Returns:
a map containing key as structure name and value as StructureDefnScript
Throws:
HawkException

cloneFunctionScript

public FunctionScript cloneFunctionScript(FunctionScript functionScript)
This clones input FunctionScript. This is used in parallel execution of hawk functions

Parameters:
functionScript -
Returns:
See Also:
ExecParallelSingleLineScript

parseFunctionScriptMap

public java.util.Map<java.lang.String,FunctionScript> parseFunctionScriptMap()
                                                                      throws HawkException
Throws:
HawkException

cacheAliases

public boolean cacheAliases()
                     throws HawkException
Throws:
HawkException

cacheFunctionScriptMap

public java.util.Map<java.lang.String,FunctionScript> cacheFunctionScriptMap()
                                                                      throws HawkException
This caches the function script map

Returns:
a map containing key as function name and value as FunctionScript
Throws:
HawkException
See Also:
FunctionScript

cacheFunctionScriptMap

public java.util.Map<java.lang.String,FunctionScript> cacheFunctionScriptMap(boolean shouldParseDetails)
                                                                      throws HawkException
This caches the function script map

Returns:
a map containing key as function name and value as FunctionScript
Throws:
HawkException
See Also:
FunctionScript

createFunctionScript

public boolean createFunctionScript(java.lang.String functionName,
                                    FunctionScript functionScript)
                             throws HawkException
Throws:
HawkException

findFunctionScript

public FunctionScript findFunctionScript(java.lang.String mangledFunctionName)
                                  throws HawkException
This finds the FunctionScript for the input mangled function name When invoked in threads other than main thread, this method clones the function script and returns the same.

Parameters:
mangledFunctionName -
Returns:
returns FunctionScript
Throws:
HawkException
See Also:
FunctionScript

getFunctionScriptMap

public java.util.Map<java.lang.String,FunctionScript> getFunctionScriptMap()
                                                                    throws HawkException
This returns the cached function->FunctionScript map. If it is not cached it invokes cacheFunctionScriptMap()

Returns:
a map containing key as function name and value as FunctionScript
Throws:
HawkException

cacheGlobalVariable

public boolean cacheGlobalVariable()
                            throws HawkException
This caches all the global variables declared

Returns:
Throws:
HawkException

isInsideMultiLineScript

public boolean isInsideMultiLineScript(int i)

interpret

public boolean interpret()
                  throws HawkException
This interprets the hawk script file.

Returns:
Throws:
HawkException - if there is no main function defined in hawk script or if the script is not interpretable.

compile

public boolean compile(java.lang.String scriptFile)
                throws HawkException
This parses the hawk script file for syntax check.

Parameters:
scriptFile - hawk script file
Returns:
true if syntax check is successful false otherwise
Throws:
HawkException - if it is not valid hawk script file

main

public static void main(java.lang.String[] args)
Entry point of hawk script interpretation

Parameters:
args - command line arguments as per java standards