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

Print this page




1802             do {
1803                 ots = ots.tail;
1804                 if (ots.isEmpty()) {
1805                     log.error(pos,
1806                         "no.encl.instance.of.type.in.scope",
1807                         c);
1808                     Assert.error();
1809                     return tree;
1810                 }
1811                 ot = ots.head;
1812             } while (ot.owner != otc);
1813             tree = access(make.at(pos).Select(tree, ot));
1814             otc = ot.type.tsym;
1815         }
1816         return tree;
1817     }
1818 
1819     /** Return tree simulating the assignment {@code this.name = name}, where
1820      *  name is the name of a free variable.
1821      */
1822     JCStatement initField(int pos, Name name) {
1823         Scope.Entry e = proxies.lookup(name);

1824         Symbol rhs = e.sym;
1825         Assert.check(rhs.owner.kind == MTH);
1826         Symbol lhs = e.next().sym;
1827         Assert.check(rhs.owner.owner == lhs.owner);
1828         make.at(pos);
1829         return
1830             make.Exec(
1831                 make.Assign(
1832                     make.Select(make.This(lhs.owner.erasure(types)), lhs),
1833                     make.Ident(rhs)).setType(lhs.erasure(types)));
1834     }
1835 
1836     /** Return tree simulating the assignment {@code this.this$n = this$n}.
1837      */
1838     JCStatement initOuterThis(int pos) {
1839         VarSymbol rhs = outerThisStack.head;
1840         Assert.check(rhs.owner.kind == MTH);
1841         VarSymbol lhs = outerThisStack.tail.head;
1842         Assert.check(rhs.owner.owner == lhs.owner);
1843         make.at(pos);


2696                 return;
2697             }
2698 
2699             // Add this$n (if needed) in front of and free variables behind
2700             // constructor parameter list.
2701             tree.params = tree.params.appendList(fvdefs);
2702             if (currentClass.hasOuterInstance())
2703                 tree.params = tree.params.prepend(otdef);
2704 
2705             // If this is an initial constructor, i.e., it does not start with
2706             // this(...), insert initializers for this$n and proxies
2707             // before (pre-1.4, after) the call to superclass constructor.
2708             JCStatement selfCall = translate(tree.body.stats.head);
2709 
2710             List<JCStatement> added = List.nil();
2711             if (fvs.nonEmpty()) {
2712                 List<Type> addedargtypes = List.nil();
2713                 for (List<VarSymbol> l = fvs; l.nonEmpty(); l = l.tail) {
2714                     if (TreeInfo.isInitialConstructor(tree))
2715                         added = added.prepend(
2716                             initField(tree.body.pos, proxyName(l.head.name)));
2717                     addedargtypes = addedargtypes.prepend(l.head.erasure(types));
2718                 }
2719                 Type olderasure = m.erasure(types);
2720                 m.erasure_field = new MethodType(
2721                     olderasure.getParameterTypes().appendList(addedargtypes),
2722                     olderasure.getReturnType(),
2723                     olderasure.getThrownTypes(),
2724                     syms.methodClass);
2725             }
2726             if (currentClass.hasOuterInstance() &&
2727                 TreeInfo.isInitialConstructor(tree))
2728             {
2729                 added = added.prepend(initOuterThis(tree.body.pos));
2730             }
2731 
2732             // pop local variables from proxy stack
2733             proxies = proxies.leave();
2734 
2735             // recursively translate following local statements and
2736             // combine with this- or super-call




1802             do {
1803                 ots = ots.tail;
1804                 if (ots.isEmpty()) {
1805                     log.error(pos,
1806                         "no.encl.instance.of.type.in.scope",
1807                         c);
1808                     Assert.error();
1809                     return tree;
1810                 }
1811                 ot = ots.head;
1812             } while (ot.owner != otc);
1813             tree = access(make.at(pos).Select(tree, ot));
1814             otc = ot.type.tsym;
1815         }
1816         return tree;
1817     }
1818 
1819     /** Return tree simulating the assignment {@code this.name = name}, where
1820      *  name is the name of a free variable.
1821      */
1822     JCStatement initField(MethodSymbol m, int pos, Name name) {
1823         Scope.Entry e = proxies.lookup(name);
1824         m.extraParams = m.extraParams.append((VarSymbol)e.sym);
1825         Symbol rhs = e.sym;
1826         Assert.check(rhs.owner.kind == MTH);
1827         Symbol lhs = e.next().sym;
1828         Assert.check(rhs.owner.owner == lhs.owner);
1829         make.at(pos);
1830         return
1831             make.Exec(
1832                 make.Assign(
1833                     make.Select(make.This(lhs.owner.erasure(types)), lhs),
1834                     make.Ident(rhs)).setType(lhs.erasure(types)));
1835     }
1836 
1837     /** Return tree simulating the assignment {@code this.this$n = this$n}.
1838      */
1839     JCStatement initOuterThis(int pos) {
1840         VarSymbol rhs = outerThisStack.head;
1841         Assert.check(rhs.owner.kind == MTH);
1842         VarSymbol lhs = outerThisStack.tail.head;
1843         Assert.check(rhs.owner.owner == lhs.owner);
1844         make.at(pos);


2697                 return;
2698             }
2699 
2700             // Add this$n (if needed) in front of and free variables behind
2701             // constructor parameter list.
2702             tree.params = tree.params.appendList(fvdefs);
2703             if (currentClass.hasOuterInstance())
2704                 tree.params = tree.params.prepend(otdef);
2705 
2706             // If this is an initial constructor, i.e., it does not start with
2707             // this(...), insert initializers for this$n and proxies
2708             // before (pre-1.4, after) the call to superclass constructor.
2709             JCStatement selfCall = translate(tree.body.stats.head);
2710 
2711             List<JCStatement> added = List.nil();
2712             if (fvs.nonEmpty()) {
2713                 List<Type> addedargtypes = List.nil();
2714                 for (List<VarSymbol> l = fvs; l.nonEmpty(); l = l.tail) {
2715                     if (TreeInfo.isInitialConstructor(tree))
2716                         added = added.prepend(
2717                           initField(m, tree.body.pos, proxyName(l.head.name)));
2718                     addedargtypes = addedargtypes.prepend(l.head.erasure(types));
2719                 }
2720                 Type olderasure = m.erasure(types);
2721                 m.erasure_field = new MethodType(
2722                     olderasure.getParameterTypes().appendList(addedargtypes),
2723                     olderasure.getReturnType(),
2724                     olderasure.getThrownTypes(),
2725                     syms.methodClass);
2726             }
2727             if (currentClass.hasOuterInstance() &&
2728                 TreeInfo.isInitialConstructor(tree))
2729             {
2730                 added = added.prepend(initOuterThis(tree.body.pos));
2731             }
2732 
2733             // pop local variables from proxy stack
2734             proxies = proxies.leave();
2735 
2736             // recursively translate following local statements and
2737             // combine with this- or super-call