2362N/A * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * WARNING: The contents of this source file are not part of any 0N/A * supported API. Code that depends on them does so at its own risk: 0N/A * they are subject to change or removal without notice. 0N/A private boolean isSuper;
// Set if qualified by 'super' or '<class>.super'. 0N/A // This is a hack used only within certain access methods generated by 0N/A // 'SourceClass.getAccessMember'. It allows an 'invokespecial' instruction 0N/A // to be forced even though 'super' does not appear within the call. 0N/A // Such access methods are needed for access to protected methods when using 0N/A // the qualified '<class>.super.<method>(...)' notation. 0N/A * Check expression type 0N/A // Access method to use if required. 0N/A // When calling a constructor, we may need to add an 0N/A // additional argument to transmit the outer instance link. 0N/A // the same error is handled elsewhere 0N/A // The effective accessing class, for access checking. 0N/A // This is normally the immediately enclosing class. 0N/A // Find the first outer scope that mentions the method. 0N/A // this is the scope for error diagnosis 0N/A // found the innermost scope in which m occurs 0N/A // Maybe an inherited method hides an apparent method. 0N/A // Keep looking at enclosing scopes to find out. 0N/A // As a consequence of the DA/DU rules in the JLS (draft of 0N/A // forthcoming 2e), all variables are both definitely assigned 0N/A // and definitely unassigned in unreachable code. Normally, this 0N/A // The use of the DA status of the 'this' variable for the extra 0N/A // check below on correct constructor usage, however, does not quite 0N/A // fit into this DA/DU scheme. The current representation of 0N/A // Vsets for unreachable dead-ends, does not allow 'clearVar' 0N/A // to work, as the DA/DU bits (all on) are implicitly represented 0N/A // by the fact that the Vset is a dead-end. The DA/DU status 0N/A // of the 'this' variable is supposed to be temporarily 0N/A // cleared at the beginning of a constructor and during the 0N/A // checking of constructor arguments (see below in this method). 0N/A // Since 'clearVar' has no effect on dead-ends, we may 0N/A // find the 'this' variable in an erroneously definitely-assigned state. 0N/A // As a workaround, we suppress the following error message when 0N/A // the Vset is a dead-end, i.e., when we are in unreachable code. 0N/A // Unfortunately, the special-case treatment of reachability for 0N/A // if-then and if-then-else allows unreachable code in some circumstances, 0N/A // thus it is possible that no error message will be emitted at all. 0N/A // While this behavior is strictly incorrect (thus we call this a 0N/A // workaround), the problematic code is indeed unreachable and will 0N/A // not be executed. In fact, it will be entirely omitted from the 0N/A // translated program, and can cause no harm at runtime. A correct 0N/A // solution would require modifying the representation of the DA/DU 0N/A // analysis to use finite Vsets only, restricting the universe 0N/A // of variables about which assertions are made (even in unreachable 0N/A // code) to variables that are actually in scope. Alternatively, the 0N/A // Vset extension and the dead-end marker (currently a reserved value 0N/A // of the extension) could be represented orthogonally. In either case, 0N/A // 'clearVar' could then be made to work on (non-canonical) dead ends. 0N/A // supers require this specific kind of checking 0N/A // Normally, the effective accessing class is the innermost 0N/A // class surrounding the current method call, but, for calls 0N/A // of the form '<class>.super.<method>(...)', it is <class>. 0N/A // This allows access to protected members of a superclass 0N/A // from within a class nested within one of its subclasses. 0N/A // Otherwise, for example, the call below to 'matchMethod' 0N/A // may fail due to the rules for visibility of inaccessible 0N/A // members. For consistency, we treat qualified 'this' in 0N/A // the same manner, as error diagnostics will be affected. 0N/A // QUERY: Are there subtle unexplored language issues here? 0N/A // Fix for 4158650. When we extend a protected inner 0N/A // class in a different package, we may not have access 0N/A // to the type of our superclass. Allow the call to 0N/A // the superclass constructor from within our constructor 0N/A // Note that this check does not apply to constructor 0N/A // calls in new instance expressions -- those are part 0N/A // of NewInstanceExpression#check(). 0N/A // Required by JLS 6.6.1. Fixes 4143715. 0N/A // (See also 4094658.) 0N/A // Compose a list of argument types 0N/A // "this" is not defined during argument checking 0N/A // "this" is defined after the constructor invocation 0N/A // Check if there are any type errors in the arguments 0N/A // Get the method field, given the argument types 0N/A // Make sure that static references are allowed 0N/A // Extension of JLS 6.6.2 for qualified 'super'. 0N/A // In <class>.super.<method>(), we cannot simply evaluate 0N/A // <class>.super to an object reference (as we would for 0N/A // <class>.super.<field>) and then perform an 'invokespecial'. 0N/A // An 'invokespecial' must be performed from within (a subclass of) 0N/A // the class in which the target method is located. 0N/A // The private case is handled below. 0N/A // Use an access method unless the effective accessing class 0N/A // (the class qualifying the 'super') is the same as the 0N/A // immediately enclosing class, i.e., the qualification was 0N/A // Access method for private field if not in the same class. 0N/A // Make sure that we are not invoking an abstract method 0N/A // Check for recursive constructor 0N/A // When a package-private class defines public or protected 0N/A // members, those members may sometimes be accessed from 0N/A // outside of the package in public subclasses. In these 0N/A // cases, we need to massage the method call to refer to 0N/A // to an accessible subclass rather than the package-private 0N/A // parent class. Part of fix for 4135692. 0N/A // Find out if the class which contains this method 0N/A // call has access to the class which declares the 0N/A // public or protected method referent. 0N/A // We don't perform this translation on constructor calls. 0N/A //System.out.println("The access of member " + 0N/A // field + " declared in class " + 0N/A // " is not allowed by the VM from class " + 0N/A // ". Replacing with an access of class " + 0N/A // We cannot make this access at the VM level. 0N/A // Construct a member which will stand for this 0N/A // method in clazz and set `field' to refer to it. 0N/A // Make sure it is qualified 0N/A // Argument was added above. 0N/A // Maintain the model for hidden outer args in outer.super(...): 0N/A // Need dummy argument for access method. 0N/A // Dummy argument follows outer instance link. 0N/A // Leave 'this.args' equal to 'newargs' but 0N/A // without the outer instance link. 0N/A // Strip outer instance link from 'this.args'. 0N/A // ASSERT(this.arg.length == nargs-1); 0N/A // No argument was added. 0N/A // Need dummy argument for access method. 0N/A // Dummy argument is first, as there is no outer instance link. 0N/A // Have ordinary method. 0N/A // Argument should have been added only for a constructor. 0N/A //System.out.println("Calling " + field + " via " + implMethod); 0N/A // Access method needs an explicit 'this' pointer. 0N/A // Follow super() by variable initializations 0N/A // Throw the declared exceptions. 0N/A /* Arrays pretend that they have "public Object clone()" that doesn't 0N/A * throw anything, according to the language spec. 0N/A /* See if there's a bogus catch for it, to issue a warning. */ 0N/A // Mark all blank finals as definitely assigned following 'this(...)'. 0N/A // Correctness follows inductively from the requirement that all blank finals 0N/A // be definitely assigned at the completion of every constructor. 0N/A // Static variables should also be considered defined as well, but this 0N/A // is handled in 'SourceClass.checkMembers', and we should not interfere. 0N/A * Check void expression 0N/A * We're about to report a "unmatched method" error. 0N/A * Try to issue a better diagnostic by comparing the actual argument types 0N/A * with the method (or methods) available. 0N/A * In particular, if there is an argument which fails to match <em>any</em> 0N/A * method, we report a type mismatch error against that particular argument. 0N/A * The diagnostic will report a target type taken from one of the methods. 0N/A * Return false if we couldn't think of anything smart to say. 0N/A // At least one argument is offensive to all overloadings. 0N/A // targetType is one of the argument types it does not match. 0N/A // The message might be slightly misleading, if there are other 0N/A // argument types that also would match. Hint at this: 0N/A //if (ambig) ttype = "{"+ttype+";...}"; 0N/A start = i+
1;
// look for other bad arguments, too 0N/A //System.out.print("BEFORE:"); s.print(System.out); System.out.println(); 0N/A // Note: If !valNeeded, then all returns in the body of the method 0N/A // change to void returns. 0N/A //System.out.print("COPY:"); body[body.length - 1].print(System.out); System.out.println(); 0N/A // Make sure the type matches what the return statements are returning. 0N/A // ctxClass is the current class trying to inline this method 0N/A // Don't inline if a qualified non-static method: the call 0N/A // itself might throw NullPointerException as a side effect 0N/A // We only allow the inlining if the current class can access 0N/A // the field, the field's class, and right's declared type. 0N/A // ctxClass is the current class trying to inline this method 0N/A // Don't inline if a qualified non-static method: the call 0N/A // itself might throw NullPointerException as a side effect 0N/A // We only allow the inlining if the current class can access 0N/A // the field, the field's class, and right's declared type. 0N/A // for now, don't allow calls to super() to be inlined. We may fix 0N/A * Grab all instance initializer code from the class definition, 0N/A * and return as one bolus. Note that we are assuming the 0N/A * the relevant fields have already been checked. 0N/A * (See the pre-pass in SourceClass.checkMembers which ensures this.) 0N/A // insert instance initializers 0N/A // it's too early to accumulate these 0N/A // append all initializers to "e": 0N/A // This section used to check for variables which were 0N/A // initialized to their default values and elide such 0N/A // initialization. This is specifically disallowed by 0N/A // JLS 12.5 numeral 4, which requires a textual ordering 0N/A // on the execution of initializers. 0N/A int i =
0;
// argument index 0N/A // 'super.<method>(...)', 'super(...)', or '<expr>.super(...)' 0N/A // 'super(...)' or '<expr>.super(...)' only 0N/A // When calling a constructor for a class with 0N/A // embedded uplevel references, add extra arguments. 0N/A // the extra arguments are inserted after this one 0N/A if (right.op == FIELD && 0N/A ((FieldExpression)right).id == idSuper) { 0N/A // '<class>.super.<method>(...)' 0N/A // 'super(...)' or '<expr>.super(...)' 0N/A // After calling a superclass constructor in a class with 0N/A // embedded uplevel references, initialize uplevel fields. 0N/A * Check if the first thing is a constructor invocation