translator: refactor the use of the filter extension
This commit is contained in:
@@ -23,8 +23,8 @@ class ProjectTranslator(val files: List<KtFile>,
|
||||
|
||||
fun addFunctionDeclarations(file: KtFile) {
|
||||
val variableManager = VariableManager(state.globalVariableCollection)
|
||||
for (declaration in file.declarations.filter { it is KtNamedFunction }) {
|
||||
val function = FunctionCodegen(state, variableManager, declaration as KtNamedFunction, codeBuilder)
|
||||
for (declaration in file.declarations.filterIsInstance<KtNamedFunction>()) {
|
||||
val function = FunctionCodegen(state, variableManager, declaration, codeBuilder)
|
||||
if (function.external) {
|
||||
state.externalFunctions.put(function.fullName, function)
|
||||
} else {
|
||||
@@ -35,24 +35,24 @@ class ProjectTranslator(val files: List<KtFile>,
|
||||
|
||||
fun addClassDeclarations(file: KtFile) {
|
||||
val variableManager = VariableManager(state.globalVariableCollection)
|
||||
for (declaration in file.declarations.filter { it is KtClass }) {
|
||||
val codegen = ClassCodegen(state, variableManager, declaration as KtClass, codeBuilder)
|
||||
for (declaration in file.declarations.filterIsInstance<KtClass>()) {
|
||||
val codegen = ClassCodegen(state, variableManager, declaration, codeBuilder)
|
||||
state.classes.put(codegen.structName, codegen)
|
||||
}
|
||||
}
|
||||
|
||||
fun addPropertyDeclarations(file: KtFile) {
|
||||
val variableManager = VariableManager(state.globalVariableCollection)
|
||||
for (declaration in file.declarations.filter { it is KtProperty }) {
|
||||
val property = PropertyCodegen(state, variableManager, declaration as KtProperty, codeBuilder)
|
||||
for (declaration in file.declarations.filterIsInstance<KtProperty>()) {
|
||||
val property = PropertyCodegen(state, variableManager, declaration, codeBuilder)
|
||||
state.properties.put(declaration.name!!, property)
|
||||
}
|
||||
}
|
||||
|
||||
fun addObjectDeclarations(file: KtFile) {
|
||||
val variableManager = VariableManager(state.globalVariableCollection)
|
||||
for (declaration in file.declarations.filter { it is KtObjectDeclaration }) {
|
||||
val codegen = ObjectCodegen(state, variableManager, declaration as KtObjectDeclaration, codeBuilder)
|
||||
for (declaration in file.declarations.filterIsInstance<KtObjectDeclaration>()) {
|
||||
val codegen = ObjectCodegen(state, variableManager, declaration, codeBuilder)
|
||||
state.objects.put(codegen.structName, codegen)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ abstract class StructCodegen(val state: TranslationState,
|
||||
|
||||
open fun prepareForGenerate() {
|
||||
generateStruct()
|
||||
classOrObject.declarations.filter { it is KtNamedFunction }.map {
|
||||
val function = FunctionCodegen(state, variableManager, it as KtNamedFunction, codeBuilder)
|
||||
classOrObject.declarations.filterIsInstance<KtNamedFunction>().map {
|
||||
val function = FunctionCodegen(state, variableManager, it, codeBuilder)
|
||||
methods.put(function.name, function)
|
||||
}
|
||||
}
|
||||
@@ -104,11 +104,11 @@ abstract class StructCodegen(val state: TranslationState,
|
||||
}
|
||||
|
||||
private fun generateEnumFields() {
|
||||
val enumEntries = classOrObject.declarations.filter { it is KtEnumEntry }
|
||||
val enumEntries = classOrObject.declarations.filterIsInstance<KtEnumEntry>()
|
||||
|
||||
for (declaration in enumEntries) {
|
||||
val name = declaration.name!!
|
||||
val initializer = (declaration as KtEnumEntry).initializerList!!.initializers[0]
|
||||
val initializer = declaration.initializerList!!.initializers[0]
|
||||
val arguments = (initializer as KtSuperTypeCallEntry).valueArguments.map { it.getArgumentExpression()!!.text }
|
||||
|
||||
val field = codeBuilder.getNewVariable(type, scope = LLVMVariableScope())
|
||||
|
||||
Reference in New Issue
Block a user