forked from JetBrains/kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure scoping definitions to be more structured.
Previously, scopes were just arbitrary names. This imposes the kind of hierarchical structure on scopes that we will want to use for optimising mangled name length.
- Loading branch information
Showing
10 changed files
with
208 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...rification/formver.core/src/org/jetbrains/kotlin/formver/names/ScopedKotlinNameBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.formver.names | ||
|
||
import org.jetbrains.kotlin.name.FqName | ||
|
||
class ScopedKotlinNameBuilder { | ||
private var scope: NameScope? = null | ||
|
||
fun complete(name: KotlinName): ScopedKotlinName { | ||
require(scope != null) { "No scope specified "} | ||
return ScopedKotlinName(scope!!, name) | ||
} | ||
|
||
fun packageScope(packageName: FqName) { | ||
require (scope == null) { "Invalid scope combination: package after $scope" } | ||
scope = PackageScope(packageName) | ||
} | ||
|
||
fun packageScope(packageName: List<String>) { | ||
require (scope == null) { "Invalid scope combination: package after $scope" } | ||
scope = PackageScope(FqName.fromSegments(packageName)) | ||
} | ||
|
||
fun globalScope() { | ||
require (scope != null) { "Global scope cannot be top-level" } | ||
scope = GlobalScope(scope!!) | ||
} | ||
|
||
fun classScope(className: ClassKotlinName) { | ||
require (scope != null) { "Public class scope cannot be top-level" } | ||
scope = ClassScope(scope!!, className) | ||
} | ||
|
||
fun publicScope() { | ||
require(scope != null) { "Public class scope cannot be top-level" } | ||
scope = PublicScope(scope!!) | ||
} | ||
|
||
fun privateScope() { | ||
require(scope != null) { "Private class scope cannot be top-level" } | ||
scope = PrivateScope(scope!!) | ||
} | ||
|
||
fun parameterScope() { | ||
require(scope == null) { "Parameter scope cannot be nested." } | ||
scope = ParameterScope | ||
} | ||
|
||
fun localScope(level: Int) { | ||
require (scope == null) { "Local scope cannot be nested." } | ||
scope = LocalScope(level) | ||
} | ||
} | ||
|
||
// TODO: generalise this to work for all names. | ||
fun buildName(init: ScopedKotlinNameBuilder.() -> KotlinName): ScopedKotlinName = | ||
ScopedKotlinNameBuilder().let { | ||
it.complete(it.init()) | ||
} |
Oops, something went wrong.