diff --git a/CHANGELOG.md b/CHANGELOG.md index 038a581..0f01972 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # TON Plugin for the IntelliJ IDEs Changelog +## [2.5.0] + +### Added +- Tolk 0.7 support +- Tolk type inference & completion +- Tolk type hints for variables & functions +- TL-B schema inspections +- TL-B constructor tag generator + +### Fixed +- A lot of minor bugs + ## [2.4.0] ### Added diff --git a/blueprint/build.gradle.kts b/blueprint/build.gradle.kts new file mode 100644 index 0000000..99c2166 --- /dev/null +++ b/blueprint/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + id("org.jetbrains.intellij.platform.module") +} + +dependencies { + intellijPlatform { + val version = providers.gradleProperty("platformVersion") + intellijIdeaCommunity(version) + } +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 43e9289..59f6f72 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,12 @@ -import org.gradle.configurationcache.extensions.capitalized + import org.jetbrains.changelog.Changelog -import org.jetbrains.grammarkit.tasks.GenerateLexerTask -import org.jetbrains.grammarkit.tasks.GenerateParserTask +import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType +import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.time.Clock import java.time.Instant val publishChannel = prop("publishChannel") -val ideaVersion = prop("ideaVersion") val pluginVersion = prop("pluginVersion").let { pluginVersion -> if (publishChannel != "release" && publishChannel != "stable") { val buildSuffix = prop("buildNumber") { @@ -19,92 +18,95 @@ val pluginVersion = prop("pluginVersion").let { pluginVersion -> } } version = pluginVersion -println("pluginVersion=$version") plugins { - kotlin("jvm") version "1.9.22" - id("org.jetbrains.intellij") version "1.17.3" + kotlin("jvm") version "2.0.10" + id("org.jetbrains.intellij.platform") id("org.jetbrains.grammarkit") version "2022.3.2.2" - id("org.jetbrains.changelog") version "2.2.0" - idea + id("org.jetbrains.changelog") version "2.2.1" } allprojects { apply(plugin = "kotlin") - repositories { - maven("https://cache-redirector.jetbrains.com/intellij-dependencies") - mavenCentral() - maven(url = "https://jitpack.io") + tasks.withType { + compilerOptions.jvmTarget.set(JvmTarget.JVM_21) + compilerOptions.freeCompilerArgs.add("-Xjvm-default=all") } - tasks.withType { - kotlinOptions.jvmTarget = "17" - kotlinOptions.freeCompilerArgs += "-Xjvm-default=all" + java { + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) } - dependencies { - implementation("me.alllex.parsus:parsus-jvm:0.6.1") - implementation("com.github.andreypfau.tlb:tlb-jvm:54070d9405") + sourceSets { + main { + kotlin.srcDir("src") + java.srcDirs("gen") + resources.srcDir("resources") + } + test { + kotlin.srcDir("test") + resources.srcDir("testResources") + } + } + tasks { + test { + useJUnitPlatform() + } } } -sourceSets { - main { - java.srcDirs("src/gen") +tasks { + buildSearchableOptions { + enabled = false } } -idea { - module { - isDownloadSources = true - generatedSourceDirs.add(file("src/gen")) +dependencies { + intellijPlatform { + val version = providers.gradleProperty("platformVersion") + create(IntelliJPlatformType.IntellijIdeaUltimate, version) + + pluginModule(implementation(project(":util"))) + pluginModule(implementation(project(":asm"))) + pluginModule(implementation(project(":tolk"))) + pluginModule(implementation(project(":func"))) + pluginModule(implementation(project(":tact"))) + pluginModule(implementation(project(":boc"))) + pluginModule(implementation(project(":tlb"))) + pluginModule(implementation(project(":fift"))) + pluginModule(implementation(project(":blueprint"))) + pluginModule(implementation(project(":fc2tolk-js"))) } } -intellij { - version.set(ideaVersion) - type.set("IU") - plugins.set( - listOf( - "JavaScript", - "com.google.ide-perf:1.3.1", - "izhangzhihao.rainbow.brackets:2023.3.2" +intellijPlatform { + pluginConfiguration { + id = "org.ton.intellij-ton" + name = "TON" + version = project.version.toString() + description = """ + TON Blockchain Development Plugin for IntelliJ: Adds support for TON blockchain programming languages, + including FunC, Tolk, Fift, Tact, and TL-B schemas. + Ideal for Web3 developers working within the TON ecosystem. + """.trimIndent() + changeNotes.set( + provider { + changelog.renderItem(changelog.getLatest(), Changelog.OutputType.HTML) + } ) - ) -} - -val generateFuncLexer = generateLexer("Func") -val generateFuncParser = generateParser("Func") - -val generateTactLexer = generateLexer("Tact") -val generateTactParser = generateParser("Tact") - -val generateFiftLexer = generateLexer("Fift") -val generateFiftParser = generateParser("Fift") - -val generateTlbLexer = generateLexer("Tlb") -val generateTlbParser = generateParser("Tlb") - -val generateAsmLexer = generateLexer("Asm") -val generateAsmParser = generateParser("Asm") - -val generateTolkLexer = generateLexer("Tolk") -val generateTolkParser = generateParser("Tolk") - -val compileKotlin = tasks.named("compileKotlin") { - dependsOn( - generateFuncParser, generateFuncLexer, - generateTactParser, generateTactLexer, - generateFiftParser, generateFiftLexer, - generateTlbParser, generateTlbLexer, - generateAsmParser, generateAsmLexer, - generateTolkParser, generateTolkLexer, - ) + ideaVersion { + sinceBuild.set("243") + untilBuild = provider { null } + } + vendor { + name = "TON Core" + url = "https://github.com/ton-blockchain/intellij-ton" + email = "andreypfau@ton.org" + } + } } -val compileJava = tasks.named("compileJava") - changelog { version.set(version) path.set("${project.projectDir}/CHANGELOG.md") @@ -115,52 +117,5 @@ changelog { groups.set(listOf("Added", "Changed", "Deprecated", "Removed", "Fixed", "Security")) } -tasks { - runIde { enabled = true } - prepareSandbox { enabled = true } - patchPluginXml { - sinceBuild.set("232") - untilBuild.set("") - changeNotes.set(provider { - changelog.renderItem(changelog.run { - getLatest() - }, Changelog.OutputType.HTML) - }) - } - buildSearchableOptions { - enabled = prop("enableBuildSearchableOptions").toBoolean() - } - configurations.runtimeClasspath.get().forEach { - println(it) - } - jar { - from({ - configurations.runtimeClasspath.get().filter { file -> - !file.nameWithoutExtension.startsWith("kotlin-stdlib") && - !file.nameWithoutExtension.startsWith("annotations") - }.map { - if (it.isDirectory) it - else zipTree(it) - } - }) - } -} - fun prop(name: String, default: (() -> String?)? = null) = extra.properties[name] as? String ?: default?.invoke() ?: error("Property `$name` is not defined in gradle.properties") - -fun generateParser(language: String, suffix: String = "", config: GenerateParserTask.() -> Unit = {}) = - task("generate${language.capitalized()}Parser${suffix.capitalized()}") { - sourceFile.set(file("src/main/grammar/${language}Parser.bnf")) - targetRootOutputDir.set(file("src/gen")) - pathToParser.set("/org/ton/intellij/${language.lowercase()}/parser/${language}Parser.java") - pathToPsiRoot.set("/org/ton/intellij/${language.lowercase()}/psi") - purgeOldFiles.set(true) - config() - } - -fun generateLexer(language: String) = task("generate${language}Lexer") { - sourceFile.set(file("src/main/grammar/${language}Lexer.flex")) - targetOutputDir.set(file("src/gen/org/ton/intellij/${language.lowercase()}/lexer")) - purgeOldFiles.set(true) -} diff --git a/gradle.properties b/gradle.properties index 6505dfe..5fcfcc7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,14 +1,16 @@ org.gradle.jvmargs=-Xmx4096m pluginGroup=org.ton -pluginVersion=2.4.3 +pluginVersion=2.5.0 publishChannel=release publishToken=token enableBuildSearchableOptions=false # Existent IDE versions can be found in the following repos: # https://www.jetbrains.com/intellij-repository/releases/ # https://www.jetbrains.com/intellij-repository/snapshots/ -ideaVersion=2024.2.4 -# https://plugins.jetbrains.com/plugin/227-psiviewer/versions -psiViewerPluginVersion=231-SNAPSHOT +ideaVersion=2024.3 kotlin.stdlib.default.dependency=false -buildNumber=1 +buildNumber=17 + +platformType=IC +platformVersion=2024.3 +org.gradle.parallel=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 48c0a02..81aa1c0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/modules/asm/build.gradle.kts b/modules/asm/build.gradle.kts new file mode 100644 index 0000000..a3db838 --- /dev/null +++ b/modules/asm/build.gradle.kts @@ -0,0 +1,37 @@ +import org.jetbrains.grammarkit.tasks.GenerateLexerTask +import org.jetbrains.grammarkit.tasks.GenerateParserTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.jetbrains.intellij.platform.module") + id("org.jetbrains.grammarkit") +} + +dependencies { + intellijPlatform { + val version = providers.gradleProperty("platformVersion") + intellijIdeaCommunity(version) + } + compileOnly(project(":util")) +} + +val generateAsmParser = task("generateAsmParser") { + sourceFile.set(file("src/org/ton/intellij/asm/parser/AsmParser.bnf")) + targetRootOutputDir.set(file("gen")) + pathToParser.set("/org/ton/intellij/asm/parser/AsmParser.java") + pathToPsiRoot.set("/org/ton/intellij/asm/psi") + purgeOldFiles.set(true) + dependsOn(":util:composedJar") +} + +//tasks.findByPath(":util:composedJar")?.mustRunAfter(generateAsmParser) + +val generateAsmLexer = task("generateAsmLexer") { + sourceFile.set(file("src/org/ton/intellij/asm/lexer/AsmLexer.flex")) + targetOutputDir.set(file("gen/org/ton/intellij/asm/lexer")) + purgeOldFiles.set(true) +} + +tasks.withType().configureEach { + dependsOn(generateAsmParser, generateAsmLexer) +} diff --git a/src/main/resources/META-INF/asm.xml b/modules/asm/resources/META-INF/asm.xml similarity index 95% rename from src/main/resources/META-INF/asm.xml rename to modules/asm/resources/META-INF/asm.xml index ed51d68..bbcd1b4 100644 --- a/src/main/resources/META-INF/asm.xml +++ b/modules/asm/resources/META-INF/asm.xml @@ -6,7 +6,7 @@ language="TVM assembly" extensions="tvm"/> + implementationClass="org.ton.intellij.asm.parser.AsmParserDefinition"/> () { override fun addCompletions( parameters: CompletionParameters, diff --git a/src/main/kotlin/org/ton/intellij/asm/AsmFile.kt b/modules/asm/src/org/ton/intellij/asm/AsmFile.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/asm/AsmFile.kt rename to modules/asm/src/org/ton/intellij/asm/AsmFile.kt diff --git a/src/main/kotlin/org/ton/intellij/asm/AsmFileElementType.kt b/modules/asm/src/org/ton/intellij/asm/AsmFileElementType.kt similarity index 55% rename from src/main/kotlin/org/ton/intellij/asm/AsmFileElementType.kt rename to modules/asm/src/org/ton/intellij/asm/AsmFileElementType.kt index 9ac5749..82d0489 100644 --- a/src/main/kotlin/org/ton/intellij/asm/AsmFileElementType.kt +++ b/modules/asm/src/org/ton/intellij/asm/AsmFileElementType.kt @@ -2,5 +2,4 @@ package org.ton.intellij.asm import com.intellij.psi.tree.IFileElementType -object AsmFileElementType : IFileElementType(AsmLanguage) { -} +object AsmFileElementType : IFileElementType(AsmLanguage) diff --git a/src/main/kotlin/org/ton/intellij/asm/AsmFileType.kt b/modules/asm/src/org/ton/intellij/asm/AsmFileType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/asm/AsmFileType.kt rename to modules/asm/src/org/ton/intellij/asm/AsmFileType.kt diff --git a/src/main/kotlin/org/ton/intellij/asm/AsmHighlighter.kt b/modules/asm/src/org/ton/intellij/asm/AsmHighlighter.kt similarity index 79% rename from src/main/kotlin/org/ton/intellij/asm/AsmHighlighter.kt rename to modules/asm/src/org/ton/intellij/asm/AsmHighlighter.kt index 3aeff3e..dd27061 100644 --- a/src/main/kotlin/org/ton/intellij/asm/AsmHighlighter.kt +++ b/modules/asm/src/org/ton/intellij/asm/AsmHighlighter.kt @@ -8,6 +8,8 @@ import com.intellij.openapi.editor.colors.TextAttributesKey import com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey import com.intellij.openapi.fileTypes.SyntaxHighlighterBase import com.intellij.psi.tree.IElementType +import org.ton.intellij.asm.lexer.AsmLexer +import org.ton.intellij.asm.psi.AsmElementTypes object AsmHighlighter : SyntaxHighlighterBase() { override fun getHighlightingLexer(): Lexer { @@ -30,6 +32,8 @@ object AsmHighlighter : SyntaxHighlighterBase() { private val INSTRUCTION = createTextAttributesKey("ASM.INSTRUCTION", XmlHighlighterColors.HTML_TAG) private val NUMBER = createTextAttributesKey("ASM.NUMBER", DefaultLanguageHighlighterColors.NUMBER) - private val STACK_REGISTER = createTextAttributesKey("ASM.STACK_REGISTER", DefaultLanguageHighlighterColors.CONSTANT) - private val CONTROL_REGISTER = createTextAttributesKey("ASM.STACK_REGISTER", DefaultLanguageHighlighterColors.CONSTANT) + private val STACK_REGISTER = + createTextAttributesKey("ASM.STACK_REGISTER", DefaultLanguageHighlighterColors.CONSTANT) + private val CONTROL_REGISTER = + createTextAttributesKey("ASM.STACK_REGISTER", DefaultLanguageHighlighterColors.CONSTANT) } diff --git a/src/main/kotlin/org/ton/intellij/asm/AsmInstructionsCsv.kt b/modules/asm/src/org/ton/intellij/asm/AsmInstructionsCsv.kt similarity index 99% rename from src/main/kotlin/org/ton/intellij/asm/AsmInstructionsCsv.kt rename to modules/asm/src/org/ton/intellij/asm/AsmInstructionsCsv.kt index 5218740..2e041e6 100644 --- a/src/main/kotlin/org/ton/intellij/asm/AsmInstructionsCsv.kt +++ b/modules/asm/src/org/ton/intellij/asm/AsmInstructionsCsv.kt @@ -13,9 +13,7 @@ object AsmInstructionsCsv { split[6], split[7], split[8] - ).also { - println("parsed: $it") - } + ) } data class Instruction( diff --git a/src/main/kotlin/org/ton/intellij/asm/AsmLanguage.kt b/modules/asm/src/org/ton/intellij/asm/AsmLanguage.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/asm/AsmLanguage.kt rename to modules/asm/src/org/ton/intellij/asm/AsmLanguage.kt diff --git a/src/main/kotlin/org/ton/intellij/asm/AsmSyntaxHighlighterFactory.kt b/modules/asm/src/org/ton/intellij/asm/AsmSyntaxHighlighterFactory.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/asm/AsmSyntaxHighlighterFactory.kt rename to modules/asm/src/org/ton/intellij/asm/AsmSyntaxHighlighterFactory.kt diff --git a/modules/asm/src/org/ton/intellij/asm/lexer/AsmLexer.flex b/modules/asm/src/org/ton/intellij/asm/lexer/AsmLexer.flex new file mode 100644 index 0000000..8b009bf --- /dev/null +++ b/modules/asm/src/org/ton/intellij/asm/lexer/AsmLexer.flex @@ -0,0 +1,59 @@ +package org.ton.intellij.asm.lexer; + +import com.intellij.psi.tree.IElementType; + +import com.intellij.lexer.FlexLexer; +import static com.intellij.psi.TokenType.BAD_CHARACTER; +import static com.intellij.psi.TokenType.WHITE_SPACE; +import static org.ton.intellij.asm.psi.AsmElementTypes.*; + +%% + +%{ + public _AsmLexer() { + this((java.io.Reader)null); + } +%} + +%public +%class _AsmLexer +%implements FlexLexer +%function advance +%type IElementType +%unicode + +EOL=\R +WHITE_SPACE=\s+ + +STACK_REGISTER=s[0-9]+|s\(-[0-9]+\) +CONTROL_REGISTER=c[0-7] +UNKNOWN_IDENTIFIER=[a-zA-Z_][a-zA-Z0-9_#]* +NUMBER_DIGIT_LITERAL=(-?[0-9]+("/"-?[0-9]+)?) +NUMBER_HEX_LITERAL=(0[xX][0-9a-fA-F]+) +NUMBER_BINARY_LITERAL=(0[bB][01]+) +SLICE_BINARY_LITERAL=(b\{[01]+}) +SLICE_HEX_LITERAL=(x\{[0-9a-fA-F_]+}) +WORD=\S+ + +%% + { + {WHITE_SPACE} { return WHITE_SPACE; } + '' { return BUILDER_END; } + '' { return SLICE_END; } + '<\{' { return CODE_BEGIN; } + '\}>' { return CODE_END; } + '\}>c' { return CODE_END_CELL; } + '\}>s' { return CODE_END_SLICE; } + {NUMBER_DIGIT_LITERAL} { return INTEGER; } + {NUMBER_BINARY_LITERAL} { return INTEGER; } + {NUMBER_HEX_LITERAL} { return INTEGER; } + {SLICE_BINARY_LITERAL} { return SLICE_BINARY; } + {SLICE_HEX_LITERAL} { return SLICE_HEX; } + {STACK_REGISTER} { return STACK_REGISTER; } + {CONTROL_REGISTER} { return CONTROL_REGISTER; } + {WORD} { return WORD; } +} + +[^] { return BAD_CHARACTER; } diff --git a/modules/asm/src/org/ton/intellij/asm/lexer/AsmLexer.kt b/modules/asm/src/org/ton/intellij/asm/lexer/AsmLexer.kt new file mode 100644 index 0000000..6881a10 --- /dev/null +++ b/modules/asm/src/org/ton/intellij/asm/lexer/AsmLexer.kt @@ -0,0 +1,5 @@ +package org.ton.intellij.asm.lexer + +import com.intellij.lexer.FlexAdapter + +class AsmLexer : FlexAdapter(_AsmLexer()) \ No newline at end of file diff --git a/modules/asm/src/org/ton/intellij/asm/parser/AsmParser.bnf b/modules/asm/src/org/ton/intellij/asm/parser/AsmParser.bnf new file mode 100644 index 0000000..bf5ae44 --- /dev/null +++ b/modules/asm/src/org/ton/intellij/asm/parser/AsmParser.bnf @@ -0,0 +1,44 @@ +{ + parserClass='org.ton.intellij.asm.parser.AsmParser' + + psiClassPrefix='Asm' + psiImplClassSuffix='Impl' + psiPackage='org.ton.intellij.asm.psi' + psiImplPackage='org.ton.intellij.asm.psi.impl' + implements='org.ton.intellij.asm.psi.AsmElement' + + elementTypeHolderClass="org.ton.intellij.asm.psi.AsmElementTypes" + elementTypeClass="org.ton.intellij.asm.psi.AsmElementType" + + generateTokenAccessors=true + + tokens = [ + INTEGER='regexp:[0-9]+' + SLICE_BINARY='regexp:(b\{[01]+})' + SLICE_HEX='regexp:(x\{[0-9a-fA-F_]+})' + STACK_REGISTER='regexp:s[0-9]+|s\(-[0-9]+\)' + CONTROL_REGISTER='regexp:c[0-7]' + BUILDER_BEGIN=' { return object : NpmPackageGeneratorPeer() { private lateinit var sampleCode: JBCheckBox @@ -132,6 +143,7 @@ class TonBlueprintProjectGenerator( val displayName: String, ) { FUNC("func", "FunC"), + TOLK("tolk", "Tolk"), TACT("tact", "Tact"); fun argument(addSampleCode: Boolean): String { @@ -147,6 +159,7 @@ class TonBlueprintProjectGenerator( class TonBlueprintProjectWizard : MultiWebTemplateNewProjectWizard( listOf( TonBlueprintProjectGenerator(TonBlueprintProjectGenerator.ProjectType.FUNC), + TonBlueprintProjectGenerator(TonBlueprintProjectGenerator.ProjectType.TOLK), TonBlueprintProjectGenerator(TonBlueprintProjectGenerator.ProjectType.TACT) ) ) { diff --git a/modules/boc/build.gradle.kts b/modules/boc/build.gradle.kts new file mode 100644 index 0000000..10da3fa --- /dev/null +++ b/modules/boc/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + id("org.jetbrains.intellij.platform.module") + id("org.jetbrains.grammarkit") +} + +dependencies { + intellijPlatform { + val version = providers.gradleProperty("platformVersion") + intellijIdeaCommunity(version) + } + compileOnly(project(":util")) +} diff --git a/src/main/resources/META-INF/boc.xml b/modules/boc/resources/META-INF/boc.xml similarity index 100% rename from src/main/resources/META-INF/boc.xml rename to modules/boc/resources/META-INF/boc.xml diff --git a/src/main/resources/icons/boc.svg b/modules/boc/resources/icons/boc.svg similarity index 100% rename from src/main/resources/icons/boc.svg rename to modules/boc/resources/icons/boc.svg diff --git a/src/main/kotlin/org/ton/intellij/boc/BocFileType.kt b/modules/boc/src/org/ton/intellij/boc/BocFileType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/boc/BocFileType.kt rename to modules/boc/src/org/ton/intellij/boc/BocFileType.kt diff --git a/src/main/kotlin/org/ton/intellij/boc/BocIcons.kt b/modules/boc/src/org/ton/intellij/boc/BocIcons.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/boc/BocIcons.kt rename to modules/boc/src/org/ton/intellij/boc/BocIcons.kt diff --git a/modules/fc2tolk-js/build.gradle.kts b/modules/fc2tolk-js/build.gradle.kts new file mode 100644 index 0000000..be97063 --- /dev/null +++ b/modules/fc2tolk-js/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + id("org.jetbrains.intellij.platform.module") + id("org.jetbrains.grammarkit") +} + +dependencies { + intellijPlatform { + val version = providers.gradleProperty("platformVersion") + intellijIdeaUltimate(version) + } + + compileOnly(project(":util")) + compileOnly(project(":func")) +} \ No newline at end of file diff --git a/modules/fc2tolk-js/resources/META-INF/fc2tolk-js.xml b/modules/fc2tolk-js/resources/META-INF/fc2tolk-js.xml new file mode 100644 index 0000000..e92fdc8 --- /dev/null +++ b/modules/fc2tolk-js/resources/META-INF/fc2tolk-js.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/modules/fc2tolk-js/src/org/ton/intellij/fc2tolkjs/FcToTolkAction.kt b/modules/fc2tolk-js/src/org/ton/intellij/fc2tolkjs/FcToTolkAction.kt new file mode 100644 index 0000000..25e5547 --- /dev/null +++ b/modules/fc2tolk-js/src/org/ton/intellij/fc2tolkjs/FcToTolkAction.kt @@ -0,0 +1,27 @@ +package org.ton.intellij.fc2tolkjs + +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.CommonDataKeys +import com.intellij.psi.PsiFile +import com.intellij.psi.PsiManager +import org.ton.intellij.func.psi.FuncFile +import org.ton.intellij.util.getAllFilesRecursively + +class FcToTolkAction : AnAction() { + override fun actionPerformed(e: AnActionEvent) { + val project = CommonDataKeys.PROJECT.getData(e.dataContext) ?: return + + } + + private fun getSelectedWritableFuncFiles(e: AnActionEvent): List { + val virtualFilesAndDirectories = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY) ?: return emptyList() + val project = e.project ?: return emptyList() + val psiManager = PsiManager.getInstance(project) + return getAllFilesRecursively(virtualFilesAndDirectories) + .asSequence() + .mapNotNull { psiManager.findFile(it) as? FuncFile } + .filter { it.isWritable } + .toList() + } +} \ No newline at end of file diff --git a/modules/fc2tolk/build.gradle.kts b/modules/fc2tolk/build.gradle.kts new file mode 100644 index 0000000..b1411a9 --- /dev/null +++ b/modules/fc2tolk/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + id("org.jetbrains.intellij.platform.module") + id("org.jetbrains.grammarkit") +} + +dependencies { + intellijPlatform { + val version = providers.gradleProperty("platformVersion") + intellijIdeaCommunity(version) + } + compileOnly(project(":func")) + compileOnly(project(":tolk")) + compileOnly(project(":util")) +} diff --git a/modules/fc2tolk/resources/META-INF/fc2tolk.xml b/modules/fc2tolk/resources/META-INF/fc2tolk.xml new file mode 100644 index 0000000..000d738 --- /dev/null +++ b/modules/fc2tolk/resources/META-INF/fc2tolk.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/modules/fc2tolk/src/org/ton/intellij/fc2tolk/FuncToFTTreeBuilder.kt b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/FuncToFTTreeBuilder.kt new file mode 100644 index 0000000..f0ab134 --- /dev/null +++ b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/FuncToFTTreeBuilder.kt @@ -0,0 +1,71 @@ +package org.ton.intellij.fc2tolk + +import com.intellij.psi.PsiElement +import com.intellij.psi.util.elementType +import org.ton.intellij.fc2tolk.tree.* +import org.ton.intellij.func.psi.* + +class FuncToFTTreeBuilder { + private val expressionTreeMapper = ExpressionTreeMapper() + private val declarationMapper = DeclarationMapper(expressionTreeMapper) + + fun buildTree(psi: PsiElement): FTTreeRoot? { + return when (psi) { + is FuncFile -> psi.toFT() + is FuncFunction -> with(declarationMapper) { psi.toFt() } + + else -> null + }?.let { + FTTreeRoot(it) + } + } + + private fun FuncFile.toFT(): FTFile { + return FTFile( + with(declarationMapper) { + functions.map { it.toFt() } + }, + ) + } + + private fun FuncTypeReference?.toFt(): FTType = if (this == null) FTUnknownType else when (this) { + is FuncPrimitiveType -> this.toFt() + is FuncTensorType -> FTTensorType.create(typeReferenceList.map { it.toFt() }) + is FuncTupleType -> FTTupleType(typeReferenceList.map { it.toFt() }) + is FuncParenType -> typeReference.toFt() + is FuncHoleType -> FTFuncHoleType + else -> FTUnknownType + } + + private fun FuncPrimitiveType?.toFt(): FTType = + when (this?.firstChild?.elementType) { + FuncElementTypes.INT_KEYWORD -> FTFuncPrimitiveType.INT + FuncElementTypes.CELL_KEYWORD -> FTFuncPrimitiveType.CELL + FuncElementTypes.BUILDER_KEYWORD -> FTFuncPrimitiveType.BUILDER + FuncElementTypes.SLICE_KEYWORD -> FTFuncPrimitiveType.SLICE + FuncElementTypes.TUPLE_KEYWORD -> FTFuncPrimitiveType.TUPLE + FuncElementTypes.CONT_KEYWORD -> FTFuncPrimitiveType.CONT + else -> FTUnknownType + } + + private inner class DeclarationMapper( + val expressionTreeMapper: ExpressionTreeMapper + ) { + fun FuncFunction.toFt() = FTFunction( + returnType = FTTypeElement(typeReference.toFt()), + name = FTNameIdentifier(nameIdentifier?.text ?: ""), + typeParameterList = FTTypeParameterList(typeParameterList.map { it.toFt() }), + functionModifiers = emptyList() + ) + + fun FuncTypeParameter.toFt() = FTTypeParameter( + FTNameIdentifier(nameIdentifier?.text ?: "") + ) + } + + private class ExpressionTreeMapper { + fun FuncExpression?.toFT() { + + } + } +} \ No newline at end of file diff --git a/modules/fc2tolk/src/org/ton/intellij/fc2tolk/conversions.kt b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/conversions.kt new file mode 100644 index 0000000..7ab39c3 --- /dev/null +++ b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/conversions.kt @@ -0,0 +1,23 @@ +package org.ton.intellij.fc2tolk + +import org.ton.intellij.fc2tolk.tree.FTTreeElement +import org.ton.intellij.fc2tolk.tree.applyRecursive + +interface ConverterContext + +abstract class Conversion { + abstract fun run(treeRoot: FTTreeElement, context: ConverterContext) +} + +abstract class RecursiveConversion(context: ConverterContext) : Conversion() { + override fun run(treeRoot: FTTreeElement, context: ConverterContext) { + val root = applyToElement(treeRoot) + assert(root === treeRoot) + } + + abstract fun applyToElement(element: FTTreeElement): FTTreeElement + + protected fun recurse(element: E): E = + applyRecursive(element, data = null) { it, _ -> applyToElement(it) } +} + diff --git a/modules/fc2tolk/src/org/ton/intellij/fc2tolk/printing/FTCodeBuilder.kt b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/printing/FTCodeBuilder.kt new file mode 100644 index 0000000..726689b --- /dev/null +++ b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/printing/FTCodeBuilder.kt @@ -0,0 +1,67 @@ +package org.ton.intellij.fc2tolk.printing + +import org.ton.intellij.fc2tolk.ConverterContext +import org.ton.intellij.fc2tolk.tree.* +import org.ton.intellij.fc2tolk.tree.visitors.FTVisitor + +class FTCodeBuilder( + private val context: ConverterContext +) { + private val printer = FTPrinterBase() + + fun printCode(root: FTTreeElement): String { + Visitor().also { root.accept(it) } + return printer.toString().replace("\r\n", "\n") + } + + private inner class Visitor : FTVisitor() { + override fun visitTreeElement(element: FTElement) { + printer.print("/* !!! Hit visitElement for element type: ${element::class} !!! */") + } + + override fun visitTreeRoot(treeRoot: FTTreeRoot) { + treeRoot.element.accept(this) + } + + override fun visitFile(file: FTFile) { + file.declarationList.forEach { it.accept(this) } + } + + override fun visitNameIdentifier(nameIdentifier: FTNameIdentifier) { + printer.print(nameIdentifier.value.escapedTolkId()) + } + + override fun visitMethodId(methodId: FTMethodId) { + val value = methodId.value + if (value != null) { + printer.print("@methodId(") + printer.print(value) + printer.print(")") + } + } + + override fun visitFunction(function: FTFunction) { + var isGetFun = false + function.functionModifiers.forEach { + it.accept(this) + if (it is FTMethodId && it.value == null) { + isGetFun = true + } + } + + if (isGetFun) { + printer.printWithSurroundingSpaces("get") + } + printer.printWithSurroundingSpaces("fun") + + function.name.accept(this) + + if (function.typeParameterList.typeParameters.isNotEmpty()) { + function.typeParameterList.accept(this) + } + + + } + + } +} \ No newline at end of file diff --git a/modules/fc2tolk/src/org/ton/intellij/fc2tolk/printing/FTPrinterBase.kt b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/printing/FTPrinterBase.kt new file mode 100644 index 0000000..7151cae --- /dev/null +++ b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/printing/FTPrinterBase.kt @@ -0,0 +1,94 @@ +package org.ton.intellij.fc2tolk.printing + +class FTPrinterBase { + private val stringBuilder = StringBuilder() + var currentIndent = 0 + private val indentSymbol = " ".repeat(4) + var lastSymbolIsLineBreak = false + private var lastSymbolIsSingleSpace = false + + override fun toString(): String = stringBuilder.toString() + + fun printWithSurroundingSpaces(value: String) { + print(" ") + print(value) + print(" ") + } + + fun print(value: String) { + if (value.isEmpty()) return + + if (value == " ") { + // Don't try to print a single space at the beginning of the line + if (lastSymbolIsLineBreak) return + + val prevLastSymbolIsSingleSpace = lastSymbolIsSingleSpace + lastSymbolIsSingleSpace = true + + // Don't try to print multiple single spaces in a row + if (!prevLastSymbolIsSingleSpace) append(" ") + } else { + lastSymbolIsSingleSpace = false + append(value) + + if (value.length >= 2 && value.last() == ' ' && value[value.lastIndex - 1] != ' ') { + lastSymbolIsSingleSpace = true + } + } + } + + fun println(lineBreaks: Int = 1) { + lastSymbolIsSingleSpace = false + repeat(lineBreaks) { append("\n") } + } + + inline fun indented(block: () -> Unit) { + currentIndent++ + block() + currentIndent-- + } + + inline fun block(body: () -> Unit) { + par(ParenthesisKind.CURVED) { + indented(body) + } + } + + inline fun par(kind: ParenthesisKind = ParenthesisKind.ROUND, body: () -> Unit) { + print(kind.open) + body() + print(kind.close) + } + + inline fun renderList(list: Collection, separator: String = ", ", renderElement: (T) -> Unit) = + renderList(list, { this.print(separator) }, renderElement) + + inline fun renderList(list: Collection, separator: () -> Unit, renderElement: (T) -> Unit) { + if (list.isEmpty()) return + var first = true + for (element in list) { + if (first) { + first = false + } else { + separator() + } + renderElement(element) + } + } + + private fun append(text: String) { + if (lastSymbolIsLineBreak) { + stringBuilder.append(indentSymbol.repeat(currentIndent)) + } + stringBuilder.append(text) + + lastSymbolIsLineBreak = stringBuilder.lastOrNull() == '\n' + } + + enum class ParenthesisKind(val open: String, val close: String) { + ROUND("(", ")"), + CURVED("{", "}"), + ANGLE("<", ">"), + SQUARE("[", "]") + } +} \ No newline at end of file diff --git a/modules/fc2tolk/src/org/ton/intellij/fc2tolk/symbols/FTTypeParameterSymbol.kt b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/symbols/FTTypeParameterSymbol.kt new file mode 100644 index 0000000..58c5dc4 --- /dev/null +++ b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/symbols/FTTypeParameterSymbol.kt @@ -0,0 +1,9 @@ +package org.ton.intellij.fc2tolk.symbols + +import org.ton.intellij.func.psi.FuncTypeParameter + +abstract class FTTypeParameterSymbol : JKSymbol + +class FTFuncTypeParameterSymbol( + override val target: FuncTypeParameter +) : FTTypeParameterSymbol() \ No newline at end of file diff --git a/modules/fc2tolk/src/org/ton/intellij/fc2tolk/symbols/JKSymbol.kt b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/symbols/JKSymbol.kt new file mode 100644 index 0000000..45b1b34 --- /dev/null +++ b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/symbols/JKSymbol.kt @@ -0,0 +1,5 @@ +package org.ton.intellij.fc2tolk.symbols + +interface JKSymbol { + val target: Any +} \ No newline at end of file diff --git a/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/base.kt b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/base.kt new file mode 100644 index 0000000..70f0a0b --- /dev/null +++ b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/base.kt @@ -0,0 +1,89 @@ +package org.ton.intellij.fc2tolk.tree + +import org.ton.intellij.fc2tolk.tree.visitors.FTVisitor +import kotlin.properties.ReadWriteProperty +import kotlin.reflect.KProperty + +interface FTElement { + val parent: FTElement? + + fun detach(from: FTElement) + fun attach(to: FTElement) +} + +abstract class FTTreeElement : FTElement { + override var parent: FTElement? = null + internal val children: ArrayList = ArrayList() + private var childNum = 0 + + override fun detach(from: FTElement) { + val prevParent = parent + require(from == parent) { + "Incorrect detach: From: $from, Actual: $prevParent" + } + parent = null + } + + override fun attach(to: FTElement) { + check(parent == null) + parent = to + } + + open fun accept(visitor: FTVisitor) = visitor.visitTreeElement(this) + + protected fun child(v: U): ReadWriteProperty { + children.add(childNum, v) + v.attach(this) + return FTChild(childNum++) + } + + protected fun children(v: List): ReadWriteProperty> { + children.add(childNum, v) + v.forEach { it.attach(this) } + return FTListChild(childNum++) + } + + open fun acceptChildren(visitor: FTVisitor) { + forEachChild { it.accept(visitor) } + } + + private inline fun forEachChild(block: (FTTreeElement) -> Unit) { + children.forEach { child -> + if (child is FTTreeElement) { + block(child) + } else { + @Suppress("UNCHECKED_CAST") + (child as? List)?.forEach { + block(it) + } + } + } + } + + private class FTListChild(val index: Int) : ReadWriteProperty> { + override fun getValue(thisRef: FTTreeElement, property: KProperty<*>): List { + @Suppress("UNCHECKED_CAST") + return thisRef.children[index] as List + } + + override fun setValue(thisRef: FTTreeElement, property: KProperty<*>, value: List) { + @Suppress("UNCHECKED_CAST") + (thisRef.children[index] as List).forEach { it.detach(thisRef) } + thisRef.children[index] = value + value.forEach { it.attach(thisRef) } + } + } + + private class FTChild(val index: Int) : ReadWriteProperty { + override fun getValue(thisRef: FTTreeElement, property: KProperty<*>): T { + @Suppress("UNCHECKED_CAST") + return thisRef.children[index] as T + } + + override fun setValue(thisRef: FTTreeElement, property: KProperty<*>, value: T) { + (thisRef.children[index] as T).detach(thisRef) + thisRef.children[index] = value + value.attach(thisRef) + } + } +} diff --git a/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/declarations.kt b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/declarations.kt new file mode 100644 index 0000000..c2bbf82 --- /dev/null +++ b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/declarations.kt @@ -0,0 +1,38 @@ +package org.ton.intellij.fc2tolk.tree + +import org.ton.intellij.fc2tolk.tree.visitors.FTVisitor + +abstract class FTDeclaration : FTTreeElement() { + abstract val name: FTNameIdentifier +} + + +class FTFunction( + returnType: FTTypeElement, + name: FTNameIdentifier, + typeParameterList: FTTypeParameterList, + functionModifiers: List +) : FTDeclaration() { + val returnType: FTTypeElement by child(returnType) + override val name: FTNameIdentifier by child(name) + val typeParameterList: FTTypeParameterList by child(typeParameterList) + val functionModifiers: List by children(functionModifiers) + + override fun accept(visitor: FTVisitor) = visitor.visitFunction(this) +} + +class FTTypeParameter( + name: FTNameIdentifier +) : FTDeclaration() { + override val name: FTNameIdentifier by child(name) + + override fun accept(visitor: FTVisitor) = visitor.visitTypeParameter(this) +} + +class FTTypeParameterList( + typeParameters: List +) : FTTreeElement() { + var typeParameters: List by children(typeParameters) + + override fun accept(visitor: FTVisitor) = visitor.visitTypeParameterList(this) +} \ No newline at end of file diff --git a/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/elements.kt b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/elements.kt new file mode 100644 index 0000000..1f34da2 --- /dev/null +++ b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/elements.kt @@ -0,0 +1,31 @@ +package org.ton.intellij.fc2tolk.tree + +import org.ton.intellij.fc2tolk.tree.visitors.FTVisitor + +class FTTreeRoot(element: FTTreeElement) : FTTreeElement() { + var element by child(element) + + override fun accept(visitor: FTVisitor) = visitor.visitTreeRoot(this) +} + +class FTFile( + declarationList: List +) : FTTreeElement() { + var declarationList: List by children(declarationList) + + override fun accept(visitor: FTVisitor) = visitor.visitFile(this) +} + +class FTNameIdentifier(val value: String) : FTTreeElement() { + override fun accept(visitor: FTVisitor) = visitor.visitNameIdentifier(this) +} + +class FTTypeElement(val type: FTType) : FTTreeElement() { + override fun accept(visitor: FTVisitor) = visitor.visitTypeElement(this) +} + +abstract class FTFunctionModifier : FTTreeElement() + +class FTMethodId(val value: String?) : FTFunctionModifier() { + override fun accept(visitor: FTVisitor) = visitor.visitMethodId(this) +} \ No newline at end of file diff --git a/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/treeUtils.kt b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/treeUtils.kt new file mode 100644 index 0000000..78a0253 --- /dev/null +++ b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/treeUtils.kt @@ -0,0 +1,89 @@ +package org.ton.intellij.fc2tolk.tree + +fun applyRecursive(element: E, data: D, func: (FTTreeElement, D) -> FTTreeElement): E { + val iterator = element.children.listIterator() + + fun applyRecursiveToList(child: List): List { + val newChild = child.map { func(it, data) } + child.forEach { it.detach(element) } + iterator.set(child) + newChild.forEach { it.attach(element) } + return newChild + } + + while (iterator.hasNext()) { + when (val child = iterator.next()) { + is List<*> -> { + @Suppress("UNCHECKED_CAST") + val newChild = applyRecursiveToList(child as List) + iterator.set(newChild) + } + + is FTTreeElement -> { + val newChild = func(child, data) + if (child !== newChild) { + child.detach(element) + iterator.set(newChild) + newChild.attach(element) + } + } + + else -> error("unsupported child type: ${child::class}") + } + } + + return element +} + +private val VALID_IDENTIFIER_REGEX = Regex("^[a-zA-Z_$][a-zA-Z_$0-9]*$") + +private val TOLK_KEYWORDS = setOf( + "return", + "var", + "repeat", + "do", + "while", + "try", + "catch", + "if", + "else", + "int", + "cell", + "slice", + "builder", + "continuation", + "tuple", + "type", + "global", + "asm", + "operator", + "infix", + "const", + "true", + "false", + "null", + "builtin", + "get", + "import", + "fun", + "redef", + "auto", + "mutate", + "assert", + "throw", + "void", + "self", + "tolk", + "val", + "bool", + "enum", + "struct", + "export", + "break", + "continue" +) + +fun String.escapedTolkId(): String { + val onlyUnderscores = isNotEmpty() && this.count { it == '_' } == length + return if (onlyUnderscores || !VALID_IDENTIFIER_REGEX.matches(this) || TOLK_KEYWORDS.contains(this)) "`$this`" else this +} \ No newline at end of file diff --git a/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/types.kt b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/types.kt new file mode 100644 index 0000000..0fac732 --- /dev/null +++ b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/types.kt @@ -0,0 +1,30 @@ +package org.ton.intellij.fc2tolk.tree + +import org.ton.intellij.fc2tolk.symbols.FTTypeParameterSymbol + +interface FTType + +object FTUnknownType : FTType + +enum class FTFuncPrimitiveType(val value: String) : FTType { + INT("int"), + CELL("cell"), + BUILDER("builder"), + SLICE("slice"), + TUPLE("tuple"), + CONT("cont"), +} + +object FTFuncHoleType : FTType + +class FTTensorType private constructor(val value: List) : FTType { + companion object { + fun create(value: List): FTType = if (value.size == 1) value[0] else FTTensorType(value) + } +} + +class FTTupleType(val value: List) : FTType + +class FTTypeParameterType( + val identifier: FTTypeParameterSymbol +) : FTType \ No newline at end of file diff --git a/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/visitors/FTVisitor.kt b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/visitors/FTVisitor.kt new file mode 100644 index 0000000..8e1380c --- /dev/null +++ b/modules/fc2tolk/src/org/ton/intellij/fc2tolk/tree/visitors/FTVisitor.kt @@ -0,0 +1,15 @@ +package org.ton.intellij.fc2tolk.tree.visitors + +import org.ton.intellij.fc2tolk.tree.* + +abstract class FTVisitor { + abstract fun visitTreeElement(element: FTElement) + open fun visitTreeRoot(treeRoot: FTTreeRoot) = visitTreeElement(treeRoot) + open fun visitNameIdentifier(nameIdentifier: FTNameIdentifier) = visitTreeElement(nameIdentifier) + open fun visitFile(file: FTFile) = visitTreeElement(file) + open fun visitTypeParameter(typeParameter: FTTypeParameter) = visitTreeElement(typeParameter) + open fun visitTypeParameterList(typeParameterList: FTTypeParameterList) = visitTreeElement(typeParameterList) + open fun visitFunction(function: FTFunction) = visitTreeElement(function) + open fun visitTypeElement(ftTypeElement: FTTypeElement) = visitTreeElement(ftTypeElement) + open fun visitMethodId(methodId: FTMethodId) = visitTreeElement(methodId) +} \ No newline at end of file diff --git a/modules/fift/build.gradle.kts b/modules/fift/build.gradle.kts new file mode 100644 index 0000000..b02cf16 --- /dev/null +++ b/modules/fift/build.gradle.kts @@ -0,0 +1,42 @@ +import org.jetbrains.grammarkit.tasks.GenerateLexerTask +import org.jetbrains.grammarkit.tasks.GenerateParserTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.jetbrains.intellij.platform.module") + id("org.jetbrains.grammarkit") +} + +dependencies { + intellijPlatform { + val version = providers.gradleProperty("platformVersion") + intellijIdeaCommunity(version) + } + compileOnly(project(":util")) +} + +val generateFiftParser = task("generateFiftParser") { + sourceFile.set(file("src/org/ton/intellij/fift/parser/FiftParser.bnf")) + targetRootOutputDir.set(file("gen")) + pathToParser.set("/org/ton/intellij/fift/parser/FiftParser.java") + pathToPsiRoot.set("/org/ton/intellij/fift/psi") + purgeOldFiles.set(true) + + dependsOn(":util:composedJar") +} + +val generateFiftLexer = task("generateFiftLexer") { + val input = "src/org/ton/intellij/fift/lexer/FiftLexer.flex" + val output = "gen/org/ton/intellij/fift/lexer" + sourceFile.set(file(input)) + targetOutputDir.set(file(output)) + purgeOldFiles.set(true) +} + +tasks.withType().configureEach { + dependsOn(generateFiftParser, generateFiftLexer) +} + +tasks.withType().configureEach { + dependsOn(generateFiftParser, generateFiftLexer) +} diff --git a/src/main/resources/META-INF/fift.xml b/modules/fift/resources/META-INF/fift.xml similarity index 100% rename from src/main/resources/META-INF/fift.xml rename to modules/fift/resources/META-INF/fift.xml diff --git a/src/main/resources/colors/highlighter_example.fif b/modules/fift/resources/colors/highlighter_example.fif similarity index 100% rename from src/main/resources/colors/highlighter_example.fif rename to modules/fift/resources/colors/highlighter_example.fif diff --git a/src/main/resources/icons/fif.svg b/modules/fift/resources/icons/fif.svg similarity index 100% rename from src/main/resources/icons/fif.svg rename to modules/fift/resources/icons/fif.svg diff --git a/src/main/kotlin/org/ton/intellij/fift/FiftFileType.kt b/modules/fift/src/org/ton/intellij/fift/FiftFileType.kt similarity index 69% rename from src/main/kotlin/org/ton/intellij/fift/FiftFileType.kt rename to modules/fift/src/org/ton/intellij/fift/FiftFileType.kt index aeb052d..c286b46 100644 --- a/src/main/kotlin/org/ton/intellij/fift/FiftFileType.kt +++ b/modules/fift/src/org/ton/intellij/fift/FiftFileType.kt @@ -1,12 +1,10 @@ package org.ton.intellij.fift import com.intellij.openapi.fileTypes.LanguageFileType -import com.intellij.openapi.vfs.VirtualFile object FiftFileType : LanguageFileType(FiftLanguage) { override fun getName() = "Fift" override fun getDescription() = "Fift" override fun getDefaultExtension() = "fif" override fun getIcon() = FiftIcons.FILE - override fun getCharset(file: VirtualFile, content: ByteArray?) = Charsets.UTF_8.name() } diff --git a/src/main/kotlin/org/ton/intellij/fift/FiftIcons.kt b/modules/fift/src/org/ton/intellij/fift/FiftIcons.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/FiftIcons.kt rename to modules/fift/src/org/ton/intellij/fift/FiftIcons.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/FiftLanguage.kt b/modules/fift/src/org/ton/intellij/fift/FiftLanguage.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/FiftLanguage.kt rename to modules/fift/src/org/ton/intellij/fift/FiftLanguage.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/completion/completion.kt b/modules/fift/src/org/ton/intellij/fift/completion/completion.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/completion/completion.kt rename to modules/fift/src/org/ton/intellij/fift/completion/completion.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/ide/annotation.kt b/modules/fift/src/org/ton/intellij/fift/ide/annotation.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/ide/annotation.kt rename to modules/fift/src/org/ton/intellij/fift/ide/annotation.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/ide/braces.kt b/modules/fift/src/org/ton/intellij/fift/ide/braces.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/ide/braces.kt rename to modules/fift/src/org/ton/intellij/fift/ide/braces.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/ide/colors.kt b/modules/fift/src/org/ton/intellij/fift/ide/colors.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/ide/colors.kt rename to modules/fift/src/org/ton/intellij/fift/ide/colors.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/ide/commenter.kt b/modules/fift/src/org/ton/intellij/fift/ide/commenter.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/ide/commenter.kt rename to modules/fift/src/org/ton/intellij/fift/ide/commenter.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/ide/highlighter.kt b/modules/fift/src/org/ton/intellij/fift/ide/highlighter.kt similarity index 98% rename from src/main/kotlin/org/ton/intellij/fift/ide/highlighter.kt rename to modules/fift/src/org/ton/intellij/fift/ide/highlighter.kt index 8424f77..aed96b0 100644 --- a/src/main/kotlin/org/ton/intellij/fift/ide/highlighter.kt +++ b/modules/fift/src/org/ton/intellij/fift/ide/highlighter.kt @@ -33,7 +33,7 @@ object FiftSyntaxHighlighter : SyntaxHighlighterBase() { TRUE, FALSE -> FiftColor.KEYWORD DUP, DROP, SWAP, ROT, REV_ROT, OVER, TUCK, NIP, DUP_DUP, DROP_DROP, SWAP_SWAP, PICK, ROLL, REV_ROLL, EXCH, EXCH2, COND_DUP, - -> FiftColor.KEYWORD + -> FiftColor.KEYWORD else -> null }.let { diff --git a/src/main/kotlin/org/ton/intellij/fift/ide/parser.kt b/modules/fift/src/org/ton/intellij/fift/ide/parser.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/ide/parser.kt rename to modules/fift/src/org/ton/intellij/fift/ide/parser.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/ide/search.kt b/modules/fift/src/org/ton/intellij/fift/ide/search.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/ide/search.kt rename to modules/fift/src/org/ton/intellij/fift/ide/search.kt diff --git a/src/main/grammar/FiftLexer.flex b/modules/fift/src/org/ton/intellij/fift/lexer/FiftLexer.flex similarity index 100% rename from src/main/grammar/FiftLexer.flex rename to modules/fift/src/org/ton/intellij/fift/lexer/FiftLexer.flex diff --git a/src/main/kotlin/org/ton/intellij/fift/lexer/FiftLexerAdapter.kt b/modules/fift/src/org/ton/intellij/fift/lexer/FiftLexerAdapter.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/lexer/FiftLexerAdapter.kt rename to modules/fift/src/org/ton/intellij/fift/lexer/FiftLexerAdapter.kt diff --git a/src/main/grammar/FiftParser.bnf b/modules/fift/src/org/ton/intellij/fift/parser/FiftParser.bnf similarity index 100% rename from src/main/grammar/FiftParser.bnf rename to modules/fift/src/org/ton/intellij/fift/parser/FiftParser.bnf diff --git a/src/main/kotlin/org/ton/intellij/fift/psi/FiftElementType.kt b/modules/fift/src/org/ton/intellij/fift/psi/FiftElementType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/psi/FiftElementType.kt rename to modules/fift/src/org/ton/intellij/fift/psi/FiftElementType.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/psi/FiftFile.kt b/modules/fift/src/org/ton/intellij/fift/psi/FiftFile.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/psi/FiftFile.kt rename to modules/fift/src/org/ton/intellij/fift/psi/FiftFile.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/psi/FiftTokenType.kt b/modules/fift/src/org/ton/intellij/fift/psi/FiftTokenType.kt similarity index 86% rename from src/main/kotlin/org/ton/intellij/fift/psi/FiftTokenType.kt rename to modules/fift/src/org/ton/intellij/fift/psi/FiftTokenType.kt index c138aea..4412887 100644 --- a/src/main/kotlin/org/ton/intellij/fift/psi/FiftTokenType.kt +++ b/modules/fift/src/org/ton/intellij/fift/psi/FiftTokenType.kt @@ -8,8 +8,7 @@ class FiftTokenType(debugName: String) : IElementType(debugName, FiftLanguage) { if (this === other) return true if (javaClass != other?.javaClass) return false other as FiftTokenType - if (index != other.index) return false - return true + return index == other.index } override fun hashCode(): Int = index.toInt() diff --git a/src/main/kotlin/org/ton/intellij/fift/psi/elements.kt b/modules/fift/src/org/ton/intellij/fift/psi/elements.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/psi/elements.kt rename to modules/fift/src/org/ton/intellij/fift/psi/elements.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/psi/factory.kt b/modules/fift/src/org/ton/intellij/fift/psi/factory.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/psi/factory.kt rename to modules/fift/src/org/ton/intellij/fift/psi/factory.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/resolve/reference.kt b/modules/fift/src/org/ton/intellij/fift/resolve/reference.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/resolve/reference.kt rename to modules/fift/src/org/ton/intellij/fift/resolve/reference.kt diff --git a/src/main/kotlin/org/ton/intellij/fift/resolve/resolver.kt b/modules/fift/src/org/ton/intellij/fift/resolve/resolver.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/fift/resolve/resolver.kt rename to modules/fift/src/org/ton/intellij/fift/resolve/resolver.kt diff --git a/modules/func/build.gradle.kts b/modules/func/build.gradle.kts new file mode 100644 index 0000000..2abed6f --- /dev/null +++ b/modules/func/build.gradle.kts @@ -0,0 +1,43 @@ +import org.jetbrains.grammarkit.tasks.GenerateLexerTask +import org.jetbrains.grammarkit.tasks.GenerateParserTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.jetbrains.intellij.platform.module") + id("org.jetbrains.grammarkit") +} + +dependencies { + intellijPlatform { + val version = providers.gradleProperty("platformVersion") + intellijIdeaCommunity(version) + } + compileOnly(project(":asm")) + compileOnly(project(":util")) +} + +val generateFuncParser = task("generateFuncParser") { + sourceFile.set(file("src/org/ton/intellij/func/parser/FuncParser.bnf")) + targetRootOutputDir.set(file("gen")) + pathToParser.set("/org/ton/intellij/func/parser/FuncParser.java") + pathToPsiRoot.set("/org/ton/intellij/func/psi") + purgeOldFiles.set(true) + + dependsOn(":util:composedJar") +} + +val generateFuncLexer = task("generateFuncLexer") { + val input = "src/org/ton/intellij/func/lexer/FuncLexer.flex" + val output = "gen/org/ton/intellij/func/lexer" + sourceFile.set(file(input)) + targetOutputDir.set(file(output)) + purgeOldFiles.set(true) +} + +tasks.withType().configureEach { + dependsOn(generateFuncParser, generateFuncLexer) +} + +tasks.withType().configureEach { + dependsOn(generateFuncParser, generateFuncLexer) +} diff --git a/src/main/resources/META-INF/func.xml b/modules/func/resources/META-INF/func.xml similarity index 94% rename from src/main/resources/META-INF/func.xml rename to modules/func/resources/META-INF/func.xml index 4303b34..f7f9d36 100644 --- a/src/main/resources/META-INF/func.xml +++ b/modules/func/resources/META-INF/func.xml @@ -71,9 +71,6 @@ - - - - - - + + + + - + diff --git a/src/main/resources/colors/highlighter_example.fc b/modules/func/resources/colors/highlighter_example.fc similarity index 100% rename from src/main/resources/colors/highlighter_example.fc rename to modules/func/resources/colors/highlighter_example.fc diff --git a/modules/func/resources/icons/func_logo.svg b/modules/func/resources/icons/func_logo.svg new file mode 100644 index 0000000..cfff6b5 --- /dev/null +++ b/modules/func/resources/icons/func_logo.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + diff --git a/src/main/resources/inspectionDescriptions/FuncDivideByZero.html b/modules/func/resources/inspectionDescriptions/FuncDivideByZero.html similarity index 100% rename from src/main/resources/inspectionDescriptions/FuncDivideByZero.html rename to modules/func/resources/inspectionDescriptions/FuncDivideByZero.html diff --git a/src/main/resources/inspectionDescriptions/FuncIntOverflow.html b/modules/func/resources/inspectionDescriptions/FuncIntOverflow.html similarity index 100% rename from src/main/resources/inspectionDescriptions/FuncIntOverflow.html rename to modules/func/resources/inspectionDescriptions/FuncIntOverflow.html diff --git a/src/main/resources/inspectionDescriptions/FuncUnusedFunction.html b/modules/func/resources/inspectionDescriptions/FuncUnusedFunction.html similarity index 100% rename from src/main/resources/inspectionDescriptions/FuncUnusedFunction.html rename to modules/func/resources/inspectionDescriptions/FuncUnusedFunction.html diff --git a/src/main/resources/inspectionDescriptions/FuncUnusedFunctionParameter.html b/modules/func/resources/inspectionDescriptions/FuncUnusedFunctionParameter.html similarity index 100% rename from src/main/resources/inspectionDescriptions/FuncUnusedFunctionParameter.html rename to modules/func/resources/inspectionDescriptions/FuncUnusedFunctionParameter.html diff --git a/src/main/resources/inspectionDescriptions/FuncUnusedVariable.html b/modules/func/resources/inspectionDescriptions/FuncUnusedVariable.html similarity index 100% rename from src/main/resources/inspectionDescriptions/FuncUnusedVariable.html rename to modules/func/resources/inspectionDescriptions/FuncUnusedVariable.html diff --git a/src/main/resources/messages/FuncBundle.properties b/modules/func/resources/messages/FuncBundle.properties similarity index 100% rename from src/main/resources/messages/FuncBundle.properties rename to modules/func/resources/messages/FuncBundle.properties diff --git a/src/main/kotlin/org/ton/intellij/func/FuncBundle.kt b/modules/func/src/org/ton/intellij/func/FuncBundle.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/FuncBundle.kt rename to modules/func/src/org/ton/intellij/func/FuncBundle.kt diff --git a/src/main/kotlin/org/ton/intellij/func/FuncFileElementType.kt b/modules/func/src/org/ton/intellij/func/FuncFileElementType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/FuncFileElementType.kt rename to modules/func/src/org/ton/intellij/func/FuncFileElementType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/FuncFileType.kt b/modules/func/src/org/ton/intellij/func/FuncFileType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/FuncFileType.kt rename to modules/func/src/org/ton/intellij/func/FuncFileType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/FuncIcons.kt b/modules/func/src/org/ton/intellij/func/FuncIcons.kt similarity index 83% rename from src/main/kotlin/org/ton/intellij/func/FuncIcons.kt rename to modules/func/src/org/ton/intellij/func/FuncIcons.kt index a7905c4..0d58620 100644 --- a/src/main/kotlin/org/ton/intellij/func/FuncIcons.kt +++ b/modules/func/src/org/ton/intellij/func/FuncIcons.kt @@ -4,7 +4,7 @@ import com.intellij.icons.AllIcons import com.intellij.openapi.util.IconLoader object FuncIcons { - val FILE = IconLoader.getIcon("/icons/fc.svg", FuncIcons::class.java) + val FILE = IconLoader.getIcon("/icons/func_logo.svg", FuncIcons::class.java) val FUNCTION = AllIcons.Nodes.Function val PARAMETER = AllIcons.Nodes.Parameter val CONSTANT = AllIcons.Nodes.Constant diff --git a/src/main/kotlin/org/ton/intellij/func/FuncLanguage.kt b/modules/func/src/org/ton/intellij/func/FuncLanguage.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/FuncLanguage.kt rename to modules/func/src/org/ton/intellij/func/FuncLanguage.kt diff --git a/src/main/kotlin/org/ton/intellij/func/FuncLanguageLevel.kt b/modules/func/src/org/ton/intellij/func/FuncLanguageLevel.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/FuncLanguageLevel.kt rename to modules/func/src/org/ton/intellij/func/FuncLanguageLevel.kt diff --git a/src/main/kotlin/org/ton/intellij/func/action/file/FuncCreateFileAction.kt b/modules/func/src/org/ton/intellij/func/action/file/FuncCreateFileAction.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/action/file/FuncCreateFileAction.kt rename to modules/func/src/org/ton/intellij/func/action/file/FuncCreateFileAction.kt diff --git a/src/main/kotlin/org/ton/intellij/func/action/file/FuncToCamelCaseAction.kt b/modules/func/src/org/ton/intellij/func/action/file/FuncToCamelCaseAction.kt similarity index 99% rename from src/main/kotlin/org/ton/intellij/func/action/file/FuncToCamelCaseAction.kt rename to modules/func/src/org/ton/intellij/func/action/file/FuncToCamelCaseAction.kt index cf1aa3e..25809a3 100644 --- a/src/main/kotlin/org/ton/intellij/func/action/file/FuncToCamelCaseAction.kt +++ b/modules/func/src/org/ton/intellij/func/action/file/FuncToCamelCaseAction.kt @@ -240,7 +240,7 @@ fun isSnakeCase(inputStr: String): Boolean { fun isCamelCase(inputStr: String): Boolean { val sanitizedStr = inputStr.filter { it.isLetterOrDigit() } - return sanitizedStr.firstOrNull()?.isLowerCase() ?: false || sanitizedStr.any { it.isUpperCase() } + return sanitizedStr.firstOrNull()?.isLowerCase() == true || sanitizedStr.any { it.isUpperCase() } } private fun snakeToCamel(inputStr: String): String { diff --git a/modules/func/src/org/ton/intellij/func/converter/ConvertFuncToTolkOptions.kt b/modules/func/src/org/ton/intellij/func/converter/ConvertFuncToTolkOptions.kt new file mode 100644 index 0000000..d9168cd --- /dev/null +++ b/modules/func/src/org/ton/intellij/func/converter/ConvertFuncToTolkOptions.kt @@ -0,0 +1,3 @@ +package org.ton.intellij.func.converter + +class ConvertFuncToTolkOptions diff --git a/modules/func/src/org/ton/intellij/func/converter/FuncConversationWarning.kt b/modules/func/src/org/ton/intellij/func/converter/FuncConversationWarning.kt new file mode 100644 index 0000000..608037a --- /dev/null +++ b/modules/func/src/org/ton/intellij/func/converter/FuncConversationWarning.kt @@ -0,0 +1,7 @@ +package org.ton.intellij.func.converter + +data class FuncConversationWarning( + val text: String, + val line: Int, + val col: Int +) diff --git a/modules/func/src/org/ton/intellij/func/converter/FuncRenamingMapping.kt b/modules/func/src/org/ton/intellij/func/converter/FuncRenamingMapping.kt new file mode 100644 index 0000000..efe9b9d --- /dev/null +++ b/modules/func/src/org/ton/intellij/func/converter/FuncRenamingMapping.kt @@ -0,0 +1,398 @@ +package org.ton.intellij.func.converter + +object FuncRenamingMapping { + val ENTRYPOINT_RENAMING = mapOf( + "recv_internal" to "onInternalMessage", + "recv_external" to "onExternalMessage", + "run_ticktock" to "onRunTickTock", + "split_prepare" to "onSplitPrepare", + "split_install" to "onSplitInstall", + ) + + val STDLIB_RENAMING = mapOf( + "fake_std_fn" to "FAKE_STD_FN", + "empty_tuple" to "createEmptyTuple", + "tpush" to "tuplePush", + "first" to "tupleFirst", + "at" to "tupleAt", + "touch" to "stackMoveToTop", + "minmax" to "minMax", + "my_address" to "getMyAddress", + "get_balance" to "getMyOriginalBalanceWithExtraCurrencies", + "cur_lt" to "getLogicalTime", + "block_lt" to "getCurrentBlockLogicalTime", + "cell_hash" to "cellHash", + "slice_hash" to "sliceHash", + "string_hash" to "stringHash", + "check_signature" to "isSignatureValid", + "check_data_signature" to "isSliceSignatureValid", + "compute_data_size" to "calculateCellSizeStrict", + "slice_compute_data_size" to "calculateSliceSizeStrict", + "compute_data_size?" to "calculateCellSize", + "slice_compute_data_size?" to "calculateSliceSize", + "~dump" to "debugPrint", + "~strdump" to "debugPrintString", + "dump_stack" to "debugDumpStack", + "get_data" to "getContractData", + "set_data" to "setContractData", + "get_c3" to "getTvmRegisterC3", + "set_c3" to "setTvmRegisterC3", + "bless" to "transformSliceToContinuation", + "accept_message" to "acceptExternalMessage", + "set_gas_limit" to "setGasLimit", + "commit" to "commitContractDataAndActions", + "divmod" to "divMod", + "moddiv" to "modDiv", + "muldiv" to "mulDivFloor", + "muldivr" to "mulDivRound", + "muldivc" to "mulDivCeil", + "muldivmod" to "mulDivMod", + "begin_parse" to "beginParse", + "end_parse" to "assertEndOfSlice", + "load_ref" to "loadRef", + "preload_ref" to "preloadRef", + "load_int" to "loadInt", + "load_uint" to "loadUint", + "preload_int" to "preloadInt", + "preload_uint" to "preloadUint", + "load_bits" to "loadBits", + "preload_bits" to "preloadBits", + "load_grams" to "loadCoins", + "load_coins" to "loadCoins", + "skip_bits" to "skipBits", + "first_bits" to "getFirstBits", + "skip_last_bits" to "removeLastBits", + "slice_last" to "getLastBits", + "load_dict" to "loadDict", + "preload_dict" to "preloadDict", + "skip_dict" to "skipDict", + "load_maybe_ref" to "loadMaybeRef", + "preload_maybe_ref" to "preloadMaybeRef", + "cell_depth" to "getCellDepth", + "slice_refs" to "getRemainingRefsCount", + "slice_bits" to "getRemainingBitsCount", + "slice_bits_refs" to "getRemainingBitsAndRefsCount", + "slice_empty?" to "isEndOfSlice", + "slice_data_empty?" to "isEndOfSliceBits", + "slice_refs_empty?" to "isEndOfSliceRefs", + "slice_depth" to "getSliceDepth", + "equal_slice_bits" to "isSliceBitsEqual", + "builder_refs" to "getBuilderRefsCount", + "builder_bits" to "getBuilderBitsCount", + "builder_depth" to "getBuilderDepth", + "begin_cell" to "beginCell", + "end_cell" to "endCell", + "store_ref" to "storeRef", + "store_uint" to "storeUint", + "store_int" to "storeInt", + "store_slice" to "storeSlice", + "store_grams" to "storeCoins", + "store_coins" to "storeCoins", + "store_dict" to "storeDict", + "store_maybe_ref" to "storeMaybeRef", + "store_builder" to "storeBuilder", + "load_msg_addr" to "loadAddress", + "parse_addr" to "parseAddress", + "parse_std_addr" to "parseStandardAddress", + "config_param" to "getBlockchainConfigParam", + "raw_reserve" to "reserveToncoinsOnBalance", + "raw_reserve_extra" to "reserveExtraCurrenciesOnBalance", + "send_raw_message" to "sendRawMessage", + "set_code" to "setContractCodePostponed", + "rand" to "randomRange", + "get_seed" to "randomGetSeed", + "set_seed" to "randomSetSeed", + "randomize" to "randomizeBy", + "randomize_lt" to "randomizeByLogicalTime", + "dump" to "debugPrint", + "strdump" to "debugPrintString", + "dump_stk" to "debugDumpStack", + "empty_list" to "createEmptyList", + "cons" to "listPrepend", + "uncons" to "listSplit", + "list_next" to "listNext", + "car" to "listGetHead", + "cdr" to "listGetTail", + "new_dict" to "createEmptyDict", + "dict_empty?" to "dictIsEmpty", + "idict_set_ref" to "iDictSetRef", + "udict_set_ref" to "uDictSetRef", + "idict_get_ref" to "iDictGetRefOrNull", + "idict_get_ref?" to "iDictGetRef", + "udict_get_ref?" to "uDictGetRef", + "idict_set_get_ref" to "iDictSetAndGetRefOrNull", + "udict_set_get_ref" to "iDictSetAndGetRefOrNull", + "idict_delete?" to "iDictDelete", + "udict_delete?" to "uDictDelete", + "idict_get?" to "iDictGet", + "udict_get?" to "uDictGet", + "idict_delete_get?" to "iDictDeleteAndGet", + "udict_delete_get?" to "uDictDeleteAndGet", + "udict_set" to "uDictSet", + "idict_set" to "iDictSet", + "dict_set" to "sDictSet", + "udict_add?" to "uDictSetIfNotExists", + "udict_replace?" to "uDictSetIfExists", + "idict_add?" to "iDictSetIfNotExists", + "idict_replace?" to "iDictSetIfExists", + "udict_set_builder" to "uDictSetBuilder", + "idict_set_builder" to "iDictSetBuilder", + "dict_set_builder" to "sDictSetBuilder", + "udict_add_builder?" to "uDictSetBuilderIfNotExists", + "udict_replace_builder?" to "uDictSetBuilderIfExists", + "idict_add_builder?" to "iDictSetBuilderIfNotExists", + "idict_replace_builder?" to "iDictSetBuilderIfExists", + "udict_delete_get_min" to "uDictDeleteFirstAndGet", + "idict_delete_get_min" to "iDictDeleteFirstAndGet", + "dict_delete_get_min" to "sDictDeleteFirstAndGet", + "udict_delete_get_max" to "uDictDeleteLastAndGet", + "idict_delete_get_max" to "iDictDeleteLastAndGet", + "dict_delete_get_max" to "sDictDeleteLastAndGet", + "udict_get_min?" to "uDictGetFirst", + "udict_get_max?" to "uDictGetLast", + "udict_get_min_ref?" to "uDictGetFirstAsRef", + "udict_get_max_ref?" to "uDictGetLastAsRef", + "idict_get_min?" to "iDictGetFirst", + "idict_get_max?" to "iDictGetLast", + "idict_get_min_ref?" to "iDictGetFirstAsRef", + "idict_get_max_ref?" to "iDictGetLastAsRef", + "udict_get_next?" to "uDictGetNext", + "udict_get_nexteq?" to "uDictGetNextOrEqual", + "udict_get_prev?" to "uDictGetPrev", + "udict_get_preveq?" to "uDictGetPrevOrEqual", + "idict_get_next?" to "iDictGetNext", + "idict_get_nexteq?" to "iDictGetNextOrEqual", + "idict_get_prev?" to "iDictGetPrev", + "idict_get_preveq?" to "iDictGetPrevOrEqual", + "udict::delete_get_min" to "uDictDeleteFirstAndGet", + "idict::delete_get_min" to "iDictDeleteFirstAndGet", + "dict::delete_get_min" to "sDictDeleteFirstAndGet", + "udict::delete_get_max" to "uDictDeleteLastAndGet", + "idict::delete_get_max" to "iDictDeleteLastAndGet", + "dict::delete_get_max" to "sDictDeleteLastAndGet", + "pfxdict_get?" to "prefixDictGet", + "pfxdict_set?" to "prefixDictSet", + "pfxdict_delete?" to "prefixDictDelete", + "my_code" to "getContractCode", + "gas_consumed" to "getGasConsumedAtTheMoment", + "my_storage_due" to "getMyStorageDuePayment", + "get_fee_cofigs" to "getBlockchainFeeConfigParams", + "skip_maybe_ref" to "skipMaybeRef", + "load_bool" to "loadBool", + "store_bool" to "storeBool", + "store_address_none" to "storeAddressNone", + "address_none" to "createAddressNone", + "load_msg_flags" to "loadMsgFlags", + "is_bounced" to "isMessageBounced", + "skip_bounced_prefix" to "skipBouncedPrefix", + ) + + val STDLIB_INTRODUCED_CONSTANTS = mapOf( + "MASTERCHAIN" to "-1", + "BASECHAIN" to "0", + "BOUNCEABLE" to "0x18", + "NON_BOUNCEABLE" to "0x10", + "SEND_MODE_REGULAR" to "0", + "SEND_MODE_PAY_FEES_SEPARATELY" to "1", + "SEND_MODE_IGNORE_ERRORS" to "2", + "SEND_MODE_DESTROY" to "32", + "SEND_MODE_CARRY_ALL_REMAINING_MESSAGE_VALUE" to "64", + "SEND_MODE_CARRY_ALL_BALANCE" to "128", + "SEND_MODE_BOUNCE_ON_ACTION_FAIL" to "16", + "SEND_MODE_ESTIMATE_FEE_ONLY" to "1024", + "RESERVE_MODE_EXACT_AMOUNT" to "0", + "RESERVE_MODE_ALL_BUT_AMOUNT" to "1", + "RESERVE_MODE_AT_MOST" to "2", + "RESERVE_MODE_INCREASE_BY_ORIGINAL_BALANCE" to "4", + "RESERVE_MODE_NEGATE_AMOUNT" to "8", + "RESERVE_MODE_BOUNCE_ON_ACTION_FAIL" to "16", + ) + + val STDLIB_DELETED_FUNCTIONS = setOf( + "single", + "unsingle", + "pair", + "unpair", + "triple", + "untriple", + "tuple4", + "untuple4", + "second", + "third", + "fourth", + "pair_first", + "pair_second", + "triple_first", + "triple_second", + "triple_third", + "buy_gas", + "parse_var_addr", + "impure_touch", + ) + + val STDLIB_AUTO_IMPORTS = mapOf( + "createEmptyDict" to "@stdlib/tvm-dicts", + "dictIsEmpty" to "@stdlib/tvm-dicts", + "iDictGet" to "@stdlib/tvm-dicts", + "uDictGet" to "@stdlib/tvm-dicts", + "sDictGet" to "@stdlib/tvm-dicts", + "iDictSet" to "@stdlib/tvm-dicts", + "uDictSet" to "@stdlib/tvm-dicts", + "sDictSet" to "@stdlib/tvm-dicts", + "iDictSetRef" to "@stdlib/tvm-dicts", + "uDictSetRef" to "@stdlib/tvm-dicts", + "sDictSetRef" to "@stdlib/tvm-dicts", + "iDictSetIfNotExists" to "@stdlib/tvm-dicts", + "uDictSetIfNotExists" to "@stdlib/tvm-dicts", + "iDictSetIfExists" to "@stdlib/tvm-dicts", + "uDictSetIfExists" to "@stdlib/tvm-dicts", + "iDictGetRef" to "@stdlib/tvm-dicts", + "uDictGetRef" to "@stdlib/tvm-dicts", + "sDictGetRef" to "@stdlib/tvm-dicts", + "iDictGetRefOrNull" to "@stdlib/tvm-dicts", + "uDictGetRefOrNull" to "@stdlib/tvm-dicts", + "sDictGetRefOrNull" to "@stdlib/tvm-dicts", + "iDictDelete" to "@stdlib/tvm-dicts", + "uDictDelete" to "@stdlib/tvm-dicts", + "sDictDelete" to "@stdlib/tvm-dicts", + "iDictSetAndGet" to "@stdlib/tvm-dicts", + "uDictSetAndGet" to "@stdlib/tvm-dicts", + "sDictSetAndGet" to "@stdlib/tvm-dicts", + "iDictSetAndGetPreviousRefOrNull" to "@stdlib/tvm-dicts", + "uDictSetAndGetPreviousRefOrNull" to "@stdlib/tvm-dicts", + "iDictDeleteAndGet" to "@stdlib/tvm-dicts", + "uDictDeleteAndGet" to "@stdlib/tvm-dicts", + "sDictDeleteAndGet" to "@stdlib/tvm-dicts", + "iDictSetBuilder" to "@stdlib/tvm-dicts", + "uDictSetBuilder" to "@stdlib/tvm-dicts", + "sDictSetBuilder" to "@stdlib/tvm-dicts", + "iDictSetBuilderIfNotExists" to "@stdlib/tvm-dicts", + "uDictSetBuilderIfNotExists" to "@stdlib/tvm-dicts", + "iDictSetBuilderIfExists" to "@stdlib/tvm-dicts", + "uDictSetBuilderIfExists" to "@stdlib/tvm-dicts", + "iDictDeleteFirstAndGet" to "@stdlib/tvm-dicts", + "uDictDeleteFirstAndGet" to "@stdlib/tvm-dicts", + "sDictDeleteFirstAndGet" to "@stdlib/tvm-dicts", + "iDictDeleteLastAndGet" to "@stdlib/tvm-dicts", + "uDictDeleteLastAndGet" to "@stdlib/tvm-dicts", + "sDictDeleteLastAndGet" to "@stdlib/tvm-dicts", + "iDictGetFirst" to "@stdlib/tvm-dicts", + "uDictGetFirst" to "@stdlib/tvm-dicts", + "sDictGetFirst" to "@stdlib/tvm-dicts", + "iDictGetFirstAsRef" to "@stdlib/tvm-dicts", + "uDictGetFirstAsRef" to "@stdlib/tvm-dicts", + "sDictGetFirstAsRef" to "@stdlib/tvm-dicts", + "iDictGetLast" to "@stdlib/tvm-dicts", + "uDictGetLast" to "@stdlib/tvm-dicts", + "sDictGetLast" to "@stdlib/tvm-dicts", + "iDictGetLastAsRef" to "@stdlib/tvm-dicts", + "uDictGetLastAsRef" to "@stdlib/tvm-dicts", + "sDictGetLastAsRef" to "@stdlib/tvm-dicts", + "iDictGetNext" to "@stdlib/tvm-dicts", + "uDictGetNext" to "@stdlib/tvm-dicts", + "iDictGetNextOrEqual" to "@stdlib/tvm-dicts", + "uDictGetNextOrEqual" to "@stdlib/tvm-dicts", + "iDictGetPrev" to "@stdlib/tvm-dicts", + "uDictGetPrev" to "@stdlib/tvm-dicts", + "iDictGetPrevOrEqual" to "@stdlib/tvm-dicts", + "uDictGetPrevOrEqual" to "@stdlib/tvm-dicts", + "prefixDictGet" to "@stdlib/tvm-dicts", + "prefixDictSet" to "@stdlib/tvm-dicts", + "prefixDictDelete" to "@stdlib/tvm-dicts", + + "getGasConsumedAtTheMoment" to "@stdlib/gas-payments", + "acceptExternalMessage" to "@stdlib/gas-payments", + "setGasLimitToMaximum" to "@stdlib/gas-payments", + "setGasLimit" to "@stdlib/gas-payments", + "calculateStorageFee" to "@stdlib/gas-payments", + "calculateMessageFee" to "@stdlib/gas-payments", + "calculateMessageFeeWithoutLumpPrice" to "@stdlib/gas-payments", + "calculateOriginalMessageFee" to "@stdlib/gas-payments", + "getMyStorageDuePayment" to "@stdlib/gas-payments", + + "createEmptyList" to "@stdlib/lisp-lists", + "listPrepend" to "@stdlib/lisp-lists", + "listSplit" to "@stdlib/lisp-lists", + "listNext" to "@stdlib/lisp-lists", + "listGetHead" to "@stdlib/lisp-lists", + "listGetTail" to "@stdlib/lisp-lists", + + "getTvmRegisterC3" to "@stdlib/tvm-lowlevel", + "setTvmRegisterC3" to "@stdlib/tvm-lowlevel", + "transformSliceToContinuation" to "@stdlib/tvm-lowlevel", + "stackMoveToTop" to "@stdlib/tvm-lowlevel", + ) + + val REMOVED_BINARY_OPERATORS = setOf( + "~%", + "^%", + "/%", + "~/=", + "^/=", + "~%=", + "^%=", + "~>>=", + "^>>=", + ) + + val KEYWORDS_RENAMING = mapOf( + "nil" to "null", + "val" to "vall", + "continue" to "continuee", + "break" to "breakk", + "self" to "selff", + ) + + val FUNCTIONS_WHERE_DOT_CALL_BECAME_MUTATING = mapOf( + "load_int" to "int", + "load_uint" to "int", + "load_bits" to "slice", + "load_ref" to "cell", + "load_grams" to "int", + "load_coins" to "int", + "load_dict" to "cell", + "load_maybe_ref" to "cell", + "load_msg_addr" to "slice", + "skip_bits" to "self", + "skip_last_bits" to "self", + "skip_dict" to "self", + "idict_set_ref" to "void", + "udict_set_ref" to "void", + "idict_set_get_ref" to "cell", + "udict_set_get_ref" to "cell", + "idict_delete?" to "int", + "udict_delete?" to "int", + "idict_delete_get?" to "(slice, int)", + "udict_delete_get?" to "(slice, int)", + "udict_set" to "void", + "idict_set" to "void", + "dict_set" to "void", + "udict_add?" to "int", + "udict_replace?" to "int", + "idict_add?" to "int", + "idict_replace?" to "int", + "udict_set_builder" to "void", + "idict_set_builder" to "void", + "dict_set_builder" to "void", + "udict_add_builder?" to "int", + "udict_replace_builder?" to "int", + "idict_add_builder?" to "int", + "idict_replace_builder?" to "int", + "udict_delete_get_min" to "(int, slice, int)", + "idict_delete_get_min" to "(int, slice, int)", + "udict::delete_get_min" to "(int, slice, int)", + "idict::delete_get_min" to "(int, slice, int)", + "dict_delete_get_min" to "(int, slice, int)", + "dict::delete_get_min" to "(int, slice, int)", + "udict_delete_get_max" to "(int, slice, int)", + "idict_delete_get_max" to "(int, slice, int)", + "udict::delete_get_max" to "(int, slice, int)", + "idict::delete_get_max" to "(int, slice, int)", + "dict_delete_get_max" to "(int, slice, int)", + "dict::delete_get_max" to "(int, slice, int)", + "pfxdict_set?" to "int", + "pfxdict_delete?" to "int", + "tpush" to "void", + "list_next" to "T", + ) +} diff --git a/modules/func/src/org/ton/intellij/func/converter/FuncToTolkConverterV1.kt b/modules/func/src/org/ton/intellij/func/converter/FuncToTolkConverterV1.kt new file mode 100644 index 0000000..7db9b5f --- /dev/null +++ b/modules/func/src/org/ton/intellij/func/converter/FuncToTolkConverterV1.kt @@ -0,0 +1,212 @@ +package org.ton.intellij.func.converter + +import com.intellij.psi.PsiElement +import com.intellij.psi.util.elementType +import org.ton.intellij.func.psi.* +import org.ton.intellij.func.psi.impl.isImpure +import org.ton.intellij.func.psi.impl.rawReturnType +import org.ton.intellij.func.type.ty.FuncTyTensor + +class FuncToTolkConverterV1 { + fun convert(file: FuncFile): FuncToTolkState { + val state = FuncToTolkState(file.text, ConvertFuncToTolkOptions()) + for (child in file.children) { + convertPsiElement(child, state) + } + return state + } + + fun convertPsiElement(psiElement: PsiElement, out: FuncToTolkState) { + when (psiElement.elementType) { + FuncElementTypes.FUNCTION -> { + (psiElement as? FuncFunction)?.let { + convertFunction(it, out) + } + } + } + } + + fun convertFunction(psiElement: FuncFunction, out: FuncToTolkState) { + val asmBody = psiElement.asmDefinition + val isImpure = psiElement.isImpure + val nameIdentifier = psiElement.nameIdentifier ?: return + val name = psiElement.name ?: return + asmBody != null && !isImpure + psiElement.inlineKeyword != null + psiElement.inlineRefKeyword != null + psiElement.methodIdDefinition?.lparen == null + val methodIdPsi = psiElement.methodIdDefinition + val typeParameterList = psiElement.typeParameterList.let { + if (psiElement.forallKeyword != null) it else null + } + var returnType = psiElement.typeReference + + out.createEmptyFork(psiElement.firstChild) + val sName = out.createEmptyFork(nameIdentifier) + val sGenerics = psiElement.forallKeyword?.let { out.createEmptyFork(it) } + psiElement.functionParameterList.firstOrNull()?.let { out.createEmptyFork(it) } + val sReturnType = out.createEmptyFork(returnType) + + if (methodIdPsi != null) { + out.registerKnownGetMethod(name) + } + + if (psiElement.blockStatement == null && psiElement.asmDefinition == null) { + out.justSkipPsi(psiElement) + return + } + + var isModifyingMethod = name.firstOrNull() == '~' + if (name.startsWith("load_") || name.startsWith("skip_") || name.startsWith("store_") || name.startsWith("set_")) { + val retType = psiElement.rawReturnType + if (retType is FuncTyTensor && retType.types.size == 2 && psiElement.functionParameterList.size > 2) { + isModifyingMethod = true + } + } + + val localVarNames = extractLocalVarNamesAndParametersFromFunction(psiElement, out) + out.onEnterFunction(localVarNames) + + if (typeParameterList != null) { + val joinedT = typeParameterList.joinToString { it.identifier.text } + sGenerics?.addTextCustom("<$joinedT>") + } + + if (isModifyingMethod) { + returnType = extractActualTypeFromModifyingMethod(returnType) + } + if (returnType is FuncHoleType && (isModifyingMethod || asmBody != null)) { + sReturnType.addTextCustom("void") + } else if (returnType is FuncHoleType) { + // skip + } else { + convertType(returnType, sReturnType) + } + + val oldName = if (name.firstOrNull() == '~') name.substring(1) else name + var newName = replaceIdentifier(oldName, out, false) + FuncRenamingMapping.ENTRYPOINT_RENAMING[newName]?.let { + newName = it + } ?: transformSnakeCaseToCamelCase(newName) + sName.addTextModified(nameIdentifier, newName) + + + } + + fun extractActualTypeFromModifyingMethod( + typeReference: FuncTypeReference, + ): FuncTypeReference { + if (typeReference is FuncParenType) { + return extractActualTypeFromModifyingMethod(typeReference.typeReference ?: return typeReference) + } + + if (typeReference is FuncTensorType) { + return typeReference.typeReferenceList.getOrNull(1) ?: typeReference + } + + return typeReference + } + + fun extractLocalVarNamesAndParametersFromFunction( + psiElement: FuncFunction, + out: FuncToTolkState + ): MutableSet { + val varNames = mutableSetOf() + for (parameter in psiElement.functionParameterList) { + val name = parameter.name ?: continue + varNames.add(replaceIdentifier(name, out, false)) + } + return varNames + } + + fun convertType(typeReference: FuncTypeReference, out: FuncToTolkState) { + when (typeReference) { + is FuncParenType -> { + convertType(typeReference.typeReference ?: return, out) + } + + is FuncPrimitiveType -> { + if (typeReference.contKeyword != null) { + out.addTextModified(typeReference, "continuation") + } else { + out.addTextUnchanged(typeReference) + } + } + + is FuncTensorType -> { + out.addTextCustom("(") + typeReference.typeReferenceList.forEach { + convertType(it, out) + } + out.addTextCustom(")") + } + + is FuncTupleType -> { + out.addTextCustom("[") + typeReference.typeReferenceList.forEach { + convertType(it, out) + } + out.addTextCustom("]") + } + + is FuncHoleType -> { + out.addTextModified(typeReference, "auto") + } + + else -> { + out.addTextUnchanged(typeReference) + } + } + } + + private val VALID_IDENTIFIER_REGEX = Regex("^[a-zA-Z_$][a-zA-Z_$0-9]*$") + + fun replaceIdentifier(name: String, out: FuncToTolkState, isFunctionCall: Boolean): String { + var newName = name + if (newName.startsWith("`")) { + return newName + } + if (!isFunctionCall && out.isInsideModifyingMethod && newName == out.selfVarNameInModifyingMethod) { + return "self" + } + if (isFunctionCall && newName in FuncRenamingMapping.STDLIB_RENAMING) { + newName = FuncRenamingMapping.STDLIB_RENAMING[newName] ?: newName + } + if (!isFunctionCall && newName in FuncRenamingMapping.KEYWORDS_RENAMING) { + newName = FuncRenamingMapping.KEYWORDS_RENAMING[newName] ?: newName + } + if (newName.endsWith("?")) { + newName = if (newName.startsWith("is_")) "" else "is_" + newName.substring(0, newName.length - 1) + } + if (!VALID_IDENTIFIER_REGEX.matches(newName)) { + newName = "`$newName`" + } + if (isFunctionCall && FuncRenamingMapping.STDLIB_AUTO_IMPORTS.containsKey(newName)) { + FuncRenamingMapping.STDLIB_AUTO_IMPORTS[newName]?.let { + out.autoImportStdlib(it) + } + } + return newName + } + + fun transformSnakeCaseToCamelCase(name: String): String { + if (name.startsWith("`")) { + return name + } + val newName = StringBuilder() + var skip = false + for (i in name.indices) { + if (skip) { + skip = false + continue + } + if (name[i] == '_' && i < name.lastIndex && name[i + 1] >= 'a' && name[i + 1] <= 'z') { + newName.append(name[i + 1].uppercase()) + skip = true + } else { + newName.append(name[i]) + } + } + return newName.toString() + } +} diff --git a/modules/func/src/org/ton/intellij/func/converter/FuncToTolkState.kt b/modules/func/src/org/ton/intellij/func/converter/FuncToTolkState.kt new file mode 100644 index 0000000..e5b433e --- /dev/null +++ b/modules/func/src/org/ton/intellij/func/converter/FuncToTolkState.kt @@ -0,0 +1,119 @@ +package org.ton.intellij.func.converter + +import com.intellij.psi.PsiElement + +class FuncToTolkState( + private var funcSource: String, + private var options: ConvertFuncToTolkOptions, + private var forkedFromPsi: PsiElement? = null, + private var lastEndOffset: Int = 0, + var selfVarNameInModifyingMethod: String? = null, + private val localVarNames: MutableSet = mutableSetOf() +) { + private val tolkSource = StringBuilder() + private val warnings = mutableListOf() + private val knownGetMethods = mutableSetOf() + private val importStdlib = mutableSetOf() + + var needInsertTolkPreamble = false + val isInsideModifyingMethod get() = selfVarNameInModifyingMethod != null + + fun createEmptyFork(offsetPsi: PsiElement): FuncToTolkState { + return FuncToTolkState( + funcSource, + options, + offsetPsi, + offsetPsi.textRange.endOffset, + selfVarNameInModifyingMethod, + localVarNames + ) + } + + fun merge(vararg forksAndDelimiters: FuncToTolkState?) { + var minStartOffset = Int.MAX_VALUE + var maxEndOffset = 0 + for (fork in forksAndDelimiters) { + val forkedPsi = fork?.forkedFromPsi + if (forkedPsi != null) { + minStartOffset = minOf(minStartOffset, forkedPsi.textRange.startOffset) + maxEndOffset = maxOf(maxEndOffset, forkedPsi.textRange.endOffset) + } + } + if (minStartOffset > lastEndOffset) { + tolkSource.append(funcSource.substring(lastEndOffset, minStartOffset)) + } + for (fork in forksAndDelimiters) { + if (fork != null) { + tolkSource.append(fork.tolkSource) + warnings.addAll(fork.warnings) + } + } + lastEndOffset = maxEndOffset + } + + + fun registerKnownGetMethod(functionName: String) { + knownGetMethods.add(functionName) + } + + fun justSkipPsi(psiElement: PsiElement, withTrailingNl: Boolean = true) { + if (psiElement.textRange.startOffset > lastEndOffset) { + tolkSource.append(funcSource.substring(lastEndOffset, psiElement.textRange.startOffset)) + } + lastEndOffset = psiElement.textRange.endOffset + if (withTrailingNl && funcSource[lastEndOffset] == '\n') { + lastEndOffset++ + } + } + + fun autoImportStdlib(stdlibFile: String) { + importStdlib.add(stdlibFile) + } + + fun onEnterFunction(localVarNames: Set) { + this.localVarNames.addAll(localVarNames) + } + + fun addTextCustom(text: String) { + this.tolkSource.append(text) + } + + private val FIRST_DERICTIVE_REGEX = Regex("#include|#pragma") + private val VAR_REDEF_REGEX = Regex("var (\\w+) redef =") + + fun resultingTolkSource(): String { + val output = StringBuilder() + + val posFirstDirective = maxOf(0, FIRST_DERICTIVE_REGEX.find(funcSource)?.range?.first ?: 0) + output.append(tolkSource.substring(0, posFirstDirective)) + + if (needInsertTolkPreamble) { + output.append("tolk 0.6\n\n") + } + for (file in importStdlib) { + output.append("import \"$file\"\n") + } + + output.append(tolkSource.substring(posFirstDirective)) + output.replace(VAR_REDEF_REGEX, "$1 =") + output.append("\n") + + return output.toString() + } + + fun addTextModified(psiElement: PsiElement, text: String) { + if (psiElement.textRange.startOffset > lastEndOffset) { + tolkSource.append(funcSource.substring(lastEndOffset, psiElement.textRange.startOffset)) + } + tolkSource.append(text) + lastEndOffset = psiElement.textRange.endOffset + } + + fun addTextUnchanged(psiElement: PsiElement) { + if (psiElement.textRange.startOffset > lastEndOffset) { + tolkSource.append(funcSource.substring(lastEndOffset, psiElement.textRange.startOffset)) + } + tolkSource.append(psiElement.text) + lastEndOffset = psiElement.textRange.endOffset + } +} diff --git a/src/main/kotlin/org/ton/intellij/func/diagnostics/FuncDiagnostic.kt b/modules/func/src/org/ton/intellij/func/diagnostics/FuncDiagnostic.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/diagnostics/FuncDiagnostic.kt rename to modules/func/src/org/ton/intellij/func/diagnostics/FuncDiagnostic.kt diff --git a/src/main/kotlin/org/ton/intellij/func/doc/FuncDocCommentElementType.kt b/modules/func/src/org/ton/intellij/func/doc/FuncDocCommentElementType.kt similarity index 97% rename from src/main/kotlin/org/ton/intellij/func/doc/FuncDocCommentElementType.kt rename to modules/func/src/org/ton/intellij/func/doc/FuncDocCommentElementType.kt index eca9252..2da02d9 100644 --- a/src/main/kotlin/org/ton/intellij/func/doc/FuncDocCommentElementType.kt +++ b/modules/func/src/org/ton/intellij/func/doc/FuncDocCommentElementType.kt @@ -29,8 +29,8 @@ import org.ton.intellij.func.doc.psi.FuncDocElementTypes.DOC_TEXT import org.ton.intellij.func.doc.psi.impl.FuncDocCommentImpl import org.ton.intellij.func.doc.psi.impl.FuncDocGapImpl import org.ton.intellij.func.psi.FuncElementTypes -import org.ton.intellij.markdown.MarkdownDocAstBuilder -import org.ton.intellij.markdown.MarkdownPsiFactory +import org.ton.intellij.util.markdown.MarkdownDocAstBuilder +import org.ton.intellij.util.markdown.MarkdownPsiFactory class FuncDocCommentElementType(debugName: String) : ILazyParseableElementType(debugName, FuncLanguage) { val factory = object : MarkdownPsiFactory { diff --git a/src/main/kotlin/org/ton/intellij/func/doc/FuncDocMarkdownFlavourDescriptor.kt b/modules/func/src/org/ton/intellij/func/doc/FuncDocMarkdownFlavourDescriptor.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/doc/FuncDocMarkdownFlavourDescriptor.kt rename to modules/func/src/org/ton/intellij/func/doc/FuncDocMarkdownFlavourDescriptor.kt diff --git a/src/main/kotlin/org/ton/intellij/func/doc/FuncDocRender.kt b/modules/func/src/org/ton/intellij/func/doc/FuncDocRender.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/doc/FuncDocRender.kt rename to modules/func/src/org/ton/intellij/func/doc/FuncDocRender.kt diff --git a/src/main/kotlin/org/ton/intellij/func/doc/FuncDocumentationProvider.kt b/modules/func/src/org/ton/intellij/func/doc/FuncDocumentationProvider.kt similarity index 95% rename from src/main/kotlin/org/ton/intellij/func/doc/FuncDocumentationProvider.kt rename to modules/func/src/org/ton/intellij/func/doc/FuncDocumentationProvider.kt index 0a0022c..b57b8fb 100644 --- a/src/main/kotlin/org/ton/intellij/func/doc/FuncDocumentationProvider.kt +++ b/modules/func/src/org/ton/intellij/func/doc/FuncDocumentationProvider.kt @@ -10,7 +10,7 @@ import org.ton.intellij.func.highlighting.FuncColor import org.ton.intellij.func.psi.* import org.ton.intellij.func.psi.impl.isImpure import org.ton.intellij.func.psi.impl.isMutable -import org.ton.intellij.markdown.MarkdownDocAstBuilder +import org.ton.intellij.util.markdown.MarkdownDocAstBuilder import java.util.function.Consumer class FuncDocumentationProvider : AbstractDocumentationProvider() { @@ -202,12 +202,7 @@ class FuncDocumentationProvider : AbstractDocumentationProvider() { is FuncUnitType -> appendStyledSpan(FuncColor.PARENTHESES.attributes, "()") else -> { - val typeIdentifier = type.typeIdentifier?.text - if (typeIdentifier != null) { - appendStyledSpan(FuncColor.TYPE_PARAMETER.attributes, typeIdentifier) - } else { - append(type) - } + append(type) } } } diff --git a/src/main/kotlin/org/ton/intellij/func/doc/FuncReferenceLinksGeneratingProvider.kt b/modules/func/src/org/ton/intellij/func/doc/FuncReferenceLinksGeneratingProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/doc/FuncReferenceLinksGeneratingProvider.kt rename to modules/func/src/org/ton/intellij/func/doc/FuncReferenceLinksGeneratingProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/func/doc/psi/FuncDocComment.kt b/modules/func/src/org/ton/intellij/func/doc/psi/FuncDocComment.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/doc/psi/FuncDocComment.kt rename to modules/func/src/org/ton/intellij/func/doc/psi/FuncDocComment.kt diff --git a/src/main/kotlin/org/ton/intellij/func/doc/psi/FuncDocElementTypes.kt b/modules/func/src/org/ton/intellij/func/doc/psi/FuncDocElementTypes.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/doc/psi/FuncDocElementTypes.kt rename to modules/func/src/org/ton/intellij/func/doc/psi/FuncDocElementTypes.kt diff --git a/src/main/kotlin/org/ton/intellij/func/doc/psi/FuncDocTokenType.kt b/modules/func/src/org/ton/intellij/func/doc/psi/FuncDocTokenType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/doc/psi/FuncDocTokenType.kt rename to modules/func/src/org/ton/intellij/func/doc/psi/FuncDocTokenType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/doc/psi/impl/FuncDocCommentImpl.kt b/modules/func/src/org/ton/intellij/func/doc/psi/impl/FuncDocCommentImpl.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/doc/psi/impl/FuncDocCommentImpl.kt rename to modules/func/src/org/ton/intellij/func/doc/psi/impl/FuncDocCommentImpl.kt diff --git a/src/main/kotlin/org/ton/intellij/func/doc/psi/impl/Psi.kt b/modules/func/src/org/ton/intellij/func/doc/psi/impl/Psi.kt similarity index 97% rename from src/main/kotlin/org/ton/intellij/func/doc/psi/impl/Psi.kt rename to modules/func/src/org/ton/intellij/func/doc/psi/impl/Psi.kt index 1f9651f..1b8cc30 100644 --- a/src/main/kotlin/org/ton/intellij/func/doc/psi/impl/Psi.kt +++ b/modules/func/src/org/ton/intellij/func/doc/psi/impl/Psi.kt @@ -27,7 +27,7 @@ abstract class FuncDocElementImpl(type: IElementType) : CompositePsiElement(type override fun toString(): String = "${javaClass.simpleName}($elementType)" } -class FuncDocGapImpl(type: IElementType, val text: CharSequence) : LeafPsiElement(type, text), FuncDocGap { +class FuncDocGapImpl(type: IElementType, text: CharSequence) : LeafPsiElement(type, text), FuncDocGap { override fun getTokenType(): IElementType = elementType } diff --git a/src/main/kotlin/org/ton/intellij/func/editor/FuncTypedHandler.kt b/modules/func/src/org/ton/intellij/func/editor/FuncTypedHandler.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/editor/FuncTypedHandler.kt rename to modules/func/src/org/ton/intellij/func/editor/FuncTypedHandler.kt diff --git a/src/main/kotlin/org/ton/intellij/func/eval/FuncConstantExpressionEvaluator.kt b/modules/func/src/org/ton/intellij/func/eval/FuncConstantExpressionEvaluator.kt similarity index 98% rename from src/main/kotlin/org/ton/intellij/func/eval/FuncConstantExpressionEvaluator.kt rename to modules/func/src/org/ton/intellij/func/eval/FuncConstantExpressionEvaluator.kt index 4d5923f..b225a74 100644 --- a/src/main/kotlin/org/ton/intellij/func/eval/FuncConstantExpressionEvaluator.kt +++ b/modules/func/src/org/ton/intellij/func/eval/FuncConstantExpressionEvaluator.kt @@ -8,9 +8,9 @@ import com.intellij.psi.util.CachedValueProvider import com.intellij.psi.util.CachedValuesManager import com.intellij.psi.util.PsiModificationTracker import org.ton.intellij.func.psi.* -import org.ton.intellij.tvm.math.divModCeil -import org.ton.intellij.tvm.math.divModFloor -import org.ton.intellij.tvm.math.divModRound +import org.ton.intellij.util.divModCeil +import org.ton.intellij.util.divModFloor +import org.ton.intellij.util.divModRound import org.ton.intellij.util.exception.ConstantEvaluationOverflowException import org.ton.intellij.util.recursionGuard import java.math.BigInteger diff --git a/src/main/kotlin/org/ton/intellij/func/eval/FuncValue.kt b/modules/func/src/org/ton/intellij/func/eval/FuncValue.kt similarity index 98% rename from src/main/kotlin/org/ton/intellij/func/eval/FuncValue.kt rename to modules/func/src/org/ton/intellij/func/eval/FuncValue.kt index c71d5ea..88c9333 100644 --- a/src/main/kotlin/org/ton/intellij/func/eval/FuncValue.kt +++ b/modules/func/src/org/ton/intellij/func/eval/FuncValue.kt @@ -7,8 +7,7 @@ import java.math.BigInteger import java.security.MessageDigest import java.util.zip.CRC32 -sealed interface FuncValue : FuncTyProvider { -} +sealed interface FuncValue : FuncTyProvider object FuncUnknownValue : FuncValue { override fun getFuncTy(): FuncTy { diff --git a/src/main/kotlin/org/ton/intellij/func/highlighting/FuncAnnotator.kt b/modules/func/src/org/ton/intellij/func/highlighting/FuncAnnotator.kt similarity index 97% rename from src/main/kotlin/org/ton/intellij/func/highlighting/FuncAnnotator.kt rename to modules/func/src/org/ton/intellij/func/highlighting/FuncAnnotator.kt index 5d360a4..b761906 100644 --- a/src/main/kotlin/org/ton/intellij/func/highlighting/FuncAnnotator.kt +++ b/modules/func/src/org/ton/intellij/func/highlighting/FuncAnnotator.kt @@ -10,8 +10,8 @@ import org.ton.intellij.func.FuncBundle import org.ton.intellij.func.eval.FuncIntValue import org.ton.intellij.func.eval.value import org.ton.intellij.func.psi.* -import org.ton.intellij.tvm.math.TVM_INT_MAX_VALUE -import org.ton.intellij.tvm.math.TVM_INT_MIN_VALUE +import org.ton.intellij.util.TVM_INT_MAX_VALUE +import org.ton.intellij.util.TVM_INT_MIN_VALUE class FuncAnnotator : Annotator { override fun annotate(element: PsiElement, holder: AnnotationHolder) { @@ -20,10 +20,12 @@ class FuncAnnotator : Annotator { highlight(element.identifier, holder, FuncColor.TYPE_PARAMETER.textAttributesKey) return } + is FuncTypeIdentifier -> { highlight(element.identifier, holder, FuncColor.TYPE_PARAMETER.textAttributesKey) return } + is FuncIncludeDefinition, is FuncPragmaDefinition -> { val sha = element.node.firstChildNode val macroName = sha.treeNext diff --git a/src/main/kotlin/org/ton/intellij/func/highlighting/FuncColor.kt b/modules/func/src/org/ton/intellij/func/highlighting/FuncColor.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/highlighting/FuncColor.kt rename to modules/func/src/org/ton/intellij/func/highlighting/FuncColor.kt diff --git a/src/main/kotlin/org/ton/intellij/func/highlighting/FuncDocAnnotator.kt b/modules/func/src/org/ton/intellij/func/highlighting/FuncDocAnnotator.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/highlighting/FuncDocAnnotator.kt rename to modules/func/src/org/ton/intellij/func/highlighting/FuncDocAnnotator.kt diff --git a/src/main/kotlin/org/ton/intellij/func/highlighting/FuncSyntaxHighlighter.kt b/modules/func/src/org/ton/intellij/func/highlighting/FuncSyntaxHighlighter.kt similarity index 98% rename from src/main/kotlin/org/ton/intellij/func/highlighting/FuncSyntaxHighlighter.kt rename to modules/func/src/org/ton/intellij/func/highlighting/FuncSyntaxHighlighter.kt index 8c2adb5..8d23b0b 100644 --- a/src/main/kotlin/org/ton/intellij/func/highlighting/FuncSyntaxHighlighter.kt +++ b/modules/func/src/org/ton/intellij/func/highlighting/FuncSyntaxHighlighter.kt @@ -17,7 +17,7 @@ class FuncSyntaxHighlighter : SyntaxHighlighterBase() { FuncElementTypes.RAW_STRING_ELEMENT, FuncElementTypes.CLOSING_QUOTE, FuncElementTypes.OPEN_QUOTE, - -> FuncColor.STRING + -> FuncColor.STRING FuncElementTypes.INTEGER_LITERAL -> FuncColor.NUMBER FuncElementTypes.SEMICOLON -> FuncColor.SEMICOLON diff --git a/src/main/kotlin/org/ton/intellij/func/highlighting/FuncSyntaxHighlighterFactory.kt b/modules/func/src/org/ton/intellij/func/highlighting/FuncSyntaxHighlighterFactory.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/highlighting/FuncSyntaxHighlighterFactory.kt rename to modules/func/src/org/ton/intellij/func/highlighting/FuncSyntaxHighlighterFactory.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/FuncBraceMatcher.kt b/modules/func/src/org/ton/intellij/func/ide/FuncBraceMatcher.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/FuncBraceMatcher.kt rename to modules/func/src/org/ton/intellij/func/ide/FuncBraceMatcher.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/FuncCommenter.kt b/modules/func/src/org/ton/intellij/func/ide/FuncCommenter.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/FuncCommenter.kt rename to modules/func/src/org/ton/intellij/func/ide/FuncCommenter.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/FuncFindUsagesProvider.kt b/modules/func/src/org/ton/intellij/func/ide/FuncFindUsagesProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/FuncFindUsagesProvider.kt rename to modules/func/src/org/ton/intellij/func/ide/FuncFindUsagesProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/FuncFoldingBuilder.kt b/modules/func/src/org/ton/intellij/func/ide/FuncFoldingBuilder.kt similarity index 91% rename from src/main/kotlin/org/ton/intellij/func/ide/FuncFoldingBuilder.kt rename to modules/func/src/org/ton/intellij/func/ide/FuncFoldingBuilder.kt index bebae84..1e53ada 100644 --- a/src/main/kotlin/org/ton/intellij/func/ide/FuncFoldingBuilder.kt +++ b/modules/func/src/org/ton/intellij/func/ide/FuncFoldingBuilder.kt @@ -16,7 +16,7 @@ class FuncFoldingBuilder : FoldingBuilder { private fun collectDescriptorsRecursively(node: ASTNode, descriptors: MutableList) { when (node.elementType) { FuncElementTypes.BLOCK_STATEMENT, - -> descriptors.add(FoldingDescriptor(node, node.textRange)) + -> descriptors.add(FoldingDescriptor(node, node.textRange)) } node.getChildren(null).forEach { childNode -> @@ -26,7 +26,7 @@ class FuncFoldingBuilder : FoldingBuilder { override fun getPlaceholderText(node: ASTNode): String = when (node.elementType) { FuncElementTypes.BLOCK_STATEMENT, - -> "{...}" + -> "{...}" else -> "..." } diff --git a/src/main/kotlin/org/ton/intellij/func/ide/FuncImplementationTextSelectioner.kt b/modules/func/src/org/ton/intellij/func/ide/FuncImplementationTextSelectioner.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/FuncImplementationTextSelectioner.kt rename to modules/func/src/org/ton/intellij/func/ide/FuncImplementationTextSelectioner.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/FuncParameterInfoHandler.kt b/modules/func/src/org/ton/intellij/func/ide/FuncParameterInfoHandler.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/FuncParameterInfoHandler.kt rename to modules/func/src/org/ton/intellij/func/ide/FuncParameterInfoHandler.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/FuncQuoteHandler.kt b/modules/func/src/org/ton/intellij/func/ide/FuncQuoteHandler.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/FuncQuoteHandler.kt rename to modules/func/src/org/ton/intellij/func/ide/FuncQuoteHandler.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/completion/FuncCharFilter.kt b/modules/func/src/org/ton/intellij/func/ide/completion/FuncCharFilter.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/completion/FuncCharFilter.kt rename to modules/func/src/org/ton/intellij/func/ide/completion/FuncCharFilter.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/completion/FuncCommonCompletionProvider.kt b/modules/func/src/org/ton/intellij/func/ide/completion/FuncCommonCompletionProvider.kt similarity index 98% rename from src/main/kotlin/org/ton/intellij/func/ide/completion/FuncCommonCompletionProvider.kt rename to modules/func/src/org/ton/intellij/func/ide/completion/FuncCommonCompletionProvider.kt index c472574..0865482 100644 --- a/src/main/kotlin/org/ton/intellij/func/ide/completion/FuncCommonCompletionProvider.kt +++ b/modules/func/src/org/ton/intellij/func/ide/completion/FuncCommonCompletionProvider.kt @@ -7,7 +7,6 @@ import com.intellij.codeInsight.lookup.LookupElement import com.intellij.codeInsight.lookup.LookupElementBuilder import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.patterns.ElementPattern -import com.intellij.patterns.PlatformPatterns.psiElement import com.intellij.psi.PsiElement import com.intellij.psi.search.PsiElementProcessor import com.intellij.psi.util.PsiTreeUtil @@ -27,7 +26,7 @@ import java.util.* object FuncCommonCompletionProvider : FuncCompletionProvider() { override val elementPattern: ElementPattern = - psiElement().withParent(psiElement()) + psiElement().withParent(psiElement()) override fun addCompletions( parameters: CompletionParameters, diff --git a/src/main/kotlin/org/ton/intellij/func/ide/completion/FuncCompletionConfidence.kt b/modules/func/src/org/ton/intellij/func/ide/completion/FuncCompletionConfidence.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/completion/FuncCompletionConfidence.kt rename to modules/func/src/org/ton/intellij/func/ide/completion/FuncCompletionConfidence.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/completion/FuncCompletionContributor.kt b/modules/func/src/org/ton/intellij/func/ide/completion/FuncCompletionContributor.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/completion/FuncCompletionContributor.kt rename to modules/func/src/org/ton/intellij/func/ide/completion/FuncCompletionContributor.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/completion/FuncCompletionProvider.kt b/modules/func/src/org/ton/intellij/func/ide/completion/FuncCompletionProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/completion/FuncCompletionProvider.kt rename to modules/func/src/org/ton/intellij/func/ide/completion/FuncCompletionProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/completion/FuncKeywordCompletionContributor.kt b/modules/func/src/org/ton/intellij/func/ide/completion/FuncKeywordCompletionContributor.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/completion/FuncKeywordCompletionContributor.kt rename to modules/func/src/org/ton/intellij/func/ide/completion/FuncKeywordCompletionContributor.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/completion/FuncKeywordCompletionProvider.kt b/modules/func/src/org/ton/intellij/func/ide/completion/FuncKeywordCompletionProvider.kt similarity index 98% rename from src/main/kotlin/org/ton/intellij/func/ide/completion/FuncKeywordCompletionProvider.kt rename to modules/func/src/org/ton/intellij/func/ide/completion/FuncKeywordCompletionProvider.kt index 1edc8a9..37ab144 100644 --- a/src/main/kotlin/org/ton/intellij/func/ide/completion/FuncKeywordCompletionProvider.kt +++ b/modules/func/src/org/ton/intellij/func/ide/completion/FuncKeywordCompletionProvider.kt @@ -21,7 +21,7 @@ class FuncKeywordCompletionProvider( context: ProcessingContext, result: CompletionResultSet, ) { - val element = parameters.position + parameters.position keywords.asReversed().forEachIndexed { index, s -> result.addElement(createKeywordLookupElement(s, priority + (index * 0.01))) } diff --git a/src/main/kotlin/org/ton/intellij/func/ide/completion/FuncMacroCompletionProvider.kt b/modules/func/src/org/ton/intellij/func/ide/completion/FuncMacroCompletionProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/completion/FuncMacroCompletionProvider.kt rename to modules/func/src/org/ton/intellij/func/ide/completion/FuncMacroCompletionProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/configurable/FuncProjectConfigurable.kt b/modules/func/src/org/ton/intellij/func/ide/configurable/FuncProjectConfigurable.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/configurable/FuncProjectConfigurable.kt rename to modules/func/src/org/ton/intellij/func/ide/configurable/FuncProjectConfigurable.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/fixes/RemoveElementFix.kt b/modules/func/src/org/ton/intellij/func/ide/fixes/RemoveElementFix.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/fixes/RemoveElementFix.kt rename to modules/func/src/org/ton/intellij/func/ide/fixes/RemoveElementFix.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/fixes/RenameUnserscoreFix.kt b/modules/func/src/org/ton/intellij/func/ide/fixes/RenameUnserscoreFix.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/fixes/RenameUnserscoreFix.kt rename to modules/func/src/org/ton/intellij/func/ide/fixes/RenameUnserscoreFix.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/formatter/FuncFormatter.kt b/modules/func/src/org/ton/intellij/func/ide/formatter/FuncFormatter.kt similarity index 99% rename from src/main/kotlin/org/ton/intellij/func/ide/formatter/FuncFormatter.kt rename to modules/func/src/org/ton/intellij/func/ide/formatter/FuncFormatter.kt index ef280be..8fe53eb 100644 --- a/src/main/kotlin/org/ton/intellij/func/ide/formatter/FuncFormatter.kt +++ b/modules/func/src/org/ton/intellij/func/ide/formatter/FuncFormatter.kt @@ -39,7 +39,6 @@ class FuncFormatter : FormattingModelBuilder { CATCH_KEYWORD, IF_KEYWORD, IFNOT_KEYWORD, - THEN_KEYWORD, ELSE_KEYWORD, ELSEIF_KEYWORD, ELSEIFNOT_KEYWORD, diff --git a/src/main/kotlin/org/ton/intellij/func/ide/formatter/FuncFormattingBlock.kt b/modules/func/src/org/ton/intellij/func/ide/formatter/FuncFormattingBlock.kt similarity index 97% rename from src/main/kotlin/org/ton/intellij/func/ide/formatter/FuncFormattingBlock.kt rename to modules/func/src/org/ton/intellij/func/ide/formatter/FuncFormattingBlock.kt index 3fc08fb..e1ce66e 100644 --- a/src/main/kotlin/org/ton/intellij/func/ide/formatter/FuncFormattingBlock.kt +++ b/modules/func/src/org/ton/intellij/func/ide/formatter/FuncFormattingBlock.kt @@ -96,8 +96,8 @@ class FuncFormattingBlock( } private fun calcWrap(child: ASTNode): Wrap? { - val type = child.elementType - val parentType = child.treeParent.elementType + child.elementType + child.treeParent.elementType // if ((type == DOT || type == TILDE) && parentType == QUALIFIED_EXPRESSION) return Wrap.createWrap( // WrapType.NORMAL, // false diff --git a/src/main/kotlin/org/ton/intellij/func/ide/formatter/FuncLanguageCodeStyleSettingsProvider.kt b/modules/func/src/org/ton/intellij/func/ide/formatter/FuncLanguageCodeStyleSettingsProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/formatter/FuncLanguageCodeStyleSettingsProvider.kt rename to modules/func/src/org/ton/intellij/func/ide/formatter/FuncLanguageCodeStyleSettingsProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/hints/FuncConstantHintsProvider.kt b/modules/func/src/org/ton/intellij/func/ide/hints/FuncConstantHintsProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/hints/FuncConstantHintsProvider.kt rename to modules/func/src/org/ton/intellij/func/ide/hints/FuncConstantHintsProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/hints/FuncParameterHintsProvider.kt b/modules/func/src/org/ton/intellij/func/ide/hints/FuncParameterHintsProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/hints/FuncParameterHintsProvider.kt rename to modules/func/src/org/ton/intellij/func/ide/hints/FuncParameterHintsProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/linemarker/FuncRecursiveCallLineMarkerProvider.kt b/modules/func/src/org/ton/intellij/func/ide/linemarker/FuncRecursiveCallLineMarkerProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/linemarker/FuncRecursiveCallLineMarkerProvider.kt rename to modules/func/src/org/ton/intellij/func/ide/linemarker/FuncRecursiveCallLineMarkerProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/quickdoc/FuncPsiDocumentationTargetProvider.kt b/modules/func/src/org/ton/intellij/func/ide/quickdoc/FuncPsiDocumentationTargetProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/ide/quickdoc/FuncPsiDocumentationTargetProvider.kt rename to modules/func/src/org/ton/intellij/func/ide/quickdoc/FuncPsiDocumentationTargetProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/func/ide/quickdoc/MarkdownNode.kt b/modules/func/src/org/ton/intellij/func/ide/quickdoc/MarkdownNode.kt similarity index 99% rename from src/main/kotlin/org/ton/intellij/func/ide/quickdoc/MarkdownNode.kt rename to modules/func/src/org/ton/intellij/func/ide/quickdoc/MarkdownNode.kt index be1701a..fceed00 100644 --- a/src/main/kotlin/org/ton/intellij/func/ide/quickdoc/MarkdownNode.kt +++ b/modules/func/src/org/ton/intellij/func/ide/quickdoc/MarkdownNode.kt @@ -102,7 +102,7 @@ class MarkdownNode( MarkdownElementTypes.CODE_BLOCK, MarkdownElementTypes.CODE_FENCE, - -> { + -> { sb.trimEnd() var language: Language = FuncLanguage val contents = StringBuilder() @@ -135,7 +135,7 @@ class MarkdownNode( MarkdownElementTypes.SHORT_REFERENCE_LINK, MarkdownElementTypes.FULL_REFERENCE_LINK, - -> { + -> { val linkLabelNode = node.child(MarkdownElementTypes.LINK_LABEL) val linkLabelContent = linkLabelNode?.children ?.dropWhile { it.type == MarkdownTokenTypes.LBRACKET } @@ -187,13 +187,13 @@ class MarkdownNode( MarkdownTokenTypes.EXCLAMATION_MARK, GFMTokenTypes.CHECK_BOX, GFMTokenTypes.GFM_AUTOLINK, - -> { + -> { sb.append(nodeText) } MarkdownTokenTypes.CODE_LINE, MarkdownTokenTypes.CODE_FENCE_CONTENT, - -> { + -> { sb.appendHighlightedByLexerAndEncodedAsHtmlCodeSnippet( when (DocumentationSettings.isHighlightingOfCodeBlocksEnabled()) { true -> DocumentationSettings.InlineCodeHighlightingMode.SEMANTIC_HIGHLIGHTING diff --git a/src/main/kotlin/org/ton/intellij/func/ide/settings/FuncProjectSettingsService.kt b/modules/func/src/org/ton/intellij/func/ide/settings/FuncProjectSettingsService.kt similarity index 90% rename from src/main/kotlin/org/ton/intellij/func/ide/settings/FuncProjectSettingsService.kt rename to modules/func/src/org/ton/intellij/func/ide/settings/FuncProjectSettingsService.kt index 2953908..35f4244 100644 --- a/src/main/kotlin/org/ton/intellij/func/ide/settings/FuncProjectSettingsService.kt +++ b/modules/func/src/org/ton/intellij/func/ide/settings/FuncProjectSettingsService.kt @@ -3,7 +3,6 @@ package org.ton.intellij.func.ide.settings import com.intellij.openapi.components.* import com.intellij.openapi.project.Project import org.ton.intellij.func.FuncLanguageLevel -import org.ton.intellij.tolk.ide.settings.TolkProjectSettingsService val Project.funcSettings: FuncProjectSettingsService get() = getService(FuncProjectSettingsService::class.java) @@ -18,9 +17,7 @@ private const val SERVICE_NAME: String = "FuncProjectSettings" ) class FuncProjectSettingsService( val project: Project -) : SimplePersistentStateComponent(FuncProjectSettings()) { - -} +) : SimplePersistentStateComponent(FuncProjectSettings()) class FuncProjectSettings : BaseState() { var languageLevel by enum(FuncLanguageLevel.FUNC_0_4_0) diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncAbstractApplicabilityBasedInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncAbstractApplicabilityBasedInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncAbstractApplicabilityBasedInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncAbstractApplicabilityBasedInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncFunctionCallInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncFunctionCallInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncFunctionCallInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncFunctionCallInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncImpureFunctionInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncImpureFunctionInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncImpureFunctionInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncImpureFunctionInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncInspectionBase.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncInspectionBase.kt similarity index 98% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncInspectionBase.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncInspectionBase.kt index a38963c..c86b168 100644 --- a/src/main/kotlin/org/ton/intellij/func/inspection/FuncInspectionBase.kt +++ b/modules/func/src/org/ton/intellij/func/inspection/FuncInspectionBase.kt @@ -31,7 +31,7 @@ abstract class FuncInspectionBase : LocalInspectionTool() { } else DUMMY_VISITOR } - open protected fun buildFuncVisitor( + protected open fun buildFuncVisitor( holder: ProblemsHolder, session: LocalInspectionToolSession, ): FuncVisitor = object : FuncVisitor() { diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncMissingReturnInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncMissingReturnInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncMissingReturnInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncMissingReturnInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncReplaceGuardClauseWithFunctionCallInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncReplaceGuardClauseWithFunctionCallInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncReplaceGuardClauseWithFunctionCallInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncReplaceGuardClauseWithFunctionCallInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncUnexpectedGetMethodCallInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncUnexpectedGetMethodCallInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncUnexpectedGetMethodCallInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncUnexpectedGetMethodCallInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncUnresolvedReferenceInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncUnresolvedReferenceInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncUnresolvedReferenceInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncUnresolvedReferenceInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncUnresolvedTypeIdentifierInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncUnresolvedTypeIdentifierInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncUnresolvedTypeIdentifierInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncUnresolvedTypeIdentifierInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncUnusedFunctionInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncUnusedFunctionInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncUnusedFunctionInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncUnusedFunctionInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncUnusedFunctionParameterInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncUnusedFunctionParameterInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncUnusedFunctionParameterInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncUnusedFunctionParameterInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncUnusedTypeParameterInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncUnusedTypeParameterInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncUnusedTypeParameterInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncUnusedTypeParameterInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/FuncUnusedVariableInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/FuncUnusedVariableInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/FuncUnusedVariableInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/FuncUnusedVariableInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/numeric/FuncDivideByZeroInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/numeric/FuncDivideByZeroInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/numeric/FuncDivideByZeroInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/numeric/FuncDivideByZeroInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/numeric/FuncIntOverflowInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/numeric/FuncIntOverflowInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/numeric/FuncIntOverflowInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/numeric/FuncIntOverflowInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/inspection/style/FuncConstantExpressionInspection.kt b/modules/func/src/org/ton/intellij/func/inspection/style/FuncConstantExpressionInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/inspection/style/FuncConstantExpressionInspection.kt rename to modules/func/src/org/ton/intellij/func/inspection/style/FuncConstantExpressionInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/func/intentions/FuncConstantExpressionIntention.kt b/modules/func/src/org/ton/intellij/func/intentions/FuncConstantExpressionIntention.kt similarity index 95% rename from src/main/kotlin/org/ton/intellij/func/intentions/FuncConstantExpressionIntention.kt rename to modules/func/src/org/ton/intellij/func/intentions/FuncConstantExpressionIntention.kt index 1b335db..448043b 100644 --- a/src/main/kotlin/org/ton/intellij/func/intentions/FuncConstantExpressionIntention.kt +++ b/modules/func/src/org/ton/intellij/func/intentions/FuncConstantExpressionIntention.kt @@ -20,8 +20,7 @@ class FuncConstantExpressionIntention : PsiElementBaseIntentionAction() { if (element !is FuncExpression) return false if (element is FuncLiteralExpression && element.integerLiteral != null) return false val parent = element.parent - if (parent is FuncExpression) return false - return true + return parent !is FuncExpression } override fun invoke(project: Project, editor: Editor?, element: PsiElement) { diff --git a/src/main/grammar/FuncLexer.flex b/modules/func/src/org/ton/intellij/func/lexer/FuncLexer.flex similarity index 100% rename from src/main/grammar/FuncLexer.flex rename to modules/func/src/org/ton/intellij/func/lexer/FuncLexer.flex diff --git a/src/main/kotlin/org/ton/intellij/func/lexer/FuncLexer.kt b/modules/func/src/org/ton/intellij/func/lexer/FuncLexer.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/lexer/FuncLexer.kt rename to modules/func/src/org/ton/intellij/func/lexer/FuncLexer.kt diff --git a/src/main/grammar/FuncParser.bnf b/modules/func/src/org/ton/intellij/func/parser/FuncParser.bnf similarity index 99% rename from src/main/grammar/FuncParser.bnf rename to modules/func/src/org/ton/intellij/func/parser/FuncParser.bnf index f9b477f..c746938 100644 --- a/src/main/grammar/FuncParser.bnf +++ b/modules/func/src/org/ton/intellij/func/parser/FuncParser.bnf @@ -490,6 +490,7 @@ HoleType ::= 'var' | '_' PrimitiveType ::= 'int' | 'cell' | 'slice' | 'builder' | 'cont' | 'tuple' | 'type' TypeIdentifier ::= IDENTIFIER { mixin="org.ton.intellij.func.psi.impl.FuncTypeIdentifierMixin" + extends=TypeReference } UnitType ::= '(' ')' diff --git a/src/main/kotlin/org/ton/intellij/func/parser/FuncParserDefinition.kt b/modules/func/src/org/ton/intellij/func/parser/FuncParserDefinition.kt similarity index 99% rename from src/main/kotlin/org/ton/intellij/func/parser/FuncParserDefinition.kt rename to modules/func/src/org/ton/intellij/func/parser/FuncParserDefinition.kt index 5de19ac..9697494 100644 --- a/src/main/kotlin/org/ton/intellij/func/parser/FuncParserDefinition.kt +++ b/modules/func/src/org/ton/intellij/func/parser/FuncParserDefinition.kt @@ -38,10 +38,13 @@ class FuncParserDefinition : ParserDefinition { companion object { @JvmField val BLOCK_COMMENT = FuncTokenType("") + @JvmField val EOL_COMMENT = FuncTokenType("") + @JvmField val BLOCK_DOC_COMMENT = FuncTokenType("") + @JvmField val EOL_DOC_COMMENT = FuncDocCommentElementType("") diff --git a/src/main/kotlin/org/ton/intellij/func/parser/FuncParserUtil.kt b/modules/func/src/org/ton/intellij/func/parser/FuncParserUtil.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/parser/FuncParserUtil.kt rename to modules/func/src/org/ton/intellij/func/parser/FuncParserUtil.kt diff --git a/modules/func/src/org/ton/intellij/func/psi/FuncDocOwner.kt b/modules/func/src/org/ton/intellij/func/psi/FuncDocOwner.kt new file mode 100644 index 0000000..093de46 --- /dev/null +++ b/modules/func/src/org/ton/intellij/func/psi/FuncDocOwner.kt @@ -0,0 +1,3 @@ +package org.ton.intellij.func.psi + +interface FuncDocOwner : FuncElement diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncElement.kt b/modules/func/src/org/ton/intellij/func/psi/FuncElement.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncElement.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncElement.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncElementType.kt b/modules/func/src/org/ton/intellij/func/psi/FuncElementType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncElementType.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncElementType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncElementTypeFactory.kt b/modules/func/src/org/ton/intellij/func/psi/FuncElementTypeFactory.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncElementTypeFactory.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncElementTypeFactory.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncFile.kt b/modules/func/src/org/ton/intellij/func/psi/FuncFile.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncFile.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncFile.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncInferenceContextOwner.kt b/modules/func/src/org/ton/intellij/func/psi/FuncInferenceContextOwner.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncInferenceContextOwner.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncInferenceContextOwner.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncNamedElement.kt b/modules/func/src/org/ton/intellij/func/psi/FuncNamedElement.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncNamedElement.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncNamedElement.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncPsiFactory.kt b/modules/func/src/org/ton/intellij/func/psi/FuncPsiFactory.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncPsiFactory.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncPsiFactory.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncPsiManager.kt b/modules/func/src/org/ton/intellij/func/psi/FuncPsiManager.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncPsiManager.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncPsiManager.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncPsiPattern.kt b/modules/func/src/org/ton/intellij/func/psi/FuncPsiPattern.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncPsiPattern.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncPsiPattern.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncPsiUtil.kt b/modules/func/src/org/ton/intellij/func/psi/FuncPsiUtil.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncPsiUtil.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncPsiUtil.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncRecursiveElementWalkingVisitor.kt b/modules/func/src/org/ton/intellij/func/psi/FuncRecursiveElementWalkingVisitor.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncRecursiveElementWalkingVisitor.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncRecursiveElementWalkingVisitor.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncStringAsmInjector.kt b/modules/func/src/org/ton/intellij/func/psi/FuncStringAsmInjector.kt similarity index 93% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncStringAsmInjector.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncStringAsmInjector.kt index 76a7cc1..ec9c0ec 100644 --- a/src/main/kotlin/org/ton/intellij/func/psi/FuncStringAsmInjector.kt +++ b/modules/func/src/org/ton/intellij/func/psi/FuncStringAsmInjector.kt @@ -11,7 +11,7 @@ class FuncStringAsmInjector : LanguageInjector { places: InjectedLanguagePlaces ) { if (host !is FuncStringLiteral) return - if (!host.isValidHost()) return + if (!host.isValidHost) return val text = host.rawString ?: return places.addPlace(AsmLanguage, text.textRangeInParent, null, null) } diff --git a/src/main/kotlin/org/ton/intellij/func/psi/FuncTokenType.kt b/modules/func/src/org/ton/intellij/func/psi/FuncTokenType.kt similarity index 98% rename from src/main/kotlin/org/ton/intellij/func/psi/FuncTokenType.kt rename to modules/func/src/org/ton/intellij/func/psi/FuncTokenType.kt index 87e135a..69226e3 100644 --- a/src/main/kotlin/org/ton/intellij/func/psi/FuncTokenType.kt +++ b/modules/func/src/org/ton/intellij/func/psi/FuncTokenType.kt @@ -26,7 +26,6 @@ val FUNC_KEYWORDS = tokenSetOf( FuncElementTypes.CATCH_KEYWORD, FuncElementTypes.IF_KEYWORD, FuncElementTypes.IFNOT_KEYWORD, - FuncElementTypes.THEN_KEYWORD, FuncElementTypes.ELSE_KEYWORD, FuncElementTypes.ELSEIF_KEYWORD, FuncElementTypes.ELSEIFNOT_KEYWORD, diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncAsmArgumentMixin.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncAsmArgumentMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncAsmArgumentMixin.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncAsmArgumentMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncBlockImpl.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncBlockImpl.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncBlockImpl.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncBlockImpl.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncCachedReference.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncCachedReference.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncCachedReference.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncCachedReference.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncCallArgument.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncCallArgument.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncCallArgument.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncCallArgument.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncConstVarMixin.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncConstVarMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncConstVarMixin.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncConstVarMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncFunctionImpl.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncFunctionImpl.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncFunctionImpl.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncFunctionImpl.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncFunctionParameterMixin.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncFunctionParameterMixin.kt similarity index 83% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncFunctionParameterMixin.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncFunctionParameterMixin.kt index b204e33..27a8597 100644 --- a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncFunctionParameterMixin.kt +++ b/modules/func/src/org/ton/intellij/func/psi/impl/FuncFunctionParameterMixin.kt @@ -2,9 +2,9 @@ package org.ton.intellij.func.psi.impl import com.intellij.lang.ASTNode import com.intellij.psi.stubs.IStubElementType +import org.ton.intellij.func.FuncIcons import org.ton.intellij.func.psi.FuncFunctionParameter import org.ton.intellij.func.stub.FuncFunctionParameterStub -import org.ton.intellij.tact.TactIcons import javax.swing.Icon abstract class FuncFunctionParameterMixin : FuncNamedElementImpl, FuncFunctionParameter { @@ -12,5 +12,5 @@ abstract class FuncFunctionParameterMixin : FuncNamedElementImpl) : super(stub, stubType) - override fun getIcon(flags: Int): Icon = TactIcons.PARAMETER + override fun getIcon(flags: Int): Icon = FuncIcons.PARAMETER } diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncGlobalVarMixin.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncGlobalVarMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncGlobalVarMixin.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncGlobalVarMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncIncludeDefinitionImpl.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncIncludeDefinitionImpl.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncIncludeDefinitionImpl.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncIncludeDefinitionImpl.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncIncludePathElementManipulator.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncIncludePathElementManipulator.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncIncludePathElementManipulator.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncIncludePathElementManipulator.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncIncludePathReference.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncIncludePathReference.kt similarity index 98% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncIncludePathReference.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncIncludePathReference.kt index 01cb010..f57e582 100644 --- a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncIncludePathReference.kt +++ b/modules/func/src/org/ton/intellij/func/psi/impl/FuncIncludePathReference.kt @@ -11,5 +11,4 @@ class FuncIncludePathReference( element.textOffset, null, true -) { -} +) diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncNamedElementImpl.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncNamedElementImpl.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncNamedElementImpl.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncNamedElementImpl.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncReference.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncReference.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncReference.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncReference.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncReferenceExpressionMixin.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncReferenceExpressionMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncReferenceExpressionMixin.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncReferenceExpressionMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncStringLiteralMixin.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncStringLiteralMixin.kt similarity index 94% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncStringLiteralMixin.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncStringLiteralMixin.kt index f9736bc..c181fcf 100644 --- a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncStringLiteralMixin.kt +++ b/modules/func/src/org/ton/intellij/func/psi/impl/FuncStringLiteralMixin.kt @@ -5,10 +5,8 @@ import com.intellij.lang.ASTNode import com.intellij.openapi.util.TextRange import com.intellij.psi.LiteralTextEscaper import com.intellij.psi.PsiLanguageInjectionHost -import com.intellij.psi.util.elementType import org.ton.intellij.func.psi.FuncAsmBody import org.ton.intellij.func.psi.FuncStringLiteral -import java.lang.StringBuilder abstract class FuncStringLiteralMixin(node: ASTNode) : ASTWrapperPsiElement(node), FuncStringLiteral { override fun isValidHost(): Boolean { diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncStubbedElementImpl.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncStubbedElementImpl.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncStubbedElementImpl.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncStubbedElementImpl.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncTypeIdentifierMixin.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncTypeIdentifierMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncTypeIdentifierMixin.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncTypeIdentifierMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/func/psi/impl/FuncTypeParameterMixin.kt b/modules/func/src/org/ton/intellij/func/psi/impl/FuncTypeParameterMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/psi/impl/FuncTypeParameterMixin.kt rename to modules/func/src/org/ton/intellij/func/psi/impl/FuncTypeParameterMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/func/refactor/FuncNamesValidator.kt b/modules/func/src/org/ton/intellij/func/refactor/FuncNamesValidator.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/refactor/FuncNamesValidator.kt rename to modules/func/src/org/ton/intellij/func/refactor/FuncNamesValidator.kt diff --git a/src/main/kotlin/org/ton/intellij/func/refactor/FuncRefactoringSupportProvider.kt b/modules/func/src/org/ton/intellij/func/refactor/FuncRefactoringSupportProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/refactor/FuncRefactoringSupportProvider.kt rename to modules/func/src/org/ton/intellij/func/refactor/FuncRefactoringSupportProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/func/resolve/FuncLookup.kt b/modules/func/src/org/ton/intellij/func/resolve/FuncLookup.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/resolve/FuncLookup.kt rename to modules/func/src/org/ton/intellij/func/resolve/FuncLookup.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/FuncConstVarStub.kt b/modules/func/src/org/ton/intellij/func/stub/FuncConstVarStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/FuncConstVarStub.kt rename to modules/func/src/org/ton/intellij/func/stub/FuncConstVarStub.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/FuncFileStub.kt b/modules/func/src/org/ton/intellij/func/stub/FuncFileStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/FuncFileStub.kt rename to modules/func/src/org/ton/intellij/func/stub/FuncFileStub.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/FuncFunctionParameterStub.kt b/modules/func/src/org/ton/intellij/func/stub/FuncFunctionParameterStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/FuncFunctionParameterStub.kt rename to modules/func/src/org/ton/intellij/func/stub/FuncFunctionParameterStub.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/FuncFunctionStub.kt b/modules/func/src/org/ton/intellij/func/stub/FuncFunctionStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/FuncFunctionStub.kt rename to modules/func/src/org/ton/intellij/func/stub/FuncFunctionStub.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/FuncGlobalVarStub.kt b/modules/func/src/org/ton/intellij/func/stub/FuncGlobalVarStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/FuncGlobalVarStub.kt rename to modules/func/src/org/ton/intellij/func/stub/FuncGlobalVarStub.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/FuncIncludeDefinitionStub.kt b/modules/func/src/org/ton/intellij/func/stub/FuncIncludeDefinitionStub.kt similarity index 80% rename from src/main/kotlin/org/ton/intellij/func/stub/FuncIncludeDefinitionStub.kt rename to modules/func/src/org/ton/intellij/func/stub/FuncIncludeDefinitionStub.kt index 2473246..2cfa5ae 100644 --- a/src/main/kotlin/org/ton/intellij/func/stub/FuncIncludeDefinitionStub.kt +++ b/modules/func/src/org/ton/intellij/func/stub/FuncIncludeDefinitionStub.kt @@ -8,12 +8,16 @@ import org.ton.intellij.func.psi.FuncIncludeDefinition class FuncIncludeDefinitionStub( parent: StubElement<*>, - elementType: IStubElementType<*,*>, + elementType: IStubElementType<*, *>, path: StringRef ) : StubBase( parent, elementType ) { - constructor(parent: StubElement<*>, elementType: IStubElementType<*, *>, path: String) : this(parent, elementType, StringRef.fromString(path)) + constructor(parent: StubElement<*>, elementType: IStubElementType<*, *>, path: String) : this( + parent, + elementType, + StringRef.fromString(path) + ) private val _path: StringRef = path diff --git a/src/main/kotlin/org/ton/intellij/func/stub/FuncNamedStub.kt b/modules/func/src/org/ton/intellij/func/stub/FuncNamedStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/FuncNamedStub.kt rename to modules/func/src/org/ton/intellij/func/stub/FuncNamedStub.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/FuncTypeParameterStub.kt b/modules/func/src/org/ton/intellij/func/stub/FuncTypeParameterStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/FuncTypeParameterStub.kt rename to modules/func/src/org/ton/intellij/func/stub/FuncTypeParameterStub.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/index/FuncNamedElementIndex.kt b/modules/func/src/org/ton/intellij/func/stub/index/FuncNamedElementIndex.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/index/FuncNamedElementIndex.kt rename to modules/func/src/org/ton/intellij/func/stub/index/FuncNamedElementIndex.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/type/FuncConstVarStubElementType.kt b/modules/func/src/org/ton/intellij/func/stub/type/FuncConstVarStubElementType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/type/FuncConstVarStubElementType.kt rename to modules/func/src/org/ton/intellij/func/stub/type/FuncConstVarStubElementType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/type/FuncFunctionParameterStubElementType.kt b/modules/func/src/org/ton/intellij/func/stub/type/FuncFunctionParameterStubElementType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/type/FuncFunctionParameterStubElementType.kt rename to modules/func/src/org/ton/intellij/func/stub/type/FuncFunctionParameterStubElementType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/type/FuncFunctionStubElementType.kt b/modules/func/src/org/ton/intellij/func/stub/type/FuncFunctionStubElementType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/type/FuncFunctionStubElementType.kt rename to modules/func/src/org/ton/intellij/func/stub/type/FuncFunctionStubElementType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/type/FuncGlobalVarStubElementType.kt b/modules/func/src/org/ton/intellij/func/stub/type/FuncGlobalVarStubElementType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/type/FuncGlobalVarStubElementType.kt rename to modules/func/src/org/ton/intellij/func/stub/type/FuncGlobalVarStubElementType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/type/FuncIncludeDefinitionStubElementType.kt b/modules/func/src/org/ton/intellij/func/stub/type/FuncIncludeDefinitionStubElementType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/type/FuncIncludeDefinitionStubElementType.kt rename to modules/func/src/org/ton/intellij/func/stub/type/FuncIncludeDefinitionStubElementType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/type/FuncNamedStubElementType.kt b/modules/func/src/org/ton/intellij/func/stub/type/FuncNamedStubElementType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/type/FuncNamedStubElementType.kt rename to modules/func/src/org/ton/intellij/func/stub/type/FuncNamedStubElementType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/type/FuncStubElementType.kt b/modules/func/src/org/ton/intellij/func/stub/type/FuncStubElementType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/type/FuncStubElementType.kt rename to modules/func/src/org/ton/intellij/func/stub/type/FuncStubElementType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/stub/type/FuncTypeParameterStubElementType.kt b/modules/func/src/org/ton/intellij/func/stub/type/FuncTypeParameterStubElementType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/stub/type/FuncTypeParameterStubElementType.kt rename to modules/func/src/org/ton/intellij/func/stub/type/FuncTypeParameterStubElementType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/template/FuncEverywhereContextType.kt b/modules/func/src/org/ton/intellij/func/template/FuncEverywhereContextType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/template/FuncEverywhereContextType.kt rename to modules/func/src/org/ton/intellij/func/template/FuncEverywhereContextType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/template/FuncTemplateContextType.kt b/modules/func/src/org/ton/intellij/func/template/FuncTemplateContextType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/template/FuncTemplateContextType.kt rename to modules/func/src/org/ton/intellij/func/template/FuncTemplateContextType.kt diff --git a/src/main/kotlin/org/ton/intellij/func/type/infer/Expectation.kt b/modules/func/src/org/ton/intellij/func/type/infer/Expectation.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/type/infer/Expectation.kt rename to modules/func/src/org/ton/intellij/func/type/infer/Expectation.kt diff --git a/src/main/kotlin/org/ton/intellij/func/type/infer/Fold.kt b/modules/func/src/org/ton/intellij/func/type/infer/Fold.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/type/infer/Fold.kt rename to modules/func/src/org/ton/intellij/func/type/infer/Fold.kt diff --git a/src/main/kotlin/org/ton/intellij/func/type/infer/TypeInference.kt b/modules/func/src/org/ton/intellij/func/type/infer/TypeInference.kt similarity index 99% rename from src/main/kotlin/org/ton/intellij/func/type/infer/TypeInference.kt rename to modules/func/src/org/ton/intellij/func/type/infer/TypeInference.kt index 2d3b4af..b496758 100644 --- a/src/main/kotlin/org/ton/intellij/func/type/infer/TypeInference.kt +++ b/modules/func/src/org/ton/intellij/func/type/infer/TypeInference.kt @@ -40,8 +40,7 @@ data class FuncInferenceResult( return resolvedRefs[element] ?: EMPTY_RESOLVED_SET } - companion object { - } + companion object } class FuncInferenceContext( diff --git a/src/main/kotlin/org/ton/intellij/func/type/infer/TypeInferenceWalker.kt b/modules/func/src/org/ton/intellij/func/type/infer/TypeInferenceWalker.kt similarity index 97% rename from src/main/kotlin/org/ton/intellij/func/type/infer/TypeInferenceWalker.kt rename to modules/func/src/org/ton/intellij/func/type/infer/TypeInferenceWalker.kt index ede5f75..0a6bcc8 100644 --- a/src/main/kotlin/org/ton/intellij/func/type/infer/TypeInferenceWalker.kt +++ b/modules/func/src/org/ton/intellij/func/type/infer/TypeInferenceWalker.kt @@ -200,8 +200,8 @@ class FuncTypeInferenceWalker( if (lhs.isTypeExpression()) { variableDeclarationState = true } - val lhsTy = lhs?.inferType() - val rhsTy = rhs?.inferType() + lhs?.inferType() + rhs?.inferType() variableDeclarationState = false return FuncTyUnit @@ -213,8 +213,8 @@ class FuncTypeInferenceWalker( val expressions = expressionList val lhs = expressions.getOrNull(0) val rhs = expressions.getOrNull(1) - val lhsTy = lhs?.inferType() - val rhsTy = rhs?.inferType() + lhs?.inferType() + rhs?.inferType() return FuncTyUnit } @@ -242,7 +242,7 @@ class FuncTypeInferenceWalker( private fun FuncTernaryExpression.inferType( expected: Expectation ): FuncTy { - val conditionTy = condition.inferType(FuncTyInt) + condition.inferType(FuncTyInt) val thenTy = thenBranch?.inferType(expected) val elseTy = elseBranch?.inferType(expected) return thenTy ?: elseTy ?: FuncTyUnknown diff --git a/src/main/kotlin/org/ton/intellij/func/type/ty/Ty.kt b/modules/func/src/org/ton/intellij/func/type/ty/Ty.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/func/type/ty/Ty.kt rename to modules/func/src/org/ton/intellij/func/type/ty/Ty.kt diff --git a/modules/tact/build.gradle.kts b/modules/tact/build.gradle.kts new file mode 100644 index 0000000..6e5c50f --- /dev/null +++ b/modules/tact/build.gradle.kts @@ -0,0 +1,42 @@ +import org.jetbrains.grammarkit.tasks.GenerateLexerTask +import org.jetbrains.grammarkit.tasks.GenerateParserTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.jetbrains.intellij.platform.module") + id("org.jetbrains.grammarkit") +} + +dependencies { + intellijPlatform { + val version = providers.gradleProperty("platformVersion") + intellijIdeaCommunity(version) + } + compileOnly(project(":util")) +} + +val generateTactParser = task("generateTactParser") { + sourceFile.set(file("src/org/ton/intellij/tact/parser/TactParser.bnf")) + targetRootOutputDir.set(file("gen")) + pathToParser.set("/org/ton/intellij/tact/parser/TactParser.java") + pathToPsiRoot.set("/org/ton/intellij/tact/psi") + purgeOldFiles.set(true) + + dependsOn(":util:composedJar") +} + +val generateTactLexer = task("generateTactLexer") { + val input = "src/org/ton/intellij/tact/lexer/TactLexer.flex" + val output = "gen/org/ton/intellij/tact/lexer" + sourceFile.set(file(input)) + targetOutputDir.set(file(output)) + purgeOldFiles.set(true) +} + +tasks.withType().configureEach { + dependsOn(generateTactParser, generateTactLexer) +} + +tasks.withType().configureEach { + dependsOn(generateTactParser, generateTactLexer) +} diff --git a/src/main/resources/META-INF/tact.xml b/modules/tact/resources/META-INF/tact.xml similarity index 98% rename from src/main/resources/META-INF/tact.xml rename to modules/tact/resources/META-INF/tact.xml index 6181350..753cfdd 100644 --- a/src/main/resources/META-INF/tact.xml +++ b/modules/tact/resources/META-INF/tact.xml @@ -74,7 +74,7 @@ - + diff --git a/src/main/resources/fileTemplates/internal/Tact File.tact.ft b/modules/tact/resources/fileTemplates/internal/Tact File.tact.ft similarity index 100% rename from src/main/resources/fileTemplates/internal/Tact File.tact.ft rename to modules/tact/resources/fileTemplates/internal/Tact File.tact.ft diff --git a/src/main/resources/icons/tact.svg b/modules/tact/resources/icons/tact.svg similarity index 100% rename from src/main/resources/icons/tact.svg rename to modules/tact/resources/icons/tact.svg diff --git a/src/main/resources/icons/tact_dark.svg b/modules/tact/resources/icons/tact_dark.svg similarity index 100% rename from src/main/resources/icons/tact_dark.svg rename to modules/tact/resources/icons/tact_dark.svg diff --git a/src/main/resources/inspectionDescriptions/TactDivideByZero.html b/modules/tact/resources/inspectionDescriptions/TactDivideByZero.html similarity index 100% rename from src/main/resources/inspectionDescriptions/TactDivideByZero.html rename to modules/tact/resources/inspectionDescriptions/TactDivideByZero.html diff --git a/src/main/resources/inspectionDescriptions/TactUnresolvedReference.html b/modules/tact/resources/inspectionDescriptions/TactUnresolvedReference.html similarity index 100% rename from src/main/resources/inspectionDescriptions/TactUnresolvedReference.html rename to modules/tact/resources/inspectionDescriptions/TactUnresolvedReference.html diff --git a/src/main/resources/messages/TactBundle.properties b/modules/tact/resources/messages/TactBundle.properties similarity index 100% rename from src/main/resources/messages/TactBundle.properties rename to modules/tact/resources/messages/TactBundle.properties diff --git a/src/main/kotlin/org/ton/intellij/tact/TactBraceMatcher.kt b/modules/tact/src/org/ton/intellij/tact/TactBraceMatcher.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/TactBraceMatcher.kt rename to modules/tact/src/org/ton/intellij/tact/TactBraceMatcher.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/TactBundle.kt b/modules/tact/src/org/ton/intellij/tact/TactBundle.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/TactBundle.kt rename to modules/tact/src/org/ton/intellij/tact/TactBundle.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/TactCommenter.kt b/modules/tact/src/org/ton/intellij/tact/TactCommenter.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/TactCommenter.kt rename to modules/tact/src/org/ton/intellij/tact/TactCommenter.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/TactFileType.kt b/modules/tact/src/org/ton/intellij/tact/TactFileType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/TactFileType.kt rename to modules/tact/src/org/ton/intellij/tact/TactFileType.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/TactFoldingBuilder.kt b/modules/tact/src/org/ton/intellij/tact/TactFoldingBuilder.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/TactFoldingBuilder.kt rename to modules/tact/src/org/ton/intellij/tact/TactFoldingBuilder.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/TactIcons.kt b/modules/tact/src/org/ton/intellij/tact/TactIcons.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/TactIcons.kt rename to modules/tact/src/org/ton/intellij/tact/TactIcons.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/TactLanguage.kt b/modules/tact/src/org/ton/intellij/tact/TactLanguage.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/TactLanguage.kt rename to modules/tact/src/org/ton/intellij/tact/TactLanguage.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/TactQuoteHandler.kt b/modules/tact/src/org/ton/intellij/tact/TactQuoteHandler.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/TactQuoteHandler.kt rename to modules/tact/src/org/ton/intellij/tact/TactQuoteHandler.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/action/file/TactCreateFileAction.kt b/modules/tact/src/org/ton/intellij/tact/action/file/TactCreateFileAction.kt similarity index 95% rename from src/main/kotlin/org/ton/intellij/tact/action/file/TactCreateFileAction.kt rename to modules/tact/src/org/ton/intellij/tact/action/file/TactCreateFileAction.kt index aa284be..7564a21 100644 --- a/src/main/kotlin/org/ton/intellij/tact/action/file/TactCreateFileAction.kt +++ b/modules/tact/src/org/ton/intellij/tact/action/file/TactCreateFileAction.kt @@ -4,7 +4,6 @@ import com.intellij.ide.actions.CreateFileFromTemplateAction import com.intellij.ide.actions.CreateFileFromTemplateDialog import com.intellij.openapi.project.Project import com.intellij.psi.PsiDirectory -import org.ton.intellij.func.FuncIcons import org.ton.intellij.tact.TactIcons class TactCreateFileAction : CreateFileFromTemplateAction( diff --git a/src/main/kotlin/org/ton/intellij/tact/annotator/TactHighlightingAnnotator.kt b/modules/tact/src/org/ton/intellij/tact/annotator/TactHighlightingAnnotator.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/annotator/TactHighlightingAnnotator.kt rename to modules/tact/src/org/ton/intellij/tact/annotator/TactHighlightingAnnotator.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/diagnostics/TactDiagnostic.kt b/modules/tact/src/org/ton/intellij/tact/diagnostics/TactDiagnostic.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/diagnostics/TactDiagnostic.kt rename to modules/tact/src/org/ton/intellij/tact/diagnostics/TactDiagnostic.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/eval/TactConstantExpressionEvaluator.kt b/modules/tact/src/org/ton/intellij/tact/eval/TactConstantExpressionEvaluator.kt similarity index 99% rename from src/main/kotlin/org/ton/intellij/tact/eval/TactConstantExpressionEvaluator.kt rename to modules/tact/src/org/ton/intellij/tact/eval/TactConstantExpressionEvaluator.kt index aa8658a..e56428a 100644 --- a/src/main/kotlin/org/ton/intellij/tact/eval/TactConstantExpressionEvaluator.kt +++ b/modules/tact/src/org/ton/intellij/tact/eval/TactConstantExpressionEvaluator.kt @@ -2,7 +2,7 @@ package org.ton.intellij.tact.eval import com.intellij.openapi.project.Project import org.ton.intellij.tact.psi.* -import org.ton.intellij.tvm.math.divModFloor +import org.ton.intellij.util.divModFloor import org.ton.intellij.util.recursionGuard import java.math.BigInteger diff --git a/src/main/kotlin/org/ton/intellij/tact/eval/TactValue.kt b/modules/tact/src/org/ton/intellij/tact/eval/TactValue.kt similarity index 93% rename from src/main/kotlin/org/ton/intellij/tact/eval/TactValue.kt rename to modules/tact/src/org/ton/intellij/tact/eval/TactValue.kt index 27da581..9252089 100644 --- a/src/main/kotlin/org/ton/intellij/tact/eval/TactValue.kt +++ b/modules/tact/src/org/ton/intellij/tact/eval/TactValue.kt @@ -2,8 +2,7 @@ package org.ton.intellij.tact.eval import java.math.BigInteger -sealed interface TactValue { -} +sealed interface TactValue data class TactIntValue( val value: BigInteger diff --git a/src/main/kotlin/org/ton/intellij/tact/formatter/TactFormatterBlock.kt b/modules/tact/src/org/ton/intellij/tact/formatter/TactFormatterBlock.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/formatter/TactFormatterBlock.kt rename to modules/tact/src/org/ton/intellij/tact/formatter/TactFormatterBlock.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/formatter/TactFormattingModelBuilder.kt b/modules/tact/src/org/ton/intellij/tact/formatter/TactFormattingModelBuilder.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/formatter/TactFormattingModelBuilder.kt rename to modules/tact/src/org/ton/intellij/tact/formatter/TactFormattingModelBuilder.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/highlighting/TactColor.kt b/modules/tact/src/org/ton/intellij/tact/highlighting/TactColor.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/highlighting/TactColor.kt rename to modules/tact/src/org/ton/intellij/tact/highlighting/TactColor.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/highlighting/TactHighlightingLexer.kt b/modules/tact/src/org/ton/intellij/tact/highlighting/TactHighlightingLexer.kt similarity index 90% rename from src/main/kotlin/org/ton/intellij/tact/highlighting/TactHighlightingLexer.kt rename to modules/tact/src/org/ton/intellij/tact/highlighting/TactHighlightingLexer.kt index 3c12c42..28eeb17 100644 --- a/src/main/kotlin/org/ton/intellij/tact/highlighting/TactHighlightingLexer.kt +++ b/modules/tact/src/org/ton/intellij/tact/highlighting/TactHighlightingLexer.kt @@ -2,6 +2,7 @@ package org.ton.intellij.tact.highlighting import com.intellij.lexer.LayeredLexer import com.intellij.lexer.StringLiteralLexer +import org.ton.intellij.tact.lexer.TactLexer import org.ton.intellij.tact.psi.TactElementTypes class TactHighlightingLexer : LayeredLexer(TactLexer()) { diff --git a/src/main/kotlin/org/ton/intellij/tact/highlighting/TactSyntaxHighlighter.kt b/modules/tact/src/org/ton/intellij/tact/highlighting/TactSyntaxHighlighter.kt similarity index 97% rename from src/main/kotlin/org/ton/intellij/tact/highlighting/TactSyntaxHighlighter.kt rename to modules/tact/src/org/ton/intellij/tact/highlighting/TactSyntaxHighlighter.kt index 598ee30..91755af 100644 --- a/src/main/kotlin/org/ton/intellij/tact/highlighting/TactSyntaxHighlighter.kt +++ b/modules/tact/src/org/ton/intellij/tact/highlighting/TactSyntaxHighlighter.kt @@ -4,6 +4,7 @@ import com.intellij.lexer.Lexer import com.intellij.openapi.editor.colors.TextAttributesKey import com.intellij.openapi.fileTypes.SyntaxHighlighterBase import com.intellij.psi.tree.IElementType +import org.ton.intellij.tact.lexer.TactLexer import org.ton.intellij.tact.psi.TACT_KEYWORDS import org.ton.intellij.tact.psi.TACT_MACROS import org.ton.intellij.tact.psi.TACT_STRING_LITERALS diff --git a/src/main/kotlin/org/ton/intellij/tact/highlighting/TactSyntaxHighlighterFactory.kt b/modules/tact/src/org/ton/intellij/tact/highlighting/TactSyntaxHighlighterFactory.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/highlighting/TactSyntaxHighlighterFactory.kt rename to modules/tact/src/org/ton/intellij/tact/highlighting/TactSyntaxHighlighterFactory.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/ide/TactFindUsagesProvider.kt b/modules/tact/src/org/ton/intellij/tact/ide/TactFindUsagesProvider.kt similarity index 93% rename from src/main/kotlin/org/ton/intellij/tact/ide/TactFindUsagesProvider.kt rename to modules/tact/src/org/ton/intellij/tact/ide/TactFindUsagesProvider.kt index 483a354..e96f287 100644 --- a/src/main/kotlin/org/ton/intellij/tact/ide/TactFindUsagesProvider.kt +++ b/modules/tact/src/org/ton/intellij/tact/ide/TactFindUsagesProvider.kt @@ -2,13 +2,12 @@ package org.ton.intellij.tact.ide import com.intellij.lang.HelpID import com.intellij.lang.cacheBuilder.DefaultWordsScanner -import com.intellij.lang.cacheBuilder.WordsScanner import com.intellij.lang.findUsages.FindUsagesProvider import com.intellij.psi.ElementDescriptionUtil import com.intellij.psi.PsiElement import com.intellij.usageView.UsageViewLongNameLocation import com.intellij.usageView.UsageViewShortNameLocation -import org.ton.intellij.tact.parser.TactLexer +import org.ton.intellij.tact.lexer.TactLexer import org.ton.intellij.tact.psi.TACT_COMMENTS import org.ton.intellij.tact.psi.TactElementTypes import org.ton.intellij.util.tokenSetOf diff --git a/src/main/kotlin/org/ton/intellij/tact/ide/completion/TactCompletionContributor.kt b/modules/tact/src/org/ton/intellij/tact/ide/completion/TactCompletionContributor.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/ide/completion/TactCompletionContributor.kt rename to modules/tact/src/org/ton/intellij/tact/ide/completion/TactCompletionContributor.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/ide/completion/TactCompletionProvider.kt b/modules/tact/src/org/ton/intellij/tact/ide/completion/TactCompletionProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/ide/completion/TactCompletionProvider.kt rename to modules/tact/src/org/ton/intellij/tact/ide/completion/TactCompletionProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/ide/completion/TactDotCompletionProvider.kt b/modules/tact/src/org/ton/intellij/tact/ide/completion/TactDotCompletionProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/ide/completion/TactDotCompletionProvider.kt rename to modules/tact/src/org/ton/intellij/tact/ide/completion/TactDotCompletionProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/ide/completion/TactReferenceCompletionProvider.kt b/modules/tact/src/org/ton/intellij/tact/ide/completion/TactReferenceCompletionProvider.kt similarity index 96% rename from src/main/kotlin/org/ton/intellij/tact/ide/completion/TactReferenceCompletionProvider.kt rename to modules/tact/src/org/ton/intellij/tact/ide/completion/TactReferenceCompletionProvider.kt index 698d707..db7d885 100644 --- a/src/main/kotlin/org/ton/intellij/tact/ide/completion/TactReferenceCompletionProvider.kt +++ b/modules/tact/src/org/ton/intellij/tact/ide/completion/TactReferenceCompletionProvider.kt @@ -26,7 +26,7 @@ class TactReferenceCompletionProvider : TactCompletionProvider() { val position = parameters.position.parent as? TactReferenceExpression ?: return val inferenceContextOwner = position.ancestorStrict() ?: return val project = position.project - val lookup = TactLookup(project, inferenceContextOwner) + TactLookup(project, inferenceContextOwner) collectVariableCandidates(position).distinctBy { it.name }.forEach { result.addElement(LookupElementBuilder.createWithIcon(it)) diff --git a/src/main/kotlin/org/ton/intellij/tact/ide/completion/TactTypeCompletionProvider.kt b/modules/tact/src/org/ton/intellij/tact/ide/completion/TactTypeCompletionProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/ide/completion/TactTypeCompletionProvider.kt rename to modules/tact/src/org/ton/intellij/tact/ide/completion/TactTypeCompletionProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/ide/hints/TactConstantHintsProvider.kt b/modules/tact/src/org/ton/intellij/tact/ide/hints/TactConstantHintsProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/ide/hints/TactConstantHintsProvider.kt rename to modules/tact/src/org/ton/intellij/tact/ide/hints/TactConstantHintsProvider.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/inspections/TactDiagnosticBasedInspection.kt b/modules/tact/src/org/ton/intellij/tact/inspections/TactDiagnosticBasedInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/inspections/TactDiagnosticBasedInspection.kt rename to modules/tact/src/org/ton/intellij/tact/inspections/TactDiagnosticBasedInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/inspections/TactLocalInspectionTool.kt b/modules/tact/src/org/ton/intellij/tact/inspections/TactLocalInspectionTool.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/inspections/TactLocalInspectionTool.kt rename to modules/tact/src/org/ton/intellij/tact/inspections/TactLocalInspectionTool.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/inspections/TactUnresolvedReferenceInspection.kt b/modules/tact/src/org/ton/intellij/tact/inspections/TactUnresolvedReferenceInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/inspections/TactUnresolvedReferenceInspection.kt rename to modules/tact/src/org/ton/intellij/tact/inspections/TactUnresolvedReferenceInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/inspections/numeric/TactDivideByZeroInspection.kt b/modules/tact/src/org/ton/intellij/tact/inspections/numeric/TactDivideByZeroInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/inspections/numeric/TactDivideByZeroInspection.kt rename to modules/tact/src/org/ton/intellij/tact/inspections/numeric/TactDivideByZeroInspection.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/inspections/style/TactConstantExpressionInspection.kt b/modules/tact/src/org/ton/intellij/tact/inspections/style/TactConstantExpressionInspection.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/inspections/style/TactConstantExpressionInspection.kt rename to modules/tact/src/org/ton/intellij/tact/inspections/style/TactConstantExpressionInspection.kt diff --git a/src/main/grammar/TactLexer.flex b/modules/tact/src/org/ton/intellij/tact/lexer/TactLexer.flex similarity index 99% rename from src/main/grammar/TactLexer.flex rename to modules/tact/src/org/ton/intellij/tact/lexer/TactLexer.flex index 1bbda8c..4533a48 100644 --- a/src/main/grammar/TactLexer.flex +++ b/modules/tact/src/org/ton/intellij/tact/lexer/TactLexer.flex @@ -1,4 +1,4 @@ -package org.ton.intellij.tact.parser; +package org.ton.intellij.tact.lexer; import com.intellij.lexer.FlexLexer; import com.intellij.psi.tree.IElementType; diff --git a/modules/tact/src/org/ton/intellij/tact/lexer/TactLexer.kt b/modules/tact/src/org/ton/intellij/tact/lexer/TactLexer.kt new file mode 100644 index 0000000..37225fb --- /dev/null +++ b/modules/tact/src/org/ton/intellij/tact/lexer/TactLexer.kt @@ -0,0 +1,5 @@ +package org.ton.intellij.tact.lexer + +import com.intellij.lexer.FlexAdapter + +class TactLexer : FlexAdapter(_TactLexer()) diff --git a/src/main/kotlin/org/ton/intellij/tact/linemarkers/TactImplLineMarkerProvider.kt b/modules/tact/src/org/ton/intellij/tact/linemarkers/TactImplLineMarkerProvider.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/linemarkers/TactImplLineMarkerProvider.kt rename to modules/tact/src/org/ton/intellij/tact/linemarkers/TactImplLineMarkerProvider.kt diff --git a/src/main/grammar/TactParser.bnf b/modules/tact/src/org/ton/intellij/tact/parser/TactParser.bnf similarity index 100% rename from src/main/grammar/TactParser.bnf rename to modules/tact/src/org/ton/intellij/tact/parser/TactParser.bnf diff --git a/src/main/kotlin/org/ton/intellij/tact/parser/TactParserDefinition.kt b/modules/tact/src/org/ton/intellij/tact/parser/TactParserDefinition.kt similarity index 90% rename from src/main/kotlin/org/ton/intellij/tact/parser/TactParserDefinition.kt rename to modules/tact/src/org/ton/intellij/tact/parser/TactParserDefinition.kt index f11295e..93bb08c 100644 --- a/src/main/kotlin/org/ton/intellij/tact/parser/TactParserDefinition.kt +++ b/modules/tact/src/org/ton/intellij/tact/parser/TactParserDefinition.kt @@ -2,11 +2,11 @@ package org.ton.intellij.tact.parser import com.intellij.lang.ASTNode import com.intellij.lang.ParserDefinition -import com.intellij.lexer.FlexAdapter import com.intellij.openapi.project.Project import com.intellij.psi.FileViewProvider import com.intellij.psi.PsiElement import com.intellij.psi.tree.TokenSet +import org.ton.intellij.tact.lexer.TactLexer import org.ton.intellij.tact.psi.TACT_COMMENTS import org.ton.intellij.tact.psi.TACT_STRING_LITERALS import org.ton.intellij.tact.psi.TactElementTypes @@ -29,4 +29,3 @@ class TactParserDefinition : ParserDefinition { override fun createFile(viewProvider: FileViewProvider) = TactFile(viewProvider) } -class TactLexer : FlexAdapter(org.ton.intellij.tact.parser._TactLexer()) diff --git a/src/main/kotlin/org/ton/intellij/tact/parser/TactParserUtil.kt b/modules/tact/src/org/ton/intellij/tact/parser/TactParserUtil.kt similarity index 63% rename from src/main/kotlin/org/ton/intellij/tact/parser/TactParserUtil.kt rename to modules/tact/src/org/ton/intellij/tact/parser/TactParserUtil.kt index cbbcb6f..22eca36 100644 --- a/src/main/kotlin/org/ton/intellij/tact/parser/TactParserUtil.kt +++ b/modules/tact/src/org/ton/intellij/tact/parser/TactParserUtil.kt @@ -2,5 +2,4 @@ package org.ton.intellij.tact.parser import com.intellij.lang.parser.GeneratedParserUtilBase -object TactParserUtil : GeneratedParserUtilBase() { -} +object TactParserUtil : GeneratedParserUtilBase() diff --git a/src/main/kotlin/org/ton/intellij/tact/project/TactLibrary.kt b/modules/tact/src/org/ton/intellij/tact/project/TactLibrary.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/project/TactLibrary.kt rename to modules/tact/src/org/ton/intellij/tact/project/TactLibrary.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactAbstractable.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactAbstractable.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactAbstractable.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactAbstractable.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactElement.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactElement.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactElement.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactElement.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactElementType.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactElementType.kt similarity index 79% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactElementType.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactElementType.kt index 2bf3f7b..913329e 100644 --- a/src/main/kotlin/org/ton/intellij/tact/psi/TactElementType.kt +++ b/modules/tact/src/org/ton/intellij/tact/psi/TactElementType.kt @@ -5,6 +5,4 @@ import org.ton.intellij.tact.TactLanguage class TactElementType( debug: String, -) : IElementType(debug, TactLanguage) { - -} +) : IElementType(debug, TactLanguage) diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactFile.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactFile.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactFile.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactFile.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactFileElementType.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactFileElementType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactFileElementType.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactFileElementType.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactFunctionLike.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactFunctionLike.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactFunctionLike.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactFunctionLike.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactInferenceContextOwner.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactInferenceContextOwner.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactInferenceContextOwner.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactInferenceContextOwner.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactItemElement.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactItemElement.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactItemElement.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactItemElement.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactNamedElement.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactNamedElement.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactNamedElement.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactNamedElement.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactPsiFactory.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactPsiFactory.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactPsiFactory.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactPsiFactory.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactRecursiveElementWalkingVisitor.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactRecursiveElementWalkingVisitor.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactRecursiveElementWalkingVisitor.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactRecursiveElementWalkingVisitor.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactTokenType.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactTokenType.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactTokenType.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactTokenType.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/TactTypeDeclarationElement.kt b/modules/tact/src/org/ton/intellij/tact/psi/TactTypeDeclarationElement.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/TactTypeDeclarationElement.kt rename to modules/tact/src/org/ton/intellij/tact/psi/TactTypeDeclarationElement.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactBouncedFunctionImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactBouncedFunctionImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactBouncedFunctionImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactBouncedFunctionImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactCallExpressionImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactCallExpressionImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactCallExpressionImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactCallExpressionImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactCatchParameterMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactCatchParameterMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactCatchParameterMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactCatchParameterMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactConstantImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactConstantImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactConstantImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactConstantImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactContractImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactContractImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactContractImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactContractImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactContractInitImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactContractInitImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactContractInitImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactContractInitImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactExternalFunctionImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactExternalFunctionImplMixin.kt similarity index 90% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactExternalFunctionImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactExternalFunctionImplMixin.kt index 3fcf8da..636063d 100644 --- a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactExternalFunctionImplMixin.kt +++ b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactExternalFunctionImplMixin.kt @@ -5,7 +5,6 @@ import com.intellij.lang.ASTNode import org.ton.intellij.tact.psi.TactBlock import org.ton.intellij.tact.psi.TactExternalFunction import org.ton.intellij.tact.psi.TactInferenceContextOwner -import org.ton.intellij.tact.psi.TactReceiveFunction abstract class TactExternalFunctionImplMixin( node: ASTNode diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactFieldExpressionImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactFieldExpressionImplMixin.kt similarity index 82% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactFieldExpressionImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactFieldExpressionImplMixin.kt index 6aa7a05..1d983f7 100644 --- a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactFieldExpressionImplMixin.kt +++ b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactFieldExpressionImplMixin.kt @@ -4,9 +4,7 @@ import com.intellij.extapi.psi.ASTWrapperPsiElement import com.intellij.lang.ASTNode import com.intellij.psi.PsiReference import org.ton.intellij.tact.psi.TactFieldExpression -import org.ton.intellij.tact.psi.TactStructExpression import org.ton.intellij.tact.resolve.TactFieldReference -import org.ton.intellij.tact.resolve.TactTypeReference abstract class TactFieldExpressionImplMixin(node: ASTNode) : ASTWrapperPsiElement(node), TactFieldExpression { override fun getReference(): PsiReference { diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactFieldImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactFieldImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactFieldImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactFieldImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactForEachKeyMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactForEachKeyMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactForEachKeyMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactForEachKeyMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactForEachValueMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactForEachValueMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactForEachValueMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactForEachValueMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactFunction.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactFunction.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactFunction.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactFunction.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactFunctionParameterImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactFunctionParameterImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactFunctionParameterImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactFunctionParameterImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactInitOfExpressionImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactInitOfExpressionImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactInitOfExpressionImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactInitOfExpressionImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactLetStatementImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactLetStatementImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactLetStatementImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactLetStatementImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactMessageImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactMessageImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactMessageImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactMessageImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactPrimitiveImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactPrimitiveImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactPrimitiveImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactPrimitiveImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactReceiveFunctionImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactReceiveFunctionImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactReceiveFunctionImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactReceiveFunctionImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactReferenceExpressionImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactReferenceExpressionImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactReferenceExpressionImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactReferenceExpressionImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactReferencedTypeImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactReferencedTypeImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactReferencedTypeImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactReferencedTypeImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactStructExpressionImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactStructExpressionImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactStructExpressionImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactStructExpressionImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactStructImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactStructImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactStructImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactStructImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/psi/impl/TactTraitImplMixin.kt b/modules/tact/src/org/ton/intellij/tact/psi/impl/TactTraitImplMixin.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/psi/impl/TactTraitImplMixin.kt rename to modules/tact/src/org/ton/intellij/tact/psi/impl/TactTraitImplMixin.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/resolve/TactFieldReference.kt b/modules/tact/src/org/ton/intellij/tact/resolve/TactFieldReference.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/resolve/TactFieldReference.kt rename to modules/tact/src/org/ton/intellij/tact/resolve/TactFieldReference.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/resolve/TactReference.kt b/modules/tact/src/org/ton/intellij/tact/resolve/TactReference.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/resolve/TactReference.kt rename to modules/tact/src/org/ton/intellij/tact/resolve/TactReference.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/resolve/TactTypeReference.kt b/modules/tact/src/org/ton/intellij/tact/resolve/TactTypeReference.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/resolve/TactTypeReference.kt rename to modules/tact/src/org/ton/intellij/tact/resolve/TactTypeReference.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/TactConstantStub.kt b/modules/tact/src/org/ton/intellij/tact/stub/TactConstantStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/stub/TactConstantStub.kt rename to modules/tact/src/org/ton/intellij/tact/stub/TactConstantStub.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/TactContractStub.kt b/modules/tact/src/org/ton/intellij/tact/stub/TactContractStub.kt similarity index 93% rename from src/main/kotlin/org/ton/intellij/tact/stub/TactContractStub.kt rename to modules/tact/src/org/ton/intellij/tact/stub/TactContractStub.kt index 71abf9d..a84b9d0 100644 --- a/src/main/kotlin/org/ton/intellij/tact/stub/TactContractStub.kt +++ b/modules/tact/src/org/ton/intellij/tact/stub/TactContractStub.kt @@ -5,8 +5,6 @@ import com.intellij.util.io.StringRef import org.ton.intellij.tact.psi.TactContract import org.ton.intellij.tact.psi.impl.TactContractImpl import org.ton.intellij.tact.stub.index.indexContract -import org.ton.intellij.tact.stub.index.indexMessage -import org.ton.intellij.tact.stub.index.indexStruct class TactContractStub( parent: StubElement<*>, diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/TactFieldStub.kt b/modules/tact/src/org/ton/intellij/tact/stub/TactFieldStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/stub/TactFieldStub.kt rename to modules/tact/src/org/ton/intellij/tact/stub/TactFieldStub.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/TactFunctionStub.kt b/modules/tact/src/org/ton/intellij/tact/stub/TactFunctionStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/stub/TactFunctionStub.kt rename to modules/tact/src/org/ton/intellij/tact/stub/TactFunctionStub.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/TactMessageStub.kt b/modules/tact/src/org/ton/intellij/tact/stub/TactMessageStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/stub/TactMessageStub.kt rename to modules/tact/src/org/ton/intellij/tact/stub/TactMessageStub.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/TactPrimitiveStub.kt b/modules/tact/src/org/ton/intellij/tact/stub/TactPrimitiveStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/stub/TactPrimitiveStub.kt rename to modules/tact/src/org/ton/intellij/tact/stub/TactPrimitiveStub.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/TactStructStub.kt b/modules/tact/src/org/ton/intellij/tact/stub/TactStructStub.kt similarity index 96% rename from src/main/kotlin/org/ton/intellij/tact/stub/TactStructStub.kt rename to modules/tact/src/org/ton/intellij/tact/stub/TactStructStub.kt index baef547..109d529 100644 --- a/src/main/kotlin/org/ton/intellij/tact/stub/TactStructStub.kt +++ b/modules/tact/src/org/ton/intellij/tact/stub/TactStructStub.kt @@ -4,7 +4,6 @@ import com.intellij.psi.stubs.* import com.intellij.util.io.StringRef import org.ton.intellij.tact.psi.TactStruct import org.ton.intellij.tact.psi.impl.TactStructImpl -import org.ton.intellij.tact.stub.index.indexMessage import org.ton.intellij.tact.stub.index.indexStruct class TactStructStub( diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/TactStub.kt b/modules/tact/src/org/ton/intellij/tact/stub/TactStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/stub/TactStub.kt rename to modules/tact/src/org/ton/intellij/tact/stub/TactStub.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/TactTraitStub.kt b/modules/tact/src/org/ton/intellij/tact/stub/TactTraitStub.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/stub/TactTraitStub.kt rename to modules/tact/src/org/ton/intellij/tact/stub/TactTraitStub.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/index/StubIndexing.kt b/modules/tact/src/org/ton/intellij/tact/stub/index/StubIndexing.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/stub/index/StubIndexing.kt rename to modules/tact/src/org/ton/intellij/tact/stub/index/StubIndexing.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/index/TactConstantIndex.kt b/modules/tact/src/org/ton/intellij/tact/stub/index/TactConstantIndex.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/stub/index/TactConstantIndex.kt rename to modules/tact/src/org/ton/intellij/tact/stub/index/TactConstantIndex.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/index/TactFunctionIndex.kt b/modules/tact/src/org/ton/intellij/tact/stub/index/TactFunctionIndex.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/stub/index/TactFunctionIndex.kt rename to modules/tact/src/org/ton/intellij/tact/stub/index/TactFunctionIndex.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/index/TactNamedElementIndex.kt b/modules/tact/src/org/ton/intellij/tact/stub/index/TactNamedElementIndex.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/stub/index/TactNamedElementIndex.kt rename to modules/tact/src/org/ton/intellij/tact/stub/index/TactNamedElementIndex.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/stub/index/TactTypesIndex.kt b/modules/tact/src/org/ton/intellij/tact/stub/index/TactTypesIndex.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/stub/index/TactTypesIndex.kt rename to modules/tact/src/org/ton/intellij/tact/stub/index/TactTypesIndex.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/type/TactLookup.kt b/modules/tact/src/org/ton/intellij/tact/type/TactLookup.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/type/TactLookup.kt rename to modules/tact/src/org/ton/intellij/tact/type/TactLookup.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/type/TactTy.kt b/modules/tact/src/org/ton/intellij/tact/type/TactTy.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/type/TactTy.kt rename to modules/tact/src/org/ton/intellij/tact/type/TactTy.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/type/TactTyInference.kt b/modules/tact/src/org/ton/intellij/tact/type/TactTyInference.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/type/TactTyInference.kt rename to modules/tact/src/org/ton/intellij/tact/type/TactTyInference.kt diff --git a/src/main/kotlin/org/ton/intellij/tact/type/TactTypeInferenceWalker.kt b/modules/tact/src/org/ton/intellij/tact/type/TactTypeInferenceWalker.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tact/type/TactTypeInferenceWalker.kt rename to modules/tact/src/org/ton/intellij/tact/type/TactTypeInferenceWalker.kt diff --git a/modules/tlb/build.gradle.kts b/modules/tlb/build.gradle.kts new file mode 100644 index 0000000..565067f --- /dev/null +++ b/modules/tlb/build.gradle.kts @@ -0,0 +1,50 @@ +import org.jetbrains.grammarkit.tasks.GenerateLexerTask +import org.jetbrains.grammarkit.tasks.GenerateParserTask +import org.jetbrains.intellij.platform.gradle.TestFrameworkType +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.jetbrains.intellij.platform.module") + id("org.jetbrains.grammarkit") +} + +dependencies { + intellijPlatform { + val version = providers.gradleProperty("platformVersion") + intellijIdeaCommunity(version) + testFramework(TestFrameworkType.Platform) + bundledPlugin("com.intellij.dev") + } + compileOnly(project(":util")) + testImplementation(kotlin("test")) +} + +val generateTlbParser = task("generateTlbParser") { + sourceFile.set(file("src/org/ton/intellij/tlb/parser/TlbParser.bnf")) + targetRootOutputDir.set(file("gen")) + pathToParser.set("/org/ton/intellij/tlb/parser/TlbParser.java") + pathToPsiRoot.set("/org/ton/intellij/tlb/psi") + purgeOldFiles.set(true) + + dependsOn(":util:composedJar") +} + +val generateTlbLexer = task("generateTlbLexer") { + val input = "src/org/ton/intellij/tlb/lexer/TlbLexer.flex" + val output = "gen/org/ton/intellij/tlb/lexer" + sourceFile.set(file(input)) + targetOutputDir.set(file(output)) + purgeOldFiles.set(true) +} + +tasks.test { + useJUnit() +} + +tasks.withType().configureEach { + dependsOn(generateTlbParser, generateTlbLexer) +} + +tasks.withType().configureEach { + dependsOn(generateTlbParser, generateTlbLexer) +} diff --git a/modules/tlb/resources/META-INF/tlb.xml b/modules/tlb/resources/META-INF/tlb.xml new file mode 100644 index 0000000..b8deccb --- /dev/null +++ b/modules/tlb/resources/META-INF/tlb.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/colors/highlighter_example.tlb b/modules/tlb/resources/colors/highlighter_example.tlb similarity index 100% rename from src/main/resources/colors/highlighter_example.tlb rename to modules/tlb/resources/colors/highlighter_example.tlb diff --git a/src/main/resources/icons/tlb.svg b/modules/tlb/resources/icons/tlb.svg similarity index 100% rename from src/main/resources/icons/tlb.svg rename to modules/tlb/resources/icons/tlb.svg diff --git a/modules/tlb/src/org/ton/intellij/tlb/ConstructorTag.kt b/modules/tlb/src/org/ton/intellij/tlb/ConstructorTag.kt new file mode 100644 index 0000000..d818617 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/ConstructorTag.kt @@ -0,0 +1,124 @@ +package org.ton.intellij.tlb + +import org.ton.intellij.tlb.psi.TlbConstructor +import org.ton.intellij.tlb.psi.TlbConstructorTag +import org.ton.intellij.tlb.psi.printToString +import java.util.zip.CRC32 + +private const val SHORT_TAG_MASK = (1L shl 59) - 1 +private const val TAG_MASK = (1L shl 63) - 1 +private const val HEX = "0123456789abcdef" + +class ConstructorTag( + val value: Long +) { + override fun toString(): String { + if (value == 0L) { + return "\$_" + } + return buildString { + var tag = value + if (SHORT_TAG_MASK and tag == 0L) { + append('$') + var c = 0 + while (tag and TAG_MASK != 0L) { + append(tag ushr 63) + tag = tag shl 1 + c++ + } + if (c == 0) { + append("_") + } + } else { + append("#") + while (tag and TAG_MASK != 0L) { + append(HEX[(tag ushr 60).toInt()]) + tag = tag shl 4 + } + if (tag == 0L) { + append("_") + } + } + } + } + + companion object { + val EMPTY = ConstructorTag(0L) + } +} + +@OptIn(ExperimentalStdlibApi::class) +fun TlbConstructor.computeTag(): ConstructorTag? { + val normalized = printToString(skipTag = true, showBraces = false) + if (normalized.contains("(invalid")) { + return null + } + return CRC32().run { + update(normalized.toByteArray()) +// println("crc32('$normalized') = ${value.toHexString()}") + ConstructorTag((value.toLong() shl 32) or 0x80000000) + } +} + +fun TlbConstructorTag.toConstructorTag(): ConstructorTag { + val str = binaryTag?.text ?: hexTag?.text ?: return ConstructorTag.EMPTY + val n = str.length + if (n <= 1) return ConstructorTag.EMPTY + var i = 1 + var value = 0L + var bits = 0 + + when (str[0]) { + '#' -> { + while (i < n) { + val c = str[i] + if (c == '_') { + break + } + val hex = when (c) { + in '0'..'9' -> c.code - '0'.code + in 'A'..'F' -> c.code - 'A'.code + 10 + in 'a'..'f' -> c.code - 'a'.code + 10 + else -> return ConstructorTag.EMPTY + } + + if (bits + 4 > 64) return ConstructorTag.EMPTY + + value = value or (hex.toLong() shl (60 - bits)) + bits += 4 + i++ + } + } + + '$' -> { + if (str[1] != '_') { + while (i < n) { + val c = str[i] + if (c != '0' && c != '1') return ConstructorTag.EMPTY + if (bits == 64) return ConstructorTag.EMPTY + + val bit = c.code - '0'.code + value = value or (bit.toLong() shl (63 - bits)) + bits++ + i++ + } + } + } + else -> return ConstructorTag.EMPTY + } + + if (i < n - 1) return ConstructorTag.EMPTY + + if (i == n - 1 && bits > 0) { + while (bits > 0 && ((value shr (64 - bits)) and 1) == 0L) { + bits-- + } + if (bits > 0) { + bits-- + } + } + + if (bits == 64) return ConstructorTag.EMPTY + + return ConstructorTag(value or (1L shl (63 - bits))) +} \ No newline at end of file diff --git a/src/main/kotlin/org/ton/intellij/tlb/TlbFileType.kt b/modules/tlb/src/org/ton/intellij/tlb/TlbFileType.kt similarity index 92% rename from src/main/kotlin/org/ton/intellij/tlb/TlbFileType.kt rename to modules/tlb/src/org/ton/intellij/tlb/TlbFileType.kt index e6c5ad1..56ec581 100644 --- a/src/main/kotlin/org/ton/intellij/tlb/TlbFileType.kt +++ b/modules/tlb/src/org/ton/intellij/tlb/TlbFileType.kt @@ -5,7 +5,7 @@ import com.intellij.openapi.vfs.VirtualFile import org.jetbrains.annotations.NonNls object TlbFileType : LanguageFileType(TlbLanguage) { - override fun getName() = "TLB" + override fun getName() = "TL-B" override fun getDescription() = "TL-B schema" override fun getDefaultExtension() = "tlb" override fun getIcon() = TlbIcons.FILE diff --git a/src/main/kotlin/org/ton/intellij/tlb/TlbIcons.kt b/modules/tlb/src/org/ton/intellij/tlb/TlbIcons.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tlb/TlbIcons.kt rename to modules/tlb/src/org/ton/intellij/tlb/TlbIcons.kt diff --git a/src/main/kotlin/org/ton/intellij/tlb/TlbLanguage.kt b/modules/tlb/src/org/ton/intellij/tlb/TlbLanguage.kt similarity index 63% rename from src/main/kotlin/org/ton/intellij/tlb/TlbLanguage.kt rename to modules/tlb/src/org/ton/intellij/tlb/TlbLanguage.kt index dcabc08..4cf8abb 100644 --- a/src/main/kotlin/org/ton/intellij/tlb/TlbLanguage.kt +++ b/modules/tlb/src/org/ton/intellij/tlb/TlbLanguage.kt @@ -4,7 +4,7 @@ import com.intellij.lang.InjectableLanguage import com.intellij.lang.Language object TlbLanguage : - Language("tlb", "text/tlb", "text/x-tlb", "text/tl-b", "text/x-tl-b", "application/x-tlb", "application/x-tl-b"), + Language("TL-B", "text/tlb", "text/x-tlb", "text/tl-b", "text/x-tl-b", "application/x-tlb", "application/x-tl-b"), InjectableLanguage { override fun isCaseSensitive(): Boolean = false } diff --git a/modules/tlb/src/org/ton/intellij/tlb/TlbSize.kt b/modules/tlb/src/org/ton/intellij/tlb/TlbSize.kt new file mode 100644 index 0000000..b73346b --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/TlbSize.kt @@ -0,0 +1,148 @@ +package org.ton.intellij.tlb + +import kotlin.math.max +import kotlin.math.min + +class TlbSize private constructor( + val value: Long +) { + constructor( + minRefs: Int, + minBits: Int, + maxRefs: Int, + maxBits: Int + ) : this( + ((minBits.toLong() * 0x100 + minRefs.toLong()) shl 32) + (maxBits.toLong() * 0x100 + maxRefs.toLong()) + ) + + val minSize: Int get() = (value ushr 32).toInt() + val maxSize: Int get() = (value and 0xFFFFFFFFL).toInt() + + // | + val maxRefs: Int get() = (value and 0xFF).toInt() + val maxBits: Int get() = ((value ushr 8) and BITS_MASK).toInt() + val minRefs: Int get() = ((value ushr 32) and 0xFF).toInt() + val minBits: Int get() = ((value ushr 40) and BITS_MASK).toInt() + + val isFixed: Boolean get() = minSize == maxSize + + fun fitsIntoCell(): Boolean = + isPossible(MAX_SIZE_CELL, minSize) + + fun isPossible(): Boolean = + isPossible(maxSize, minSize) + + fun normalize(): TlbSize { + return TlbSize(normalize(value)) + } + + fun withoutMin(): TlbSize = TlbSize(value and ((1L shl 32) - 1)) + + operator fun plus(other: TlbSize): TlbSize { + return TlbSize(normalize(value + other.value)) + } + + infix fun or(other: TlbSize): TlbSize { + return TlbSize( + minRefs = min(minRefs, other.minRefs), + minBits = min(minBits, other.minBits), + maxRefs = max(maxRefs, other.maxRefs), + maxBits = max(maxBits, other.maxBits) + ) + } + + operator fun times(count: Int): TlbSize { + return when (count) { + 0 -> TlbSize(0) + 1 -> this + else -> TlbSize( + min(minRefs * count, MAX_REFS_MASK.toInt()), + min(minBits * count, BITS_MASK.toInt()), + min(maxRefs * count, MAX_REFS_MASK.toInt()), + min(maxBits * count, BITS_MASK.toInt()) + ) + } + } + + fun timesAtLeast(count: Int): TlbSize { + val clampedCount = min(max(count, 0), 1024) + return TlbSize( + minRefs = min(minRefs * clampedCount, MAX_REFS_MASK.toInt()), + minBits = min(minBits * clampedCount, BITS_MASK.toInt()), + maxRefs = if (maxRefs != 0) MAX_REFS_MASK.toInt() else 0, + maxBits = if (maxBits != 0) BITS_MASK.toInt() else 0 + ) + } + + override fun toString(): String = buildString { + fun appendSize(bits: Int, refs: Int) { + if (bits >= 1024 && refs >= 7) { + append("Inf") + } else { + append(bits) + if (refs > 0) { + append("+") + append(refs) + append("R") + } + } + } + + if (isFixed) { + append("=") + } + appendSize(minBits, minRefs) + if (!isFixed) { + append("..") + appendSize(maxBits, maxRefs) + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is TlbSize) return false + if (value != other.value) return false + return true + } + + override fun hashCode(): Int = value.hashCode() + + companion object { + const val MAX_SIZE_CELL: Int = 0x3FF04 // 0x3FF = 1023 bits, 0x04 = 4 refs + const val BITS_MASK: Long = 0x7FF + const val MAX_REFS_MASK: Long = 7 + + val ONE_REF: TlbSize = TlbSize(0x100000001) + val ANY: TlbSize = TlbSize(0x7ff07) + val IMPOSSIBLE: TlbSize = TlbSize(0x7ff07L shl 32) + val ZERO: TlbSize = TlbSize(0) + + fun convertSize(z: Int): Int = ((z and 0xFF) shl 16) or (z ushr 8) + + private fun isPossible( + maxSize: Int, + minSize: Int + ): Boolean = (maxSize - minSize).toLong() and 0x80000080 == 0L + + private fun normalize(value: Long): Long { + var v = value + v = normalize(v, 0xF8, 7) + v = normalize(v, 0xfff80000, 0x7ff00) + v = normalize(v, 0xF8L shl 32, 7L shl 32) + v = normalize(v, 0xfff80000L shl 32, 0x7ff00L shl 32) + return v + } + + private fun normalize(value: Long, a: Long, b: Long): Long { + if (value and a != 0L) { + return (value or (a or b)) - a + } + return value + } + + fun fixedSize(size: Int): TlbSize = TlbSize(size.toLong() * 0x10000000100) + + fun range(minSize: Int, maxSize: Int): TlbSize = + TlbSize(((minSize.toLong() shl 32) + maxSize) shl 8) + } +} diff --git a/modules/tlb/src/org/ton/intellij/tlb/dev/PsiViewerTlbSizeNode.kt b/modules/tlb/src/org/ton/intellij/tlb/dev/PsiViewerTlbSizeNode.kt new file mode 100644 index 0000000..3985a0a --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/dev/PsiViewerTlbSizeNode.kt @@ -0,0 +1,35 @@ +package org.ton.intellij.tlb.dev + +import com.intellij.dev.psiViewer.properties.tree.PsiViewerPropertyNode +import com.intellij.dev.psiViewer.properties.tree.nodes.computePsiViewerApiClassesNodes +import com.intellij.dev.psiViewer.properties.tree.nodes.psiViewerApiClassesExtending +import com.intellij.dev.psiViewer.properties.tree.nodes.psiViewerPsiTypeAttributes +import org.ton.intellij.tlb.TlbSize + +class PsiViewerTlbSizeNode( + private val size: TlbSize, + private val nodeContext: PsiViewerPropertyNode.Context +) : PsiViewerPropertyNode { + class Factory : PsiViewerPropertyNode.Factory { + override suspend fun createNode( + nodeContext: PsiViewerPropertyNode.Context, + returnedValue: Any + ): PsiViewerPropertyNode? { + val type = returnedValue as? TlbSize ?: return null + return PsiViewerTlbSizeNode(type, nodeContext) + } + + override fun isMatchingType(clazz: Class<*>): Boolean = TlbSize::class.java.isAssignableFrom(clazz) + } + + override val children = PsiViewerPropertyNode.Children.Async { + val psiTypeApiClasses = size::class.java.psiViewerApiClassesExtending(TlbSize::class.java) + computePsiViewerApiClassesNodes(psiTypeApiClasses, size, nodeContext) + } + + override val presentation = PsiViewerPropertyNode.Presentation { + it.append(size.toString(), psiViewerPsiTypeAttributes()) + } + + override val weight: Int = 25 +} \ No newline at end of file diff --git a/src/main/kotlin/org/ton/intellij/tlb/ide/actions/createFile.kt b/modules/tlb/src/org/ton/intellij/tlb/ide/actions/createFile.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tlb/ide/actions/createFile.kt rename to modules/tlb/src/org/ton/intellij/tlb/ide/actions/createFile.kt diff --git a/modules/tlb/src/org/ton/intellij/tlb/ide/annotation.kt b/modules/tlb/src/org/ton/intellij/tlb/ide/annotation.kt new file mode 100644 index 0000000..6c57692 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/ide/annotation.kt @@ -0,0 +1,90 @@ +package org.ton.intellij.tlb.ide + +import com.intellij.codeInspection.ProblemHighlightType +import com.intellij.lang.annotation.AnnotationHolder +import com.intellij.lang.annotation.Annotator +import com.intellij.lang.annotation.HighlightSeverity +import com.intellij.psi.PsiElement +import org.ton.intellij.tlb.psi.* + +class TlbAnnotator : Annotator { + + override fun annotate(element: PsiElement, holder: AnnotationHolder) { + when(element) { + is TlbConstructor -> { + holder.annotateInfo(element.identifier, TlbColor.CONSTRUCTOR_NAME) + } + is TlbCommonField -> { + val identifier = element.identifier + if (identifier != null) { + holder.annotateInfo(identifier, TlbColor.FIELD_NAME) + } + } + is TlbImplicitField -> { + if (element.typeKeyword != null) { + holder.annotateInfo(element.identifier, TlbColor.TYPE_PARAMETER) + } else { + holder.annotateInfo(element.identifier, TlbColor.IMPLICIT_FIELD_NAME) + } + } + is TlbResultType -> { + holder.annotateInfo(element.identifier, TlbColor.CONSTRUCTOR_TYPE_NAME) + } + is TlbParamTypeExpression -> { + val resolved = element.reference?.resolve() + when(resolved) { + is TlbImplicitField -> { + if (resolved.typeKeyword != null) { + holder.annotateInfo(element, TlbColor.TYPE_PARAMETER) + } else { + holder.annotateInfo(element, TlbColor.IMPLICIT_FIELD_NAME) + } + } + null -> { + val text = element.text + if (text.startsWith("uint") || text.startsWith("int") || text.startsWith("bits")) { + holder.annotateInfo(element, TlbColor.BUILTIN_TYPE) + } + } + } + } + } +// when (element) { +// is TlbConstructorName -> holder.annotateInfo(element, TlbColor.CONSTRUCTOR_NAME) +// is TlbFieldName -> holder.annotateInfo(element, TlbColor.FIELD_NAME) +// is TlbImplicitFieldName -> holder.annotateInfo(element, TlbColor.IMPLICIT_FIELD_NAME) +// is TlbImplicitFieldType -> holder.annotateInfo(element, TlbColor.TYPE) +// is TlbCombinatorName -> holder.annotateInfo(element, TlbColor.COMBINATOR_NAME) +// is TlbNamedRefMixin -> { +// when (element.reference.multiResolve().firstOrNull()) { +// is TlbFieldName -> holder.annotateInfo(element, TlbColor.FIELD_NAME) +// is TlbNamedField -> holder.annotateInfo(element, TlbColor.FIELD_NAME) +// is TlbImplicitFieldName -> holder.annotateInfo(element, TlbColor.IMPLICIT_FIELD_NAME) +// is TlbImplicitField -> holder.annotateInfo(element, TlbColor.IMPLICIT_FIELD_NAME) +// is TlbCombinatorName -> holder.annotateInfo(element, TlbColor.TYPE) +// else -> { +// if (element.name in TlbParserDefinition.INBUILT_TYPE_NAMES) { +// holder.annotateInfo(element, TlbColor.TYPE) +// } else if (element.containingFile.isPhysical) { +// holder.annotateUnknown(element) +// } +// } +// } +// } +// } + } + + private fun AnnotationHolder.annotateInfo(element: PsiElement, color: TlbColor) { + newSilentAnnotation(HighlightSeverity.INFORMATION) + .range(element) + .textAttributes(color.textAttributesKey) + .create() + } + + private fun AnnotationHolder.annotateUnknown(element: PsiElement) { + newAnnotation(HighlightSeverity.ERROR, "Unresolved reference: ${element.text}") + .range(element) + .highlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL) + .create() + } +} diff --git a/src/main/kotlin/org/ton/intellij/tlb/ide/braces.kt b/modules/tlb/src/org/ton/intellij/tlb/ide/braces.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tlb/ide/braces.kt rename to modules/tlb/src/org/ton/intellij/tlb/ide/braces.kt diff --git a/src/main/kotlin/org/ton/intellij/tlb/ide/colors.kt b/modules/tlb/src/org/ton/intellij/tlb/ide/colors.kt similarity index 87% rename from src/main/kotlin/org/ton/intellij/tlb/ide/colors.kt rename to modules/tlb/src/org/ton/intellij/tlb/ide/colors.kt index e654cbb..8294cf0 100644 --- a/src/main/kotlin/org/ton/intellij/tlb/ide/colors.kt +++ b/modules/tlb/src/org/ton/intellij/tlb/ide/colors.kt @@ -30,9 +30,10 @@ enum class TlbColor( HEX_TAG("HEX Tag", Defaults.STATIC_FIELD), BINARY_TAG("Binary Tag", Defaults.STATIC_FIELD), FIELD_NAME("Field name", XmlHighlighterColors.HTML_ATTRIBUTE_NAME), - IMPLICIT_FIELD_NAME("Implicit field name", TextAttributesKey.find("KOTLIN_TYPE_PARAMETER")), - COMBINATOR_NAME("Combinator name", Defaults.KEYWORD), - TYPE("Type", XmlHighlighterColors.HTML_ATTRIBUTE_VALUE) + TYPE_PARAMETER("Type parameter", TextAttributesKey.find("TYPE_PARAMETER_NAME_ATTRIBUTES")), + CONSTRUCTOR_TYPE_NAME("Constructor type name", Defaults.KEYWORD), + IMPLICIT_FIELD_NAME("Implicit field name", XmlHighlighterColors.HTML_ATTRIBUTE_VALUE), + BUILTIN_TYPE("Builtin type", XmlHighlighterColors.HTML_ATTRIBUTE_VALUE) ; val textAttributesKey = diff --git a/src/main/kotlin/org/ton/intellij/tlb/ide/commenter.kt b/modules/tlb/src/org/ton/intellij/tlb/ide/commenter.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tlb/ide/commenter.kt rename to modules/tlb/src/org/ton/intellij/tlb/ide/commenter.kt diff --git a/src/main/kotlin/org/ton/intellij/tlb/ide/highlighter.kt b/modules/tlb/src/org/ton/intellij/tlb/ide/highlighter.kt similarity index 91% rename from src/main/kotlin/org/ton/intellij/tlb/ide/highlighter.kt rename to modules/tlb/src/org/ton/intellij/tlb/ide/highlighter.kt index 3e91851..e515a52 100644 --- a/src/main/kotlin/org/ton/intellij/tlb/ide/highlighter.kt +++ b/modules/tlb/src/org/ton/intellij/tlb/ide/highlighter.kt @@ -25,10 +25,10 @@ object TlbSyntaxHighlighter : SyntaxHighlighterBase() { NUMBER -> TlbColor.NUMBER HEX_TAG -> TlbColor.HEX_TAG BINARY_TAG -> TlbColor.BINARY_TAG - PREDIFINED_TYPE -> TlbColor.TYPE + PREDIFINED_TYPE -> TlbColor.IMPLICIT_FIELD_NAME IDENTIFIER -> TlbColor.FIELD_NAME CIRCUMFLEX, COLUMN, EQ -> TlbColor.OPERATION_SIGN - in TlbParserDefinition.BUILTIN_TYPES -> TlbColor.TYPE + in TlbParserDefinition.BUILTIN_TYPES -> TlbColor.IMPLICIT_FIELD_NAME else -> null }.let { pack(it?.textAttributesKey) diff --git a/src/main/kotlin/org/ton/intellij/tlb/ide/parser.kt b/modules/tlb/src/org/ton/intellij/tlb/ide/parser.kt similarity index 76% rename from src/main/kotlin/org/ton/intellij/tlb/ide/parser.kt rename to modules/tlb/src/org/ton/intellij/tlb/ide/parser.kt index e2d74b2..edb6487 100644 --- a/src/main/kotlin/org/ton/intellij/tlb/ide/parser.kt +++ b/modules/tlb/src/org/ton/intellij/tlb/ide/parser.kt @@ -36,25 +36,5 @@ class TlbParserDefinition : ParserDefinition { val BUILTIN_TYPES = TokenSet.create( TAG, DOUBLE_TAG, NAT_LESS, NAT_LEQ ) - val INBUILT_TYPE_NAMES = buildSet { - add("Any") - add("Cell") - add("Type") - add("int") - add("uint") - add("bits") - repeat(2056) { - add("int$it") - } - repeat(2057) { - add("uint$it") - } - repeat(1023) { - add("bits$it") - } - BUILTIN_TYPES.types.forEach { builtinType -> - add(builtinType.toString()) - } - } } } \ No newline at end of file diff --git a/src/main/kotlin/org/ton/intellij/tlb/ide/search.kt b/modules/tlb/src/org/ton/intellij/tlb/ide/search.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tlb/ide/search.kt rename to modules/tlb/src/org/ton/intellij/tlb/ide/search.kt diff --git a/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbFieldAsExpressionInspection.kt b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbFieldAsExpressionInspection.kt new file mode 100644 index 0000000..1a6f0bf --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbFieldAsExpressionInspection.kt @@ -0,0 +1,25 @@ +package org.ton.intellij.tlb.inspection + +import com.intellij.codeInspection.LocalInspectionToolSession +import com.intellij.codeInspection.ProblemsHolder +import org.ton.intellij.tlb.psi.TlbCommonField +import org.ton.intellij.tlb.psi.TlbParamTypeExpression +import org.ton.intellij.tlb.psi.TlbVisitor +import org.ton.intellij.tlb.psi.isNatural + +class TlbFieldAsExpressionInspection : TlbInspectionBase() { + override fun buildTlbVisitor( + holder: ProblemsHolder, + session: LocalInspectionToolSession + ): TlbVisitor = object : TlbVisitor() { + override fun visitParamTypeExpression(o: TlbParamTypeExpression) { + val resolved = o.reference?.resolve() + if (resolved is TlbCommonField && !resolved.typeExpression.isNatural()) { + holder.registerProblem( + o, + "Can't use a field in an expression unless it is either an integer or a type", + ) + } + } + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbGetBitNegateInspection.kt b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbGetBitNegateInspection.kt new file mode 100644 index 0000000..a599cda --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbGetBitNegateInspection.kt @@ -0,0 +1,34 @@ +package org.ton.intellij.tlb.inspection + +import com.intellij.codeInspection.LocalInspectionToolSession +import com.intellij.codeInspection.ProblemsHolder +import org.ton.intellij.tlb.psi.TlbGetBitTypeExpression +import org.ton.intellij.tlb.psi.TlbVisitor +import org.ton.intellij.tlb.psi.isNegated +import org.ton.intellij.tlb.psi.unwrap + +class TlbGetBitNegateInspection : TlbInspectionBase(){ + override fun buildTlbVisitor( + holder: ProblemsHolder, + session: LocalInspectionToolSession + ): TlbVisitor = object : TlbVisitor() { + override fun visitGetBitTypeExpression(o: TlbGetBitTypeExpression) { + val typeExpressionList = o.typeExpressionList + val left = typeExpressionList.firstOrNull()?.unwrap() ?: return + if (left.isNegated()) { + holder.registerProblem( + left, + "Can't apply bit selection operator `.` to values of negative polarity", + ) + } + + val right = typeExpressionList.getOrNull(1)?.unwrap() ?: return + if (right.isNegated()) { + holder.registerProblem( + right, + "Can't apply bit selection operator `.` to values of negative polarity", + ) + } + } + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbGetBitTypeInspection.kt b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbGetBitTypeInspection.kt new file mode 100644 index 0000000..1942e3c --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbGetBitTypeInspection.kt @@ -0,0 +1,38 @@ +package org.ton.intellij.tlb.inspection + +import com.intellij.codeInspection.LocalInspectionToolSession +import com.intellij.codeInspection.ProblemsHolder +import com.intellij.psi.PsiElement +import org.ton.intellij.tlb.psi.* + +class TlbGetBitTypeInspection : TlbInspectionBase() { + override fun buildTlbVisitor( + holder: ProblemsHolder, + session: LocalInspectionToolSession + ): TlbVisitor = object : TlbVisitor() { + override fun visitGetBitTypeExpression(o: TlbGetBitTypeExpression) { + val typeExpressionList = o.typeExpressionList + val left = typeExpressionList.firstOrNull()?.unwrap() ?: return + val resolvedParam = left.reference?.resolve() + when (resolvedParam) { + is TlbImplicitField -> { + if (resolvedParam.typeKeyword != null) { + reportProblem(holder, left) + } + } + + is TlbConstructor, + is TlbResultType -> { + reportProblem(holder, left) + } + } + } + } + + private fun reportProblem(holder: ProblemsHolder, element: PsiElement) { + holder.registerProblem( + element, + "Can't apply bit selection operator `.` to types", + ) + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbImplicitConstructorTagInspection.kt b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbImplicitConstructorTagInspection.kt new file mode 100644 index 0000000..8ce390e --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbImplicitConstructorTagInspection.kt @@ -0,0 +1,45 @@ +package org.ton.intellij.tlb.inspection + +import com.intellij.codeInspection.LocalInspectionToolSession +import com.intellij.codeInspection.LocalQuickFix +import com.intellij.codeInspection.ProblemsHolder +import com.intellij.psi.util.PsiTreeUtil +import org.ton.intellij.tlb.ConstructorTag +import org.ton.intellij.tlb.computeTag +import org.ton.intellij.tlb.inspection.fix.TlbSetConstructorTagFix +import org.ton.intellij.tlb.psi.TlbConstructor +import org.ton.intellij.tlb.psi.TlbVisitor + +class TlbImplicitConstructorTagInspection : TlbInspectionBase() { + override fun buildTlbVisitor( + holder: ProblemsHolder, + session: LocalInspectionToolSession + ): TlbVisitor = object : TlbVisitor() { + override fun visitConstructor(o: TlbConstructor) { + val constructorTag = o.constructorTag + if (constructorTag != null) { + return + } + if (o.name == "_") { + return + } + if (PsiTreeUtil.hasErrorElements(o)) { + return + } + + val fixes = ArrayList(2) + fixes.add(TlbSetConstructorTagFix(o, ConstructorTag.EMPTY)) + + val computedTag = o.computeTag() + if (computedTag != null) { + fixes.add(TlbSetConstructorTagFix(o, computedTag)) + } + + holder.registerProblem( + o.identifier, + "Constructor tag not defined", + *fixes.toTypedArray() + ) + } + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbInspectionBase.kt b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbInspectionBase.kt new file mode 100644 index 0000000..a20aaa7 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbInspectionBase.kt @@ -0,0 +1,70 @@ +package org.ton.intellij.tlb.inspection + +import com.intellij.codeInspection.* +import com.intellij.codeInspection.util.InspectionMessage +import com.intellij.openapi.util.TextRange +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiElementVisitor +import com.intellij.psi.PsiFile +import org.ton.intellij.tlb.psi.TlbFile +import org.ton.intellij.tlb.psi.TlbVisitor + +abstract class TlbInspectionBase : LocalInspectionTool() { + companion object { + private val DUMMY_VISITOR = object : TlbVisitor() { + } + } + + override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { + return super.buildVisitor(holder, isOnTheFly) + } + + override fun buildVisitor( + holder: ProblemsHolder, + isOnTheFly: Boolean, + session: LocalInspectionToolSession, + ): PsiElementVisitor { + val file = session.file as? TlbFile + return if (file != null) { + buildTlbVisitor(holder, session) + } else DUMMY_VISITOR + } + + protected open fun buildTlbVisitor( + holder: ProblemsHolder, + session: LocalInspectionToolSession, + ): TlbVisitor = object : TlbVisitor() { + override fun visitFile(file: PsiFile) { + if (file is TlbFile) { + checkFile(file, holder) + } + } + } + + protected fun checkFile(file: TlbFile, problemsHolder: ProblemsHolder) { + } + + fun ProblemsHolder.registerProblemWithoutOfflineInformation( + element: PsiElement, + @InspectionMessage description: String, + isOnTheFly: Boolean, + highlightType: ProblemHighlightType, + vararg fixes: LocalQuickFix, + ) { + registerProblemWithoutOfflineInformation(element, description, isOnTheFly, highlightType, null, *fixes) + } + + fun ProblemsHolder.registerProblemWithoutOfflineInformation( + element: PsiElement, + @InspectionMessage description: String, + isOnTheFly: Boolean, + highlightType: ProblemHighlightType, + range: TextRange?, + vararg fixes: LocalQuickFix, + ) { + if (!isOnTheFly && highlightType == ProblemHighlightType.INFORMATION) return + val problemDescriptor = + manager.createProblemDescriptor(element, range, description, highlightType, isOnTheFly, *fixes) + registerProblem(problemDescriptor) + } +} diff --git a/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbNegateExplicitFieldInspection.kt b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbNegateExplicitFieldInspection.kt new file mode 100644 index 0000000..8bb011f --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbNegateExplicitFieldInspection.kt @@ -0,0 +1,27 @@ +package org.ton.intellij.tlb.inspection + +import com.intellij.codeInspection.LocalInspectionToolSession +import com.intellij.codeInspection.ProblemsHolder +import com.intellij.psi.util.parentOfType +import org.ton.intellij.tlb.psi.TlbCommonField +import org.ton.intellij.tlb.psi.TlbNegatedTypeExpression +import org.ton.intellij.tlb.psi.TlbParamList +import org.ton.intellij.tlb.psi.TlbVisitor + +class TlbNegateExplicitFieldInspection : TlbInspectionBase() { + override fun buildTlbVisitor( + holder: ProblemsHolder, + session: LocalInspectionToolSession + ): TlbVisitor = object : TlbVisitor() { + override fun visitNegatedTypeExpression(o: TlbNegatedTypeExpression) { + val typeExpression = o.typeExpression + val resolved = typeExpression?.reference?.resolve() + if (resolved is TlbCommonField && o.parentOfType() == null) { + holder.registerProblem( + typeExpression, + "Can't negate an explicit field", + ) + } + } + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbUninitializedImplicitFieldInspection.kt b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbUninitializedImplicitFieldInspection.kt new file mode 100644 index 0000000..b1605dd --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbUninitializedImplicitFieldInspection.kt @@ -0,0 +1,34 @@ +package org.ton.intellij.tlb.inspection + +import com.intellij.codeInspection.LocalInspectionToolSession +import com.intellij.codeInspection.ProblemsHolder +import com.intellij.psi.search.searches.ReferencesSearch +import com.intellij.psi.util.parentOfType +import org.ton.intellij.tlb.psi.TlbImplicitField +import org.ton.intellij.tlb.psi.TlbNegatedTypeExpression +import org.ton.intellij.tlb.psi.TlbParamList +import org.ton.intellij.tlb.psi.TlbVisitor + +class TlbUninitializedImplicitFieldInspection : TlbInspectionBase() { + override fun buildTlbVisitor( + holder: ProblemsHolder, + session: LocalInspectionToolSession + ): TlbVisitor = object : TlbVisitor() { + override fun visitImplicitField(o: TlbImplicitField) { + val isNat = o.tag != null + val allUsages = ReferencesSearch.search(o, o.useScope) + val initializers = allUsages.filtering { + val element = it.element + (isNat && element.parent is TlbNegatedTypeExpression) || element.parentOfType() != null + } + if (initializers.none()) { + allUsages.forEach { + holder.registerProblem( + it.element, + "Implicit field `${o.name}` is not initialized", + ) + } + } + } + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbUnresolvedReferenceInspection.kt b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbUnresolvedReferenceInspection.kt new file mode 100644 index 0000000..acd0e16 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbUnresolvedReferenceInspection.kt @@ -0,0 +1,24 @@ +package org.ton.intellij.tlb.inspection + +import com.intellij.codeInspection.LocalInspectionToolSession +import com.intellij.codeInspection.ProblemHighlightType +import com.intellij.codeInspection.ProblemsHolder +import org.ton.intellij.tlb.psi.TlbParamTypeExpression +import org.ton.intellij.tlb.psi.TlbReference +import org.ton.intellij.tlb.psi.TlbVisitor + +class TlbUnresolvedReferenceInspection : TlbInspectionBase() { + override fun buildTlbVisitor( + holder: ProblemsHolder, + session: LocalInspectionToolSession + ): TlbVisitor = object : TlbVisitor() { + override fun visitParamTypeExpression(expression: TlbParamTypeExpression) { + val name = expression.identifier?.text ?: return + if (name == "Any" || name == "Cell" || name.startsWith("uint") || name.startsWith("int") || name.startsWith("bits")) return + val reference = expression.reference as? TlbReference ?: return + if (reference.multiResolve(false).isEmpty()) { + holder.registerProblem(expression, "Unresolved reference: ${expression.text}", ProblemHighlightType.LIKE_UNKNOWN_SYMBOL) + } + } + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbWrongResultTypeNameCaseInspection.kt b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbWrongResultTypeNameCaseInspection.kt new file mode 100644 index 0000000..605f421 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/inspection/TlbWrongResultTypeNameCaseInspection.kt @@ -0,0 +1,99 @@ +package org.ton.intellij.tlb.inspection + +import com.intellij.codeInspection.LocalInspectionToolSession +import com.intellij.codeInspection.LocalQuickFixOnPsiElement +import com.intellij.codeInspection.ProblemsHolder +import com.intellij.codeInspection.util.IntentionFamilyName +import com.intellij.codeInspection.util.IntentionName +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import org.ton.intellij.tlb.psi.TlbResultType +import org.ton.intellij.tlb.psi.TlbVisitor +import org.ton.intellij.tlb.psi.tlbPsiFactory +import java.util.* + +class TlbWrongResultTypeNameCaseInspection : TlbInspectionBase() { + override fun buildTlbVisitor( + holder: ProblemsHolder, + session: LocalInspectionToolSession + ): TlbVisitor = object : TlbVisitor() { + override fun visitResultType(o: TlbResultType) { + val symbolCase = determineSymbolCase(o.name ?: return) + if (symbolCase == SymbolCase.UPPERCASE) return + val identifier = o.identifier + holder.registerProblem( + identifier, + "Type name must begin with an uppercase letter", + TlbChangeCaseFix(identifier, true) + ) + } + } + + class TlbChangeCaseFix(private val identifier: PsiElement, private val toUppercase: Boolean) : + LocalQuickFixOnPsiElement(identifier) { + override fun getText(): @IntentionName String { + return if (toUppercase) "Change to Uppercase" + else "Change to Lowercase" + } + + override fun invoke( + project: Project, + file: PsiFile, + startElement: PsiElement, + endElement: PsiElement + ) { + val name = identifier.text ?: return + val newName = if (toUppercase) name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } + else name.replaceFirstChar { if (it.isUpperCase()) it.lowercase(Locale.getDefault()) else it.toString() } + identifier.replace(project.tlbPsiFactory.createIdentifier(newName)) + } + + override fun getFamilyName(): @IntentionFamilyName String { + return "Change case" + } + } + + + enum class SymbolCase { + UNDEFINED, + LOWERCASE, + UPPERCASE, + BANG_LOWERCASE + } + + fun determineSymbolCase(input: String): SymbolCase { + var state = SymbolCase.UNDEFINED + var partialUtf8 = 0 + var firstCharSign = 0 + + for (char in input) { + if (char == '.') { + state = SymbolCase.UNDEFINED + partialUtf8 = 0 + firstCharSign = 0 + } else if (state == SymbolCase.UNDEFINED) { + if (firstCharSign == 0) { + firstCharSign = if (char == '!') 1 else -1 + } + if (char.isLetter()) { + state = if (char.isLowerCase()) SymbolCase.LOWERCASE else SymbolCase.UPPERCASE + } else { + if (partialUtf8 != 0 && (char.code and 0xc0) == 0x80) { + partialUtf8 = (partialUtf8 shl 6) or (char.code and 0x3f) + if (partialUtf8 in 0x410 until 0x450) { + state = if (partialUtf8 < 0x430) SymbolCase.UPPERCASE else SymbolCase.LOWERCASE + } + } + partialUtf8 = if ((char.code and 0xe0) == 0xc0) (char.code and 0x1f) else 0 + } + } + } + + if (firstCharSign == 1 && state == SymbolCase.LOWERCASE) { + state = SymbolCase.BANG_LOWERCASE + } + + return state + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/inspection/fix/TlbSetConstructorTagFix.kt b/modules/tlb/src/org/ton/intellij/tlb/inspection/fix/TlbSetConstructorTagFix.kt new file mode 100644 index 0000000..2157ccd --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/inspection/fix/TlbSetConstructorTagFix.kt @@ -0,0 +1,38 @@ +package org.ton.intellij.tlb.inspection.fix + +import com.intellij.codeInspection.LocalQuickFixOnPsiElement +import com.intellij.codeInspection.util.IntentionFamilyName +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import org.ton.intellij.tlb.ConstructorTag +import org.ton.intellij.tlb.psi.TlbConstructor +import org.ton.intellij.tlb.psi.TlbConstructorTag +import org.ton.intellij.tlb.psi.tlbPsiFactory + +class TlbSetConstructorTagFix(constructor: TlbConstructor, private val tag: ConstructorTag) : + LocalQuickFixOnPsiElement(constructor) { + override fun getText(): String = "Set '$tag' constructor tag" + + override fun getFamilyName(): @IntentionFamilyName String = "Set constructor tag" + + override fun invoke( + project: Project, + file: PsiFile, + startElement: PsiElement, + endElement: PsiElement + ) { + startElement as? TlbConstructor ?: return + val constructorTag = project.tlbPsiFactory.createFromText("foo$tag = Foo;") + if (constructorTag == null) { + println("Failed to create constructor tag") + return + } + val currentConstructorTag = startElement.constructorTag + if (currentConstructorTag != null) { + currentConstructorTag.replace(constructorTag) + } else { + startElement.addAfter(constructorTag, startElement.identifier) + } + } +} \ No newline at end of file diff --git a/src/main/grammar/TlbLexer.flex b/modules/tlb/src/org/ton/intellij/tlb/lexer/TlbLexer.flex similarity index 97% rename from src/main/grammar/TlbLexer.flex rename to modules/tlb/src/org/ton/intellij/tlb/lexer/TlbLexer.flex index a92448d..dabf326 100644 --- a/src/main/grammar/TlbLexer.flex +++ b/modules/tlb/src/org/ton/intellij/tlb/lexer/TlbLexer.flex @@ -83,7 +83,7 @@ LINE_COMMENT = "/""/"[^\n]* NUMBER=[0-9]+ IDENTIFIER=[a-zA-Z_][0-9a-zA-Z0-9_]* -PREDIFINED_TYPE=u?int[0-9]+|Cell +//PREDIFINED_TYPE=u?int[0-9]+|Cell %xstate BLOCK_COMMENT_STATE, DOC_COMMENT_STATE @@ -133,8 +133,7 @@ PREDIFINED_TYPE=u?int[0-9]+|Cell {LINE_COMMENT} { return LINE_COMMENT; } {NUMBER} { return NUMBER; } -{PREDIFINED_TYPE} { return PREDIFINED_TYPE; } -{IDENTIFIER} { return IDENTIFIER; } + "+" { return PLUS; } "-" { return MINUS; } @@ -149,6 +148,7 @@ PREDIFINED_TYPE=u?int[0-9]+|Cell "]" { return RBRACKET; } "=" { return EQUALS; } "?" { return QUESTION; } +"!" { return EXCL; } "." { return DOT; } "~" { return TILDE; } "^" { return CIRCUMFLEX; } @@ -167,4 +167,8 @@ PREDIFINED_TYPE=u?int[0-9]+|Cell "#<=" { return NAT_LEQ; } "#" { return TAG; } +"Type" { return TYPE_KEYWORD; } + +{IDENTIFIER} { return IDENTIFIER; } + [^] { return BAD_CHARACTER; } diff --git a/src/main/kotlin/org/ton/intellij/tlb/lexer/TlbLexerAdapter.kt b/modules/tlb/src/org/ton/intellij/tlb/lexer/TlbLexerAdapter.kt similarity index 100% rename from src/main/kotlin/org/ton/intellij/tlb/lexer/TlbLexerAdapter.kt rename to modules/tlb/src/org/ton/intellij/tlb/lexer/TlbLexerAdapter.kt diff --git a/modules/tlb/src/org/ton/intellij/tlb/parser/TlbParser.bnf b/modules/tlb/src/org/ton/intellij/tlb/parser/TlbParser.bnf new file mode 100644 index 0000000..5db2912 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/parser/TlbParser.bnf @@ -0,0 +1,240 @@ +{ + parserClass="org.ton.intellij.tlb.parser.TlbParser" + extends="com.intellij.extapi.psi.ASTWrapperPsiElement" + + psiClassPrefix="Tlb" + psiImplClassSuffix="Impl" + psiPackage="org.ton.intellij.tlb.psi" + psiImplPackage="org.ton.intellij.tlb.psi.impl" + implements="org.ton.intellij.tlb.psi.TlbElement" + + elementTypeHolderClass="org.ton.intellij.tlb.psi.TlbTypes" + elementTypeClass="org.ton.intellij.tlb.psi.TlbElementType" + tokenTypeClass="org.ton.intellij.tlb.psi.TlbTokenType" + + extends(".+Field")=Field + extends(".+TypeExpression")=TypeExpression + + generateTokenAccessors=true + + tokens = [ + HEX_TAG='regexp:#([0-9a-fA-F]+_?|_)' + BINARY_TAG='regexp:\$[01]*_?' + + PLUS='+' + MINUS='-' + TIMES='*' + COLUMN=':' + SEMICOLUMN=';' + LPAREN='(' + RPAREN=')' + LBRACE='{' + RBRACE='}' + LBRACKET='[' + RBRACKET=']' + EQUALS='=' + UNDERSCORE='_' + QUESTION='?' + EXCL='!' + DOT='.' + TILDE='~' + DOUBLE_TAG='##' + TAG='#' + CIRCUMFLEX='^' + DOLLAR='$' + EQ='==' + LESS='<' + GREATER='>' + LEQ='<=' + GEQ='>=' + NEQ='!=' + NAT_LESS='#<' + NAT_LEQ='#<=' + TYPE_KEYWORD='Type' + WHITE_SPACE='regexp:\s+' + COMMENT='regexp:(//.*)' + NUMBER='regexp:[0-9]+' + PREDIFINED_TYPE='PREDIFINED_TYPE' + IDENTIFIER='regexp:[a-zA-Z_][0-9a-zA-Z0-9_]*' + ] +} + +private root ::= Constructor_with_recovery* +private Constructor_with_recovery ::= !(<>) Constructor { + pin=1 + recoverWhile=Constructor_recovery +} +private Constructor_recovery ::= !('!'|IDENTIFIER) + +Constructor ::= ConstructorFullId FieldList ResultType_with_eq ';' { + pin=1 + implements=[ + "org.ton.intellij.tlb.psi.TlbFieldListOwner" + "org.ton.intellij.tlb.psi.TlbNamedElement" + ] + mixin="org.ton.intellij.tlb.psi.impl.TlbConstructorMixin" +} +private ConstructorFullId ::= ('!'? IDENTIFIER) ConstructorTag? { + pin=1 +} +ConstructorTag ::= HEX_TAG | BINARY_TAG + +private ResultType_with_eq ::= '=' ResultType { + pin=1 +} +ResultType ::= IDENTIFIER ParamList { + implements=[ + "org.ton.intellij.tlb.psi.TlbNamedElement" + ] + mixin="org.ton.intellij.tlb.psi.impl.TlbResultTypeMixin" + recoverWhile=ResultType_recovery +} +private ResultType_recovery ::= !(';'|'!') + +ParamList ::= Param* { + recoverWhile=ParamList_recovery +} +private ParamList_recovery ::= !(';'|'!'|IDENTIFIER) +private Param ::= (NegatedTermTypeExpression | TermTypeExpression) !(BINARY_TAG|HEX_TAG|'{'|'[') +NegatedTermTypeExpression ::= '~' TermTypeExpression { + pin = 1 + elementType=NegatedTypeExpression +} + +FieldList ::= Field* { + recoverWhile=FieldList_recovery +} + +private FieldList_recovery ::= !('='|']'|';'|) + +Field ::= ImplicitField | ConstraintField | CommonField + +CommonField ::= FieldName? FieldTypeExpression { + mixin="org.ton.intellij.tlb.psi.impl.TlbCommonFieldMixin" + implements=[ + "org.ton.intellij.tlb.psi.TlbNamedElement" + ] +} +ImplicitField ::= '{' FieldName ('#'|'Type') '}' { + pin = 2 + mixin="org.ton.intellij.tlb.psi.impl.TlbImplicitFieldMixin" + implements=[ + "org.ton.intellij.tlb.psi.TlbNamedElement" + ] +} +ConstraintField ::= '{' ConstraintTypeExpression '}' { + pin=2 +} + +private FieldName ::= IDENTIFIER ':' +TypeExpression ::= AddTypeExpression + | MulTypeExpression + | ApplyTypeExpression + | FieldTypeExpression { + implements=["org.ton.intellij.tlb.psi.TlbSizeOwner"] +} + +private Operator ::= '=' | '<=' | '<' | '>=' | '>' +ConstraintTypeExpression ::= TypeExpression Operator TypeExpression { + rightAssociative=true + mixin="org.ton.intellij.tlb.psi.impl.TlbConstraintTypeExpressionMixin" +} + +AddTypeExpression ::= TypeExpression '+' TypeExpression +MulTypeExpression ::= TypeExpression '*' TypeExpression +ApplyTypeExpression ::= TypeExpression ArgumentList { + mixin="org.ton.intellij.tlb.psi.impl.TlbApplyTypeExpressionMixin" +} +ArgumentList ::= (&('('|IDENTIFIER|NUMBER|'~'|'^'|'[') FieldTypeExpression)+ + +private FieldTypeExpression ::= + CondTypeExpression | + GetBitTypeExpression | + TermTypeExpression + +CondTypeExpression ::= TypeExpression '?' TermTypeExpression +GetBitTypeExpression ::= TypeExpression '.' TermTypeExpression + +private TermTypeExpression ::= + ParenTypeExpression | + IntTypeExpression | + ConstructorTypeExpression | + ReferenceTypeExpression | + NegatedParamTypeExpression | + ParamTypeExpression + +ParenTypeExpression ::= '(' TypeExpression ')' { + pin = 1 +} +IntTypeExpression ::= NUMBER + +ConstructorTypeExpression ::= '[' FieldList ']' { + pin = 1 + implements=[ + "org.ton.intellij.tlb.psi.TlbFieldListOwner" + ] +} +ReferenceTypeExpression ::= '^' TermTypeExpression { + pin = 1 +} +NegatedParamTypeExpression ::= '~' ParamTypeExpression { + pin = 1 + elementType=NegatedTypeExpression +} +ParamTypeExpression ::= IDENTIFIER | '#' | '##' | '#<=' | '#<' { + mixin="org.ton.intellij.tlb.psi.impl.TlbParamTypeExpressionMixin" +} + +fake NegatedTypeExpression ::= '~' TypeExpression { + pin = 1 +} + +//combinator_declaration ::= [ '!' ] constructor [ constructor_prefix ] field_definition_list '=' combinator ';' {pin=2} +// +//constructor ::= ( '_' | constructor_name ) +//constructor_name ::= IDENTIFIER +//constructor_prefix ::= HEX_TAG | BINARY_TAG +//combinator ::= combinator_name type_expression* {pin=1} +//combinator_name ::= IDENTIFIER { +// implements = "org.ton.intellij.tlb.psi.TlbNamedElement" +// mixin = "org.ton.intellij.tlb.psi.TlbNamedElementImpl" +//} +// +//private field_definition_list_recovery ::= !( '=' | ']' ) +//field_definition_list ::= field_definition* {recoverWhile=field_definition_list_recovery} +//field_definition ::= implicit_definition | named_field | cell_ref | paren_expression | expr95 +//implicit_definition ::= '{' ( implicit_field | expression ) '}' {pin=1} +//named_field ::= field_name ':' expr95 {pin=2} +//field_name ::= '_' | IDENTIFIER { +// implements = "org.ton.intellij.tlb.psi.TlbNamedElement" +// mixin = "org.ton.intellij.tlb.psi.TlbNamedElementImpl" +//} +//implicit_field ::= implicit_field_name ':' implicit_field_type {pin=2} +//implicit_field_type ::= '#' | 'Type' +//implicit_field_name ::= IDENTIFIER { +// implements = "org.ton.intellij.tlb.psi.TlbNamedElement" +// mixin = "org.ton.intellij.tlb.psi.TlbNamedElementImpl" +//} +// +//anonymous_constructor ::= '[' field_definition_list ']' {pin=1} +// +//cell_ref ::= '^' type_expression {pin=1} +// +//expression ::= expr10 +//private expr10 ::= expr20 '=' expr20 | expr20 '<=' expr20 | expr20 '<' expr20 | expr20 '>=' expr20 | expr20 '>' expr20 | expr20 +//private expr20 ::= expr30 ( '+' expr30 )* +//private expr30 ::= expr90 ( '*' expr90 )* +//private expr90 ::= expr95+ +//private expr95 ::= expr97 [ cond_type ] +//private cond_type ::= '?' type_expression {pin=1} +//private expr97 ::= type_expression [ '.' type_expression ] +// +//type_expression ::= [ '~' ] ( paren_expression | anonymous_constructor | cell_ref | builtin_type | NUMBER | named_ref ) +//named_ref ::= IDENTIFIER { +// implements = "org.ton.intellij.tlb.psi.TlbNamedElement" +// mixin = "org.ton.intellij.tlb.psi.TlbNamedRefMixin" +//} +//private paren_expression ::= "(" expression ')' {pin=1} +//builtin_type ::= '#<' | '#<=' | '##' | '#' | PREDIFINED_TYPE +//noinspection BnfUnusedRule +private unused_in_bnf ::= LINE_COMMENT | BLOCK_COMMENT | LINE_DOCUMENTATION | BLOCK_DOCUMENTATION diff --git a/src/main/kotlin/org/ton/intellij/tlb/psi/TlbElementType.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/TlbElementType.kt similarity index 90% rename from src/main/kotlin/org/ton/intellij/tlb/psi/TlbElementType.kt rename to modules/tlb/src/org/ton/intellij/tlb/psi/TlbElementType.kt index f3d70fb..873bdfe 100644 --- a/src/main/kotlin/org/ton/intellij/tlb/psi/TlbElementType.kt +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/TlbElementType.kt @@ -3,6 +3,4 @@ package org.ton.intellij.tlb.psi import com.intellij.psi.tree.IElementType import org.ton.intellij.tlb.TlbLanguage -class TlbElementType(debugName: String) : IElementType(debugName, TlbLanguage) { - -} \ No newline at end of file +class TlbElementType(debugName: String) : IElementType(debugName, TlbLanguage) \ No newline at end of file diff --git a/src/main/kotlin/org/ton/intellij/tlb/psi/TlbFile.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/TlbFile.kt similarity index 54% rename from src/main/kotlin/org/ton/intellij/tlb/psi/TlbFile.kt rename to modules/tlb/src/org/ton/intellij/tlb/psi/TlbFile.kt index e996888..f0f17c8 100644 --- a/src/main/kotlin/org/ton/intellij/tlb/psi/TlbFile.kt +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/TlbFile.kt @@ -9,4 +9,14 @@ import org.ton.intellij.tlb.TlbLanguage class TlbFile(viewProvider: FileViewProvider) : PsiFileBase(viewProvider, TlbLanguage), TlbElement { override fun getFileType(): FileType = TlbFileType override fun toString(): String = "TLB" + + fun findResultTypes(name: String): Sequence = sequence { + val constructors = findChildrenByClass(TlbConstructor::class.java) + for (constructor in constructors) { + val resultType = constructor.resultType ?: continue + if (resultType.name == name) { + yield(resultType) + } + } + } } diff --git a/modules/tlb/src/org/ton/intellij/tlb/psi/TlbReference.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/TlbReference.kt new file mode 100644 index 0000000..57032df --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/TlbReference.kt @@ -0,0 +1,89 @@ +package org.ton.intellij.tlb.psi + +import com.intellij.openapi.project.Project +import com.intellij.openapi.util.TextRange +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiElementResolveResult +import com.intellij.psi.PsiReferenceBase +import com.intellij.psi.ResolveResult +import com.intellij.psi.impl.source.resolve.ResolveCache +import com.intellij.psi.util.PsiTreeUtil +import com.intellij.psi.util.parentOfType + +class TlbReference( + val project: Project, + element: TlbParamTypeExpression, + rangeInElement: TextRange, +) : PsiReferenceBase.Poly(element, rangeInElement, false) { + private val resolver = ResolveCache.PolyVariantResolver { t, incompleteCode -> + if (!myElement.isValid) return@PolyVariantResolver ResolveResult.EMPTY_ARRAY + val name = t.element.identifier?.text ?: return@PolyVariantResolver ResolveResult.EMPTY_ARRAY + val results = ArrayList() + + PsiTreeUtil.treeWalkUp(t.element, null) { scope, lastParent -> + if (scope is TlbParamList) { + for (field in scope.parentOfType()?.fieldList?.fieldList.orEmpty()) { + if (field is TlbNamedElement && field.name == name) { + results.add(PsiElementResolveResult(field)) + if (!incompleteCode) { + return@treeWalkUp false + } + } + } + return@treeWalkUp false + } + if (scope is TlbFieldList) { + for (field in scope.fieldList) { + if (field == lastParent) { + return@treeWalkUp false + } + if (field is TlbNamedElement && field.name == name) { + results.add(PsiElementResolveResult(field)) + if (!incompleteCode) { + return@treeWalkUp false + } + } + } + false + } else { + true + } + } + if (results.isNotEmpty()) { + return@PolyVariantResolver results.toTypedArray() + } + + val argumentList = (element.parent as? TlbApplyTypeExpression)?.argumentList?.typeExpressionList ?: emptyList() + + val tlbFile = t.element.containingFile as? TlbFile + tlbFile?.findResultTypes(name)?.forEach { resultType -> + val parameterList = resultType.paramList.typeExpressionList + if (incompleteCode || matchArgumentAndParams(argumentList, parameterList)) { + results.add(PsiElementResolveResult(resultType)) + } + } + + results.toTypedArray() + } + + fun matchArgumentAndParams(args: List, params: List): Boolean { + if (args.size != params.size) return false + return args.zip(params).all { (arg, param) -> + if (arg is TlbIntTypeExpression && param is TlbIntTypeExpression) { + arg.text == param.text + } else { + true + } + } + } + + override fun handleElementRename(newElementName: String): PsiElement { + element.identifier?.replace(project.tlbPsiFactory.createIdentifier(newElementName)) + return element + } + + override fun multiResolve(incompleteCode: Boolean): Array { + return ResolveCache.getInstance(project) + .resolveWithCaching(this, resolver, true, incompleteCode) + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/psi/TlbSizeOwner.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/TlbSizeOwner.kt new file mode 100644 index 0000000..61c009a --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/TlbSizeOwner.kt @@ -0,0 +1,7 @@ +package org.ton.intellij.tlb.psi + +import org.ton.intellij.tlb.TlbSize + +interface TlbSizeOwner : TlbElement { + val tlbSize: TlbSize? get() = null +} \ No newline at end of file diff --git a/src/main/kotlin/org/ton/intellij/tlb/psi/TlbTokenType.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/TlbTokenType.kt similarity index 86% rename from src/main/kotlin/org/ton/intellij/tlb/psi/TlbTokenType.kt rename to modules/tlb/src/org/ton/intellij/tlb/psi/TlbTokenType.kt index 092700d..fb24f42 100644 --- a/src/main/kotlin/org/ton/intellij/tlb/psi/TlbTokenType.kt +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/TlbTokenType.kt @@ -8,8 +8,7 @@ class TlbTokenType(debugName: String) : IElementType(debugName, TlbLanguage) { if (this === other) return true if (javaClass != other?.javaClass) return false other as TlbTokenType - if (index != other.index) return false - return true + return index == other.index } override fun hashCode(): Int = index.toInt() diff --git a/modules/tlb/src/org/ton/intellij/tlb/psi/elements.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/elements.kt new file mode 100644 index 0000000..45f7ed7 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/elements.kt @@ -0,0 +1,92 @@ +package org.ton.intellij.tlb.psi + +import com.intellij.extapi.psi.ASTWrapperPsiElement +import com.intellij.lang.ASTNode +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiNameIdentifierOwner + +interface TlbElement : PsiElement +abstract class TlbElementImpl(node: ASTNode) : ASTWrapperPsiElement(node) + +interface TlbNamedElement : TlbElement, PsiNameIdentifierOwner { + val identifier: PsiElement? + + override fun getNameIdentifier(): PsiElement? = identifier +} + + +abstract class TlbNamedElementImpl(node: ASTNode) : TlbElementImpl(node), TlbNamedElement { + override fun getName(): String? = nameIdentifier?.text + + override fun setName(name: String): PsiElement = apply { + nameIdentifier?.replace(project.tlbPsiFactory.createIdentifier(name)) + } + + override fun getTextOffset(): Int = nameIdentifier?.textOffset ?: super.getTextOffset() +} + +interface TlbFieldListOwner : TlbElement { + val fieldList: TlbFieldList? +} + +//interface TlbNaturalTypeExpression : TlbTypeExpression { +// +//} + +fun TlbTypeExpression.unwrap(): TlbTypeExpression? { + var current: TlbTypeExpression? = this + while (current is TlbParenTypeExpression) { + current = current.typeExpression + } + return current +} + +fun TlbTypeExpression.naturalValue(): Int? { + return when (this) { + is TlbIntTypeExpression -> naturalValue() + is TlbParenTypeExpression -> naturalValue() + else -> null + } +} + +fun TlbTypeExpression.isNatural(): Boolean { + when (val unwrapped = unwrap()) { + is TlbApplyTypeExpression -> return unwrapped.isNatural() + is TlbIntTypeExpression -> return true + is TlbParamTypeExpression -> return unwrapped.isNatural() + else -> { + val naturalValue = unwrapped?.naturalValue() + if (naturalValue == null) { + return false + } + return false + } + } +} + +fun TlbApplyTypeExpression.isNatural(): Boolean { + return typeExpression.isNatural() +} + +fun TlbParamTypeExpression.isNatural(): Boolean { + return doubleTag != null || + natLeq != null || + natLess != null || + tag != null || + (reference?.resolve() as? TlbImplicitField)?.tag != null || + (identifier?.text?.let { + it.startsWith("uint") || it.startsWith("int") + } == true) +} + +fun TlbParenTypeExpression.naturalValue(): Int? { + return unwrap()?.naturalValue() +} + +fun TlbIntTypeExpression.naturalValue(): Int? { + return number.text.toIntOrNull() +} + +fun TlbTypeExpression.isNegated(): Boolean { + return unwrap() is TlbNegatedTypeExpression +} \ No newline at end of file diff --git a/src/main/kotlin/org/ton/intellij/tlb/psi/factory.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/factory.kt similarity index 66% rename from src/main/kotlin/org/ton/intellij/tlb/psi/factory.kt rename to modules/tlb/src/org/ton/intellij/tlb/psi/factory.kt index 4ebe6fe..e4f19f9 100644 --- a/src/main/kotlin/org/ton/intellij/tlb/psi/factory.kt +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/factory.kt @@ -3,16 +3,18 @@ package org.ton.intellij.tlb.psi import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import com.intellij.psi.PsiFileFactory +import com.intellij.psi.util.PsiTreeUtil import org.ton.intellij.tlb.TlbFileType -import org.ton.intellij.util.childOfType val Project.tlbPsiFactory get() = TlbPsiFactory(this) class TlbPsiFactory(val project: Project) { - inline fun createFromText(code: CharSequence): T? = - PsiFileFactory.getInstance(project) + inline fun createFromText(code: CharSequence): T? { + val file = PsiFileFactory.getInstance(project) .createFileFromText("DUMMY.tlb", TlbFileType, code) - .childOfType() - fun createIdentifier(text: String) = createFromText("$text#_ = $text;")!!.identifier + return PsiTreeUtil.findChildrenOfAnyType(file, T::class.java).firstOrNull() + } + + fun createIdentifier(text: String) = createFromText("$text#_ = $text;")!!.identifier } diff --git a/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbApplyTypeExpressionMixin.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbApplyTypeExpressionMixin.kt new file mode 100644 index 0000000..0f9da91 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbApplyTypeExpressionMixin.kt @@ -0,0 +1,36 @@ +package org.ton.intellij.tlb.psi.impl + +import com.intellij.extapi.psi.ASTWrapperPsiElement +import com.intellij.lang.ASTNode +import org.ton.intellij.tlb.TlbSize +import org.ton.intellij.tlb.psi.TlbApplyTypeExpression +import org.ton.intellij.tlb.psi.TlbParamTypeExpression +import org.ton.intellij.tlb.psi.naturalValue +import org.ton.intellij.tlb.psi.unwrap +import kotlin.math.min + +abstract class TlbApplyTypeExpressionMixin(node: ASTNode) : ASTWrapperPsiElement(node), TlbApplyTypeExpression { + override val tlbSize: TlbSize? + get() { + val args = argumentList.typeExpressionList + val type = typeExpression.unwrap() + if (args.size == 1 && type is TlbParamTypeExpression) { + val value = args.first().naturalValue() + if (value != null) { + val size = when(type.text) { + "##", "int", "uint", "bits" -> TlbSize.fixedSize(min(value, 2047)) + "#<=" -> TlbSize.fixedSize(32 - value.countLeadingZeroBits()) + "#<" -> TlbSize.fixedSize( + if (value != 0) 32 - (value - 1).countLeadingZeroBits() else 2047 + ) + else -> null + } + if (size != null) { + return size + } + } + } + // resolve size for types + return null + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbCommonFieldMixin.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbCommonFieldMixin.kt new file mode 100644 index 0000000..3f6152d --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbCommonFieldMixin.kt @@ -0,0 +1,9 @@ +package org.ton.intellij.tlb.psi.impl + +import com.intellij.lang.ASTNode +import org.ton.intellij.tlb.psi.TlbCommonField +import org.ton.intellij.tlb.psi.TlbNamedElementImpl + +abstract class TlbCommonFieldMixin(node: ASTNode) : TlbNamedElementImpl(node), TlbCommonField { + +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbConstraintTypeExpressionMixin.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbConstraintTypeExpressionMixin.kt new file mode 100644 index 0000000..5a8f403 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbConstraintTypeExpressionMixin.kt @@ -0,0 +1,10 @@ +package org.ton.intellij.tlb.psi.impl + +import com.intellij.extapi.psi.ASTWrapperPsiElement +import com.intellij.lang.ASTNode +import org.ton.intellij.tlb.TlbSize +import org.ton.intellij.tlb.psi.TlbConstraintTypeExpression + +abstract class TlbConstraintTypeExpressionMixin(node: ASTNode): ASTWrapperPsiElement(node), TlbConstraintTypeExpression { + override val tlbSize: TlbSize get() = TlbSize.ZERO +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbConstructorMixin.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbConstructorMixin.kt new file mode 100644 index 0000000..7393805 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbConstructorMixin.kt @@ -0,0 +1,20 @@ +package org.ton.intellij.tlb.psi.impl + +import com.intellij.lang.ASTNode +import org.ton.intellij.tlb.psi.TlbCommonField +import org.ton.intellij.tlb.psi.TlbConstructor +import org.ton.intellij.tlb.psi.TlbNamedElementImpl +import org.ton.intellij.tlb.psi.TlbTypeExpression + +abstract class TlbConstructorMixin(node: ASTNode) : TlbNamedElementImpl(node), TlbConstructor { + fun calculateSize(params: Map) { + var size = constructorTag?.binaryTag + fieldList?.fieldList?.forEach { field -> + if (field !is TlbCommonField) return + val tlbSize = field.typeExpression.tlbSize + if (tlbSize != null) { + + } + } + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbImplicitFieldMixin.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbImplicitFieldMixin.kt new file mode 100644 index 0000000..6d98555 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbImplicitFieldMixin.kt @@ -0,0 +1,9 @@ +package org.ton.intellij.tlb.psi.impl + +import com.intellij.lang.ASTNode +import org.ton.intellij.tlb.psi.TlbImplicitField +import org.ton.intellij.tlb.psi.TlbNamedElementImpl + +abstract class TlbImplicitFieldMixin(node: ASTNode) : TlbNamedElementImpl(node), TlbImplicitField { + +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbParamTypeExpressionMixin.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbParamTypeExpressionMixin.kt new file mode 100644 index 0000000..9a48e3a --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbParamTypeExpressionMixin.kt @@ -0,0 +1,13 @@ +package org.ton.intellij.tlb.psi.impl + +import com.intellij.extapi.psi.ASTWrapperPsiElement +import com.intellij.lang.ASTNode +import com.intellij.openapi.util.TextRange +import org.ton.intellij.tlb.psi.TlbParamTypeExpression +import org.ton.intellij.tlb.psi.TlbReference + +abstract class TlbParamTypeExpressionMixin(node: ASTNode) : ASTWrapperPsiElement(node), TlbParamTypeExpression { + override fun getReference(): TlbReference? { + return TlbReference(project,this, TextRange.create(0, textLength)) + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbResultTypeMixin.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbResultTypeMixin.kt new file mode 100644 index 0000000..4378b0e --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/impl/TlbResultTypeMixin.kt @@ -0,0 +1,9 @@ +package org.ton.intellij.tlb.psi.impl + +import com.intellij.lang.ASTNode +import org.ton.intellij.tlb.psi.TlbNamedElementImpl +import org.ton.intellij.tlb.psi.TlbResultType + +abstract class TlbResultTypeMixin(node: ASTNode) : TlbNamedElementImpl(node), TlbResultType { + +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/psi/print.kt b/modules/tlb/src/org/ton/intellij/tlb/psi/print.kt new file mode 100644 index 0000000..758fee2 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/psi/print.kt @@ -0,0 +1,280 @@ +package org.ton.intellij.tlb.psi + + + +fun TlbFieldList.print( + appendable: Appendable, + showBraces: Boolean = true, +) { + fieldList.forEachIndexed { index, field -> + if (index > 0) { + appendable.append(" ") + } + field.print(appendable, showBraces) + } +} + +fun TlbField.print( + appendable: Appendable, + showBraces: Boolean = true, +) { + when (this) { + is TlbImplicitField -> { + if (showBraces) { + appendable.append("{") + } + appendable.append(identifier.text) + appendable.append(":") + when { + typeKeyword != null -> appendable.append("Type") + tag != null -> appendable.append("#") + } + if (showBraces) { + appendable.append("}") + } + } + + is TlbConstraintField -> { + if (showBraces) { + appendable.append("{") + } + typeExpression.print(appendable) + if (showBraces) { + appendable.append("}") + } + } + + is TlbCommonField -> { + val name = identifier?.text + if (name != null) { + appendable.append(name) + appendable.append(":") + } + typeExpression.print(appendable, skipParens = !showBraces) + } + } +} + +fun TlbConstructor.printToString( + skipTag: Boolean = false, + showBraces: Boolean = true, +) = buildString { print(this, skipTag, showBraces) } +fun TlbConstructor.print( + appendable: Appendable, + skipTag: Boolean = false, + implicitBraces: Boolean = true, +) { + appendable.append(name) + if (!skipTag) { + val constructorTag = constructorTag?.text + if (constructorTag == null) { + appendable.append("(invalid-constructor-tag)") + } + appendable.append(constructorTag) + } + val fieldList = fieldList + if (fieldList == null) { + appendable.append("(invalid-constructor-field-list)") + return + } + if (fieldList.fieldList.isNotEmpty()) { + appendable.append(" ") + } + fieldList.print(appendable, implicitBraces) + appendable.append(" = ") + + val resultType = resultType + if (resultType == null) { + appendable.append("(invalid-constructor-result-type)") + return + } + appendable.append(resultType.name) + val params = resultType.paramList.typeExpressionList + params.forEach { + appendable.append(" ") +// if (it is TlbNegatedTypeExpression && it.typeExpression !is TlbIntTypeExpression) { +// appendable.append("~") // TL-B bug? +// } + it.print(appendable, 100, !implicitBraces) + } +} + +fun TlbTypeExpression.print( + appendable: Appendable, + priority: Int = 0, + skipParens: Boolean = false +) { + if (priority > 0 && skipParens) { + return print(appendable, 0, true) + } + when (this) { + is TlbNegatedTypeExpression -> { + appendable.append("~") + this.typeExpression?.print(appendable, priority, skipParens) + } + + is TlbParamTypeExpression -> { + appendable.append(text) + } + + is TlbConstructorTypeExpression -> { + val fieldList = fieldList + if (fieldList == null) { + appendable.append("(invalid-constructor-type-expression)") + return + } + appendable.append("[") + fieldList.print(appendable) + appendable.append("]") + } + + is TlbApplyTypeExpression -> { + val arguments = argumentList.typeExpressionList + val showParens = priority > 90 && arguments.isNotEmpty() + if (showParens) { + appendable.append("(") + } + typeExpression.print(appendable, 91) + arguments.forEachIndexed { index, argument -> + appendable.append(" ") + argument.print(appendable, 91, skipParens) + } + if (showParens) { + appendable.append(")") + } + } + + is TlbAddTypeExpression -> { + val args = typeExpressionList + if (args.size != 2) { + appendable.append("(invalid-add-type-expression)") + return + } + if (priority > 20) { + appendable.append("(") + } + args[0].print(appendable, 20, skipParens) + appendable.append(" + ") + args[1].print(appendable, 21, skipParens) + if (priority > 20) { + appendable.append(")") + } + } + + is TlbGetBitTypeExpression -> { + val args = typeExpressionList + if (args.size != 2) { + appendable.append("(invalid-get-bit-type-expression)") + return + } + if (priority > 97) { + appendable.append("(") + } + args[0].print(appendable, 98, skipParens) + appendable.append(".") + args[1].print(appendable, 98, skipParens) + if (priority > 97) { + appendable.append(")") + } + } + + is TlbConstraintTypeExpression -> { + val operator = children.getOrNull(1) + if (operator == null) { + appendable.append("(invalid-constraint-type-expression)") + return + } + var arguments = typeExpressionList + val showParens = priority > 90 && arguments.isNotEmpty() + if (showParens) { + appendable.append("(") + } + when { + equals != null -> { + appendable.append("=") + } + geq != null -> { + appendable.append("<=") + arguments = arguments.reversed() + } + greater != null -> { + appendable.append("<") + arguments = arguments.reversed() + } + leq != null -> { + appendable.append("<=") + } + less != null -> { + appendable.append("<") + } + else -> "??" + } + arguments.forEachIndexed { index, argument -> + appendable.append(" ") + argument.print(appendable, 0, skipParens) + } + if (showParens) { + appendable.append(")") + } + } + + is TlbIntTypeExpression -> { + appendable.append(text) + } + + is TlbMulTypeExpression -> { + var args = typeExpressionList + if (args.size != 2) { + appendable.append("(invalid-mul-type-expression)") + return + } + if (args[1].unwrap() is TlbIntTypeExpression) { + args = args.reversed() + } + if (priority > 30) { + appendable.append("(") + } + args[0].print(appendable, 30, skipParens) + appendable.append(" * ") + args[1].print(appendable, 31, skipParens) + if (priority > 30) { + appendable.append(")") + } + } + + is TlbCondTypeExpression -> { + val args = typeExpressionList + if (args.size != 2) { + appendable.append("(invalid-cond-type-expression)") + return + } + if (priority > 95) { + appendable.append("(") + } + args[0].print(appendable, 96, skipParens) + appendable.append(" ? ") + args[1].print(appendable, 96, skipParens) + if (priority > 95) { + appendable.append(")") + } + } + + is TlbReferenceTypeExpression -> { + val arg = typeExpression + if (arg == null) { + appendable.append("(invalid-reference-type-expression)") + return + } + appendable.append("^") + arg.print(appendable, 100, skipParens) + } + + is TlbParenTypeExpression -> { + unwrap()?.print(appendable, priority, skipParens) + } + + else -> { + appendable.append("(unknown-type)") + } + } +} \ No newline at end of file diff --git a/modules/tlb/src/org/ton/intellij/tlb/resolve/resolver.kt b/modules/tlb/src/org/ton/intellij/tlb/resolve/resolver.kt new file mode 100644 index 0000000..5dd6b27 --- /dev/null +++ b/modules/tlb/src/org/ton/intellij/tlb/resolve/resolver.kt @@ -0,0 +1,41 @@ +package org.ton.intellij.tlb.resolve + +//fun TlbElement.resolveFile() = if (this is TlbFile) this else containingFile as TlbFile +// +//fun TlbFile.resolveCombinatorDeclarations() = childrenOfType().asSequence() +//fun TlbFile.resolveAllCombinatorDeclarations() = +// virtualFile.parent?.children?.asSequence()?.filter { file -> +// file.extension.equals(TlbFileType.defaultExtension, ignoreCase = true) +// }?.map { file -> +// project.psiManager.findFile(file) as? TlbFile +// }?.filterNotNull()?.flatMap { file -> +// file.resolveCombinatorDeclarations() +// } ?: emptySequence() +// +//fun TlbCombinatorDeclaration.resolveImplicitDefinitions() = +// fieldDefinitionList?.fieldDefinitionList?.asSequence()?.map { +// it.implicitDefinition +// }?.filterNotNull() ?: emptySequence() +// +//fun TlbAnonymousConstructor?.resolveImplicitDefinitions() = +// this?.fieldDefinitionList?.fieldDefinitionList?.asSequence()?.map { +// it.implicitDefinition +// }?.filterNotNull() ?: emptySequence() +// +//fun TlbCombinatorDeclaration.resolveImplicitFields() = resolveImplicitDefinitions().map { +// it.implicitField +//}.filterNotNull() +// +//fun TlbAnonymousConstructor?.resolveImplicitFields() = resolveImplicitDefinitions().map { +// it.implicitField +//}.filterNotNull() +// +//fun TlbCombinatorDeclaration.resolveFields() = +// fieldDefinitionList?.fieldDefinitionList?.asSequence()?.map { +// it.namedField +// }?.filterNotNull() ?: emptySequence() +// +//fun TlbAnonymousConstructor?.resolveFields() = +// this?.fieldDefinitionList?.fieldDefinitionList?.asSequence()?.map { +// it.namedField +// }?.filterNotNull() ?: emptySequence() diff --git a/modules/tlb/test/org/ton/intellij/tlb/PrintTest.kt b/modules/tlb/test/org/ton/intellij/tlb/PrintTest.kt new file mode 100644 index 0000000..aad1104 --- /dev/null +++ b/modules/tlb/test/org/ton/intellij/tlb/PrintTest.kt @@ -0,0 +1,76 @@ +package org.ton.intellij.tlb + +import com.intellij.testFramework.fixtures.BasePlatformTestCase +import org.intellij.lang.annotations.Language +import org.ton.intellij.tlb.psi.TlbConstructor +import org.ton.intellij.tlb.psi.tlbPsiFactory + +class PrintTest : BasePlatformTestCase() { + + fun testTags() { + checkTag("unit\$_ = Unit;", "#1853ad91") + checkTag("true\$_ = True;", "#3fedd339") + checkTag("bool_false\$0 = Bool;", "#e95dd78d") + checkTag("bool_true\$1 = Bool;", "#b814e002") + checkTag("bool_false\$0 = BoolFalse;", "#f3214771") + checkTag("bool_true\$1 = BoolTrue;", "#b5311773") + checkTag("nothing\$0 {X:Type} = Maybe X;", "#db8ec3e2") + checkTag("just\$1 {X:Type} value:X = Maybe X;", "#45eec617") + checkTag("left\$0 {X:Type} {Y:Type} value:X = Either X Y;", "#0a29cd5d") + checkTag("right\$1 {X:Type} {Y:Type} value:Y = Either X Y;", "#df3ecb3b") + checkTag("pair\$_ {X:Type} {Y:Type} first:X second:Y = Both X Y;", "#e03721eb") + checkTag("bit\$_ (## 1) = Bit;", "#12acf7f6") + checkTag("hm_edge#_ {n:#} {X:Type} {l:#} {m:#} label:(HmLabel ~l n) {n = (~m) + l} node:(HashmapNode m X) = Hashmap n X;", "#2002a049") + checkTag("hmn_leaf#_ {X:Type} value:X = HashmapNode 0 X;", "#87f847b7") + checkTag("hmn_fork#_ {n:#} {X:Type} left:^(Hashmap n X) right:^(Hashmap n X) = HashmapNode (n + 1) X;", "#3b92e2d6") +// checkTag("hml_short\$0 {m:#} {n:#} len:(Unary ~n) {n <= m} s:(n * Bit) = HmLabel ~n m;", "#f23b17a1") +// checkTag("hml_long\$10 {m:#} n:(#<= m) s:(n * Bit) = HmLabel ~n m;", "#5d5ff77a") +// checkTag("hml_same\$11 {m:#} v:Bit n:(#<= m) = HmLabel ~n m;", "#1d8307c6") + checkTag("unary_zero\$0 = Unary ~0;", "#aebc9392") +// checkTag("unary_succ\$1 {n:#} x:(Unary ~n) = Unary ~(n + 1);", "#c0e89234") + checkTag("hme_empty\$0 {n:#} {X:Type} = HashmapE n X;", "#40b92161") + checkTag("hme_root\$1 {n:#} {X:Type} root:^(Hashmap n X) = HashmapE n X;", "#1cc05be9") + checkTag("ahm_edge#_ {n:#} {X:Type} {Y:Type} {l:#} {m:#} label:(HmLabel ~l n) {n = (~m) + l} node:(HashmapAugNode m X Y) = HashmapAug n X Y;", "#f92ab7ac") + checkTag("ahmn_leaf#_ {X:Type} {Y:Type} extra:Y value:X = HashmapAugNode 0 X Y;", "#c55ee841") + checkTag("ahmn_fork#_ {n:#} {X:Type} {Y:Type} left:^(HashmapAug n X Y) right:^(HashmapAug n X Y) extra:Y = HashmapAugNode (n + 1) X Y;", "#86a053f1") + checkTag("ahme_empty\$0 {n:#} {X:Type} {Y:Type} extra:Y = HashmapAugE n X Y;", "#af55dae6") + checkTag("ahme_root\$1 {n:#} {X:Type} {Y:Type} root:^(HashmapAug n X Y) extra:Y = HashmapAugE n X Y;", "#e135d248") + checkTag("vhm_edge#_ {n:#} {X:Type} {l:#} {m:#} label:(HmLabel ~l n) {n = (~m) + l} node:(VarHashmapNode m X) = VarHashmap n X;", "#a6983b07") + checkTag("vhmn_leaf\$00 {n:#} {X:Type} value:X = VarHashmapNode n X;", "#a0bd0298") + checkTag("vhmn_fork\$01 {n:#} {X:Type} left:^(VarHashmap n X) right:^(VarHashmap n X) value:(Maybe X) = VarHashmapNode (n + 1) X;", "#0f725d4b") + checkTag("vhmn_cont\$1 {n:#} {X:Type} branch:Bit child:^(VarHashmap n X) value:X = VarHashmapNode (n + 1) X;", "#4b086da5") + checkTag("vhme_empty\$0 {n:#} {X:Type} = VarHashmapE n X;", "#98c3d231") + checkTag("vhme_root\$1 {n:#} {X:Type} root:^(VarHashmap n X) = VarHashmapE n X;", "#76fc36fa") + checkTag("phm_edge#_ {n:#} {X:Type} {l:#} {m:#} label:(HmLabel ~l n) {n = (~m) + l} node:(PfxHashmapNode m X) = PfxHashmap n X;", "#5eaa8af5") + checkTag("phmn_leaf\$0 {n:#} {X:Type} value:X = PfxHashmapNode n X;", "#efd29692") + checkTag("phmn_fork\$1 {n:#} {X:Type} left:^(PfxHashmap n X) right:^(PfxHashmap n X) = PfxHashmapNode (n + 1) X;", "#31cbadd5") + checkTag("phme_empty\$0 {n:#} {X:Type} = PfxHashmapE n X;", "#99ecf592") + checkTag("phme_root\$1 {n:#} {X:Type} root:^(PfxHashmap n X) = PfxHashmapE n X;", "#86026190") + + checkTag("addr_none\$00 = MsgAddressExt;", "#9ccb7139") + checkTag("addr_extern\$01 len:(## 9) external_address:(bits len) = MsgAddressExt;", "#ee7b72a3") + checkTag("anycast_info\$_ depth:(#<= 30) { depth >= 1 } rewrite_pfx:(bits depth) = Anycast;", "#9843f64b") + checkTag("addr_std\$10 anycast:(Maybe Anycast) workchain_id:int8 address:bits256 = MsgAddressInt;", "#ca70d9f6") + checkTag("addr_var\$11 anycast:(Maybe Anycast) addr_len:(## 9) workchain_id:int32 address:(bits addr_len) = MsgAddressInt;", "#9bb90082") + checkTag("var_uint\$_ {n:#} len:(#< n) value:(uint (len * 8)) = VarUInteger n;", "#988e36b3") + checkTag("var_int\$_ {n:#} len:(#< n) value:(int (len * 8)) = VarInteger n;", "#225aaee0") + checkTag("nanograms\$_ amount:(VarUInteger 16) = Grams;", "#31468450") + checkTag("extra_currencies\$_ dict:(HashmapE 32 (VarUInteger 32)) = ExtraCurrencyCollection;", "#99662f55") + checkTag("currencies\$_ grams:Grams other:ExtraCurrencyCollection = CurrencyCollection;", "#54dfb0fb") + } + + private fun checkTag( + @Language("TLB") + text: String, + expected: String + ) { + val constructor = createConstructor(text) + val tag = constructor.computeTag() + assertEquals(expected, tag.toString()) + } + + private fun createConstructor( + @Language("TLB") + text: String + ) = project.tlbPsiFactory.createFromText(text)!! +} \ No newline at end of file diff --git a/modules/tlb/test/org/ton/intellij/tlb/parser_test_cases.md b/modules/tlb/test/org/ton/intellij/tlb/parser_test_cases.md new file mode 100644 index 0000000..22590ab --- /dev/null +++ b/modules/tlb/test/org/ton/intellij/tlb/parser_test_cases.md @@ -0,0 +1,5 @@ +``` +error: multiplication allowed only by constant values +var_uint {n:#} len:(#< n) value:(uint (len * (8 + 3))) + ^ +``` \ No newline at end of file diff --git a/modules/tlb/testResources/META-INF/plugin.xml b/modules/tlb/testResources/META-INF/plugin.xml new file mode 100644 index 0000000..1d5d34b --- /dev/null +++ b/modules/tlb/testResources/META-INF/plugin.xml @@ -0,0 +1,4 @@ + + org.ton.intellij-ton.tlb + + diff --git a/modules/tolk/build.gradle.kts b/modules/tolk/build.gradle.kts new file mode 100644 index 0000000..e2d0c3d --- /dev/null +++ b/modules/tolk/build.gradle.kts @@ -0,0 +1,44 @@ +import org.jetbrains.grammarkit.tasks.GenerateLexerTask +import org.jetbrains.grammarkit.tasks.GenerateParserTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.jetbrains.intellij.platform.module") + id("org.jetbrains.grammarkit") +} + +dependencies { + intellijPlatform { + val version = providers.gradleProperty("platformVersion") + intellijIdeaCommunity(version) + bundledPlugin("com.intellij.dev") + } + compileOnly(project(":asm")) + compileOnly(project(":util")) +} + +val generateTolkParser = task("generateTolkParser") { + sourceFile.set(file("src/org/ton/intellij/tolk/parser/TolkParser.bnf")) + targetRootOutputDir.set(file("gen")) + pathToParser.set("/org/ton/intellij/tolk/parser/TolkParser.java") + pathToPsiRoot.set("/org/ton/intellij/tolk/psi") + purgeOldFiles.set(true) + + dependsOn(":util:composedJar") +} + +val generateTolkLexer = task("generateTolkLexer") { + val input = "src/org/ton/intellij/tolk/lexer/TolkLexer.flex" + val output = "gen/org/ton/intellij/tolk/lexer" + sourceFile.set(file(input)) + targetOutputDir.set(file(output)) + purgeOldFiles.set(true) +} + +tasks.withType().configureEach { + dependsOn(generateTolkParser, generateTolkLexer) +} + +tasks.withType().configureEach { + dependsOn(generateTolkParser, generateTolkLexer) +} diff --git a/src/main/resources/META-INF/tolk.xml b/modules/tolk/resources/META-INF/tolk.xml similarity index 72% rename from src/main/resources/META-INF/tolk.xml rename to modules/tolk/resources/META-INF/tolk.xml index e67f926..3656805 100644 --- a/src/main/resources/META-INF/tolk.xml +++ b/modules/tolk/resources/META-INF/tolk.xml @@ -16,14 +16,16 @@ + - + + @@ -36,6 +38,7 @@ + @@ -47,20 +50,46 @@