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

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 104
5e89c4ca637c
child 554
9d9f26857129
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

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

mercurial