001    /*
002     * Copyright 1999-2008 Sun Microsystems, Inc.  All Rights Reserved.
003     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004     *
005     * This code is free software; you can redistribute it and/or modify it
006     * under the terms of the GNU General Public License version 2 only, as
007     * published by the Free Software Foundation.  Sun designates this
008     * particular file as subject to the "Classpath" exception as provided
009     * by Sun in the LICENSE file that accompanied this code.
010     *
011     * This code is distributed in the hope that it will be useful, but WITHOUT
012     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014     * version 2 for more details (a copy is included in the LICENSE file that
015     * accompanied this code).
016     *
017     * You should have received a copy of the GNU General Public License version
018     * 2 along with this work; if not, write to the Free Software Foundation,
019     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020     *
021     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022     * CA 95054 USA or visit www.sun.com if you need additional information or
023     * have any questions.
024     */
025    
026    package com.sun.tools.javac.comp;
027    
028    import com.sun.tools.javac.util.*;
029    import com.sun.tools.javac.code.*;
030    
031    /** Contains information specific to the attribute and enter
032     *  passes, to be used in place of the generic field in environments.
033     *
034     *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
035     *  you write code that depends on this, you do so at your own risk.
036     *  This code and its internal interfaces are subject to change or
037     *  deletion without notice.</b>
038     */
039    public class AttrContext {
040    
041        /** The scope of local symbols.
042         */
043        Scope scope = null;
044    
045        /** The number of enclosing `static' modifiers.
046         */
047        int staticLevel = 0;
048    
049        /** Is this an environment for a this(...) or super(...) call?
050         */
051        boolean isSelfCall = false;
052    
053        /** Are we evaluating the selector of a `super' or type name?
054         */
055        boolean selectSuper = false;
056    
057        /** Are arguments to current function applications boxed into an array for varargs?
058         */
059        boolean varArgs = false;
060    
061        /** A list of type variables that are all-quantifed in current context.
062         */
063        List<Type> tvars = List.nil();
064    
065        /** A record of the lint/SuppressWarnings currently in effect
066         */
067        Lint lint;
068    
069        /** The variable whose initializer is being attributed
070         * useful for detecting self-references in variable initializers
071         */
072        Symbol enclVar = null;
073    
074        /** Duplicate this context, replacing scope field and copying all others.
075         */
076        AttrContext dup(Scope scope) {
077            AttrContext info = new AttrContext();
078            info.scope = scope;
079            info.staticLevel = staticLevel;
080            info.isSelfCall = isSelfCall;
081            info.selectSuper = selectSuper;
082            info.varArgs = varArgs;
083            info.tvars = tvars;
084            info.lint = lint;
085            info.enclVar = enclVar;
086            return info;
087        }
088    
089        /** Duplicate this context, copying all fields.
090         */
091        AttrContext dup() {
092            return dup(scope);
093        }
094    
095        public Iterable<Symbol> getLocalElements() {
096            if (scope == null)
097                return List.nil();
098            return scope.getElements();
099        }
100    
101        public String toString() {
102            return "AttrContext[" + scope.toString() + "]";
103        }
104    }