common: unused marker for marking values as unused intentionally

This commit is contained in:
Alex Zenla 2023-09-23 16:30:00 -07:00
parent 4ae1d19012
commit 87623505c0
Signed by: alex
GPG Key ID: C0780728420EBFE5
4 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,9 @@
package gay.pizza.pork.common
@Suppress("NOTHING_TO_INLINE", "UnusedReceiverParameter", "unused")
inline fun Any?.markIsUnused() {}
@Suppress("NOTHING_TO_INLINE", "unused")
inline fun unused(value: Any?) {
value.markIsUnused()
}

View File

@ -1,6 +1,7 @@
package gay.pizza.pork.evaluator
import gay.pizza.pork.ast.ArgumentSpec
import gay.pizza.pork.common.unused
class InternalNativeProvider(val quiet: Boolean = false) : NativeProvider {
private val functions = mutableMapOf(
@ -16,18 +17,21 @@ class InternalNativeProvider(val quiet: Boolean = false) : NativeProvider {
}
private fun printValues(arguments: ArgumentList, stack: CallStack): Any {
unused(stack)
if (quiet || arguments.isEmpty()) return None
print(arguments.joinToString(" "))
return None
}
private fun printLine(arguments: ArgumentList, stack: CallStack): Any {
unused(stack)
if (quiet) return None
println(arguments.joinToString(" "))
return None
}
private fun setInList(arguments: ArgumentList, stack: CallStack): Any {
unused(stack)
@Suppress("UNCHECKED_CAST")
val list = arguments[0] as MutableList<Any>
val value = arguments[2]
@ -36,6 +40,7 @@ class InternalNativeProvider(val quiet: Boolean = false) : NativeProvider {
}
private fun listInitWith(arguments: ArgumentList, stack: CallStack): Any {
unused(stack)
val size = (arguments[0] as Number).toInt()
return MutableList(size) { arguments[1] }
}

View File

@ -7,6 +7,7 @@ plugins {
}
dependencies {
implementation(project(":common"))
implementation(project(":parser"))
}

View File

@ -10,6 +10,7 @@ import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.childrenOfType
import com.intellij.util.PlatformIcons
import gay.pizza.pork.ast.NodeType
import gay.pizza.pork.common.unused
import gay.pizza.pork.idea.PorkElementTypes
import gay.pizza.pork.idea.PorkLanguage
import gay.pizza.pork.idea.psi.gen.*
@ -44,6 +45,7 @@ object PorkElementHelpers {
}
fun referenceOfElement(element: PorkElement, type: NodeType): PsiReference? {
unused(type)
val textRangeOfSymbolInElement = element.childrenOfType<SymbolElement>().firstOrNull()?.textRangeInParent ?: return null
return PorkIdentifierReference(element, textRangeOfSymbolInElement)
}