Package org.glassfish.rmic.tools.tree
Class Context
- java.lang.Object
-
- org.glassfish.rmic.tools.tree.Context
-
- All Implemented Interfaces:
Constants
,RuntimeConstants
- Direct Known Subclasses:
CheckContext
,CodeContext
public class Context extends java.lang.Object implements Constants
WARNING: The contents of this source file are not part of any supported API. Code that depends on them does so at its own risk: they are subject to change or removal without notice.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) LocalMember
classes
(package private) MemberDefinition
field
(package private) int
frameNumber
(package private) LocalMember
locals
(package private) Node
node
(package private) Context
prev
(package private) int
scopeNumber
(package private) int
varNumber
-
Fields inherited from interface org.glassfish.rmic.tools.java.Constants
ABSTRACT, ACCM_CLASS, ACCM_FIELD, ACCM_INNERCLASS, ACCM_MEMBER, ACCM_METHOD, ADD, AND, ARRAY, ARRAYACCESS, ASGADD, ASGBITAND, ASGBITOR, ASGBITXOR, ASGDIV, ASGLSHIFT, ASGMUL, ASGREM, ASGRSHIFT, ASGSUB, ASGURSHIFT, ASSIGN, ATT_ALL, ATT_ALLCLASSES, ATT_CODE, BITAND, BITNOT, BITOR, BITXOR, BOOLEAN, BOOLEANVAL, BREAK, BYTE, BYTEVAL, CASE, CAST, CATCH, CHAR, CHARVAL, CLASS, COLON, COMMA, COMMENT, COND, CONST, CONTINUE, CONVERT, CS_BINARY, CS_CHECKED, CS_COMPILED, CS_NOTFOUND, CS_PARSED, CS_SOURCE, CS_UNDECIDED, CS_UNDEFINED, CT_BLOCK, CT_BRANCH_FALSE, CT_BRANCH_TRUE, CT_CASE, CT_FIKT_METHOD, CT_FIKT_RET, CT_FIRST_KIND, CT_LAST_KIND, CT_METHOD, CT_SWITH_WO_DEF, DEC, DECLARATION, DEFAULT, DIV, DO, DOUBLE, DOUBLEVAL, ELSE, EQ, ERROR, EXPR, EXPRESSION, EXTENDS, F_COVDATA, F_COVERAGE, F_DEBUG_LINES, F_DEBUG_SOURCE, F_DEBUG_VARS, F_DEPENDENCIES, F_DEPRECATION, F_DUMP, F_ERRORSREPORTED, F_OPT, F_OPT_INTERCLASS, F_PRINT_DEPENDENCIES, F_STRICTDEFAULT, F_VERBOSE, F_VERSION12, F_WARNINGS, FALSE, FIELD, FINAL, FINALLY, FLOAT, FLOATVAL, FOR, GE, GOTO, GT, idAppend, idClass, idClassInit, idClone, idCode, idConstantValue, idCoverageTable, idDeprecated, idDocumentation, IDENT, idExceptions, idFinallyReturnValue, idGetClass, idInit, idInnerClasses, idJavaIoSerializable, idJavaLang, idJavaLangClass, idJavaLangCloneable, idJavaLangError, idJavaLangException, idJavaLangObject, idJavaLangRuntimeException, idJavaLangString, idJavaLangStringBuffer, idJavaLangThrowable, idLength, idLineNumberTable, idLocalVariableTable, idNew, idNull, idSourceFile, idStar, idSuper, idSynthetic, idThis, idToString, idTYPE, idValueOf, IF, IMPLEMENTS, IMPORT, INC, INLINEMETHOD, INLINENEWINSTANCE, INLINERETURN, INSTANCEOF, INT, INTERFACE, INTVAL, LBRACE, LE, LENGTH, LONG, LONGVAL, LPAREN, LSHIFT, LSQBRACKET, LT, M_ABSTRACT, M_ANONYMOUS, M_DEPRECATED, M_FINAL, M_INLINEABLE, M_INTERFACE, M_LOCAL, M_NATIVE, M_PRIVATE, M_PROTECTED, M_PUBLIC, M_STATIC, M_STRICTFP, M_SYNCHRONIZED, M_SYNTHETIC, M_TRANSIENT, M_VOLATILE, MAXFILESIZE, MAXLINENUMBER, METHOD, MM_CLASS, MM_FIELD, MM_MEMBER, MM_METHOD, MUL, NATIVE, NE, NEG, NEW, NEWARRAY, NEWFROMNAME, NEWINSTANCE, NOT, NULL, opNames, opPrecedence, OR, PACKAGE, paraDeprecated, POS, POSTDEC, POSTINC, PREDEC, prefixAccess, prefixArray, prefixClass, prefixLoc, prefixThis, prefixVal, PREINC, PRIVATE, PROTECTED, PUBLIC, QUESTIONMARK, RBRACE, REM, RETURN, RPAREN, RSHIFT, RSQBRACKET, SEMICOLON, SHORT, SHORTVAL, SIG_INNERCLASS, SIGC_INNERCLASS, STAT, STATIC, STRICTFP, STRINGVAL, SUB, SUPER, SWITCH, SYNCHRONIZED, TC_ARRAY, TC_BOOLEAN, TC_BYTE, TC_CHAR, TC_CLASS, TC_DOUBLE, TC_ERROR, TC_FLOAT, TC_INT, TC_LONG, TC_METHOD, TC_NULL, TC_SHORT, TC_VOID, THIS, THROW, THROWS, TM_ARRAY, TM_BOOLEAN, TM_BYTE, TM_CHAR, TM_CLASS, TM_DOUBLE, TM_ERROR, TM_FLOAT, TM_INT, TM_INT32, TM_INTEGER, TM_LONG, TM_METHOD, TM_NULL, TM_NUM32, TM_NUM64, TM_NUMBER, TM_REAL, TM_REFERENCE, TM_SHORT, TM_VOID, tracing, TRANSIENT, TRUE, TRY, TYPE, URSHIFT, VARDECLARATION, VOID, VOLATILE, WHEREOFFSETBITS, WHILE
-
Fields inherited from interface org.glassfish.rmic.tools.java.RuntimeConstants
ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, CONSTANT_CLASS, CONSTANT_DOUBLE, CONSTANT_FIELD, CONSTANT_FLOAT, CONSTANT_INTEGER, CONSTANT_INTERFACEMETHOD, CONSTANT_INVOKEDYNAMIC, CONSTANT_LONG, CONSTANT_METHOD, CONSTANT_METHODHANDLE, CONSTANT_METHODTYPE, CONSTANT_NAMEANDTYPE, CONSTANT_STRING, CONSTANT_UNICODE, CONSTANT_UTF8, JAVA_DEFAULT_MINOR_VERSION, JAVA_DEFAULT_VERSION, JAVA_MAGIC, JAVA_MAX_SUPPORTED_MINOR_VERSION, JAVA_MAX_SUPPORTED_VERSION, JAVA_MIN_SUPPORTED_VERSION, opc_aaload, opc_aastore, opc_aconst_null, opc_aload, opc_aload_0, opc_aload_1, opc_aload_2, opc_aload_3, opc_anewarray, opc_areturn, opc_arraylength, opc_astore, opc_astore_0, opc_astore_1, opc_astore_2, opc_astore_3, opc_athrow, opc_baload, opc_bastore, opc_bipush, opc_breakpoint, opc_caload, opc_castore, opc_checkcast, opc_d2f, opc_d2i, opc_d2l, opc_dadd, opc_daload, opc_dastore, opc_dcmpg, opc_dcmpl, opc_dconst_0, opc_dconst_1, opc_ddiv, opc_dead, opc_dload, opc_dload_0, opc_dload_1, opc_dload_2, opc_dload_3, opc_dmul, opc_dneg, opc_drem, opc_dreturn, opc_dstore, opc_dstore_0, opc_dstore_1, opc_dstore_2, opc_dstore_3, opc_dsub, opc_dup, opc_dup_x1, opc_dup_x2, opc_dup2, opc_dup2_x1, opc_dup2_x2, opc_f2d, opc_f2i, opc_f2l, opc_fadd, opc_faload, opc_fastore, opc_fcmpg, opc_fcmpl, opc_fconst_0, opc_fconst_1, opc_fconst_2, opc_fdiv, opc_fload, opc_fload_0, opc_fload_1, opc_fload_2, opc_fload_3, opc_fmul, opc_fneg, opc_frem, opc_freturn, opc_fstore, opc_fstore_0, opc_fstore_1, opc_fstore_2, opc_fstore_3, opc_fsub, opc_getfield, opc_getstatic, opc_goto, opc_goto_w, opc_i2b, opc_i2c, opc_i2d, opc_i2f, opc_i2l, opc_i2s, opc_iadd, opc_iaload, opc_iand, opc_iastore, opc_iconst_0, opc_iconst_1, opc_iconst_2, opc_iconst_3, opc_iconst_4, opc_iconst_5, opc_iconst_m1, opc_idiv, opc_if_acmpeq, opc_if_acmpne, opc_if_icmpeq, opc_if_icmpge, opc_if_icmpgt, opc_if_icmple, opc_if_icmplt, opc_if_icmpne, opc_ifeq, opc_ifge, opc_ifgt, opc_ifle, opc_iflt, opc_ifne, opc_ifnonnull, opc_ifnull, opc_iinc, opc_iload, opc_iload_0, opc_iload_1, opc_iload_2, opc_iload_3, opc_imul, opc_ineg, opc_instanceof, opc_invokedynamic, opc_invokeinterface, opc_invokespecial, opc_invokestatic, opc_invokevirtual, opc_ior, opc_irem, opc_ireturn, opc_ishl, opc_ishr, opc_istore, opc_istore_0, opc_istore_1, opc_istore_2, opc_istore_3, opc_isub, opc_iushr, opc_ixor, opc_jsr, opc_jsr_w, opc_l2d, opc_l2f, opc_l2i, opc_label, opc_ladd, opc_laload, opc_land, opc_lastore, opc_lcmp, opc_lconst_0, opc_lconst_1, opc_ldc, opc_ldc_w, opc_ldc2_w, opc_ldiv, opc_lload, opc_lload_0, opc_lload_1, opc_lload_2, opc_lload_3, opc_lmul, opc_lneg, opc_lookupswitch, opc_lor, opc_lrem, opc_lreturn, opc_lshl, opc_lshr, opc_lstore, opc_lstore_0, opc_lstore_1, opc_lstore_2, opc_lstore_3, opc_lsub, opc_lushr, opc_lxor, opc_monitorenter, opc_monitorexit, opc_multianewarray, opc_new, opc_newarray, opc_nop, opc_pop, opc_pop2, opc_putfield, opc_putstatic, opc_ret, opc_return, opc_saload, opc_sastore, opc_sipush, opc_swap, opc_tableswitch, opc_try, opc_wide, opcLengths, opcNames, SIG_ARRAY, SIG_BOOLEAN, SIG_BYTE, SIG_CHAR, SIG_CLASS, SIG_DOUBLE, SIG_ENDCLASS, SIG_ENDMETHOD, SIG_FLOAT, SIG_INT, SIG_LONG, SIG_METHOD, SIG_PACKAGE, SIG_SHORT, SIG_VOID, SIGC_ARRAY, SIGC_BOOLEAN, SIGC_BYTE, SIGC_CHAR, SIGC_CLASS, SIGC_DOUBLE, SIGC_ENDCLASS, SIGC_ENDMETHOD, SIGC_FLOAT, SIGC_INT, SIGC_LONG, SIGC_METHOD, SIGC_PACKAGE, SIGC_SHORT, SIGC_VOID, T_BOOLEAN, T_BYTE, T_CHAR, T_CLASS, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT
-
-
Constructor Summary
Constructors Constructor Description Context(Context ctx)
Context(Context ctx, ClassDefinition c)
Create a new context, for initializing a class.Context(Context ctx, MemberDefinition field)
Create the initial context for a method The incoming context is inherited fromContext(Context ctx, Node node)
Create a new nested context, for a block statement
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canReach(Environment env, MemberDefinition f)
Check if a field can reach another field (only considers forward references, not the access modifiers).void
checkBackBranch(Environment env, Statement loop, Vset vsEntry, Vset vsBack)
Raise an error if a blank final was definitely unassigned on entry to a loop, but has possibly been assigned on the back-branch.int
declare(Environment env, LocalMember local)
Declare localint
declareFieldNumber(MemberDefinition field)
Assign a number to a class field.Expression
findOuterLink(Environment env, long where, ClassDefinition reqc, MemberDefinition f, boolean needExactMatch)
Expression
findOuterLink(Environment env, long where, MemberDefinition f)
Return a local expression which can serve as the base reference for the given field.ClassDefinition
findScope(Environment env, ClassDefinition reqc)
From which enclosing class do members of this type come?Identifier
getApparentClassName(Environment env, Identifier name)
Return the name of a lexically apparent type, skipping inherited members, and ignoring the current pacakge and imports.MemberDefinition
getApparentField(Environment env, Identifier name)
Like getField, except that it skips over inherited fields.Context
getBreakContext(Identifier lbl)
Get the destination context of a breakprivate MemberDefinition
getClassCommon(Environment env, Identifier name, boolean apparentOnly)
Context
getContinueContext(Identifier lbl)
Get the destination context of a continueMemberDefinition
getElement(int number)
Return the local field or member field corresponding to a number.MemberDefinition
getField()
Return the field containing the present context.MemberDefinition
getField(Environment env, Identifier name)
Get either a local variable, or a field in a current classprivate MemberDefinition
getFieldCommon(Environment env, Identifier name, boolean apparentOnly)
int
getFieldNumber(MemberDefinition field)
Retrieve a number previously assigned by declareMember().(package private) Context
getInlineContext()
Get the nearest inlined context(package private) Context
getInlineMemberContext(MemberDefinition field)
Get the context of a field that is being inlinedContext
getLabelContext(Identifier lbl)
Get the context that corresponds to a label, return null if not found.LocalMember
getLocalClass(Identifier name)
Get a local class by nameLocalMember
getLocalField(Identifier name)
Get a local variable by nameCheckContext
getReturnContext()
Get the destination context of a return (the method body)int
getScopeNumber(ClassDefinition c)
Get the scope number for a reference to a member of this class (Larger scope numbers are more deeply nested.)int
getThisNumber()
Return the number of the innermost current instance reference.CheckContext
getTryExitContext()
Get the context of the innermost surrounding try-block.int
getVarNumber()
boolean
isInScope(LocalMember field)
Check if the given field is active in this context.Expression
makeReference(Environment env, LocalMember target)
Implement a reference (usually an uplevel one).private static boolean
match(Environment env, ClassDefinition thisc, ClassDefinition reqc)
static Environment
newEnvironment(Environment env, Context ctx)
Extend an environment with the given context.UplevelReference
noteReference(Environment env, LocalMember target)
Notice a reference (usually an uplevel one).static boolean
outerLinkExists(Environment env, ClassDefinition reqc, ClassDefinition thisc)
Is there a "this" of type reqc in scope?Vset
removeAdditionalVars(Vset vset)
Remove variables from the vset set that are no longer part of this context.(package private) Identifier
resolveName(Environment env, Identifier name)
Resolve a type name from within a local scope.
-
-
-
Field Detail
-
prev
Context prev
-
node
Node node
-
varNumber
int varNumber
-
locals
LocalMember locals
-
classes
LocalMember classes
-
field
MemberDefinition field
-
scopeNumber
int scopeNumber
-
frameNumber
int frameNumber
-
-
Constructor Detail
-
Context
public Context(Context ctx, MemberDefinition field)
Create the initial context for a method The incoming context is inherited from
-
Context
public Context(Context ctx, ClassDefinition c)
Create a new context, for initializing a class.
-
Context
public Context(Context ctx)
-
-
Method Detail
-
declare
public int declare(Environment env, LocalMember local)
Declare local
-
getLocalField
public LocalMember getLocalField(Identifier name)
Get a local variable by name
-
getScopeNumber
public int getScopeNumber(ClassDefinition c)
Get the scope number for a reference to a member of this class (Larger scope numbers are more deeply nested.)- See Also:
LocalMember.scopeNumber
-
getFieldCommon
private MemberDefinition getFieldCommon(Environment env, Identifier name, boolean apparentOnly) throws AmbiguousMember, ClassNotFound
- Throws:
AmbiguousMember
ClassNotFound
-
declareFieldNumber
public int declareFieldNumber(MemberDefinition field)
Assign a number to a class field. (This is used to track definite assignment of some blank finals.)
-
getFieldNumber
public int getFieldNumber(MemberDefinition field)
Retrieve a number previously assigned by declareMember(). Return -1 if there was no such assignment in this context.
-
getElement
public MemberDefinition getElement(int number)
Return the local field or member field corresponding to a number. Return null if there is no such field.
-
getLocalClass
public LocalMember getLocalClass(Identifier name)
Get a local class by name
-
getClassCommon
private MemberDefinition getClassCommon(Environment env, Identifier name, boolean apparentOnly) throws ClassNotFound
- Throws:
ClassNotFound
-
getField
public final MemberDefinition getField(Environment env, Identifier name) throws AmbiguousMember, ClassNotFound
Get either a local variable, or a field in a current class- Throws:
AmbiguousMember
ClassNotFound
-
getApparentField
public final MemberDefinition getApparentField(Environment env, Identifier name) throws AmbiguousMember, ClassNotFound
Like getField, except that it skips over inherited fields. Used for error checking.- Throws:
AmbiguousMember
ClassNotFound
-
isInScope
public boolean isInScope(LocalMember field)
Check if the given field is active in this context.
-
noteReference
public UplevelReference noteReference(Environment env, LocalMember target)
Notice a reference (usually an uplevel one). Update the references list of every enclosing class which is enclosed by the scope of the target. Update decisions about which uplevels to make into fields. Return the uplevel reference descriptor, or null if it's local.The target must be in scope in this context. So, call this method only from the check phase. (In other phases, the context may be less complete.)
This can and should be called both before and after classes are frozen. It should be a no-op, and will raise a compiler error if not.
-
makeReference
public Expression makeReference(Environment env, LocalMember target)
Implement a reference (usually an uplevel one). Call noteReference() first, to make sure the reference lists are up to date.The resulting expression tree does not need checking; it can be code-generated right away. If the reference is not uplevel, the result is an IDENT or THIS.
-
findOuterLink
public Expression findOuterLink(Environment env, long where, MemberDefinition f)
Return a local expression which can serve as the base reference for the given field. If the field is a constructor, return an expression for the implicit enclosing instance argument.Return null if there is no need for such an argument, or if there was an error.
-
match
private static boolean match(Environment env, ClassDefinition thisc, ClassDefinition reqc)
-
findOuterLink
public Expression findOuterLink(Environment env, long where, ClassDefinition reqc, MemberDefinition f, boolean needExactMatch)
-
outerLinkExists
public static boolean outerLinkExists(Environment env, ClassDefinition reqc, ClassDefinition thisc)
Is there a "this" of type reqc in scope?
-
findScope
public ClassDefinition findScope(Environment env, ClassDefinition reqc)
From which enclosing class do members of this type come?
-
resolveName
Identifier resolveName(Environment env, Identifier name)
Resolve a type name from within a local scope.
-
getApparentClassName
public Identifier getApparentClassName(Environment env, Identifier name)
Return the name of a lexically apparent type, skipping inherited members, and ignoring the current pacakge and imports. This is used for error checking.
-
checkBackBranch
public void checkBackBranch(Environment env, Statement loop, Vset vsEntry, Vset vsBack)
Raise an error if a blank final was definitely unassigned on entry to a loop, but has possibly been assigned on the back-branch. If this is the case, the loop may be assigning it multiple times.
-
canReach
public boolean canReach(Environment env, MemberDefinition f)
Check if a field can reach another field (only considers forward references, not the access modifiers).
-
getLabelContext
public Context getLabelContext(Identifier lbl)
Get the context that corresponds to a label, return null if not found.
-
getBreakContext
public Context getBreakContext(Identifier lbl)
Get the destination context of a break
-
getContinueContext
public Context getContinueContext(Identifier lbl)
Get the destination context of a continue
-
getReturnContext
public CheckContext getReturnContext()
Get the destination context of a return (the method body)
-
getTryExitContext
public CheckContext getTryExitContext()
Get the context of the innermost surrounding try-block. Consider only try-blocks contained within the same method. (There could be others when searching from within a method of a local class, but they are irrelevant to our purpose.) This is used for recording DA/DU information preceding all abnormal transfers of control: break, continue, return, and throw.
-
getInlineContext
Context getInlineContext()
Get the nearest inlined context
-
getInlineMemberContext
Context getInlineMemberContext(MemberDefinition field)
Get the context of a field that is being inlined
-
removeAdditionalVars
public final Vset removeAdditionalVars(Vset vset)
Remove variables from the vset set that are no longer part of this context.
-
getVarNumber
public final int getVarNumber()
-
getThisNumber
public int getThisNumber()
Return the number of the innermost current instance reference.
-
getField
public final MemberDefinition getField()
Return the field containing the present context.
-
newEnvironment
public static Environment newEnvironment(Environment env, Context ctx)
Extend an environment with the given context. The resulting environment behaves the same as the given one, except that resolveName() takes into account local class names in this context.
-
-