Kotlin: Tweak generator

This commit is contained in:
Ian Lynagh
2021-07-28 12:05:42 +01:00
parent d28059a1c0
commit 4e27da33e4
2 changed files with 7 additions and 7 deletions

View File

@@ -50,7 +50,7 @@ with open('src/main/kotlin/KotlinExtractorDbScheme.kt', 'w') as kt:
flags=re.DOTALL):
for db_type in re.findall(':\s*@([^\s,]+)\s*(?:,|$)', body):
type_hierarchy[db_type] = type_hierarchy.get(db_type, set())
kt.write('fun write' + upperFirst(relname) + '(data: TrapWriter, ')
kt.write('fun TrapWriter.write' + upperFirst(relname) + '(')
for colname, db_type in re.findall('(\S+)\s*:\s*([^\s,]+)', body):
kt.write(colname + ': ')
if db_type == 'int':
@@ -70,7 +70,7 @@ with open('src/main/kotlin/KotlinExtractorDbScheme.kt', 'w') as kt:
raise Exception('Bad db_type: ' + db_type)
kt.write(', ')
kt.write(') {\n')
kt.write(' data.writeTrap("' + relname + '(')
kt.write(' this.writeTrap("' + relname + '(')
comma = ''
for colname, db_type in re.findall('(\S+)\s*:\s*([^\s,]+)', body):
kt.write(comma)

View File

@@ -76,7 +76,7 @@ class FileTrapWriter(
val id: Label<DbLocation_default> = getFreshId()
val fileId: Label<DbFile> = getIdFor(fileLabel)
writeTrap("$id = @\"loc,{$fileId},$startLine,$startColumn,$endLine,$endColumn\"\n")
writeLocations_default(this, id, fileId, startLine, startColumn, endLine, endColumn)
writeLocations_default(id, fileId, startLine, startColumn, endLine, endColumn)
return id
}
val labelMapping: MutableMap<String, Label<*>> = mutableMapOf<String, Label<*>>()
@@ -110,10 +110,10 @@ class KotlinExtractorVisitor(val trapDir: File, val srcDir: File) : IrElementVis
val pkg = declaration.packageFqName?.asString() ?: ""
val cls = declaration.name.asString()
data.writeTrap("$pkgId = @\"pkg;$pkg\"\n")
writePackages(data, pkgId, pkg)
data.writePackages(pkgId, pkg)
data.writeTrap("$id = @\"class;$pkg.$cls\"\n")
writeClasses(data, id, cls, pkgId, id)
writeHasLocation(data, id, locId)
data.writeClasses(id, cls, pkgId, id)
data.writeHasLocation(id, locId)
declaration.acceptChildren(this, data)
}
override fun visitFile(declaration: IrFile, data: TrapWriter) {
@@ -134,7 +134,7 @@ class KotlinExtractorVisitor(val trapDir: File, val srcDir: File) : IrElementVis
val tw = FileTrapWriter(fileLabel, trapFileBW, declaration.fileEntry)
val id: Label<DbFile> = tw.getIdFor(fileLabel)
tw.writeTrap("$id = $fileLabel\n")
writeFiles(tw, id, filePath, basename, extension, 0)
tw.writeFiles(id, filePath, basename, extension, 0)
declaration.acceptChildren(this, tw)
}
}