@@ -217,6 +217,47 @@ private fun KotlinFileExtractor.extractNull(
217
217
extractExprContext(it, locId, callable, enclosingStmt)
218
218
}
219
219
220
+ private fun KotlinFileExtractor.extractConstantInteger (
221
+ t : KaType ,
222
+ text : String ,
223
+ v : Number ,
224
+ locId : Label <DbLocation >,
225
+ parent : Label <out DbExprparent >,
226
+ idx : Int ,
227
+ callable : Label <out DbCallable >? ,
228
+ enclosingStmt : Label <out DbStmt >? ,
229
+ /*
230
+ OLD: KE1
231
+ overrideId: Label<out DbExpr>? = null
232
+ */
233
+ ) =
234
+ extractConstant(tw::writeExprs_integerliteral, t, text, v.toString(), locId, parent, idx, callable, enclosingStmt)
235
+
236
+ @Suppress(" UNCHECKED_CAST" )
237
+ private fun <T : DbExpr > KotlinFileExtractor.extractConstant (
238
+ write : (Label <out T >, Label <out DbType >, Label <out DbExprparent >, Int ) -> Unit ,
239
+ t : KaType ,
240
+ textName : String ,
241
+ textValue : String ,
242
+ locId : Label <DbLocation >,
243
+ parent : Label <out DbExprparent >,
244
+ idx : Int ,
245
+ callable : Label <out DbCallable >? ,
246
+ enclosingStmt : Label <out DbStmt >? ,
247
+ /*
248
+ OLD: KE1
249
+ overrideId: Label<out DbExpr>? = null
250
+ */
251
+ ) =
252
+ // OLD: KE1: Was: exprIdOrFresh<DbIntegerliteral>(overrideId).also {
253
+ tw.getFreshIdLabel<T >().also {
254
+ val type = useType(t)
255
+ write(it, type.javaResult.id, parent, idx)
256
+ tw.writeExprsKotlinType(it, type.kotlinResult.id)
257
+ tw.writeNamestrings(textName, textValue, it as Label <out DbNamedexprorstmt >)
258
+ extractExprContext(it, locId, callable, enclosingStmt)
259
+ }
260
+
220
261
/*
221
262
OLD: KE1
222
263
private fun extractAssignExpr(
@@ -436,8 +477,8 @@ private fun KotlinFileExtractor.extractBinaryExpression(
436
477
)
437
478
438
479
extractConstantInteger(
439
- " 0" ,
440
480
builtinTypes.int,
481
+ " 0" ,
441
482
0 ,
442
483
tw.getLocation(expression),
443
484
id,
@@ -1912,16 +1953,65 @@ private fun KotlinFileExtractor.extractConstant(
1912
1953
if (t == null ) {
1913
1954
TODO ()
1914
1955
}
1915
- when (elementType) {
1916
- KtNodeTypes .NULL -> {
1917
- return extractNull(
1956
+ return when (elementType) {
1957
+ KtNodeTypes .NULL -> extractNull(
1958
+ t,
1959
+ tw.getLocation(e),
1960
+ parent,
1961
+ idx,
1962
+ enclosingCallable,
1963
+ enclosingStmt,
1964
+ // OLD: KE1: overrideId = overrideId
1965
+ )
1966
+
1967
+ KtNodeTypes .BOOLEAN_CONSTANT -> extractConstant(
1968
+ tw::writeExprs_booleanliteral,
1969
+ t,
1970
+ text,
1971
+ text,
1972
+ tw.getLocation(e),
1973
+ parent,
1974
+ idx,
1975
+ enclosingCallable,
1976
+ enclosingStmt
1977
+ )
1978
+
1979
+ KtNodeTypes .CHARACTER_CONSTANT -> extractConstant(
1980
+ tw::writeExprs_characterliteral,
1981
+ t,
1982
+ text,
1983
+ text,
1984
+ tw.getLocation(e),
1985
+ parent,
1986
+ idx,
1987
+ enclosingCallable,
1988
+ enclosingStmt
1989
+ )
1990
+
1991
+
1992
+ KtNodeTypes .FLOAT_CONSTANT -> {
1993
+ val f = parseNumericLiteral(text, elementType)
1994
+
1995
+ if (f == null ) {
1996
+ TODO ()
1997
+ }
1998
+
1999
+ val trapWriterWriteExpr = when {
2000
+ t.isFloatType -> tw::writeExprs_floatingpointliteral
2001
+ t.isDoubleType -> tw::writeExprs_doubleliteral
2002
+ else -> TODO ()
2003
+ }
2004
+
2005
+ return extractConstant(
2006
+ trapWriterWriteExpr,
1918
2007
t,
2008
+ f.toString(),
2009
+ f.toString(),
1919
2010
tw.getLocation(e),
1920
2011
parent,
1921
2012
idx,
1922
2013
enclosingCallable,
1923
- enclosingStmt,
1924
- // OLD: KE1: overrideId = overrideId
2014
+ enclosingStmt
1925
2015
)
1926
2016
}
1927
2017
@@ -1933,11 +2023,10 @@ private fun KotlinFileExtractor.extractConstant(
1933
2023
TODO ()
1934
2024
}
1935
2025
1936
-
1937
2026
t.isIntType || t.isShortType || t.isByteType -> {
1938
2027
return extractConstantInteger(
1939
- text,
1940
2028
t,
2029
+ text,
1941
2030
i,
1942
2031
tw.getLocation(e),
1943
2032
parent,
@@ -1952,15 +2041,17 @@ private fun KotlinFileExtractor.extractConstant(
1952
2041
}
1953
2042
1954
2043
t.isLongType -> {
1955
- // OLD: KE1: Was: exprIdOrFresh<DbLongliteral>(overrideId).also { id ->
1956
- return tw.getFreshIdLabel<DbLongliteral >().also { id ->
1957
- val type = useType(t)
1958
- val locId = tw.getLocation(e)
1959
- tw.writeExprs_longliteral(id, type.javaResult.id, parent, idx)
1960
- tw.writeExprsKotlinType(id, type.kotlinResult.id)
1961
- extractExprContext(id, locId, enclosingCallable, enclosingStmt)
1962
- tw.writeNamestrings(text, i.toString(), id)
1963
- }
2044
+ return extractConstant(
2045
+ tw::writeExprs_longliteral,
2046
+ t,
2047
+ text,
2048
+ i.toString(),
2049
+ tw.getLocation(e),
2050
+ parent,
2051
+ idx,
2052
+ enclosingCallable,
2053
+ enclosingStmt
2054
+ )
1964
2055
}
1965
2056
1966
2057
else -> {
@@ -1973,68 +2064,6 @@ private fun KotlinFileExtractor.extractConstant(
1973
2064
TODO ()
1974
2065
}
1975
2066
}
1976
-
1977
- // TODO: Wrong
1978
- return TODO ()
1979
- /*
1980
- OLD: KE1
1981
- val v = e.value
1982
- return when {
1983
- v is Float -> {
1984
- exprIdOrFresh<DbFloatingpointliteral>(overrideId).also { id ->
1985
- val type = useType(e.type)
1986
- val locId = tw.getLocation(e)
1987
- tw.writeExprs_floatingpointliteral(id, type.javaResult.id, parent, idx)
1988
- tw.writeExprsKotlinType(id, type.kotlinResult.id)
1989
- extractExprContext(id, locId, enclosingCallable, enclosingStmt)
1990
- tw.writeNamestrings(v.toString(), v.toString(), id)
1991
- }
1992
- }
1993
- v is Double -> {
1994
- exprIdOrFresh<DbDoubleliteral>(overrideId).also { id ->
1995
- val type = useType(e.type)
1996
- val locId = tw.getLocation(e)
1997
- tw.writeExprs_doubleliteral(id, type.javaResult.id, parent, idx)
1998
- tw.writeExprsKotlinType(id, type.kotlinResult.id)
1999
- extractExprContext(id, locId, enclosingCallable, enclosingStmt)
2000
- tw.writeNamestrings(v.toString(), v.toString(), id)
2001
- }
2002
- }
2003
- v is Boolean -> {
2004
- exprIdOrFresh<DbBooleanliteral>(overrideId).also { id ->
2005
- val type = useType(e.type)
2006
- val locId = tw.getLocation(e)
2007
- tw.writeExprs_booleanliteral(id, type.javaResult.id, parent, idx)
2008
- tw.writeExprsKotlinType(id, type.kotlinResult.id)
2009
- extractExprContext(id, locId, enclosingCallable, enclosingStmt)
2010
- tw.writeNamestrings(v.toString(), v.toString(), id)
2011
- }
2012
- }
2013
- v is Char -> {
2014
- exprIdOrFresh<DbCharacterliteral>(overrideId).also { id ->
2015
- val type = useType(e.type)
2016
- val locId = tw.getLocation(e)
2017
- tw.writeExprs_characterliteral(id, type.javaResult.id, parent, idx)
2018
- tw.writeExprsKotlinType(id, type.kotlinResult.id)
2019
- extractExprContext(id, locId, enclosingCallable, enclosingStmt)
2020
- tw.writeNamestrings(v.toString(), v.toString(), id)
2021
- }
2022
- }
2023
- v is String -> {
2024
- exprIdOrFresh<DbStringliteral>(overrideId).also { id ->
2025
- val type = useType(e.type)
2026
- val locId = tw.getLocation(e)
2027
- tw.writeExprs_stringliteral(id, type.javaResult.id, parent, idx)
2028
- tw.writeExprsKotlinType(id, type.kotlinResult.id)
2029
- extractExprContext(id, locId, enclosingCallable, enclosingStmt)
2030
- tw.writeNamestrings(toQuotedLiteral(v.toString()), v.toString(), id)
2031
- }
2032
- }
2033
- else -> {
2034
- null.also { logger.errorElement("Unrecognised IrConst: " + v.javaClass, e) }
2035
- }
2036
- }
2037
- */
2038
2067
}
2039
2068
2040
2069
/*
0 commit comments