diff --git a/App/lib/core/Gen/Func/FuncGenDef.vp b/App/lib/core/Gen/Func/FuncGenDef.vp index e2dd135..6faaab5 100644 --- a/App/lib/core/Gen/Func/FuncGenDef.vp +++ b/App/lib/core/Gen/Func/FuncGenDef.vp @@ -86,6 +86,18 @@ novirtual class FuncGenDef(CallGenBase.CallGenBase): if self.Gen.CallGenLeafKit.count_owned_overloads(trans._funcs, trans._func_count, name, trans.ModuleSha1) >= 2: return 1 return 0 + # _overload_append - 有界追加(本类局部工具)。 + # 不能调用 FuncGenBase._append_str:FuncGenDef 与 FuncGenBase 是同一层的兄弟 mixin, + # FuncGenDef 的 MRO 里没有 FuncGenBase(编译期会报 "method return type cannot be obtained")。 + def _overload_append(self, buf: str, s: str) -> int: + """把 s 追加到 buf(上限 OVERLOAD_SIG_TEXT_MAX);0=成功 / 1=超长""" + if buf is None or s is None: return 1 + cur: sizet = string.strlen(buf) + ln: sizet = string.strlen(s) + if cur + ln + 1 > OVERLOAD_SIG_TEXT_MAX: return 1 + string.strcpy(buf + cur, s) + return 0 + # _overload_sig_text - 重载签名文本:把每个形参的类型写成 SpecToText 规范文本后逗号连接。 # 用注解(而不是 LLVM 类型)生成:LLVM 没有符号性,int/uint 会撞;走 SpecFromLLVMType + # SpecWithSign 后别名展开为 i32/u32,指针是 p:i32,结构体是 st:{模块sha1}.类名 @@ -148,23 +160,30 @@ novirtual class FuncGenDef(CallGenBase.CallGenBase): self.Gen.TypeGenErr.fatal_error(arg, f"overloaded function '{fd.name}' parameter '{arg.arg}' signature text too long", "InternalCompilerError") return None if first == 0: - if string.strlen(buf) + 2 > OVERLOAD_SIG_TEXT_MAX: + if self._overload_append(buf, ",") != 0: stdlib.free(buf) stdlib.free(one) self.Gen.TypeGenErr.fatal_error(fd, f"overloaded function '{fd.name}' parameter list is too long", "InternalCompilerError") return None - self._append_str(buf, ",", OVERLOAD_SIG_TEXT_MAX) first = 0 - if string.strlen(buf) + string.strlen(one) + 2 > OVERLOAD_SIG_TEXT_MAX: + if self._overload_append(buf, one) != 0: stdlib.free(buf) stdlib.free(one) self.Gen.TypeGenErr.fatal_error(fd, f"overloaded function '{fd.name}' parameter list is too long", "InternalCompilerError") return None - self._append_str(buf, one, OVERLOAD_SIG_TEXT_MAX) # *args -> 可变参数标记,必须与定参区分开(ORFunc(int) 与 ORFunc(int, ...) 是两个重载) if ags.vararg is not None: - if first == 0: self._append_str(buf, ",", OVERLOAD_SIG_TEXT_MAX) - self._append_str(buf, "...", OVERLOAD_SIG_TEXT_MAX) + if first == 0: + if self._overload_append(buf, ",") != 0: + stdlib.free(buf) + stdlib.free(one) + self.Gen.TypeGenErr.fatal_error(fd, f"overloaded function '{fd.name}' parameter list is too long", "InternalCompilerError") + return None + if self._overload_append(buf, "...") != 0: + stdlib.free(buf) + stdlib.free(one) + self.Gen.TypeGenErr.fatal_error(fd, f"overloaded function '{fd.name}' parameter list is too long", "InternalCompilerError") + return None first = 0 stdlib.free(one) return buf