< 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 bit 21 is available. (used earlier to tag compiler-generated abstract methods that implement
131      *  an interface method (Miranda methods)).
132      */
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.

373     /**
374      * Flag to mark a record field that was not initialized in the compact constructor
375      */
376     public static final long UNINITIALIZED_FIELD= 1L<<51; // VarSymbols only
377 
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         ENUM(Flags.ENUM),
486         MANDATED(Flags.MANDATED),

487         NOOUTERTHIS(Flags.NOOUTERTHIS),
488         EXISTS(Flags.EXISTS),
489         COMPOUND(Flags.COMPOUND),
490         CLASS_SEEN(Flags.CLASS_SEEN),
491         SOURCE_SEEN(Flags.SOURCE_SEEN),
492         LOCKED(Flags.LOCKED),
493         UNATTRIBUTED(Flags.UNATTRIBUTED),
494         ANONCONSTR(Flags.ANONCONSTR),
495         ACYCLIC(Flags.ACYCLIC),
496         PARAMETER(Flags.PARAMETER),
497         VARARGS(Flags.VARARGS),
498         ACYCLIC_ANN(Flags.ACYCLIC_ANN),
499         GENERATEDCONSTR(Flags.GENERATEDCONSTR),
500         HYPOTHETICAL(Flags.HYPOTHETICAL),
501         PROPRIETARY(Flags.PROPRIETARY),
502         UNION(Flags.UNION),
503         EFFECTIVELY_FINAL(Flags.EFFECTIVELY_FINAL),
504         CLASH(Flags.CLASH),
505         AUXILIARY(Flags.AUXILIARY),
506         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 */
102     public static final int PRIMITIVE_CLASS  = 1<<16;
103 
104     public static final int StandardFlags = 0x0fff;
105 
106     // Because the following access flags are overloaded with other
107     // bit positions, we translate them when reading and writing class
108     // files into unique bits positions: ACC_SYNTHETIC <-> SYNTHETIC,
109     // for example.
110     public static final int ACC_SUPER    = 0x0020;
111     public static final int ACC_BRIDGE   = 0x0040;
112     public static final int ACC_VARARGS  = 0x0080;
113     public static final int ACC_PRIMITIVE = 0x0100;
114     public static final int ACC_MODULE   = 0x8000;
115 
116     /*****************************************
117      * Internal compiler flags (no bits in the lower 16).
118      *****************************************/
119 
120     /** Flag is set if symbol is deprecated.  See also DEPRECATED_REMOVAL.
121      */
122     public static final int DEPRECATED   = 1<<17;
123 
124     /** Flag is set for a variable symbol if the variable's definition
125      *  has an initializer part.
126      */
127     public static final int HASINIT          = 1<<18;
128 
129     /** Flag is set for a class symbol if it defines one or more non-empty
130      *  instance initializer block(s). This is relevenat only for class symbols
131      *  that originate from source types. For binary types the instance initializer
132      *  blocks are "normalized" into the constructors.
133      */
134     public static final int HASINITBLOCK         = 1<<18;
135 
136     /** Flag is set for a method symbol if it is an empty no-arg ctor.
137      *  i.e one that simply returns (jlO) or merely chains to a super's
138      *  EMPTYNOARGCONSTR
139      */
140     public static final int EMPTYNOARGCONSTR         = 1<<18;
141 
142     /**
143      * Flag is set for a reference favoring primitive class.
144      */
145     public static final int REFERENCE_FAVORING          = 1<<19;
146 
147     /** Flag is set for compiler-generated anonymous method symbols
148      *  that `own' an initializer block.
149      */
150     public static final int BLOCK            = 1<<20;
151 
152     /** Flag bit 21 is available. (used earlier to tag compiler-generated abstract methods that implement
153      *  an interface method (Miranda methods)).
154      */
155 
156     /** Flag is set for nested classes that do not access instance members
157      *  or `this' of an outer class and therefore don't need to be passed
158      *  a this$n reference.  This value is currently set only for anonymous
159      *  classes in superclass constructor calls.
160      *  todo: use this value for optimizing away this$n parameters in
161      *  other cases.
162      */
163     public static final int NOOUTERTHIS  = 1<<22;
164 
165     /** Flag is set for package symbols if a package has a member or
166      *  directory and therefore exists.

395     /**
396      * Flag to mark a record field that was not initialized in the compact constructor
397      */
398     public static final long UNINITIALIZED_FIELD= 1L<<51; // VarSymbols only
399 
400     /** Flag is set for compiler-generated record members, it could be applied to
401      *  accessors and fields
402      */
403     public static final int GENERATED_MEMBER = 1<<24; // MethodSymbols and VarSymbols
404 
405     /**
406      * Flag to indicate sealed class/interface declaration.
407      */
408     public static final long SEALED = 1L<<62; // ClassSymbols
409 
410     /**
411      * Flag to indicate that the class/interface was declared with the non-sealed modifier.
412      */
413     public static final long NON_SEALED = 1L<<63; // ClassSymbols
414 
415     // Encodings for extended flags stored using attributes
416     /**
417      * Flag to indicate that the primitive class is reference default.
418      */
419     public static final int ACC_REF_DEFAULT = 1;
420 
421     /** Modifier masks.
422      */
423     public static final int
424         AccessFlags                       = PUBLIC | PROTECTED | PRIVATE,
425         LocalClassFlags                   = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC  | PRIMITIVE_CLASS,
426         StaticLocalFlags                  = LocalClassFlags | STATIC | INTERFACE,
427         MemberClassFlags                  = LocalClassFlags | INTERFACE | AccessFlags,
428         MemberStaticClassFlags            = MemberClassFlags | STATIC,
429         ClassFlags                        = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
430         InterfaceVarFlags                 = FINAL | STATIC | PUBLIC,
431         VarFlags                          = AccessFlags | FINAL | STATIC |
432                                             VOLATILE | TRANSIENT | ENUM,
433         ConstructorFlags                  = AccessFlags,
434         InterfaceMethodFlags              = ABSTRACT | PUBLIC,
435         MethodFlags                       = AccessFlags | ABSTRACT | STATIC | NATIVE |
436                                             SYNCHRONIZED | FINAL | STRICTFP,
437         RecordMethodFlags                 = AccessFlags | ABSTRACT | STATIC |
438                                             SYNCHRONIZED | FINAL | STRICTFP;
439     public static final long
440         ExtendedStandardFlags             = (long)StandardFlags | DEFAULT | SEALED | NON_SEALED | PRIMITIVE_CLASS,
441         ExtendedMemberClassFlags          = (long)MemberClassFlags | SEALED | NON_SEALED,
442         ExtendedMemberStaticClassFlags    = (long) MemberStaticClassFlags | SEALED | NON_SEALED,
443         ExtendedClassFlags                = (long)ClassFlags | SEALED | NON_SEALED,
444         ModifierFlags                     = ((long)StandardFlags & ~INTERFACE) | DEFAULT | SEALED | NON_SEALED,
445         InterfaceMethodMask               = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT,
446         AnnotationTypeElementMask         = ABSTRACT | PUBLIC,
447         LocalVarFlags                     = FINAL | PARAMETER,
448         ReceiverParamFlags                = PARAMETER;
449 
450     public static Set<Modifier> asModifierSet(long flags) {
451         Set<Modifier> modifiers = modifierSets.get(flags);
452         if (modifiers == null) {
453             modifiers = java.util.EnumSet.noneOf(Modifier.class);
454             if (0 != (flags & PUBLIC))    modifiers.add(Modifier.PUBLIC);
455             if (0 != (flags & PROTECTED)) modifiers.add(Modifier.PROTECTED);
456             if (0 != (flags & PRIVATE))   modifiers.add(Modifier.PRIVATE);
457             if (0 != (flags & ABSTRACT))  modifiers.add(Modifier.ABSTRACT);
458             if (0 != (flags & STATIC))    modifiers.add(Modifier.STATIC);
459             if (0 != (flags & SEALED))    modifiers.add(Modifier.SEALED);
460             if (0 != (flags & NON_SEALED))
461                                           modifiers.add(Modifier.NON_SEALED);
462             if (0 != (flags & FINAL))     modifiers.add(Modifier.FINAL);
463             if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT);
464             if (0 != (flags & VOLATILE))  modifiers.add(Modifier.VOLATILE);
465             if (0 != (flags & SYNCHRONIZED))
466                                           modifiers.add(Modifier.SYNCHRONIZED);
467             if (0 != (flags & NATIVE))    modifiers.add(Modifier.NATIVE);
468             if (0 != (flags & STRICTFP))  modifiers.add(Modifier.STRICTFP);
469             if (0 != (flags & DEFAULT))   modifiers.add(Modifier.DEFAULT);
470             if (0 != (flags & PRIMITIVE_CLASS))     modifiers.add(Modifier.PRIMITIVE);
471             modifiers = Collections.unmodifiableSet(modifiers);
472             modifierSets.put(flags, modifiers);
473         }
474         return modifiers;
475     }
476 
477     // Cache of modifier sets.
478     private static final Map<Long, Set<Modifier>> modifierSets = new ConcurrentHashMap<>(64);
479 
480     public static boolean isStatic(Symbol symbol) {
481         return (symbol.flags() & STATIC) != 0;
482     }
483 
484     public static boolean isEnum(Symbol symbol) {
485         return (symbol.flags() & ENUM) != 0;
486     }
487 
488     public static boolean isConstant(Symbol.VarSymbol symbol) {
489         return symbol.getConstValue() != null;
490     }

492 
493     public enum Flag {
494         PUBLIC(Flags.PUBLIC),
495         PRIVATE(Flags.PRIVATE),
496         PROTECTED(Flags.PROTECTED),
497         STATIC(Flags.STATIC),
498         FINAL(Flags.FINAL),
499         SYNCHRONIZED(Flags.SYNCHRONIZED),
500         VOLATILE(Flags.VOLATILE),
501         TRANSIENT(Flags.TRANSIENT),
502         NATIVE(Flags.NATIVE),
503         INTERFACE(Flags.INTERFACE),
504         ABSTRACT(Flags.ABSTRACT),
505         DEFAULT(Flags.DEFAULT),
506         STRICTFP(Flags.STRICTFP),
507         BRIDGE(Flags.BRIDGE),
508         SYNTHETIC(Flags.SYNTHETIC),
509         ANNOTATION(Flags.ANNOTATION),
510         DEPRECATED(Flags.DEPRECATED),
511         HASINIT(Flags.HASINIT),
512         HASINITBLOCK(Flags.HASINITBLOCK),
513         EMPTYNOARGCONSTR(Flags.EMPTYNOARGCONSTR),
514         REFERENCE_FAVORING(Flags.REFERENCE_FAVORING),
515         BLOCK(Flags.BLOCK),
516         ENUM(Flags.ENUM),
517         MANDATED(Flags.MANDATED),
518         PRIMITIVE(Flags.PRIMITIVE_CLASS),
519         NOOUTERTHIS(Flags.NOOUTERTHIS),
520         EXISTS(Flags.EXISTS),
521         COMPOUND(Flags.COMPOUND),
522         CLASS_SEEN(Flags.CLASS_SEEN),
523         SOURCE_SEEN(Flags.SOURCE_SEEN),
524         LOCKED(Flags.LOCKED),
525         UNATTRIBUTED(Flags.UNATTRIBUTED),
526         ANONCONSTR(Flags.ANONCONSTR),
527         ACYCLIC(Flags.ACYCLIC),
528         PARAMETER(Flags.PARAMETER),
529         VARARGS(Flags.VARARGS),
530         ACYCLIC_ANN(Flags.ACYCLIC_ANN),
531         GENERATEDCONSTR(Flags.GENERATEDCONSTR),
532         HYPOTHETICAL(Flags.HYPOTHETICAL),
533         PROPRIETARY(Flags.PROPRIETARY),
534         UNION(Flags.UNION),
535         EFFECTIVELY_FINAL(Flags.EFFECTIVELY_FINAL),
536         CLASH(Flags.CLASH),
537         AUXILIARY(Flags.AUXILIARY),
538         NOT_IN_PROFILE(Flags.NOT_IN_PROFILE),
< prev index next >