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

Mon, 15 Apr 2013 14:18:30 +0100

author
mcimadamore
date
Mon, 15 Apr 2013 14:18:30 +0100
changeset 1697
950e8ac120f0
parent 1409
33abf479f202
child 1917
2fbe77c38802
permissions
-rw-r--r--

8010923: Avoid redundant speculative attribution
Summary: Add optimization to avoid speculative attribution for certain argument expressions
Reviewed-by: jjg

duke@1 1 /*
jjg@1409 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javac.comp;
duke@1 27
duke@1 28 import com.sun.tools.javac.tree.*;
duke@1 29 import java.util.Iterator;
duke@1 30 import java.util.NoSuchElementException;
duke@1 31
duke@1 32 /** A class for environments, instances of which are passed as
duke@1 33 * arguments to tree visitors. Environments refer to important ancestors
duke@1 34 * of the subtree that's currently visited, such as the enclosing method,
duke@1 35 * the enclosing class, or the enclosing toplevel node. They also contain
duke@1 36 * a generic component, represented as a type parameter, to carry further
duke@1 37 * information specific to individual passes.
duke@1 38 *
jjg@581 39 * <p><b>This is NOT part of any supported API.
jjg@581 40 * If you write code that depends on this, you do so at your own risk.
duke@1 41 * This code and its internal interfaces are subject to change or
duke@1 42 * deletion without notice.</b>
duke@1 43 */
duke@1 44 public class Env<A> implements Iterable<Env<A>> {
duke@1 45
duke@1 46 /** The next enclosing environment.
duke@1 47 */
duke@1 48 public Env<A> next;
duke@1 49
duke@1 50 /** The environment enclosing the current class.
duke@1 51 */
duke@1 52 public Env<A> outer;
duke@1 53
duke@1 54 /** The tree with which this environment is associated.
duke@1 55 */
duke@1 56 public JCTree tree;
duke@1 57
duke@1 58 /** The enclosing toplevel tree.
duke@1 59 */
duke@1 60 public JCTree.JCCompilationUnit toplevel;
duke@1 61
duke@1 62 /** The next enclosing class definition.
duke@1 63 */
duke@1 64 public JCTree.JCClassDecl enclClass;
duke@1 65
duke@1 66 /** The next enclosing method definition.
duke@1 67 */
duke@1 68 public JCTree.JCMethodDecl enclMethod;
duke@1 69
duke@1 70 /** A generic field for further information.
duke@1 71 */
duke@1 72 public A info;
duke@1 73
duke@1 74 /** Is this an environment for evaluating a base clause?
duke@1 75 */
duke@1 76 public boolean baseClause = false;
duke@1 77
duke@1 78 /** Create an outermost environment for a given (toplevel)tree,
duke@1 79 * with a given info field.
duke@1 80 */
duke@1 81 public Env(JCTree tree, A info) {
duke@1 82 this.next = null;
duke@1 83 this.outer = null;
duke@1 84 this.tree = tree;
duke@1 85 this.toplevel = null;
duke@1 86 this.enclClass = null;
duke@1 87 this.enclMethod = null;
duke@1 88 this.info = info;
duke@1 89 }
duke@1 90
duke@1 91 /** Duplicate this environment, updating with given tree and info,
duke@1 92 * and copying all other fields.
duke@1 93 */
duke@1 94 public Env<A> dup(JCTree tree, A info) {
duke@1 95 return dupto(new Env<A>(tree, info));
duke@1 96 }
duke@1 97
duke@1 98 /** Duplicate this environment into a given Environment,
duke@1 99 * using its tree and info, and copying all other fields.
duke@1 100 */
duke@1 101 public Env<A> dupto(Env<A> that) {
duke@1 102 that.next = this;
duke@1 103 that.outer = this.outer;
duke@1 104 that.toplevel = this.toplevel;
duke@1 105 that.enclClass = this.enclClass;
duke@1 106 that.enclMethod = this.enclMethod;
duke@1 107 return that;
duke@1 108 }
duke@1 109
duke@1 110 /** Duplicate this environment, updating with given tree,
duke@1 111 * and copying all other fields.
duke@1 112 */
duke@1 113 public Env<A> dup(JCTree tree) {
duke@1 114 return dup(tree, this.info);
duke@1 115 }
duke@1 116
duke@1 117 /** Return closest enclosing environment which points to a tree with given tag.
duke@1 118 */
jjg@1127 119 public Env<A> enclosing(JCTree.Tag tag) {
duke@1 120 Env<A> env1 = this;
jjg@1127 121 while (env1 != null && !env1.tree.hasTag(tag)) env1 = env1.next;
duke@1 122 return env1;
duke@1 123 }
duke@1 124
jjg@1409 125 @Override
duke@1 126 public String toString() {
duke@1 127 return "Env[" + info + (outer == null ? "" : ",outer=" + outer) + "]";
duke@1 128 }
duke@1 129
duke@1 130 public Iterator<Env<A>> iterator() {
duke@1 131 return new Iterator<Env<A>>() {
duke@1 132 Env<A> next = Env.this;
duke@1 133 public boolean hasNext() {
duke@1 134 return next.outer != null;
duke@1 135 }
duke@1 136 public Env<A> next() {
duke@1 137 if (hasNext()) {
duke@1 138 Env<A> current = next;
duke@1 139 next = current.outer;
duke@1 140 return current;
duke@1 141 }
duke@1 142 throw new NoSuchElementException();
duke@1 143
duke@1 144 }
duke@1 145 public void remove() {
duke@1 146 throw new UnsupportedOperationException();
duke@1 147 }
duke@1 148 };
duke@1 149 }
duke@1 150 }

mercurial