diff --git a/App/lib/core/Gen/Type/TypeGenCType.vp b/App/lib/core/Gen/Type/TypeGenCType.vp index a0f90ef..b335065 100644 --- a/App/lib/core/Gen/Type/TypeGenCType.vp +++ b/App/lib/core/Gen/Type/TypeGenCType.vp @@ -419,8 +419,10 @@ class TypeGenCType(TypeGenBase.TypeGenBase): src_len: sizet = string.strlen(src) count: int = 0 line_start: sizet = 0 - # line parse buffer ("NAME\0VALUE\0"), reused per file (register_ctypedef copies) - td_buf: str = pool.alloc(320) + # line parse buffer ("NAME\0VALUE\0"), reused per file (register_ctypedef copies). + # 512 (not 320): _parse_typedef_line normalizes a C-style RHS (`const T` / `T*`) into + # the longer canonical `|` union text, so the VALUE area must hold the expanded form. + td_buf: str = pool.alloc(512) for i in range(src_len + 1): if i == src_len or src[i] == '\n': line_len: sizet = i - line_start diff --git a/App/lib/core/Gen/Type/TypeGenResolve.vp b/App/lib/core/Gen/Type/TypeGenResolve.vp index dc880e4..3ef43d6 100644 --- a/App/lib/core/Gen/Type/TypeGenResolve.vp +++ b/App/lib/core/Gen/Type/TypeGenResolve.vp @@ -978,9 +978,44 @@ novirtual class TypeGenResolve(TypeGenBase.TypeGenBase): out_buf[ci] = buf[line_start + name_s + ci] ci += 1 out_buf[name_l] = '\0' - for ci in range(vlen): - out_buf[name_l + 1 + ci] = buf[line_start + vs + ci] - out_buf[name_l + 1 + vlen] = '\0' + # Normalize a C-style typedef RHS (`const T` / `T*`) into the canonical `|` union text, + # mirroring TPC's TypeAnnotationResolver._NormalizeTypedefRhsText: leading const/volatile + # become `t.CConst |` / `t.CVolatile |`, trailing `*` runs become ` | t.CPtr`. Text without + # these forms is copied verbatim (byte-identical to the pre-normalization behavior). + pos: sizet = name_l + 1 + k: sizet = vs + while True: + if k + 6 <= ve and string.strncmp(buf + line_start + k, "const", 5) == 0 and (buf[line_start + k + 5] == ' ' or buf[line_start + k + 5] == '\t'): + string.memcpy(out_buf + pos, "t.CConst | ", 11) + pos += 11 + k += 6 + elif k + 9 <= ve and string.strncmp(buf + line_start + k, "volatile", 8) == 0 and (buf[line_start + k + 8] == ' ' or buf[line_start + k + 8] == '\t'): + string.memcpy(out_buf + pos, "t.CVolatile | ", 14) + pos += 14 + k += 9 + else: + break + while k < ve and (buf[line_start + k] == ' ' or buf[line_start + k] == '\t'): k += 1 + ptrs: sizet = 0 + ve2: sizet = ve + while ve2 > k and buf[line_start + ve2 - 1] == '*': + ptrs += 1 + ve2 -= 1 + while ve2 > k and (buf[line_start + ve2 - 1] == ' ' or buf[line_start + ve2 - 1] == '\t'): ve2 -= 1 + vlen2: sizet = ve2 - k + if vlen2 > 190: vlen2 = 190 + # Output capacity guard (register_ctypedef_from_source allocates 512 bytes for NAME\0VALUE\0). + if pos + vlen2 + ptrs * 11 > 500: + if pos + ptrs * 11 >= 500: ptrs = 0 + if pos + ptrs * 11 >= 500: vlen2 = 0 + else: vlen2 = 500 - pos - ptrs * 11 + for ci2 in range(vlen2): + out_buf[pos + ci2] = buf[line_start + k + ci2] + pos += vlen2 + for pi in range(ptrs): + string.memcpy(out_buf + pos, " | t.CPtr", 9) + pos += 9 + out_buf[pos] = '\0' return 1 def _lookup_builtins_typedef(self, pool: memhub.MemBuddy*, name: str) -> str: """Last-match fallback: look up a CTypedef declared in includes/builtins.vp."""