@@ -62,16 +62,13 @@ import org.jetbrains.kotlin.fir.expressions.FirLiteralExpression
6262import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier
6363import org.jetbrains.kotlin.fir.expressions.UnresolvedExpressionTypeAccess
6464import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
65- import org.jetbrains.kotlin.fir.references.resolved
66- import org.jetbrains.kotlin.fir.references.symbol
67- import org.jetbrains.kotlin.fir.references.toResolvedNamedFunctionSymbol
65+ import org.jetbrains.kotlin.fir.references.toResolvedFunctionSymbol
6866import org.jetbrains.kotlin.fir.resolve.fqName
6967import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
7068import org.jetbrains.kotlin.fir.types.classId
7169import org.jetbrains.kotlin.fir.types.coneType
7270import org.jetbrains.kotlin.name.CallableId
7371import org.jetbrains.kotlin.name.ClassId
74- import org.jetbrains.kotlin.name.FqName
7572import org.jetbrains.kotlin.name.Name
7673import org.jetbrains.kotlin.name.StandardClassIds
7774import org.jetbrains.kotlinx.dataframe.plugin.impl.api.AddDslStringInvoke
@@ -91,25 +88,22 @@ import org.jetbrains.kotlinx.dataframe.plugin.impl.api.FrameCols0
9188import org.jetbrains.kotlinx.dataframe.plugin.impl.api.MapToFrame
9289import org.jetbrains.kotlinx.dataframe.plugin.impl.api.Move0
9390import org.jetbrains.kotlinx.dataframe.plugin.impl.api.PairConstructor
91+ import org.jetbrains.kotlinx.dataframe.plugin.impl.api.PairToConstructor
9492import org.jetbrains.kotlinx.dataframe.plugin.impl.api.ReadExcel
9593import org.jetbrains.kotlinx.dataframe.plugin.impl.api.ToDataFrame
9694import org.jetbrains.kotlinx.dataframe.plugin.impl.api.ToDataFrameColumn
9795import org.jetbrains.kotlinx.dataframe.plugin.impl.api.ToDataFrameDefault
9896import org.jetbrains.kotlinx.dataframe.plugin.impl.api.ToDataFrameDsl
9997import org.jetbrains.kotlinx.dataframe.plugin.impl.api.ToDataFrameFrom
10098import org.jetbrains.kotlinx.dataframe.plugin.impl.api.ToTop
99+ import org.jetbrains.kotlinx.dataframe.plugin.impl.api.TrimMargin
101100import org.jetbrains.kotlinx.dataframe.plugin.impl.api.Update0
102101import org.jetbrains.kotlinx.dataframe.plugin.impl.api.UpdateWith0
103102import org.jetbrains.kotlinx.dataframe.plugin.utils.Names
104103
105- @OptIn(UnresolvedExpressionTypeAccess ::class )
106104internal fun FirFunctionCall.loadInterpreter (session : FirSession ): Interpreter <* >? {
107- if (
108- calleeReference.toResolvedNamedFunctionSymbol()?.callableId == Names .TO &&
109- coneTypeOrNull?.classId == Names .PAIR
110- ) {
111- return PairConstructor ()
112- }
105+ val interpreter = Stdlib .interpreter(this )
106+ if (interpreter != null ) return interpreter
113107 val symbol =
114108 (calleeReference as ? FirResolvedNamedReference )?.resolvedSymbol as ? FirCallableSymbol ? : return null
115109 val argName = Name .identifier(" interpreter" )
@@ -121,6 +115,32 @@ internal fun FirFunctionCall.loadInterpreter(session: FirSession): Interpreter<*
121115 }
122116}
123117
118+ private object Stdlib {
119+ private val map: MutableMap <Key , Interpreter <* >> = mutableMapOf ()
120+ init {
121+ register(Names .TO , Names .PAIR , PairToConstructor ())
122+ register(Names .PAIR_CONSTRUCTOR , Names .PAIR , PairConstructor ())
123+ register(Names .TRIM_MARGIN , StandardClassIds .String , TrimMargin ())
124+ register(Names .TRIM_INDENT , StandardClassIds .String , TrimMargin ())
125+ }
126+
127+ @OptIn(UnresolvedExpressionTypeAccess ::class )
128+ fun interpreter (call : FirFunctionCall ): Interpreter <* >? {
129+ val id = call.calleeReference.toResolvedFunctionSymbol()?.callableId ? : return null
130+ val returnType = call.coneTypeOrNull?.classId ? : return null
131+ return map[Key (id, returnType)]
132+ }
133+
134+ fun register (id : CallableId , returnType : ClassId , interpreter : Interpreter <* >) {
135+ map[Key (id, returnType)] = interpreter
136+ }
137+ }
138+
139+ private data class Key (
140+ val id : CallableId ,
141+ val returnType : ClassId ,
142+ )
143+
124144internal fun FirFunctionCall.interpreterName (session : FirSession ): String? {
125145 val symbol =
126146 (calleeReference as ? FirResolvedNamedReference )?.resolvedSymbol as ? FirCallableSymbol ? : return null
0 commit comments