@@ -32,7 +32,7 @@ interface ITySubstitutor {
3232class GenericAnalyzer (arg : ITy , private val par : ITy ) : TyVisitor() {
3333 var cur: ITy = arg
3434
35- var map: MutableMap <String , ITy >? = null
35+ var map: MutableMap <String , ITy >? = null
3636
3737 fun analyze (result : MutableMap <String , ITy >) {
3838 map = result
@@ -86,7 +86,7 @@ class GenericAnalyzer(arg: ITy, private val par: ITy) : TyVisitor() {
8686 warp(arg.returnTy) { par.returnTy.accept(this ) }
8787 }
8888
89- private fun warp (ty : ITy , action : () -> Unit ) {
89+ private fun warp (ty : ITy , action : () -> Unit ) {
9090 if (Ty .isInvalid(ty))
9191 return
9292 val arg = cur
@@ -108,13 +108,18 @@ open class TySubstitutor : ITySubstitutor {
108108 }
109109
110110 override fun substitute (function : ITyFunction ): ITy {
111- return TySerializedFunction (function.mainSignature.substitute(this ),
112- function.signatures.map { it.substitute(this ) }.toTypedArray(),
113- function.flags)
111+ return TySerializedFunction (
112+ function.mainSignature.substitute(this ),
113+ function.signatures.map { it.substitute(this ) }.toTypedArray(),
114+ function.flags
115+ )
114116 }
115117}
116118
119+ // cppcxy: 我对这里的递归爆栈感到绝望
117120class TyAliasSubstitutor private constructor(val project : Project ) : ITySubstitutor {
121+ val walkedClassName = mutableSetOf<String >()
122+
118123 companion object {
119124 fun substitute (ty : ITy , context : SearchContext ): ITy {
120125 /* if (context.forStub)
@@ -124,12 +129,18 @@ class TyAliasSubstitutor private constructor(val project: Project) : ITySubstitu
124129 }
125130
126131 override fun substitute (function : ITyFunction ): ITy {
127- return TySerializedFunction (function.mainSignature.substitute(this ),
128- function.signatures.map { it.substitute(this ) }.toTypedArray(),
129- function.flags)
132+ return TySerializedFunction (
133+ function.mainSignature.substitute(this ),
134+ function.signatures.map { it.substitute(this ) }.toTypedArray(),
135+ function.flags
136+ )
130137 }
131138
132139 override fun substitute (clazz : ITyClass ): ITy {
140+ if (clazz.className in this .walkedClassName) {
141+ return clazz
142+ }
143+ this .walkedClassName.add(clazz.className)
133144 return clazz.recoverAlias(SearchContext .get(project), this )
134145 }
135146
0 commit comments