Refactor flags in kotlinx-metadata
- rename object Flags to Flag and merge it with MetadataFlag - use typealias Flags instead of Int - use top level function "flagsOf" instead of "Flags.invoke" to construct a bitmask #KT-23198
This commit is contained in:
@@ -31,7 +31,7 @@ Let's assume we've obtained an instance of `KotlinClassMetadata.Class`; other ki
|
||||
|
||||
```kotlin
|
||||
metadata.accept(object : KmClassVisitor() {
|
||||
override fun visitFunction(flags: Int, name: String): KmFunctionVisitor? {
|
||||
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? {
|
||||
// This will be called for each function in the class. "name" is the
|
||||
// function name, and "flags" represent modifier flags (see below)
|
||||
|
||||
@@ -47,14 +47,14 @@ Please refer to [`MetadataSmokeTest.listInlineFunctions`](test/kotlinx/metadata/
|
||||
|
||||
## Flags
|
||||
|
||||
Numerous `visit*` methods are declared with the parameter named `flags`. These flags represent modifiers or other boolean attributes of a declaration or a type. To check if a certain flag is present, call one of the flags in [`Flags`](../src/kotlinx/metadata/Flags.kt) on the given integer value. The set of applicable flags is documented in each `visit*` method. For example, for functions, this is common declaration flags (visibility, modality) plus `Flags.Function` flags:
|
||||
Numerous `visit*` methods take the parameter named `flags`. These flags represent modifiers or other boolean attributes of a declaration or a type. To check if a certain flag is present, call one of the flags in [`Flag`](../src/kotlinx/metadata/Flag.kt) on the given integer value. The set of applicable flags is documented in each `visit*` method. For example, for functions, this is common declaration flags (visibility, modality) plus `Flag.Function` flags:
|
||||
|
||||
```kotlin
|
||||
override fun visitFunction(flags: Int, name: String): KmFunctionVisitor? {
|
||||
if (Flags.IS_PUBLIC(flags)) {
|
||||
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? {
|
||||
if (Flag.IS_PUBLIC(flags)) {
|
||||
println("function $name is public")
|
||||
}
|
||||
if (Flags.Function.IS_SUSPEND(flags)) {
|
||||
if (Flag.Function.IS_SUSPEND(flags)) {
|
||||
println("function $name has the 'suspend' modifier")
|
||||
}
|
||||
...
|
||||
@@ -92,11 +92,11 @@ When using metadata writers from Kotlin source code, it's very convenient to use
|
||||
// Writing metadata of a class
|
||||
val header = KotlinClassMetadata.Class.Writer().run {
|
||||
// Visiting the name and the modifiers on the class.
|
||||
// Flags are constructed by invoking "Flags(...)"
|
||||
visit(Flags(Flags.IS_PUBLIC), "MyClass")
|
||||
// Flags are constructed by invoking "flagsOf(...)"
|
||||
visit(flagsOf(Flag.IS_PUBLIC), "MyClass")
|
||||
|
||||
// Adding one public primary constructor
|
||||
visitConstructor(Flags(Flags.IS_PUBLIC, Flags.Constructor.IS_PRIMARY))!!.run {
|
||||
visitConstructor(flagsOf(Flag.IS_PUBLIC, Flag.Constructor.IS_PRIMARY))!!.run {
|
||||
// Visiting JVM signature (for example, to be used by kotlin-reflect)
|
||||
(visitExtensions(JvmConstructorExtensionVisitor.TYPE) as JvmConstructorExtensionVisitor).run {
|
||||
visit("<init>()V")
|
||||
|
||||
@@ -38,14 +38,14 @@ class MetadataSmokeTest {
|
||||
|
||||
val klass = KotlinClassMetadata.read(L::class.java.readMetadata()) as KotlinClassMetadata.Class
|
||||
klass.accept(object : KmClassVisitor() {
|
||||
override fun visitFunction(flags: Int, name: String): KmFunctionVisitor? {
|
||||
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? {
|
||||
return object : KmFunctionVisitor() {
|
||||
override fun visitExtensions(type: KmExtensionType): KmFunctionExtensionVisitor? {
|
||||
if (type != JvmFunctionExtensionVisitor.TYPE) return null
|
||||
|
||||
return object : JvmFunctionExtensionVisitor() {
|
||||
override fun visit(desc: String?) {
|
||||
if (Flags.Function.IS_INLINE(flags) && desc != null) {
|
||||
if (Flag.Function.IS_INLINE(flags) && desc != null) {
|
||||
inlineFunctions += desc
|
||||
}
|
||||
}
|
||||
@@ -69,14 +69,14 @@ class MetadataSmokeTest {
|
||||
// }
|
||||
|
||||
val header = KotlinClassMetadata.Class.Writer().run {
|
||||
visit(Flags(Flags.IS_PUBLIC), "Hello")
|
||||
visitConstructor(Flags(Flags.IS_PUBLIC, Flags.Constructor.IS_PRIMARY))!!.run {
|
||||
visit(flagsOf(Flag.IS_PUBLIC), "Hello")
|
||||
visitConstructor(flagsOf(Flag.IS_PUBLIC, Flag.Constructor.IS_PRIMARY))!!.run {
|
||||
(visitExtensions(JvmConstructorExtensionVisitor.TYPE) as JvmConstructorExtensionVisitor).run {
|
||||
visit("<init>()V")
|
||||
}
|
||||
visitEnd()
|
||||
}
|
||||
visitFunction(Flags(Flags.IS_PUBLIC, Flags.Function.IS_DECLARATION), "hello")!!.run {
|
||||
visitFunction(flagsOf(Flag.IS_PUBLIC, Flag.Function.IS_DECLARATION), "hello")!!.run {
|
||||
visitReturnType(0)!!.run {
|
||||
visitClass("kotlin/String")
|
||||
visitEnd()
|
||||
|
||||
@@ -0,0 +1,493 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlinx.metadata
|
||||
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf.*
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags as F
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf.Class.Kind as ClassKind
|
||||
|
||||
/**
|
||||
* Represents a boolean flag that is either present or not in a Kotlin declaration. A "flag" is a boolean trait that is either present
|
||||
* or not in a declaration. To check whether the flag is present in the bitmask, call [Flag.invoke] on the flag, passing the bitmask
|
||||
* as the argument:
|
||||
*
|
||||
* override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? {
|
||||
* if (Flag.Function.IS_INLINE(flags)) {
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* To construct a bitmask out of several flags, call [flagsOf] on the needed flags:
|
||||
*
|
||||
* v.visitFunction(flagsOf(Flag.Function.IS_DECLARATION, Flag.Function.IS_INLINE), "foo")
|
||||
*
|
||||
* Flag common to multiple kinds of Kotlin declarations ("common flags") are declared in [Flag.Common].
|
||||
* Flag applicable to specific kinds of declarations ("declaration-specific flags") are declared in nested objects of the [Flag] object.
|
||||
*
|
||||
* Some flags are mutually exclusive, i.e. there are "flag groups" such that no more than one flag from each group can be present
|
||||
* in the same bitmask. Among common flags, there are the following flag groups:
|
||||
* * visibility flags: [IS_INTERNAL], [IS_PRIVATE], [IS_PROTECTED], [IS_PUBLIC], [IS_PRIVATE_TO_THIS], [IS_LOCAL]
|
||||
* * modality flags: [IS_FINAL], [IS_OPEN], [IS_ABSTRACT], [IS_SEALED]
|
||||
*
|
||||
* Some declaration-specific flags form other flag groups, see the documentation of the corresponding containers for more information.
|
||||
*
|
||||
* @see Flags
|
||||
* @see flagsOf
|
||||
*/
|
||||
class Flag internal constructor(
|
||||
private val offset: Int,
|
||||
private val bitWidth: Int,
|
||||
private val value: Int
|
||||
) {
|
||||
internal constructor(field: F.FlagField<*>, value: Int) : this(field.offset, field.bitWidth, value)
|
||||
|
||||
internal constructor(field: F.BooleanFlagField) : this(field, 1)
|
||||
|
||||
internal operator fun plus(flags: Flags): Flags =
|
||||
(flags and (((1 shl bitWidth) - 1) shl offset).inv()) + (value shl offset)
|
||||
|
||||
/**
|
||||
* Checks whether the flag is present in the given bitmask.
|
||||
*/
|
||||
operator fun invoke(flags: Flags): Boolean =
|
||||
(flags ushr offset) and ((1 shl bitWidth) - 1) == value
|
||||
|
||||
companion object Common {
|
||||
/**
|
||||
* Signifies that the corresponding declaration has at least one annotation.
|
||||
*
|
||||
* This flag is useful for reading Kotlin metadata on JVM efficiently. On JVM, most of the annotations are written not to the Kotlin
|
||||
* metadata, but directly on the corresponding declarations in the class file. This flag can be used as an optimization to avoid
|
||||
* reading annotations from the class file (which can be slow) in case when a declaration has no annotations.
|
||||
*/
|
||||
@JvmField
|
||||
val HAS_ANNOTATIONS = Flag(F.HAS_ANNOTATIONS)
|
||||
|
||||
|
||||
/**
|
||||
* A visibility flag, signifying that the corresponding declaration is `internal`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INTERNAL = Flag(F.VISIBILITY, Visibility.INTERNAL_VALUE)
|
||||
|
||||
/**
|
||||
* A visibility flag, signifying that the corresponding declaration is `private`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_PRIVATE = Flag(F.VISIBILITY, Visibility.PRIVATE_VALUE)
|
||||
|
||||
/**
|
||||
* A visibility flag, signifying that the corresponding declaration is `protected`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_PROTECTED = Flag(F.VISIBILITY, Visibility.PROTECTED_VALUE)
|
||||
|
||||
/**
|
||||
* A visibility flag, signifying that the corresponding declaration is `public`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_PUBLIC = Flag(F.VISIBILITY, Visibility.PUBLIC_VALUE)
|
||||
|
||||
/**
|
||||
* A visibility flag, signifying that the corresponding declaration is "private-to-this", which is a non-denotable visibility of
|
||||
* private members in Kotlin which are callable only on the same instance of the declaring class.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_PRIVATE_TO_THIS = Flag(F.VISIBILITY, Visibility.PRIVATE_TO_THIS_VALUE)
|
||||
|
||||
/**
|
||||
* A visibility flag, signifying that the corresponding declaration is local, i.e. declared inside a code block
|
||||
* and not visible from the outside.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_LOCAL = Flag(F.VISIBILITY, Visibility.LOCAL_VALUE)
|
||||
|
||||
|
||||
/**
|
||||
* A modality flag, signifying that the corresponding declaration is `final`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_FINAL = Flag(F.MODALITY, Modality.FINAL_VALUE)
|
||||
|
||||
/**
|
||||
* A modality flag, signifying that the corresponding declaration is `open`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_OPEN = Flag(F.MODALITY, Modality.OPEN_VALUE)
|
||||
|
||||
/**
|
||||
* A modality flag, signifying that the corresponding declaration is `abstract`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_ABSTRACT = Flag(F.MODALITY, Modality.ABSTRACT_VALUE)
|
||||
|
||||
/**
|
||||
* A modality flag, signifying that the corresponding declaration is `sealed`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_SEALED = Flag(F.MODALITY, Modality.SEALED_VALUE)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin classes, including interfaces, objects, enum classes and annotation classes.
|
||||
*
|
||||
* In addition to the common flag groups, the following flag groups exist for class flags:
|
||||
* * class kind flags: [IS_CLASS], [IS_INTERFACE], [IS_ENUM_CLASS], [IS_ENUM_ENTRY], [IS_ANNOTATION_CLASS], [IS_OBJECT],
|
||||
* [IS_COMPANION_OBJECT]
|
||||
*/
|
||||
object Class {
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is a usual `class`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_CLASS = Flag(F.CLASS_KIND, ClassKind.CLASS_VALUE)
|
||||
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is an `interface`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INTERFACE = Flag(F.CLASS_KIND, ClassKind.INTERFACE_VALUE)
|
||||
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is an `enum class`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_ENUM_CLASS = Flag(F.CLASS_KIND, ClassKind.ENUM_CLASS_VALUE)
|
||||
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is an enum entry.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_ENUM_ENTRY = Flag(F.CLASS_KIND, ClassKind.ENUM_ENTRY_VALUE)
|
||||
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is an `annotation class`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_ANNOTATION_CLASS = Flag(F.CLASS_KIND, ClassKind.ANNOTATION_CLASS_VALUE)
|
||||
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is a non-companion `object`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_OBJECT = Flag(F.CLASS_KIND, ClassKind.OBJECT_VALUE)
|
||||
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is a `companion object`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_COMPANION_OBJECT = Flag(F.CLASS_KIND, ClassKind.COMPANION_OBJECT_VALUE)
|
||||
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding class is `inner`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INNER = Flag(F.IS_INNER)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding class is `data`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_DATA = Flag(F.IS_DATA)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding class is `external`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXTERNAL = Flag(F.IS_EXTERNAL_CLASS)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding class is `expect`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXPECT = Flag(F.IS_EXPECT_CLASS)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding class is `inline`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INLINE = Flag(F.IS_INLINE_CLASS)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin constructors.
|
||||
*/
|
||||
object Constructor {
|
||||
/**
|
||||
* Signifies that the corresponding constructor is primary, i.e. declared in the class header, not in the class body.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_PRIMARY = Flag(F.IS_SECONDARY, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin functions.
|
||||
*
|
||||
* In addition to the common flag groups, the following flag groups exist for function flags:
|
||||
* * member kind flags: [IS_DECLARATION], [IS_FAKE_OVERRIDE], [IS_DELEGATION], [IS_SYNTHESIZED]
|
||||
*/
|
||||
object Function {
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding function is explicitly declared in the containing class.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_DECLARATION = Flag(F.MEMBER_KIND, MemberKind.DECLARATION_VALUE)
|
||||
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding function exists in the containing class because a function with a suitable
|
||||
* signature exists in a supertype. This flag is not written by the Kotlin compiler and its effects are unspecified.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_FAKE_OVERRIDE = Flag(F.MEMBER_KIND, MemberKind.FAKE_OVERRIDE_VALUE)
|
||||
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding function exists in the containing class because it has been produced
|
||||
* by interface delegation (delegation "by").
|
||||
*/
|
||||
@JvmField
|
||||
val IS_DELEGATION = Flag(F.MEMBER_KIND, MemberKind.DELEGATION_VALUE)
|
||||
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding function exists in the containing class because it has been synthesized
|
||||
* by the compiler and has no declaration in the source code.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_SYNTHESIZED = Flag(F.MEMBER_KIND, MemberKind.SYNTHESIZED_VALUE)
|
||||
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `operator`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_OPERATOR = Flag(F.IS_OPERATOR)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `infix`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INFIX = Flag(F.IS_INFIX)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `inline`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INLINE = Flag(F.IS_INLINE)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `tailrec`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_TAILREC = Flag(F.IS_TAILREC)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `external`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXTERNAL = Flag(F.IS_EXTERNAL_FUNCTION)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `suspend`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_SUSPEND = Flag(F.IS_SUSPEND)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `expect`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXPECT = Flag(F.IS_EXPECT_FUNCTION)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin properties.
|
||||
*
|
||||
* In addition to the common flag groups, the following flag groups exist for property flags:
|
||||
* * member kind flags: [IS_DECLARATION], [IS_FAKE_OVERRIDE], [IS_DELEGATION], [IS_SYNTHESIZED]
|
||||
*/
|
||||
object Property {
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding property is explicitly declared in the containing class.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_DECLARATION = Flag(F.MEMBER_KIND, MemberKind.DECLARATION_VALUE)
|
||||
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding property exists in the containing class because a property with a suitable
|
||||
* signature exists in a supertype. This flag is not written by the Kotlin compiler and its effects are unspecified.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_FAKE_OVERRIDE = Flag(F.MEMBER_KIND, MemberKind.FAKE_OVERRIDE_VALUE)
|
||||
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding property exists in the containing class because it has been produced
|
||||
* by interface delegation (delegation "by").
|
||||
*/
|
||||
@JvmField
|
||||
val IS_DELEGATION = Flag(F.MEMBER_KIND, MemberKind.DELEGATION_VALUE)
|
||||
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding property exists in the containing class because it has been synthesized
|
||||
* by the compiler and has no declaration in the source code.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_SYNTHESIZED = Flag(F.MEMBER_KIND, MemberKind.SYNTHESIZED_VALUE)
|
||||
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property is `var`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_VAR = Flag(F.IS_VAR)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property has a getter.
|
||||
*/
|
||||
@JvmField
|
||||
val HAS_GETTER = Flag(F.HAS_GETTER)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property has a setter.
|
||||
*/
|
||||
@JvmField
|
||||
val HAS_SETTER = Flag(F.HAS_SETTER)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property is `const`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_CONST = Flag(F.IS_CONST)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property is `lateinit`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_LATEINIT = Flag(F.IS_LATEINIT)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property has a constant value. On JVM, this flag allows an optimization similarly to
|
||||
* [F.HAS_ANNOTATIONS]: constant values of properties are written to the bytecode directly, and this flag can be used to avoid
|
||||
* reading the value from the bytecode in case there isn't one.
|
||||
*/
|
||||
@JvmField
|
||||
val HAS_CONSTANT = Flag(F.HAS_CONSTANT)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property is `external`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXTERNAL = Flag(F.IS_EXTERNAL_PROPERTY)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property is a delegated property.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_DELEGATED = Flag(F.IS_DELEGATED)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property is `expect`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXPECT = Flag(F.IS_EXPECT_PROPERTY)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin property getters and setters.
|
||||
*/
|
||||
object PropertyAccessor {
|
||||
/**
|
||||
* Signifies that the corresponding property accessor is not default, i.e. it has a body and/or annotations in the source code.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_NOT_DEFAULT = Flag(F.IS_NOT_DEFAULT)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property accessor is `external`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXTERNAL = Flag(F.IS_EXTERNAL_ACCESSOR)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property accessor is `inline`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INLINE = Flag(F.IS_INLINE_ACCESSOR)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin types.
|
||||
*/
|
||||
object Type {
|
||||
/**
|
||||
* Signifies that the corresponding type is marked as nullable, i.e. has a question mark at the end of its notation.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_NULLABLE = Flag(0, 1, 1)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding type is `suspend`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_SUSPEND = Flag(F.SUSPEND_TYPE.offset + 1, F.SUSPEND_TYPE.bitWidth, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin type parameters.
|
||||
*/
|
||||
object TypeParameter {
|
||||
/**
|
||||
* Signifies that the corresponding type parameter is `reified`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_REIFIED = Flag(0, 1, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin value parameters.
|
||||
*/
|
||||
object ValueParameter {
|
||||
/**
|
||||
* Signifies that the corresponding value parameter declares a default value. Note that the default value itself can be a complex
|
||||
* expression and is not available via metadata. Also note that in case of an override of a parameter with default value, the
|
||||
* parameter in the derived method does _not_ declare the default value ([DECLARES_DEFAULT_VALUE] == false), but the parameter is
|
||||
* still optional at the call site because the default value from the base method is used.
|
||||
*/
|
||||
@JvmField
|
||||
val DECLARES_DEFAULT_VALUE = Flag(F.DECLARES_DEFAULT_VALUE)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding value parameter is `crossinline`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_CROSSINLINE = Flag(F.IS_CROSSINLINE)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding value parameter is `noinline`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_NOINLINE = Flag(F.IS_NOINLINE)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin effect expressions.
|
||||
*
|
||||
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
|
||||
* may change in a subsequent release.
|
||||
*/
|
||||
object EffectExpression {
|
||||
/**
|
||||
* Signifies that the corresponding effect expression should be negated to compute the proposition or the conclusion of an effect.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_NEGATED = Flag(F.IS_NEGATED)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding effect expression checks whether a value of some variable is `null`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_NULL_CHECK_PREDICATE = Flag(F.IS_NULL_CHECK_PREDICATE)
|
||||
}
|
||||
}
|
||||
@@ -1,481 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlinx.metadata
|
||||
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf.*
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags as F
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf.Class.Kind as ClassKind
|
||||
/**
|
||||
* Declaration flags are represented as bitmasks of this type.
|
||||
*
|
||||
* @see Flag
|
||||
*/
|
||||
typealias Flags = Int
|
||||
|
||||
/**
|
||||
* A container of all flags applicable to all Kotlin declarations. A "flag" is a boolean trait that is either present or not
|
||||
* in a declaration. To check whether the flag is present in the bitmask, call [MetadataFlag.invoke] on the flag, passing the bitmask
|
||||
* as the argument:
|
||||
* Combines several flags into an integer bitmask.
|
||||
*
|
||||
* override fun visitFunction(flags: Int, name: String): KmFunctionVisitor? {
|
||||
* if (Flags.Function.IS_INLINE(flags)) {
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* To construct a bitmask out of several flags, call [Flags.invoke] on the needed flags:
|
||||
*
|
||||
* v.visitFunction(Flags(Flags.Function.IS_DECLARATION, Flags.Function.IS_INLINE), "foo")
|
||||
*
|
||||
* Flags common to multiple kinds of Kotlin declarations ("common flags") are declared directly in the [Flags] object.
|
||||
* Flags applicable to specific kinds of declarations ("declaration-specific flags") are declared in nested objects of the [Flags] object.
|
||||
*
|
||||
* Some flags are mutually exclusive, i.e. there are "flag groups" such that no more than one flag from each group can be present
|
||||
* in the same bitmask. Among common flags, there are the following flag groups:
|
||||
* * visibility flags: [IS_INTERNAL], [IS_PRIVATE], [IS_PROTECTED], [IS_PUBLIC], [IS_PRIVATE_TO_THIS], [IS_LOCAL]
|
||||
* * modality flags: [IS_FINAL], [IS_OPEN], [IS_ABSTRACT], [IS_SEALED]
|
||||
*
|
||||
* Some declaration-specific flags form other flag groups, see the documentation of the corresponding containers for more information.
|
||||
* Note that in case several mutually exclusive flags are passed (for example, several visibility flags), the resulting bitmask will
|
||||
* hold the value of the latest flag. For example, `flagsOf(Flag.IS_PRIVATE, Flag.IS_PUBLIC, Flag.IS_INTERNAL)` is the same as
|
||||
* `flagsOf(Flag.IS_INTERNAL)`.
|
||||
*/
|
||||
object Flags {
|
||||
/**
|
||||
* Combines several flags into an integer bitmask. Note that in case several mutually exclusive flags are passed (for example,
|
||||
* several visibility flags), the resulting bitmask will hold the value of the latest flag.
|
||||
*
|
||||
* For example, `Flags(Flags.IS_PRIVATE, Flags.IS_PUBLIC, Flags.IS_INTERNAL)` is the same as `Flags(Flags.IS_INTERNAL)`
|
||||
*/
|
||||
operator fun invoke(vararg flags: MetadataFlag): Int =
|
||||
flags.fold(0) { acc, flag -> flag + acc }
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding declaration has at least one annotation.
|
||||
*
|
||||
* This flag is useful for reading Kotlin metadata on JVM efficiently. On JVM, most of the annotations are written not to the Kotlin
|
||||
* metadata, but directly on the corresponding declarations in the class file. This flag can be used as an optimization to avoid
|
||||
* reading annotations from the class file (which can be slow) in case when a declaration has no annotations.
|
||||
*/
|
||||
@JvmField
|
||||
val HAS_ANNOTATIONS = MetadataFlag(F.HAS_ANNOTATIONS)
|
||||
|
||||
|
||||
/**
|
||||
* A visibility flag, signifying that the corresponding declaration is `internal`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INTERNAL = MetadataFlag(F.VISIBILITY, Visibility.INTERNAL_VALUE)
|
||||
|
||||
/**
|
||||
* A visibility flag, signifying that the corresponding declaration is `private`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_PRIVATE = MetadataFlag(F.VISIBILITY, Visibility.PRIVATE_VALUE)
|
||||
|
||||
/**
|
||||
* A visibility flag, signifying that the corresponding declaration is `protected`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_PROTECTED = MetadataFlag(F.VISIBILITY, Visibility.PROTECTED_VALUE)
|
||||
|
||||
/**
|
||||
* A visibility flag, signifying that the corresponding declaration is `public`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_PUBLIC = MetadataFlag(F.VISIBILITY, Visibility.PUBLIC_VALUE)
|
||||
|
||||
/**
|
||||
* A visibility flag, signifying that the corresponding declaration is "private-to-this", which is a non-denotable visibility of
|
||||
* private members in Kotlin which are callable only on the same instance of the declaring class.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_PRIVATE_TO_THIS = MetadataFlag(F.VISIBILITY, Visibility.PRIVATE_TO_THIS_VALUE)
|
||||
|
||||
/**
|
||||
* A visibility flag, signifying that the corresponding declaration is local, i.e. declared inside a code block
|
||||
* and not visible from the outside.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_LOCAL = MetadataFlag(F.VISIBILITY, Visibility.LOCAL_VALUE)
|
||||
|
||||
|
||||
/**
|
||||
* A modality flag, signifying that the corresponding declaration is `final`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_FINAL = MetadataFlag(F.MODALITY, Modality.FINAL_VALUE)
|
||||
|
||||
/**
|
||||
* A modality flag, signifying that the corresponding declaration is `open`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_OPEN = MetadataFlag(F.MODALITY, Modality.OPEN_VALUE)
|
||||
|
||||
/**
|
||||
* A modality flag, signifying that the corresponding declaration is `abstract`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_ABSTRACT = MetadataFlag(F.MODALITY, Modality.ABSTRACT_VALUE)
|
||||
|
||||
/**
|
||||
* A modality flag, signifying that the corresponding declaration is `sealed`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_SEALED = MetadataFlag(F.MODALITY, Modality.SEALED_VALUE)
|
||||
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin classes, including interfaces, objects, enum classes and annotation classes.
|
||||
*
|
||||
* In addition to the common flag groups, the following flag groups exist for class flags:
|
||||
* * class kind flags: [IS_CLASS], [IS_INTERFACE], [IS_ENUM_CLASS], [IS_ENUM_ENTRY], [IS_ANNOTATION_CLASS], [IS_OBJECT],
|
||||
* [IS_COMPANION_OBJECT]
|
||||
*/
|
||||
object Class {
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is a usual `class`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_CLASS = MetadataFlag(F.CLASS_KIND, ClassKind.CLASS_VALUE)
|
||||
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is an `interface`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INTERFACE = MetadataFlag(F.CLASS_KIND, ClassKind.INTERFACE_VALUE)
|
||||
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is an `enum class`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_ENUM_CLASS = MetadataFlag(F.CLASS_KIND, ClassKind.ENUM_CLASS_VALUE)
|
||||
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is an enum entry.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_ENUM_ENTRY = MetadataFlag(F.CLASS_KIND, ClassKind.ENUM_ENTRY_VALUE)
|
||||
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is an `annotation class`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_ANNOTATION_CLASS = MetadataFlag(F.CLASS_KIND, ClassKind.ANNOTATION_CLASS_VALUE)
|
||||
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is a non-companion `object`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_OBJECT = MetadataFlag(F.CLASS_KIND, ClassKind.OBJECT_VALUE)
|
||||
|
||||
/**
|
||||
* A class kind flag, signifying that the corresponding class is a `companion object`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_COMPANION_OBJECT = MetadataFlag(F.CLASS_KIND, ClassKind.COMPANION_OBJECT_VALUE)
|
||||
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding class is `inner`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INNER = MetadataFlag(F.IS_INNER)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding class is `data`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_DATA = MetadataFlag(F.IS_DATA)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding class is `external`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXTERNAL = MetadataFlag(F.IS_EXTERNAL_CLASS)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding class is `expect`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXPECT = MetadataFlag(F.IS_EXPECT_CLASS)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding class is `inline`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INLINE = MetadataFlag(F.IS_INLINE_CLASS)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin constructors.
|
||||
*/
|
||||
object Constructor {
|
||||
/**
|
||||
* Signifies that the corresponding constructor is primary, i.e. declared in the class header, not in the class body.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_PRIMARY = MetadataFlag(F.IS_SECONDARY, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin functions.
|
||||
*
|
||||
* In addition to the common flag groups, the following flag groups exist for function flags:
|
||||
* * member kind flags: [IS_DECLARATION], [IS_FAKE_OVERRIDE], [IS_DELEGATION], [IS_SYNTHESIZED]
|
||||
*/
|
||||
object Function {
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding function is explicitly declared in the containing class.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_DECLARATION = MetadataFlag(F.MEMBER_KIND, MemberKind.DECLARATION_VALUE)
|
||||
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding function exists in the containing class because a function with a suitable
|
||||
* signature exists in a supertype. This flag is not written by the Kotlin compiler and its effects are unspecified.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_FAKE_OVERRIDE = MetadataFlag(F.MEMBER_KIND, MemberKind.FAKE_OVERRIDE_VALUE)
|
||||
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding function exists in the containing class because it has been produced
|
||||
* by interface delegation (delegation "by").
|
||||
*/
|
||||
@JvmField
|
||||
val IS_DELEGATION = MetadataFlag(F.MEMBER_KIND, MemberKind.DELEGATION_VALUE)
|
||||
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding function exists in the containing class because it has been synthesized
|
||||
* by the compiler and has no declaration in the source code.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_SYNTHESIZED = MetadataFlag(F.MEMBER_KIND, MemberKind.SYNTHESIZED_VALUE)
|
||||
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `operator`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_OPERATOR = MetadataFlag(F.IS_OPERATOR)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `infix`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INFIX = MetadataFlag(F.IS_INFIX)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `inline`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INLINE = MetadataFlag(F.IS_INLINE)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `tailrec`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_TAILREC = MetadataFlag(F.IS_TAILREC)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `external`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXTERNAL = MetadataFlag(F.IS_EXTERNAL_FUNCTION)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `suspend`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_SUSPEND = MetadataFlag(F.IS_SUSPEND)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding function is `expect`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXPECT = MetadataFlag(F.IS_EXPECT_FUNCTION)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin properties.
|
||||
*
|
||||
* In addition to the common flag groups, the following flag groups exist for property flags:
|
||||
* * member kind flags: [IS_DECLARATION], [IS_FAKE_OVERRIDE], [IS_DELEGATION], [IS_SYNTHESIZED]
|
||||
*/
|
||||
object Property {
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding property is explicitly declared in the containing class.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_DECLARATION = MetadataFlag(F.MEMBER_KIND, MemberKind.DECLARATION_VALUE)
|
||||
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding property exists in the containing class because a property with a suitable
|
||||
* signature exists in a supertype. This flag is not written by the Kotlin compiler and its effects are unspecified.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_FAKE_OVERRIDE = MetadataFlag(F.MEMBER_KIND, MemberKind.FAKE_OVERRIDE_VALUE)
|
||||
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding property exists in the containing class because it has been produced
|
||||
* by interface delegation (delegation "by").
|
||||
*/
|
||||
@JvmField
|
||||
val IS_DELEGATION = MetadataFlag(F.MEMBER_KIND, MemberKind.DELEGATION_VALUE)
|
||||
|
||||
/**
|
||||
* A member kind flag, signifying that the corresponding property exists in the containing class because it has been synthesized
|
||||
* by the compiler and has no declaration in the source code.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_SYNTHESIZED = MetadataFlag(F.MEMBER_KIND, MemberKind.SYNTHESIZED_VALUE)
|
||||
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property is `var`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_VAR = MetadataFlag(F.IS_VAR)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property has a getter.
|
||||
*/
|
||||
@JvmField
|
||||
val HAS_GETTER = MetadataFlag(F.HAS_GETTER)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property has a setter.
|
||||
*/
|
||||
@JvmField
|
||||
val HAS_SETTER = MetadataFlag(F.HAS_SETTER)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property is `const`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_CONST = MetadataFlag(F.IS_CONST)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property is `lateinit`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_LATEINIT = MetadataFlag(F.IS_LATEINIT)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property has a constant value. On JVM, this flag allows an optimization similarly to
|
||||
* [F.HAS_ANNOTATIONS]: constant values of properties are written to the bytecode directly, and this flag can be used to avoid
|
||||
* reading the value from the bytecode in case there isn't one.
|
||||
*/
|
||||
@JvmField
|
||||
val HAS_CONSTANT = MetadataFlag(F.HAS_CONSTANT)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property is `external`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXTERNAL = MetadataFlag(F.IS_EXTERNAL_PROPERTY)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property is a delegated property.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_DELEGATED = MetadataFlag(F.IS_DELEGATED)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property is `expect`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXPECT = MetadataFlag(F.IS_EXPECT_PROPERTY)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin property getters and setters.
|
||||
*/
|
||||
object PropertyAccessor {
|
||||
/**
|
||||
* Signifies that the corresponding property accessor is not default, i.e. it has a body and/or annotations in the source code.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_NOT_DEFAULT = MetadataFlag(F.IS_NOT_DEFAULT)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property accessor is `external`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_EXTERNAL = MetadataFlag(F.IS_EXTERNAL_ACCESSOR)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding property accessor is `inline`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_INLINE = MetadataFlag(F.IS_INLINE_ACCESSOR)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin types.
|
||||
*/
|
||||
object Type {
|
||||
/**
|
||||
* Signifies that the corresponding type is marked as nullable, i.e. has a question mark at the end of its notation.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_NULLABLE = MetadataFlag(0, 1, 1)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding type is `suspend`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_SUSPEND = MetadataFlag(F.SUSPEND_TYPE.offset + 1, F.SUSPEND_TYPE.bitWidth, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin type parameters.
|
||||
*/
|
||||
object TypeParameter {
|
||||
/**
|
||||
* Signifies that the corresponding type parameter is `reified`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_REIFIED = MetadataFlag(0, 1, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin value parameters.
|
||||
*/
|
||||
object ValueParameter {
|
||||
/**
|
||||
* Signifies that the corresponding value parameter declares a default value. Note that the default value itself can be a complex
|
||||
* expression and is not available via metadata. Also note that in case of an override of a parameter with default value, the
|
||||
* parameter in the derived method does _not_ declare the default value ([DECLARES_DEFAULT_VALUE] == false), but the parameter is
|
||||
* still optional at the call site because the default value from the base method is used.
|
||||
*/
|
||||
@JvmField
|
||||
val DECLARES_DEFAULT_VALUE = MetadataFlag(F.DECLARES_DEFAULT_VALUE)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding value parameter is `crossinline`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_CROSSINLINE = MetadataFlag(F.IS_CROSSINLINE)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding value parameter is `noinline`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_NOINLINE = MetadataFlag(F.IS_NOINLINE)
|
||||
}
|
||||
|
||||
/**
|
||||
* A container of flags applicable to Kotlin effect expressions.
|
||||
*
|
||||
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
|
||||
* may change in a subsequent release.
|
||||
*/
|
||||
object EffectExpression {
|
||||
/**
|
||||
* Signifies that the corresponding effect expression should be negated to compute the proposition or the conclusion of an effect.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_NEGATED = MetadataFlag(F.IS_NEGATED)
|
||||
|
||||
/**
|
||||
* Signifies that the corresponding effect expression checks whether a value of some variable is `null`.
|
||||
*/
|
||||
@JvmField
|
||||
val IS_NULL_CHECK_PREDICATE = MetadataFlag(F.IS_NULL_CHECK_PREDICATE)
|
||||
}
|
||||
}
|
||||
fun flagsOf(vararg flags: Flag): Flags =
|
||||
flags.fold(0) { acc, flag -> flag + acc }
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlinx.metadata
|
||||
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags.BooleanFlagField
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags.FlagField
|
||||
|
||||
/**
|
||||
* Represents a boolean flag that is either present or not in a Kotlin declaration.
|
||||
*
|
||||
* @see Flags
|
||||
*/
|
||||
class MetadataFlag internal constructor(
|
||||
private val offset: Int,
|
||||
private val bitWidth: Int,
|
||||
private val value: Int
|
||||
) {
|
||||
internal constructor(field: FlagField<*>, value: Int) : this(field.offset, field.bitWidth, value)
|
||||
|
||||
internal constructor(field: BooleanFlagField) : this(field, 1)
|
||||
|
||||
internal operator fun plus(flags: Int): Int =
|
||||
(flags and (((1 shl bitWidth) - 1) shl offset).inv()) + (value shl offset)
|
||||
|
||||
/**
|
||||
* Checks whether the flag is present in the given bitmask.
|
||||
*/
|
||||
operator fun invoke(flags: Int): Boolean =
|
||||
(flags ushr offset) and ((1 shl bitWidth) - 1) == value
|
||||
}
|
||||
@@ -8,7 +8,7 @@ package kotlinx.metadata
|
||||
/**
|
||||
* Represents an annotation, written to the Kotlin metadata. Note that not all annotations are written to metadata on all platforms.
|
||||
* For example, on JVM most of the annotations are written directly on the corresponding declarations in the class file,
|
||||
* and entries in the metadata only have a flag ([Flags.HAS_ANNOTATIONS]) to signal if they do have annotations in the bytecode.
|
||||
* and entries in the metadata only have a flag ([Flag.HAS_ANNOTATIONS]) to signal if they do have annotations in the bytecode.
|
||||
* On JVM, only annotations on type parameters and types are serialized to the Kotlin metadata.
|
||||
*
|
||||
* @param className the fully qualified name of the annotation class
|
||||
|
||||
@@ -9,8 +9,8 @@ import kotlinx.metadata.*
|
||||
import kotlinx.metadata.impl.extensions.MetadataExtensions
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.*
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags
|
||||
import org.jetbrains.kotlin.protobuf.MessageLite
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags as F
|
||||
|
||||
class ReadContext(
|
||||
internal val strings: NameResolver,
|
||||
@@ -104,8 +104,8 @@ private fun KmDeclarationContainerVisitor.visitDeclarations(
|
||||
|
||||
for (property in properties) {
|
||||
val flags = property.flags
|
||||
val defaultAccessorFlags = Flags.getAccessorFlags(
|
||||
Flags.HAS_ANNOTATIONS.get(flags), Flags.VISIBILITY.get(flags), Flags.MODALITY.get(flags), false, false, false
|
||||
val defaultAccessorFlags = F.getAccessorFlags(
|
||||
F.HAS_ANNOTATIONS.get(flags), F.VISIBILITY.get(flags), F.MODALITY.get(flags), false, false, false
|
||||
)
|
||||
visitProperty(
|
||||
flags,
|
||||
@@ -242,7 +242,7 @@ private fun ProtoBuf.ValueParameter.accept(v: KmValueParameterVisitor, c: ReadCo
|
||||
}
|
||||
|
||||
private inline fun ProtoBuf.TypeParameter.accept(
|
||||
visit: (flags: Int, name: String, id: Int, variance: KmVariance) -> KmTypeParameterVisitor?,
|
||||
visit: (flags: Flags, name: String, id: Int, variance: KmVariance) -> KmTypeParameterVisitor?,
|
||||
c: ReadContext
|
||||
) {
|
||||
val variance = when (variance!!) {
|
||||
@@ -405,9 +405,9 @@ private fun ProtoBuf.Expression.accept(v: KmEffectExpressionVisitor, c: ReadCont
|
||||
v.visitEnd()
|
||||
}
|
||||
|
||||
private val ProtoBuf.Type.typeFlags: Int
|
||||
private val ProtoBuf.Type.typeFlags: Flags
|
||||
get() = (if (nullable) 1 shl 0 else 0) +
|
||||
(flags shl 1)
|
||||
|
||||
private val ProtoBuf.TypeParameter.typeParameterFlags: Int
|
||||
private val ProtoBuf.TypeParameter.typeParameterFlags: Flags
|
||||
get() = if (reified) 1 else 0
|
||||
|
||||
@@ -25,13 +25,13 @@ class WriteContext {
|
||||
}
|
||||
|
||||
private fun writeTypeParameter(
|
||||
c: WriteContext, flags: Int, name: String, id: Int, variance: KmVariance,
|
||||
c: WriteContext, flags: Flags, name: String, id: Int, variance: KmVariance,
|
||||
output: (ProtoBuf.TypeParameter.Builder) -> Unit
|
||||
): KmTypeParameterVisitor =
|
||||
object : KmTypeParameterVisitor() {
|
||||
private val t = ProtoBuf.TypeParameter.newBuilder()
|
||||
|
||||
override fun visitUpperBound(flags: Int): KmTypeVisitor? =
|
||||
override fun visitUpperBound(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.addUpperBound(it) }
|
||||
|
||||
override fun visitExtensions(type: KmExtensionType): KmTypeParameterExtensionVisitor? =
|
||||
@@ -40,7 +40,7 @@ private fun writeTypeParameter(
|
||||
override fun visitEnd() {
|
||||
t.name = c[name]
|
||||
t.id = id
|
||||
val reified = Flags.TypeParameter.IS_REIFIED(flags)
|
||||
val reified = Flag.TypeParameter.IS_REIFIED(flags)
|
||||
if (reified != ProtoBuf.TypeParameter.getDefaultInstance().reified) {
|
||||
t.reified = reified
|
||||
}
|
||||
@@ -53,7 +53,7 @@ private fun writeTypeParameter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeType(c: WriteContext, flags: Int, output: (ProtoBuf.Type.Builder) -> Unit): KmTypeVisitor =
|
||||
private fun writeType(c: WriteContext, flags: Flags, output: (ProtoBuf.Type.Builder) -> Unit): KmTypeVisitor =
|
||||
object : KmTypeVisitor() {
|
||||
private val t = ProtoBuf.Type.newBuilder()
|
||||
|
||||
@@ -71,7 +71,7 @@ private fun writeType(c: WriteContext, flags: Int, output: (ProtoBuf.Type.Builde
|
||||
})
|
||||
}
|
||||
|
||||
override fun visitArgument(flags: Int, variance: KmVariance): KmTypeVisitor? =
|
||||
override fun visitArgument(flags: Flags, variance: KmVariance): KmTypeVisitor? =
|
||||
writeType(c, flags) { argument ->
|
||||
t.addArgument(ProtoBuf.Type.Argument.newBuilder().apply {
|
||||
if (variance == KmVariance.IN) {
|
||||
@@ -87,13 +87,13 @@ private fun writeType(c: WriteContext, flags: Int, output: (ProtoBuf.Type.Builde
|
||||
t.typeParameter = id
|
||||
}
|
||||
|
||||
override fun visitAbbreviatedType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitAbbreviatedType(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.abbreviatedType = it.build() }
|
||||
|
||||
override fun visitOuterType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitOuterType(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.outerType = it.build() }
|
||||
|
||||
override fun visitFlexibleTypeUpperBound(flags: Int, typeFlexibilityId: String?): KmTypeVisitor? =
|
||||
override fun visitFlexibleTypeUpperBound(flags: Flags, typeFlexibilityId: String?): KmTypeVisitor? =
|
||||
writeType(c, flags) {
|
||||
if (typeFlexibilityId != null) {
|
||||
t.flexibleTypeCapabilitiesId = c[typeFlexibilityId]
|
||||
@@ -105,7 +105,7 @@ private fun writeType(c: WriteContext, flags: Int, output: (ProtoBuf.Type.Builde
|
||||
c.extensions.writeTypeExtensions(type, t, c.strings)
|
||||
|
||||
override fun visitEnd() {
|
||||
if (Flags.Type.IS_NULLABLE(flags)) {
|
||||
if (Flag.Type.IS_NULLABLE(flags)) {
|
||||
t.nullable = true
|
||||
}
|
||||
val flagsToWrite = flags shr 1
|
||||
@@ -116,11 +116,11 @@ private fun writeType(c: WriteContext, flags: Int, output: (ProtoBuf.Type.Builde
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeConstructor(c: WriteContext, flags: Int, output: (ProtoBuf.Constructor.Builder) -> Unit): KmConstructorVisitor =
|
||||
private fun writeConstructor(c: WriteContext, flags: Flags, output: (ProtoBuf.Constructor.Builder) -> Unit): KmConstructorVisitor =
|
||||
object : KmConstructorVisitor() {
|
||||
val t = ProtoBuf.Constructor.newBuilder()
|
||||
|
||||
override fun visitValueParameter(flags: Int, name: String): KmValueParameterVisitor? =
|
||||
override fun visitValueParameter(flags: Flags, name: String): KmValueParameterVisitor? =
|
||||
writeValueParameter(c, flags, name) { t.addValueParameter(it.build()) }
|
||||
|
||||
override fun visitVersionRequirement(): KmVersionRequirementVisitor? =
|
||||
@@ -137,20 +137,20 @@ private fun writeConstructor(c: WriteContext, flags: Int, output: (ProtoBuf.Cons
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeFunction(c: WriteContext, flags: Int, name: String, output: (ProtoBuf.Function.Builder) -> Unit): KmFunctionVisitor =
|
||||
private fun writeFunction(c: WriteContext, flags: Flags, name: String, output: (ProtoBuf.Function.Builder) -> Unit): KmFunctionVisitor =
|
||||
object : KmFunctionVisitor() {
|
||||
val t = ProtoBuf.Function.newBuilder()
|
||||
|
||||
override fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
override fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
writeTypeParameter(c, flags, name, id, variance) { t.addTypeParameter(it) }
|
||||
|
||||
override fun visitReceiverParameterType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitReceiverParameterType(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.receiverType = it.build() }
|
||||
|
||||
override fun visitValueParameter(flags: Int, name: String): KmValueParameterVisitor? =
|
||||
override fun visitValueParameter(flags: Flags, name: String): KmValueParameterVisitor? =
|
||||
writeValueParameter(c, flags, name) { t.addValueParameter(it) }
|
||||
|
||||
override fun visitReturnType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitReturnType(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.returnType = it.build() }
|
||||
|
||||
override fun visitVersionRequirement(): KmVersionRequirementVisitor? =
|
||||
@@ -172,20 +172,20 @@ private fun writeFunction(c: WriteContext, flags: Int, name: String, output: (Pr
|
||||
}
|
||||
|
||||
private fun writeProperty(
|
||||
c: WriteContext, flags: Int, name: String, getterFlags: Int, setterFlags: Int, output: (ProtoBuf.Property.Builder) -> Unit
|
||||
c: WriteContext, flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags, output: (ProtoBuf.Property.Builder) -> Unit
|
||||
): KmPropertyVisitor = object : KmPropertyVisitor() {
|
||||
val t = ProtoBuf.Property.newBuilder()
|
||||
|
||||
override fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
override fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
writeTypeParameter(c, flags, name, id, variance) { t.addTypeParameter(it) }
|
||||
|
||||
override fun visitReceiverParameterType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitReceiverParameterType(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.receiverType = it.build() }
|
||||
|
||||
override fun visitSetterParameter(flags: Int, name: String): KmValueParameterVisitor? =
|
||||
override fun visitSetterParameter(flags: Flags, name: String): KmValueParameterVisitor? =
|
||||
writeValueParameter(c, flags, name) { t.setterValueParameter = it.build() }
|
||||
|
||||
override fun visitReturnType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitReturnType(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.returnType = it.build() }
|
||||
|
||||
override fun visitVersionRequirement(): KmVersionRequirementVisitor? =
|
||||
@@ -207,15 +207,15 @@ private fun writeProperty(
|
||||
}
|
||||
|
||||
private fun writeValueParameter(
|
||||
c: WriteContext, flags: Int, name: String,
|
||||
c: WriteContext, flags: Flags, name: String,
|
||||
output: (ProtoBuf.ValueParameter.Builder) -> Unit
|
||||
): KmValueParameterVisitor = object : KmValueParameterVisitor() {
|
||||
val t = ProtoBuf.ValueParameter.newBuilder()
|
||||
|
||||
override fun visitType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitType(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.type = it.build() }
|
||||
|
||||
override fun visitVarargElementType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitVarargElementType(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.varargElementType = it.build() }
|
||||
|
||||
override fun visitEnd() {
|
||||
@@ -228,18 +228,18 @@ private fun writeValueParameter(
|
||||
}
|
||||
|
||||
private fun writeTypeAlias(
|
||||
c: WriteContext, flags: Int, name: String,
|
||||
c: WriteContext, flags: Flags, name: String,
|
||||
output: (ProtoBuf.TypeAlias.Builder) -> Unit
|
||||
): KmTypeAliasVisitor = object : KmTypeAliasVisitor() {
|
||||
val t = ProtoBuf.TypeAlias.newBuilder()
|
||||
|
||||
override fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
override fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
writeTypeParameter(c, flags, name, id, variance) { t.addTypeParameter(it) }
|
||||
|
||||
override fun visitUnderlyingType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitUnderlyingType(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.underlyingType = it.build() }
|
||||
|
||||
override fun visitExpandedType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitExpandedType(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.expandedType = it.build() }
|
||||
|
||||
override fun visitAnnotation(annotation: KmAnnotation) {
|
||||
@@ -351,7 +351,7 @@ private fun writeEffectExpression(c: WriteContext, output: (ProtoBuf.Expression.
|
||||
object : KmEffectExpressionVisitor() {
|
||||
val t = ProtoBuf.Expression.newBuilder()
|
||||
|
||||
override fun visit(flags: Int, parameterIndex: Int?) {
|
||||
override fun visit(flags: Flags, parameterIndex: Int?) {
|
||||
if (flags != ProtoBuf.Expression.getDefaultInstance().flags) {
|
||||
t.flags = flags
|
||||
}
|
||||
@@ -370,7 +370,7 @@ private fun writeEffectExpression(c: WriteContext, output: (ProtoBuf.Expression.
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitIsInstanceType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitIsInstanceType(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.isInstanceType = it.build() }
|
||||
|
||||
override fun visitAndArgument(): KmEffectExpressionVisitor? =
|
||||
@@ -388,29 +388,29 @@ open class ClassWriter : KmClassVisitor() {
|
||||
val t = ProtoBuf.Class.newBuilder()!!
|
||||
val c = WriteContext()
|
||||
|
||||
override fun visit(flags: Int, name: ClassName) {
|
||||
override fun visit(flags: Flags, name: ClassName) {
|
||||
if (flags != ProtoBuf.Class.getDefaultInstance().flags) {
|
||||
t.flags = flags
|
||||
}
|
||||
t.fqName = c.getClassName(name)
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
override fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
writeTypeParameter(c, flags, name, id, variance) { t.addTypeParameter(it) }
|
||||
|
||||
override fun visitSupertype(flags: Int): KmTypeVisitor? =
|
||||
override fun visitSupertype(flags: Flags): KmTypeVisitor? =
|
||||
writeType(c, flags) { t.addSupertype(it) }
|
||||
|
||||
override fun visitConstructor(flags: Int): KmConstructorVisitor? =
|
||||
override fun visitConstructor(flags: Flags): KmConstructorVisitor? =
|
||||
writeConstructor(c, flags) { t.addConstructor(it) }
|
||||
|
||||
override fun visitFunction(flags: Int, name: String): KmFunctionVisitor? =
|
||||
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? =
|
||||
writeFunction(c, flags, name) { t.addFunction(it) }
|
||||
|
||||
override fun visitProperty(flags: Int, name: String, getterFlags: Int, setterFlags: Int): KmPropertyVisitor? =
|
||||
override fun visitProperty(flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags): KmPropertyVisitor? =
|
||||
writeProperty(c, flags, name, getterFlags, setterFlags) { t.addProperty(it) }
|
||||
|
||||
override fun visitTypeAlias(flags: Int, name: String): KmTypeAliasVisitor? =
|
||||
override fun visitTypeAlias(flags: Flags, name: String): KmTypeAliasVisitor? =
|
||||
writeTypeAlias(c, flags, name) { t.addTypeAlias(it) }
|
||||
|
||||
override fun visitCompanionObject(name: String) {
|
||||
@@ -445,13 +445,13 @@ open class PackageWriter : KmPackageVisitor() {
|
||||
val t = ProtoBuf.Package.newBuilder()!!
|
||||
val c = WriteContext()
|
||||
|
||||
override fun visitFunction(flags: Int, name: String): KmFunctionVisitor? =
|
||||
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? =
|
||||
writeFunction(c, flags, name) { t.addFunction(it) }
|
||||
|
||||
override fun visitProperty(flags: Int, name: String, getterFlags: Int, setterFlags: Int): KmPropertyVisitor? =
|
||||
override fun visitProperty(flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags): KmPropertyVisitor? =
|
||||
writeProperty(c, flags, name, getterFlags, setterFlags) { t.addProperty(it) }
|
||||
|
||||
override fun visitTypeAlias(flags: Int, name: String): KmTypeAliasVisitor? =
|
||||
override fun visitTypeAlias(flags: Flags, name: String): KmTypeAliasVisitor? =
|
||||
writeTypeAlias(c, flags, name) { t.addTypeAlias(it) }
|
||||
|
||||
override fun visitEnd() {
|
||||
@@ -465,6 +465,6 @@ open class LambdaWriter : KmLambdaVisitor() {
|
||||
var t: ProtoBuf.Function.Builder? = null
|
||||
val c = WriteContext()
|
||||
|
||||
override fun visitFunction(flags: Int, name: String): KmFunctionVisitor? =
|
||||
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? =
|
||||
writeFunction(c, flags, name) { t = it }
|
||||
}
|
||||
|
||||
@@ -12,32 +12,32 @@ abstract class KmDeclarationContainerVisitor @JvmOverloads constructor(protected
|
||||
/**
|
||||
* Visits a function in the container.
|
||||
*
|
||||
* @param flags function flags, consisting of [Flags.HAS_ANNOTATIONS], visibility flag, modality flag and [Flags.Function] flags
|
||||
* @param flags function flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag, modality flag and [Flag.Function] flags
|
||||
* @param name the name of the function
|
||||
*/
|
||||
open fun visitFunction(flags: Int, name: String): KmFunctionVisitor? =
|
||||
open fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? =
|
||||
delegate?.visitFunction(flags, name)
|
||||
|
||||
/**
|
||||
* Visits a property in the container.
|
||||
*
|
||||
* @param flags property flags, consisting of [Flags.HAS_ANNOTATIONS], visibility flag, modality flag and [Flags.Property] flags
|
||||
* @param flags property flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag, modality flag and [Flag.Property] flags
|
||||
* @param name the name of the property
|
||||
* @param getterFlags property accessor flags, consisting of [Flags.HAS_ANNOTATIONS], visibility flag, modality flag
|
||||
* and [Flags.PropertyAccessor] flags
|
||||
* @param setterFlags property accessor flags, consisting of [Flags.HAS_ANNOTATIONS], visibility flag, modality flag
|
||||
* and [Flags.PropertyAccessor] flags
|
||||
* @param getterFlags property accessor flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag, modality flag
|
||||
* and [Flag.PropertyAccessor] flags
|
||||
* @param setterFlags property accessor flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag, modality flag
|
||||
* and [Flag.PropertyAccessor] flags
|
||||
*/
|
||||
open fun visitProperty(flags: Int, name: String, getterFlags: Int, setterFlags: Int): KmPropertyVisitor? =
|
||||
open fun visitProperty(flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags): KmPropertyVisitor? =
|
||||
delegate?.visitProperty(flags, name, getterFlags, setterFlags)
|
||||
|
||||
/**
|
||||
* Visits a type alias in the container.
|
||||
*
|
||||
* @param flags type alias flags, consisting of [Flags.HAS_ANNOTATIONS] and visibility flag
|
||||
* @param flags type alias flags, consisting of [Flag.HAS_ANNOTATIONS] and visibility flag
|
||||
* @param name the name of the type alias
|
||||
*/
|
||||
open fun visitTypeAlias(flags: Int, name: String): KmTypeAliasVisitor? =
|
||||
open fun visitTypeAlias(flags: Flags, name: String): KmTypeAliasVisitor? =
|
||||
delegate?.visitTypeAlias(flags, name)
|
||||
}
|
||||
|
||||
@@ -54,39 +54,39 @@ abstract class KmClassVisitor @JvmOverloads constructor(delegate: KmClassVisitor
|
||||
/**
|
||||
* Visits the basic information about the class.
|
||||
*
|
||||
* @param flags class flags, consisting of [Flags.HAS_ANNOTATIONS], visibility flag, modality flag and [Flags.Class] flags
|
||||
* @param flags class flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag, modality flag and [Flag.Class] flags
|
||||
* @param name the name of the class
|
||||
*/
|
||||
open fun visit(flags: Int, name: ClassName) {
|
||||
open fun visit(flags: Flags, name: ClassName) {
|
||||
delegate?.visit(flags, name)
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a type parameter of the class.
|
||||
*
|
||||
* @param flags type parameter flags, consisting of [Flags.TypeParameter] flags
|
||||
* @param flags type parameter flags, consisting of [Flag.TypeParameter] flags
|
||||
* @param name the name of the type parameter
|
||||
* @param id the id of the type parameter, useful to be able to uniquely identify the type parameter in different contexts where
|
||||
* the name isn't enough (e.g. `class A<T> { fun <T> foo(t: T) }`)
|
||||
* @param variance the declaration-site variance of the type parameter
|
||||
*/
|
||||
open fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
open fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
delegate?.visitTypeParameter(flags, name, id, variance)
|
||||
|
||||
/**
|
||||
* Visits a supertype of the class.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitSupertype(flags: Int): KmTypeVisitor? =
|
||||
open fun visitSupertype(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitSupertype(flags)
|
||||
|
||||
/**
|
||||
* Visits a constructor of the class.
|
||||
*
|
||||
* @param flags constructor flags, consisting of [Flags.HAS_ANNOTATIONS], visibility flag and [Flags.Constructor] flags
|
||||
* @param flags constructor flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag and [Flag.Constructor] flags
|
||||
*/
|
||||
open fun visitConstructor(flags: Int): KmConstructorVisitor? =
|
||||
open fun visitConstructor(flags: Flags): KmConstructorVisitor? =
|
||||
delegate?.visitConstructor(flags)
|
||||
|
||||
/**
|
||||
@@ -165,10 +165,10 @@ abstract class KmLambdaVisitor @JvmOverloads constructor(private val delegate: K
|
||||
/**
|
||||
* Visits the signature of a synthetic anonymous function, representing the lambda.
|
||||
*
|
||||
* @param flags function flags, consisting of [Flags.HAS_ANNOTATIONS], visibility flag, modality flag and [Flags.Function] flags
|
||||
* @param flags function flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag, modality flag and [Flag.Function] flags
|
||||
* @param name the name of the function (usually `"<anonymous>"` or `"<no name provided>"` for lambdas emitted by the Kotlin compiler)
|
||||
*/
|
||||
open fun visitFunction(flags: Int, name: String): KmFunctionVisitor? =
|
||||
open fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? =
|
||||
delegate?.visitFunction(flags, name)
|
||||
|
||||
/**
|
||||
@@ -188,10 +188,10 @@ abstract class KmConstructorVisitor @JvmOverloads constructor(private val delega
|
||||
/**
|
||||
* Visits a value parameter of the constructor.
|
||||
*
|
||||
* @param flags value parameter flags, consisting of [Flags.ValueParameter] flags
|
||||
* @param flags value parameter flags, consisting of [Flag.ValueParameter] flags
|
||||
* @param name the name of the value parameter
|
||||
*/
|
||||
open fun visitValueParameter(flags: Int, name: String): KmValueParameterVisitor? =
|
||||
open fun visitValueParameter(flags: Flags, name: String): KmValueParameterVisitor? =
|
||||
delegate?.visitValueParameter(flags, name)
|
||||
|
||||
/**
|
||||
@@ -226,38 +226,38 @@ abstract class KmFunctionVisitor @JvmOverloads constructor(private val delegate:
|
||||
/**
|
||||
* Visits a type parameter of the function.
|
||||
*
|
||||
* @param flags type parameter flags, consisting of [Flags.TypeParameter] flags
|
||||
* @param flags type parameter flags, consisting of [Flag.TypeParameter] flags
|
||||
* @param name the name of the type parameter
|
||||
* @param id the id of the type parameter, useful to be able to uniquely identify the type parameter in different contexts where
|
||||
* the name isn't enough (e.g. `class A<T> { fun <T> foo(t: T) }`)
|
||||
* @param variance the declaration-site variance of the type parameter
|
||||
*/
|
||||
open fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
open fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
delegate?.visitTypeParameter(flags, name, id, variance)
|
||||
|
||||
/**
|
||||
* Visits the type of the receiver of the function, if this is an extension function.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitReceiverParameterType(flags: Int): KmTypeVisitor? =
|
||||
open fun visitReceiverParameterType(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitReceiverParameterType(flags)
|
||||
|
||||
/**
|
||||
* Visits a value parameter of the function.
|
||||
*
|
||||
* @param flags value parameter flags, consisting of [Flags.ValueParameter] flags
|
||||
* @param flags value parameter flags, consisting of [Flag.ValueParameter] flags
|
||||
* @param name the name of the value parameter
|
||||
*/
|
||||
open fun visitValueParameter(flags: Int, name: String): KmValueParameterVisitor? =
|
||||
open fun visitValueParameter(flags: Flags, name: String): KmValueParameterVisitor? =
|
||||
delegate?.visitValueParameter(flags, name)
|
||||
|
||||
/**
|
||||
* Visits the return type of the function.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitReturnType(flags: Int): KmTypeVisitor? =
|
||||
open fun visitReturnType(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitReturnType(flags)
|
||||
|
||||
/**
|
||||
@@ -298,38 +298,38 @@ abstract class KmPropertyVisitor @JvmOverloads constructor(private val delegate:
|
||||
/**
|
||||
* Visits a type parameter of the property.
|
||||
*
|
||||
* @param flags type parameter flags, consisting of [Flags.TypeParameter] flags
|
||||
* @param flags type parameter flags, consisting of [Flag.TypeParameter] flags
|
||||
* @param name the name of the type parameter
|
||||
* @param id the id of the type parameter, useful to be able to uniquely identify the type parameter in different contexts where
|
||||
* the name isn't enough (e.g. `class A<T> { fun <T> foo(t: T) }`)
|
||||
* @param variance the declaration-site variance of the type parameter
|
||||
*/
|
||||
open fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
open fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
delegate?.visitTypeParameter(flags, name, id, variance)
|
||||
|
||||
/**
|
||||
* Visits the type of the receiver of the property, if this is an extension property.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitReceiverParameterType(flags: Int): KmTypeVisitor? =
|
||||
open fun visitReceiverParameterType(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitReceiverParameterType(flags)
|
||||
|
||||
/**
|
||||
* Visits a value parameter of the setter of this property, if this is a `var` property.
|
||||
*
|
||||
* @param flags value parameter flags, consisting of [Flags.ValueParameter] flags
|
||||
* @param flags value parameter flags, consisting of [Flag.ValueParameter] flags
|
||||
* @param name the name of the value parameter (`"<set-?>"` for properties emitted by the Kotlin compiler)
|
||||
*/
|
||||
open fun visitSetterParameter(flags: Int, name: String): KmValueParameterVisitor? =
|
||||
open fun visitSetterParameter(flags: Flags, name: String): KmValueParameterVisitor? =
|
||||
delegate?.visitSetterParameter(flags, name)
|
||||
|
||||
/**
|
||||
* Visits the type of the property.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitReturnType(flags: Int): KmTypeVisitor? =
|
||||
open fun visitReturnType(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitReturnType(flags)
|
||||
|
||||
/**
|
||||
@@ -364,30 +364,30 @@ abstract class KmTypeAliasVisitor @JvmOverloads constructor(private val delegate
|
||||
/**
|
||||
* Visits a type parameter of the type alias.
|
||||
*
|
||||
* @param flags type parameter flags, consisting of [Flags.TypeParameter] flags
|
||||
* @param flags type parameter flags, consisting of [Flag.TypeParameter] flags
|
||||
* @param name the name of the type parameter
|
||||
* @param id the id of the type parameter, useful to be able to uniquely identify the type parameter in different contexts where
|
||||
* the name isn't enough (e.g. `class A<T> { fun <T> foo(t: T) }`)
|
||||
* @param variance the declaration-site variance of the type parameter
|
||||
*/
|
||||
open fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
open fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
delegate?.visitTypeParameter(flags, name, id, variance)
|
||||
|
||||
/**
|
||||
* Visits the underlying type of the type alias, i.e. the type in the right-hand side of the type alias declaration.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitUnderlyingType(flags: Int): KmTypeVisitor? =
|
||||
open fun visitUnderlyingType(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitUnderlyingType(flags)
|
||||
|
||||
/**
|
||||
* Visits the expanded type of the type alias, i.e. the full expansion of the underlying type, where all type aliases are substituted
|
||||
* with their expanded types. If not type aliases are used in the underlying type, expanded type is equal to the underlying type.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitExpandedType(flags: Int): KmTypeVisitor? =
|
||||
open fun visitExpandedType(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitExpandedType(flags)
|
||||
|
||||
/**
|
||||
@@ -423,17 +423,17 @@ abstract class KmValueParameterVisitor @JvmOverloads constructor(private val del
|
||||
/**
|
||||
* Visits the type of the value parameter, if this is **not** a `vararg` parameter.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitType(flags: Int): KmTypeVisitor? =
|
||||
open fun visitType(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitType(flags)
|
||||
|
||||
/**
|
||||
* Visits the type of the value parameter, if this is a `vararg` parameter.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitVarargElementType(flags: Int): KmTypeVisitor? =
|
||||
open fun visitVarargElementType(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitVarargElementType(flags)
|
||||
|
||||
/**
|
||||
@@ -453,9 +453,9 @@ abstract class KmTypeParameterVisitor @JvmOverloads constructor(private val dele
|
||||
/**
|
||||
* Visits the upper bound of the type parameter.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitUpperBound(flags: Int): KmTypeVisitor? =
|
||||
open fun visitUpperBound(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitUpperBound(flags)
|
||||
|
||||
/**
|
||||
@@ -518,10 +518,10 @@ abstract class KmTypeVisitor @JvmOverloads constructor(private val delegate: KmT
|
||||
* Visits the type projection used in a type argument of the type based on a class or on a type alias.
|
||||
* For example, in `MutableMap<in String?, *>`, `in String?` is the type projection which is the first type argument of the type.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
* @param variance the variance of the type projection
|
||||
*/
|
||||
open fun visitArgument(flags: Int, variance: KmVariance): KmTypeVisitor? =
|
||||
open fun visitArgument(flags: Flags, variance: KmVariance): KmTypeVisitor? =
|
||||
delegate?.visitArgument(flags, variance)
|
||||
|
||||
/**
|
||||
@@ -541,9 +541,9 @@ abstract class KmTypeVisitor @JvmOverloads constructor(private val delegate: KmT
|
||||
*
|
||||
* The type of the `foo`'s parameter in the metadata is actually `MutableList<Any>`, and its abbreviation is `A<Any>`.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitAbbreviatedType(flags: Int): KmTypeVisitor? =
|
||||
open fun visitAbbreviatedType(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitAbbreviatedType(flags)
|
||||
|
||||
/**
|
||||
@@ -556,20 +556,20 @@ abstract class KmTypeVisitor @JvmOverloads constructor(private val delegate: KmT
|
||||
* The type of the `foo`'s parameter in the metadata is `B<Byte>` (a type whose classifier is class `B`, and it has one type argument,
|
||||
* type `Byte?`), and its outer type is `A<*>` (a type whose classifier is class `A`, and it has one type argument, star projection).
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitOuterType(flags: Int): KmTypeVisitor? =
|
||||
open fun visitOuterType(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitOuterType(flags)
|
||||
|
||||
/**
|
||||
* Visits the upper bound of the type, marking it as flexible and its contents as the lower bound. Flexible types in Kotlin include
|
||||
* platform types in Kotlin/JVM and `dynamic` type in Kotlin/JS.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
* @param typeFlexibilityId id of the kind of flexibility this type has. For example, "kotlin.jvm.PlatformType" for JVM platform types,
|
||||
* or "kotlin.DynamicType" for JS dynamic type
|
||||
*/
|
||||
open fun visitFlexibleTypeUpperBound(flags: Int, typeFlexibilityId: String?): KmTypeVisitor? =
|
||||
open fun visitFlexibleTypeUpperBound(flags: Flags, typeFlexibilityId: String?): KmTypeVisitor? =
|
||||
delegate?.visitFlexibleTypeUpperBound(flags, typeFlexibilityId)
|
||||
|
||||
/**
|
||||
@@ -699,18 +699,18 @@ abstract class KmEffectVisitor @JvmOverloads constructor(private val delegate: K
|
||||
abstract class KmEffectExpressionVisitor @JvmOverloads constructor(private val delegate: KmEffectExpressionVisitor? = null) {
|
||||
/**
|
||||
* Visits the basic information of the effect expression.
|
||||
*
|
||||
* @param flags effect expression flags, consisting of [Flags.EffectExpression] flags
|
||||
*
|
||||
* @param flags effect expression flags, consisting of [Flag.EffectExpression] flags
|
||||
* @param parameterIndex optional 1-based index of the value parameter of the function, for effects which assert something about
|
||||
* the function parameters. The index 0 means the extension receiver parameter
|
||||
*/
|
||||
open fun visit(flags: Int, parameterIndex: Int?) {
|
||||
open fun visit(flags: Flags, parameterIndex: Int?) {
|
||||
delegate?.visit(flags, parameterIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits the constant value used in the effect expression. May be `true`, `false` or `null`.
|
||||
*
|
||||
*
|
||||
* @param value the constant value
|
||||
*/
|
||||
open fun visitConstantValue(value: Any?) {
|
||||
@@ -719,10 +719,10 @@ abstract class KmEffectExpressionVisitor @JvmOverloads constructor(private val d
|
||||
|
||||
/**
|
||||
* Visits the type used as the target of an `is`-expression in the effect expression.
|
||||
*
|
||||
* @param flags type flags, consisting of [Flags.Type] flags
|
||||
*
|
||||
* @param flags type flags, consisting of [Flag.Type] flags
|
||||
*/
|
||||
open fun visitIsInstanceType(flags: Int): KmTypeVisitor? =
|
||||
open fun visitIsInstanceType(flags: Flags): KmTypeVisitor? =
|
||||
delegate?.visitIsInstanceType(flags)
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@ private object SpecialCharacters {
|
||||
const val TYPE_ALIAS_MARKER = '^'
|
||||
}
|
||||
|
||||
private fun visitFunction(sb: StringBuilder, flags: Int, name: String): KmFunctionVisitor =
|
||||
private fun visitFunction(sb: StringBuilder, flags: Flags, name: String): KmFunctionVisitor =
|
||||
object : KmFunctionVisitor() {
|
||||
val typeParams = mutableListOf<String>()
|
||||
val params = mutableListOf<String>()
|
||||
@@ -21,18 +21,18 @@ private fun visitFunction(sb: StringBuilder, flags: Int, name: String): KmFuncti
|
||||
var versionRequirement: String? = null
|
||||
var jvmDesc: String? = null
|
||||
|
||||
override fun visitReceiverParameterType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitReceiverParameterType(flags: Flags): KmTypeVisitor? =
|
||||
printType(flags) { receiverParameterType = it }
|
||||
|
||||
override fun visitTypeParameter(
|
||||
flags: Int, name: String, id: Int, variance: KmVariance
|
||||
flags: Flags, name: String, id: Int, variance: KmVariance
|
||||
): KmTypeParameterVisitor? =
|
||||
printTypeParameter(flags, name, id, variance) { typeParams.add(it) }
|
||||
|
||||
override fun visitValueParameter(flags: Int, name: String): KmValueParameterVisitor? =
|
||||
override fun visitValueParameter(flags: Flags, name: String): KmValueParameterVisitor? =
|
||||
printValueParameter(flags, name) { params.add(it) }
|
||||
|
||||
override fun visitReturnType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitReturnType(flags: Flags): KmTypeVisitor? =
|
||||
printType(flags) { returnType = it }
|
||||
|
||||
override fun visitVersionRequirement(): KmVersionRequirementVisitor? =
|
||||
@@ -74,7 +74,7 @@ private fun visitFunction(sb: StringBuilder, flags: Int, name: String): KmFuncti
|
||||
}
|
||||
}
|
||||
|
||||
private fun visitProperty(sb: StringBuilder, flags: Int, name: String, getterFlags: Int, setterFlags: Int): KmPropertyVisitor =
|
||||
private fun visitProperty(sb: StringBuilder, flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags): KmPropertyVisitor =
|
||||
object : KmPropertyVisitor() {
|
||||
val typeParams = mutableListOf<String>()
|
||||
var receiverParameterType: String? = null
|
||||
@@ -87,16 +87,16 @@ private fun visitProperty(sb: StringBuilder, flags: Int, name: String, getterFla
|
||||
var jvmSetterDesc: String? = null
|
||||
var jvmSyntheticMethodForAnnotationsDesc: String? = null
|
||||
|
||||
override fun visitReceiverParameterType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitReceiverParameterType(flags: Flags): KmTypeVisitor? =
|
||||
printType(flags) { receiverParameterType = it }
|
||||
|
||||
override fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
override fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
printTypeParameter(flags, name, id, variance) { typeParams.add(it) }
|
||||
|
||||
override fun visitSetterParameter(flags: Int, name: String): KmValueParameterVisitor? =
|
||||
override fun visitSetterParameter(flags: Flags, name: String): KmValueParameterVisitor? =
|
||||
printValueParameter(flags, name) { setterParameter = it }
|
||||
|
||||
override fun visitReturnType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitReturnType(flags: Flags): KmTypeVisitor? =
|
||||
printType(flags) { returnType = it }
|
||||
|
||||
override fun visitVersionRequirement(): KmVersionRequirementVisitor? =
|
||||
@@ -141,7 +141,7 @@ private fun visitProperty(sb: StringBuilder, flags: Int, name: String, getterFla
|
||||
}
|
||||
sb.append(" ")
|
||||
sb.appendFlags(flags, PROPERTY_FLAGS_MAP)
|
||||
sb.append(if (Flags.Property.IS_VAR(flags)) "var " else "val ")
|
||||
sb.append(if (Flag.Property.IS_VAR(flags)) "var " else "val ")
|
||||
if (typeParams.isNotEmpty()) {
|
||||
typeParams.joinTo(sb, prefix = "<", postfix = ">")
|
||||
sb.append(" ")
|
||||
@@ -153,16 +153,16 @@ private fun visitProperty(sb: StringBuilder, flags: Int, name: String, getterFla
|
||||
if (returnType != null) {
|
||||
sb.append(": ").append(returnType)
|
||||
}
|
||||
if (Flags.Property.HAS_CONSTANT(flags)) {
|
||||
if (Flag.Property.HAS_CONSTANT(flags)) {
|
||||
sb.append(" /* = ... */")
|
||||
}
|
||||
sb.appendln()
|
||||
if (Flags.Property.HAS_GETTER(flags)) {
|
||||
if (Flag.Property.HAS_GETTER(flags)) {
|
||||
sb.append(" ")
|
||||
sb.appendFlags(getterFlags, PROPERTY_ACCESSOR_FLAGS_MAP)
|
||||
sb.appendln("get")
|
||||
}
|
||||
if (Flags.Property.HAS_SETTER(flags)) {
|
||||
if (Flag.Property.HAS_SETTER(flags)) {
|
||||
sb.append(" ")
|
||||
sb.appendFlags(setterFlags, PROPERTY_ACCESSOR_FLAGS_MAP)
|
||||
sb.append("set")
|
||||
@@ -174,13 +174,13 @@ private fun visitProperty(sb: StringBuilder, flags: Int, name: String, getterFla
|
||||
}
|
||||
}
|
||||
|
||||
private fun visitConstructor(sb: StringBuilder, flags: Int): KmConstructorVisitor =
|
||||
private fun visitConstructor(sb: StringBuilder, flags: Flags): KmConstructorVisitor =
|
||||
object : KmConstructorVisitor() {
|
||||
val params = mutableListOf<String>()
|
||||
var versionRequirement: String? = null
|
||||
var jvmDesc: String? = null
|
||||
|
||||
override fun visitValueParameter(flags: Int, name: String): KmValueParameterVisitor? =
|
||||
override fun visitValueParameter(flags: Flags, name: String): KmValueParameterVisitor? =
|
||||
printValueParameter(flags, name) { params.add(it) }
|
||||
|
||||
override fun visitVersionRequirement(): KmVersionRequirementVisitor? =
|
||||
@@ -211,7 +211,7 @@ private fun visitConstructor(sb: StringBuilder, flags: Int): KmConstructorVisito
|
||||
}
|
||||
}
|
||||
|
||||
private fun visitTypeAlias(sb: StringBuilder, flags: Int, name: String): KmTypeAliasVisitor =
|
||||
private fun visitTypeAlias(sb: StringBuilder, flags: Flags, name: String): KmTypeAliasVisitor =
|
||||
object : KmTypeAliasVisitor() {
|
||||
val annotations = mutableListOf<KmAnnotation>()
|
||||
val typeParams = mutableListOf<String>()
|
||||
@@ -219,13 +219,13 @@ private fun visitTypeAlias(sb: StringBuilder, flags: Int, name: String): KmTypeA
|
||||
var expandedType: String? = null
|
||||
var versionRequirement: String? = null
|
||||
|
||||
override fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
override fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
printTypeParameter(flags, name, id, variance) { typeParams.add(it) }
|
||||
|
||||
override fun visitUnderlyingType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitUnderlyingType(flags: Flags): KmTypeVisitor? =
|
||||
printType(flags) { underlyingType = it }
|
||||
|
||||
override fun visitExpandedType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitExpandedType(flags: Flags): KmTypeVisitor? =
|
||||
printType(flags) { expandedType = it }
|
||||
|
||||
override fun visitAnnotation(annotation: KmAnnotation) {
|
||||
@@ -259,7 +259,7 @@ private fun visitTypeAlias(sb: StringBuilder, flags: Int, name: String): KmTypeA
|
||||
}
|
||||
}
|
||||
|
||||
private fun printType(flags: Int, output: (String) -> Unit): KmTypeVisitor =
|
||||
private fun printType(flags: Flags, output: (String) -> Unit): KmTypeVisitor =
|
||||
object : KmTypeVisitor() {
|
||||
var classifier: String? = null
|
||||
val arguments = mutableListOf<String>()
|
||||
@@ -281,10 +281,10 @@ private fun printType(flags: Int, output: (String) -> Unit): KmTypeVisitor =
|
||||
classifier = "$name${SpecialCharacters.TYPE_ALIAS_MARKER}"
|
||||
}
|
||||
|
||||
override fun visitAbbreviatedType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitAbbreviatedType(flags: Flags): KmTypeVisitor? =
|
||||
printType(flags) { abbreviatedType = it }
|
||||
|
||||
override fun visitArgument(flags: Int, variance: KmVariance): KmTypeVisitor? =
|
||||
override fun visitArgument(flags: Flags, variance: KmVariance): KmTypeVisitor? =
|
||||
printType(flags) { argumentTypeString ->
|
||||
arguments += buildString {
|
||||
if (variance != KmVariance.INVARIANT) {
|
||||
@@ -298,10 +298,10 @@ private fun printType(flags: Int, output: (String) -> Unit): KmTypeVisitor =
|
||||
arguments += "*"
|
||||
}
|
||||
|
||||
override fun visitOuterType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitOuterType(flags: Flags): KmTypeVisitor? =
|
||||
printType(flags) { outerType = it }
|
||||
|
||||
override fun visitFlexibleTypeUpperBound(flags: Int, typeFlexibilityId: String?): KmTypeVisitor? =
|
||||
override fun visitFlexibleTypeUpperBound(flags: Flags, typeFlexibilityId: String?): KmTypeVisitor? =
|
||||
if (typeFlexibilityId == JvmTypeExtensionVisitor.PLATFORM_TYPE_ID) {
|
||||
printType(flags) { platformTypeUpperBound = it }
|
||||
} else null
|
||||
@@ -336,7 +336,7 @@ private fun printType(flags: Int, output: (String) -> Unit): KmTypeVisitor =
|
||||
if (arguments.isNotEmpty()) {
|
||||
arguments.joinTo(this, prefix = "<", postfix = ">")
|
||||
}
|
||||
if (Flags.Type.IS_NULLABLE(flags)) {
|
||||
if (Flag.Type.IS_NULLABLE(flags)) {
|
||||
append("?")
|
||||
}
|
||||
if (abbreviatedType != null) {
|
||||
@@ -352,12 +352,14 @@ private fun printType(flags: Int, output: (String) -> Unit): KmTypeVisitor =
|
||||
}
|
||||
}
|
||||
|
||||
private fun printTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance, output: (String) -> Unit): KmTypeParameterVisitor =
|
||||
private fun printTypeParameter(
|
||||
flags: Flags, name: String, id: Int, variance: KmVariance, output: (String) -> Unit
|
||||
): KmTypeParameterVisitor =
|
||||
object : KmTypeParameterVisitor() {
|
||||
val bounds = mutableListOf<String>()
|
||||
val jvmAnnotations = mutableListOf<KmAnnotation>()
|
||||
|
||||
override fun visitUpperBound(flags: Int): KmTypeVisitor? =
|
||||
override fun visitUpperBound(flags: Flags): KmTypeVisitor? =
|
||||
printType(flags) { bounds += it }
|
||||
|
||||
override fun visitExtensions(type: KmExtensionType): KmTypeParameterExtensionVisitor? {
|
||||
@@ -386,15 +388,15 @@ private fun printTypeParameter(flags: Int, name: String, id: Int, variance: KmVa
|
||||
}
|
||||
}
|
||||
|
||||
private fun printValueParameter(flags: Int, name: String, output: (String) -> Unit): KmValueParameterVisitor =
|
||||
private fun printValueParameter(flags: Flags, name: String, output: (String) -> Unit): KmValueParameterVisitor =
|
||||
object : KmValueParameterVisitor() {
|
||||
var varargElementType: String? = null
|
||||
var type: String? = null
|
||||
|
||||
override fun visitType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitType(flags: Flags): KmTypeVisitor? =
|
||||
printType(flags) { type = it }
|
||||
|
||||
override fun visitVarargElementType(flags: Int): KmTypeVisitor? =
|
||||
override fun visitVarargElementType(flags: Flags): KmTypeVisitor? =
|
||||
printType(flags) { varargElementType = it }
|
||||
|
||||
override fun visitEnd() {
|
||||
@@ -405,7 +407,7 @@ private fun printValueParameter(flags: Int, name: String, output: (String) -> Un
|
||||
} else {
|
||||
append(name).append(": ").append(type)
|
||||
}
|
||||
if (Flags.ValueParameter.DECLARES_DEFAULT_VALUE(flags)) {
|
||||
if (Flag.ValueParameter.DECLARES_DEFAULT_VALUE(flags)) {
|
||||
append(" /* = ... */")
|
||||
}
|
||||
})
|
||||
@@ -491,7 +493,7 @@ private fun printVersionRequirement(output: (String) -> Unit): KmVersionRequirem
|
||||
}
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendFlags(flags: Int, map: Map<MetadataFlag, String>) {
|
||||
private fun StringBuilder.appendFlags(flags: Flags, map: Map<Flag, String>) {
|
||||
for ((modifier, string) in map) {
|
||||
if (modifier(flags)) {
|
||||
append(string)
|
||||
@@ -508,13 +510,13 @@ class ClassPrinter : KmClassVisitor(), AbstractPrinter<KotlinClassMetadata.Class
|
||||
private val sb = StringBuilder()
|
||||
private val result = StringBuilder()
|
||||
|
||||
private var flags: Int? = null
|
||||
private var flags: Flags? = null
|
||||
private var name: ClassName? = null
|
||||
private val typeParams = mutableListOf<String>()
|
||||
private val supertypes = mutableListOf<String>()
|
||||
private var versionRequirement: String? = null
|
||||
|
||||
override fun visit(flags: Int, name: ClassName) {
|
||||
override fun visit(flags: Flags, name: ClassName) {
|
||||
this.flags = flags
|
||||
this.name = name
|
||||
}
|
||||
@@ -537,22 +539,22 @@ class ClassPrinter : KmClassVisitor(), AbstractPrinter<KotlinClassMetadata.Class
|
||||
result.appendln("}")
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
override fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor? =
|
||||
printTypeParameter(flags, name, id, variance) { typeParams.add(it) }
|
||||
|
||||
override fun visitSupertype(flags: Int): KmTypeVisitor? =
|
||||
override fun visitSupertype(flags: Flags): KmTypeVisitor? =
|
||||
printType(flags) { supertypes.add(it) }
|
||||
|
||||
override fun visitConstructor(flags: Int): KmConstructorVisitor? =
|
||||
override fun visitConstructor(flags: Flags): KmConstructorVisitor? =
|
||||
visitConstructor(sb, flags)
|
||||
|
||||
override fun visitFunction(flags: Int, name: String): KmFunctionVisitor? =
|
||||
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? =
|
||||
visitFunction(sb, flags, name)
|
||||
|
||||
override fun visitProperty(flags: Int, name: String, getterFlags: Int, setterFlags: Int): KmPropertyVisitor? =
|
||||
override fun visitProperty(flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags): KmPropertyVisitor? =
|
||||
visitProperty(sb, flags, name, getterFlags, setterFlags)
|
||||
|
||||
override fun visitTypeAlias(flags: Int, name: String): KmTypeAliasVisitor? =
|
||||
override fun visitTypeAlias(flags: Flags, name: String): KmTypeAliasVisitor? =
|
||||
visitTypeAlias(sb, flags, name)
|
||||
|
||||
override fun visitCompanionObject(name: String) {
|
||||
@@ -593,13 +595,13 @@ abstract class PackagePrinter : KmPackageVisitor() {
|
||||
sb.appendln("}")
|
||||
}
|
||||
|
||||
override fun visitFunction(flags: Int, name: String): KmFunctionVisitor? =
|
||||
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? =
|
||||
visitFunction(sb, flags, name)
|
||||
|
||||
override fun visitProperty(flags: Int, name: String, getterFlags: Int, setterFlags: Int): KmPropertyVisitor? =
|
||||
override fun visitProperty(flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags): KmPropertyVisitor? =
|
||||
visitProperty(sb, flags, name, getterFlags, setterFlags)
|
||||
|
||||
override fun visitTypeAlias(flags: Int, name: String): KmTypeAliasVisitor? =
|
||||
override fun visitTypeAlias(flags: Flags, name: String): KmTypeAliasVisitor? =
|
||||
visitTypeAlias(sb, flags, name)
|
||||
}
|
||||
|
||||
@@ -615,7 +617,7 @@ class LambdaPrinter : KmLambdaVisitor(), AbstractPrinter<KotlinClassMetadata.Syn
|
||||
appendln("lambda {")
|
||||
}
|
||||
|
||||
override fun visitFunction(flags: Int, name: String): KmFunctionVisitor? =
|
||||
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? =
|
||||
visitFunction(sb, flags, name)
|
||||
|
||||
override fun visitEnd() {
|
||||
@@ -679,84 +681,84 @@ class ModuleFilePrinter : KmModuleVisitor() {
|
||||
}
|
||||
|
||||
private val VISIBILITY_FLAGS_MAP = mapOf(
|
||||
Flags.IS_INTERNAL to "internal",
|
||||
Flags.IS_PRIVATE to "private",
|
||||
Flags.IS_PRIVATE_TO_THIS to "private",
|
||||
Flags.IS_PROTECTED to "protected",
|
||||
Flags.IS_PUBLIC to "public",
|
||||
Flags.IS_LOCAL to "local"
|
||||
Flag.IS_INTERNAL to "internal",
|
||||
Flag.IS_PRIVATE to "private",
|
||||
Flag.IS_PRIVATE_TO_THIS to "private",
|
||||
Flag.IS_PROTECTED to "protected",
|
||||
Flag.IS_PUBLIC to "public",
|
||||
Flag.IS_LOCAL to "local"
|
||||
)
|
||||
|
||||
private val COMMON_FLAGS_MAP = VISIBILITY_FLAGS_MAP + mapOf(
|
||||
Flags.IS_FINAL to "final",
|
||||
Flags.IS_OPEN to "open",
|
||||
Flags.IS_ABSTRACT to "abstract",
|
||||
Flags.IS_SEALED to "sealed"
|
||||
Flag.IS_FINAL to "final",
|
||||
Flag.IS_OPEN to "open",
|
||||
Flag.IS_ABSTRACT to "abstract",
|
||||
Flag.IS_SEALED to "sealed"
|
||||
)
|
||||
|
||||
private val CLASS_FLAGS_MAP = COMMON_FLAGS_MAP + mapOf(
|
||||
Flags.Class.IS_INNER to "inner",
|
||||
Flags.Class.IS_DATA to "data",
|
||||
Flags.Class.IS_EXTERNAL to "external",
|
||||
Flags.Class.IS_EXPECT to "expect",
|
||||
Flags.Class.IS_INLINE to "inline",
|
||||
Flag.Class.IS_INNER to "inner",
|
||||
Flag.Class.IS_DATA to "data",
|
||||
Flag.Class.IS_EXTERNAL to "external",
|
||||
Flag.Class.IS_EXPECT to "expect",
|
||||
Flag.Class.IS_INLINE to "inline",
|
||||
|
||||
Flags.Class.IS_CLASS to "class",
|
||||
Flags.Class.IS_INTERFACE to "interface",
|
||||
Flags.Class.IS_ENUM_CLASS to "enum class",
|
||||
Flags.Class.IS_ENUM_ENTRY to "enum entry",
|
||||
Flags.Class.IS_ANNOTATION_CLASS to "annotation class",
|
||||
Flags.Class.IS_OBJECT to "object",
|
||||
Flags.Class.IS_COMPANION_OBJECT to "companion object"
|
||||
Flag.Class.IS_CLASS to "class",
|
||||
Flag.Class.IS_INTERFACE to "interface",
|
||||
Flag.Class.IS_ENUM_CLASS to "enum class",
|
||||
Flag.Class.IS_ENUM_ENTRY to "enum entry",
|
||||
Flag.Class.IS_ANNOTATION_CLASS to "annotation class",
|
||||
Flag.Class.IS_OBJECT to "object",
|
||||
Flag.Class.IS_COMPANION_OBJECT to "companion object"
|
||||
)
|
||||
|
||||
private val CONSTRUCTOR_FLAGS_MAP = VISIBILITY_FLAGS_MAP + mapOf(
|
||||
Flags.Constructor.IS_PRIMARY to "/* primary */"
|
||||
Flag.Constructor.IS_PRIMARY to "/* primary */"
|
||||
)
|
||||
|
||||
private val FUNCTION_FLAGS_MAP = COMMON_FLAGS_MAP + mapOf(
|
||||
Flags.Function.IS_DECLARATION to "",
|
||||
Flags.Function.IS_FAKE_OVERRIDE to "/* fake override */",
|
||||
Flags.Function.IS_DELEGATION to "/* delegation */",
|
||||
Flags.Function.IS_SYNTHESIZED to "/* synthesized */",
|
||||
Flag.Function.IS_DECLARATION to "",
|
||||
Flag.Function.IS_FAKE_OVERRIDE to "/* fake override */",
|
||||
Flag.Function.IS_DELEGATION to "/* delegation */",
|
||||
Flag.Function.IS_SYNTHESIZED to "/* synthesized */",
|
||||
|
||||
Flags.Function.IS_OPERATOR to "operator",
|
||||
Flags.Function.IS_INFIX to "infix",
|
||||
Flags.Function.IS_INLINE to "inline",
|
||||
Flags.Function.IS_TAILREC to "tailrec",
|
||||
Flags.Function.IS_EXTERNAL to "external",
|
||||
Flags.Function.IS_SUSPEND to "suspend",
|
||||
Flags.Function.IS_EXPECT to "expect"
|
||||
Flag.Function.IS_OPERATOR to "operator",
|
||||
Flag.Function.IS_INFIX to "infix",
|
||||
Flag.Function.IS_INLINE to "inline",
|
||||
Flag.Function.IS_TAILREC to "tailrec",
|
||||
Flag.Function.IS_EXTERNAL to "external",
|
||||
Flag.Function.IS_SUSPEND to "suspend",
|
||||
Flag.Function.IS_EXPECT to "expect"
|
||||
)
|
||||
|
||||
private val PROPERTY_FLAGS_MAP = COMMON_FLAGS_MAP + mapOf(
|
||||
Flags.Property.IS_DECLARATION to "",
|
||||
Flags.Property.IS_FAKE_OVERRIDE to "/* fake override */",
|
||||
Flags.Property.IS_DELEGATION to "/* delegation */",
|
||||
Flags.Property.IS_SYNTHESIZED to "/* synthesized */",
|
||||
Flag.Property.IS_DECLARATION to "",
|
||||
Flag.Property.IS_FAKE_OVERRIDE to "/* fake override */",
|
||||
Flag.Property.IS_DELEGATION to "/* delegation */",
|
||||
Flag.Property.IS_SYNTHESIZED to "/* synthesized */",
|
||||
|
||||
Flags.Property.IS_CONST to "const",
|
||||
Flags.Property.IS_LATEINIT to "lateinit",
|
||||
Flags.Property.IS_EXTERNAL to "external",
|
||||
Flags.Property.IS_DELEGATED to "/* delegated */",
|
||||
Flags.Property.IS_EXPECT to "expect"
|
||||
Flag.Property.IS_CONST to "const",
|
||||
Flag.Property.IS_LATEINIT to "lateinit",
|
||||
Flag.Property.IS_EXTERNAL to "external",
|
||||
Flag.Property.IS_DELEGATED to "/* delegated */",
|
||||
Flag.Property.IS_EXPECT to "expect"
|
||||
)
|
||||
|
||||
private val PROPERTY_ACCESSOR_FLAGS_MAP = COMMON_FLAGS_MAP + mapOf(
|
||||
Flags.PropertyAccessor.IS_NOT_DEFAULT to "/* non-default */",
|
||||
Flags.PropertyAccessor.IS_EXTERNAL to "external",
|
||||
Flags.PropertyAccessor.IS_INLINE to "inline"
|
||||
Flag.PropertyAccessor.IS_NOT_DEFAULT to "/* non-default */",
|
||||
Flag.PropertyAccessor.IS_EXTERNAL to "external",
|
||||
Flag.PropertyAccessor.IS_INLINE to "inline"
|
||||
)
|
||||
|
||||
private val VALUE_PARAMETER_FLAGS_MAP = mapOf(
|
||||
Flags.ValueParameter.IS_CROSSINLINE to "crossinline",
|
||||
Flags.ValueParameter.IS_NOINLINE to "noinline"
|
||||
Flag.ValueParameter.IS_CROSSINLINE to "crossinline",
|
||||
Flag.ValueParameter.IS_NOINLINE to "noinline"
|
||||
)
|
||||
|
||||
private val TYPE_PARAMETER_FLAGS_MAP = mapOf(
|
||||
Flags.TypeParameter.IS_REIFIED to "reified"
|
||||
Flag.TypeParameter.IS_REIFIED to "reified"
|
||||
)
|
||||
|
||||
private val TYPE_FLAGS_MAP = mapOf(
|
||||
Flags.Type.IS_SUSPEND to "suspend"
|
||||
Flag.Type.IS_SUSPEND to "suspend"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user