< 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     /** Class is a unnamed top level class.
127      */
128     public static final int UNNAMED_CLASS    = 1<<19;
129 
130     /** Flag is set for compiler-generated anonymous method symbols
131      *  that `own' an initializer block.
132      */
133     public static final int BLOCK            = 1<<20;
134 



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

396 
397     /**
398      * Flag to indicate that the class/interface was declared with the non-sealed modifier.
399      */
400     public static final long NON_SEALED = 1L<<63; // ClassSymbols
401 
402     /**
403      * Describe modifier flags as they might appear in source code, i.e.,
404      * separated by spaces and in the order suggested by JLS 8.1.1.
405      */
406     public static String toSource(long flags) {
407         return asModifierSet(flags).stream()
408           .map(Modifier::toString)
409           .collect(Collectors.joining(" "));
410     }
411 
412     /** Modifier masks.
413      */
414     public static final int
415         AccessFlags                       = PUBLIC | PROTECTED | PRIVATE,
416         LocalClassFlags                   = FINAL | ABSTRACT | STRICTFP | ENUM | SYNTHETIC,
417         StaticLocalFlags                  = LocalClassFlags | STATIC | INTERFACE,
418         MemberClassFlags                  = LocalClassFlags | INTERFACE | AccessFlags,
419         MemberStaticClassFlags            = MemberClassFlags | STATIC,
420         ClassFlags                        = LocalClassFlags | INTERFACE | PUBLIC | ANNOTATION,
421         InterfaceVarFlags                 = FINAL | STATIC | PUBLIC,
422         VarFlags                          = AccessFlags | FINAL | STATIC |
423                                             VOLATILE | TRANSIENT | ENUM,
424         ConstructorFlags                  = AccessFlags,
425         InterfaceMethodFlags              = ABSTRACT | PUBLIC,
426         MethodFlags                       = AccessFlags | ABSTRACT | STATIC | NATIVE |
427                                             SYNCHRONIZED | FINAL | STRICTFP,
428         RecordMethodFlags                 = AccessFlags | ABSTRACT | STATIC |
429                                             SYNCHRONIZED | FINAL | STRICTFP;

430     public static final long
431         ExtendedStandardFlags             = (long)StandardFlags | DEFAULT | SEALED | NON_SEALED,
432         ExtendedMemberClassFlags          = (long)MemberClassFlags | SEALED | NON_SEALED,
433         ExtendedMemberStaticClassFlags    = (long) MemberStaticClassFlags | SEALED | NON_SEALED,
434         ExtendedClassFlags                = (long)ClassFlags | SEALED | NON_SEALED,
435         ModifierFlags                     = ((long)StandardFlags & ~INTERFACE) | DEFAULT | SEALED | NON_SEALED,


436         InterfaceMethodMask               = ABSTRACT | PRIVATE | STATIC | PUBLIC | STRICTFP | DEFAULT,
437         AnnotationTypeElementMask         = ABSTRACT | PUBLIC,
438         LocalVarFlags                     = FINAL | PARAMETER,
439         ReceiverParamFlags                = PARAMETER;
440 
441     public static Set<Modifier> asModifierSet(long flags) {
442         Set<Modifier> modifiers = modifierSets.get(flags);
443         if (modifiers == null) {
444             modifiers = java.util.EnumSet.noneOf(Modifier.class);
445             if (0 != (flags & PUBLIC))    modifiers.add(Modifier.PUBLIC);
446             if (0 != (flags & PROTECTED)) modifiers.add(Modifier.PROTECTED);
447             if (0 != (flags & PRIVATE))   modifiers.add(Modifier.PRIVATE);
448             if (0 != (flags & ABSTRACT))  modifiers.add(Modifier.ABSTRACT);
449             if (0 != (flags & STATIC))    modifiers.add(Modifier.STATIC);
450             if (0 != (flags & SEALED))    modifiers.add(Modifier.SEALED);
451             if (0 != (flags & NON_SEALED))
452                                           modifiers.add(Modifier.NON_SEALED);
453             if (0 != (flags & FINAL))     modifiers.add(Modifier.FINAL);
454             if (0 != (flags & TRANSIENT)) modifiers.add(Modifier.TRANSIENT);
455             if (0 != (flags & VOLATILE))  modifiers.add(Modifier.VOLATILE);
456             if (0 != (flags & SYNCHRONIZED))
457                                           modifiers.add(Modifier.SYNCHRONIZED);
458             if (0 != (flags & NATIVE))    modifiers.add(Modifier.NATIVE);
459             if (0 != (flags & STRICTFP))  modifiers.add(Modifier.STRICTFP);
460             if (0 != (flags & DEFAULT))   modifiers.add(Modifier.DEFAULT);


461             modifiers = Collections.unmodifiableSet(modifiers);
462             modifierSets.put(flags, modifiers);
463         }
464         return modifiers;
465     }
466 
467     // Cache of modifier sets.
468     private static final Map<Long, Set<Modifier>> modifierSets = new ConcurrentHashMap<>(64);
469 
470     public static boolean isStatic(Symbol symbol) {
471         return (symbol.flags() & STATIC) != 0;
472     }
473 
474     public static boolean isEnum(Symbol symbol) {
475         return (symbol.flags() & ENUM) != 0;
476     }
477 
478     public static boolean isConstant(Symbol.VarSymbol symbol) {
479         return symbol.getConstValue() != null;
480     }

482 
483     public enum Flag {
484         PUBLIC(Flags.PUBLIC),
485         PRIVATE(Flags.PRIVATE),
486         PROTECTED(Flags.PROTECTED),
487         STATIC(Flags.STATIC),
488         FINAL(Flags.FINAL),
489         SYNCHRONIZED(Flags.SYNCHRONIZED),
490         VOLATILE(Flags.VOLATILE),
491         TRANSIENT(Flags.TRANSIENT),
492         NATIVE(Flags.NATIVE),
493         INTERFACE(Flags.INTERFACE),
494         ABSTRACT(Flags.ABSTRACT),
495         DEFAULT(Flags.DEFAULT),
496         STRICTFP(Flags.STRICTFP),
497         BRIDGE(Flags.BRIDGE),
498         SYNTHETIC(Flags.SYNTHETIC),
499         ANNOTATION(Flags.ANNOTATION),
500         DEPRECATED(Flags.DEPRECATED),
501         HASINIT(Flags.HASINIT),








502         UNNAMED_CLASS(Flags.UNNAMED_CLASS),
503         BLOCK(Flags.BLOCK),
504         FROM_SOURCE(Flags.FROM_SOURCE),
505         ENUM(Flags.ENUM),
506         MANDATED(Flags.MANDATED),


507         NOOUTERTHIS(Flags.NOOUTERTHIS),
508         EXISTS(Flags.EXISTS),
509         COMPOUND(Flags.COMPOUND),
510         CLASS_SEEN(Flags.CLASS_SEEN),
511         SOURCE_SEEN(Flags.SOURCE_SEEN),
512         LOCKED(Flags.LOCKED),
513         UNATTRIBUTED(Flags.UNATTRIBUTED),
514         ANONCONSTR(Flags.ANONCONSTR),
515         ACYCLIC(Flags.ACYCLIC),
516         PARAMETER(Flags.PARAMETER),
517         VARARGS(Flags.VARARGS),
518         ACYCLIC_ANN(Flags.ACYCLIC_ANN),
519         GENERATEDCONSTR(Flags.GENERATEDCONSTR),
520         HYPOTHETICAL(Flags.HYPOTHETICAL),
521         PROPRIETARY(Flags.PROPRIETARY),
522         UNION(Flags.UNION),
523         EFFECTIVELY_FINAL(Flags.EFFECTIVELY_FINAL),
524         CLASH(Flags.CLASH),
525         AUXILIARY(Flags.AUXILIARY),
526         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     /** Class is a unnamed top level class.
157      */
158     public static final int UNNAMED_CLASS    = 1<<23;
159 
160     /** Flag is set for compiler-generated anonymous method symbols
161      *  that `own' an initializer block.
162      */
163     public static final int BLOCK            = 1<<20;
164 
165     /** Marks a type as a value class */
166     public static final int VALUE_CLASS      = 1<<20;
167 
168     /** Flag is set for ClassSymbols that are being compiled from source.
169      */
170     public static final int FROM_SOURCE      = 1<<21; //ClassSymbols
171 
172     /** Flag is set for nested classes that do not access instance members
173      *  or `this' of an outer class and therefore don't need to be passed
174      *  a this$n reference.  This value is currently set only for anonymous
175      *  classes in superclass constructor calls.
176      *  todo: use this value for optimizing away this$n parameters in
177      *  other cases.
178      */
179     public static final int NOOUTERTHIS  = 1<<22;
180 
181     /** Flag is set for package symbols if a package has a member or
182      *  directory and therefore exists.
183      */
184     public static final int EXISTS           = 1<<23;
185 
186     /** Flag is set for compiler-generated compound classes
187      *  representing multiple variable bounds

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

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