com.sun.tools.javac.comp
Class Lower

java.lang.Object
  extended by com.sun.tools.javac.tree.JCTree.Visitor
      extended by com.sun.tools.javac.tree.TreeTranslator
          extended by com.sun.tools.javac.comp.Lower

public class Lower
extends TreeTranslator

This pass translates away some syntactic sugar: inner classes, class literals, assertions, foreach loops, etc.

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.


Nested Class Summary
(package private)  class Lower.ClassMap
          A navigator class for assembling a mapping from local class symbols to class definition trees.
(package private)  class Lower.EnumMapping
          This map gives a translation table to be used for enum switches.
(package private)  class Lower.FreeVarCollector
          A navigator class for collecting the free variables accessed from a local class.
(package private) static interface Lower.TreeBuilder
          Building blocks for let expressions
 
Field Summary
private  java.util.Map<Symbol,Symbol.MethodSymbol> accessConstrs
          A mapping from (constructor) symbols to access constructor symbols.
private  ListBuffer<Symbol> accessed
          A queue for all accessed symbols.
private  java.util.Map<Symbol,java.lang.Integer> accessNums
          A mapping from symbols to their access numbers.
private  java.util.Map<Symbol,Symbol.MethodSymbol[]> accessSyms
          A mapping from symbols to an array of access symbols, indexed by access code.
(package private)  java.util.Map<Symbol,Symbol> actualSymbols
          A hash table mapping virtual accessed symbols in outer subclasses to the actually referred symbol in superclasses.
private  boolean allowEnums
           
private static int ASSIGNcode
          Access codes for dereferencing, assignment, and pre/post increment/decrement.
private  Attr attr
           
(package private)  Env<AttrContext> attrEnv
          Environment for symbol lookup, set by translateTopLevelClass.
private  ConstFold cfolder
           
private  Check chk
           
(package private)  java.util.Map<Symbol.ClassSymbol,JCTree.JCClassDecl> classdefs
          A hash table mapping local classes to their definitions.
private  Name classDollar
           
(package private)  Lower.ClassMap classMap
           
(package private)  Symbol.ClassSymbol currentClass
          The currently enclosing class.
(package private)  JCTree.JCMethodDecl currentMethodDef
          The current method definition.
(package private)  Symbol.MethodSymbol currentMethodSym
          The current method symbol.
private  boolean debugLower
           
private static int DEREFcode
          Access codes for dereferencing, assignment, and pre/post increment/decrement.
private  Name dollarAssertionsDisabled
           
private  JCTree.JCExpression enclOp
          Visitor argument: enclosing operator node.
(package private)  java.util.Map<JCTree,java.lang.Integer> endPositions
          A hash table mapping syntax trees to their ending source positions.
(package private)  java.util.Map<Symbol.TypeSymbol,Lower.EnumMapping> enumSwitchMap
           
private static int FIRSTASGOPcode
          Access codes for dereferencing, assignment, and pre/post increment/decrement.
(package private)  java.util.Map<Symbol.ClassSymbol,List<Symbol.VarSymbol>> freevarCache
          A hash table mapping class symbols to lists of free variables.
private  Log log
           
protected static Context.Key<Lower> lowerKey
           
private  TreeMaker make
           
private  JCDiagnostic.DiagnosticPosition make_pos
           
private  Names names
           
private static int NCODES
          Number of access codes
(package private)  JCTree.JCClassDecl outermostClassDef
          The currently enclosing outermost class definition.
(package private)  JCTree outermostMemberDef
          The currently enclosing outermost member definition.
(package private)  List<Symbol.VarSymbol> outerThisStack
          A stack containing the this$n field of the currently translated classes (if needed) in innermost first order.
private static int POSTDECcode
          Access codes for dereferencing, assignment, and pre/post increment/decrement.
private static int POSTINCcode
          Access codes for dereferencing, assignment, and pre/post increment/decrement.
private static int PREDECcode
          Access codes for dereferencing, assignment, and pre/post increment/decrement.
private static int PREINCcode
          Access codes for dereferencing, assignment, and pre/post increment/decrement.
(package private)  Scope proxies
          A scope containing all free variable proxies for currently translated class, as well as its this$n symbol (if needed).
private  ClassReader reader
           
private  Resolve rs
           
private  Source source
           
private  Symtab syms
           
private  Symbol.MethodSymbol systemArraycopyMethod
           
private  Target target
           
(package private)  ListBuffer<JCTree> translated
          A queue of all translated classes.
private  Types types
           
private  ClassWriter writer
           
 
Fields inherited from class com.sun.tools.javac.tree.TreeTranslator
result
 
Constructor Summary
protected Lower(Context context)
           
 
Method Summary
(package private)  JCTree abstractLval(JCTree lval, Lower.TreeBuilder builder)
           
(package private)  JCTree abstractRval(JCTree rval, Lower.TreeBuilder builder)
           
(package private)  JCTree abstractRval(JCTree rval, Type type, Lower.TreeBuilder builder)
          Construct an expression using the builder, with the given rval expression as an argument to the builder.
(package private)  JCTree.JCExpression access(JCTree.JCExpression tree)
          Ensure that identifier is accessible, return tree accessing the identifier.
(package private)  JCTree.JCExpression access(Symbol sym, JCTree.JCExpression tree, JCTree.JCExpression enclOp, boolean refSuper)
          Ensure that identifier is accessible, return tree accessing the identifier.
(package private)  JCTree.JCExpression accessBase(JCDiagnostic.DiagnosticPosition pos, Symbol sym)
          The qualifier to be used for accessing a symbol in an outer class.
(package private)  Symbol.ClassSymbol accessClass(Symbol sym, boolean protAccess, JCTree tree)
          The class in which an access method for given symbol goes.
private static int accessCode(int bytecode)
          Map bytecode of binary operation to access code of corresponding assignment operation.
private static int accessCode(JCTree tree, JCTree enclOp)
          return access code for identifier,
(package private)  Symbol accessConstructor(JCDiagnostic.DiagnosticPosition pos, Symbol constr)
          Return access constructor for a private constructor, or the constructor itself, if no access constructor is needed.
(package private)  JCTree accessConstructorDef(int pos, Symbol constr, Symbol.MethodSymbol accessor)
          Construct definition of an access constructor.
(package private)  Symbol.ClassSymbol accessConstructorTag()
          Return an anonymous class nested in this toplevel class.
(package private)  JCTree accessDef(int pos, Symbol vsym, Symbol.MethodSymbol accessor, int acode)
          Construct definition of an access method.
(package private)  Name accessName(int anum, int acode)
          The name of the access method with number `anum' and access code `acode'.
(package private)  Symbol.MethodSymbol accessSymbol(Symbol sym, JCTree tree, JCTree enclOp, boolean protAccess, boolean refSuper)
          Return access symbol for a private or protected symbol from an inner class.
private  Symbol.MethodSymbol addEnumCompareTo(JCTree.JCClassDecl cdef, Symbol.VarSymbol ordinalSymbol)
           
private  void addEnumCompatibleMembers(JCTree.JCClassDecl cdef)
           
private  Symbol.MethodSymbol addEnumFieldNameMethod(JCTree.JCClassDecl cdef, Symbol.VarSymbol nameSymbol)
           
private  Symbol.MethodSymbol addEnumFieldOrdinalMethod(JCTree.JCClassDecl cdef, Symbol.VarSymbol ordinalSymbol)
           
private  Symbol.VarSymbol addEnumNameField(JCTree.JCClassDecl cdef)
           
private  Symbol.VarSymbol addEnumOrdinalField(JCTree.JCClassDecl cdef)
           
private  Symbol.MethodSymbol addEnumToString(JCTree.JCClassDecl cdef, Symbol.VarSymbol nameSymbol)
           
private  JCTree.JCExpression assertFlagTest(JCDiagnostic.DiagnosticPosition pos)
          Code for enabling/disabling assertions.
private  Symbol.OperatorSymbol binaryAccessOperator(int acode)
          Return binary operator that corresponds to given access code.
(package private)  List<JCTree.JCExpression> boxArgs(List<Type> parameters, List<JCTree.JCExpression> _args, Type varargsElement)
           
(package private)
<T extends JCTree>
T
boxIfNeeded(T tree, Type type)
          Expand a boxing or unboxing conversion if needed.
(package private)  JCTree.JCExpression boxPrimitive(JCTree.JCExpression tree)
          Box up a single primitive expression.
(package private)  JCTree.JCExpression boxPrimitive(JCTree.JCExpression tree, Type box)
          Box up a single primitive expression.
private  Name cacheName(java.lang.String sig)
          The Name Of The variable to cache T.class values.
private  Symbol.VarSymbol cacheSym(JCDiagnostic.DiagnosticPosition pos, java.lang.String sig)
          The variable symbol that caches T.class values.
(package private)  JCTree.JCClassDecl classDef(Symbol.ClassSymbol c)
          Map a class symbol to its definition.
private  Symbol.MethodSymbol classDollarSym(JCDiagnostic.DiagnosticPosition pos)
          Return symbol for "class$" method.
(package private)  JCTree.JCBlock classDollarSymBody(JCDiagnostic.DiagnosticPosition pos, JCTree.JCMethodDecl md)
          Generate code for class$(String name).
private  JCTree.JCExpression classOf(JCTree clazz)
          The tree simulating a T.class expression.
private  JCTree.JCExpression classOfType(Type type, JCDiagnostic.DiagnosticPosition pos)
           
private  JCTree convert(JCTree tree, Type pt)
           
private  void duplicateError(JCDiagnostic.DiagnosticPosition pos, Symbol sym)
          Report a conflict between a user symbol and a synthetic symbol.
private  void enterSynthetic(JCDiagnostic.DiagnosticPosition pos, Symbol sym, Scope s)
          Enter a synthetic symbol in a given scope, but complain if there was already one there.
(package private)  List<JCTree.JCVariableDecl> freevarDefs(int pos, List<Symbol.VarSymbol> freevars, Symbol owner)
          Proxy definitions for all free variables in given list, in reverse order.
(package private)  List<Symbol.VarSymbol> freevars(Symbol.ClassSymbol c)
          Return the variables accessed from within a local class, which are declared in the local class' owner.
(package private)  JCTree.JCStatement initField(int pos, Name name)
          Return tree simulating the assignment , where name is the name of a free variable.
(package private)  JCTree.JCStatement initOuterThis(int pos)
          Return tree simulating the assignment .
static Lower instance(Context context)
           
(package private)  JCTree.JCExpression loadFreevar(JCDiagnostic.DiagnosticPosition pos, Symbol.VarSymbol v)
           
(package private)  List<JCTree.JCExpression> loadFreevars(JCDiagnostic.DiagnosticPosition pos, List<Symbol.VarSymbol> freevars)
          Return a list of trees that load the free variables in given list, in reverse order.
private  Symbol.MethodSymbol lookupConstructor(JCDiagnostic.DiagnosticPosition pos, Type qual, List<Type> args)
          Look up a constructor.
private  Symbol.VarSymbol lookupField(JCDiagnostic.DiagnosticPosition pos, Type qual, Name name)
          Look up a field.
private  Symbol.MethodSymbol lookupMethod(JCDiagnostic.DiagnosticPosition pos, Name name, Type qual, List<Type> args)
          Look up a method in a given scope.
private  Symbol lookupSynthetic(Name name, Scope s)
          Look up a synthetic name in a given scope.
(package private)  JCTree lowerBoxedPostop(JCTree.JCUnary tree)
          Lower a tree of the form e++ or e-- where e is an object type
(package private)  TreeMaker make_at(JCDiagnostic.DiagnosticPosition pos)
          Equivalent to make.at(pos.getStartPosition()) with side effect of caching pos as make_pos, for use in diagnostics.
(package private)  void makeAccessible(Symbol sym)
          Add all required access methods for a private symbol to enclosing class.
(package private)  JCTree.JCAssignOp makeAssignop(int optag, JCTree lhs, JCTree rhs)
          Make an attributed assignop expression.
(package private)  JCTree.JCBinary makeBinary(int optag, JCTree.JCExpression lhs, JCTree.JCExpression rhs)
          Make an attributed binary expression.
private  JCTree.JCMethodInvocation makeCall(JCTree.JCExpression left, Name name, List<JCTree.JCExpression> args)
          Create an attributed tree of the form left.name().
(package private)  JCTree makeComma(JCTree expr1, JCTree expr2)
           
(package private)  Symbol.ClassSymbol makeEmptyClass(long flags, Symbol.ClassSymbol owner)
          Create an empty anonymous class definition and enter and complete its symbol.
(package private)  JCTree.JCExpression makeLit(Type type, java.lang.Object value)
          Make an attributed tree representing a literal.
(package private)  JCTree.JCNewClass makeNewClass(Type ctype, List<JCTree.JCExpression> args)
          Make an attributed class instance creation expression.
(package private)  JCTree.JCExpression makeNull()
          Make an attributed tree representing null.
(package private)  JCTree.JCExpression makeOuterThis(JCDiagnostic.DiagnosticPosition pos, Symbol.TypeSymbol c)
          Construct a tree that represents the outer instance .
(package private)  JCTree.JCExpression makeOwnerThis(JCDiagnostic.DiagnosticPosition pos, Symbol sym, boolean preciseMatch)
          Construct a tree that represents the closest outer instance such that the given symbol is a member of C.
(package private)  JCTree.JCExpression makeOwnerThisN(JCDiagnostic.DiagnosticPosition pos, Symbol sym, boolean preciseMatch)
          Similar to makeOwnerThis but will never pick "this".
(package private)  JCTree.JCExpression makeString(JCTree.JCExpression tree)
          Convert tree into string object, unless it has already a reference type..
(package private)  JCTree.JCExpression makeThis(JCDiagnostic.DiagnosticPosition pos, Symbol.TypeSymbol c)
          Construct a tree simulating the expression .
(package private)  JCTree.JCUnary makeUnary(int optag, JCTree.JCExpression arg)
          Make an attributed unary expression.
(package private)  Lower.EnumMapping mapForEnum(JCDiagnostic.DiagnosticPosition pos, Symbol.TypeSymbol enumClass)
           
(package private)  boolean needsPrivateAccess(Symbol sym)
          Do we need an access method to reference private symbol?
(package private)  boolean needsProtectedAccess(Symbol sym, JCTree tree)
          Do we need an access method to reference symbol in other package?
private  Symbol.ClassSymbol outerCacheClass()
          Return the symbol of a class to contain a cache of compiler-generated statics such as class$ and the $assertionsDisabled flag.
(package private)  JCTree.JCVariableDecl outerThisDef(int pos, Symbol owner)
          Definition for this$n field.
(package private)  Name outerThisName(Type type, Symbol owner)
          The name of a this$n field
private  void patchTargets(JCTree body, JCTree src, JCTree dest)
          Patch up break and continue targets.
(package private)  Name proxyName(Name name)
          The name of a free variable proxy.
<T extends JCTree>
List<T>
translate(List<T> trees, JCTree.JCExpression enclOp)
          Visitor method: Translate list of trees.
<T extends JCTree>
List<T>
translate(List<T> trees, Type type)
          Visitor method: Translate list of trees.
<T extends JCTree>
T
translate(T tree)
          Visitor method: Translate a single node.
<T extends JCTree>
T
translate(T tree, JCTree.JCExpression enclOp)
          Visitor method: Translate tree.
<T extends JCTree>
T
translate(T tree, Type type)
          Visitor method: Translate a single node, boxing or unboxing if needed.
 List<JCTree> translateTopLevelClass(Env<AttrContext> env, JCTree cdef, TreeMaker make)
          Translate a toplevel class and return a list consisting of the translated class and translated versions of all inner classes.
private static int treeTag(Symbol.OperatorSymbol operator)
          Return tree tag for assignment operation corresponding to given binary operator.
(package private)  JCTree.JCExpression unbox(JCTree.JCExpression tree, Type primitive)
          Unbox an object to a primitive value.
private  boolean useClone()
           
 void visitAnnotation(JCTree.JCAnnotation tree)
           
 void visitApply(JCTree.JCMethodInvocation tree)
           
private  void visitArrayForeachLoop(JCTree.JCEnhancedForLoop tree)
          A statment of the form
 void visitAssert(JCTree.JCAssert tree)
          Visitor method for assert statements.
 void visitAssign(JCTree.JCAssign tree)
           
 void visitAssignop(JCTree.JCAssignOp tree)
           
 void visitBinary(JCTree.JCBinary tree)
           
 void visitBlock(JCTree.JCBlock tree)
           
 void visitClassDef(JCTree.JCClassDecl tree)
           
 void visitConditional(JCTree.JCConditional tree)
          Visitor method for conditional expressions.
 void visitDoLoop(JCTree.JCDoWhileLoop tree)
           
private  void visitEnumConstantDef(JCTree.JCVariableDecl var, int ordinal)
          Translate an enumeration constant and its initializer.
private  void visitEnumDef(JCTree.JCClassDecl tree)
          Translate an enum class.
 JCTree visitEnumSwitch(JCTree.JCSwitch tree)
           
 void visitForeachLoop(JCTree.JCEnhancedForLoop tree)
          Translate away the foreach loop.
 void visitForLoop(JCTree.JCForLoop tree)
           
 void visitIdent(JCTree.JCIdent tree)
           
 void visitIf(JCTree.JCIf tree)
          Visitor method for if statements.
 void visitIndexed(JCTree.JCArrayAccess tree)
           
private  void visitIterableForeachLoop(JCTree.JCEnhancedForLoop tree)
          A statement of the form
 void visitLetExpr(JCTree.LetExpr tree)
           
 void visitMethodDef(JCTree.JCMethodDecl tree)
           
private  void visitMethodDefInternal(JCTree.JCMethodDecl tree)
           
 void visitNewArray(JCTree.JCNewArray tree)
           
 void visitNewClass(JCTree.JCNewClass tree)
           
 void visitParens(JCTree.JCParens tree)
          Visitor method for parenthesized expressions.
 void visitReturn(JCTree.JCReturn tree)
           
 void visitSelect(JCTree.JCFieldAccess tree)
           
 void visitSwitch(JCTree.JCSwitch tree)
           
 void visitTopLevel(JCTree.JCCompilationUnit tree)
           
 void visitTypeCast(JCTree.JCTypeCast tree)
           
 void visitUnary(JCTree.JCUnary tree)
           
 void visitVarDef(JCTree.JCVariableDecl tree)
           
 void visitWhileLoop(JCTree.JCWhileLoop tree)
           
 
Methods inherited from class com.sun.tools.javac.tree.TreeTranslator
translate, translateAnnotations, translateCases, translateCatchers, translateTypeParams, translateVarDefs, visitBracketExpr, visitBracketStat, visitBreak, visitCase, visitCatch, visitContinue, visitErroneous, visitExec, visitImport, visitLabelled, visitLiteral, visitModifiers, visitSkip, visitSynchronized, visitThrow, visitTree, visitTry, visitTypeApply, visitTypeArray, visitTypeBoundKind, visitTypeIdent, visitTypeParameter, visitTypeTest, visitWildcard
 
Methods inherited from class com.sun.tools.javac.tree.JCTree.Visitor
visitEscapeExpr, visitEscapeStat
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lowerKey

protected static final Context.Key<Lower> lowerKey

names

private Names names

log

private Log log

syms

private Symtab syms

rs

private Resolve rs

chk

private Check chk

attr

private Attr attr

make

private TreeMaker make

make_pos

private JCDiagnostic.DiagnosticPosition make_pos

writer

private ClassWriter writer

reader

private ClassReader reader

cfolder

private ConstFold cfolder

target

private Target target

source

private Source source

allowEnums

private boolean allowEnums

dollarAssertionsDisabled

private final Name dollarAssertionsDisabled

classDollar

private final Name classDollar

types

private Types types

debugLower

private boolean debugLower

currentClass

Symbol.ClassSymbol currentClass
The currently enclosing class.


translated

ListBuffer<JCTree> translated
A queue of all translated classes.


attrEnv

Env<AttrContext> attrEnv
Environment for symbol lookup, set by translateTopLevelClass.


endPositions

java.util.Map<JCTree,java.lang.Integer> endPositions
A hash table mapping syntax trees to their ending source positions.


classdefs

java.util.Map<Symbol.ClassSymbol,JCTree.JCClassDecl> classdefs
A hash table mapping local classes to their definitions.


actualSymbols

java.util.Map<Symbol,Symbol> actualSymbols
A hash table mapping virtual accessed symbols in outer subclasses to the actually referred symbol in superclasses.


currentMethodDef

JCTree.JCMethodDecl currentMethodDef
The current method definition.


currentMethodSym

Symbol.MethodSymbol currentMethodSym
The current method symbol.


outermostClassDef

JCTree.JCClassDecl outermostClassDef
The currently enclosing outermost class definition.


outermostMemberDef

JCTree outermostMemberDef
The currently enclosing outermost member definition.


classMap

Lower.ClassMap classMap

freevarCache

java.util.Map<Symbol.ClassSymbol,List<Symbol.VarSymbol>> freevarCache
A hash table mapping class symbols to lists of free variables. accessed by them. Only free variables of the method immediately containing a class are associated with that class.


enumSwitchMap

java.util.Map<Symbol.TypeSymbol,Lower.EnumMapping> enumSwitchMap

DEREFcode

private static final int DEREFcode
Access codes for dereferencing, assignment, and pre/post increment/decrement. Access codes for assignment operations are determined by method accessCode below. All access codes for accesses to the current class are even. If a member of the superclass should be accessed instead (because access was via a qualified super), add one to the corresponding code for the current class, making the number odd. This numbering scheme is used by the backend to decide whether to issue an invokevirtual or invokespecial call.

See Also:
Gen.visitSelect(Select tree), Constant Field Values

ASSIGNcode

private static final int ASSIGNcode
Access codes for dereferencing, assignment, and pre/post increment/decrement. Access codes for assignment operations are determined by method accessCode below. All access codes for accesses to the current class are even. If a member of the superclass should be accessed instead (because access was via a qualified super), add one to the corresponding code for the current class, making the number odd. This numbering scheme is used by the backend to decide whether to issue an invokevirtual or invokespecial call.

See Also:
Gen.visitSelect(Select tree), Constant Field Values

PREINCcode

private static final int PREINCcode
Access codes for dereferencing, assignment, and pre/post increment/decrement. Access codes for assignment operations are determined by method accessCode below. All access codes for accesses to the current class are even. If a member of the superclass should be accessed instead (because access was via a qualified super), add one to the corresponding code for the current class, making the number odd. This numbering scheme is used by the backend to decide whether to issue an invokevirtual or invokespecial call.

See Also:
Gen.visitSelect(Select tree), Constant Field Values

PREDECcode

private static final int PREDECcode
Access codes for dereferencing, assignment, and pre/post increment/decrement. Access codes for assignment operations are determined by method accessCode below. All access codes for accesses to the current class are even. If a member of the superclass should be accessed instead (because access was via a qualified super), add one to the corresponding code for the current class, making the number odd. This numbering scheme is used by the backend to decide whether to issue an invokevirtual or invokespecial call.

See Also:
Gen.visitSelect(Select tree), Constant Field Values

POSTINCcode

private static final int POSTINCcode
Access codes for dereferencing, assignment, and pre/post increment/decrement. Access codes for assignment operations are determined by method accessCode below. All access codes for accesses to the current class are even. If a member of the superclass should be accessed instead (because access was via a qualified super), add one to the corresponding code for the current class, making the number odd. This numbering scheme is used by the backend to decide whether to issue an invokevirtual or invokespecial call.

See Also:
Gen.visitSelect(Select tree), Constant Field Values

POSTDECcode

private static final int POSTDECcode
Access codes for dereferencing, assignment, and pre/post increment/decrement. Access codes for assignment operations are determined by method accessCode below. All access codes for accesses to the current class are even. If a member of the superclass should be accessed instead (because access was via a qualified super), add one to the corresponding code for the current class, making the number odd. This numbering scheme is used by the backend to decide whether to issue an invokevirtual or invokespecial call.

See Also:
Gen.visitSelect(Select tree), Constant Field Values

FIRSTASGOPcode

private static final int FIRSTASGOPcode
Access codes for dereferencing, assignment, and pre/post increment/decrement. Access codes for assignment operations are determined by method accessCode below. All access codes for accesses to the current class are even. If a member of the superclass should be accessed instead (because access was via a qualified super), add one to the corresponding code for the current class, making the number odd. This numbering scheme is used by the backend to decide whether to issue an invokevirtual or invokespecial call.

See Also:
Gen.visitSelect(Select tree), Constant Field Values

NCODES

private static final int NCODES
Number of access codes


accessNums

private java.util.Map<Symbol,java.lang.Integer> accessNums
A mapping from symbols to their access numbers.


accessSyms

private java.util.Map<Symbol,Symbol.MethodSymbol[]> accessSyms
A mapping from symbols to an array of access symbols, indexed by access code.


accessConstrs

private java.util.Map<Symbol,Symbol.MethodSymbol> accessConstrs
A mapping from (constructor) symbols to access constructor symbols.


accessed

private ListBuffer<Symbol> accessed
A queue for all accessed symbols.


proxies

Scope proxies
A scope containing all free variable proxies for currently translated class, as well as its this$n symbol (if needed). Proxy scopes are nested in the same way classes are. Inside a constructor, proxies and any this$n symbol are duplicated in an additional innermost scope, where they represent the constructor parameters.


outerThisStack

List<Symbol.VarSymbol> outerThisStack
A stack containing the this$n field of the currently translated classes (if needed) in innermost first order. Inside a constructor, proxies and any this$n symbol are duplicated in an additional innermost scope, where they represent the constructor parameters.


enclOp

private JCTree.JCExpression enclOp
Visitor argument: enclosing operator node.


systemArraycopyMethod

private Symbol.MethodSymbol systemArraycopyMethod
Constructor Detail

Lower

protected Lower(Context context)
Method Detail

instance

public static Lower instance(Context context)

classDef

JCTree.JCClassDecl classDef(Symbol.ClassSymbol c)
Map a class symbol to its definition.

Parameters:
c - The class symbol of which we want to determine the definition.

freevars

List<Symbol.VarSymbol> freevars(Symbol.ClassSymbol c)
Return the variables accessed from within a local class, which are declared in the local class' owner. (in reverse order of first access).


mapForEnum

Lower.EnumMapping mapForEnum(JCDiagnostic.DiagnosticPosition pos,
                             Symbol.TypeSymbol enumClass)

make_at

TreeMaker make_at(JCDiagnostic.DiagnosticPosition pos)
Equivalent to make.at(pos.getStartPosition()) with side effect of caching pos as make_pos, for use in diagnostics.


makeLit

JCTree.JCExpression makeLit(Type type,
                            java.lang.Object value)
Make an attributed tree representing a literal. This will be an Ident node in the case of boolean literals, a Literal node in all other cases.

Parameters:
type - The literal's type.
value - The literal's value.

makeNull

JCTree.JCExpression makeNull()
Make an attributed tree representing null.


makeNewClass

JCTree.JCNewClass makeNewClass(Type ctype,
                               List<JCTree.JCExpression> args)
Make an attributed class instance creation expression.

Parameters:
ctype - The class type.
args - The constructor arguments.

makeUnary

JCTree.JCUnary makeUnary(int optag,
                         JCTree.JCExpression arg)
Make an attributed unary expression.

Parameters:
optag - The operators tree tag.
arg - The operator's argument.

makeBinary

JCTree.JCBinary makeBinary(int optag,
                           JCTree.JCExpression lhs,
                           JCTree.JCExpression rhs)
Make an attributed binary expression.

Parameters:
optag - The operators tree tag.
lhs - The operator's left argument.
rhs - The operator's right argument.

makeAssignop

JCTree.JCAssignOp makeAssignop(int optag,
                               JCTree lhs,
                               JCTree rhs)
Make an attributed assignop expression.

Parameters:
optag - The operators tree tag.
lhs - The operator's left argument.
rhs - The operator's right argument.

makeString

JCTree.JCExpression makeString(JCTree.JCExpression tree)
Convert tree into string object, unless it has already a reference type..


makeEmptyClass

Symbol.ClassSymbol makeEmptyClass(long flags,
                                  Symbol.ClassSymbol owner)
Create an empty anonymous class definition and enter and complete its symbol. Return the class definition's symbol. and create

Parameters:
flags - The class symbol's flags
owner - The class symbol's owner

duplicateError

private void duplicateError(JCDiagnostic.DiagnosticPosition pos,
                            Symbol sym)
Report a conflict between a user symbol and a synthetic symbol.


enterSynthetic

private void enterSynthetic(JCDiagnostic.DiagnosticPosition pos,
                            Symbol sym,
                            Scope s)
Enter a synthetic symbol in a given scope, but complain if there was already one there.

Parameters:
pos - Position for error reporting.
sym - The symbol.
s - The scope.

lookupSynthetic

private Symbol lookupSynthetic(Name name,
                               Scope s)
Look up a synthetic name in a given scope.

Parameters:
scope - The scope.
name - The name.

lookupMethod

private Symbol.MethodSymbol lookupMethod(JCDiagnostic.DiagnosticPosition pos,
                                         Name name,
                                         Type qual,
                                         List<Type> args)
Look up a method in a given scope.


lookupConstructor

private Symbol.MethodSymbol lookupConstructor(JCDiagnostic.DiagnosticPosition pos,
                                              Type qual,
                                              List<Type> args)
Look up a constructor.


lookupField

private Symbol.VarSymbol lookupField(JCDiagnostic.DiagnosticPosition pos,
                                     Type qual,
                                     Name name)
Look up a field.


accessCode

private static int accessCode(int bytecode)
Map bytecode of binary operation to access code of corresponding assignment operation. This is always an even number.


accessCode

private static int accessCode(JCTree tree,
                              JCTree enclOp)
return access code for identifier,

Parameters:
tree - The tree representing the identifier use.
enclOp - The closest enclosing operation node of tree, null if tree is not a subtree of an operation.

binaryAccessOperator

private Symbol.OperatorSymbol binaryAccessOperator(int acode)
Return binary operator that corresponds to given access code.


treeTag

private static int treeTag(Symbol.OperatorSymbol operator)
Return tree tag for assignment operation corresponding to given binary operator.


accessName

Name accessName(int anum,
                int acode)
The name of the access method with number `anum' and access code `acode'.


accessSymbol

Symbol.MethodSymbol accessSymbol(Symbol sym,
                                 JCTree tree,
                                 JCTree enclOp,
                                 boolean protAccess,
                                 boolean refSuper)
Return access symbol for a private or protected symbol from an inner class.

Parameters:
sym - The accessed private symbol.
tree - The accessing tree.
enclOp - The closest enclosing operation node of tree, null if tree is not a subtree of an operation.
protAccess - Is access to a protected symbol in another package?
refSuper - Is access via a (qualified) C.super?

accessBase

JCTree.JCExpression accessBase(JCDiagnostic.DiagnosticPosition pos,
                               Symbol sym)
The qualifier to be used for accessing a symbol in an outer class. This is either C.sym or C.this.sym, depending on whether or not sym is static.

Parameters:
sym - The accessed symbol.

needsPrivateAccess

boolean needsPrivateAccess(Symbol sym)
Do we need an access method to reference private symbol?


needsProtectedAccess

boolean needsProtectedAccess(Symbol sym,
                             JCTree tree)
Do we need an access method to reference symbol in other package?


accessClass

Symbol.ClassSymbol accessClass(Symbol sym,
                               boolean protAccess,
                               JCTree tree)
The class in which an access method for given symbol goes.

Parameters:
sym - The access symbol
protAccess - Is access to a protected symbol in another package?

access

JCTree.JCExpression access(Symbol sym,
                           JCTree.JCExpression tree,
                           JCTree.JCExpression enclOp,
                           boolean refSuper)
Ensure that identifier is accessible, return tree accessing the identifier.

Parameters:
sym - The accessed symbol.
tree - The tree referring to the symbol.
enclOp - The closest enclosing operation node of tree, null if tree is not a subtree of an operation.
refSuper - Is access via a (qualified) C.super?

access

JCTree.JCExpression access(JCTree.JCExpression tree)
Ensure that identifier is accessible, return tree accessing the identifier.

Parameters:
tree - The identifier tree.

accessConstructor

Symbol accessConstructor(JCDiagnostic.DiagnosticPosition pos,
                         Symbol constr)
Return access constructor for a private constructor, or the constructor itself, if no access constructor is needed.

Parameters:
pos - The position to report diagnostics, if any.
constr - The private constructor.

accessConstructorTag

Symbol.ClassSymbol accessConstructorTag()
Return an anonymous class nested in this toplevel class.


makeAccessible

void makeAccessible(Symbol sym)
Add all required access methods for a private symbol to enclosing class.

Parameters:
sym - The symbol.

accessDef

JCTree accessDef(int pos,
                 Symbol vsym,
                 Symbol.MethodSymbol accessor,
                 int acode)
Construct definition of an access method.

Parameters:
pos - The source code position of the definition.
vsym - The private or protected symbol.
accessor - The access method for the symbol.
acode - The access code.

accessConstructorDef

JCTree accessConstructorDef(int pos,
                            Symbol constr,
                            Symbol.MethodSymbol accessor)
Construct definition of an access constructor.

Parameters:
pos - The source code position of the definition.
constr - The private constructor.
accessor - The access method for the constructor.

proxyName

Name proxyName(Name name)
The name of a free variable proxy.


freevarDefs

List<JCTree.JCVariableDecl> freevarDefs(int pos,
                                        List<Symbol.VarSymbol> freevars,
                                        Symbol owner)
Proxy definitions for all free variables in given list, in reverse order.

Parameters:
pos - The source code position of the definition.
freevars - The free variables.
owner - The class in which the definitions go.

outerThisName

Name outerThisName(Type type,
                   Symbol owner)
The name of a this$n field

Parameters:
type - The class referenced by the this$n field

outerThisDef

JCTree.JCVariableDecl outerThisDef(int pos,
                                   Symbol owner)
Definition for this$n field.

Parameters:
pos - The source code position of the definition.
owner - The class in which the definition goes.

loadFreevars

List<JCTree.JCExpression> loadFreevars(JCDiagnostic.DiagnosticPosition pos,
                                       List<Symbol.VarSymbol> freevars)
Return a list of trees that load the free variables in given list, in reverse order.

Parameters:
pos - The source code position to be used for the trees.
freevars - The list of free variables.

loadFreevar

JCTree.JCExpression loadFreevar(JCDiagnostic.DiagnosticPosition pos,
                                Symbol.VarSymbol v)

makeThis

JCTree.JCExpression makeThis(JCDiagnostic.DiagnosticPosition pos,
                             Symbol.TypeSymbol c)
Construct a tree simulating the expression .

Parameters:
pos - The source code position to be used for the tree.
c - The qualifier class.

makeOuterThis

JCTree.JCExpression makeOuterThis(JCDiagnostic.DiagnosticPosition pos,
                                  Symbol.TypeSymbol c)
Construct a tree that represents the outer instance . Never pick the current `this'.

Parameters:
pos - The source code position to be used for the tree.
c - The qualifier class.

makeOwnerThis

JCTree.JCExpression makeOwnerThis(JCDiagnostic.DiagnosticPosition pos,
                                  Symbol sym,
                                  boolean preciseMatch)
Construct a tree that represents the closest outer instance such that the given symbol is a member of C.

Parameters:
pos - The source code position to be used for the tree.
sym - The accessed symbol.
preciseMatch - should we accept a type that is a subtype of sym's owner, even if it doesn't contain sym due to hiding, overriding, or non-inheritance due to protection?

makeOwnerThisN

JCTree.JCExpression makeOwnerThisN(JCDiagnostic.DiagnosticPosition pos,
                                   Symbol sym,
                                   boolean preciseMatch)
Similar to makeOwnerThis but will never pick "this".


initField

JCTree.JCStatement initField(int pos,
                             Name name)
Return tree simulating the assignment , where name is the name of a free variable.


initOuterThis

JCTree.JCStatement initOuterThis(int pos)
Return tree simulating the assignment .


outerCacheClass

private Symbol.ClassSymbol outerCacheClass()
Return the symbol of a class to contain a cache of compiler-generated statics such as class$ and the $assertionsDisabled flag. We create an anonymous nested class (unless one already exists) and return its symbol. However, for backward compatibility in 1.4 and earlier we use the top-level class itself.


classDollarSym

private Symbol.MethodSymbol classDollarSym(JCDiagnostic.DiagnosticPosition pos)
Return symbol for "class$" method. If there is no method definition for class$, construct one as follows: class class$(String x0) { try { return Class.forName(x0); } catch (ClassNotFoundException x1) { throw new NoClassDefFoundError(x1.getMessage()); } }


classDollarSymBody

JCTree.JCBlock classDollarSymBody(JCDiagnostic.DiagnosticPosition pos,
                                  JCTree.JCMethodDecl md)
Generate code for class$(String name).


makeCall

private JCTree.JCMethodInvocation makeCall(JCTree.JCExpression left,
                                           Name name,
                                           List<JCTree.JCExpression> args)
Create an attributed tree of the form left.name().


cacheName

private Name cacheName(java.lang.String sig)
The Name Of The variable to cache T.class values.

Parameters:
sig - The signature of type T.

cacheSym

private Symbol.VarSymbol cacheSym(JCDiagnostic.DiagnosticPosition pos,
                                  java.lang.String sig)
The variable symbol that caches T.class values. If none exists yet, create a definition.

Parameters:
sig - The signature of type T.
pos - The position to report diagnostics, if any.

classOf

private JCTree.JCExpression classOf(JCTree clazz)
The tree simulating a T.class expression.

Parameters:
clazz - The tree identifying type T.

classOfType

private JCTree.JCExpression classOfType(Type type,
                                        JCDiagnostic.DiagnosticPosition pos)

assertFlagTest

private JCTree.JCExpression assertFlagTest(JCDiagnostic.DiagnosticPosition pos)
Code for enabling/disabling assertions.


abstractRval

JCTree abstractRval(JCTree rval,
                    Type type,
                    Lower.TreeBuilder builder)
Construct an expression using the builder, with the given rval expression as an argument to the builder. However, the rval expression must be computed only once, even if used multiple times in the result of the builder. We do that by constructing a "let" expression that saves the rvalue into a temporary variable and then uses the temporary variable in place of the expression built by the builder. The complete resulting expression is of the form
    (let TYPE TEMP = RVAL;
     in (BUILDER(TEMP)))
  
where TEMP is a newly declared variable in the let expression.


abstractRval

JCTree abstractRval(JCTree rval,
                    Lower.TreeBuilder builder)

abstractLval

JCTree abstractLval(JCTree lval,
                    Lower.TreeBuilder builder)

makeComma

JCTree makeComma(JCTree expr1,
                 JCTree expr2)

translate

public <T extends JCTree> T translate(T tree)
Visitor method: Translate a single node. Attach the source position from the old tree to its replacement tree.

Overrides:
translate in class TreeTranslator

translate

public <T extends JCTree> T translate(T tree,
                                      Type type)
Visitor method: Translate a single node, boxing or unboxing if needed.


translate

public <T extends JCTree> T translate(T tree,
                                      JCTree.JCExpression enclOp)
Visitor method: Translate tree.


translate

public <T extends JCTree> List<T> translate(List<T> trees,
                                            JCTree.JCExpression enclOp)
Visitor method: Translate list of trees.


translate

public <T extends JCTree> List<T> translate(List<T> trees,
                                            Type type)
Visitor method: Translate list of trees.


visitTopLevel

public void visitTopLevel(JCTree.JCCompilationUnit tree)
Overrides:
visitTopLevel in class TreeTranslator

visitClassDef

public void visitClassDef(JCTree.JCClassDecl tree)
Overrides:
visitClassDef in class TreeTranslator

visitEnumDef

private void visitEnumDef(JCTree.JCClassDecl tree)
Translate an enum class.


useClone

private boolean useClone()

visitEnumConstantDef

private void visitEnumConstantDef(JCTree.JCVariableDecl var,
                                  int ordinal)
Translate an enumeration constant and its initializer.


visitMethodDef

public void visitMethodDef(JCTree.JCMethodDecl tree)
Overrides:
visitMethodDef in class TreeTranslator

visitMethodDefInternal

private void visitMethodDefInternal(JCTree.JCMethodDecl tree)

visitTypeCast

public void visitTypeCast(JCTree.JCTypeCast tree)
Overrides:
visitTypeCast in class TreeTranslator

visitNewClass

public void visitNewClass(JCTree.JCNewClass tree)
Overrides:
visitNewClass in class TreeTranslator

visitConditional

public void visitConditional(JCTree.JCConditional tree)
Visitor method for conditional expressions.

Overrides:
visitConditional in class TreeTranslator

convert

private JCTree convert(JCTree tree,
                       Type pt)

visitIf

public void visitIf(JCTree.JCIf tree)
Visitor method for if statements.

Overrides:
visitIf in class TreeTranslator

visitAssert

public void visitAssert(JCTree.JCAssert tree)
Visitor method for assert statements. Translate them away.

Overrides:
visitAssert in class TreeTranslator

visitApply

public void visitApply(JCTree.JCMethodInvocation tree)
Overrides:
visitApply in class TreeTranslator

boxArgs

List<JCTree.JCExpression> boxArgs(List<Type> parameters,
                                  List<JCTree.JCExpression> _args,
                                  Type varargsElement)

boxIfNeeded

<T extends JCTree> T boxIfNeeded(T tree,
                                 Type type)
Expand a boxing or unboxing conversion if needed.


boxPrimitive

JCTree.JCExpression boxPrimitive(JCTree.JCExpression tree)
Box up a single primitive expression.


boxPrimitive

JCTree.JCExpression boxPrimitive(JCTree.JCExpression tree,
                                 Type box)
Box up a single primitive expression.


unbox

JCTree.JCExpression unbox(JCTree.JCExpression tree,
                          Type primitive)
Unbox an object to a primitive value.


visitParens

public void visitParens(JCTree.JCParens tree)
Visitor method for parenthesized expressions. If the subexpression has changed, omit the parens.

Overrides:
visitParens in class TreeTranslator

visitIndexed

public void visitIndexed(JCTree.JCArrayAccess tree)
Overrides:
visitIndexed in class TreeTranslator

visitAssign

public void visitAssign(JCTree.JCAssign tree)
Overrides:
visitAssign in class TreeTranslator

visitAssignop

public void visitAssignop(JCTree.JCAssignOp tree)
Overrides:
visitAssignop in class TreeTranslator

lowerBoxedPostop

JCTree lowerBoxedPostop(JCTree.JCUnary tree)
Lower a tree of the form e++ or e-- where e is an object type


visitUnary

public void visitUnary(JCTree.JCUnary tree)
Overrides:
visitUnary in class TreeTranslator

visitBinary

public void visitBinary(JCTree.JCBinary tree)
Overrides:
visitBinary in class TreeTranslator

visitIdent

public void visitIdent(JCTree.JCIdent tree)
Overrides:
visitIdent in class TreeTranslator

visitForeachLoop

public void visitForeachLoop(JCTree.JCEnhancedForLoop tree)
Translate away the foreach loop.

Overrides:
visitForeachLoop in class TreeTranslator

visitArrayForeachLoop

private void visitArrayForeachLoop(JCTree.JCEnhancedForLoop tree)
A statment of the form
     for ( T v : arrayexpr ) stmt;
 
(where arrayexpr is of an array type) gets translated to
     for ( { arraytype #arr = arrayexpr;
             int #len = array.length;
             int #i = 0; };
           #i < #len; i$++ ) {
         T v = arr$[#i];
         stmt;
     }
 
where #arr, #len, and #i are freshly named synthetic local variables.


patchTargets

private void patchTargets(JCTree body,
                          JCTree src,
                          JCTree dest)
Patch up break and continue targets.


visitIterableForeachLoop

private void visitIterableForeachLoop(JCTree.JCEnhancedForLoop tree)
A statement of the form
     for ( T v : coll ) stmt ;
 
(where coll implements Iterable) gets translated to
     for ( Iterator #i = coll.iterator(); #i.hasNext(); ) {
         T v = (T) #i.next();
         stmt;
     }
 
where #i is a freshly named synthetic local variable.


visitVarDef

public void visitVarDef(JCTree.JCVariableDecl tree)
Overrides:
visitVarDef in class TreeTranslator

visitBlock

public void visitBlock(JCTree.JCBlock tree)
Overrides:
visitBlock in class TreeTranslator

visitDoLoop

public void visitDoLoop(JCTree.JCDoWhileLoop tree)
Overrides:
visitDoLoop in class TreeTranslator

visitWhileLoop

public void visitWhileLoop(JCTree.JCWhileLoop tree)
Overrides:
visitWhileLoop in class TreeTranslator

visitForLoop

public void visitForLoop(JCTree.JCForLoop tree)
Overrides:
visitForLoop in class TreeTranslator

visitReturn

public void visitReturn(JCTree.JCReturn tree)
Overrides:
visitReturn in class TreeTranslator

visitSwitch

public void visitSwitch(JCTree.JCSwitch tree)
Overrides:
visitSwitch in class TreeTranslator

visitEnumSwitch

public JCTree visitEnumSwitch(JCTree.JCSwitch tree)

visitNewArray

public void visitNewArray(JCTree.JCNewArray tree)
Overrides:
visitNewArray in class TreeTranslator

visitSelect

public void visitSelect(JCTree.JCFieldAccess tree)
Overrides:
visitSelect in class TreeTranslator

visitLetExpr

public void visitLetExpr(JCTree.LetExpr tree)
Overrides:
visitLetExpr in class TreeTranslator

visitAnnotation

public void visitAnnotation(JCTree.JCAnnotation tree)
Overrides:
visitAnnotation in class TreeTranslator

translateTopLevelClass

public List<JCTree> translateTopLevelClass(Env<AttrContext> env,
                                           JCTree cdef,
                                           TreeMaker make)
Translate a toplevel class and return a list consisting of the translated class and translated versions of all inner classes.

Parameters:
env - The attribution environment current at the class definition. We need this for resolving some additional symbols.
cdef - The tree representing the class definition.

addEnumCompatibleMembers

private void addEnumCompatibleMembers(JCTree.JCClassDecl cdef)

addEnumOrdinalField

private Symbol.VarSymbol addEnumOrdinalField(JCTree.JCClassDecl cdef)

addEnumNameField

private Symbol.VarSymbol addEnumNameField(JCTree.JCClassDecl cdef)

addEnumFieldOrdinalMethod

private Symbol.MethodSymbol addEnumFieldOrdinalMethod(JCTree.JCClassDecl cdef,
                                                      Symbol.VarSymbol ordinalSymbol)

addEnumFieldNameMethod

private Symbol.MethodSymbol addEnumFieldNameMethod(JCTree.JCClassDecl cdef,
                                                   Symbol.VarSymbol nameSymbol)

addEnumToString

private Symbol.MethodSymbol addEnumToString(JCTree.JCClassDecl cdef,
                                            Symbol.VarSymbol nameSymbol)

addEnumCompareTo

private Symbol.MethodSymbol addEnumCompareTo(JCTree.JCClassDecl cdef,
                                             Symbol.VarSymbol ordinalSymbol)