From cda4cca805be3113743318c7b4217a9ff3a079ec Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 3 Oct 2026 18:20:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor(generic):=20=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=AE=9E=E5=8F=82=E7=AC=A6=E5=8F=B7=E5=88=A4=E5=AE=9A=E5=A4=8D?= =?UTF-8?q?=E7=94=A8=20spec=5Fsign=5Fof=5Fannot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 两处 Call 推断由 SpecSignFromTypeNameSpan 改为 TypeGenCType.spec_sign_of_annot,复用注解侧唯一真源(精确名白名单 + CTypedef 链逐层展开) - 收益:别名(uint64/size_t/WCHAR->WORD->uint16 等)也能判出符号性,不再是裸白名单的 UNKNOWN --- App/lib/core/Gen/Call/CallGenCtor.vp | 7 ++++--- App/lib/core/Gen/Class/ClassGenGeneric.vp | 17 ++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/App/lib/core/Gen/Call/CallGenCtor.vp b/App/lib/core/Gen/Call/CallGenCtor.vp index c826def..ce5e758 100644 --- a/App/lib/core/Gen/Call/CallGenCtor.vp +++ b/App/lib/core/Gen/Call/CallGenCtor.vp @@ -859,8 +859,9 @@ novirtual class CallGenCtor(CallGenBase.CallGenBase): cty_c: llvmlite.LLVMType* = self.Gen.TypeGenResolve.resolve_annotation_type( pool, cl_f.func, trans._imported_modules, trans._from_imports, trans, 0) if cty_c is not None: - # 符号性从被调名源码文本取(LLVM 层 iN/uN 同形):决定 - # CUInt64T/CInt16T 这类无裸名别名位宽发 t.CUInt64T / t.CInt64T。 + # 符号性从被调名源码文本取(LLVM 层 iN/uN 同形),复用注解侧 + # 唯一真源 spec_sign_of_annot(白名单 + CTypedef 链回退): + # 决定 CUInt64T/CInt16T 这类无裸名别名位宽发 t.CUInt64T/t.CInt64T。 callee_txt_c: str = None if fk_c == ast.ASTKind.Name: callee_txt_c = ast.Name*(cl_f.func).id @@ -868,7 +869,7 @@ novirtual class CallGenCtor(CallGenBase.CallGenBase): callee_txt_c = ast.Attribute*(cl_f.func).attr sign_c: int = TSpec.TS_SIGN_UNKNOWN if callee_txt_c is not None: - sign_c = TSpec.SpecSignFromTypeNameSpan(callee_txt_c, 0, string.strlen(callee_txt_c)) + sign_c = self.Gen.TypeGenCType.spec_sign_of_annot(callee_txt_c, 0) ta_c: str = self.Gen.ClassGenGeneric.infer_scalar_type_arg_from_llvm_ty(pool, cty_c, sign_c) if ta_c is not None: return ta_c diff --git a/App/lib/core/Gen/Class/ClassGenGeneric.vp b/App/lib/core/Gen/Class/ClassGenGeneric.vp index a51228c..6c16f83 100644 --- a/App/lib/core/Gen/Class/ClassGenGeneric.vp +++ b/App/lib/core/Gen/Class/ClassGenGeneric.vp @@ -410,8 +410,11 @@ novirtual class ClassGenGeneric(ClassGenBase.ClassGenBase): pool, cl_f.func, trans._imported_modules, trans._from_imports, trans, 0) if cty_f is not None: # 符号性只能从**被调名源码文本**取(LLVM 层 iN/uN 同形, - # SpecFromLLVMType 恒给 SIGNED):CUInt64T/CInt16T 这类 - # 无裸名别名的位宽必须靠它决定发 t.CUInt64T 还是 t.CInt64T。 + # SpecFromLLVMType 恒给 SIGNED)。复用注解侧唯一真源 + # TypeGenCType.spec_sign_of_annot(精确名白名单 + + # CTypedef 链回退 ⇒ 别名如 uint64 也能判出符号): + # CUInt64T/CInt16T 这类无裸名别名的位宽靠它决定发 + # t.CUInt64T 还是 t.CInt64T。 callee_txt: str = None if fk_f == ast.ASTKind.Name: callee_txt = ast.Name*(cl_f.func).id @@ -419,7 +422,7 @@ novirtual class ClassGenGeneric(ClassGenBase.ClassGenBase): callee_txt = ast.Attribute*(cl_f.func).attr sign_f: int = TSpec.TS_SIGN_UNKNOWN if callee_txt is not None: - sign_f = TSpec.SpecSignFromTypeNameSpan(callee_txt, 0, string.strlen(callee_txt)) + sign_f = self.Gen.TypeGenCType.spec_sign_of_annot(callee_txt, 0) return self.infer_scalar_type_arg_from_llvm_ty(pool, cty_f, sign_f) return None return None @@ -464,7 +467,7 @@ novirtual class ClassGenGeneric(ClassGenBase.ClassGenBase): - SIGN_FROM_SPEC(默认):读 sp.IsSigned(注解侧 Spec 经 SpecWithSign 写入,可信); - 显式 TS_SIGN_*:由调用方给出(LLVM 类型路径符号性在 LLVM 层已丢失, - 只能由**被调名文本**经 TSpec.SpecSignFromTypeNameSpan 判定)。 + 只能由**被调名文本**经 TypeGenCType.spec_sign_of_annot 判定)。 """ if pool is None or sp is None: return None buf: str = pool.alloc(32) @@ -519,9 +522,9 @@ novirtual class ClassGenGeneric(ClassGenBase.ClassGenBase): None ⇒ 调用方不据此推断(宁缺毋错,不按名字子串猜)。 sign:LLVM 类型层无法区分 iN/uN(SpecFromLLVMType 恒给 TS_SIGN_SIGNED) - ⇒ 无符号性必须由调用方从**被调名源码文本**经 TSpec.SpecSignFromTypeName - 判定后传入;未知传 TSpec.TS_SIGN_UNKNOWN(此时 i16/i64 这类无裸名别名的 - 位宽推不出,本函数返回 None)。 + ⇒ 无符号性必须由调用方从**被调名源码文本**经 + TypeGenCType.spec_sign_of_annot 判定后传入;未知传 TSpec.TS_SIGN_UNKNOWN + (此时 i16/i64 这类无裸名别名的位宽推不出,本函数返回 None)。 """ if pool is None or ty is None: return None