src/share/classes/com/sun/tools/javac/code/Flags.java

Tue, 12 Mar 2013 16:02:43 +0000

author
mcimadamore
date
Tue, 12 Mar 2013 16:02:43 +0000
changeset 1628
5ddecb91d843
parent 1603
6118072811e5
child 1672
0d47e6131490
permissions
-rw-r--r--

8009545: Graph inference: dependencies between inference variables should be set during incorporation
Summary: Move all transitivity checks into the incorporation round
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 1999, 2013, Oracle and/or its affiliates. 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.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.javac.code;
    28 import java.util.Collections;
    29 import java.util.EnumSet;
    30 import java.util.Map;
    31 import java.util.Set;
    33 import javax.lang.model.element.Modifier;
    35 /** Access flags and other modifiers for Java classes and members.
    36  *
    37  *  <p><b>This is NOT part of any supported API.
    38  *  If you write code that depends on this, you do so at your own risk.
    39  *  This code and its internal interfaces are subject to change or
    40  *  deletion without notice.</b>
    41  */
    42 public class Flags {
    44     private Flags() {} // uninstantiable
    46     public static String toString(long flags) {
    47         StringBuilder buf = new StringBuilder();
    48         String sep = "";
    49         for (Flag s : asFlagSet(flags)) {
    50             buf.append(sep);
    51             buf.append(s);
    52             sep = " ";
    53         }
    54         return buf.toString();
    55     }
    57     public static EnumSet<Flag> asFlagSet(long mask) {
    58         EnumSet<Flag> flags = EnumSet.noneOf(Flag.class);
    59         if ((mask&PUBLIC) != 0) flags.add(Flag.PUBLIC);
    60         if ((mask&PRIVATE) != 0) flags.add(Flag.PRIVATE);
    61         if ((mask&PROTECTED) != 0) flags.add(Flag.PROTECTED);
    62         if ((mask&STATIC) != 0) flags.add(Flag.STATIC);
    63         if ((mask&FINAL) != 0) flags.add(Flag.FINAL);
    64         if ((mask&SYNCHRONIZED) != 0) flags.add(Flag.SYNCHRONIZED);
    65         if ((mask&VOLATILE) != 0) flags.add(Flag.VOLATILE);
    66         if ((mask&TRANSIENT) != 0) flags.add(Flag.TRANSIENT);
    67         if ((mask&NATIVE) != 0) flags.add(Flag.NATIVE);
    68         if ((mask&INTERFACE) != 0) flags.add(Flag.INTERFACE);
    69         if ((mask&ABSTRACT) != 0) flags.add(Flag.ABSTRACT);
    70         if ((mask&DEFAULT) != 0) flags.add(Flag.DEFAULT);
    71         if ((mask&STRICTFP) != 0) flags.add(Flag.STRICTFP);
    72         if ((mask&BRIDGE) != 0) flags.add(Flag.BRIDGE);
    73         if ((mask&SYNTHETIC) != 0) flags.add(Flag.SYNTHETIC);
    74         if ((mask&DEPRECATED) != 0) flags.add(Flag.DEPRECATED);
    75         if ((mask&HASINIT) != 0) flags.add(Flag.HASINIT);
    76         if ((mask&ENUM) != 0) flags.add(Flag.ENUM);
    77         if ((mask&MANDATED) != 0) flags.add(Flag.MANDATED);
    78         if ((mask&IPROXY) != 0) flags.add(Flag.IPROXY);
    79         if ((mask&NOOUTERTHIS) != 0) flags.add(Flag.NOOUTERTHIS);
    80         if ((mask&EXISTS) != 0) flags.add(Flag.EXISTS);
    81         if ((mask&COMPOUND) != 0) flags.add(Flag.COMPOUND);
    82         if ((mask&CLASS_SEEN) != 0) flags.add(Flag.CLASS_SEEN);
    83         if ((mask&SOURCE_SEEN) != 0) flags.add(Flag.SOURCE_SEEN);
    84         if ((mask&LOCKED) != 0) flags.add(Flag.LOCKED);
    85         if ((mask&UNATTRIBUTED) != 0) flags.add(Flag.UNATTRIBUTED);
    86         if ((mask&ANONCONSTR) != 0) flags.add(Flag.ANONCONSTR);
    87         if ((mask&ACYCLIC) != 0) flags.add(Flag.ACYCLIC);
    88         if ((mask&PARAMETER) != 0) flags.add(Flag.PARAMETER);
    89         if ((mask&VARARGS) != 0) flags.add(Flag.VARARGS);
    90         return flags;
    91     }
    93     /* Standard Java flags.
    94      */
    95     public static final int PUBLIC       = 1<<0;
    96     public static final int PRIVATE      = 1<<1;
    97     public static final int PROTECTED    = 1<<2;
    98     public static final int STATIC       = 1<<3;
    99     public static final int FINAL        = 1<<4;
   100     public static final int SYNCHRONIZED = 1<<5;
   101     public static final int VOLATILE     = 1<<6;
   102     public static final int TRANSIENT    = 1<<7;
   103     public static final int NATIVE       = 1<<8;
   104     public static final int INTERFACE    = 1<<9;
   105     public static final int ABSTRACT     = 1<<10;
   106     public static final int STRICTFP     = 1<<11;
   108     /* Flag that marks a symbol synthetic, added in classfile v49.0. */
   109     public static final int SYNTHETIC    = 1<<12;
   111     /** Flag that marks attribute interfaces, added in classfile v49.0. */
   112     public static final int ANNOTATION   = 1<<13;
   114     /** An enumeration type or an enumeration constant, added in
   115      *  classfile v49.0. */
   116     public static final int ENUM         = 1<<14;
   118     /** Added in SE8, represents constructs implicitly declared in source. */
   119     public static final int MANDATED     = 1<<15;
   121     public static final int StandardFlags = 0x0fff;
   122     public static final int ModifierFlags = StandardFlags & ~INTERFACE;
   124     // Because the following access flags are overloaded with other
   125     // bit positions, we translate them when reading and writing class
   126     // files into unique bits positions: ACC_SYNTHETIC <-> SYNTHETIC,
   127     // for example.
   128     public static final int ACC_SUPER    = 0x0020;
   129     public static final int ACC_BRIDGE   = 0x0040;
   130     public static final int ACC_VARARGS  = 0x0080;
   132     /*****************************************
   133      * Internal compiler flags (no bits in the lower 16).
   134      *****************************************/
   136     /** Flag is set if symbol is deprecated.
   137      */
   138     public static final int DEPRECATED   = 1<<17;
   140     /** Flag is set for a variable symbol if the variable's definition
   141      *  has an initializer part.
   142      */
   143     public static final int HASINIT          = 1<<18;
   145     /** Flag is set for compiler-generated anonymous method symbols
   146      *  that `own' an initializer block.
   147      */
   148     public static final int BLOCK            = 1<<20;
   150     /** Flag is set for compiler-generated abstract methods that implement
   151      *  an interface method (Miranda methods).
   152      */
   153     public static final int IPROXY           = 1<<21;
   155     /** Flag is set for nested classes that do not access instance members
   156      *  or `this' of an outer class and therefore don't need to be passed
   157      *  a this$n reference.  This flag is currently set only for anonymous
   158      *  classes in superclass constructor calls and only for pre 1.4 targets.
   159      *  todo: use this flag for optimizing away this$n parameters in
   160      *  other cases.
   161      */
   162     public static final int NOOUTERTHIS  = 1<<22;
   164     /** Flag is set for package symbols if a package has a member or
   165      *  directory and therefore exists.
   166      */
   167     public static final int EXISTS           = 1<<23;
   169     /** Flag is set for compiler-generated compound classes
   170      *  representing multiple variable bounds
   171      */
   172     public static final int COMPOUND     = 1<<24;
   174     /** Flag is set for class symbols if a class file was found for this class.
   175      */
   176     public static final int CLASS_SEEN   = 1<<25;
   178     /** Flag is set for class symbols if a source file was found for this
   179      *  class.
   180      */
   181     public static final int SOURCE_SEEN  = 1<<26;
   183     /* State flags (are reset during compilation).
   184      */
   186     /** Flag for class symbols is set and later re-set as a lock in
   187      *  Enter to detect cycles in the superclass/superinterface
   188      *  relations.  Similarly for constructor call cycle detection in
   189      *  Attr.
   190      */
   191     public static final int LOCKED           = 1<<27;
   193     /** Flag for class symbols is set and later re-set to indicate that a class
   194      *  has been entered but has not yet been attributed.
   195      */
   196     public static final int UNATTRIBUTED = 1<<28;
   198     /** Flag for synthesized default constructors of anonymous classes.
   199      */
   200     public static final int ANONCONSTR   = 1<<29;
   202     /** Flag for class symbols to indicate it has been checked and found
   203      *  acyclic.
   204      */
   205     public static final int ACYCLIC          = 1<<30;
   207     /** Flag that marks bridge methods.
   208      */
   209     public static final long BRIDGE          = 1L<<31;
   211     /** Flag that marks formal parameters.
   212      */
   213     public static final long PARAMETER   = 1L<<33;
   215     /** Flag that marks varargs methods.
   216      */
   217     public static final long VARARGS   = 1L<<34;
   219     /** Flag for annotation type symbols to indicate it has been
   220      *  checked and found acyclic.
   221      */
   222     public static final long ACYCLIC_ANN      = 1L<<35;
   224     /** Flag that marks a generated default constructor.
   225      */
   226     public static final long GENERATEDCONSTR   = 1L<<36;
   228     /** Flag that marks a hypothetical method that need not really be
   229      *  generated in the binary, but is present in the symbol table to
   230      *  simplify checking for erasure clashes - also used for 292 poly sig methods.
   231      */
   232     public static final long HYPOTHETICAL   = 1L<<37;
   234     /**
   235      * Flag that marks an internal proprietary class.
   236      */
   237     public static final long PROPRIETARY = 1L<<38;
   239     /**
   240      * Flag that marks a multi-catch parameter.
   241      */
   242     public static final long UNION = 1L<<39;
   244     /**
   245      * Flag that marks a special kind of bridge method (the ones that
   246      * come from restricted supertype bounds).
   247      */
   248     public static final long OVERRIDE_BRIDGE = 1L<<40;
   250     /**
   251      * Flag that marks an 'effectively final' local variable.
   252      */
   253     public static final long EFFECTIVELY_FINAL = 1L<<41;
   255     /**
   256      * Flag that marks non-override equivalent methods with the same signature.
   257      */
   258     public static final long CLASH = 1L<<42;
   260     /**
   261      * Flag that marks either a default method or an interface containing default methods.
   262      */
   263     public static final long DEFAULT = 1L<<43;
   265     /**
   266      * Flag that marks class as auxiliary, ie a non-public class following
   267      * the public class in a source file, that could block implicit compilation.
   268      */
   269     public static final long AUXILIARY = 1L<<44;
   271     /**
   272      * Flag that marks that a symbol is not available in the current profile
   273      */
   274     public static final long NOT_IN_PROFILE = 1L<<45;
   276     /**
   277      * Flag that indicates that an override error has been detected by Check.
   278      */
   279     public static final long BAD_OVERRIDE = 1L<<45;
   281     /** Modifier masks.
   282      */
   283     public static final int
   284         AccessFlags           = PUBLIC | PROTECTED | PRIVATE,
   285         LocalClassFlags       = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC,
   286         MemberClassFlags      = LocalClassFlags | INTERFACE | AccessFlags,
   287         ClassFlags            = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
   288         InterfaceVarFlags     = FINAL | STATIC | PUBLIC,
   289         VarFlags              = AccessFlags | FINAL | STATIC |
   290                                 VOLATILE | TRANSIENT | ENUM,
   291         ConstructorFlags      = AccessFlags,
   292         InterfaceMethodFlags  = ABSTRACT | PUBLIC,
   293         MethodFlags           = AccessFlags | ABSTRACT | STATIC | NATIVE |
   294                                 SYNCHRONIZED | FINAL | STRICTFP;
   295     public static final long
   296         ExtendedStandardFlags       = (long)StandardFlags | DEFAULT,
   297         InterfaceMethodMask         = ABSTRACT | STATIC | PUBLIC | STRICTFP | DEFAULT,
   298         LocalVarFlags               = FINAL | PARAMETER;
   301     public static Set<Modifier> asModifierSet(long flags) {
   302         Set<Modifier> modifiers = modifierSets.get(flags);
   303         if (modifiers == null) {
   304             modifiers = java.util.EnumSet.noneOf(Modifier.class);
   305             if (0 != (flags & PUBLIC))    modifiers.add(Modifier.PUBLIC);
   306             if (0 != (flags & PROTECTED)) modifiers.add(Modifier.PROTECTED);
   307             if (0 != (flags & PRIVATE))   modifiers.add(Modifier.PRIVATE);
   308             if (0 != (flags & ABSTRACT))  modifiers.add(Modifier.ABSTRACT);
   309             if (0 != (flags & STATIC))    modifiers.add(Modifier.STATIC);
   310             if (0 != (flags & FINAL))     modifiers.add(Modifier.FINAL);
   311             if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT);
   312             if (0 != (flags & VOLATILE))  modifiers.add(Modifier.VOLATILE);
   313             if (0 != (flags & SYNCHRONIZED))
   314                                           modifiers.add(Modifier.SYNCHRONIZED);
   315             if (0 != (flags & NATIVE))    modifiers.add(Modifier.NATIVE);
   316             if (0 != (flags & STRICTFP))  modifiers.add(Modifier.STRICTFP);
   317             modifiers = Collections.unmodifiableSet(modifiers);
   318             modifierSets.put(flags, modifiers);
   319         }
   320         return modifiers;
   321     }
   323     // Cache of modifier sets.
   324     private static final Map<Long, Set<Modifier>> modifierSets =
   325         new java.util.concurrent.ConcurrentHashMap<Long, Set<Modifier>>(64);
   327     public static boolean isStatic(Symbol symbol) {
   328         return (symbol.flags() & STATIC) != 0;
   329     }
   331     public static boolean isEnum(Symbol symbol) {
   332         return (symbol.flags() & ENUM) != 0;
   333     }
   335     public static boolean isConstant(Symbol.VarSymbol symbol) {
   336         return symbol.getConstValue() != null;
   337     }
   339     public enum Flag {
   341         PUBLIC("public"),
   342         PRIVATE("private"),
   343         PROTECTED("protected"),
   344         STATIC("static"),
   345         FINAL("final"),
   346         SYNCHRONIZED("synchronized"),
   347         VOLATILE("volatile"),
   348         TRANSIENT("transient"),
   349         NATIVE("native"),
   350         INTERFACE("interface"),
   351         ABSTRACT("abstract"),
   352         DEFAULT("default"),
   353         STRICTFP("strictfp"),
   354         BRIDGE("bridge"),
   355         SYNTHETIC("synthetic"),
   356         DEPRECATED("deprecated"),
   357         HASINIT("hasinit"),
   358         ENUM("enum"),
   359         MANDATED("mandated"),
   360         IPROXY("iproxy"),
   361         NOOUTERTHIS("noouterthis"),
   362         EXISTS("exists"),
   363         COMPOUND("compound"),
   364         CLASS_SEEN("class_seen"),
   365         SOURCE_SEEN("source_seen"),
   366         LOCKED("locked"),
   367         UNATTRIBUTED("unattributed"),
   368         ANONCONSTR("anonconstr"),
   369         ACYCLIC("acyclic"),
   370         PARAMETER("parameter"),
   371         VARARGS("varargs"),
   372         PACKAGE("package");
   374         private final String name;
   376         Flag(String name) {
   377             this.name = name;
   378         }
   380         public String toString() {
   381             return name;
   382         }
   383     }
   384 }

mercurial