fix(overload): 签名文本改用类内 _overload_append,避免跨 mixin 调用 FuncGenBase._append_str
FuncGenDef 与 FuncGenBase 是兄弟 mixin,MRO 中不含对方;在 FuncGenDef 里调用 self._append_str 会让调用点解析失败(method return type cannot be obtained precisely: _append_str)。改为 FuncGenDef 自己的有界追加,并把超长判定并进去重处理。
This commit is contained in:
1 parent
195af1101e
commit
00c385dc94
1 file changed
+25
-6
@@ -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
|
||||
|
||||
Reference in new issue
Block a user