Class JSAstTranslator
java.lang.Object
com.ibm.wala.cast.tree.visit.CAstVisitor<AstTranslator.WalkContext>
com.ibm.wala.cast.ir.translator.AstTranslator
com.ibm.wala.cast.js.translator.JSAstTranslator
- All Implemented Interfaces:
ArrayOpHandler
,TranslatorToIR
Specialization of
AstTranslator
for JavaScript.-
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
-
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 context) 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 wc, 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 LI, 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 arrayRef, int[] dimValues) generate IR for a CAst array read, updating context.cfg()void
doArrayWrite
(AstTranslator.WalkContext context, int arrayValue, CAstNode arrayRef, 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 readNode) 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 int
doGlobalRead
(CAstNode n, AstTranslator.WalkContext context, String name, TypeReference type) generate instructions for a read of a globalprotected int
doLexicallyScopedRead
(CAstNode n, AstTranslator.WalkContext context, String name, TypeReference type) Note that the caller is responsible for ensuring that name is defined in a lexical scope.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, 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
doPrologue
(AstTranslator.WalkContext context) generate prologue code for each function bodyprotected void
doThrow
(AstTranslator.WalkContext context, int exception) generate IR for a CAst throw expression, updating context.cfg()protected boolean
doVisit
(CAstNode n, AstTranslator.WalkContext context, 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 boolean
ignoreName
(String name) protected void
leaveInstanceOf
(CAstNode n, AstTranslator.WalkContext c, CAstVisitor<AstTranslator.WalkContext> visitor) Leave an InstanceOf node.protected String[]
makeNameMap
(CAstEntity n, Set<AstTranslator.Scope> scopes, SSAInstruction[] insts) protected TypeReference
protected CAstType
topType()
the most-general type for the language being translatedprotected 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
visitInstanceOf
(CAstNode n, AstTranslator.WalkContext c, CAstVisitor<AstTranslator.WalkContext> visitor) Visit an InstanceOf node.Methods inherited from class com.ibm.wala.cast.ir.translator.AstTranslator
assignValue, closeFunctionEntity, doGlobalWrite, doIsFieldDefined, doLexicallyScopedWrite, doLocalRead, doLocalWrite, enterEntity, getArgumentCount, getArgumentNames, getCodeContext, getIncludedEntity, getTypeForNode, handleUnspecifiedLiteralKey, hasSpecialUndeclaredVariables, 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, leaveThis, leaveThrow, leaveTry, leaveTryBlock, leaveTypeEntity, leaveTypeLiteralExpr, leaveUnaryExpr, leaveUnwind, leaveVar, leaveVarAssign, leaveVarAssignOp, leaveVoid, leaveYield, liftDeclarationsForLexicalScoping, makeCodeContext, makeFileContext, makeGlobalRef, makeLocalContext, 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, leaveCast, leaveClassStmt, leaveEntity, leaveForIn, leaveMacroEntity, leaveMacroVar, leaveNode, leaveObjectLiteralAssign, postProcessEntity, postProcessNode, setParent, visit, visitAllChildren, visitArrayLiteralAssign, visitAssignNodes, visitCast, visitChildren, visitClassStmt, visitEntities, visitEntity, visitForIn, visitInclude, visitMacroVar, visitNode, visitObjectLiteralAssign, visitScopedEntities, visitScopedEntities
-
Field Details
-
Any
-
-
Constructor Details
-
JSAstTranslator
-
-
Method Details
-
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
-
treatGlobalsAsLexicallyScoped
protected boolean treatGlobalsAsLexicallyScoped()Description copied from class:AstTranslator
can lexical reads / writes access globals?- Specified by:
treatGlobalsAsLexicallyScoped
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
-
ignoreName
- Overrides:
ignoreName
in classAstTranslator
- Parameters:
name
- A variable name- Returns:
- is this name safe to overwrite, i.e. it's synthetic from the translator?
-
makeNameMap
protected String[] makeNameMap(CAstEntity n, Set<AstTranslator.Scope> scopes, SSAInstruction[] insts) - Overrides:
makeNameMap
in classAstTranslator
-
doLexicallyScopedRead
protected int doLexicallyScopedRead(CAstNode n, AstTranslator.WalkContext context, String name, TypeReference type) Description copied from class:AstTranslator
Note that the caller is responsible for ensuring that name is defined in a lexical scope.- Overrides:
doLexicallyScopedRead
in classAstTranslator
- Parameters:
n
- the AST node representing the read
-
doGlobalRead
protected int doGlobalRead(CAstNode n, AstTranslator.WalkContext context, String name, TypeReference type) Description copied from class:AstTranslator
generate instructions for a read of a global- Overrides:
doGlobalRead
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
-
defineField
Description copied from class:AstTranslator
define a new field fieldEntity within topEntity- Specified by:
defineField
in classAstTranslator
-
composeEntityName
Description copied from class:AstTranslator
create the language-appropriate name for f- Specified by:
composeEntityName
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 LI, 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
-
doThrow
Description copied from class:AstTranslator
generate IR for a CAst throw expression, updating context.cfg()- Specified by:
doThrow
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
-
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
-
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
-
doArrayRead
public void doArrayRead(AstTranslator.WalkContext context, int result, int arrayValue, CAstNode arrayRef, 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 arrayRef, 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 readNode) 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
-
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
-
visitInstanceOf
protected boolean visitInstanceOf(CAstNode n, AstTranslator.WalkContext c, CAstVisitor<AstTranslator.WalkContext> visitor) Description copied from class:CAstVisitor
Visit an InstanceOf node.- Overrides:
visitInstanceOf
in classCAstVisitor<AstTranslator.WalkContext>
- Parameters:
n
- the node to processc
- a visitor-specific context- Returns:
- true if no further processing is needed
-
leaveInstanceOf
protected void leaveInstanceOf(CAstNode n, AstTranslator.WalkContext c, CAstVisitor<AstTranslator.WalkContext> visitor) Description copied from class:CAstVisitor
Leave an InstanceOf node.- Overrides:
leaveInstanceOf
in classCAstVisitor<AstTranslator.WalkContext>
- Parameters:
n
- the node to processc
- a visitor-specific context
-
doPrologue
Description copied from class:AstTranslator
generate prologue code for each function body- Overrides:
doPrologue
in classAstTranslator
-
doVisit
protected boolean doVisit(CAstNode n, AstTranslator.WalkContext context, 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
-