Reverse dependency 'psi' <-> 'frontend.common'

Move ParseUtils to 'psi', and ImportPath to 'frontend.common'.

Now 'psi' depends on 'frontend.common', and that allows to remove
dependency of 'fir:tree:tree-generator' on 'psi', allowing the former to
compile in parallel with the old frontend code.
This commit is contained in:
Alexander Udalov
2020-03-15 15:14:54 +01:00
committed by Alexander Udalov
parent d70271b6aa
commit b6fdc96994
8 changed files with 11 additions and 30 deletions
+1 -7
View File
@@ -1,9 +1,3 @@
/*
* Copyright 2000-2018 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.
*/
plugins {
kotlin("jvm")
id("jps-compatible")
@@ -21,6 +15,7 @@ dependencies {
compile(project(":core:descriptors"))
compile(project(":compiler:util"))
compile(project(":compiler:frontend.common"))
compile(project(":kotlin-script-runtime"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
@@ -45,4 +40,3 @@ tasks.findByName("lexer")!!.apply {
ant.properties["flex.classpath"] = jflexPath.asPath
}
}
@@ -0,0 +1,96 @@
/*
* Copyright 2010-2020 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.parsing
import com.intellij.psi.tree.IElementType
import com.intellij.util.text.LiteralFormatUtil
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.utils.extractRadix
fun hasLongSuffix(text: String) = text.endsWith('l') || text.endsWith('L')
fun hasUnsignedSuffix(text: String) = text.endsWith('u') || text.endsWith('U')
fun hasUnsignedLongSuffix(text: String) =
text.endsWith("ul") || text.endsWith("uL") ||
text.endsWith("Ul") || text.endsWith("UL")
fun parseNumericLiteral(text: String, type: IElementType): Number? {
val canonicalText = LiteralFormatUtil.removeUnderscores(text)
return when (type) {
KtNodeTypes.INTEGER_CONSTANT -> parseLong(canonicalText)
KtNodeTypes.FLOAT_CONSTANT -> parseFloatingLiteral(canonicalText)
else -> null
}
}
private fun parseLong(text: String): Long? {
fun String.removeSuffix(i: Int): String = this.substring(0, this.length - i)
return try {
val isUnsigned: Boolean
val numberWithoutSuffix: String
when {
hasUnsignedLongSuffix(text) -> {
isUnsigned = true
numberWithoutSuffix = text.removeSuffix(2)
}
hasUnsignedSuffix(text) -> {
isUnsigned = true
numberWithoutSuffix = text.removeSuffix(1)
}
hasLongSuffix(text) -> {
isUnsigned = false
numberWithoutSuffix = text.removeSuffix(1)
}
else -> {
isUnsigned = false
numberWithoutSuffix = text
}
}
val (number, radix) = extractRadix(numberWithoutSuffix)
if (isUnsigned) {
java.lang.Long.parseUnsignedLong(number, radix)
} else {
java.lang.Long.parseLong(number, radix)
}
} catch (e: NumberFormatException) {
null
}
}
private fun parseFloatingLiteral(text: String): Number? {
if (text.toLowerCase().endsWith('f')) {
return parseFloat(text)
}
return parseDouble(text)
}
private fun parseDouble(text: String): Double? {
try {
return java.lang.Double.parseDouble(text)
} catch (e: NumberFormatException) {
return null
}
}
private fun parseFloat(text: String): Float? {
try {
return java.lang.Float.parseFloat(text)
} catch (e: NumberFormatException) {
return null
}
}
fun parseBoolean(text: String): Boolean {
if ("true".equals(text)) {
return true
} else if ("false".equals(text)) {
return false
}
throw IllegalStateException("Must not happen. A boolean literal has text: " + text)
}
@@ -1,56 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.renderer.*
data class ImportPath @JvmOverloads constructor(val fqName: FqName, val isAllUnder: Boolean, val alias: Name? = null) {
val pathStr: String
get() = fqName.toUnsafe().render() + if (isAllUnder) ".*" else ""
override fun toString(): String {
return pathStr + if (alias != null) " as " + alias.asString() else ""
}
fun hasAlias(): Boolean {
return alias != null
}
val importedName: Name?
get() {
if (!isAllUnder) {
return alias ?: fqName.shortName()
}
return null
}
companion object {
@JvmStatic
fun fromString(pathStr: String): ImportPath {
return if (pathStr.endsWith(".*")) {
ImportPath(FqName(pathStr.substring(0, pathStr.length - 2)), isAllUnder = true)
} else {
ImportPath(FqName(pathStr), isAllUnder = false)
}
}
}
}