Class JavaCAst2IRTranslator
java.lang.Object
com.ibm.wala.cast.tree.visit.CAstVisitor<AstTranslator.WalkContext>
com.ibm.wala.cast.ir.translator.AstTranslator
com.ibm.wala.cast.java.translator.JavaCAst2IRTranslator
- All Implemented Interfaces:
ArrayOpHandler
,TranslatorToIR
-
Nested Class Summary
Nested classes/interfaces inherited from class com.ibm.wala.cast.ir.translator.AstTranslator
AstTranslator.AbstractScope, AstTranslator.AbstractSymbol, AstTranslator.AstCFG, AstTranslator.AstLexicalInformation, AstTranslator.CodeEntityContext, AstTranslator.FinalCAstSymbol, AstTranslator.IncipientCFG, AstTranslator.InternalCAstSymbol, AstTranslator.PreBasicBlock, AstTranslator.RootContext, AstTranslator.Scope, AstTranslator.ScopeType, AstTranslator.Symbol, AstTranslator.TypeContext, 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, entity2ExposedNames, entity2WrittenNames, insts, loader, namedEntityResolver
Fields inherited from class com.ibm.wala.cast.tree.visit.CAstVisitor
currentPosition
-
Constructor Summary
ConstructorDescriptionJavaCAst2IRTranslator
(ModuleEntry module, CAstEntity sourceFileEntity, JavaSourceLoaderImpl loader, SetOfClasses exclusions) -
Method Summary
Modifier and TypeMethodDescriptionprotected String
composeEntityName
(AstTranslator.WalkContext parent, CAstEntity f) create the language-appropriate name for fprotected void
declareFunction
(CAstEntity N, AstTranslator.WalkContext definingContext) declare a new function, represented by Nprotected TypeReference
for a block that catches all exceptions, what is the root exception type that it can catch? E.g., for Java, java.lang.Throwableprotected void
defineField
(CAstEntity topEntity, AstTranslator.WalkContext definingContext, CAstEntity n) define a new field fieldEntity within topEntityprotected void
defineFunction
(CAstEntity N, AstTranslator.WalkContext definingContext, AbstractCFG<SSAInstruction, ? extends IBasicBlock<SSAInstruction>> cfg, SymbolTable symtab, boolean hasCatchBlock, Map<IBasicBlock<SSAInstruction>, 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
doGlobalWrite
(AstTranslator.WalkContext context, String name, TypeReference type, int rval) generate instructions for a write of a globalprotected 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, 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, AstTranslator.WalkContext wc, CAstVisitor<AstTranslator.WalkContext> visitor) Node processing hook; sub-classes are expected to override if they introduce new node types.protected CAstType
the most-general exception type for the language being translatedprotected CAstSourcePositionMap.Position[]
protected boolean
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, AstTranslator.WalkContext context, CAstVisitor<AstTranslator.WalkContext> visitor) Leave a Cast node.protected void
leaveInstanceOf
(CAstNode n, AstTranslator.WalkContext context, CAstVisitor<AstTranslator.WalkContext> visitor) Leave an InstanceOf node.protected void
leaveThis
(CAstNode n, AstTranslator.WalkContext c, CAstVisitor<AstTranslator.WalkContext> visitor) Leave a This node.loader()
protected TypeReference
protected CAstType
topType()
the most-general type for the language being translatedvoid
protected boolean
can lexical reads / writes access globals?protected boolean
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
visitCast
(CAstNode n, AstTranslator.WalkContext context, CAstVisitor<AstTranslator.WalkContext> visitor) Visit a Cast node.protected boolean
visitInstanceOf
(CAstNode n, AstTranslator.WalkContext context, CAstVisitor<AstTranslator.WalkContext> 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, getArgumentCount, getArgumentNames, getCodeContext, getIncludedEntity, getTypeForNode, handleUnspecifiedLiteralKey, hasSpecialUndeclaredVariables, ignoreName, 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, leaveSpecialParentScope, leaveSuper, leaveSwitch, leaveSwitchValue, leaveThrow, leaveTry, leaveTryBlock, leaveTypeEntity, leaveTypeLiteralExpr, leaveUnaryExpr, leaveUnwind, leaveVar, leaveVarAssign, leaveVarAssignOp, leaveVoid, leaveYield, liftDeclarationsForLexicalScoping, makeCodeContext, makeFileContext, makeGlobalRef, makeLocalContext, makeNameMap, makeScriptScope, makeSpecialParentContext, makeTypeContext, makeTypeScope, makeUnwindContext, processAssignOp, processFunctionExpr, processIf, setDefaultValue, topLevelFunctionsInGlobalScope, translate, 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, visitSpecialParentScope, visitSuper, visitSwitch, visitThis, visitThrow, visitTry, visitTypeEntity, visitTypeLiteralExpr, visitUnaryExpr, visitUnwind, visitVar, visitVarAssign, visitVarAssignOp, visitVoid, visitYield, walkEntities
Methods inherited from class com.ibm.wala.cast.tree.visit.CAstVisitor
doVisitArrayRefNode, doVisitAssignNodes, doVisitEntity, enterNode, getCurrentPosition, getParent, leaveArrayLiteralAssign, leaveClassStmt, leaveEntity, leaveForIn, leaveMacroEntity, leaveMacroVar, leaveNode, leaveObjectLiteralAssign, postProcessEntity, postProcessNode, setParent, visit, visitAllChildren, visitArrayLiteralAssign, visitAssignNodes, visitChildren, visitClassStmt, visitEntities, visitEntity, visitForIn, visitInclude, visitMacroVar, visitNode, visitObjectLiteralAssign, visitScopedEntities, visitScopedEntities
-
Constructor Details
-
JavaCAst2IRTranslator
public JavaCAst2IRTranslator(ModuleEntry module, CAstEntity sourceFileEntity, JavaSourceLoaderImpl loader, SetOfClasses exclusions)
-
-
Method Details
-
translate
public void translate() -
sourceFileEntity
-
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 classAstTranslator
-
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 classAstTranslator
-
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 classAstTranslator
-
makeType
- Specified by:
makeType
in classAstTranslator
-
treatGlobalsAsLexicallyScoped
protected boolean treatGlobalsAsLexicallyScoped()Description copied from class:AstTranslator
can lexical reads / writes access globals?- Specified by:
treatGlobalsAsLexicallyScoped
in classAstTranslator
-
doThrow
Description copied from class:AstTranslator
generate IR for a CAst throw expression, updating context.cfg()- Specified by:
doThrow
in classAstTranslator
-
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 interfaceArrayOpHandler
- Specified by:
doArrayRead
in classAstTranslator
-
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 interfaceArrayOpHandler
- Specified by:
doArrayWrite
in classAstTranslator
-
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 classAstTranslator
-
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 classAstTranslator
-
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 classAstTranslator
-
doNewObject
protected void doNewObject(AstTranslator.WalkContext context, CAstNode newNode, int result, Object type, int[] arguments) Description copied from class:AstTranslator
generate IR for a CAst new expression, updating context.cfg()- Specified by:
doNewObject
in classAstTranslator
-
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 classAstTranslator
-
doGlobalWrite
protected void doGlobalWrite(AstTranslator.WalkContext context, String name, TypeReference type, int rval) Description copied from class:AstTranslator
generate instructions for a write of a global- Overrides:
doGlobalWrite
in classAstTranslator
-
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 classAstTranslator
-
declareFunction
Description copied from class:AstTranslator
declare a new function, represented by N- Specified by:
declareFunction
in classAstTranslator
-
defineFunction
protected void defineFunction(CAstEntity N, AstTranslator.WalkContext definingContext, AbstractCFG<SSAInstruction, ? extends IBasicBlock<SSAInstruction>> cfg, SymbolTable symtab, boolean hasCatchBlock, Map<IBasicBlock<SSAInstruction>, 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 classAstTranslator
-
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 classAstTranslator
-
composeEntityName
Description copied from class:AstTranslator
create the language-appropriate name for f- Specified by:
composeEntityName
in classAstTranslator
-
defineType
Description copied from class:AstTranslator
define a new (presumably nested) type. return true if type was successfully defined, false otherwise- Specified by:
defineType
in classAstTranslator
-
leaveThis
protected void leaveThis(CAstNode n, AstTranslator.WalkContext c, CAstVisitor<AstTranslator.WalkContext> visitor) Description copied from class:CAstVisitor
Leave a This node.- Overrides:
leaveThis
in classAstTranslator
- Parameters:
n
- the node to processc
- a visitor-specific context
-
visitCast
protected boolean visitCast(CAstNode n, AstTranslator.WalkContext context, CAstVisitor<AstTranslator.WalkContext> visitor) Description copied from class:CAstVisitor
Visit a Cast node.- Overrides:
visitCast
in classCAstVisitor<AstTranslator.WalkContext>
- Parameters:
n
- the node to processcontext
- a visitor-specific context- Returns:
- true if no further processing is needed
-
leaveCast
protected void leaveCast(CAstNode n, AstTranslator.WalkContext context, CAstVisitor<AstTranslator.WalkContext> visitor) Description copied from class:CAstVisitor
Leave a Cast node.- Overrides:
leaveCast
in classCAstVisitor<AstTranslator.WalkContext>
- Parameters:
n
- the node to processcontext
- a visitor-specific context
-
visitInstanceOf
protected boolean visitInstanceOf(CAstNode n, AstTranslator.WalkContext context, CAstVisitor<AstTranslator.WalkContext> visitor) Description copied from class:CAstVisitor
Visit an InstanceOf node.- Overrides:
visitInstanceOf
in classCAstVisitor<AstTranslator.WalkContext>
- Parameters:
n
- the node to processcontext
- a visitor-specific context- Returns:
- true if no further processing is needed
-
leaveInstanceOf
protected void leaveInstanceOf(CAstNode n, AstTranslator.WalkContext context, CAstVisitor<AstTranslator.WalkContext> visitor) Description copied from class:CAstVisitor
Leave an InstanceOf node.- Overrides:
leaveInstanceOf
in classCAstVisitor<AstTranslator.WalkContext>
- Parameters:
n
- the node to processcontext
- a visitor-specific context
-
doVisit
protected boolean doVisit(CAstNode n, AstTranslator.WalkContext wc, CAstVisitor<AstTranslator.WalkContext> 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 classCAstVisitor<AstTranslator.WalkContext>
- Returns:
- true if node was handled
-
topType
Description copied from class:AstTranslator
the most-general type for the language being translated- Specified by:
topType
in classAstTranslator
-
exceptionType
Description copied from class:AstTranslator
the most-general exception type for the language being translated- Specified by:
exceptionType
in classAstTranslator
-
getParameterPositions
- Specified by:
getParameterPositions
in classAstTranslator
-