< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java

Print this page




  76 
  77     private final Names names;
  78     private final Log log;
  79     private final Symtab syms;
  80     private final Resolve rs;
  81     private final Operators operators;
  82     private final Check chk;
  83     private final Attr attr;
  84     private TreeMaker make;
  85     private DiagnosticPosition make_pos;
  86     private final ClassWriter writer;
  87     private final ConstFold cfolder;
  88     private final Target target;
  89     private final Source source;
  90     private final TypeEnvs typeEnvs;
  91     private final Name dollarAssertionsDisabled;
  92     private final Name classDollar;
  93     private final Name dollarCloseResource;
  94     private final Types types;
  95     private final boolean debugLower;

  96     private final PkgInfo pkginfoOpt;
  97 
  98     protected Lower(Context context) {
  99         context.put(lowerKey, this);
 100         names = Names.instance(context);
 101         log = Log.instance(context);
 102         syms = Symtab.instance(context);
 103         rs = Resolve.instance(context);
 104         operators = Operators.instance(context);
 105         chk = Check.instance(context);
 106         attr = Attr.instance(context);
 107         make = TreeMaker.instance(context);
 108         writer = ClassWriter.instance(context);
 109         cfolder = ConstFold.instance(context);
 110         target = Target.instance(context);
 111         source = Source.instance(context);
 112         typeEnvs = TypeEnvs.instance(context);
 113         dollarAssertionsDisabled = names.
 114             fromString(target.syntheticNameChar() + "assertionsDisabled");
 115         classDollar = names.
 116             fromString("class" + target.syntheticNameChar());
 117         dollarCloseResource = names.
 118             fromString(target.syntheticNameChar() + "closeResource");
 119 
 120         types = Types.instance(context);
 121         Options options = Options.instance(context);
 122         debugLower = options.isSet("debuglower");
 123         pkginfoOpt = PkgInfo.get(options);

 124     }
 125 
 126     /** The currently enclosing class.
 127      */
 128     ClassSymbol currentClass;
 129 
 130     /** A queue of all translated classes.
 131      */
 132     ListBuffer<JCTree> translated;
 133 
 134     /** Environment for symbol lookup, set by translateTopLevelClass.
 135      */
 136     Env<AttrContext> attrEnv;
 137 
 138     /** A hash table mapping syntax trees to their ending source positions.
 139      */
 140     EndPosTable endPosTable;
 141 
 142 /**************************************************************************
 143  * Global mappings


 989             enterSynthetic(tree.pos(), accessor, accOwner.members());
 990             accessors[acode] = accessor;
 991         }
 992         return accessor;
 993     }
 994 
 995     /** The qualifier to be used for accessing a symbol in an outer class.
 996      *  This is either C.sym or C.this.sym, depending on whether or not
 997      *  sym is static.
 998      *  @param sym   The accessed symbol.
 999      */
1000     JCExpression accessBase(DiagnosticPosition pos, Symbol sym) {
1001         return (sym.flags() & STATIC) != 0
1002             ? access(make.at(pos.getStartPosition()).QualIdent(sym.owner))
1003             : makeOwnerThis(pos, sym, true);
1004     }
1005 
1006     /** Do we need an access method to reference private symbol?
1007      */
1008     boolean needsPrivateAccess(Symbol sym) {



1009         if ((sym.flags() & PRIVATE) == 0 || sym.owner == currentClass) {
1010             return false;
1011         } else if (sym.name == names.init && sym.owner.isLocal()) {
1012             // private constructor in local class: relax protection
1013             sym.flags_field &= ~PRIVATE;
1014             return false;
1015         } else {
1016             return true;
1017         }
1018     }
1019 
1020     /** Do we need an access method to reference symbol in other package?
1021      */
1022     boolean needsProtectedAccess(Symbol sym, JCTree tree) {

1023         if ((sym.flags() & PROTECTED) == 0 ||
1024             sym.owner.owner == currentClass.owner || // fast special case
1025             sym.packge() == currentClass.packge())
1026             return false;
1027         if (!currentClass.isSubClass(sym.owner, types))
1028             return true;
1029         if ((sym.flags() & STATIC) != 0 ||
1030             !tree.hasTag(SELECT) ||
1031             TreeInfo.name(((JCFieldAccess) tree).selected) == names._super)
1032             return false;
1033         return !((JCFieldAccess) tree).selected.type.tsym.isSubClass(currentClass, types);
1034     }
1035 
1036     /** The class in which an access method for given symbol goes.
1037      *  @param sym        The access symbol
1038      *  @param protAccess Is access to a protected symbol in another
1039      *                    package?
1040      */
1041     ClassSymbol accessClass(Symbol sym, boolean protAccess, JCTree tree) {
1042         if (protAccess) {




  76 
  77     private final Names names;
  78     private final Log log;
  79     private final Symtab syms;
  80     private final Resolve rs;
  81     private final Operators operators;
  82     private final Check chk;
  83     private final Attr attr;
  84     private TreeMaker make;
  85     private DiagnosticPosition make_pos;
  86     private final ClassWriter writer;
  87     private final ConstFold cfolder;
  88     private final Target target;
  89     private final Source source;
  90     private final TypeEnvs typeEnvs;
  91     private final Name dollarAssertionsDisabled;
  92     private final Name classDollar;
  93     private final Name dollarCloseResource;
  94     private final Types types;
  95     private final boolean debugLower;
  96     private final boolean disableProtectedAccessors; // experimental
  97     private final PkgInfo pkginfoOpt;
  98 
  99     protected Lower(Context context) {
 100         context.put(lowerKey, this);
 101         names = Names.instance(context);
 102         log = Log.instance(context);
 103         syms = Symtab.instance(context);
 104         rs = Resolve.instance(context);
 105         operators = Operators.instance(context);
 106         chk = Check.instance(context);
 107         attr = Attr.instance(context);
 108         make = TreeMaker.instance(context);
 109         writer = ClassWriter.instance(context);
 110         cfolder = ConstFold.instance(context);
 111         target = Target.instance(context);
 112         source = Source.instance(context);
 113         typeEnvs = TypeEnvs.instance(context);
 114         dollarAssertionsDisabled = names.
 115             fromString(target.syntheticNameChar() + "assertionsDisabled");
 116         classDollar = names.
 117             fromString("class" + target.syntheticNameChar());
 118         dollarCloseResource = names.
 119             fromString(target.syntheticNameChar() + "closeResource");
 120 
 121         types = Types.instance(context);
 122         Options options = Options.instance(context);
 123         debugLower = options.isSet("debuglower");
 124         pkginfoOpt = PkgInfo.get(options);
 125         disableProtectedAccessors = options.isSet("disableProtectedAccessors");
 126     }
 127 
 128     /** The currently enclosing class.
 129      */
 130     ClassSymbol currentClass;
 131 
 132     /** A queue of all translated classes.
 133      */
 134     ListBuffer<JCTree> translated;
 135 
 136     /** Environment for symbol lookup, set by translateTopLevelClass.
 137      */
 138     Env<AttrContext> attrEnv;
 139 
 140     /** A hash table mapping syntax trees to their ending source positions.
 141      */
 142     EndPosTable endPosTable;
 143 
 144 /**************************************************************************
 145  * Global mappings


 991             enterSynthetic(tree.pos(), accessor, accOwner.members());
 992             accessors[acode] = accessor;
 993         }
 994         return accessor;
 995     }
 996 
 997     /** The qualifier to be used for accessing a symbol in an outer class.
 998      *  This is either C.sym or C.this.sym, depending on whether or not
 999      *  sym is static.
1000      *  @param sym   The accessed symbol.
1001      */
1002     JCExpression accessBase(DiagnosticPosition pos, Symbol sym) {
1003         return (sym.flags() & STATIC) != 0
1004             ? access(make.at(pos.getStartPosition()).QualIdent(sym.owner))
1005             : makeOwnerThis(pos, sym, true);
1006     }
1007 
1008     /** Do we need an access method to reference private symbol?
1009      */
1010     boolean needsPrivateAccess(Symbol sym) {
1011         if (target.hasNestmateAccess()) {
1012             return false;
1013         }
1014         if ((sym.flags() & PRIVATE) == 0 || sym.owner == currentClass) {
1015             return false;
1016         } else if (sym.name == names.init && sym.owner.isLocal()) {
1017             // private constructor in local class: relax protection
1018             sym.flags_field &= ~PRIVATE;
1019             return false;
1020         } else {
1021             return true;
1022         }
1023     }
1024 
1025     /** Do we need an access method to reference symbol in other package?
1026      */
1027     boolean needsProtectedAccess(Symbol sym, JCTree tree) {
1028         if (disableProtectedAccessors) return false;
1029         if ((sym.flags() & PROTECTED) == 0 ||
1030             sym.owner.owner == currentClass.owner || // fast special case
1031             sym.packge() == currentClass.packge())
1032             return false;
1033         if (!currentClass.isSubClass(sym.owner, types))
1034             return true;
1035         if ((sym.flags() & STATIC) != 0 ||
1036             !tree.hasTag(SELECT) ||
1037             TreeInfo.name(((JCFieldAccess) tree).selected) == names._super)
1038             return false;
1039         return !((JCFieldAccess) tree).selected.type.tsym.isSubClass(currentClass, types);
1040     }
1041 
1042     /** The class in which an access method for given symbol goes.
1043      *  @param sym        The access symbol
1044      *  @param protAccess Is access to a protected symbol in another
1045      *                    package?
1046      */
1047     ClassSymbol accessClass(Symbol sym, boolean protAccess, JCTree tree) {
1048         if (protAccess) {


< prev index next >