< prev index next >

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

Print this page




 784         }
 785     };
 786 
 787     /** Look up a synthetic name in a given scope.
 788      *  @param s            The scope.
 789      *  @param name         The name.
 790      */
 791     private Symbol lookupSynthetic(Name name, Scope s) {
 792         Symbol sym = s.findFirst(name);
 793         return (sym==null || (sym.flags()&SYNTHETIC)==0) ? null : sym;
 794     }
 795 
 796     /** Look up a method in a given scope.
 797      */
 798     private MethodSymbol lookupMethod(DiagnosticPosition pos, Name name, Type qual, List<Type> args) {
 799         return rs.resolveInternalMethod(pos, attrEnv, qual, name, args, List.nil());
 800     }
 801 
 802     /** Anon inner classes are used as access constructor tags.
 803      * accessConstructorTag will use an existing anon class if one is available,
 804      * and synthethise a class (with makeEmptyClass) if one is not available.
 805      * However, there is a small possibility that an existing class will not
 806      * be generated as expected if it is inside a conditional with a constant
 807      * expression. If that is found to be the case, create an empty class tree here.
 808      */
 809     private void checkAccessConstructorTags() {
 810         for (List<ClassSymbol> l = accessConstrTags; l.nonEmpty(); l = l.tail) {
 811             ClassSymbol c = l.head;
 812             if (isTranslatedClassAvailable(c))
 813                 continue;
 814             // Create class definition tree.
 815             JCClassDecl cdec = makeEmptyClass(STATIC | SYNTHETIC,
 816                     c.outermostClass(), c.flatname, false);
 817             swapAccessConstructorTag(c, cdec.sym);
 818             translated.append(cdec);
 819         }
 820     }
 821     // where
 822     private boolean isTranslatedClassAvailable(ClassSymbol c) {
 823         for (JCTree tree: translated) {
 824             if (tree.hasTag(CLASSDEF)


1320      */
1321     JCTree accessDef(int pos, Symbol vsym, MethodSymbol accessor, int acode) {
1322 //      System.err.println("access " + vsym + " with " + accessor);//DEBUG
1323         currentClass = vsym.owner.enclClass();
1324         make.at(pos);
1325         JCMethodDecl md = make.MethodDef(accessor, null);
1326 
1327         // Find actual symbol
1328         Symbol sym = actualSymbols.get(vsym);
1329         if (sym == null) sym = vsym;
1330 
1331         JCExpression ref;           // The tree referencing the private symbol.
1332         List<JCExpression> args;    // Any additional arguments to be passed along.
1333         if ((sym.flags() & STATIC) != 0) {
1334             ref = make.Ident(sym);
1335             args = make.Idents(md.params);
1336         } else {
1337             JCExpression site = make.Ident(md.params.head);
1338             if (acode % 2 != 0) {
1339                 //odd access codes represent qualified super accesses - need to
1340                 //emit reference to the direct superclass, even if the refered
1341                 //member is from an indirect superclass (JLS 13.1)
1342                 site.setType(types.erasure(types.supertype(vsym.owner.enclClass().type)));
1343             }
1344             ref = make.Select(site, sym);
1345             args = make.Idents(md.params.tail);
1346         }
1347         JCStatement stat;          // The statement accessing the private symbol.
1348         if (sym.kind == VAR) {
1349             // Normalize out all odd access codes by taking floor modulo 2:
1350             int acode1 = acode - (acode & 1);
1351 
1352             JCExpression expr;      // The access method's return value.
1353             AccessCode aCode = AccessCode.getFromCode(acode1);
1354             switch (aCode) {
1355             case DEREF:
1356                 expr = ref;
1357                 break;
1358             case ASSIGN:
1359                 expr = make.Assign(ref, args.head);
1360                 break;




 784         }
 785     };
 786 
 787     /** Look up a synthetic name in a given scope.
 788      *  @param s            The scope.
 789      *  @param name         The name.
 790      */
 791     private Symbol lookupSynthetic(Name name, Scope s) {
 792         Symbol sym = s.findFirst(name);
 793         return (sym==null || (sym.flags()&SYNTHETIC)==0) ? null : sym;
 794     }
 795 
 796     /** Look up a method in a given scope.
 797      */
 798     private MethodSymbol lookupMethod(DiagnosticPosition pos, Name name, Type qual, List<Type> args) {
 799         return rs.resolveInternalMethod(pos, attrEnv, qual, name, args, List.nil());
 800     }
 801 
 802     /** Anon inner classes are used as access constructor tags.
 803      * accessConstructorTag will use an existing anon class if one is available,
 804      * and synthesize a class (with makeEmptyClass) if one is not available.
 805      * However, there is a small possibility that an existing class will not
 806      * be generated as expected if it is inside a conditional with a constant
 807      * expression. If that is found to be the case, create an empty class tree here.
 808      */
 809     private void checkAccessConstructorTags() {
 810         for (List<ClassSymbol> l = accessConstrTags; l.nonEmpty(); l = l.tail) {
 811             ClassSymbol c = l.head;
 812             if (isTranslatedClassAvailable(c))
 813                 continue;
 814             // Create class definition tree.
 815             JCClassDecl cdec = makeEmptyClass(STATIC | SYNTHETIC,
 816                     c.outermostClass(), c.flatname, false);
 817             swapAccessConstructorTag(c, cdec.sym);
 818             translated.append(cdec);
 819         }
 820     }
 821     // where
 822     private boolean isTranslatedClassAvailable(ClassSymbol c) {
 823         for (JCTree tree: translated) {
 824             if (tree.hasTag(CLASSDEF)


1320      */
1321     JCTree accessDef(int pos, Symbol vsym, MethodSymbol accessor, int acode) {
1322 //      System.err.println("access " + vsym + " with " + accessor);//DEBUG
1323         currentClass = vsym.owner.enclClass();
1324         make.at(pos);
1325         JCMethodDecl md = make.MethodDef(accessor, null);
1326 
1327         // Find actual symbol
1328         Symbol sym = actualSymbols.get(vsym);
1329         if (sym == null) sym = vsym;
1330 
1331         JCExpression ref;           // The tree referencing the private symbol.
1332         List<JCExpression> args;    // Any additional arguments to be passed along.
1333         if ((sym.flags() & STATIC) != 0) {
1334             ref = make.Ident(sym);
1335             args = make.Idents(md.params);
1336         } else {
1337             JCExpression site = make.Ident(md.params.head);
1338             if (acode % 2 != 0) {
1339                 //odd access codes represent qualified super accesses - need to
1340                 //emit reference to the direct superclass, even if the referred
1341                 //member is from an indirect superclass (JLS 13.1)
1342                 site.setType(types.erasure(types.supertype(vsym.owner.enclClass().type)));
1343             }
1344             ref = make.Select(site, sym);
1345             args = make.Idents(md.params.tail);
1346         }
1347         JCStatement stat;          // The statement accessing the private symbol.
1348         if (sym.kind == VAR) {
1349             // Normalize out all odd access codes by taking floor modulo 2:
1350             int acode1 = acode - (acode & 1);
1351 
1352             JCExpression expr;      // The access method's return value.
1353             AccessCode aCode = AccessCode.getFromCode(acode1);
1354             switch (aCode) {
1355             case DEREF:
1356                 expr = ref;
1357                 break;
1358             case ASSIGN:
1359                 expr = make.Assign(ref, args.head);
1360                 break;


< prev index next >