@@ -340,12 +340,12 @@ class AstClass(
340340 val source : String ,
341341 program : AstProgram ,
342342 val name : FqName ,
343- val modifiers : AstModifiers ,
343+ override val modifiers : AstModifiers ,
344344 val extending : FqName ? = null ,
345345 val implementing : List <FqName > = listOf(),
346346 annotations : List <AstAnnotation > = listOf(),
347347 val classId : Int = program.lastClassId++
348- ) : AstAnnotatedElement(program, name.ref, annotations), IUserData by UserData() {
348+ ) : AstAnnotatedElement(program, name.ref, annotations), IUserData by UserData(), WithAstModifiersClass {
349349 val types get() = program.types
350350
351351 val implementingUnique by lazy { implementing.distinct() }
@@ -680,14 +680,14 @@ class AstField(
680680 val id : Int = containingClass.program.lastFieldId++,
681681 name : String ,
682682 type : AstType ,
683- val modifiers : AstModifiers ,
683+ override val modifiers : AstModifiers ,
684684 val desc : String ,
685685 annotations : List <AstAnnotation >,
686686 val genericSignature : String? ,
687687 val constantValue : Any? = null ,
688688 val types : AstTypes ,
689689 override val ref : AstFieldRef = AstFieldRef (containingClass.name, name, type)
690- ) : AstMember(containingClass, name, type, if (genericSignature != null) types.demangle(genericSignature) else type, modifiers.isStatic, modifiers.visibility, ref, annotations), FieldRef {
690+ ) : AstMember(containingClass, name, type, if (genericSignature != null) types.demangle(genericSignature) else type, modifiers.isStatic, modifiers.visibility, ref, annotations), FieldRef, WithAstModifiersField {
691691 val uniqueName = containingClass.uniqueNames.alloc(name)
692692 val isFinal: Boolean = modifiers.isFinal
693693 val refWithoutClass: AstFieldWithoutClassRef by lazy { AstFieldWithoutClassRef (this .name, this .type) }
@@ -711,7 +711,7 @@ class AstMethod constructor(
711711 val signature : String ,
712712 val genericSignature : String? ,
713713 val defaultTag : Any? ,
714- val modifiers : AstModifiers ,
714+ override val modifiers : AstModifiers ,
715715 var generateBody : () -> AstBody ? ,
716716 val bodyRef : AstMethodRef ? = null ,
717717 val parameterAnnotations : List <List <AstAnnotation >> = listOf(),
@@ -721,7 +721,7 @@ class AstMethod constructor(
721721 containingClass, name, methodType,
722722 if (genericSignature != null) containingClass.types.demangleMethod(genericSignature) else methodType,
723723 modifiers.isStatic, modifiers.visibility, ref, annotations
724- ), MethodRef {
724+ ), MethodRef, WithAstModifiersMethod {
725725 val types: AstTypes get() = program.types
726726
727727 val parameterAnnotationsList: List <AstAnnotationList > = parameterAnnotations.map { AstAnnotationList (ref, it) }
@@ -736,8 +736,6 @@ class AstMethod constructor(
736736 }
737737 }
738738
739- val isNative: Boolean = modifiers.isNative
740-
741739 private var generatedBody: Boolean = false
742740 private var generatedBodyBody: AstBody ? = null
743741
@@ -845,8 +843,19 @@ val AstMethodRef.isInstanceInit: Boolean get() = name == "<init>"
845843val AstMethodRef .isClassInit: Boolean get() = name == " <clinit>"
846844val AstMethodRef .isClassOrInstanceInit: Boolean get() = isInstanceInit || isClassInit
847845
846+ interface WithAstModifiers {
847+ val modifiers: AstModifiers
848+ }
849+
850+ interface WithAstModifiersMember : WithAstModifiers
851+ interface WithAstModifiersMethod : WithAstModifiersMember
852+ interface WithAstModifiersField : WithAstModifiersMember
853+ interface WithAstModifiersParameter : WithAstModifiers
854+ interface WithAstModifiersClass : WithAstModifiers
855+
848856@Suppress(" unused" )
849- data class AstModifiers (val acc : Int ) {
857+ data class AstModifiers (val acc : Int ) : WithAstModifiersMethod, WithAstModifiersField, WithAstModifiersClass, WithAstModifiersParameter {
858+ override val modifiers = this
850859 companion object {
851860 fun withFlags (vararg flags : Int ): AstModifiers {
852861 var out = 0
@@ -875,43 +884,6 @@ data class AstModifiers(val acc: Int) {
875884 const val ACC_MANDATED = 0x8000 // parameter
876885 }
877886
878- val isPublic: Boolean get() = acc hasFlag ACC_PUBLIC
879- val isPrivate: Boolean get() = acc hasFlag ACC_PRIVATE
880- val isProtected: Boolean get() = acc hasFlag ACC_PROTECTED
881- val isStatic: Boolean get() = acc hasFlag ACC_STATIC
882- val isFinal: Boolean get() = acc hasFlag ACC_FINAL
883- val isSuper: Boolean get() = acc hasFlag ACC_SUPER
884- val isSynchronized: Boolean get() = acc hasFlag ACC_SYNCHRONIZED
885- val isVolatile: Boolean get() = acc hasFlag ACC_VOLATILE
886- val isBridge: Boolean get() = acc hasFlag ACC_BRIDGE
887- val isVarargs: Boolean get() = acc hasFlag ACC_VARARGS
888- val isTransient: Boolean get() = acc hasFlag ACC_TRANSIENT
889- val isNative: Boolean get() = acc hasFlag ACC_NATIVE
890- val isInterface: Boolean get() = acc hasFlag ACC_INTERFACE
891- val isAbstract: Boolean get() = acc hasFlag ACC_ABSTRACT
892- val isStrict: Boolean get() = acc hasFlag ACC_STRICT
893- val isSynthetic: Boolean get() = acc hasFlag ACC_SYNTHETIC
894- val isAnnotation: Boolean get() = acc hasFlag ACC_ANNOTATION
895- val isEnum: Boolean get() = acc hasFlag ACC_ENUM
896- val isMandated: Boolean get() = acc hasFlag ACC_MANDATED
897- val isConcrete: Boolean get() = ! isNative && ! isAbstract
898-
899- val visibility: AstVisibility get() = if (isPublic) {
900- AstVisibility .PUBLIC
901- } else if (isProtected) {
902- AstVisibility .PROTECTED
903- } else {
904- AstVisibility .PRIVATE
905- }
906-
907- val classType: AstClassType get() = if (isInterface) {
908- AstClassType .INTERFACE
909- } else if (isAbstract) {
910- AstClassType .ABSTRACT
911- } else {
912- AstClassType .CLASS
913- }
914-
915887 fun with (flags : Int ) = AstModifiers (this .acc or flags)
916888 fun without (flags : Int ) = AstModifiers (this .acc and flags.inv ())
917889
@@ -927,6 +899,38 @@ data class AstModifiers(val acc: Int) {
927899 override fun toString (): String = " $acc "
928900}
929901
902+ val WithAstModifiers .isPublic: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_PUBLIC
903+ val WithAstModifiers .isPrivate: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_PRIVATE
904+ val WithAstModifiers .isProtected: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_PROTECTED
905+ val WithAstModifiersMember .isStatic: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_STATIC
906+ val WithAstModifiers .isFinal: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_FINAL
907+ val WithAstModifiersMethod .isSynchronized: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_SYNCHRONIZED
908+ val WithAstModifiersField .isVolatile: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_VOLATILE
909+ val WithAstModifiersMethod .isBridge: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_BRIDGE
910+ val WithAstModifiersMethod .isVarargs: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_VARARGS
911+ val WithAstModifiersField .isTransient: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_TRANSIENT
912+ val WithAstModifiersMethod .isNative: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_NATIVE
913+ val WithAstModifiersMethod .isAbstract: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_ABSTRACT
914+ val WithAstModifiersMethod .isStrict: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_STRICT
915+ val WithAstModifiers .isSynthetic: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_SYNTHETIC
916+ val WithAstModifiersParameter .isMandated: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_MANDATED
917+ val WithAstModifiersMethod .isConcrete: Boolean get() = ! isNative && ! isAbstract
918+ val WithAstModifiers .visibility: AstVisibility get() = when {
919+ isPublic -> AstVisibility .PUBLIC
920+ isProtected -> AstVisibility .PROTECTED
921+ else -> AstVisibility .PRIVATE
922+ }
923+ val WithAstModifiersClass .isSuper: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_SUPER
924+ val WithAstModifiersClass .isInterface: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_INTERFACE
925+ val WithAstModifiersClass .isAbstract: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_ABSTRACT
926+ val WithAstModifiersClass .isAnnotation: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_ANNOTATION
927+ val WithAstModifiersClass .isEnum: Boolean get() = modifiers.acc hasFlag AstModifiers .ACC_ENUM
928+ val WithAstModifiersClass .classType: AstClassType get() = when {
929+ isInterface -> AstClassType .INTERFACE
930+ isAbstract -> AstClassType .ABSTRACT
931+ else -> AstClassType .CLASS
932+ }
933+
930934fun ARRAY (type : AstClass ) = AstType .ARRAY (type.astType)
931935
932936fun getCommonTypePrim (a : AstType .Primitive , b : AstType .Primitive ): AstType .Primitive {
0 commit comments