refactor(generic): 类型实参符号判定复用 spec_sign_of_annot
- 两处 Call 推断由 SpecSignFromTypeNameSpan 改为 TypeGenCType.spec_sign_of_annot,复用注解侧唯一真源(精确名白名单 + CTypedef 链逐层展开) - 收益:别名(uint64/size_t/WCHAR->WORD->uint16 等)也能判出符号性,不再是裸白名单的 UNKNOWN
This commit is contained in:
1 parent
2ac412c11a
commit
cda4cca805
2 files changed
+14
-10
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user