refactor: 全量迁移 includes 到新规范语法
按根目录 新规范 迁移 R1/R2/R3/R4/R6/R7/R8/R9:指针 T* 后缀、内建类型短别名、c.Addr/c.Deref 单目化、c.Asm 改 __asm__、t.CDefine 改 define 软关键字、t.CEnum 改 enum。R4 对内建 cast 多参实参保留 c.Deref 原写法(单目化会致 TPC 类型退化)。验证:includes 52/52 编译通过,TransPyV 自举产物顺序回归 77/77 全通过。
This commit is contained in:
1 parent
aecdf27132
commit
e80284a6d5
88 files changed
+4474
-4474
No files matched your search
+4
-4
@@ -141,7 +141,7 @@ def _init_ast(node: rawptr[AST], pool: rawptr[memhub.MemManager], lineno: int, c
|
||||
node.children = None
|
||||
|
||||
|
||||
def _set_parent_list(lst: list[rawptr[AST]] | t.CPtr, parent: rawptr[AST]):
|
||||
def _set_parent_list(lst: list[rawptr[AST]]*, parent: rawptr[AST]):
|
||||
"""Set list children parent pointers."""
|
||||
if lst is None: return
|
||||
for i in range(lst.__len__()):
|
||||
@@ -149,7 +149,7 @@ def _set_parent_list(lst: list[rawptr[AST]] | t.CPtr, parent: rawptr[AST]):
|
||||
if child is not None: child.parent = parent
|
||||
|
||||
|
||||
def _append_child(lst: list[rawptr[AST]] | t.CPtr, node: rawptr[AST],
|
||||
def _append_child(lst: list[rawptr[AST]]*, node: rawptr[AST],
|
||||
pool: rawptr[memhub.MemManager]):
|
||||
"""Append child nodes to a list (module-level function, to avoid conflicts with the AST.append method name).
|
||||
|
||||
@@ -276,7 +276,7 @@ def _op_name(op: int) -> str:
|
||||
return "NoneOp"
|
||||
|
||||
|
||||
def _dump_list(lst: list[rawptr[AST]] | t.CPtr, buf: str, size: sizet, pos: sizet) -> sizet:
|
||||
def _dump_list(lst: list[rawptr[AST]]*, buf: str, size: sizet, pos: sizet) -> sizet:
|
||||
"""Traverse a list[AST | CPtr] container, polymorphically dump each element."""
|
||||
if lst is None:
|
||||
pos = _emit(buf, size, pos, "[]")
|
||||
@@ -328,7 +328,7 @@ virtual class AST:
|
||||
col_offset: int
|
||||
end_lineno: int
|
||||
end_col_offset: int
|
||||
children: list[rawptr[AST]] | t.CPtr
|
||||
children: list[rawptr[AST]]*
|
||||
|
||||
def kind(self) -> int:
|
||||
"""Returns the node type (ASTKind value), overridden by subclasses"""
|
||||
|
||||
+167
-167
@@ -25,21 +25,21 @@ def _ast_pool_fatal(what: str, need: sizet):
|
||||
# Organized as a type-safe enum using t.CEnum; old names XXX retained as compatible aliases
|
||||
# ============================================================
|
||||
|
||||
class TokenType(t.CEnum):
|
||||
EndMarker: t.State
|
||||
NewLine: t.State
|
||||
Indent: t.State
|
||||
Dedent: t.State
|
||||
Name: t.State
|
||||
Number: t.State
|
||||
String: t.State
|
||||
FStringStart: t.State
|
||||
FStringMiddle: t.State
|
||||
FStringEnd: t.State
|
||||
Op: t.State
|
||||
Nl: t.State
|
||||
Comment: t.State
|
||||
Encoding: t.State
|
||||
enum TokenType:
|
||||
EndMarker
|
||||
NewLine
|
||||
Indent
|
||||
Dedent
|
||||
Name
|
||||
Number
|
||||
String
|
||||
FStringStart
|
||||
FStringMiddle
|
||||
FStringEnd
|
||||
Op
|
||||
Nl
|
||||
Comment
|
||||
Encoding
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -48,108 +48,108 @@ class TokenType(t.CEnum):
|
||||
# NotKeyword(0) represents a non-keyword (sentinel to avoid conflict between False_=0 and kw_subtype=0)
|
||||
# ============================================================
|
||||
|
||||
class Keyword(t.CEnum):
|
||||
NotKeyword: t.State
|
||||
False_: t.State
|
||||
None_: t.State
|
||||
True_: t.State
|
||||
And: t.State
|
||||
As: t.State
|
||||
Assert: t.State
|
||||
Async: t.State
|
||||
Await: t.State
|
||||
Break: t.State
|
||||
Class: t.State
|
||||
Continue: t.State
|
||||
Def: t.State
|
||||
Del: t.State
|
||||
Elif: t.State
|
||||
Else: t.State
|
||||
Except: t.State
|
||||
Finally: t.State
|
||||
For: t.State
|
||||
From: t.State
|
||||
Global: t.State
|
||||
If: t.State
|
||||
Import: t.State
|
||||
In: t.State
|
||||
Is: t.State
|
||||
Lambda: t.State
|
||||
Nonlocal: t.State
|
||||
Not: t.State
|
||||
Or: t.State
|
||||
Pass: t.State
|
||||
Raise: t.State
|
||||
Return: t.State
|
||||
Try: t.State
|
||||
While: t.State
|
||||
With: t.State
|
||||
Yield: t.State
|
||||
Match: t.State
|
||||
Case: t.State
|
||||
Type: t.State
|
||||
enum Keyword:
|
||||
NotKeyword
|
||||
False_
|
||||
None_
|
||||
True_
|
||||
And
|
||||
As
|
||||
Assert
|
||||
Async
|
||||
Await
|
||||
Break
|
||||
Class
|
||||
Continue
|
||||
Def
|
||||
Del
|
||||
Elif
|
||||
Else
|
||||
Except
|
||||
Finally
|
||||
For
|
||||
From
|
||||
Global
|
||||
If
|
||||
Import
|
||||
In
|
||||
Is
|
||||
Lambda
|
||||
Nonlocal
|
||||
Not
|
||||
Or
|
||||
Pass
|
||||
Raise
|
||||
Return
|
||||
Try
|
||||
While
|
||||
With
|
||||
Yield
|
||||
Match
|
||||
Case
|
||||
Type
|
||||
# def 的别名关键字(fn/fun/func/function,语义与 def 完全相同)
|
||||
Fn: t.State
|
||||
Fun: t.State
|
||||
Func: t.State
|
||||
Function: t.State
|
||||
Fn
|
||||
Fun
|
||||
Func
|
||||
Function
|
||||
# extern 函数声明关键字(FFI,等价 t.State 标记;软判定见 _is_funcdef_kw)
|
||||
Extern: t.State
|
||||
Extern
|
||||
# export 函数声明关键字(等价 t.CExport,裸名导出不加 SHA1 头;软判定见 _is_funcdef_kw)
|
||||
Export: t.State
|
||||
Export
|
||||
# define 宏函数关键字(与 def 语义一致,返回注解自动追加 t.CDefine 标记
|
||||
# 为宏函数;软判定见 _is_funcdef_kw)
|
||||
Define: t.State
|
||||
Define
|
||||
# enum 枚举定义关键字(语法糖:`enum X:` 与 `class X(t.CEnum):` 等价,
|
||||
# 见 parser.vp 的 _parse_enumdef)。追加在**表尾**而非插在 Class 之后:
|
||||
# 本枚举成员的值按声明序递增,插在中间会平移 Class 之后所有关键字的编号
|
||||
# (kw_subtype 数值),追加则既有编号逐字不变。
|
||||
Enum: t.State
|
||||
# typedef 类型别名关键字(语法糖:`typedef T1 = T2` 与
|
||||
# `T1: t.CTypedef = T2` 等价,见 parser.vp 的 _parse_typedef)。同样追加在
|
||||
# **表尾**:既有关键字编号(kw_subtype)逐字不变。
|
||||
Typedef: t.State
|
||||
# 类型描述符关键字 const / volatile(语法糖:描述符写在类型前,
|
||||
# `a: const int` 与 `a: t.CConst | int` 等价,见 parser.vp 的 _parse_type_ann)。
|
||||
# 同样追加在**表尾**:既有关键字编号(kw_subtype)逐字不变。
|
||||
# 二者是**软关键字**——只在注解位置(`:` 后 / `->` 后)生效;作标识符的写法
|
||||
# (t.attr.const(),TransPyV/Test/App/attr_test.vp:142)不受影响:
|
||||
# 该处 token 类型仍是 Name,属性名解析只看 TokenType.Name,不看 kw_subtype。
|
||||
Const: t.State
|
||||
Volatile: t.State
|
||||
# virtual / novirtual 修饰符关键字(语法糖:`virtual class C:` /
|
||||
# `novirtual class C:` / `virtual def m(...)` / `novirtual def m(...)`,
|
||||
# 与手写类/方法装饰器 `@t.CVTable` / `@t.NoVTable` **同一套表示**,
|
||||
# 见 parser.vp 的 _ParseVirtualModified)。同样追加在**表尾**:既有关键字
|
||||
# 编号(kw_subtype)逐字不变。
|
||||
# 二者是**软关键字**——只在"语句起始 + 紧跟 class/def"时生效;作标识符的写法
|
||||
# (`x = d.virtual` / 形参名 / for 目标 / 字典键)不受影响:那些位置按
|
||||
# TokenType.Name 解析,不看 kw_subtype。
|
||||
Virtual: t.State
|
||||
Novirtual: t.State
|
||||
# union 类型定义关键字(语法糖:`union X:` 与 `class X(t.CUnion):` 等价,
|
||||
# 见 parser.vp 的 _parse_uniondef)。同样追加在**表尾**:既有关键字编号
|
||||
# (kw_subtype)逐字不变;全仓 .vp 源码中 `union` 不作标识符使用。
|
||||
Union: t.State
|
||||
# renum 变体类型定义关键字(语法糖:`renum X:` 与 `class X(t.REnum):` 等价,
|
||||
# 见 parser.vp 的 _parse_renumdef)。同样追加在**表尾**:既有关键字编号
|
||||
# (kw_subtype)逐字不变;全仓 .vp 源码中 `renum` 不作标识符使用。
|
||||
Renum: t.State
|
||||
# struct 纯数据类型定义关键字(语法糖:`struct X:` 与
|
||||
# `class X(t.CStruct):` + `@t.NoVTable` 等价,见 parser.vp 的 _parse_structdef):
|
||||
# 与 class 同形,但**只能表示数据类型**——禁止 virtual/novirtual 修饰、禁止类体内
|
||||
# 定义 def。同样追加在**表尾**:既有关键字编号(kw_subtype)逐字不变;
|
||||
# 全仓 .vp 源码中 `struct` 不作标识符使用(仅出现在注释/字符串与
|
||||
# build_gep_struct 之类复合标识符里)。
|
||||
Struct: t.State
|
||||
Enum
|
||||
# typedef 类型别名关键字(语法糖:`typedef T1 = T2` 与
|
||||
# `T1: t.CTypedef = T2` 等价,见 parser.vp 的 _parse_typedef)。同样追加在
|
||||
# **表尾**:既有关键字编号(kw_subtype)逐字不变。
|
||||
Typedef
|
||||
# 类型描述符关键字 const / volatile(语法糖:描述符写在类型前,
|
||||
# `a: const int` 与 `a: t.CConst | int` 等价,见 parser.vp 的 _parse_type_ann)。
|
||||
# 同样追加在**表尾**:既有关键字编号(kw_subtype)逐字不变。
|
||||
# 二者是**软关键字**——只在注解位置(`:` 后 / `->` 后)生效;作标识符的写法
|
||||
# (t.attr.const(),TransPyV/Test/App/attr_test.vp:142)不受影响:
|
||||
# 该处 token 类型仍是 Name,属性名解析只看 TokenType.Name,不看 kw_subtype。
|
||||
Const
|
||||
Volatile
|
||||
# virtual / novirtual 修饰符关键字(语法糖:`virtual class C:` /
|
||||
# `novirtual class C:` / `virtual def m(...)` / `novirtual def m(...)`,
|
||||
# 与手写类/方法装饰器 `@t.CVTable` / `@t.NoVTable` **同一套表示**,
|
||||
# 见 parser.vp 的 _ParseVirtualModified)。同样追加在**表尾**:既有关键字
|
||||
# 编号(kw_subtype)逐字不变。
|
||||
# 二者是**软关键字**——只在"语句起始 + 紧跟 class/def"时生效;作标识符的写法
|
||||
# (`x = d.virtual` / 形参名 / for 目标 / 字典键)不受影响:那些位置按
|
||||
# TokenType.Name 解析,不看 kw_subtype。
|
||||
Virtual
|
||||
Novirtual
|
||||
# union 类型定义关键字(语法糖:`union X:` 与 `class X(t.CUnion):` 等价,
|
||||
# 见 parser.vp 的 _parse_uniondef)。同样追加在**表尾**:既有关键字编号
|
||||
# (kw_subtype)逐字不变;全仓 .vp 源码中 `union` 不作标识符使用。
|
||||
Union
|
||||
# renum 变体类型定义关键字(语法糖:`renum X:` 与 `class X(t.REnum):` 等价,
|
||||
# 见 parser.vp 的 _parse_renumdef)。同样追加在**表尾**:既有关键字编号
|
||||
# (kw_subtype)逐字不变;全仓 .vp 源码中 `renum` 不作标识符使用。
|
||||
Renum
|
||||
# struct 纯数据类型定义关键字(语法糖:`struct X:` 与
|
||||
# `class X(t.CStruct):` + `@t.NoVTable` 等价,见 parser.vp 的 _parse_structdef):
|
||||
# 与 class 同形,但**只能表示数据类型**——禁止 virtual/novirtual 修饰、禁止类体内
|
||||
# 定义 def。同样追加在**表尾**:既有关键字编号(kw_subtype)逐字不变;
|
||||
# 全仓 .vp 源码中 `struct` 不作标识符使用(仅出现在注释/字符串与
|
||||
# build_gep_struct 之类复合标识符里)。
|
||||
Struct
|
||||
# switch 多分支语句关键字(`switch <expr>:` + `case <常量>: ` / `default:`,
|
||||
# 见 parser.vp 的 _parse_switch)。C switch 语义:默认**不穿透**,case 体内
|
||||
# 写 `fallthrough` 才落到下一个 case。同样追加在**表尾**:既有关键字编号
|
||||
# (kw_subtype)逐字不变;全仓 .vp 源码中 `switch` 不作标识符使用。
|
||||
Switch: t.State
|
||||
Switch
|
||||
# fallthrough 语句关键字(仅在 switch 的 case 体内合法;match 内使用报错)。
|
||||
# 追加在**表尾**:既有关键字编号(kw_subtype)逐字不变。
|
||||
FallThrough: t.State
|
||||
FallThrough
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -158,55 +158,55 @@ class Keyword(t.CEnum):
|
||||
# Stored in the token.op_subtype field
|
||||
# ============================================================
|
||||
|
||||
class TokOp(t.CEnum):
|
||||
LPar: t.State # (
|
||||
RPar: t.State # )
|
||||
Lsqb: t.State # [
|
||||
Rsqb: t.State # ]
|
||||
LBrace: t.State # {
|
||||
RBrace: t.State # }
|
||||
Comma: t.State # ,
|
||||
Colon: t.State # :
|
||||
Dot: t.State # .
|
||||
Semi: t.State # ;
|
||||
At: t.State # @
|
||||
Equal: t.State # =
|
||||
RArrow: t.State # ->
|
||||
PlusEq: t.State # +=
|
||||
MinusEq: t.State # -=
|
||||
StarEq: t.State # *=
|
||||
SlashEq: t.State # /=
|
||||
DSlashEq: t.State # //=
|
||||
PercentEq: t.State # %=
|
||||
AtEq: t.State # @=
|
||||
AmpEq: t.State # &=
|
||||
VBarEq: t.State # |=
|
||||
CaretEq: t.State # ^=
|
||||
GtGtEq: t.State # >>=
|
||||
LtLtEq: t.State # <<=
|
||||
StarEqEq: t.State # **=
|
||||
DSlash: t.State # //
|
||||
StarStar: t.State # **
|
||||
LtLt: t.State # <<
|
||||
GtGt: t.State # >>
|
||||
LessEq: t.State # <=
|
||||
GreaterEq: t.State # >=
|
||||
EqEq: t.State # ==
|
||||
ExclaimEq: t.State # !=
|
||||
Less: t.State # <
|
||||
Greater: t.State # >
|
||||
Plus: t.State # +
|
||||
Minus: t.State # -
|
||||
Star: t.State # *
|
||||
Slash: t.State # /
|
||||
Percent: t.State # %
|
||||
Amp: t.State # &
|
||||
VBar: t.State # |
|
||||
Caret: t.State # ^
|
||||
Tilde: t.State # ~
|
||||
ColonEq: t.State # :=
|
||||
Ellipsis: t.State # ...
|
||||
Bang: t.State # !(Non-standard, used for parsing tolerance)
|
||||
enum TokOp:
|
||||
LPar # (
|
||||
RPar # )
|
||||
Lsqb # [
|
||||
Rsqb # ]
|
||||
LBrace # {
|
||||
RBrace # }
|
||||
Comma # ,
|
||||
Colon # :
|
||||
Dot # .
|
||||
Semi # ;
|
||||
At # @
|
||||
Equal # =
|
||||
RArrow # ->
|
||||
PlusEq # +=
|
||||
MinusEq # -=
|
||||
StarEq # *=
|
||||
SlashEq # /=
|
||||
DSlashEq # //=
|
||||
PercentEq # %=
|
||||
AtEq # @=
|
||||
AmpEq # &=
|
||||
VBarEq # |=
|
||||
CaretEq # ^=
|
||||
GtGtEq # >>=
|
||||
LtLtEq # <<=
|
||||
StarEqEq # **=
|
||||
DSlash # //
|
||||
StarStar # **
|
||||
LtLt # <<
|
||||
GtGt # >>
|
||||
LessEq # <=
|
||||
GreaterEq # >=
|
||||
EqEq # ==
|
||||
ExclaimEq # !=
|
||||
Less # <
|
||||
Greater # >
|
||||
Plus # +
|
||||
Minus # -
|
||||
Star # *
|
||||
Slash # /
|
||||
Percent # %
|
||||
Amp # &
|
||||
VBar # |
|
||||
Caret # ^
|
||||
Tilde # ~
|
||||
ColonEq # :=
|
||||
Ellipsis # ...
|
||||
Bang # !(Non-standard, used for parsing tolerance)
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -264,18 +264,18 @@ _kw_pool: rawptr[memhub.MemManager] = None
|
||||
# 返回 0(无需回退链表扫描);回退仅用于索引未建成(分配失败)时,保证正确性。
|
||||
_kw_index: sizet* = None
|
||||
# 索引槽数(2 的幂且 > 2*46,负载 < 0.5,探测必然终止)
|
||||
_KW_IDX_CAP: t.CDefine = 128
|
||||
define _KW_IDX_CAP = 128
|
||||
# FNV-1a 64 位常量(与 hashtable.vp 同款)
|
||||
_KW_FNV_OFFSET: t.CUInt64T = 0xcbf29ce484222325
|
||||
_KW_FNV_PRIME: t.CUInt64T = 0x100000001b3
|
||||
_KW_FNV_OFFSET: uint64 = 0xcbf29ce484222325
|
||||
_KW_FNV_PRIME: uint64 = 0x100000001b3
|
||||
|
||||
|
||||
def _kw_hash_str(key: str) -> uint64:
|
||||
"""关键字名 FNV-1a 64 位哈希(同一键必得同一值;仅用于槽定位)"""
|
||||
h: t.CUInt64T = _KW_FNV_OFFSET
|
||||
h: uint64 = _KW_FNV_OFFSET
|
||||
k: str = key
|
||||
while k[0] != 0:
|
||||
h = h ^ t.CUInt64T(k[0])
|
||||
h = h ^ uint64(k[0])
|
||||
h = h * _KW_FNV_PRIME
|
||||
k += 1
|
||||
return uint64(h)
|
||||
@@ -298,7 +298,7 @@ def _kw_index_put(entry: rawptr[KwEntry]):
|
||||
if cur_s == 0:
|
||||
slot[0] = sizet(entry)
|
||||
return
|
||||
cur: KwEntry | t.CPtr = (KwEntry | t.CPtr)(t.CPtr(uint64(cur_s)))
|
||||
cur: KwEntry* = (KwEntry*)(t.CPtr(uint64(cur_s)))
|
||||
if string.strcmp(cur.name, entry.name) == 0:
|
||||
return
|
||||
idx = (idx + 1) & mask
|
||||
@@ -343,7 +343,7 @@ def _kw_lookup(name: str) -> int:
|
||||
cur_s: sizet = slot[0]
|
||||
if cur_s == 0:
|
||||
return 0
|
||||
cur: KwEntry | t.CPtr = (KwEntry | t.CPtr)(t.CPtr(uint64(cur_s)))
|
||||
cur: KwEntry* = (KwEntry*)(t.CPtr(uint64(cur_s)))
|
||||
if string.strcmp(cur.name, name) == 0:
|
||||
return cur.kw_id
|
||||
idx = (idx + 1) & mask
|
||||
@@ -421,15 +421,15 @@ def _init_keywords(pool: rawptr[memhub.MemManager]):
|
||||
# virtual / novirtual 修饰符软关键字(仅"语句起始 + 紧跟 class/def"生效,
|
||||
# 见 parser.vp 的 _ParseVirtualModified)
|
||||
_kw_intern(pool, "virtual", Keyword.Virtual)
|
||||
_kw_intern(pool, "novirtual", Keyword.Novirtual)
|
||||
_kw_intern(pool, "union", Keyword.Union)
|
||||
# renum 变体类型定义关键字(语法糖,同 enum/union,见 parser.vp 的 _parse_renumdef)
|
||||
_kw_intern(pool, "renum", Keyword.Renum)
|
||||
# struct 纯数据类型定义关键字(语法糖,同 enum/union/renum,见 parser.vp 的
|
||||
# _parse_structdef:基类 t.CStruct + 伪装饰器 @t.NoVTable,禁 virtual/novirtual、禁 def)
|
||||
_kw_intern(pool, "struct", Keyword.Struct)
|
||||
# switch / fallthrough 关键字(见 parser.vp 的 _parse_switch 与 _parse_small_stmt)
|
||||
_kw_intern(pool, "switch", Keyword.Switch)
|
||||
_kw_intern(pool, "novirtual", Keyword.Novirtual)
|
||||
_kw_intern(pool, "union", Keyword.Union)
|
||||
# renum 变体类型定义关键字(语法糖,同 enum/union,见 parser.vp 的 _parse_renumdef)
|
||||
_kw_intern(pool, "renum", Keyword.Renum)
|
||||
# struct 纯数据类型定义关键字(语法糖,同 enum/union/renum,见 parser.vp 的
|
||||
# _parse_structdef:基类 t.CStruct + 伪装饰器 @t.NoVTable,禁 virtual/novirtual、禁 def)
|
||||
_kw_intern(pool, "struct", Keyword.Struct)
|
||||
# switch / fallthrough 关键字(见 parser.vp 的 _parse_switch 与 _parse_small_stmt)
|
||||
_kw_intern(pool, "switch", Keyword.Switch)
|
||||
_kw_intern(pool, "fallthrough", Keyword.FallThrough)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user