< prev index next >

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

Print this page

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







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

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

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





















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



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

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      * Describe modifier flags as they migh appear in source code, i.e.,
395      * separated by spaces and in the order suggested by JLS 8.1.1.
396      */
397     public static String toSource(long flags) {
398         return asModifierSet(flags).stream()
399           .map(Modifier::toString)
400           .collect(Collectors.joining(" "));
401     }
402 
403     /** Modifier masks.
404      */
405     public static final int
406         AccessFlags                       = PUBLIC | PROTECTED | PRIVATE,
407         LocalClassFlags                   = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC,
408         StaticLocalFlags                  = LocalClassFlags | STATIC | INTERFACE,
409         MemberClassFlags                  = LocalClassFlags | INTERFACE | AccessFlags,
410         MemberStaticClassFlags            = MemberClassFlags | STATIC,
411         ClassFlags                        = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
412         InterfaceVarFlags                 = FINAL | STATIC | PUBLIC,
413         VarFlags                          = AccessFlags | FINAL | STATIC |
414                                             VOLATILE | TRANSIENT | ENUM,
415         ConstructorFlags                  = AccessFlags,
416         InterfaceMethodFlags              = ABSTRACT | PUBLIC,
417         MethodFlags                       = AccessFlags | ABSTRACT | STATIC | NATIVE |
418                                             SYNCHRONIZED | FINAL | STRICTFP,
419         RecordMethodFlags                 = AccessFlags | ABSTRACT | STATIC |
420                                             SYNCHRONIZED | FINAL | STRICTFP;

421     public static final long
422         ExtendedStandardFlags             = (long)StandardFlags | DEFAULT | SEALED | NON_SEALED,
423         ExtendedMemberClassFlags          = (long)MemberClassFlags | SEALED | NON_SEALED,
424         ExtendedMemberStaticClassFlags    = (long) MemberStaticClassFlags | SEALED | NON_SEALED,
425         ExtendedClassFlags                = (long)ClassFlags | SEALED | NON_SEALED,
426         ModifierFlags                     = ((long)StandardFlags & ~INTERFACE) | DEFAULT | SEALED | NON_SEALED,


427         InterfaceMethodMask               = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT,
428         AnnotationTypeElementMask         = ABSTRACT | PUBLIC,
429         LocalVarFlags                     = FINAL | PARAMETER,
430         ReceiverParamFlags                = PARAMETER;
431 
432     public static Set<Modifier> asModifierSet(long flags) {
433         Set<Modifier> modifiers = modifierSets.get(flags);
434         if (modifiers == null) {
435             modifiers = java.util.EnumSet.noneOf(Modifier.class);
436             if (0 != (flags & PUBLIC))    modifiers.add(Modifier.PUBLIC);
437             if (0 != (flags & PROTECTED)) modifiers.add(Modifier.PROTECTED);
438             if (0 != (flags & PRIVATE))   modifiers.add(Modifier.PRIVATE);
439             if (0 != (flags & ABSTRACT))  modifiers.add(Modifier.ABSTRACT);
440             if (0 != (flags & STATIC))    modifiers.add(Modifier.STATIC);
441             if (0 != (flags & SEALED))    modifiers.add(Modifier.SEALED);
442             if (0 != (flags & NON_SEALED))
443                                           modifiers.add(Modifier.NON_SEALED);
444             if (0 != (flags & FINAL))     modifiers.add(Modifier.FINAL);
445             if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT);
446             if (0 != (flags & VOLATILE))  modifiers.add(Modifier.VOLATILE);
447             if (0 != (flags & SYNCHRONIZED))
448                                           modifiers.add(Modifier.SYNCHRONIZED);
449             if (0 != (flags & NATIVE))    modifiers.add(Modifier.NATIVE);
450             if (0 != (flags & STRICTFP))  modifiers.add(Modifier.STRICTFP);
451             if (0 != (flags & DEFAULT))   modifiers.add(Modifier.DEFAULT);


452             modifiers = Collections.unmodifiableSet(modifiers);
453             modifierSets.put(flags, modifiers);
454         }
455         return modifiers;
456     }
457 
458     // Cache of modifier sets.
459     private static final Map<Long, Set<Modifier>> modifierSets = new ConcurrentHashMap<>(64);
460 
461     public static boolean isStatic(Symbol symbol) {
462         return (symbol.flags() & STATIC) != 0;
463     }
464 
465     public static boolean isEnum(Symbol symbol) {
466         return (symbol.flags() & ENUM) != 0;
467     }
468 
469     public static boolean isConstant(Symbol.VarSymbol symbol) {
470         return symbol.getConstValue() != null;
471     }

473 
474     public enum Flag {
475         PUBLIC(Flags.PUBLIC),
476         PRIVATE(Flags.PRIVATE),
477         PROTECTED(Flags.PROTECTED),
478         STATIC(Flags.STATIC),
479         FINAL(Flags.FINAL),
480         SYNCHRONIZED(Flags.SYNCHRONIZED),
481         VOLATILE(Flags.VOLATILE),
482         TRANSIENT(Flags.TRANSIENT),
483         NATIVE(Flags.NATIVE),
484         INTERFACE(Flags.INTERFACE),
485         ABSTRACT(Flags.ABSTRACT),
486         DEFAULT(Flags.DEFAULT),
487         STRICTFP(Flags.STRICTFP),
488         BRIDGE(Flags.BRIDGE),
489         SYNTHETIC(Flags.SYNTHETIC),
490         ANNOTATION(Flags.ANNOTATION),
491         DEPRECATED(Flags.DEPRECATED),
492         HASINIT(Flags.HASINIT),








493         BLOCK(Flags.BLOCK),
494         FROM_SOURCE(Flags.FROM_SOURCE),
495         ENUM(Flags.ENUM),
496         MANDATED(Flags.MANDATED),


497         NOOUTERTHIS(Flags.NOOUTERTHIS),
498         EXISTS(Flags.EXISTS),
499         COMPOUND(Flags.COMPOUND),
500         CLASS_SEEN(Flags.CLASS_SEEN),
501         SOURCE_SEEN(Flags.SOURCE_SEEN),
502         LOCKED(Flags.LOCKED),
503         UNATTRIBUTED(Flags.UNATTRIBUTED),
504         ANONCONSTR(Flags.ANONCONSTR),
505         ACYCLIC(Flags.ACYCLIC),
506         PARAMETER(Flags.PARAMETER),
507         VARARGS(Flags.VARARGS),
508         ACYCLIC_ANN(Flags.ACYCLIC_ANN),
509         GENERATEDCONSTR(Flags.GENERATEDCONSTR),
510         HYPOTHETICAL(Flags.HYPOTHETICAL),
511         PROPRIETARY(Flags.PROPRIETARY),
512         UNION(Flags.UNION),
513         EFFECTIVELY_FINAL(Flags.EFFECTIVELY_FINAL),
514         CLASH(Flags.CLASH),
515         AUXILIARY(Flags.AUXILIARY),
516         NOT_IN_PROFILE(Flags.NOT_IN_PROFILE),

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

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      * Describe modifier flags as they migh appear in source code, i.e.,
428      * separated by spaces and in the order suggested by JLS 8.1.1.
429      */
430     public static String toSource(long flags) {
431         return asModifierSet(flags).stream()
432           .map(Modifier::toString)
433           .collect(Collectors.joining(" "));
434     }
435 
436     /** Modifier masks.
437      */
438     public static final int
439         AccessFlags                       = PUBLIC | PROTECTED | PRIVATE,
440         LocalClassFlags                   = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC | ACC_IDENTITY,
441         StaticLocalClassFlags             = LocalClassFlags | STATIC | INTERFACE,
442         MemberClassFlags                  = LocalClassFlags | INTERFACE | AccessFlags,
443         MemberStaticClassFlags            = MemberClassFlags | STATIC,
444         ClassFlags                        = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
445         InterfaceVarFlags                 = FINAL | STATIC | PUBLIC,
446         VarFlags                          = AccessFlags | FINAL | STATIC |
447                                             VOLATILE | TRANSIENT | ENUM,
448         ConstructorFlags                  = AccessFlags,
449         InterfaceMethodFlags              = ABSTRACT | PUBLIC,
450         MethodFlags                       = AccessFlags | ABSTRACT | STATIC | NATIVE |
451                                             SYNCHRONIZED | FINAL | STRICTFP,
452         RecordMethodFlags                 = AccessFlags | ABSTRACT | STATIC |
453                                             SYNCHRONIZED | FINAL | STRICTFP,
454         AdjustedClassFlags                = ClassFlags | ACC_PRIMITIVE | ACC_VALUE;
455     public static final long
456         ExtendedStandardFlags             = (long)StandardFlags | DEFAULT | SEALED | NON_SEALED | PRIMITIVE_CLASS | VALUE_CLASS,
457         ExtendedMemberClassFlags          = (long)MemberClassFlags | SEALED | NON_SEALED | PRIMITIVE_CLASS | VALUE_CLASS,
458         ExtendedMemberStaticClassFlags    = (long) MemberStaticClassFlags | SEALED | NON_SEALED | PRIMITIVE_CLASS | VALUE_CLASS,
459         ExtendedClassFlags                = (long)ClassFlags | SEALED | NON_SEALED | PRIMITIVE_CLASS | VALUE_CLASS,
460         ExtendedLocalClassFlags           = (long) LocalClassFlags | PRIMITIVE_CLASS | VALUE_CLASS,
461         ExtendedStaticLocalClassFlags     = (long) StaticLocalClassFlags | PRIMITIVE_CLASS | VALUE_CLASS,
462         ModifierFlags                     = ((long)StandardFlags & ~INTERFACE) | DEFAULT | SEALED | NON_SEALED | PRIMITIVE_CLASS | VALUE_CLASS,
463         InterfaceMethodMask               = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT,
464         AnnotationTypeElementMask         = ABSTRACT | PUBLIC,
465         LocalVarFlags                     = FINAL | PARAMETER,
466         ReceiverParamFlags                = PARAMETER;
467 
468     public static Set<Modifier> asModifierSet(long flags) {
469         Set<Modifier> modifiers = modifierSets.get(flags);
470         if (modifiers == null) {
471             modifiers = java.util.EnumSet.noneOf(Modifier.class);
472             if (0 != (flags & PUBLIC))    modifiers.add(Modifier.PUBLIC);
473             if (0 != (flags & PROTECTED)) modifiers.add(Modifier.PROTECTED);
474             if (0 != (flags & PRIVATE))   modifiers.add(Modifier.PRIVATE);
475             if (0 != (flags & ABSTRACT))  modifiers.add(Modifier.ABSTRACT);
476             if (0 != (flags & STATIC))    modifiers.add(Modifier.STATIC);
477             if (0 != (flags & SEALED))    modifiers.add(Modifier.SEALED);
478             if (0 != (flags & NON_SEALED))
479                                           modifiers.add(Modifier.NON_SEALED);
480             if (0 != (flags & FINAL))     modifiers.add(Modifier.FINAL);
481             if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT);
482             if (0 != (flags & VOLATILE))  modifiers.add(Modifier.VOLATILE);
483             if (0 != (flags & SYNCHRONIZED))
484                                           modifiers.add(Modifier.SYNCHRONIZED);
485             if (0 != (flags & NATIVE))    modifiers.add(Modifier.NATIVE);
486             if (0 != (flags & STRICTFP))  modifiers.add(Modifier.STRICTFP);
487             if (0 != (flags & DEFAULT))   modifiers.add(Modifier.DEFAULT);
488             if (0 != (flags & PRIMITIVE_CLASS))     modifiers.add(Modifier.PRIMITIVE);
489             if (0 != (flags & VALUE_CLASS))     modifiers.add(Modifier.VALUE);
490             modifiers = Collections.unmodifiableSet(modifiers);
491             modifierSets.put(flags, modifiers);
492         }
493         return modifiers;
494     }
495 
496     // Cache of modifier sets.
497     private static final Map<Long, Set<Modifier>> modifierSets = new ConcurrentHashMap<>(64);
498 
499     public static boolean isStatic(Symbol symbol) {
500         return (symbol.flags() & STATIC) != 0;
501     }
502 
503     public static boolean isEnum(Symbol symbol) {
504         return (symbol.flags() & ENUM) != 0;
505     }
506 
507     public static boolean isConstant(Symbol.VarSymbol symbol) {
508         return symbol.getConstValue() != null;
509     }

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