@@ -937,18 +937,30 @@ class X {
937937 return id
938938 }
939939
940- fun getPropertyLabel (p : IrProperty ) : String {
940+ fun getFieldLabel (p : IrField ) : String {
941941 val parentId = useDeclarationParent(p.parent)
942942 val label = " @\" field;{$parentId };${p.name.asString()} \" "
943943 return label
944944 }
945945
946- fun useProperty (p : IrProperty ): Label <out DbField > {
947- var label = getPropertyLabel (p)
946+ fun useField (p : IrField ): Label <out DbField > {
947+ var label = getFieldLabel (p)
948948 val id: Label <DbField > = tw.getLabelFor(label)
949949 return id
950950 }
951951
952+ fun getPropertyLabel (p : IrProperty ) : String {
953+ val parentId = useDeclarationParent(p.parent)
954+ val label = " @\" property;{$parentId };${p.name.asString()} \" "
955+ return label
956+ }
957+
958+ fun useProperty (p : IrProperty ): Label <out DbKt_property > {
959+ var label = getPropertyLabel(p)
960+ val id: Label <DbKt_property > = tw.getLabelFor(label)
961+ return id
962+ }
963+
952964 private fun getEnumEntryLabel (ee : IrEnumEntry ) : String {
953965 val parentId = useDeclarationParent(ee.parent)
954966 val label = " @\" field;{$parentId };${ee.name.asString()} \" "
@@ -1216,12 +1228,15 @@ open class KotlinFileExtractor(
12161228 tw.writeExprs_assignexpr(assignmentId, type.javaResult.id, type.kotlinResult.id, stmtId, 0 )
12171229 tw.writeHasLocation(assignmentId, declLocId)
12181230
1231+ /*
1232+ TODO
12191233 val lhsId = tw.getFreshIdLabel<DbVaraccess>()
12201234 val lhsType = useType(backingField.type)
12211235 tw.writeExprs_varaccess(lhsId, lhsType.javaResult.id, lhsType.kotlinResult.id, assignmentId, 0)
12221236 tw.writeHasLocation(lhsId, declLocId)
12231237 val vId = useProperty(decl) // todo: fix this. We should be assigning the field, and not the property
12241238 tw.writeVariableBinding(lhsId, vId)
1239+ */
12251240
12261241 extractExpressionExpr(initializer.expression, obinitId, assignmentId, 1 )
12271242 }
@@ -1239,7 +1254,7 @@ open class KotlinFileExtractor(
12391254 }
12401255 }
12411256
1242- fun extractFunction (f : IrFunction , parentId : Label <out DbReftype >) {
1257+ fun extractFunction (f : IrFunction , parentId : Label <out DbReftype >): Label < out DbCallable > {
12431258 currentFunction = f
12441259
12451260 f.typeParameters.map { extractTypeParameter(it) }
@@ -1274,24 +1289,57 @@ open class KotlinFileExtractor(
12741289 }
12751290
12761291 currentFunction = null
1292+ return id
1293+ }
1294+
1295+ fun extractField (f : IrField , parentId : Label <out DbReftype >): Label <out DbField > {
1296+ val id = useField(f)
1297+ val locId = tw.getLocation(f)
1298+ val type = useType(f.type)
1299+ tw.writeFields(id, f.name.asString(), type.javaResult.id, type.kotlinResult.id, parentId, id)
1300+ tw.writeHasLocation(id, locId)
1301+ return id
12771302 }
12781303
12791304 fun extractProperty (p : IrProperty , parentId : Label <out DbReftype >) {
1305+ val id = useProperty(p)
1306+ val locId = tw.getLocation(p)
1307+ tw.writeKtProperties(id, p.name.asString())
1308+ tw.writeHasLocation(id, locId)
1309+
12801310 val bf = p.backingField
1281- if (bf == null ) {
1282- logger.warnElement(Severity .ErrorSevere , " IrProperty without backing field" , p)
1311+ val getter = p.getter
1312+ val setter = p.setter
1313+
1314+ if (getter != null ) {
1315+ @Suppress(" UNCHECKED_CAST" )
1316+ val getterId = extractFunction(getter, parentId) as Label <out DbMethod >
1317+ tw.writeKtPropertyGetters(id, getterId)
12831318 } else {
1284- val id = useProperty(p)
1285- val locId = tw.getLocation(p)
1286- val type = useType(bf.type)
1287- tw.writeFields(id, p.name.asString(), type.javaResult.id, type.kotlinResult.id, parentId, id)
1288- tw.writeHasLocation(id, locId)
1319+ logger.warnElement(Severity .ErrorSevere , " IrProperty without a getter" , p)
1320+ }
1321+
1322+ if (setter != null ) {
1323+ if (! p.isVar) {
1324+ logger.warnElement(Severity .ErrorSevere , " !isVar property with a setter" , p)
1325+ }
1326+ @Suppress(" UNCHECKED_CAST" )
1327+ val setterId = extractFunction(setter, parentId) as Label <out DbMethod >
1328+ tw.writeKtPropertySetters(id, setterId)
1329+ } else {
1330+ if (p.isVar) {
1331+ logger.warnElement(Severity .ErrorSevere , " isVar property without a setter" , p)
1332+ }
1333+ }
1334+
1335+ if (bf != null ) {
1336+ val fieldId = extractField(bf, parentId)
1337+ tw.writeKtPropertyBackingFields(id, fieldId)
12891338 }
12901339 }
12911340
12921341 fun extractEnumEntry (ee : IrEnumEntry , parentId : Label <out DbReftype >) {
12931342 val id = useEnumEntry(ee)
1294- val locId = tw.getLocation(ee)
12951343 val parent = ee.parent
12961344 if (parent !is IrClass ) {
12971345 logger.warnElement(Severity .ErrorSevere , " Enum entry with unexpected parent: " + parent.javaClass, ee)
@@ -1300,6 +1348,7 @@ open class KotlinFileExtractor(
13001348 } else {
13011349 val type = useSimpleTypeClass(parent, emptyList(), false )
13021350 tw.writeFields(id, ee.name.asString(), type.javaResult.id, type.kotlinResult.id, parentId, id)
1351+ val locId = tw.getLocation(ee)
13031352 tw.writeHasLocation(id, locId)
13041353 }
13051354 }
0 commit comments