Home » openjdk-7 » com.sun.tools » javac » comp » [javadoc | source]
com.sun.tools.javac.comp
public class: Lower [javadoc | source]
java.lang.Object
   com.sun.tools.javac.tree.JCTree.Visitor
      com.sun.tools.javac.tree.TreeTranslator
         com.sun.tools.javac.comp.Lower
This pass translates away some syntactic sugar: inner classes, class literals, assertions, foreach loops, etc.

This is NOT part of any supported API. 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:
class  Lower.ClassMap  A navigator class for assembling a mapping from local class symbols to class definition trees. There is only one case; all other cases simply traverse down the tree. 
class  Lower.FreeVarCollector  A navigator class for collecting the free variables accessed from a local class. There is only one case; all other cases simply traverse down the tree. 
class  Lower.EnumMapping  This map gives a translation table to be used for enum switches.

For each enum that appears as the type of a switch expression, we maintain an EnumMapping to assist in the translation, as exemplified by the following example:

we translate

         switch(colorExpression) {
         case red: stmt1;
         case green: stmt2;
         }
 
into
         switch(Outer$0.$EnumMap$Color[colorExpression.ordinal()]) {
         case 1: stmt1;
         case 2: stmt2
         }
 
with the auxiliary table initialized as follows:
         class Outer$0 {
             synthetic final int[] $EnumMap$Color = new int[Color.values().length];
             static {
                 try { $EnumMap$Color[red.ordinal()] = 1; } catch (NoSuchFieldError ex) {}
                 try { $EnumMap$Color[green.ordinal()] = 2; } catch (NoSuchFieldError ex) {}
             }
         }
 
class EnumMapping provides mapping data and support methods for this translation. 
interface  Lower.TreeBuilder  Building blocks for let expressions ************************************************************************ 
Field Summary
protected static final  Key<Lower> lowerKey     
 ClassSymbol currentClass    The currently enclosing class. 
 ListBuffer<JCTree> translated    A queue of all translated classes. 
 Env<AttrContext> attrEnv    Environment for symbol lookup, set by translateTopLevelClass. 
 Map<JCTree, Integer> endPositions    A hash table mapping syntax trees to their ending source positions. 
 Map<ClassSymbol, JCClassDecl> classdefs    A hash table mapping local classes to their definitions. 
 Map<Symbol, Symbol> actualSymbols    A hash table mapping virtual accessed symbols in outer subclasses to the actually referred symbol in superclasses. 
 JCMethodDecl currentMethodDef    The current method definition. 
 MethodSymbol currentMethodSym    The current method symbol. 
 JCClassDecl outermostClassDef    The currently enclosing outermost class definition. 
 JCTree outermostMemberDef    The currently enclosing outermost member definition. 
 ClassMap classMap     
 Map<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. 
 Map<TypeSymbol, EnumMapping> enumSwitchMap     
 Visitor conflictsChecker     
 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. 
 Scope twrVars    A scope containing all unnamed resource variables/saved exception variables for translated TWR blocks 
 List<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. 
Fields inherited from com.sun.tools.javac.tree.TreeTranslator:
result
Constructor:
 protected Lower(Context context) 
Method from com.sun.tools.javac.comp.Lower Summary:
abstractLval,   abstractRval,   abstractRval,   access,   access,   accessBase,   accessClass,   accessConstructor,   accessConstructorDef,   accessConstructorTag,   accessDef,   accessName,   accessSymbol,   boxArgs,   boxIfNeeded,   boxPrimitive,   boxPrimitive,   checkConflicts,   classDef,   classDollarSymBody,   freevarDefs,   freevars,   initField,   initOuterThis,   instance,   loadFreevar,   loadFreevars,   lowerBoxedPostop,   makeAccessible,   makeAssignop,   makeBinary,   makeComma,   makeEmptyClass,   makeLit,   makeNewClass,   makeNull,   makeOuterThis,   makeOwnerThis,   makeOwnerThisN,   makeString,   makeThis,   makeTwrTry,   makeUnary,   make_at,   mapForEnum,   needsPrivateAccess,   needsProtectedAccess,   outerThisDef,   outerThisName,   proxyName,   translate,   translate,   translate,   translate,   translate,   translateTopLevelClass,   unbox,   visitAnnotation,   visitApply,   visitAssert,   visitAssign,   visitAssignop,   visitBinary,   visitBlock,   visitClassDef,   visitConditional,   visitDoLoop,   visitEnumSwitch,   visitForLoop,   visitForeachLoop,   visitIdent,   visitIf,   visitIndexed,   visitLetExpr,   visitMethodDef,   visitNewArray,   visitNewClass,   visitParens,   visitReturn,   visitSelect,   visitStringSwitch,   visitSwitch,   visitTopLevel,   visitTry,   visitTypeCast,   visitUnary,   visitVarDef,   visitWhileLoop
Methods from com.sun.tools.javac.tree.TreeTranslator:
translate,   translate,   translateAnnotations,   translateCases,   translateCatchers,   translateTypeParams,   translateVarDefs,   visitAnnotation,   visitApply,   visitAssert,   visitAssign,   visitAssignop,   visitBinary,   visitBlock,   visitBreak,   visitCase,   visitCatch,   visitClassDef,   visitConditional,   visitContinue,   visitDoLoop,   visitErroneous,   visitExec,   visitForLoop,   visitForeachLoop,   visitIdent,   visitIf,   visitImport,   visitIndexed,   visitLabelled,   visitLetExpr,   visitLiteral,   visitMethodDef,   visitModifiers,   visitNewArray,   visitNewClass,   visitParens,   visitReturn,   visitSelect,   visitSkip,   visitSwitch,   visitSynchronized,   visitThrow,   visitTopLevel,   visitTree,   visitTry,   visitTypeApply,   visitTypeArray,   visitTypeBoundKind,   visitTypeCast,   visitTypeIdent,   visitTypeParameter,   visitTypeTest,   visitTypeUnion,   visitUnary,   visitVarDef,   visitWhileLoop,   visitWildcard
Methods from com.sun.tools.javac.tree.JCTree$Visitor:
visitAnnotation,   visitApply,   visitAssert,   visitAssign,   visitAssignop,   visitBinary,   visitBlock,   visitBreak,   visitCase,   visitCatch,   visitClassDef,   visitConditional,   visitContinue,   visitDoLoop,   visitErroneous,   visitExec,   visitForLoop,   visitForeachLoop,   visitIdent,   visitIf,   visitImport,   visitIndexed,   visitLabelled,   visitLetExpr,   visitLiteral,   visitMethodDef,   visitModifiers,   visitNewArray,   visitNewClass,   visitParens,   visitReturn,   visitSelect,   visitSkip,   visitSwitch,   visitSynchronized,   visitThrow,   visitTopLevel,   visitTree,   visitTry,   visitTypeApply,   visitTypeArray,   visitTypeBoundKind,   visitTypeCast,   visitTypeIdent,   visitTypeParameter,   visitTypeTest,   visitTypeUnion,   visitUnary,   visitVarDef,   visitWhileLoop,   visitWildcard
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.sun.tools.javac.comp.Lower Detail:
 JCTree abstractLval(JCTree lval,
    TreeBuilder builder) 
 JCTree abstractRval(JCTree rval,
    TreeBuilder builder) 
 JCTree abstractRval(JCTree rval,
    Type type,
    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.
 JCExpression access(JCExpression tree) 
    Ensure that identifier is accessible, return tree accessing the identifier.
 JCExpression access(Symbol sym,
    JCExpression tree,
    JCExpression enclOp,
    boolean refSuper) 
    Ensure that identifier is accessible, return tree accessing the identifier.
 JCExpression accessBase(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.
 ClassSymbol accessClass(Symbol sym,
    boolean protAccess,
    JCTree tree) 
    The class in which an access method for given symbol goes.
 Symbol accessConstructor(DiagnosticPosition pos,
    Symbol constr) 
    Return access constructor for a private constructor, or the constructor itself, if no access constructor is needed.
 JCTree accessConstructorDef(int pos,
    Symbol constr,
    MethodSymbol accessor) 
    Construct definition of an access constructor.
 ClassSymbol accessConstructorTag() 
    Return an anonymous class nested in this toplevel class.
 JCTree accessDef(int pos,
    Symbol vsym,
    MethodSymbol accessor,
    int acode) 
    Construct definition of an access method.
 Name accessName(int anum,
    int acode) 
    The name of the access method with number `anum' and access code `acode'.
 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.
 List<JCExpression> boxArgs(List<Type> parameters,
    List<JCExpression> _args,
    Type varargsElement) 
 T boxIfNeeded(T tree,
    Type type) 
    Expand a boxing or unboxing conversion if needed.
 JCExpression boxPrimitive(JCExpression tree) 
    Box up a single primitive expression.
 JCExpression boxPrimitive(JCExpression tree,
    Type box) 
    Box up a single primitive expression.
  void checkConflicts(List<JCTree> translatedTrees) 
    Check whether synthetic symbols generated during lowering conflict with user-defined symbols.
 JCClassDecl classDef(ClassSymbol c) 
    Map a class symbol to its definition.
 JCBlock classDollarSymBody(DiagnosticPosition pos,
    JCMethodDecl md) 
    Generate code for class$(String name).
 List<JCVariableDecl> freevarDefs(int pos,
    List<VarSymbol> freevars,
    Symbol owner) 
    Proxy definitions for all free variables in given list, in reverse order.
 List<VarSymbol> freevars(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).
 JCStatement initField(int pos,
    Name name) 
    Return tree simulating the assignment , where name is the name of a free variable.
 JCStatement initOuterThis(int pos) 
    Return tree simulating the assignment .
 public static Lower instance(Context context) 
 JCExpression loadFreevar(DiagnosticPosition pos,
    VarSymbol v) 
 List<JCExpression> loadFreevars(DiagnosticPosition pos,
    List<VarSymbol> freevars) 
    Return a list of trees that load the free variables in given list, in reverse order.
 JCTree lowerBoxedPostop(JCUnary tree) 
    Lower a tree of the form e++ or e-- where e is an object type
  void makeAccessible(Symbol sym) 
    Add all required access methods for a private symbol to enclosing class.
 JCAssignOp makeAssignop(int optag,
    JCTree lhs,
    JCTree rhs) 
    Make an attributed assignop expression.
 JCBinary makeBinary(int optag,
    JCExpression lhs,
    JCExpression rhs) 
    Make an attributed binary expression.
 JCTree makeComma(JCTree expr1,
    JCTree expr2) 
 ClassSymbol makeEmptyClass(long flags,
    ClassSymbol owner) 
    Create an empty anonymous class definition and enter and complete its symbol. Return the class definition's symbol. and create
 JCExpression makeLit(Type type,
    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.
 JCNewClass makeNewClass(Type ctype,
    List<JCExpression> args) 
    Make an attributed class instance creation expression.
 JCExpression makeNull() 
    Make an attributed tree representing null.
 JCExpression makeOuterThis(DiagnosticPosition pos,
    TypeSymbol c) 
    Construct a tree that represents the outer instance . Never pick the current `this'.
 JCExpression makeOwnerThis(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.
 JCExpression makeOwnerThisN(DiagnosticPosition pos,
    Symbol sym,
    boolean preciseMatch) 
    Similar to makeOwnerThis but will never pick "this".
 JCExpression makeString(JCExpression tree) 
    Convert tree into string object, unless it has already a reference type..
 JCExpression makeThis(DiagnosticPosition pos,
    TypeSymbol c) 
    Construct a tree simulating the expression .
 JCTree makeTwrTry(JCTry tree) 
    Optionally replace a try statement with the desugaring of a try-with-resources statement. The canonical desugaring of try ResourceSpecification Block is { final VariableModifiers_minus_final R #resource = Expression; Throwable #primaryException = null; try ResourceSpecificationtail Block catch (Throwable #t) { #primaryException = t; throw #t; } finally { if (#resource != null) { if (#primaryException != null) { try { #resource.close(); } catch(Throwable #suppressedException) { #primaryException.addSuppressed(#suppressedException); } } else { #resource.close(); } } }
 JCUnary makeUnary(int optag,
    JCExpression arg) 
    Make an attributed unary expression.
 TreeMaker make_at(DiagnosticPosition pos) 
    Equivalent to make.at(pos.getStartPosition()) with side effect of caching pos as make_pos, for use in diagnostics. *
 EnumMapping mapForEnum(DiagnosticPosition pos,
    TypeSymbol enumClass) 
 boolean needsPrivateAccess(Symbol sym) 
    Do we need an access method to reference private symbol?
 boolean needsProtectedAccess(Symbol sym,
    JCTree tree) 
    Do we need an access method to reference symbol in other package?
 JCVariableDecl outerThisDef(int pos,
    Symbol owner) 
    Definition for this$n field.
 Name outerThisName(Type type,
    Symbol owner) 
    The name of a this$n field
 Name proxyName(Name name) 
    The name of a free variable proxy.
 public T translate(T tree) 
    Visitor method: Translate a single node. Attach the source position from the old tree to its replacement tree.
 public T translate(T tree,
    Type type) 
    Visitor method: Translate a single node, boxing or unboxing if needed.
 public T translate(T tree,
    JCExpression enclOp) 
    Visitor method: Translate tree.
 public List<T> translate(List<T> trees,
    JCExpression enclOp) 
    Visitor method: Translate list of trees.
 public List<T> translate(List<T> trees,
    Type type) 
    Visitor method: Translate list of trees.
 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.
 JCExpression unbox(JCExpression tree,
    Type primitive) 
    Unbox an object to a primitive value.
 public  void visitAnnotation(JCAnnotation tree) 
 public  void visitApply(JCMethodInvocation tree) 
 public  void visitAssert(JCAssert tree) 
    Visitor method for assert statements. Translate them away.
 public  void visitAssign(JCAssign tree) 
 public  void visitAssignop(JCAssignOp tree) 
 public  void visitBinary(JCBinary tree) 
 public  void visitBlock(JCBlock tree) 
 public  void visitClassDef(JCClassDecl tree) 
 public  void visitConditional(JCConditional tree) 
    Visitor method for conditional expressions.
 public  void visitDoLoop(JCDoWhileLoop tree) 
 public JCTree visitEnumSwitch(JCSwitch tree) 
 public  void visitForLoop(JCForLoop tree) 
 public  void visitForeachLoop(JCEnhancedForLoop tree) 
    Translate away the foreach loop.
 public  void visitIdent(JCIdent tree) 
 public  void visitIf(JCIf tree) 
    Visitor method for if statements.
 public  void visitIndexed(JCArrayAccess tree) 
 public  void visitLetExpr(LetExpr tree) 
 public  void visitMethodDef(JCMethodDecl tree) 
 public  void visitNewArray(JCNewArray tree) 
 public  void visitNewClass(JCNewClass tree) 
 public  void visitParens(JCParens tree) 
    Visitor method for parenthesized expressions. If the subexpression has changed, omit the parens.
 public  void visitReturn(JCReturn tree) 
 public  void visitSelect(JCFieldAccess tree) 
 public JCTree visitStringSwitch(JCSwitch tree) 
 public  void visitSwitch(JCSwitch tree) 
 public  void visitTopLevel(JCCompilationUnit tree) 
 public  void visitTry(JCTry tree) 
 public  void visitTypeCast(JCTypeCast tree) 
 public  void visitUnary(JCUnary tree) 
 public  void visitVarDef(JCVariableDecl tree) 
 public  void visitWhileLoop(JCWhileLoop tree)