com.ibm.wala.cast.java.translator
Class JavaCAst2IRTranslator

java.lang.Object
  extended by com.ibm.wala.cast.tree.visit.CAstVisitor
      extended by com.ibm.wala.cast.ir.translator.AstTranslator
          extended by com.ibm.wala.cast.java.translator.JavaCAst2IRTranslator
All Implemented Interfaces:
ArrayOpHandler, TranslatorToIR

public class JavaCAst2IRTranslator
extends AstTranslator


Nested Class Summary
 
Nested classes/interfaces inherited from class com.ibm.wala.cast.ir.translator.AstTranslator
AstTranslator.AstCFG, AstTranslator.AstLexicalInformation, AstTranslator.DefaultContext, AstTranslator.FinalCAstSymbol, AstTranslator.IncipientCFG, AstTranslator.InternalCAstSymbol, AstTranslator.PreBasicBlock, AstTranslator.Scope, AstTranslator.ScopeType, AstTranslator.Symbol, AstTranslator.UnwindState, AstTranslator.WalkContext
 
Nested classes/interfaces inherited from class com.ibm.wala.cast.tree.visit.CAstVisitor
CAstVisitor.Context
 
Field Summary
 
Fields inherited from class com.ibm.wala.cast.ir.translator.AstTranslator
DEBUG_ALL, DEBUG_CFG, DEBUG_LEXICAL, DEBUG_NAMES, DEBUG_TOP, insts, loader, namedEntityResolver
 
Constructor Summary
JavaCAst2IRTranslator(ModuleEntry module, CAstEntity sourceFileEntity, JavaSourceLoaderImpl loader)
           
 
Method Summary
protected  java.lang.String composeEntityName(AstTranslator.WalkContext parent, CAstEntity f)
          create the language-appropriate name for f
protected  void declareFunction(CAstEntity N, AstTranslator.WalkContext definingContext)
          declare a new function, represented by N
protected  TypeReference defaultCatchType()
          for a block that catches all exceptions, what is the root exception type that it can catch? E.g., for Java, java.lang.Throwable
protected  void defineField(CAstEntity topEntity, AstTranslator.WalkContext definingContext, CAstEntity n)
          define a new field fieldEntity within topEntity
protected  void defineFunction(CAstEntity N, AstTranslator.WalkContext definingContext, AbstractCFG cfg, SymbolTable symtab, boolean hasCatchBlock, TypeReference[][] caughtTypes, boolean hasMonitorOp, AstTranslator.AstLexicalInformation lexicalInfo, AstMethod.DebuggingInformation debugInfo)
          fully define a function.
protected  boolean defineType(CAstEntity type, AstTranslator.WalkContext wc)
          define a new (presumably nested) type.
 void doArrayRead(AstTranslator.WalkContext context, int result, int arrayValue, CAstNode arrayRefNode, int[] dimValues)
          generate IR for a CAst array read, updating context.cfg()
 void doArrayWrite(AstTranslator.WalkContext context, int arrayValue, CAstNode arrayRefNode, int[] dimValues, int rval)
          generate IR for a CAst array write, updating context.cfg()
protected  void doCall(AstTranslator.WalkContext context, CAstNode call, int result, int exception, CAstNode name, int receiver, int[] arguments)
          generate IR for a CAst method call expression, updating context.cfg()
protected  void doFieldRead(AstTranslator.WalkContext context, int result, int receiver, CAstNode elt, CAstNode parent)
          generate IR for a CAst field read, updating context.cfg()
protected  void doFieldWrite(AstTranslator.WalkContext context, int receiver, CAstNode elt, CAstNode parent, int rval)
          generate IR for a CAst field write, updating context.cfg()
protected  void doGlobalRead(AstTranslator.WalkContext context, int result, java.lang.String name)
           
protected  void doGlobalWrite(AstTranslator.WalkContext context, java.lang.String name, int rval)
          generate instructions for a write of a global
protected  void doMaterializeFunction(CAstNode n, AstTranslator.WalkContext context, int result, int exception, CAstEntity fn)
          generate IR for a CAst function expression, updating context.cfg()
protected  void doNewObject(AstTranslator.WalkContext context, CAstNode newNode, int result, java.lang.Object type, int[] arguments)
          generate IR for a CAst new expression, updating context.cfg()
protected  void doPrimitive(int resultVal, AstTranslator.WalkContext context, CAstNode primitiveCall)
          generate IR for call modeling creation of primitive value, updating context.cfg()
protected  void doThrow(AstTranslator.WalkContext context, int exception)
          generate IR for a CAst throw expression, updating context.cfg()
protected  boolean doVisit(CAstNode n, CAstVisitor.Context context, CAstVisitor visitor)
          Node processing hook; sub-classes are expected to override if they introduce new node types.
protected  boolean hasImplicitGlobals()
          If this returns true, new global declarations get created for any attempt to access a non-existent variable (believe it or not, JavaScript actually does this!)
protected  void leaveCast(CAstNode n, CAstVisitor.Context c, CAstVisitor visitor)
          Leave a Cast node.
protected  void leaveInstanceOf(CAstNode n, CAstVisitor.Context c, CAstVisitor visitor)
          Leave an InstanceOf node.
protected  void leaveThis(CAstNode n, CAstVisitor.Context c, CAstVisitor visitor)
          Leave a This node.
 JavaSourceLoaderImpl loader()
           
protected  TypeReference makeType(CAstType type)
           
 CAstEntity sourceFileEntity()
           
 void translate()
           
protected  boolean treatGlobalsAsLexicallyScoped()
          can lexical reads / writes access globals?
protected  boolean useDefaultInitValues()
          does the language care about using type-appropriate default values? For Java, the answer is yes (ints should get a default value of 0, null for pointers, etc.).
protected  boolean useLocalValuesForLexicalVars()
          given accesses in a method to variables defined in an enclosing lexical scope, is it legal to read the variable into a local l once at the beginning of the method, operate on l through the method body (rather than performing separate lexical read / write operations), and write back the value in l (if necessary) at the end of the method?
protected  boolean visitCast(CAstNode n, CAstVisitor.Context c, CAstVisitor visitor)
          Visit a Cast node.
protected  boolean visitInstanceOf(CAstNode n, CAstVisitor.Context c, CAstVisitor visitor)
          Visit an InstanceOf node.
 
Methods inherited from class com.ibm.wala.cast.ir.translator.AstTranslator
assignValue, closeFunctionEntity, doGlobalRead, doIsFieldDefined, doLexicallyScopedRead, doLexicallyScopedWrite, doLocalRead, doLocalWrite, doPrologue, enterEntity, enterNode, getGlobalScope, getIncludedEntity, getTypeForNode, getValue, handleUnspecifiedLiteralKey, hasSpecialUndeclaredVariables, hasValue, initFunctionEntity, isExceptionLabel, leaveArrayLength, leaveArrayLiteral, leaveArrayLiteralInitElement, leaveArrayLiteralObject, leaveArrayRef, leaveArrayRefAssign, leaveArrayRefAssignOp, leaveAssert, leaveAssign, leaveBinaryExpr, leaveBlockExpr, leaveBlockExprAssign, leaveBlockExprAssignOp, leaveBlockStmt, leaveCall, leaveCatch, leaveConstant, leaveDeclStmt, leaveEachElementGet, leaveEachElementHasNext, leaveEcho, leaveEmpty, leaveFieldEntity, leaveFileEntity, leaveFunctionEntity, leaveFunctionExpr, leaveFunctionStmt, leaveGetCaughtException, leaveGlobalEntity, leaveGoto, leaveIfExpr, leaveIfExprCondition, leaveIfExprTrueClause, leaveIfgoto, leaveIfStmt, leaveIfStmtCondition, leaveIfStmtTrueClause, leaveInclude, leaveIsDefinedExpr, leaveLabelStmt, leaveLocalScope, leaveLoop, leaveLoopHeader, leaveNew, leaveObjectLiteral, leaveObjectLiteralFieldInit, leaveObjectRef, leaveObjectRefAssign, leaveObjectRefAssignOp, leavePrimitive, leaveReturn, leaveScriptEntity, leaveSuper, leaveSwitch, leaveSwitchValue, leaveThrow, leaveTry, leaveTryBlock, leaveTypeEntity, leaveTypeLiteralExpr, leaveUnaryExpr, leaveUnwind, leaveVar, leaveVarAssign, leaveVarAssignOp, leaveVoid, makeCodeContext, makeFileContext, makeGlobalRef, makeLocalContext, makeTypeContext, makeTypeScope, makeUnwindContext, postProcessNode, processAssignOp, processFunctionExpr, processIf, processObjectRefAssignOp, setArrayOpHandler, setValue, topLevelFunctionsInGlobalScope, translate, translateBinaryOpcode, translateConditionOpcode, translateUnaryOpcode, visitArrayLength, visitArrayLiteral, visitArrayRef, visitArrayRefAssign, visitArrayRefAssignOp, visitAssert, visitAssign, visitBinaryExpr, visitBlockExpr, visitBlockExprAssign, visitBlockExprAssignOp, visitBlockStmt, visitCall, visitCatch, visitConstant, visitDeclStmt, visitEachElementGet, visitEachElementHasNext, visitEcho, visitEmpty, visitFieldEntity, visitFileEntity, visitFunctionEntity, visitFunctionExpr, visitFunctionStmt, visitGetCaughtException, visitGlobalEntity, visitGoto, visitIfExpr, visitIfgoto, visitIfStmt, visitIsDefinedExpr, visitLabelStmt, visitLocalScope, visitLoop, visitMacroEntity, visitNew, visitObjectLiteral, visitObjectRef, visitObjectRefAssign, visitObjectRefAssignOp, visitPrimitive, visitReturn, visitScriptEntity, visitSuper, visitSwitch, visitThis, visitThrow, visitTry, visitTypeEntity, visitTypeLiteralExpr, visitUnaryExpr, visitUnwind, visitVar, visitVarAssign, visitVarAssignOp, visitVoid, walkEntities
 
Methods inherited from class com.ibm.wala.cast.tree.visit.CAstVisitor
doVisitArrayRefNode, doVisitAssignNodes, doVisitEntity, getParent, leaveEntity, leaveMacroEntity, leaveMacroVar, leaveNode, postProcessEntity, setParent, visit, visitAllChildren, visitAssignNodes, visitChildren, visitEntities, visitEntity, visitInclude, visitMacroVar, visitNode, visitScopedEntities, visitScopedEntities
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaCAst2IRTranslator

public JavaCAst2IRTranslator(ModuleEntry module,
                             CAstEntity sourceFileEntity,
                             JavaSourceLoaderImpl loader)
Method Detail

translate

public void translate()

sourceFileEntity

public CAstEntity sourceFileEntity()

loader

public JavaSourceLoaderImpl loader()

useDefaultInitValues

protected boolean useDefaultInitValues()
Description copied from class: AstTranslator
does the language care about using type-appropriate default values? For Java, the answer is yes (ints should get a default value of 0, null for pointers, etc.). For JavaScript, the answer is no, as any variable can hold the value 'undefined'.

Specified by:
useDefaultInitValues in class AstTranslator

hasImplicitGlobals

protected boolean hasImplicitGlobals()
Description copied from class: AstTranslator
If this returns true, new global declarations get created for any attempt to access a non-existent variable (believe it or not, JavaScript actually does this!)

Overrides:
hasImplicitGlobals in class AstTranslator

defaultCatchType

protected TypeReference defaultCatchType()
Description copied from class: AstTranslator
for a block that catches all exceptions, what is the root exception type that it can catch? E.g., for Java, java.lang.Throwable

Specified by:
defaultCatchType in class AstTranslator

makeType

protected TypeReference makeType(CAstType type)
Specified by:
makeType in class AstTranslator

treatGlobalsAsLexicallyScoped

protected boolean treatGlobalsAsLexicallyScoped()
Description copied from class: AstTranslator
can lexical reads / writes access globals?

Specified by:
treatGlobalsAsLexicallyScoped in class AstTranslator

useLocalValuesForLexicalVars

protected boolean useLocalValuesForLexicalVars()
Description copied from class: AstTranslator
given accesses in a method to variables defined in an enclosing lexical scope, is it legal to read the variable into a local l once at the beginning of the method, operate on l through the method body (rather than performing separate lexical read / write operations), and write back the value in l (if necessary) at the end of the method?

Specified by:
useLocalValuesForLexicalVars in class AstTranslator

doThrow

protected void doThrow(AstTranslator.WalkContext context,
                       int exception)
Description copied from class: AstTranslator
generate IR for a CAst throw expression, updating context.cfg()

Specified by:
doThrow in class AstTranslator

doArrayRead

public void doArrayRead(AstTranslator.WalkContext context,
                        int result,
                        int arrayValue,
                        CAstNode arrayRefNode,
                        int[] dimValues)
Description copied from class: AstTranslator
generate IR for a CAst array read, updating context.cfg()

Specified by:
doArrayRead in interface ArrayOpHandler
Specified by:
doArrayRead in class AstTranslator

doArrayWrite

public void doArrayWrite(AstTranslator.WalkContext context,
                         int arrayValue,
                         CAstNode arrayRefNode,
                         int[] dimValues,
                         int rval)
Description copied from class: AstTranslator
generate IR for a CAst array write, updating context.cfg()

Specified by:
doArrayWrite in interface ArrayOpHandler
Specified by:
doArrayWrite in class AstTranslator

doFieldRead

protected void doFieldRead(AstTranslator.WalkContext context,
                           int result,
                           int receiver,
                           CAstNode elt,
                           CAstNode parent)
Description copied from class: AstTranslator
generate IR for a CAst field read, updating context.cfg()

Specified by:
doFieldRead in class AstTranslator

doFieldWrite

protected void doFieldWrite(AstTranslator.WalkContext context,
                            int receiver,
                            CAstNode elt,
                            CAstNode parent,
                            int rval)
Description copied from class: AstTranslator
generate IR for a CAst field write, updating context.cfg()

Specified by:
doFieldWrite in class AstTranslator

doMaterializeFunction

protected void doMaterializeFunction(CAstNode n,
                                     AstTranslator.WalkContext context,
                                     int result,
                                     int exception,
                                     CAstEntity fn)
Description copied from class: AstTranslator
generate IR for a CAst function expression, updating context.cfg()

Specified by:
doMaterializeFunction in class AstTranslator

doNewObject

protected void doNewObject(AstTranslator.WalkContext context,
                           CAstNode newNode,
                           int result,
                           java.lang.Object type,
                           int[] arguments)
Description copied from class: AstTranslator
generate IR for a CAst new expression, updating context.cfg()

Specified by:
doNewObject in class AstTranslator

doCall

protected void doCall(AstTranslator.WalkContext context,
                      CAstNode call,
                      int result,
                      int exception,
                      CAstNode name,
                      int receiver,
                      int[] arguments)
Description copied from class: AstTranslator
generate IR for a CAst method call expression, updating context.cfg()

Specified by:
doCall in class AstTranslator

doGlobalRead

protected void doGlobalRead(AstTranslator.WalkContext context,
                            int result,
                            java.lang.String name)

doGlobalWrite

protected void doGlobalWrite(AstTranslator.WalkContext context,
                             java.lang.String name,
                             int rval)
Description copied from class: AstTranslator
generate instructions for a write of a global

Overrides:
doGlobalWrite in class AstTranslator

defineField

protected void defineField(CAstEntity topEntity,
                           AstTranslator.WalkContext definingContext,
                           CAstEntity n)
Description copied from class: AstTranslator
define a new field fieldEntity within topEntity

Specified by:
defineField in class AstTranslator

declareFunction

protected void declareFunction(CAstEntity N,
                               AstTranslator.WalkContext definingContext)
Description copied from class: AstTranslator
declare a new function, represented by N

Specified by:
declareFunction in class AstTranslator

defineFunction

protected void defineFunction(CAstEntity N,
                              AstTranslator.WalkContext definingContext,
                              AbstractCFG cfg,
                              SymbolTable symtab,
                              boolean hasCatchBlock,
                              TypeReference[][] caughtTypes,
                              boolean hasMonitorOp,
                              AstTranslator.AstLexicalInformation lexicalInfo,
                              AstMethod.DebuggingInformation debugInfo)
Description copied from class: AstTranslator
fully define a function. invoked after all the code of the function has been processed

Specified by:
defineFunction in class AstTranslator

doPrimitive

protected void doPrimitive(int resultVal,
                           AstTranslator.WalkContext context,
                           CAstNode primitiveCall)
Description copied from class: AstTranslator
generate IR for call modeling creation of primitive value, updating context.cfg()

Specified by:
doPrimitive in class AstTranslator

composeEntityName

protected java.lang.String composeEntityName(AstTranslator.WalkContext parent,
                                             CAstEntity f)
Description copied from class: AstTranslator
create the language-appropriate name for f

Specified by:
composeEntityName in class AstTranslator

defineType

protected boolean defineType(CAstEntity type,
                             AstTranslator.WalkContext wc)
Description copied from class: AstTranslator
define a new (presumably nested) type. return true if type was successfully defined, false otherwise

Specified by:
defineType in class AstTranslator

leaveThis

protected void leaveThis(CAstNode n,
                         CAstVisitor.Context c,
                         CAstVisitor visitor)
Description copied from class: CAstVisitor
Leave a This node.

Overrides:
leaveThis in class AstTranslator
Parameters:
n - the node to process
c - a visitor-specific context

visitCast

protected boolean visitCast(CAstNode n,
                            CAstVisitor.Context c,
                            CAstVisitor visitor)
Description copied from class: CAstVisitor
Visit a Cast node.

Overrides:
visitCast in class CAstVisitor
Parameters:
n - the node to process
c - a visitor-specific context
Returns:
true if no further processing is needed

leaveCast

protected void leaveCast(CAstNode n,
                         CAstVisitor.Context c,
                         CAstVisitor visitor)
Description copied from class: CAstVisitor
Leave a Cast node.

Overrides:
leaveCast in class CAstVisitor
Parameters:
n - the node to process
c - a visitor-specific context

visitInstanceOf

protected boolean visitInstanceOf(CAstNode n,
                                  CAstVisitor.Context c,
                                  CAstVisitor visitor)
Description copied from class: CAstVisitor
Visit an InstanceOf node.

Overrides:
visitInstanceOf in class CAstVisitor
Parameters:
n - the node to process
c - a visitor-specific context
Returns:
true if no further processing is needed

leaveInstanceOf

protected void leaveInstanceOf(CAstNode n,
                               CAstVisitor.Context c,
                               CAstVisitor visitor)
Description copied from class: CAstVisitor
Leave an InstanceOf node.

Overrides:
leaveInstanceOf in class CAstVisitor
Parameters:
n - the node to process
c - a visitor-specific context

doVisit

protected boolean doVisit(CAstNode n,
                          CAstVisitor.Context context,
                          CAstVisitor visitor)
Description copied from class: CAstVisitor
Node processing hook; sub-classes are expected to override if they introduce new node types. (Should invoke super.doVisit() for unprocessed nodes.)

Overrides:
doVisit in class CAstVisitor
Returns:
true if node was handled