<commit_before>/*
 * Copyright (c) 2017. tangzx(<EMAIL>)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.tang.intellij.lua.ty

import com.intellij.psi.stubs.StubInputStream
import com.intellij.psi.stubs.StubOutputStream
import com.intellij.util.io.StringRef
import com.tang.intellij.lua.psi.LuaParamInfo

enum class TyKind {
    Unknown,
    Primitive,
    Array,
    Function,
    Class,
    Union,
    Generic
}
enum class TyPrimitiveKind {
    String,
    Number,
    Boolean
}

interface ITy {

    val isAnonymous: Boolean

    val kind: TyKind

    val displayName: String

    fun union(ty: ITy): ITy

    fun createTypeString(): String

    fun createReturnString(): String
}

abstract class Ty(override val kind: TyKind) : ITy {

    override val isAnonymous: Boolean = false

    override fun union(ty: ITy): ITy {
        return TyUnion.union(this, ty)
    }

    override fun createTypeString(): String {
        val s = toString()
        return if (s.isEmpty()) "any" else s
    }

    override fun createReturnString(): String {
        val s = toString()
        return if (s.isEmpty()) "void" else s
    }

    override fun toString(): String {
        val list = mutableListOf<String>()
        TyUnion.each(this) {
            list.add(it.displayName)
        }
        return list.joinToString("|")
    }

    companion object {

        val UNKNOWN = TyUnknown()
        val BOOLEAN = TyPrimitive(TyPrimitiveKind.Boolean, "boolean")
        val STRING = TyPrimitive(TyPrimitiveKind.String, "string")
        val NUMBER = TyPrimitive(TyPrimitiveKind.Number, "number")<commit_msg>flags<commit_after>/*
 * Copyright (c) 2017. tangzx(<EMAIL>)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.tang.intellij.lua.ty

import com.intellij.psi.stubs.StubInputStream
import com.intellij.psi.stubs.StubOutputStream
import com.intellij.util.io.StringRef
import com.tang.intellij.lua.psi.LuaParamInfo

enum class TyKind {
    Unknown,
    Primitive,
    Array,
    Function,
    Class,
    Union,
    Generic
}
enum class TyPrimitiveKind {
    String,
    Number,
    Boolean
}

interface ITy {

    val isAnonymous: Boolean

    val kind: TyKind

    val displayName: String

    val flags: Int

    fun union(ty: ITy): ITy

    fun createTypeString(): String

    fun createReturnString(): String

    fun isFlag(flag: Int): Boolean
}

abstract class Ty(override val kind: TyKind) : ITy {

    override var flags: Int = 0

    override val isAnonymous: Boolean = false

    override fun isFlag(flag: Int): Boolean = flags and flag == flag

    fun writeFlag(flag: Int) {
        flags = flags or flag
    }

    override fun union(ty: ITy): ITy {
        return TyUnion.union(this, ty)
    }

    override fun createTypeString(): String {
        val s = toString()
        return if (s.isEmpty()) "any" else s
    }

    override fun createReturnString(): String {
        val s = toString()
        return if (s.isEmpty()) "void" else s
    }

    override fun toString(): String {
        val list = mutableListOf<String>()
        TyUnion.each(this) {
            list.add(it.displayName)
        }
        return list.joinToString("|")
    }

    companion object {

        val UNKNOWN = TyUnknown()
        val BOOLEAN = TyPrimitive(TyPrimitiveKind.Boolean, "boolean")
        val STRING = TyPrimitive(TyPrimitiveKind.String, "string")
        val NUMBER = TyPrimitive(TyPrimitiveKind.Number, "number")
{'fraction_non_alphanumeric': 0.09231458660094106, 'fraction_numerical': 0.003809097019941743, 'mean_word_length': 2.86159169550173, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2392253', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1291, 'n_words': 435}