org.codehaus.groovy.classgen
Class AsmClassGenerator

java.lang.Object
  extended byorg.codehaus.groovy.ast.CodeVisitorSupport
      extended byorg.codehaus.groovy.classgen.ClassGenerator
          extended byorg.codehaus.groovy.classgen.AsmClassGenerator
All Implemented Interfaces:
org.objectweb.asm.Constants, GroovyClassVisitor, GroovyCodeVisitor

public class AsmClassGenerator
extends ClassGenerator

Generates Java class versions of Groovy classes using ASM.

Version:
$Revision: 1.24 $
Author:
James Strachan, Bing Ran

Field Summary
(package private)  MethodCaller asBool
           
(package private)  MethodCaller asIntMethod
           
(package private)  MethodCaller asIteratorMethod
           
static boolean ASM_DEBUG
           
(package private)  MethodCaller assertFailedMethod
           
(package private)  MethodCaller asTypeMethod
           
(package private)  MethodCaller bitNegation
           
(package private)  java.util.Map classCache
           
private  ClassNode classNode
           
private  int columnNumber
           
(package private)  MethodCaller compareEqualMethod
           
(package private)  MethodCaller compareGreaterThanEqualMethod
           
(package private)  MethodCaller compareGreaterThanMethod
           
(package private)  MethodCaller compareIdenticalMethod
           
(package private)  MethodCaller compareLessThanEqualMethod
           
(package private)  MethodCaller compareLessThanMethod
           
(package private)  MethodCaller compareNotEqualMethod
           
(package private)  MethodCaller compareToMethod
           
private  ConstructorNode constructorNode
           
private  GeneratorContext context
           
(package private)  MethodCaller convertPrimitiveArray
           
(package private)  MethodCaller convertToPrimitiveArray
           
static boolean CREATE_DEBUG_INFO
           
static boolean CREATE_LINE_NUMBER_INFO
           
(package private)  MethodCaller createListMethod
           
(package private)  MethodCaller createMapMethod
           
(package private)  MethodCaller createRangeMethod
           
(package private)  MethodCaller createTupleMethod
           
private  ASTNode currentASTNode
           
private  org.objectweb.asm.CodeVisitor cv
           
private  org.objectweb.asm.ClassVisitor cw
           
private  boolean definingParameters
           
private  org.objectweb.asm.ClassWriter dummyClassWriter
           
private  DummyClassGenerator dummyGen
           
static java.lang.String EB_SWITCH_NAME
           
 boolean ENABLE_EARLY_BINDING
           
private  java.util.List exceptionBlocks
           
(package private)  MethodCaller findRegexMethod
           
(package private)  MethodCaller getAttributeMethod
           
(package private)  MethodCaller getAttributeSafeMethod
           
(package private)  MethodCaller getGroovyObjectPropertyMethod
           
(package private)  MethodCaller getPropertyMethod
           
(package private)  MethodCaller getPropertySafeMethod
           
private  BytecodeHelper helper
           
private  java.lang.String internalBaseClassName
           
private  java.lang.String internalClassName
           
(package private)  MethodCaller invokeClosureMethod
           
(package private)  MethodCaller invokeConstructorMethod
           
(package private)  MethodCaller invokeConstructorOfMethod
           
(package private)  MethodCaller invokeMethodMethod
           
(package private)  MethodCaller invokeMethodSafeMethod
           
(package private)  MethodCaller invokeNoArgumentsConstructorOf
           
(package private)  MethodCaller invokeNoArgumentsMethod
           
(package private)  MethodCaller invokeStaticMethodMethod
           
(package private)  MethodCaller invokeStaticNoArgumentsMethod
           
(package private)  MethodCaller invokeSuperMethodMethod
           
(package private)  MethodCaller isCaseMethod
           
(package private)  MethodCaller iteratorHasNextMethod
           
(package private)  MethodCaller iteratorNextMethod
           
private  int lastVariableIndex
           
private  boolean leftHandExpression
          are we on the left or right of an expression
private  int lineNumber
           
private  java.util.logging.Logger log
           
private static boolean MARK_START
           
(package private)  MethodCaller matchRegexMethod
           
private  MethodNode methodNode
           
private  java.util.Set mutableVars
           
(package private)  MethodCaller negation
           
(package private)  MethodCaller notBoolean
           
(package private)  MethodCaller notObject
           
private  ClassNode outermostClass
           
private  boolean outputReturn
          have we output a return statement yet
private  boolean passingClosureParams
           
(package private)  MethodCaller regexPattern
           
private  BlockScope scope
           
(package private)  MethodCaller setAttributeMethod2
           
(package private)  MethodCaller setAttributeSafeMethod2
           
(package private)  MethodCaller setGroovyObjectPropertyMethod
           
(package private)  MethodCaller setPropertyMethod
           
(package private)  MethodCaller setPropertyMethod2
           
(package private)  MethodCaller setPropertySafeMethod2
           
private  java.lang.String sourceFile
           
private  java.util.Set syntheticStaticFields
           
private static int tempVariableNameCounter
           
private  VariableScope variableScope
           
private  java.util.Map variableStack
          maps the variable names to the JVM indices
 
Fields inherited from class org.codehaus.groovy.classgen.ClassGenerator
asmJDKVersion, classLoader, innerClasses
 
Fields inherited from interface org.objectweb.asm.Constants
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, V1_1, V1_2, V1_3, V1_4, V1_5
 
Constructor Summary
AsmClassGenerator(GeneratorContext context, org.objectweb.asm.ClassVisitor classVisitor, java.lang.ClassLoader classLoader, java.lang.String sourceFile)
           
 
Method Summary
protected  void addFieldsToVisitor(VariableScope scope)
           
protected  boolean addInnerClass(ClassNode innerClass)
           
private  void addVariableNames(Expression expression, java.util.List list)
           
protected  boolean argumentsUseStack(Expression arguments)
           
private static boolean asBool(java.lang.Object object)
           
private static java.lang.Character asCharacter(java.lang.Number value)
           
private static java.lang.Character asCharacter(java.lang.String text)
           
private static java.lang.Object asType(java.lang.Object object, java.lang.Class type)
           
private  boolean canBeAssignedFrom(java.lang.Class l, java.lang.Class r)
           
private  boolean canBeAssignedFrom(Expression l, Expression r)
           
private  boolean canBeAssignedFrom(java.lang.String ltype, java.lang.String rtype)
           
private  void cast(java.lang.Class aClass)
           
protected  java.lang.String checkForQualifiedClass(PropertyExpression expression)
          Checks if the given property expression represents a fully qualified class name
protected  java.lang.String checkValidType(java.lang.String type, ASTNode node, java.lang.String message)
           
protected  Type checkValidType(Type type, ASTNode node, java.lang.String message)
           
private  void copyTypeClass(Expression leftExpression, Expression rightExpression)
           
protected  ClassNode createClosureClass(ClosureExpression expression)
           
private  void createDummyClass(ClassNode classNode)
           
protected  ClassNode createGStringClass(GStringExpression expression)
           
protected  Expression createReturnLHSExpression(Expression expression)
          For assignment expressions, return a safe expression for the LHS we can use to return the value
protected  Expression createReusableExpression(Expression expression)
           
protected  void createSyntheticStaticFields()
           
protected  java.lang.String createVariableName(java.lang.String type)
           
protected  Variable defineVariable(java.lang.String name, java.lang.String type)
          Defines the given variable in scope and assigns it to the stack
protected  Variable defineVariable(java.lang.String name, java.lang.String type, boolean define)
           
private  Variable defineVariable(java.lang.String name, Type type, boolean define)
           
protected  void doConvertAndCast(java.lang.String type)
           
protected  void doConvertAndCast(java.lang.String type, Expression expression, boolean ignoreAutoboxing)
          Casts to the given type unless it can be determined that the cast is unnecessary
protected  boolean emptyArguments(Expression arguments)
           
protected  void evalBinaryExp_EarlyBinding(MethodCaller compareMethod, BinaryExpression expression)
          note: leave the primitive boolean on staock for comparison expressions.
protected  void evalBinaryExp_LateBinding(MethodCaller compareMethod, BinaryExpression expression)
           
private  void evaluateBinaryExpression(MethodCaller compareMethod, BinaryExpression bin)
           
protected  void evaluateBinaryExpression(java.lang.String method, BinaryExpression expression)
           
protected  void evaluateBinaryExpressionWithAsignment(java.lang.String method, BinaryExpression expression)
           
protected  void evaluateCompareTo(BinaryExpression expression)
           
protected  void evaluateEqual(BinaryExpression expression)
           
protected  void evaluateExpression(Expression expression)
           
protected  void evaluateInstanceof(BinaryExpression expression)
           
protected  void evaluateLogicalAndExpression(BinaryExpression expression)
           
protected  void evaluateLogicalOrExpression(BinaryExpression expression)
           
protected  void evaluatePostfixMethod(java.lang.String method, Expression expression)
           
protected  void evaluatePrefixMethod(java.lang.String method, Expression expression)
           
protected  void findMutableVariables()
           
protected  ConstructorNode findSuperConstructor(MethodCallExpression call)
          Attempts to find the constructor in a super class
protected  MethodNode findSuperMethod(MethodCallExpression call)
          Attempts to find the method of the given name in a super class
protected  boolean firstStatementIsSuperInit(Statement code)
           
protected  Parameter[] getClosureSharedVariables(ClosureExpression expression)
           
protected  CompileUnit getCompileUnit()
           
protected  java.lang.String getExpressionType(Expression expression)
           
protected  java.lang.String getLHSType(Expression leftExpression)
          Deduces the type name required for some casting
private  MetaMethod getMethodOfThisAndSuper(java.lang.String methName, java.lang.Class[] argsArray, boolean isStaticCall)
          search in the current classNode and super class for matching method
private  int getNextVariableID()
           
protected  ClassNode getOutermostClass()
           
protected  VariableScope getVariableScope()
           
protected  java.lang.String getVariableType(java.lang.String name)
           
protected  boolean isComparisonExpression(Expression expression)
           
private  boolean isDoubleSizeVariable(Type type)
           
protected  boolean isFieldOrVariable(java.lang.String name)
           
protected  boolean isGroovyObject(Expression objectExpression)
           
protected  boolean isHolderVariable(Expression expression)
           
protected  boolean isInClosureConstructor()
           
private  boolean isInnerClass()
           
protected  boolean isInScriptBody()
           
protected  boolean isNonStaticField(Expression expression)
           
protected  boolean isNotFieldOfOutermostClass(java.lang.String var)
           
protected  boolean isPopRequired(Expression expression)
           
protected static boolean isPrimitiveFieldType(java.lang.String type)
           
protected  boolean isStaticMethod()
           
protected  boolean isThisExpression(Expression expression)
           
protected  boolean isValidTypeForCast(java.lang.String type)
           
private  void load(Expression exp)
           
protected  void loadArguments(Parameter[] parameters, Expression expression)
          Loads and coerces the argument values for the given method call
protected  java.lang.Class loadClass(java.lang.String name)
           
 void loadInstanceField(FieldExpression fldExp)
          RHS instance field.
 void loadStaticField(FieldExpression fldExp)
           
protected  void loadThisOrOwner()
          Loads either this object or if we're inside a closure then load the top level owner
protected  void onLineNumber(ASTNode statement, java.lang.String message)
           
protected  void popScope()
           
protected  void processFieldAccess(java.lang.String name, FieldNode field, int steps)
           
protected  void processPropertyVariable(Variable variable)
           
protected  void processStackVariable(Variable variable)
           
protected  void pushBlockScope()
           
protected  void pushBlockScope(boolean canContinue, boolean canBreak)
          create a new scope.
(package private)  void removeVar(Variable v)
           
protected  void resetVariableStack(Parameter[] parameters)
           
 void resolve(AttributeExpression attributeExpression)
           
 void resolve(ConstructorCallExpression call)
          attemtp to identify the exact runtime method call the expression is intended for, for possible early binding.
 void resolve(MethodCallExpression call)
          attemtp to identify the exact runtime method call the expression is intended for, for possible early binding.
 void resolve(PropertyExpression propertyExpression)
           
 MetaMethod resolve(StaticMethodCallExpression staticCall)
           
 void resolve(VariableExpression expression)
          to find out the real type of a Variable Object
protected  java.lang.String resolveClassName(java.lang.String type)
           
private  void store(Expression expression)
           
private  Variable storeInTemp(java.lang.String name, java.lang.String type)
           
 void storeStaticField(FieldExpression expression)
           
 void storeThisInstanceField(FieldExpression expression)
           
private  void throwException(java.lang.String s)
           
protected  void visitAndAutoboxBoolean(Expression expression)
           
 void visitArrayExpression(ArrayExpression expression)
           
 void visitAssertStatement(AssertStatement statement)
           
private  Variable visitASTOREInTemp(java.lang.String s)
           
 void visitAttributeExpression(AttributeExpression expression)
           
 void visitBinaryExpression(BinaryExpression expression)
           
 void visitBitwiseNegExpression(BitwiseNegExpression expression)
           
 void visitBooleanExpression(BooleanExpression expression)
          return a primitive boolean value of the BooleanExpresion.
 void visitBreakStatement(BreakStatement statement)
           
 void visitCaseStatement(CaseStatement statement)
           
 void visitCaseStatement(CaseStatement statement, int switchVariableIndex, org.objectweb.asm.Label thisLabel, org.objectweb.asm.Label nextLabel)
           
 void visitCastExpression(CastExpression expression)
           
 void visitClass(ClassNode classNode)
           
 void visitClassExpression(ClassExpression expression)
          load class object on stack
 void visitClosureExpression(ClosureExpression expression)
           
 void visitConstantExpression(ConstantExpression expression)
          Generate byte code for constants
 void visitConstructor(ConstructorNode node)
           
 void visitConstructorCallExpression(ConstructorCallExpression call)
           
 void visitContinueStatement(ContinueStatement statement)
           
 void visitDoWhileLoop(DoWhileStatement loop)
           
 void visitExpressionStatement(ExpressionStatement statement)
           
 void visitField(FieldNode fieldNode)
           
 void visitFieldExpression(FieldExpression expression)
           
 void visitForLoop(ForStatement loop)
           
 void visitGStringExpression(GStringExpression expression)
           
 void visitIfElse(IfStatement ifElse)
           
 void visitListExpression(ListExpression expression)
           
 void visitMapEntryExpression(MapEntryExpression expression)
           
 void visitMapExpression(MapExpression expression)
           
 void visitMethod(MethodNode node)
           
 void visitMethodCallExpression(MethodCallExpression call)
           
 void visitNegationExpression(NegationExpression expression)
           
 void visitNotExpression(NotExpression expression)
           
protected  void visitOuterFieldExpression(FieldExpression expression, ClassNode outerClassNode, int steps, boolean first)
           
protected  void visitParameter(ASTNode node, Parameter parameter)
           
protected  void visitParameters(ASTNode node, Parameter[] parameters)
           
 void visitPostfixExpression(PostfixExpression expression)
           
 void visitPrefixExpression(PrefixExpression expression)
           
 void visitProperty(PropertyNode statement)
          Creates a getter, setter and field
 void visitPropertyExpression(PropertyExpression expression)
           
 void visitRangeExpression(RangeExpression expression)
           
 void visitRegexExpression(RegexExpression expression)
           
 void visitReturnStatement(ReturnStatement statement)
           
 void visitStaticMethodCallExpression(StaticMethodCallExpression call)
           
 void visitSwitch(SwitchStatement statement)
           
 void visitSynchronizedStatement(SynchronizedStatement statement)
           
 void visitTernaryExpression(TernaryExpression expression)
           
 void visitThrowStatement(ThrowStatement statement)
           
 void visitTryCatchFinally(TryCatchStatement statement)
           
 void visitTupleExpression(TupleExpression expression)
           
private  void visitVariableEndLabel(Variable v)
           
 void visitVariableExpression(VariableExpression expression)
          Visits a bare (unqualified) variable expression.
private  void visitVariableStartLabel(Variable variable)
           
 void visitWhileLoop(WhileStatement loop)
           
 
Methods inherited from class org.codehaus.groovy.classgen.ClassGenerator
getClassLoader, getInnerClasses
 
Methods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport
visitBlockStatement, visitListOfExpressions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private java.util.logging.Logger log

cw

private org.objectweb.asm.ClassVisitor cw

cv

private org.objectweb.asm.CodeVisitor cv

context

private GeneratorContext context

sourceFile

private java.lang.String sourceFile

classNode

private ClassNode classNode

outermostClass

private ClassNode outermostClass

internalClassName

private java.lang.String internalClassName

internalBaseClassName

private java.lang.String internalBaseClassName

variableStack

private java.util.Map variableStack
maps the variable names to the JVM indices


outputReturn

private boolean outputReturn
have we output a return statement yet


leftHandExpression

private boolean leftHandExpression
are we on the left or right of an expression


invokeMethodMethod

MethodCaller invokeMethodMethod

invokeMethodSafeMethod

MethodCaller invokeMethodSafeMethod

invokeStaticMethodMethod

MethodCaller invokeStaticMethodMethod

invokeConstructorMethod

MethodCaller invokeConstructorMethod

invokeConstructorOfMethod

MethodCaller invokeConstructorOfMethod

invokeNoArgumentsConstructorOf

MethodCaller invokeNoArgumentsConstructorOf

invokeClosureMethod

MethodCaller invokeClosureMethod

invokeSuperMethodMethod

MethodCaller invokeSuperMethodMethod

invokeNoArgumentsMethod

MethodCaller invokeNoArgumentsMethod

invokeStaticNoArgumentsMethod

MethodCaller invokeStaticNoArgumentsMethod

asIntMethod

MethodCaller asIntMethod

asTypeMethod

MethodCaller asTypeMethod

getAttributeMethod

MethodCaller getAttributeMethod

getAttributeSafeMethod

MethodCaller getAttributeSafeMethod

setAttributeMethod2

MethodCaller setAttributeMethod2

setAttributeSafeMethod2

MethodCaller setAttributeSafeMethod2

getPropertyMethod

MethodCaller getPropertyMethod

getPropertySafeMethod

MethodCaller getPropertySafeMethod

setPropertyMethod

MethodCaller setPropertyMethod

setPropertyMethod2

MethodCaller setPropertyMethod2

setPropertySafeMethod2

MethodCaller setPropertySafeMethod2

getGroovyObjectPropertyMethod

MethodCaller getGroovyObjectPropertyMethod

setGroovyObjectPropertyMethod

MethodCaller setGroovyObjectPropertyMethod

asIteratorMethod

MethodCaller asIteratorMethod

asBool

MethodCaller asBool

notBoolean

MethodCaller notBoolean

notObject

MethodCaller notObject

regexPattern

MethodCaller regexPattern

negation

MethodCaller negation

bitNegation

MethodCaller bitNegation

convertPrimitiveArray

MethodCaller convertPrimitiveArray

convertToPrimitiveArray

MethodCaller convertToPrimitiveArray

compareIdenticalMethod

MethodCaller compareIdenticalMethod

compareEqualMethod

MethodCaller compareEqualMethod

compareNotEqualMethod

MethodCaller compareNotEqualMethod

compareToMethod

MethodCaller compareToMethod

findRegexMethod

MethodCaller findRegexMethod

matchRegexMethod

MethodCaller matchRegexMethod

compareLessThanMethod

MethodCaller compareLessThanMethod

compareLessThanEqualMethod

MethodCaller compareLessThanEqualMethod

compareGreaterThanMethod

MethodCaller compareGreaterThanMethod

compareGreaterThanEqualMethod

MethodCaller compareGreaterThanEqualMethod

isCaseMethod

MethodCaller isCaseMethod

createListMethod

MethodCaller createListMethod

createTupleMethod

MethodCaller createTupleMethod

createMapMethod

MethodCaller createMapMethod

createRangeMethod

MethodCaller createRangeMethod

assertFailedMethod

MethodCaller assertFailedMethod

iteratorNextMethod

MethodCaller iteratorNextMethod

iteratorHasNextMethod

MethodCaller iteratorHasNextMethod

lastVariableIndex

private int lastVariableIndex

tempVariableNameCounter

private static int tempVariableNameCounter

exceptionBlocks

private java.util.List exceptionBlocks

definingParameters

private boolean definingParameters

syntheticStaticFields

private java.util.Set syntheticStaticFields

mutableVars

private java.util.Set mutableVars

passingClosureParams

private boolean passingClosureParams

constructorNode

private ConstructorNode constructorNode

methodNode

private MethodNode methodNode

scope

private BlockScope scope

helper

private BytecodeHelper helper

variableScope

private VariableScope variableScope

CREATE_DEBUG_INFO

public static final boolean CREATE_DEBUG_INFO
See Also:
Constant Field Values

CREATE_LINE_NUMBER_INFO

public static final boolean CREATE_LINE_NUMBER_INFO
See Also:
Constant Field Values

MARK_START

private static final boolean MARK_START
See Also:
Constant Field Values

EB_SWITCH_NAME

public static final java.lang.String EB_SWITCH_NAME
See Also:
Constant Field Values

ENABLE_EARLY_BINDING

public boolean ENABLE_EARLY_BINDING

ASM_DEBUG

public static final boolean ASM_DEBUG
See Also:
Constant Field Values

lineNumber

private int lineNumber

columnNumber

private int columnNumber

currentASTNode

private ASTNode currentASTNode

dummyGen

private DummyClassGenerator dummyGen

dummyClassWriter

private org.objectweb.asm.ClassWriter dummyClassWriter

classCache

java.util.Map classCache
Constructor Detail

AsmClassGenerator

public AsmClassGenerator(GeneratorContext context,
                         org.objectweb.asm.ClassVisitor classVisitor,
                         java.lang.ClassLoader classLoader,
                         java.lang.String sourceFile)
Method Detail

visitClass

public void visitClass(ClassNode classNode)

createDummyClass

private void createDummyClass(ClassNode classNode)

visitConstructor

public void visitConstructor(ConstructorNode node)

visitMethod

public void visitMethod(MethodNode node)

visitParameters

protected void visitParameters(ASTNode node,
                               Parameter[] parameters)

visitParameter

protected void visitParameter(ASTNode node,
                              Parameter parameter)

visitField

public void visitField(FieldNode fieldNode)

visitProperty

public void visitProperty(PropertyNode statement)
Creates a getter, setter and field


visitForLoop

public void visitForLoop(ForStatement loop)
Specified by:
visitForLoop in interface GroovyCodeVisitor
Overrides:
visitForLoop in class CodeVisitorSupport

visitWhileLoop

public void visitWhileLoop(WhileStatement loop)
Specified by:
visitWhileLoop in interface GroovyCodeVisitor
Overrides:
visitWhileLoop in class CodeVisitorSupport

visitDoWhileLoop

public void visitDoWhileLoop(DoWhileStatement loop)
Specified by:
visitDoWhileLoop in interface GroovyCodeVisitor
Overrides:
visitDoWhileLoop in class CodeVisitorSupport

visitIfElse

public void visitIfElse(IfStatement ifElse)
Specified by:
visitIfElse in interface GroovyCodeVisitor
Overrides:
visitIfElse in class CodeVisitorSupport

visitTernaryExpression

public void visitTernaryExpression(TernaryExpression expression)
Specified by:
visitTernaryExpression in interface GroovyCodeVisitor
Overrides:
visitTernaryExpression in class CodeVisitorSupport

visitAssertStatement

public void visitAssertStatement(AssertStatement statement)
Specified by:
visitAssertStatement in interface GroovyCodeVisitor
Overrides:
visitAssertStatement in class CodeVisitorSupport

addVariableNames

private void addVariableNames(Expression expression,
                              java.util.List list)

visitTryCatchFinally

public void visitTryCatchFinally(TryCatchStatement statement)
Specified by:
visitTryCatchFinally in interface GroovyCodeVisitor
Overrides:
visitTryCatchFinally in class CodeVisitorSupport

storeInTemp

private Variable storeInTemp(java.lang.String name,
                             java.lang.String type)

visitSwitch

public void visitSwitch(SwitchStatement statement)
Specified by:
visitSwitch in interface GroovyCodeVisitor
Overrides:
visitSwitch in class CodeVisitorSupport

visitCaseStatement

public void visitCaseStatement(CaseStatement statement)
Specified by:
visitCaseStatement in interface GroovyCodeVisitor
Overrides:
visitCaseStatement in class CodeVisitorSupport

visitCaseStatement

public void visitCaseStatement(CaseStatement statement,
                               int switchVariableIndex,
                               org.objectweb.asm.Label thisLabel,
                               org.objectweb.asm.Label nextLabel)

visitBreakStatement

public void visitBreakStatement(BreakStatement statement)
Specified by:
visitBreakStatement in interface GroovyCodeVisitor
Overrides:
visitBreakStatement in class CodeVisitorSupport

visitContinueStatement

public void visitContinueStatement(ContinueStatement statement)
Specified by:
visitContinueStatement in interface GroovyCodeVisitor
Overrides:
visitContinueStatement in class CodeVisitorSupport

visitSynchronizedStatement

public void visitSynchronizedStatement(SynchronizedStatement statement)
Specified by:
visitSynchronizedStatement in interface GroovyCodeVisitor
Overrides:
visitSynchronizedStatement in class CodeVisitorSupport

visitThrowStatement

public void visitThrowStatement(ThrowStatement statement)
Specified by:
visitThrowStatement in interface GroovyCodeVisitor
Overrides:
visitThrowStatement in class CodeVisitorSupport

visitReturnStatement

public void visitReturnStatement(ReturnStatement statement)
Specified by:
visitReturnStatement in interface GroovyCodeVisitor
Overrides:
visitReturnStatement in class CodeVisitorSupport

doConvertAndCast

protected void doConvertAndCast(java.lang.String type,
                                Expression expression,
                                boolean ignoreAutoboxing)
Casts to the given type unless it can be determined that the cast is unnecessary


evaluateExpression

protected void evaluateExpression(Expression expression)
Parameters:
expression -

visitExpressionStatement

public void visitExpressionStatement(ExpressionStatement statement)
Specified by:
visitExpressionStatement in interface GroovyCodeVisitor
Overrides:
visitExpressionStatement in class CodeVisitorSupport

visitBinaryExpression

public void visitBinaryExpression(BinaryExpression expression)
Specified by:
visitBinaryExpression in interface GroovyCodeVisitor
Overrides:
visitBinaryExpression in class CodeVisitorSupport

load

private void load(Expression exp)

visitPostfixExpression

public void visitPostfixExpression(PostfixExpression expression)
Specified by:
visitPostfixExpression in interface GroovyCodeVisitor
Overrides:
visitPostfixExpression in class CodeVisitorSupport

store

private void store(Expression expression)

throwException

private void throwException(java.lang.String s)

visitPrefixExpression

public void visitPrefixExpression(PrefixExpression expression)
Specified by:
visitPrefixExpression in interface GroovyCodeVisitor
Overrides:
visitPrefixExpression in class CodeVisitorSupport

visitClosureExpression

public void visitClosureExpression(ClosureExpression expression)
Specified by:
visitClosureExpression in interface GroovyCodeVisitor
Overrides:
visitClosureExpression in class CodeVisitorSupport

loadThisOrOwner

protected void loadThisOrOwner()
Loads either this object or if we're inside a closure then load the top level owner


visitRegexExpression

public void visitRegexExpression(RegexExpression expression)
Specified by:
visitRegexExpression in interface GroovyCodeVisitor
Overrides:
visitRegexExpression in class CodeVisitorSupport

visitConstantExpression

public void visitConstantExpression(ConstantExpression expression)
Generate byte code for constants

Specified by:
visitConstantExpression in interface GroovyCodeVisitor
Overrides:
visitConstantExpression in class CodeVisitorSupport
See Also:
Class field types

visitNegationExpression

public void visitNegationExpression(NegationExpression expression)
Specified by:
visitNegationExpression in interface GroovyCodeVisitor
Overrides:
visitNegationExpression in class CodeVisitorSupport

visitBitwiseNegExpression

public void visitBitwiseNegExpression(BitwiseNegExpression expression)
Specified by:
visitBitwiseNegExpression in interface GroovyCodeVisitor
Overrides:
visitBitwiseNegExpression in class CodeVisitorSupport

visitCastExpression

public void visitCastExpression(CastExpression expression)
Specified by:
visitCastExpression in interface GroovyCodeVisitor
Overrides:
visitCastExpression in class CodeVisitorSupport

visitNotExpression

public void visitNotExpression(NotExpression expression)
Specified by:
visitNotExpression in interface GroovyCodeVisitor
Overrides:
visitNotExpression in class CodeVisitorSupport

visitBooleanExpression

public void visitBooleanExpression(BooleanExpression expression)
return a primitive boolean value of the BooleanExpresion.

Specified by:
visitBooleanExpression in interface GroovyCodeVisitor
Overrides:
visitBooleanExpression in class CodeVisitorSupport
Parameters:
expression -

visitMethodCallExpression

public void visitMethodCallExpression(MethodCallExpression call)
Specified by:
visitMethodCallExpression in interface GroovyCodeVisitor
Overrides:
visitMethodCallExpression in class CodeVisitorSupport

loadArguments

protected void loadArguments(Parameter[] parameters,
                             Expression expression)
Loads and coerces the argument values for the given method call


findSuperMethod

protected MethodNode findSuperMethod(MethodCallExpression call)
Attempts to find the method of the given name in a super class


findSuperConstructor

protected ConstructorNode findSuperConstructor(MethodCallExpression call)
Attempts to find the constructor in a super class


emptyArguments

protected boolean emptyArguments(Expression arguments)

visitStaticMethodCallExpression

public void visitStaticMethodCallExpression(StaticMethodCallExpression call)
Specified by:
visitStaticMethodCallExpression in interface GroovyCodeVisitor
Overrides:
visitStaticMethodCallExpression in class CodeVisitorSupport

visitConstructorCallExpression

public void visitConstructorCallExpression(ConstructorCallExpression call)
Specified by:
visitConstructorCallExpression in interface GroovyCodeVisitor
Overrides:
visitConstructorCallExpression in class CodeVisitorSupport

visitPropertyExpression

public void visitPropertyExpression(PropertyExpression expression)
Specified by:
visitPropertyExpression in interface GroovyCodeVisitor
Overrides:
visitPropertyExpression in class CodeVisitorSupport

visitAttributeExpression

public void visitAttributeExpression(AttributeExpression expression)
Specified by:
visitAttributeExpression in interface GroovyCodeVisitor
Overrides:
visitAttributeExpression in class CodeVisitorSupport

isGroovyObject

protected boolean isGroovyObject(Expression objectExpression)

checkForQualifiedClass

protected java.lang.String checkForQualifiedClass(PropertyExpression expression)
Checks if the given property expression represents a fully qualified class name

Returns:
the class name or null if the property is not a valid class name

visitFieldExpression

public void visitFieldExpression(FieldExpression expression)
Specified by:
visitFieldExpression in interface GroovyCodeVisitor
Overrides:
visitFieldExpression in class CodeVisitorSupport

loadStaticField

public void loadStaticField(FieldExpression fldExp)
Parameters:
fldExp -

loadInstanceField

public void loadInstanceField(FieldExpression fldExp)
RHS instance field. should move most of the code in the BytecodeHelper

Parameters:
fldExp -

storeThisInstanceField

public void storeThisInstanceField(FieldExpression expression)

storeStaticField

public void storeStaticField(FieldExpression expression)

visitOuterFieldExpression

protected void visitOuterFieldExpression(FieldExpression expression,
                                         ClassNode outerClassNode,
                                         int steps,
                                         boolean first)

visitVariableExpression

public void visitVariableExpression(VariableExpression expression)
Visits a bare (unqualified) variable expression.

Specified by:
visitVariableExpression in interface GroovyCodeVisitor
Overrides:
visitVariableExpression in class CodeVisitorSupport

processStackVariable

protected void processStackVariable(Variable variable)

visitVariableStartLabel

private void visitVariableStartLabel(Variable variable)

processPropertyVariable

protected void processPropertyVariable(Variable variable)

processFieldAccess

protected void processFieldAccess(java.lang.String name,
                                  FieldNode field,
                                  int steps)

isInScriptBody

protected boolean isInScriptBody()
Returns:
true if we are in a script body, where all variables declared are no longer local variables but are properties

isPopRequired

protected boolean isPopRequired(Expression expression)
Returns:
true if this expression will have left a value on the stack that must be popped

firstStatementIsSuperInit

protected boolean firstStatementIsSuperInit(Statement code)

createSyntheticStaticFields

protected void createSyntheticStaticFields()

visitClassExpression

public void visitClassExpression(ClassExpression expression)
load class object on stack

Specified by:
visitClassExpression in interface GroovyCodeVisitor
Overrides:
visitClassExpression in class CodeVisitorSupport

visitRangeExpression

public void visitRangeExpression(RangeExpression expression)
Specified by:
visitRangeExpression in interface GroovyCodeVisitor
Overrides:
visitRangeExpression in class CodeVisitorSupport

visitMapEntryExpression

public void visitMapEntryExpression(MapEntryExpression expression)
Specified by:
visitMapEntryExpression in interface GroovyCodeVisitor
Overrides:
visitMapEntryExpression in class CodeVisitorSupport

visitMapExpression

public void visitMapExpression(MapExpression expression)
Specified by:
visitMapExpression in interface GroovyCodeVisitor
Overrides:
visitMapExpression in class CodeVisitorSupport

visitTupleExpression

public void visitTupleExpression(TupleExpression expression)
Specified by:
visitTupleExpression in interface GroovyCodeVisitor
Overrides:
visitTupleExpression in class CodeVisitorSupport

visitArrayExpression

public void visitArrayExpression(ArrayExpression expression)
Specified by:
visitArrayExpression in interface GroovyCodeVisitor
Overrides:
visitArrayExpression in class CodeVisitorSupport

visitListExpression

public void visitListExpression(ListExpression expression)
Specified by:
visitListExpression in interface GroovyCodeVisitor
Overrides:
visitListExpression in class CodeVisitorSupport

visitGStringExpression

public void visitGStringExpression(GStringExpression expression)
Specified by:
visitGStringExpression in interface GroovyCodeVisitor
Overrides:
visitGStringExpression in class CodeVisitorSupport

visitASTOREInTemp

private Variable visitASTOREInTemp(java.lang.String s)

addInnerClass

protected boolean addInnerClass(ClassNode innerClass)

createClosureClass

protected ClassNode createClosureClass(ClosureExpression expression)

getOutermostClass

protected ClassNode getOutermostClass()

createGStringClass

protected ClassNode createGStringClass(GStringExpression expression)

doConvertAndCast

protected void doConvertAndCast(java.lang.String type)

evaluateLogicalOrExpression

protected void evaluateLogicalOrExpression(BinaryExpression expression)

evaluateLogicalAndExpression

protected void evaluateLogicalAndExpression(BinaryExpression expression)

evaluateBinaryExpression

protected void evaluateBinaryExpression(java.lang.String method,
                                        BinaryExpression expression)

evaluateCompareTo

protected void evaluateCompareTo(BinaryExpression expression)

evaluateBinaryExpressionWithAsignment

protected void evaluateBinaryExpressionWithAsignment(java.lang.String method,
                                                     BinaryExpression expression)

evaluateBinaryExpression

private void evaluateBinaryExpression(MethodCaller compareMethod,
                                      BinaryExpression bin)

evalBinaryExp_LateBinding

protected void evalBinaryExp_LateBinding(MethodCaller compareMethod,
                                         BinaryExpression expression)

evalBinaryExp_EarlyBinding

protected void evalBinaryExp_EarlyBinding(MethodCaller compareMethod,
                                          BinaryExpression expression)
note: leave the primitive boolean on staock for comparison expressions. All the result types need to match the utility methods in the ScriptBytecodeAdapter.

Parameters:
compareMethod -
expression -

cast

private void cast(java.lang.Class aClass)

evaluateEqual

protected void evaluateEqual(BinaryExpression expression)

copyTypeClass

private void copyTypeClass(Expression leftExpression,
                           Expression rightExpression)

canBeAssignedFrom

private boolean canBeAssignedFrom(java.lang.String ltype,
                                  java.lang.String rtype)

canBeAssignedFrom

private boolean canBeAssignedFrom(Expression l,
                                  Expression r)

canBeAssignedFrom

private boolean canBeAssignedFrom(java.lang.Class l,
                                  java.lang.Class r)

getLHSType

protected java.lang.String getLHSType(Expression leftExpression)
Deduces the type name required for some casting

Returns:
the type of the given (LHS) expression or null if it is java.lang.Object or it cannot be deduced

isValidTypeForCast

protected boolean isValidTypeForCast(java.lang.String type)

visitAndAutoboxBoolean

protected void visitAndAutoboxBoolean(Expression expression)

evaluatePrefixMethod

protected void evaluatePrefixMethod(java.lang.String method,
                                    Expression expression)

evaluatePostfixMethod

protected void evaluatePostfixMethod(java.lang.String method,
                                     Expression expression)

isHolderVariable

protected boolean isHolderVariable(Expression expression)

evaluateInstanceof

protected void evaluateInstanceof(BinaryExpression expression)

argumentsUseStack

protected boolean argumentsUseStack(Expression arguments)
Returns:
true if the given argument expression requires the stack, in which case the arguments are evaluated first, stored in the variable stack and then reloaded to make a method call

isNonStaticField

protected boolean isNonStaticField(Expression expression)
Returns:
true if the given expression represents a non-static field

isThisExpression

protected boolean isThisExpression(Expression expression)

createReturnLHSExpression

protected Expression createReturnLHSExpression(Expression expression)
For assignment expressions, return a safe expression for the LHS we can use to return the value


createReusableExpression

protected Expression createReusableExpression(Expression expression)

isComparisonExpression

protected boolean isComparisonExpression(Expression expression)

onLineNumber

protected void onLineNumber(ASTNode statement,
                            java.lang.String message)

getVariableScope

protected VariableScope getVariableScope()

getClosureSharedVariables

protected Parameter[] getClosureSharedVariables(ClosureExpression expression)
Returns:
a list of parameters for each local variable which needs to be passed into a closure

isNotFieldOfOutermostClass

protected boolean isNotFieldOfOutermostClass(java.lang.String var)

findMutableVariables

protected void findMutableVariables()

addFieldsToVisitor

protected void addFieldsToVisitor(VariableScope scope)

isInnerClass

private boolean isInnerClass()

getVariableType

protected java.lang.String getVariableType(java.lang.String name)

resetVariableStack

protected void resetVariableStack(Parameter[] parameters)

popScope

protected void popScope()

removeVar

void removeVar(Variable v)

visitVariableEndLabel

private void visitVariableEndLabel(Variable v)

pushBlockScope

protected void pushBlockScope()

pushBlockScope

protected void pushBlockScope(boolean canContinue,
                              boolean canBreak)
create a new scope. Set break/continue label if the canXXX parameter is true. Otherwise inherit parent's label.

Parameters:
canContinue - true if the start of the scope can take continue label
canBreak - true if the end of the scope can take break label

defineVariable

protected Variable defineVariable(java.lang.String name,
                                  java.lang.String type)
Defines the given variable in scope and assigns it to the stack


defineVariable

protected Variable defineVariable(java.lang.String name,
                                  java.lang.String type,
                                  boolean define)

defineVariable

private Variable defineVariable(java.lang.String name,
                                Type type,
                                boolean define)

isDoubleSizeVariable

private boolean isDoubleSizeVariable(Type type)

getNextVariableID

private int getNextVariableID()

isFieldOrVariable

protected boolean isFieldOrVariable(java.lang.String name)
Returns:
true if the given name is a local variable or a field

checkValidType

protected Type checkValidType(Type type,
                              ASTNode node,
                              java.lang.String message)

checkValidType

protected java.lang.String checkValidType(java.lang.String type,
                                          ASTNode node,
                                          java.lang.String message)

resolveClassName

protected java.lang.String resolveClassName(java.lang.String type)

createVariableName

protected java.lang.String createVariableName(java.lang.String type)

getExpressionType

protected java.lang.String getExpressionType(Expression expression)
Returns:
if the type of the expression can be determined at compile time then this method returns the type - otherwise null

isPrimitiveFieldType

protected static boolean isPrimitiveFieldType(java.lang.String type)
Returns:
true if the value is an Integer, a Float, a Long, a Double or a String .

isInClosureConstructor

protected boolean isInClosureConstructor()

isStaticMethod

protected boolean isStaticMethod()

loadClass

protected java.lang.Class loadClass(java.lang.String name)
Returns:
loads the given type name

getCompileUnit

protected CompileUnit getCompileUnit()

resolve

public void resolve(MethodCallExpression call)
attemtp to identify the exact runtime method call the expression is intended for, for possible early binding.

Parameters:
call -

resolve

public void resolve(ConstructorCallExpression call)
attemtp to identify the exact runtime method call the expression is intended for, for possible early binding.

Parameters:
call -

resolve

public void resolve(PropertyExpression propertyExpression)

resolve

public void resolve(AttributeExpression attributeExpression)

getMethodOfThisAndSuper

private MetaMethod getMethodOfThisAndSuper(java.lang.String methName,
                                           java.lang.Class[] argsArray,
                                           boolean isStaticCall)
search in the current classNode and super class for matching method


resolve

public void resolve(VariableExpression expression)
to find out the real type of a Variable Object


resolve

public MetaMethod resolve(StaticMethodCallExpression staticCall)

asType

private static java.lang.Object asType(java.lang.Object object,
                                       java.lang.Class type)

asBool

private static boolean asBool(java.lang.Object object)

asCharacter

private static java.lang.Character asCharacter(java.lang.Number value)

asCharacter

private static java.lang.Character asCharacter(java.lang.String text)


Copyright © 2003-2005 The Codehaus. All Rights Reserved.