|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectkoala.dynamicjava.interpreter.TreeInterpreter
This class contains method to interpret the constructs of the language.
Nested Class Summary | |
protected class |
TreeInterpreter.ConstructorParametersDescriptor
Used to store the informations about explicit constructors invocation |
protected class |
TreeInterpreter.MethodDescriptor
Used to store the informations about dynamically created methods |
Field Summary | |
protected boolean |
accessible
Track the state of calls to 'setAccessible' |
protected Context |
checkVisitorContext
|
protected TreeClassLoader |
classLoader
The class loader |
protected static java.util.Map |
constructorParameters
The explicit constructor call parameters |
protected Context |
evalVisitorContext
|
protected LibraryFinder |
libraryFinder
The library finder |
protected static java.util.Map |
methods
The methods |
protected Context |
nameVisitorContext
|
protected static int |
nClass
Used to generate classes |
protected ParserFactory |
parserFactory
The parser |
Constructor Summary | |
TreeInterpreter(ParserFactory pf)
Creates a new interpreter |
|
TreeInterpreter(ParserFactory pf,
java.lang.ClassLoader cl)
Creates a new interpreter |
Method Summary | |
void |
addClassPath(java.lang.String path)
Adds a class search path |
void |
addClassURL(java.net.URL url)
Adds a class search URL |
void |
addLibraryPath(java.lang.String path)
Adds a library search path |
void |
addLibrarySuffix(java.lang.String s)
Adds a library file suffix |
java.util.List |
buildStatementList(java.io.Reader r,
java.lang.String fname)
Parses a script and creates the associated syntax trees. |
java.lang.Class |
defineClass(java.lang.String name,
byte[] code)
Converts an array of bytes into an instance of the class Class |
void |
defineVariable(java.lang.String name,
boolean value)
Defines a boolean variable in the interpreter environment |
void |
defineVariable(java.lang.String name,
byte value)
Defines a byte variable in the interpreter environment |
void |
defineVariable(java.lang.String name,
char value)
Defines a char variable in the interpreter environment |
void |
defineVariable(java.lang.String name,
double value)
Defines an double variable in the interpreter environment |
void |
defineVariable(java.lang.String name,
float value)
Defines an float variable in the interpreter environment |
void |
defineVariable(java.lang.String name,
int value)
Defines an int variable in the interpreter environment |
void |
defineVariable(java.lang.String name,
long value)
Defines an long variable in the interpreter environment |
void |
defineVariable(java.lang.String name,
java.lang.Object value)
Defines a variable in the interpreter environment |
void |
defineVariable(java.lang.String name,
java.lang.Object value,
java.lang.Class c)
Defines a variable in the interpreter environment |
void |
defineVariable(java.lang.String name,
short value)
Defines a short variable in the interpreter environment |
protected void |
finalize()
Called before the destruction of the interpreter |
boolean |
getAccessible()
Observe the state of calls to setAccessible() |
java.lang.ClassLoader |
getClassLoader()
Gets the class loader |
java.util.Set |
getClassNames()
Returns the defined class names |
java.lang.Class |
getExceptionClass()
Returns the class of the execution exception |
LibraryFinder |
getLibraryFinder()
Gets the library finder |
ParserFactory |
getParserFactory()
Gets the parser factory |
java.lang.Object |
getVariable(java.lang.String name)
Gets the value of a variable |
java.lang.Class |
getVariableClass(java.lang.String name)
Gets the class of a variable |
java.util.Set |
getVariableNames()
Returns the defined variable names |
java.lang.Object |
interpret(java.io.InputStream is,
java.lang.String fname)
Runs the interpreter |
java.lang.Object |
interpret(java.util.List statements)
Runs the interpreter on a statement list. |
java.lang.Object |
interpret(java.io.Reader r,
java.lang.String fname)
Runs the interpreter |
java.lang.Object |
interpret(java.lang.String fname)
Runs the interpreter |
protected java.lang.Object[] |
interpretArguments(java.lang.Class c,
TreeInterpreter.ConstructorParametersDescriptor cpd,
java.lang.Object[] args)
This method is used to implement constructor invocation. |
static java.lang.Object[] |
interpretArguments(java.lang.String key,
java.lang.Object[] args)
This method is used to implement constructor invocation. |
protected java.lang.Object |
interpretMethod(java.lang.Class c,
TreeInterpreter.MethodDescriptor md,
java.lang.Object obj,
java.lang.Object[] params)
Interprets the body of a method |
static java.lang.Object |
invokeMethod(java.lang.String key,
java.lang.Object obj,
java.lang.Object[] params)
Interprets the body of a method |
java.lang.Class |
loadClass(java.lang.String name)
Loads an interpreted class |
void |
registerConstructorArguments(java.lang.String sig,
java.util.List params,
java.util.List exprs,
ImportationManager im)
Registers a constructor arguments |
void |
registerMethod(java.lang.String sig,
MethodDeclaration md,
ImportationManager im)
Registers a method. |
void |
setAccessible(boolean accessible)
Set the interpreter contexts to override public/protected/private access restrictions on the methods and fields it handles. |
void |
setVariable(java.lang.String name,
java.lang.Object value)
Sets the value of a variable |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected ParserFactory parserFactory
protected LibraryFinder libraryFinder
protected TreeClassLoader classLoader
protected static java.util.Map methods
protected static java.util.Map constructorParameters
protected static int nClass
protected Context nameVisitorContext
protected Context checkVisitorContext
protected Context evalVisitorContext
protected boolean accessible
setAccessible(boolean)
Constructor Detail |
public TreeInterpreter(ParserFactory pf)
pf
- the parser factorypublic TreeInterpreter(ParserFactory pf, java.lang.ClassLoader cl)
pf
- the parser factorycl
- the auxiliary class loader used to load external classesMethod Detail |
public java.lang.Object interpret(java.io.Reader r, java.lang.String fname) throws InterpreterException
interpret
in interface Interpreter
fname
- the name of the parsed streamr
- the reader
InterpreterException
public java.lang.Object interpret(java.io.InputStream is, java.lang.String fname) throws InterpreterException
interpret
in interface Interpreter
is
- the input stream from which the statements are readfname
- the name of the parsed stream
InterpreterException
public java.lang.Object interpret(java.lang.String fname) throws InterpreterException, java.io.IOException
interpret
in interface Interpreter
fname
- the name of a file to interpret
InterpreterException
java.io.IOException
public java.util.List buildStatementList(java.io.Reader r, java.lang.String fname) throws InterpreterException
fname
- the name of the parsed stream
InterpreterException
public java.lang.Object interpret(java.util.List statements) throws InterpreterException
statements
- the statement list to evaluate
InterpreterException
public void defineVariable(java.lang.String name, java.lang.Object value, java.lang.Class c)
name
- the variable's namevalue
- the initial value of the variablec
- the variable's type.
java.lang.IllegalStateException
- if name is already definedpublic void defineVariable(java.lang.String name, java.lang.Object value)
defineVariable
in interface Interpreter
name
- the variable's namevalue
- the initial value of the variable
java.lang.IllegalStateException
- if name is already definedpublic void defineVariable(java.lang.String name, boolean value)
name
- the variable's namevalue
- the initial value of the variable
java.lang.IllegalStateException
- if name is already definedpublic void defineVariable(java.lang.String name, byte value)
name
- the variable's namevalue
- the initial value of the variable
java.lang.IllegalStateException
- if name is already definedpublic void defineVariable(java.lang.String name, short value)
name
- the variable's namevalue
- the initial value of the variable
java.lang.IllegalStateException
- if name is already definedpublic void defineVariable(java.lang.String name, char value)
name
- the variable's namevalue
- the initial value of the variable
java.lang.IllegalStateException
- if name is already definedpublic void defineVariable(java.lang.String name, int value)
name
- the variable's namevalue
- the initial value of the variable
java.lang.IllegalStateException
- if name is already definedpublic void defineVariable(java.lang.String name, long value)
name
- the variable's namevalue
- the initial value of the variable
java.lang.IllegalStateException
- if name is already definedpublic void defineVariable(java.lang.String name, float value)
name
- the variable's namevalue
- the initial value of the variable
java.lang.IllegalStateException
- if name is already definedpublic void defineVariable(java.lang.String name, double value)
name
- the variable's namevalue
- the initial value of the variable
java.lang.IllegalStateException
- if name is already definedpublic void setVariable(java.lang.String name, java.lang.Object value)
setVariable
in interface Interpreter
name
- the variable's namevalue
- the value of the variable
java.lang.IllegalStateException
- if the assignment is invalidpublic java.lang.Object getVariable(java.lang.String name)
getVariable
in interface Interpreter
name
- the variable's name
java.lang.IllegalStateException
- if the variable do not existpublic java.lang.Class getVariableClass(java.lang.String name)
getVariableClass
in interface Interpreter
name
- the variable's name
java.lang.IllegalStateException
- if the variable do not existpublic java.util.Set getVariableNames()
getVariableNames
in interface Interpreter
public void setAccessible(boolean accessible)
Interpreter
setAccessible
in interface Interpreter
public boolean getAccessible()
Interpreter
getAccessible
in interface Interpreter
public java.util.Set getClassNames()
getClassNames
in interface Interpreter
public void addClassPath(java.lang.String path)
addClassPath
in interface Interpreter
path
- the path to addpublic void addClassURL(java.net.URL url)
addClassURL
in interface Interpreter
url
- the url to addpublic void addLibraryPath(java.lang.String path)
addLibraryPath
in interface Interpreter
path
- the path to addpublic void addLibrarySuffix(java.lang.String s)
addLibrarySuffix
in interface Interpreter
s
- the suffix to addpublic java.lang.Class loadClass(java.lang.String name) throws java.lang.ClassNotFoundException
loadClass
in interface Interpreter
java.lang.ClassNotFoundException
- if the class cannot be findpublic java.lang.Class defineClass(java.lang.String name, byte[] code)
defineClass
in interface Interpreter
java.lang.ClassFormatError
- if the class cannot be definedpublic java.lang.ClassLoader getClassLoader()
getClassLoader
in interface Interpreter
public LibraryFinder getLibraryFinder()
getLibraryFinder
in interface Interpreter
public ParserFactory getParserFactory()
getParserFactory
in interface Interpreter
public java.lang.Class getExceptionClass()
public void registerMethod(java.lang.String sig, MethodDeclaration md, ImportationManager im)
sig
- the method's signaturemd
- the method declarationim
- the importation managerpublic static java.lang.Object invokeMethod(java.lang.String key, java.lang.Object obj, java.lang.Object[] params)
key
- the key used to find the body of a methodobj
- the object (this)params
- the argumentsprotected java.lang.Object interpretMethod(java.lang.Class c, TreeInterpreter.MethodDescriptor md, java.lang.Object obj, java.lang.Object[] params)
c
- the declaring class of the methodmd
- the method descriptorobj
- the object (this)params
- the argumentspublic void registerConstructorArguments(java.lang.String sig, java.util.List params, java.util.List exprs, ImportationManager im)
public static java.lang.Object[] interpretArguments(java.lang.String key, java.lang.Object[] args)
key
- the key used to find the informations about the constructorargs
- the arguments passed to this constructor
protected java.lang.Object[] interpretArguments(java.lang.Class c, TreeInterpreter.ConstructorParametersDescriptor cpd, java.lang.Object[] args)
c
- the declaring class of the constructorcpd
- the parameter descriptorargs
- the arguments passed to this constructor
protected void finalize() throws java.lang.Throwable
java.lang.Throwable
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |