< prev index next >

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

Print this page

 81     public static final int VOLATILE     = 1<<6;
 82     public static final int TRANSIENT    = 1<<7;
 83     public static final int NATIVE       = 1<<8;
 84     public static final int INTERFACE    = 1<<9;
 85     public static final int ABSTRACT     = 1<<10;
 86     public static final int STRICTFP     = 1<<11;
 87 
 88     /* Flag that marks a symbol synthetic, added in classfile v49.0. */
 89     public static final int SYNTHETIC    = 1<<12;
 90 
 91     /** Flag that marks attribute interfaces, added in classfile v49.0. */
 92     public static final int ANNOTATION   = 1<<13;
 93 
 94     /** An enumeration type or an enumeration constant, added in
 95      *  classfile v49.0. */
 96     public static final int ENUM         = 1<<14;
 97 
 98     /** Added in SE8, represents constructs implicitly declared in source. */
 99     public static final int MANDATED     = 1<<15;
100 







101     public static final int StandardFlags = 0x0fff;
102 
103     // Because the following access flags are overloaded with other
104     // bit positions, we translate them when reading and writing class
105     // files into unique bits positions: ACC_SYNTHETIC <-> SYNTHETIC,
106     // for example.
107     public static final int ACC_SUPER    = 0x0020;

108     public static final int ACC_BRIDGE   = 0x0040;
109     public static final int ACC_VARARGS  = 0x0080;

110     public static final int ACC_MODULE   = 0x8000;
111 
112     /*****************************************
113      * Internal compiler flags (no bits in the lower 16).
114      *****************************************/
115 
116     /** Flag is set if symbol is deprecated.  See also DEPRECATED_REMOVAL.
117      */
118     public static final int DEPRECATED   = 1<<17;
119 
120     /** Flag is set for a variable symbol if the variable's definition
121      *  has an initializer part.
122      */
123     public static final int HASINIT          = 1<<18;
124 





















125     /** Flag is set for compiler-generated anonymous method symbols
126      *  that `own' an initializer block.
127      */
128     public static final int BLOCK            = 1<<20;
129 



130     /** Flag is set for ClassSymbols that are being compiled from source.
131      */
132     public static final int FROM_SOURCE      = 1<<21; //ClassSymbols
133 
134     /** Flag is set for nested classes that do not access instance members
135      *  or `this' of an outer class and therefore don't need to be passed
136      *  a this$n reference.  This value is currently set only for anonymous
137      *  classes in superclass constructor calls.
138      *  todo: use this value for optimizing away this$n parameters in
139      *  other cases.
140      */
141     public static final int NOOUTERTHIS  = 1<<22;
142 
143     /** Flag is set for package symbols if a package has a member or
144      *  directory and therefore exists.
145      */
146     public static final int EXISTS           = 1<<23;
147 
148     /** Flag is set for compiler-generated compound classes
149      *  representing multiple variable bounds

378     /** Flag is set for compiler-generated record members, it could be applied to
379      *  accessors and fields
380      */
381     public static final int GENERATED_MEMBER = 1<<24; // MethodSymbols and VarSymbols
382 
383     /**
384      * Flag to indicate sealed class/interface declaration.
385      */
386     public static final long SEALED = 1L<<62; // ClassSymbols
387 
388     /**
389      * Flag to indicate that the class/interface was declared with the non-sealed modifier.
390      */
391     public static final long NON_SEALED = 1L<<63; // ClassSymbols
392 
393 
394     /** Modifier masks.
395      */
396     public static final int
397         AccessFlags                       = PUBLIC | PROTECTED | PRIVATE,
398         LocalClassFlags                   = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC,
399         StaticLocalFlags                  = LocalClassFlags | STATIC | INTERFACE,
400         MemberClassFlags                  = LocalClassFlags | INTERFACE | AccessFlags,
401         MemberStaticClassFlags            = MemberClassFlags | STATIC,
402         ClassFlags                        = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
403         InterfaceVarFlags                 = FINAL | STATIC | PUBLIC,
404         VarFlags                          = AccessFlags | FINAL | STATIC |
405                                             VOLATILE | TRANSIENT | ENUM,
406         ConstructorFlags                  = AccessFlags,
407         InterfaceMethodFlags              = ABSTRACT | PUBLIC,
408         MethodFlags                       = AccessFlags | ABSTRACT | STATIC | NATIVE |
409                                             SYNCHRONIZED | FINAL | STRICTFP,
410         RecordMethodFlags                 = AccessFlags | ABSTRACT | STATIC |
411                                             SYNCHRONIZED | FINAL | STRICTFP;

412     public static final long
413         ExtendedStandardFlags             = (long)StandardFlags | DEFAULT | SEALED | NON_SEALED,
414         ExtendedMemberClassFlags          = (long)MemberClassFlags | SEALED | NON_SEALED,
415         ExtendedMemberStaticClassFlags    = (long) MemberStaticClassFlags | SEALED | NON_SEALED,
416         ExtendedClassFlags                = (long)ClassFlags | SEALED | NON_SEALED,
417         ModifierFlags                     = ((long)StandardFlags & ~INTERFACE) | DEFAULT | SEALED | NON_SEALED,


418         InterfaceMethodMask               = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT,
419         AnnotationTypeElementMask         = ABSTRACT | PUBLIC,
420         LocalVarFlags                     = FINAL | PARAMETER,
421         ReceiverParamFlags                = PARAMETER;
422 
423     public static Set<Modifier> asModifierSet(long flags) {
424         Set<Modifier> modifiers = modifierSets.get(flags);
425         if (modifiers == null) {
426             modifiers = java.util.EnumSet.noneOf(Modifier.class);
427             if (0 != (flags & PUBLIC))    modifiers.add(Modifier.PUBLIC);
428             if (0 != (flags & PROTECTED)) modifiers.add(Modifier.PROTECTED);
429             if (0 != (flags & PRIVATE))   modifiers.add(Modifier.PRIVATE);
430             if (0 != (flags & ABSTRACT))  modifiers.add(Modifier.ABSTRACT);
431             if (0 != (flags & STATIC))    modifiers.add(Modifier.STATIC);
432             if (0 != (flags & SEALED))    modifiers.add(Modifier.SEALED);
433             if (0 != (flags & NON_SEALED))
434                                           modifiers.add(Modifier.NON_SEALED);
435             if (0 != (flags & FINAL))     modifiers.add(Modifier.FINAL);
436             if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT);
437             if (0 != (flags & VOLATILE))  modifiers.add(Modifier.VOLATILE);
438             if (0 != (flags & SYNCHRONIZED))
439                                           modifiers.add(Modifier.SYNCHRONIZED);
440             if (0 != (flags & NATIVE))    modifiers.add(Modifier.NATIVE);
441             if (0 != (flags & STRICTFP))  modifiers.add(Modifier.STRICTFP);
442             if (0 != (flags & DEFAULT))   modifiers.add(Modifier.DEFAULT);


443             modifiers = Collections.unmodifiableSet(modifiers);
444             modifierSets.put(flags, modifiers);
445         }
446         return modifiers;
447     }
448 
449     // Cache of modifier sets.
450     private static final Map<Long, Set<Modifier>> modifierSets = new ConcurrentHashMap<>(64);
451 
452     public static boolean isStatic(Symbol symbol) {
453         return (symbol.flags() & STATIC) != 0;
454     }
455 
456     public static boolean isEnum(Symbol symbol) {
457         return (symbol.flags() & ENUM) != 0;
458     }
459 
460     public static boolean isConstant(Symbol.VarSymbol symbol) {
461         return symbol.getConstValue() != null;
462     }

464 
465     public enum Flag {
466         PUBLIC(Flags.PUBLIC),
467         PRIVATE(Flags.PRIVATE),
468         PROTECTED(Flags.PROTECTED),
469         STATIC(Flags.STATIC),
470         FINAL(Flags.FINAL),
471         SYNCHRONIZED(Flags.SYNCHRONIZED),
472         VOLATILE(Flags.VOLATILE),
473         TRANSIENT(Flags.TRANSIENT),
474         NATIVE(Flags.NATIVE),
475         INTERFACE(Flags.INTERFACE),
476         ABSTRACT(Flags.ABSTRACT),
477         DEFAULT(Flags.DEFAULT),
478         STRICTFP(Flags.STRICTFP),
479         BRIDGE(Flags.BRIDGE),
480         SYNTHETIC(Flags.SYNTHETIC),
481         ANNOTATION(Flags.ANNOTATION),
482         DEPRECATED(Flags.DEPRECATED),
483         HASINIT(Flags.HASINIT),








484         BLOCK(Flags.BLOCK),
485         FROM_SOURCE(Flags.FROM_SOURCE),
486         ENUM(Flags.ENUM),
487         MANDATED(Flags.MANDATED),


488         NOOUTERTHIS(Flags.NOOUTERTHIS),
489         EXISTS(Flags.EXISTS),
490         COMPOUND(Flags.COMPOUND),
491         CLASS_SEEN(Flags.CLASS_SEEN),
492         SOURCE_SEEN(Flags.SOURCE_SEEN),
493         LOCKED(Flags.LOCKED),
494         UNATTRIBUTED(Flags.UNATTRIBUTED),
495         ANONCONSTR(Flags.ANONCONSTR),
496         ACYCLIC(Flags.ACYCLIC),
497         PARAMETER(Flags.PARAMETER),
498         VARARGS(Flags.VARARGS),
499         ACYCLIC_ANN(Flags.ACYCLIC_ANN),
500         GENERATEDCONSTR(Flags.GENERATEDCONSTR),
501         HYPOTHETICAL(Flags.HYPOTHETICAL),
502         PROPRIETARY(Flags.PROPRIETARY),
503         UNION(Flags.UNION),
504         EFFECTIVELY_FINAL(Flags.EFFECTIVELY_FINAL),
505         CLASH(Flags.CLASH),
506         AUXILIARY(Flags.AUXILIARY),
507         NOT_IN_PROFILE(Flags.NOT_IN_PROFILE),

 81     public static final int VOLATILE     = 1<<6;
 82     public static final int TRANSIENT    = 1<<7;
 83     public static final int NATIVE       = 1<<8;
 84     public static final int INTERFACE    = 1<<9;
 85     public static final int ABSTRACT     = 1<<10;
 86     public static final int STRICTFP     = 1<<11;
 87 
 88     /* Flag that marks a symbol synthetic, added in classfile v49.0. */
 89     public static final int SYNTHETIC    = 1<<12;
 90 
 91     /** Flag that marks attribute interfaces, added in classfile v49.0. */
 92     public static final int ANNOTATION   = 1<<13;
 93 
 94     /** An enumeration type or an enumeration constant, added in
 95      *  classfile v49.0. */
 96     public static final int ENUM         = 1<<14;
 97 
 98     /** Added in SE8, represents constructs implicitly declared in source. */
 99     public static final int MANDATED     = 1<<15;
100 
101     /** Marks a type as a primitive class. We can't reuse the class file encoding (ACC_PRIMITIVE)
102      * since the latter shares its value (0x800) with ACC_STRICT (javac speak: STRICT_FP) and while
103      * STRICT_FP is not a valid flag for a class in the class file level, javac's ASTs flag a class
104      * as being STRICT_FP so as to propagate the FP strictness to methods of the class thereby causing
105      * a clash */
106     public static final int PRIMITIVE_CLASS  = 1<<16;
107 
108     public static final int StandardFlags = 0x0fff;
109 
110     // Because the following access flags are overloaded with other
111     // bit positions, we translate them when reading and writing class
112     // files into unique bits positions: ACC_SYNTHETIC <-> SYNTHETIC,
113     // for example.
114     public static final int ACC_IDENTITY = 0x0020;
115     public static final int ACC_VALUE    = 0x0040;
116     public static final int ACC_BRIDGE   = 0x0040;
117     public static final int ACC_VARARGS  = 0x0080;
118     public static final int ACC_PRIMITIVE = 0x0800;
119     public static final int ACC_MODULE   = 0x8000;
120 
121     /*****************************************
122      * Internal compiler flags (no bits in the lower 16).
123      *****************************************/
124 
125     /** Flag is set if symbol is deprecated.  See also DEPRECATED_REMOVAL.
126      */
127     public static final int DEPRECATED   = 1<<17;
128 
129     /** Flag is set for a variable symbol if the variable's definition
130      *  has an initializer part.
131      */
132     public static final int HASINIT          = 1<<18;
133 
134     /** Flag is set for a class symbol if it defines one or more non-empty
135      *  instance initializer block(s). This is relevenat only for class symbols
136      *  that originate from source types. For binary types the instance initializer
137      *  blocks are "normalized" into the constructors.
138      */
139     public static final int HASINITBLOCK         = 1<<18;
140 
141     /** Flag is set for a method symbol if it is an empty no-arg ctor.
142      *  i.e. one that simply returns (jlO) or merely chains to a super's
143      *  no-arg ctor
144      */
145     public static final int EMPTYNOARGCONSTR         = 1<<18;
146 
147     /** Flag is set for a class or interface whose instances have identity
148      * i.e. class/interface declarations that are expressly declared with
149      * the modifier `identity' or (b) any concrete class not declared with the
150      * modifier `value' (c) abstract class not declared `value' but meets various
151      * stipulations (d) older class files with ACC_SUPER bit set
152      */
153     public static final int IDENTITY_TYPE            = 1<<19;
154 
155     /** Flag is set for compiler-generated anonymous method symbols
156      *  that `own' an initializer block.
157      */
158     public static final int BLOCK            = 1<<20;
159 
160     /** Marks a type as a value class */
161     public static final int VALUE_CLASS      = 1<<20;
162 
163     /** Flag is set for ClassSymbols that are being compiled from source.
164      */
165     public static final int FROM_SOURCE      = 1<<21; //ClassSymbols
166 
167     /** Flag is set for nested classes that do not access instance members
168      *  or `this' of an outer class and therefore don't need to be passed
169      *  a this$n reference.  This value is currently set only for anonymous
170      *  classes in superclass constructor calls.
171      *  todo: use this value for optimizing away this$n parameters in
172      *  other cases.
173      */
174     public static final int NOOUTERTHIS  = 1<<22;
175 
176     /** Flag is set for package symbols if a package has a member or
177      *  directory and therefore exists.
178      */
179     public static final int EXISTS           = 1<<23;
180 
181     /** Flag is set for compiler-generated compound classes
182      *  representing multiple variable bounds

411     /** Flag is set for compiler-generated record members, it could be applied to
412      *  accessors and fields
413      */
414     public static final int GENERATED_MEMBER = 1<<24; // MethodSymbols and VarSymbols
415 
416     /**
417      * Flag to indicate sealed class/interface declaration.
418      */
419     public static final long SEALED = 1L<<62; // ClassSymbols
420 
421     /**
422      * Flag to indicate that the class/interface was declared with the non-sealed modifier.
423      */
424     public static final long NON_SEALED = 1L<<63; // ClassSymbols
425 
426 
427     /** Modifier masks.
428      */
429     public static final int
430         AccessFlags                       = PUBLIC | PROTECTED | PRIVATE,
431         LocalClassFlags                   = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC | ACC_IDENTITY,
432         StaticLocalClassFlags             = LocalClassFlags | STATIC | INTERFACE,
433         MemberClassFlags                  = LocalClassFlags | INTERFACE | AccessFlags,
434         MemberStaticClassFlags            = MemberClassFlags | STATIC,
435         ClassFlags                        = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
436         InterfaceVarFlags                 = FINAL | STATIC | PUBLIC,
437         VarFlags                          = AccessFlags | FINAL | STATIC |
438                                             VOLATILE | TRANSIENT | ENUM,
439         ConstructorFlags                  = AccessFlags,
440         InterfaceMethodFlags              = ABSTRACT | PUBLIC,
441         MethodFlags                       = AccessFlags | ABSTRACT | STATIC | NATIVE |
442                                             SYNCHRONIZED | FINAL | STRICTFP,
443         RecordMethodFlags                 = AccessFlags | ABSTRACT | STATIC |
444                                             SYNCHRONIZED | FINAL | STRICTFP,
445         AdjustedClassFlags                = ClassFlags | ACC_PRIMITIVE | ACC_VALUE;
446     public static final long
447         ExtendedStandardFlags             = (long)StandardFlags | DEFAULT | SEALED | NON_SEALED | PRIMITIVE_CLASS | VALUE_CLASS,
448         ExtendedMemberClassFlags          = (long)MemberClassFlags | SEALED | NON_SEALED | PRIMITIVE_CLASS | VALUE_CLASS,
449         ExtendedMemberStaticClassFlags    = (long) MemberStaticClassFlags | SEALED | NON_SEALED | PRIMITIVE_CLASS | VALUE_CLASS,
450         ExtendedClassFlags                = (long)ClassFlags | SEALED | NON_SEALED | PRIMITIVE_CLASS | VALUE_CLASS,
451         ExtendedLocalClassFlags           = (long) LocalClassFlags | PRIMITIVE_CLASS | VALUE_CLASS,
452         ExtendedStaticLocalClassFlags     = (long) StaticLocalClassFlags | PRIMITIVE_CLASS | VALUE_CLASS,
453         ModifierFlags                     = ((long)StandardFlags & ~INTERFACE) | DEFAULT | SEALED | NON_SEALED | PRIMITIVE_CLASS | VALUE_CLASS,
454         InterfaceMethodMask               = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT,
455         AnnotationTypeElementMask         = ABSTRACT | PUBLIC,
456         LocalVarFlags                     = FINAL | PARAMETER,
457         ReceiverParamFlags                = PARAMETER;
458 
459     public static Set<Modifier> asModifierSet(long flags) {
460         Set<Modifier> modifiers = modifierSets.get(flags);
461         if (modifiers == null) {
462             modifiers = java.util.EnumSet.noneOf(Modifier.class);
463             if (0 != (flags & PUBLIC))    modifiers.add(Modifier.PUBLIC);
464             if (0 != (flags & PROTECTED)) modifiers.add(Modifier.PROTECTED);
465             if (0 != (flags & PRIVATE))   modifiers.add(Modifier.PRIVATE);
466             if (0 != (flags & ABSTRACT))  modifiers.add(Modifier.ABSTRACT);
467             if (0 != (flags & STATIC))    modifiers.add(Modifier.STATIC);
468             if (0 != (flags & SEALED))    modifiers.add(Modifier.SEALED);
469             if (0 != (flags & NON_SEALED))
470                                           modifiers.add(Modifier.NON_SEALED);
471             if (0 != (flags & FINAL))     modifiers.add(Modifier.FINAL);
472             if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT);
473             if (0 != (flags & VOLATILE))  modifiers.add(Modifier.VOLATILE);
474             if (0 != (flags & SYNCHRONIZED))
475                                           modifiers.add(Modifier.SYNCHRONIZED);
476             if (0 != (flags & NATIVE))    modifiers.add(Modifier.NATIVE);
477             if (0 != (flags & STRICTFP))  modifiers.add(Modifier.STRICTFP);
478             if (0 != (flags & DEFAULT))   modifiers.add(Modifier.DEFAULT);
479             if (0 != (flags & PRIMITIVE_CLASS))     modifiers.add(Modifier.PRIMITIVE);
480             if (0 != (flags & VALUE_CLASS))     modifiers.add(Modifier.VALUE);
481             modifiers = Collections.unmodifiableSet(modifiers);
482             modifierSets.put(flags, modifiers);
483         }
484         return modifiers;
485     }
486 
487     // Cache of modifier sets.
488     private static final Map<Long, Set<Modifier>> modifierSets = new ConcurrentHashMap<>(64);
489 
490     public static boolean isStatic(Symbol symbol) {
491         return (symbol.flags() & STATIC) != 0;
492     }
493 
494     public static boolean isEnum(Symbol symbol) {
495         return (symbol.flags() & ENUM) != 0;
496     }
497 
498     public static boolean isConstant(Symbol.VarSymbol symbol) {
499         return symbol.getConstValue() != null;
500     }

502 
503     public enum Flag {
504         PUBLIC(Flags.PUBLIC),
505         PRIVATE(Flags.PRIVATE),
506         PROTECTED(Flags.PROTECTED),
507         STATIC(Flags.STATIC),
508         FINAL(Flags.FINAL),
509         SYNCHRONIZED(Flags.SYNCHRONIZED),
510         VOLATILE(Flags.VOLATILE),
511         TRANSIENT(Flags.TRANSIENT),
512         NATIVE(Flags.NATIVE),
513         INTERFACE(Flags.INTERFACE),
514         ABSTRACT(Flags.ABSTRACT),
515         DEFAULT(Flags.DEFAULT),
516         STRICTFP(Flags.STRICTFP),
517         BRIDGE(Flags.BRIDGE),
518         SYNTHETIC(Flags.SYNTHETIC),
519         ANNOTATION(Flags.ANNOTATION),
520         DEPRECATED(Flags.DEPRECATED),
521         HASINIT(Flags.HASINIT),
522         HASINITBLOCK(Flags.HASINITBLOCK),
523         EMPTYNOARGCONSTR(Flags.EMPTYNOARGCONSTR),
524         IDENTITY_TYPE(Flags.IDENTITY_TYPE) {
525             @Override
526             public String toString() {
527                 return "identity";
528             }
529         },
530         BLOCK(Flags.BLOCK),
531         FROM_SOURCE(Flags.FROM_SOURCE),
532         ENUM(Flags.ENUM),
533         MANDATED(Flags.MANDATED),
534         PRIMITIVE(Flags.PRIMITIVE_CLASS),
535         VALUE(Flags.VALUE_CLASS),
536         NOOUTERTHIS(Flags.NOOUTERTHIS),
537         EXISTS(Flags.EXISTS),
538         COMPOUND(Flags.COMPOUND),
539         CLASS_SEEN(Flags.CLASS_SEEN),
540         SOURCE_SEEN(Flags.SOURCE_SEEN),
541         LOCKED(Flags.LOCKED),
542         UNATTRIBUTED(Flags.UNATTRIBUTED),
543         ANONCONSTR(Flags.ANONCONSTR),
544         ACYCLIC(Flags.ACYCLIC),
545         PARAMETER(Flags.PARAMETER),
546         VARARGS(Flags.VARARGS),
547         ACYCLIC_ANN(Flags.ACYCLIC_ANN),
548         GENERATEDCONSTR(Flags.GENERATEDCONSTR),
549         HYPOTHETICAL(Flags.HYPOTHETICAL),
550         PROPRIETARY(Flags.PROPRIETARY),
551         UNION(Flags.UNION),
552         EFFECTIVELY_FINAL(Flags.EFFECTIVELY_FINAL),
553         CLASH(Flags.CLASH),
554         AUXILIARY(Flags.AUXILIARY),
555         NOT_IN_PROFILE(Flags.NOT_IN_PROFILE),
< prev index next >