|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.objectweb.fractal.julia.asm.AbstractCodeGenerator
public abstract class AbstractCodeGenerator
An abstract CodeGenerator
to add interception code
"around" methods. More precisely, depending on the result of the getInterceptionType
method, the code adapters returned
by the generateInterceptionCode
method
(see CodeGenerator
) transform the original methods into
methods of the following form:
method-signature { // pre code block generated by 'generateInterceptionCodeBlock' // original method code }if
getInterceptionType
returns
EMPTY
,
method-signature { return-type result; // pre code block generated by 'generateInterceptionCodeBlock' // original method code, where returns are replaced with gotos // post code block generated by 'generateInterceptionCodeBlock' return result; }if
getInterceptionType
returns
NORMAL
,
method-signature { // pre code block generated by 'generateInterceptionCodeBlock' try { // original method code } finally { // post code block generated by 'generateInterceptionCodeBlock' } }if
getInterceptionType
returns
FINALLY
.
Field Summary |
---|
Fields inherited from interface org.objectweb.fractal.julia.asm.CodeGenerator |
---|
IN, IN_OUT, OUT |
Constructor Summary | |
---|---|
AbstractCodeGenerator()
|
Method Summary | |
---|---|
void |
close()
Closes this code generator. |
void |
generateCloneCode(MethodVisitor cv)
Generates the cloning code for this code generator. |
void |
generateInitCode(MethodVisitor cv)
Generates the initialization code for this code generator. |
MethodVisitor |
generateInterceptionCode(Method m,
MethodVisitor cv)
Generates the interception code for the given method. |
protected abstract void |
generateInterceptionCodeBlock(Method m,
boolean pre,
MethodVisitor cv,
int formals)
Generates an interception code block for the given method. |
List |
getImplementedInterfaces()
Returns the list of interfaces to be added to be implemented by the generated interceptor. |
protected int |
getInterceptionCodeFormals(Method m)
Returns the number of local variables that are used by the generated interception code. |
protected int |
getInterceptionType(Method m)
Returns the type of the interception code to be generated for the given method. |
int |
init(InterceptorClassGenerator icg)
Initializes this code generator. |
protected boolean |
intercept(Method m)
Returns true if this code generator must generate interception code for the given method. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractCodeGenerator()
Method Detail |
---|
public int init(InterceptorClassGenerator icg)
CodeGenerator
init
in interface CodeGenerator
icg
- the interceptor class generator to which this code generator
belongs.
IN
,
OUT
or IN_OUT
.public void generateInitCode(MethodVisitor cv) throws ClassGenerationException
CodeGenerator
initFcController
method by the interceptor class generator that calls this
method. By hypothesis, the stack is empty at the beginning of the generated
code. Moreover, the stack must also be empty at the end of the code
generated by this method.
generateInitCode
in interface CodeGenerator
cv
- the method visitor to be used to generate the initialization
code.
ClassGenerationException
- if a problem occurs.public MethodVisitor generateInterceptionCode(Method m, MethodVisitor cv) throws ClassGenerationException
CodeGenerator
generateInterceptionCode
in interface CodeGenerator
m
- the method for which the interception code must be generated.cv
- the method visitor to be used to generate the interception code.
CodeAdapter
, that should add the
interception code to the visited code on the fly. See CodeGenerator
.
ClassGenerationException
- if a problem occurs.public void generateCloneCode(MethodVisitor cv) throws ClassGenerationException
CodeGenerator
clone
method by the interceptor class generator that calls this method. By
hypothesis, the stack is empty at the beginning of the generated code.
Moreover, the stack must also be empty at the end of the code generated by
this method.
generateCloneCode
in interface CodeGenerator
cv
- the method visitor to be used to generate the cloning code.
ClassGenerationException
- if a problem occurs.public void close()
CodeGenerator
close
in interface CodeGenerator
protected boolean intercept(Method m)
m
- a method object.
protected int getInterceptionType(Method m)
NORMAL
for all methods.
m
- a method object.
EMPTY
to generate only a pre
code block at the beginning of the method, NORMAL
to generate both a pre code
block and a post code block, or FINALLY
to generate a pre code block, and a post code block inside a
finally block (to be sure that the post code block will always be
executed).protected int getInterceptionCodeFormals(Method m)
m
- a method object.
protected abstract void generateInterceptionCodeBlock(Method m, boolean pre, MethodVisitor cv, int formals)
m
- the method for which the interception code must be generated.pre
- true to generate a pre code block, or false to
generate a post code block.cv
- the method visitor to be used to generate the interception code.formals
- the index of the first local variable reserved for the code
block. The generated code can use the local variables between indexes
formals, inclusive, and formals +
getInterceptionCodeFormals(m), exclusive.public List getImplementedInterfaces() throws ClassGenerationException
This method provides an empty implementation, returning an empty List.
Subclasses which need to add interfaces to be implemented by the generated interceptor should override this method.
getImplementedInterfaces
in interface CodeGenerator
ClassGenerationException
- if a problem occurs.CodeGenerator.getImplementedInterfaces()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |