Class 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.
    • 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

        Context​(Context ctx,
                Node node)
        Create a new nested context, for a block statement
      • Context

        public Context​(Context ctx)
    • Method Detail

      • 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
      • 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.
      • 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.

      • 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.