From 229266de43ee5be9e9f67e56deed5c1ef3011df3 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 13 Feb 2025 12:04:02 +0100 Subject: [PATCH] NIFC: support C++ reference types via a pointer qualifier (#530) * NIFC: support C++ reference types via a pointer qualifier * only active when the backend is C++ --- doc/nifc-spec.md | 10 +- doc/tags.md | 1 + src/models/callconv_tags.nim | 20 +- src/models/nifc_tags.nim | 75 ++--- src/models/nimony_tags.nim | 272 ++++++++-------- src/models/tags.nim | 586 ++++++++++++++++++----------------- src/nifc/genexprs.nim | 20 +- src/nifc/gentypes.nim | 16 +- 8 files changed, 517 insertions(+), 483 deletions(-) diff --git a/doc/nifc-spec.md b/doc/nifc-spec.md index 44f489a2..d69588c6 100644 --- a/doc/nifc-spec.md +++ b/doc/nifc-spec.md @@ -80,7 +80,7 @@ CharLiteral ::= StringLiteral ::= IntBits ::= ('+' | '-') [0-9]+ -Lvalue ::= Symbol | (deref Expr) | +Lvalue ::= Symbol | (deref Expr (cppref)?) | (at Expr Expr) | # array indexing (dot Expr Symbol Number) | # field access (pat Expr Expr) | # pointer indexing @@ -92,7 +92,7 @@ CallCanRaise ::= (onerr Stmt Expr+) Expr ::= Number | CharLiteral | StringLiteral | Lvalue | (par Expr) | # wraps the expression in parentheses - (addr Lvalue) | # "address of" operation + (addr Lvalue (cppref)?) | # "address of" operation (nil) | (false) | (true) | (inf) | (neginf) | (nan) | (and Expr Expr) | # "&&" @@ -191,7 +191,7 @@ Type ::= Symbol | (c IntBits IntQualifier*) | # character types (bool IntQualifier*) | (void) | - (ptr Type PtrQualifier*) | # pointer to a single object + (ptr Type PtrQualifier* (cppref)?) | # pointer to a single object (flexarray Type) | (aptr Type PtrQualifier*) | # pointer to an array of objects ProcType @@ -277,6 +277,10 @@ Notes: - `var` is always a local variable, `gvar` is a global variable and `tvar` a thread local variable. - `SCOPE` indicates the construct introduces a new local scope for variables. +- `cppref` is a pragma that indicates that the pointer should be translated into a C++ + reference (`T&`). The `(deref)` and `(addr)` operations are still mandatory then and + must be annotated with `(cppref)` too. `(cppref)` can be combined with `(ro)` to produce + a `const T&` reference. Scopes diff --git a/doc/tags.md b/doc/tags.md index 303e7a81..f48f949f 100644 --- a/doc/tags.md +++ b/doc/tags.md @@ -99,6 +99,7 @@ | atomic | TQC | `atomic` type qualifier for NIFC | | ro | TQC | `readonly` (= `const`) type qualifier for NIFC | | restrict | TQC | type qualifier for NIFC | +| cppref | TQC | type qualifier for NIFC that provides a C++ reference | | i | TC, TN | `int` builtin type | | u | TC, TN | `uint` builtin type | | f | TC, TN | `float` builtin type | diff --git a/src/models/callconv_tags.nim b/src/models/callconv_tags.nim index 92095ab9..6fdd22b9 100644 --- a/src/models/callconv_tags.nim +++ b/src/models/callconv_tags.nim @@ -4,16 +4,16 @@ type CallConv* = enum NoCallConv - Cdecl = (110, "cdecl") ## `cdecl` calling convention - Stdcall = (111, "stdcall") ## `stdcall` calling convention - Safecall = (112, "safecall") ## `safecall` calling convention - Syscall = (113, "syscall") ## `syscall` calling convention - Fastcall = (114, "fastcall") ## `fastcall` calling convention - Thiscall = (115, "thiscall") ## `thiscall` calling convention - Noconv = (116, "noconv") ## no explicit calling convention - Member = (117, "member") ## `member` calling convention - Nimcall = (118, "nimcall") ## `nimcall` calling convention + Cdecl = (111, "cdecl") ## `cdecl` calling convention + Stdcall = (112, "stdcall") ## `stdcall` calling convention + Safecall = (113, "safecall") ## `safecall` calling convention + Syscall = (114, "syscall") ## `syscall` calling convention + Fastcall = (115, "fastcall") ## `fastcall` calling convention + Thiscall = (116, "thiscall") ## `thiscall` calling convention + Noconv = (117, "noconv") ## no explicit calling convention + Member = (118, "member") ## `member` calling convention + Nimcall = (119, "nimcall") ## `nimcall` calling convention proc rawTagIsCallConv*(raw: uint32): bool {.inline.} = - raw >= 110'u32 and raw <= 118'u32 + raw >= 111'u32 and raw <= 119'u32 diff --git a/src/models/nifc_tags.nim b/src/models/nifc_tags.nim index d7791ee5..701e9ed8 100644 --- a/src/models/nifc_tags.nim +++ b/src/models/nifc_tags.nim @@ -44,10 +44,10 @@ type CastC = (44, "cast") ConvC = (45, "conv") ## type conversion CallC = (46, "call") ## call operation - ErrvC = (245, "errv") ## error flag for `NIFC` + ErrvC = (246, "errv") ## error flag for `NIFC` proc rawTagIsNifcExpr*(raw: uint32): bool {.inline.} = - raw <= 255'u32 and raw.uint8 in {2'u8, 3'u8, 4'u8, 5'u8, 6'u8, 7'u8, 8'u8, 9'u8, 10'u8, 11'u8, 12'u8, 13'u8, 14'u8, 15'u8, 16'u8, 17'u8, 18'u8, 19'u8, 20'u8, 21'u8, 22'u8, 24'u8, 29'u8, 30'u8, 31'u8, 32'u8, 33'u8, 34'u8, 35'u8, 36'u8, 37'u8, 38'u8, 39'u8, 40'u8, 41'u8, 42'u8, 43'u8, 44'u8, 45'u8, 46'u8, 245'u8} + raw <= 255'u32 and raw.uint8 in {2'u8, 3'u8, 4'u8, 5'u8, 6'u8, 7'u8, 8'u8, 9'u8, 10'u8, 11'u8, 12'u8, 13'u8, 14'u8, 15'u8, 16'u8, 17'u8, 18'u8, 19'u8, 20'u8, 21'u8, 22'u8, 24'u8, 29'u8, 30'u8, 31'u8, 32'u8, 33'u8, 34'u8, 35'u8, 36'u8, 37'u8, 38'u8, 39'u8, 40'u8, 41'u8, 42'u8, 43'u8, 44'u8, 45'u8, 46'u8, 246'u8} type NifcStmt* = enum @@ -70,15 +70,15 @@ type JmpS = (88, "jmp") ## jump/goto instruction RetS = (89, "ret") ## `return` instruction StmtsS = (91, "stmts") ## list of statements - ImpS = (129, "imp") ## import declaration - InclS = (131, "incl") ## `#include` statement or `incl` set operation - DiscardS = (139, "discard") ## `discard` statement - TryS = (140, "try") ## `try` statement - RaiseS = (141, "raise") ## `raise` statement - OnerrS = (142, "onerr") ## error handling statement + ImpS = (130, "imp") ## import declaration + InclS = (132, "incl") ## `#include` statement or `incl` set operation + DiscardS = (140, "discard") ## `discard` statement + TryS = (141, "try") ## `try` statement + RaiseS = (142, "raise") ## `raise` statement + OnerrS = (143, "onerr") ## error handling statement proc rawTagIsNifcStmt*(raw: uint32): bool {.inline.} = - raw <= 255'u32 and raw.uint8 in {46'u8, 50'u8, 51'u8, 52'u8, 54'u8, 61'u8, 68'u8, 73'u8, 74'u8, 75'u8, 76'u8, 81'u8, 84'u8, 85'u8, 87'u8, 88'u8, 89'u8, 91'u8, 129'u8, 131'u8, 139'u8, 140'u8, 141'u8, 142'u8} + raw <= 255'u32 and raw.uint8 in {46'u8, 50'u8, 51'u8, 52'u8, 54'u8, 61'u8, 68'u8, 73'u8, 74'u8, 75'u8, 76'u8, 81'u8, 84'u8, 85'u8, 87'u8, 88'u8, 89'u8, 91'u8, 130'u8, 132'u8, 140'u8, 141'u8, 142'u8, 143'u8} type NifcType* = enum @@ -88,19 +88,19 @@ type ObjectT = (94, "object") ## object type declaration EnumT = (95, "enum") ## enum type declaration ProctypeT = (96, "proctype") ## proc type declaration (soon obsolete, use params instead) - IT = (100, "i") ## `int` builtin type - UT = (101, "u") ## `uint` builtin type - FT = (102, "f") ## `float` builtin type - CT = (103, "c") ## `char` builtin type - BoolT = (104, "bool") ## `bool` builtin type - VoidT = (105, "void") ## `void` return type - PtrT = (106, "ptr") ## `ptr` type contructor - ArrayT = (107, "array") ## `array` type constructor - FlexarrayT = (108, "flexarray") ## `flexarray` type constructor - AptrT = (109, "aptr") ## "pointer to array of" type constructor + IT = (101, "i") ## `int` builtin type + UT = (102, "u") ## `uint` builtin type + FT = (103, "f") ## `float` builtin type + CT = (104, "c") ## `char` builtin type + BoolT = (105, "bool") ## `bool` builtin type + VoidT = (106, "void") ## `void` return type + PtrT = (107, "ptr") ## `ptr` type contructor + ArrayT = (108, "array") ## `array` type constructor + FlexarrayT = (109, "flexarray") ## `flexarray` type constructor + AptrT = (110, "aptr") ## "pointer to array of" type constructor proc rawTagIsNifcType*(raw: uint32): bool {.inline.} = - raw >= 92'u32 and raw <= 109'u32 and raw != 97'u32 and raw != 98'u32 and raw != 99'u32 + raw <= 255'u32 and raw.uint8 in {92'u8, 93'u8, 94'u8, 95'u8, 96'u8, 101'u8, 102'u8, 103'u8, 104'u8, 105'u8, 106'u8, 107'u8, 108'u8, 109'u8, 110'u8} type NifcOther* = enum @@ -115,30 +115,30 @@ type ElifU = (78, "elif") ## pair of (condition, action) ElseU = (79, "else") ## `else` action OfU = (86, "of") ## `of` branch within a `case` statement - PragmasU = (125, "pragmas") ## begin of pragma section + PragmasU = (126, "pragmas") ## begin of pragma section proc rawTagIsNifcOther*(raw: uint32): bool {.inline.} = - raw <= 255'u32 and raw.uint8 in {28'u8, 48'u8, 49'u8, 53'u8, 58'u8, 59'u8, 60'u8, 78'u8, 79'u8, 86'u8, 125'u8} + raw <= 255'u32 and raw.uint8 in {28'u8, 48'u8, 49'u8, 53'u8, 58'u8, 59'u8, 60'u8, 78'u8, 79'u8, 86'u8, 126'u8} type NifcPragma* = enum NoPragma - InlineP = (119, "inline") ## `inline` proc annotation - NoinlineP = (120, "noinline") ## `noinline` proc annotation - AttrP = (121, "attr") ## general attribute annoation - VarargsP = (122, "varargs") ## `varargs` proc annotation - WasP = (123, "was") - SelectanyP = (124, "selectany") - AlignP = (126, "align") - BitsP = (127, "bits") - VectorP = (128, "vector") - NodeclP = (130, "nodecl") ## `nodecl` annotation - RaisesP = (143, "raises") ## proc annotation - ErrsP = (144, "errs") ## proc annotation - StaticP = (145, "static") ## `static` type or annotation + InlineP = (120, "inline") ## `inline` proc annotation + NoinlineP = (121, "noinline") ## `noinline` proc annotation + AttrP = (122, "attr") ## general attribute annoation + VarargsP = (123, "varargs") ## `varargs` proc annotation + WasP = (124, "was") + SelectanyP = (125, "selectany") + AlignP = (127, "align") + BitsP = (128, "bits") + VectorP = (129, "vector") + NodeclP = (131, "nodecl") ## `nodecl` annotation + RaisesP = (144, "raises") ## proc annotation + ErrsP = (145, "errs") ## proc annotation + StaticP = (146, "static") ## `static` type or annotation proc rawTagIsNifcPragma*(raw: uint32): bool {.inline.} = - raw <= 255'u32 and raw.uint8 in {119'u8, 120'u8, 121'u8, 122'u8, 123'u8, 124'u8, 126'u8, 127'u8, 128'u8, 130'u8, 143'u8, 144'u8, 145'u8} + raw <= 255'u32 and raw.uint8 in {120'u8, 121'u8, 122'u8, 123'u8, 124'u8, 125'u8, 127'u8, 128'u8, 129'u8, 131'u8, 144'u8, 145'u8, 146'u8} type NifcTypeQualifier* = enum @@ -146,9 +146,10 @@ type AtomicQ = (97, "atomic") ## `atomic` type qualifier for NIFC RoQ = (98, "ro") ## `readonly` (= `const`) type qualifier for NIFC RestrictQ = (99, "restrict") ## type qualifier for NIFC + CpprefQ = (100, "cppref") ## type qualifier for NIFC that provides a C++ reference proc rawTagIsNifcTypeQualifier*(raw: uint32): bool {.inline.} = - raw >= 97'u32 and raw <= 99'u32 + raw >= 97'u32 and raw <= 100'u32 type NifcSym* = enum diff --git a/src/models/nimony_tags.nim b/src/models/nimony_tags.nim index 361c8f06..6fddc6f2 100644 --- a/src/models/nimony_tags.nim +++ b/src/models/nimony_tags.nim @@ -50,54 +50,54 @@ type CmdX = (47, "cmd") ## command operation CchoiceX = (71, "cchoice") ## closed choice OchoiceX = (72, "ochoice") ## open choice - QuotedX = (200, "quoted") ## name in backticks - HderefX = (201, "hderef") ## hidden pointer deref operation - DdotX = (202, "ddot") ## deref dot - HaddrX = (203, "haddr") ## hidden address of operation - NewobjX = (204, "newobj") ## new object constructor - TupX = (205, "tup") ## tuple constructor - SetconstrX = (206, "setconstr") ## set constructor - AshrX = (207, "ashr") - OconvX = (208, "oconv") ## object conversion - HconvX = (209, "hconv") ## hidden basic type conversion - DconvX = (210, "dconv") ## conversion between `distinct` types - CallstrlitX = (211, "callstrlit") - InfixX = (212, "infix") - PrefixX = (213, "prefix") - HcallX = (214, "hcall") ## hidden converter call - CompilesX = (215, "compiles") - DeclaredX = (216, "declared") - DefinedX = (217, "defined") - HighX = (218, "high") - LowX = (219, "low") - TypeofX = (220, "typeof") - UnpackX = (221, "unpack") - EnumtostrX = (222, "enumtostr") - IsmainmoduleX = (223, "ismainmodule") - DefaultobjX = (224, "defaultobj") - DefaulttupX = (225, "defaulttup") - ExprX = (226, "expr") - ArratX = (227, "arrat") - TupatX = (228, "tupat") - PlussetX = (229, "plusset") - MinussetX = (230, "minusset") - MulsetX = (231, "mulset") - XorsetX = (232, "xorset") - EqsetX = (233, "eqset") - LesetX = (234, "leset") - LtsetX = (235, "ltset") - InsetX = (236, "inset") - CardX = (237, "card") - EmoveX = (238, "emove") - DestroyX = (239, "destroy") - DupX = (240, "dup") - CopyX = (241, "copy") - WasmovedX = (242, "wasmoved") - SinkhX = (243, "sinkh") - TraceX = (244, "trace") + QuotedX = (201, "quoted") ## name in backticks + HderefX = (202, "hderef") ## hidden pointer deref operation + DdotX = (203, "ddot") ## deref dot + HaddrX = (204, "haddr") ## hidden address of operation + NewobjX = (205, "newobj") ## new object constructor + TupX = (206, "tup") ## tuple constructor + SetconstrX = (207, "setconstr") ## set constructor + AshrX = (208, "ashr") + OconvX = (209, "oconv") ## object conversion + HconvX = (210, "hconv") ## hidden basic type conversion + DconvX = (211, "dconv") ## conversion between `distinct` types + CallstrlitX = (212, "callstrlit") + InfixX = (213, "infix") + PrefixX = (214, "prefix") + HcallX = (215, "hcall") ## hidden converter call + CompilesX = (216, "compiles") + DeclaredX = (217, "declared") + DefinedX = (218, "defined") + HighX = (219, "high") + LowX = (220, "low") + TypeofX = (221, "typeof") + UnpackX = (222, "unpack") + EnumtostrX = (223, "enumtostr") + IsmainmoduleX = (224, "ismainmodule") + DefaultobjX = (225, "defaultobj") + DefaulttupX = (226, "defaulttup") + ExprX = (227, "expr") + ArratX = (228, "arrat") + TupatX = (229, "tupat") + PlussetX = (230, "plusset") + MinussetX = (231, "minusset") + MulsetX = (232, "mulset") + XorsetX = (233, "xorset") + EqsetX = (234, "eqset") + LesetX = (235, "leset") + LtsetX = (236, "ltset") + InsetX = (237, "inset") + CardX = (238, "card") + EmoveX = (239, "emove") + DestroyX = (240, "destroy") + DupX = (241, "dup") + CopyX = (242, "copy") + WasmovedX = (243, "wasmoved") + SinkhX = (244, "sinkh") + TraceX = (245, "trace") proc rawTagIsNimonyExpr*(raw: uint32): bool {.inline.} = - raw <= 255'u32 and raw.uint8 in {1'u8, 2'u8, 3'u8, 4'u8, 5'u8, 6'u8, 7'u8, 8'u8, 9'u8, 10'u8, 11'u8, 12'u8, 13'u8, 14'u8, 15'u8, 16'u8, 17'u8, 18'u8, 19'u8, 20'u8, 21'u8, 23'u8, 25'u8, 26'u8, 27'u8, 29'u8, 30'u8, 31'u8, 32'u8, 33'u8, 34'u8, 35'u8, 36'u8, 37'u8, 38'u8, 39'u8, 40'u8, 41'u8, 42'u8, 43'u8, 44'u8, 45'u8, 46'u8, 47'u8, 71'u8, 72'u8, 200'u8, 201'u8, 202'u8, 203'u8, 204'u8, 205'u8, 206'u8, 207'u8, 208'u8, 209'u8, 210'u8, 211'u8, 212'u8, 213'u8, 214'u8, 215'u8, 216'u8, 217'u8, 218'u8, 219'u8, 220'u8, 221'u8, 222'u8, 223'u8, 224'u8, 225'u8, 226'u8, 227'u8, 228'u8, 229'u8, 230'u8, 231'u8, 232'u8, 233'u8, 234'u8, 235'u8, 236'u8, 237'u8, 238'u8, 239'u8, 240'u8, 241'u8, 242'u8, 243'u8, 244'u8} + raw <= 255'u32 and raw.uint8 in {1'u8, 2'u8, 3'u8, 4'u8, 5'u8, 6'u8, 7'u8, 8'u8, 9'u8, 10'u8, 11'u8, 12'u8, 13'u8, 14'u8, 15'u8, 16'u8, 17'u8, 18'u8, 19'u8, 20'u8, 21'u8, 23'u8, 25'u8, 26'u8, 27'u8, 29'u8, 30'u8, 31'u8, 32'u8, 33'u8, 34'u8, 35'u8, 36'u8, 37'u8, 38'u8, 39'u8, 40'u8, 41'u8, 42'u8, 43'u8, 44'u8, 45'u8, 46'u8, 47'u8, 71'u8, 72'u8, 201'u8, 202'u8, 203'u8, 204'u8, 205'u8, 206'u8, 207'u8, 208'u8, 209'u8, 210'u8, 211'u8, 212'u8, 213'u8, 214'u8, 215'u8, 216'u8, 217'u8, 218'u8, 219'u8, 220'u8, 221'u8, 222'u8, 223'u8, 224'u8, 225'u8, 226'u8, 227'u8, 228'u8, 229'u8, 230'u8, 231'u8, 232'u8, 233'u8, 234'u8, 235'u8, 236'u8, 237'u8, 238'u8, 239'u8, 240'u8, 241'u8, 242'u8, 243'u8, 244'u8, 245'u8} type NimonyStmt* = enum @@ -131,21 +131,21 @@ type RetS = (89, "ret") ## `return` instruction YldS = (90, "yld") ## yield statement StmtsS = (91, "stmts") ## list of statements - PragmasS = (125, "pragmas") ## begin of pragma section - InclS = (131, "incl") ## `#include` statement or `incl` set operation - ExclS = (132, "excl") ## `excl` set operation - IncludeS = (133, "include") ## `include` statement - ImportS = (134, "import") ## `import` statement - FromS = (135, "from") ## `from` statement - ImportexceptS = (136, "importexcept") ## `importexcept` statement - ExportS = (137, "export") ## `export` statement - CommentS = (138, "comment") ## `comment` statement - DiscardS = (139, "discard") ## `discard` statement - TryS = (140, "try") ## `try` statement - RaiseS = (141, "raise") ## `raise` statement + PragmasS = (126, "pragmas") ## begin of pragma section + InclS = (132, "incl") ## `#include` statement or `incl` set operation + ExclS = (133, "excl") ## `excl` set operation + IncludeS = (134, "include") ## `include` statement + ImportS = (135, "import") ## `import` statement + FromS = (136, "from") ## `from` statement + ImportexceptS = (137, "importexcept") ## `importexcept` statement + ExportS = (138, "export") ## `export` statement + CommentS = (139, "comment") ## `comment` statement + DiscardS = (140, "discard") ## `discard` statement + TryS = (141, "try") ## `try` statement + RaiseS = (142, "raise") ## `raise` statement proc rawTagIsNimonyStmt*(raw: uint32): bool {.inline.} = - raw <= 255'u32 and raw.uint8 in {46'u8, 47'u8, 52'u8, 54'u8, 55'u8, 56'u8, 57'u8, 61'u8, 62'u8, 63'u8, 64'u8, 65'u8, 66'u8, 67'u8, 68'u8, 69'u8, 73'u8, 74'u8, 75'u8, 76'u8, 77'u8, 81'u8, 82'u8, 83'u8, 84'u8, 85'u8, 89'u8, 90'u8, 91'u8, 125'u8, 131'u8, 132'u8, 133'u8, 134'u8, 135'u8, 136'u8, 137'u8, 138'u8, 139'u8, 140'u8, 141'u8} + raw <= 255'u32 and raw.uint8 in {46'u8, 47'u8, 52'u8, 54'u8, 55'u8, 56'u8, 57'u8, 61'u8, 62'u8, 63'u8, 64'u8, 65'u8, 66'u8, 67'u8, 68'u8, 69'u8, 73'u8, 74'u8, 75'u8, 76'u8, 77'u8, 81'u8, 82'u8, 83'u8, 84'u8, 85'u8, 89'u8, 90'u8, 91'u8, 126'u8, 132'u8, 133'u8, 134'u8, 135'u8, 136'u8, 137'u8, 138'u8, 139'u8, 140'u8, 141'u8, 142'u8} type NimonyType* = enum @@ -160,45 +160,45 @@ type ObjectT = (94, "object") ## object type declaration EnumT = (95, "enum") ## enum type declaration ProctypeT = (96, "proctype") ## proc type declaration (soon obsolete, use params instead) - IT = (100, "i") ## `int` builtin type - UT = (101, "u") ## `uint` builtin type - FT = (102, "f") ## `float` builtin type - CT = (103, "c") ## `char` builtin type - BoolT = (104, "bool") ## `bool` builtin type - VoidT = (105, "void") ## `void` return type - PtrT = (106, "ptr") ## `ptr` type contructor - ArrayT = (107, "array") ## `array` type constructor - VarargsT = (122, "varargs") ## `varargs` proc annotation - StaticT = (145, "static") ## `static` type or annotation - RefobjT = (154, "refobj") ## `ref object` type - PtrobjT = (155, "ptrobj") ## `ptr object` type - TupleT = (156, "tuple") ## `tuple` type - OnumT = (157, "onum") ## enum with holes type - RefT = (158, "ref") ## `ref` type - MutT = (159, "mut") ## `mut` type - OutT = (160, "out") ## `out` type - LentT = (161, "lent") ## `lent` type - SinkT = (162, "sink") ## `sink` type - NiltT = (163, "nilt") ## `nilt` type - ConceptT = (164, "concept") ## `concept` type - DistinctT = (165, "distinct") ## `distinct` type - ItertypeT = (166, "itertype") ## `itertype` type - RangetypeT = (167, "rangetype") ## `rangetype` type - UarrayT = (168, "uarray") ## `uarray` type - OpenarrayT = (169, "openarray") ## `openarray` type - SetT = (170, "set") ## `set` type - AutoT = (171, "auto") ## `auto` type - SymkindT = (172, "symkind") ## `symkind` type - TypekindT = (173, "typekind") ## `typekind` type - TypedescT = (174, "typedesc") ## `typedesc` type - UntypedT = (175, "untyped") ## `untyped` type - TypedT = (176, "typed") ## `typed` type - CstringT = (177, "cstring") ## `cstring` type - PointerT = (178, "pointer") ## `pointer` type - OrdinalT = (179, "ordinal") ## `ordinal` type + IT = (101, "i") ## `int` builtin type + UT = (102, "u") ## `uint` builtin type + FT = (103, "f") ## `float` builtin type + CT = (104, "c") ## `char` builtin type + BoolT = (105, "bool") ## `bool` builtin type + VoidT = (106, "void") ## `void` return type + PtrT = (107, "ptr") ## `ptr` type contructor + ArrayT = (108, "array") ## `array` type constructor + VarargsT = (123, "varargs") ## `varargs` proc annotation + StaticT = (146, "static") ## `static` type or annotation + RefobjT = (155, "refobj") ## `ref object` type + PtrobjT = (156, "ptrobj") ## `ptr object` type + TupleT = (157, "tuple") ## `tuple` type + OnumT = (158, "onum") ## enum with holes type + RefT = (159, "ref") ## `ref` type + MutT = (160, "mut") ## `mut` type + OutT = (161, "out") ## `out` type + LentT = (162, "lent") ## `lent` type + SinkT = (163, "sink") ## `sink` type + NiltT = (164, "nilt") ## `nilt` type + ConceptT = (165, "concept") ## `concept` type + DistinctT = (166, "distinct") ## `distinct` type + ItertypeT = (167, "itertype") ## `itertype` type + RangetypeT = (168, "rangetype") ## `rangetype` type + UarrayT = (169, "uarray") ## `uarray` type + OpenarrayT = (170, "openarray") ## `openarray` type + SetT = (171, "set") ## `set` type + AutoT = (172, "auto") ## `auto` type + SymkindT = (173, "symkind") ## `symkind` type + TypekindT = (174, "typekind") ## `typekind` type + TypedescT = (175, "typedesc") ## `typedesc` type + UntypedT = (176, "untyped") ## `untyped` type + TypedT = (177, "typed") ## `typed` type + CstringT = (178, "cstring") ## `cstring` type + PointerT = (179, "pointer") ## `pointer` type + OrdinalT = (180, "ordinal") ## `ordinal` type proc rawTagIsNimonyType*(raw: uint32): bool {.inline.} = - raw <= 255'u32 and raw.uint8 in {1'u8, 3'u8, 15'u8, 16'u8, 17'u8, 63'u8, 92'u8, 94'u8, 95'u8, 96'u8, 100'u8, 101'u8, 102'u8, 103'u8, 104'u8, 105'u8, 106'u8, 107'u8, 122'u8, 145'u8, 154'u8, 155'u8, 156'u8, 157'u8, 158'u8, 159'u8, 160'u8, 161'u8, 162'u8, 163'u8, 164'u8, 165'u8, 166'u8, 167'u8, 168'u8, 169'u8, 170'u8, 171'u8, 172'u8, 173'u8, 174'u8, 175'u8, 176'u8, 177'u8, 178'u8, 179'u8} + raw <= 255'u32 and raw.uint8 in {1'u8, 3'u8, 15'u8, 16'u8, 17'u8, 63'u8, 92'u8, 94'u8, 95'u8, 96'u8, 101'u8, 102'u8, 103'u8, 104'u8, 105'u8, 106'u8, 107'u8, 108'u8, 123'u8, 146'u8, 155'u8, 156'u8, 157'u8, 158'u8, 159'u8, 160'u8, 161'u8, 162'u8, 163'u8, 164'u8, 165'u8, 166'u8, 167'u8, 168'u8, 169'u8, 170'u8, 171'u8, 172'u8, 173'u8, 174'u8, 175'u8, 176'u8, 177'u8, 178'u8, 179'u8, 180'u8} type NimonyOther* = enum @@ -214,50 +214,50 @@ type ElseU = (79, "else") ## `else` action TypevarsU = (80, "typevars") ## type variable/generic parameters OfU = (86, "of") ## `of` branch within a `case` statement - PragmasU = (125, "pragmas") ## begin of pragma section - UnpackflatU = (150, "unpackflat") ## unpack into flat variable list - UnpacktupU = (151, "unpacktup") ## unpack tuple - ExceptU = (152, "except") ## except subsection - FinU = (153, "fin") ## finally subsection + PragmasU = (126, "pragmas") ## begin of pragma section + UnpackflatU = (151, "unpackflat") ## unpack into flat variable list + UnpacktupU = (152, "unpacktup") ## unpack tuple + ExceptU = (153, "except") ## except subsection + FinU = (154, "fin") ## finally subsection proc rawTagIsNimonyOther*(raw: uint32): bool {.inline.} = - raw <= 255'u32 and raw.uint8 in {28'u8, 48'u8, 49'u8, 53'u8, 58'u8, 59'u8, 60'u8, 78'u8, 79'u8, 80'u8, 86'u8, 125'u8, 150'u8, 151'u8, 152'u8, 153'u8} + raw <= 255'u32 and raw.uint8 in {28'u8, 48'u8, 49'u8, 53'u8, 58'u8, 59'u8, 60'u8, 78'u8, 79'u8, 80'u8, 86'u8, 126'u8, 151'u8, 152'u8, 153'u8, 154'u8} type NimonyPragma* = enum NoPragma EmitP = (73, "emit") ## emit statement - InlineP = (119, "inline") ## `inline` proc annotation - NoinlineP = (120, "noinline") ## `noinline` proc annotation - VarargsP = (122, "varargs") ## `varargs` proc annotation - SelectanyP = (124, "selectany") - AlignP = (126, "align") - BitsP = (127, "bits") - NodeclP = (130, "nodecl") ## `nodecl` annotation - RaisesP = (143, "raises") ## proc annotation - MagicP = (180, "magic") ## `magic` pragma - ImportcP = (181, "importc") ## `importc` pragma - ImportcppP = (182, "importcpp") ## `importcpp` pragma - ExportcP = (183, "exportc") ## `exportc` pragma - HeaderP = (184, "header") ## `header` pragma - ThreadvarP = (185, "threadvar") ## `threadvar` pragma - GlobalP = (186, "global") ## `global` pragma - DiscardableP = (187, "discardable") ## `discardable` pragma - NoreturnP = (188, "noreturn") ## `noreturn` pragma - BorrowP = (189, "borrow") ## `borrow` pragma - NoSideEffectP = (190, "noSideEffect") ## `noSideEffect` pragma - NodestroyP = (191, "nodestroy") ## `nodestroy` pragma - PluginP = (192, "plugin") ## `plugin` pragma - BycopyP = (193, "bycopy") ## `bycopy` pragma - ByrefP = (194, "byref") ## `byref` pragma - NoinitP = (195, "noinit") ## `noinit` pragma - RequiresP = (196, "requires") ## `requires` pragma - EnsuresP = (197, "ensures") ## `ensures` pragma - BuildP = (198, "build") ## `build` pragma - StringP = (199, "string") ## `string` pragma + InlineP = (120, "inline") ## `inline` proc annotation + NoinlineP = (121, "noinline") ## `noinline` proc annotation + VarargsP = (123, "varargs") ## `varargs` proc annotation + SelectanyP = (125, "selectany") + AlignP = (127, "align") + BitsP = (128, "bits") + NodeclP = (131, "nodecl") ## `nodecl` annotation + RaisesP = (144, "raises") ## proc annotation + MagicP = (181, "magic") ## `magic` pragma + ImportcP = (182, "importc") ## `importc` pragma + ImportcppP = (183, "importcpp") ## `importcpp` pragma + ExportcP = (184, "exportc") ## `exportc` pragma + HeaderP = (185, "header") ## `header` pragma + ThreadvarP = (186, "threadvar") ## `threadvar` pragma + GlobalP = (187, "global") ## `global` pragma + DiscardableP = (188, "discardable") ## `discardable` pragma + NoreturnP = (189, "noreturn") ## `noreturn` pragma + BorrowP = (190, "borrow") ## `borrow` pragma + NoSideEffectP = (191, "noSideEffect") ## `noSideEffect` pragma + NodestroyP = (192, "nodestroy") ## `nodestroy` pragma + PluginP = (193, "plugin") ## `plugin` pragma + BycopyP = (194, "bycopy") ## `bycopy` pragma + ByrefP = (195, "byref") ## `byref` pragma + NoinitP = (196, "noinit") ## `noinit` pragma + RequiresP = (197, "requires") ## `requires` pragma + EnsuresP = (198, "ensures") ## `ensures` pragma + BuildP = (199, "build") ## `build` pragma + StringP = (200, "string") ## `string` pragma proc rawTagIsNimonyPragma*(raw: uint32): bool {.inline.} = - raw <= 255'u32 and raw.uint8 in {73'u8, 119'u8, 120'u8, 122'u8, 124'u8, 126'u8, 127'u8, 130'u8, 143'u8, 180'u8, 181'u8, 182'u8, 183'u8, 184'u8, 185'u8, 186'u8, 187'u8, 188'u8, 189'u8, 190'u8, 191'u8, 192'u8, 193'u8, 194'u8, 195'u8, 196'u8, 197'u8, 198'u8, 199'u8} + raw <= 255'u32 and raw.uint8 in {73'u8, 120'u8, 121'u8, 123'u8, 125'u8, 127'u8, 128'u8, 131'u8, 144'u8, 181'u8, 182'u8, 183'u8, 184'u8, 185'u8, 186'u8, 187'u8, 188'u8, 189'u8, 190'u8, 191'u8, 192'u8, 193'u8, 194'u8, 195'u8, 196'u8, 197'u8, 198'u8, 199'u8, 200'u8} type NimonySym* = enum @@ -289,11 +289,11 @@ proc rawTagIsNimonySym*(raw: uint32): bool {.inline.} = type ControlFlowKind* = enum NoControlFlow - IteF = (146, "ite") ## if-then-else - GraphF = (147, "graph") ## disjoint subgraph annotation - ForbindF = (148, "forbind") ## bindings for a `for` loop but the loop itself is mapped to gotos - KillF = (149, "kill") ## some.var is about to disappear (scope exit) + IteF = (147, "ite") ## if-then-else + GraphF = (148, "graph") ## disjoint subgraph annotation + ForbindF = (149, "forbind") ## bindings for a `for` loop but the loop itself is mapped to gotos + KillF = (150, "kill") ## some.var is about to disappear (scope exit) proc rawTagIsControlFlowKind*(raw: uint32): bool {.inline.} = - raw >= 146'u32 and raw <= 149'u32 + raw >= 147'u32 and raw <= 150'u32 diff --git a/src/models/tags.nim b/src/models/tags.nim index ceb5892b..4c1e4582 100644 --- a/src/models/tags.nim +++ b/src/models/tags.nim @@ -101,152 +101,153 @@ const ("atomic", 97), ("ro", 98), ("restrict", 99), - ("i", 100), - ("u", 101), - ("f", 102), - ("c", 103), - ("bool", 104), - ("void", 105), - ("ptr", 106), - ("array", 107), - ("flexarray", 108), - ("aptr", 109), - ("cdecl", 110), - ("stdcall", 111), - ("safecall", 112), - ("syscall", 113), - ("fastcall", 114), - ("thiscall", 115), - ("noconv", 116), - ("member", 117), - ("nimcall", 118), - ("inline", 119), - ("noinline", 120), - ("attr", 121), - ("varargs", 122), - ("was", 123), - ("selectany", 124), - ("pragmas", 125), - ("align", 126), - ("bits", 127), - ("vector", 128), - ("imp", 129), - ("nodecl", 130), - ("incl", 131), - ("excl", 132), - ("include", 133), - ("import", 134), - ("from", 135), - ("importexcept", 136), - ("export", 137), - ("comment", 138), - ("discard", 139), - ("try", 140), - ("raise", 141), - ("onerr", 142), - ("raises", 143), - ("errs", 144), - ("static", 145), - ("ite", 146), - ("graph", 147), - ("forbind", 148), - ("kill", 149), - ("unpackflat", 150), - ("unpacktup", 151), - ("except", 152), - ("fin", 153), - ("refobj", 154), - ("ptrobj", 155), - ("tuple", 156), - ("onum", 157), - ("ref", 158), - ("mut", 159), - ("out", 160), - ("lent", 161), - ("sink", 162), - ("nilt", 163), - ("concept", 164), - ("distinct", 165), - ("itertype", 166), - ("rangetype", 167), - ("uarray", 168), - ("openarray", 169), - ("set", 170), - ("auto", 171), - ("symkind", 172), - ("typekind", 173), - ("typedesc", 174), - ("untyped", 175), - ("typed", 176), - ("cstring", 177), - ("pointer", 178), - ("ordinal", 179), - ("magic", 180), - ("importc", 181), - ("importcpp", 182), - ("exportc", 183), - ("header", 184), - ("threadvar", 185), - ("global", 186), - ("discardable", 187), - ("noreturn", 188), - ("borrow", 189), - ("noSideEffect", 190), - ("nodestroy", 191), - ("plugin", 192), - ("bycopy", 193), - ("byref", 194), - ("noinit", 195), - ("requires", 196), - ("ensures", 197), - ("build", 198), - ("string", 199), - ("quoted", 200), - ("hderef", 201), - ("ddot", 202), - ("haddr", 203), - ("newobj", 204), - ("tup", 205), - ("setconstr", 206), - ("ashr", 207), - ("oconv", 208), - ("hconv", 209), - ("dconv", 210), - ("callstrlit", 211), - ("infix", 212), - ("prefix", 213), - ("hcall", 214), - ("compiles", 215), - ("declared", 216), - ("defined", 217), - ("high", 218), - ("low", 219), - ("typeof", 220), - ("unpack", 221), - ("enumtostr", 222), - ("ismainmodule", 223), - ("defaultobj", 224), - ("defaulttup", 225), - ("expr", 226), - ("arrat", 227), - ("tupat", 228), - ("plusset", 229), - ("minusset", 230), - ("mulset", 231), - ("xorset", 232), - ("eqset", 233), - ("leset", 234), - ("ltset", 235), - ("inset", 236), - ("card", 237), - ("emove", 238), - ("destroy", 239), - ("dup", 240), - ("copy", 241), - ("wasmoved", 242), - ("sinkh", 243), - ("trace", 244), - ("errv", 245) + ("cppref", 100), + ("i", 101), + ("u", 102), + ("f", 103), + ("c", 104), + ("bool", 105), + ("void", 106), + ("ptr", 107), + ("array", 108), + ("flexarray", 109), + ("aptr", 110), + ("cdecl", 111), + ("stdcall", 112), + ("safecall", 113), + ("syscall", 114), + ("fastcall", 115), + ("thiscall", 116), + ("noconv", 117), + ("member", 118), + ("nimcall", 119), + ("inline", 120), + ("noinline", 121), + ("attr", 122), + ("varargs", 123), + ("was", 124), + ("selectany", 125), + ("pragmas", 126), + ("align", 127), + ("bits", 128), + ("vector", 129), + ("imp", 130), + ("nodecl", 131), + ("incl", 132), + ("excl", 133), + ("include", 134), + ("import", 135), + ("from", 136), + ("importexcept", 137), + ("export", 138), + ("comment", 139), + ("discard", 140), + ("try", 141), + ("raise", 142), + ("onerr", 143), + ("raises", 144), + ("errs", 145), + ("static", 146), + ("ite", 147), + ("graph", 148), + ("forbind", 149), + ("kill", 150), + ("unpackflat", 151), + ("unpacktup", 152), + ("except", 153), + ("fin", 154), + ("refobj", 155), + ("ptrobj", 156), + ("tuple", 157), + ("onum", 158), + ("ref", 159), + ("mut", 160), + ("out", 161), + ("lent", 162), + ("sink", 163), + ("nilt", 164), + ("concept", 165), + ("distinct", 166), + ("itertype", 167), + ("rangetype", 168), + ("uarray", 169), + ("openarray", 170), + ("set", 171), + ("auto", 172), + ("symkind", 173), + ("typekind", 174), + ("typedesc", 175), + ("untyped", 176), + ("typed", 177), + ("cstring", 178), + ("pointer", 179), + ("ordinal", 180), + ("magic", 181), + ("importc", 182), + ("importcpp", 183), + ("exportc", 184), + ("header", 185), + ("threadvar", 186), + ("global", 187), + ("discardable", 188), + ("noreturn", 189), + ("borrow", 190), + ("noSideEffect", 191), + ("nodestroy", 192), + ("plugin", 193), + ("bycopy", 194), + ("byref", 195), + ("noinit", 196), + ("requires", 197), + ("ensures", 198), + ("build", 199), + ("string", 200), + ("quoted", 201), + ("hderef", 202), + ("ddot", 203), + ("haddr", 204), + ("newobj", 205), + ("tup", 206), + ("setconstr", 207), + ("ashr", 208), + ("oconv", 209), + ("hconv", 210), + ("dconv", 211), + ("callstrlit", 212), + ("infix", 213), + ("prefix", 214), + ("hcall", 215), + ("compiles", 216), + ("declared", 217), + ("defined", 218), + ("high", 219), + ("low", 220), + ("typeof", 221), + ("unpack", 222), + ("enumtostr", 223), + ("ismainmodule", 224), + ("defaultobj", 225), + ("defaulttup", 226), + ("expr", 227), + ("arrat", 228), + ("tupat", 229), + ("plusset", 230), + ("minusset", 231), + ("mulset", 232), + ("xorset", 233), + ("eqset", 234), + ("leset", 235), + ("ltset", 236), + ("inset", 237), + ("card", 238), + ("emove", 239), + ("destroy", 240), + ("dup", 241), + ("copy", 242), + ("wasmoved", 243), + ("sinkh", 244), + ("trace", 245), + ("errv", 246) ] const ErrTagId* = 1 @@ -348,149 +349,150 @@ const AtomicTagId* = 97 RoTagId* = 98 RestrictTagId* = 99 - ITagId* = 100 - UTagId* = 101 - FTagId* = 102 - CTagId* = 103 - BoolTagId* = 104 - VoidTagId* = 105 - PtrTagId* = 106 - ArrayTagId* = 107 - FlexarrayTagId* = 108 - AptrTagId* = 109 - CdeclTagId* = 110 - StdcallTagId* = 111 - SafecallTagId* = 112 - SyscallTagId* = 113 - FastcallTagId* = 114 - ThiscallTagId* = 115 - NoconvTagId* = 116 - MemberTagId* = 117 - NimcallTagId* = 118 - InlineTagId* = 119 - NoinlineTagId* = 120 - AttrTagId* = 121 - VarargsTagId* = 122 - WasTagId* = 123 - SelectanyTagId* = 124 - PragmasTagId* = 125 - AlignTagId* = 126 - BitsTagId* = 127 - VectorTagId* = 128 - ImpTagId* = 129 - NodeclTagId* = 130 - InclTagId* = 131 - ExclTagId* = 132 - IncludeTagId* = 133 - ImportTagId* = 134 - FromTagId* = 135 - ImportexceptTagId* = 136 - ExportTagId* = 137 - CommentTagId* = 138 - DiscardTagId* = 139 - TryTagId* = 140 - RaiseTagId* = 141 - OnerrTagId* = 142 - RaisesTagId* = 143 - ErrsTagId* = 144 - StaticTagId* = 145 - IteTagId* = 146 - GraphTagId* = 147 - ForbindTagId* = 148 - KillTagId* = 149 - UnpackflatTagId* = 150 - UnpacktupTagId* = 151 - ExceptTagId* = 152 - FinTagId* = 153 - RefobjTagId* = 154 - PtrobjTagId* = 155 - TupleTagId* = 156 - OnumTagId* = 157 - RefTagId* = 158 - MutTagId* = 159 - OutTagId* = 160 - LentTagId* = 161 - SinkTagId* = 162 - NiltTagId* = 163 - ConceptTagId* = 164 - DistinctTagId* = 165 - ItertypeTagId* = 166 - RangetypeTagId* = 167 - UarrayTagId* = 168 - OpenarrayTagId* = 169 - SetTagId* = 170 - AutoTagId* = 171 - SymkindTagId* = 172 - TypekindTagId* = 173 - TypedescTagId* = 174 - UntypedTagId* = 175 - TypedTagId* = 176 - CstringTagId* = 177 - PointerTagId* = 178 - OrdinalTagId* = 179 - MagicTagId* = 180 - ImportcTagId* = 181 - ImportcppTagId* = 182 - ExportcTagId* = 183 - HeaderTagId* = 184 - ThreadvarTagId* = 185 - GlobalTagId* = 186 - DiscardableTagId* = 187 - NoreturnTagId* = 188 - BorrowTagId* = 189 - NoSideEffectTagId* = 190 - NodestroyTagId* = 191 - PluginTagId* = 192 - BycopyTagId* = 193 - ByrefTagId* = 194 - NoinitTagId* = 195 - RequiresTagId* = 196 - EnsuresTagId* = 197 - BuildTagId* = 198 - StringTagId* = 199 - QuotedTagId* = 200 - HderefTagId* = 201 - DdotTagId* = 202 - HaddrTagId* = 203 - NewobjTagId* = 204 - TupTagId* = 205 - SetconstrTagId* = 206 - AshrTagId* = 207 - OconvTagId* = 208 - HconvTagId* = 209 - DconvTagId* = 210 - CallstrlitTagId* = 211 - InfixTagId* = 212 - PrefixTagId* = 213 - HcallTagId* = 214 - CompilesTagId* = 215 - DeclaredTagId* = 216 - DefinedTagId* = 217 - HighTagId* = 218 - LowTagId* = 219 - TypeofTagId* = 220 - UnpackTagId* = 221 - EnumtostrTagId* = 222 - IsmainmoduleTagId* = 223 - DefaultobjTagId* = 224 - DefaulttupTagId* = 225 - ExprTagId* = 226 - ArratTagId* = 227 - TupatTagId* = 228 - PlussetTagId* = 229 - MinussetTagId* = 230 - MulsetTagId* = 231 - XorsetTagId* = 232 - EqsetTagId* = 233 - LesetTagId* = 234 - LtsetTagId* = 235 - InsetTagId* = 236 - CardTagId* = 237 - EmoveTagId* = 238 - DestroyTagId* = 239 - DupTagId* = 240 - CopyTagId* = 241 - WasmovedTagId* = 242 - SinkhTagId* = 243 - TraceTagId* = 244 - ErrvTagId* = 245 + CpprefTagId* = 100 + ITagId* = 101 + UTagId* = 102 + FTagId* = 103 + CTagId* = 104 + BoolTagId* = 105 + VoidTagId* = 106 + PtrTagId* = 107 + ArrayTagId* = 108 + FlexarrayTagId* = 109 + AptrTagId* = 110 + CdeclTagId* = 111 + StdcallTagId* = 112 + SafecallTagId* = 113 + SyscallTagId* = 114 + FastcallTagId* = 115 + ThiscallTagId* = 116 + NoconvTagId* = 117 + MemberTagId* = 118 + NimcallTagId* = 119 + InlineTagId* = 120 + NoinlineTagId* = 121 + AttrTagId* = 122 + VarargsTagId* = 123 + WasTagId* = 124 + SelectanyTagId* = 125 + PragmasTagId* = 126 + AlignTagId* = 127 + BitsTagId* = 128 + VectorTagId* = 129 + ImpTagId* = 130 + NodeclTagId* = 131 + InclTagId* = 132 + ExclTagId* = 133 + IncludeTagId* = 134 + ImportTagId* = 135 + FromTagId* = 136 + ImportexceptTagId* = 137 + ExportTagId* = 138 + CommentTagId* = 139 + DiscardTagId* = 140 + TryTagId* = 141 + RaiseTagId* = 142 + OnerrTagId* = 143 + RaisesTagId* = 144 + ErrsTagId* = 145 + StaticTagId* = 146 + IteTagId* = 147 + GraphTagId* = 148 + ForbindTagId* = 149 + KillTagId* = 150 + UnpackflatTagId* = 151 + UnpacktupTagId* = 152 + ExceptTagId* = 153 + FinTagId* = 154 + RefobjTagId* = 155 + PtrobjTagId* = 156 + TupleTagId* = 157 + OnumTagId* = 158 + RefTagId* = 159 + MutTagId* = 160 + OutTagId* = 161 + LentTagId* = 162 + SinkTagId* = 163 + NiltTagId* = 164 + ConceptTagId* = 165 + DistinctTagId* = 166 + ItertypeTagId* = 167 + RangetypeTagId* = 168 + UarrayTagId* = 169 + OpenarrayTagId* = 170 + SetTagId* = 171 + AutoTagId* = 172 + SymkindTagId* = 173 + TypekindTagId* = 174 + TypedescTagId* = 175 + UntypedTagId* = 176 + TypedTagId* = 177 + CstringTagId* = 178 + PointerTagId* = 179 + OrdinalTagId* = 180 + MagicTagId* = 181 + ImportcTagId* = 182 + ImportcppTagId* = 183 + ExportcTagId* = 184 + HeaderTagId* = 185 + ThreadvarTagId* = 186 + GlobalTagId* = 187 + DiscardableTagId* = 188 + NoreturnTagId* = 189 + BorrowTagId* = 190 + NoSideEffectTagId* = 191 + NodestroyTagId* = 192 + PluginTagId* = 193 + BycopyTagId* = 194 + ByrefTagId* = 195 + NoinitTagId* = 196 + RequiresTagId* = 197 + EnsuresTagId* = 198 + BuildTagId* = 199 + StringTagId* = 200 + QuotedTagId* = 201 + HderefTagId* = 202 + DdotTagId* = 203 + HaddrTagId* = 204 + NewobjTagId* = 205 + TupTagId* = 206 + SetconstrTagId* = 207 + AshrTagId* = 208 + OconvTagId* = 209 + HconvTagId* = 210 + DconvTagId* = 211 + CallstrlitTagId* = 212 + InfixTagId* = 213 + PrefixTagId* = 214 + HcallTagId* = 215 + CompilesTagId* = 216 + DeclaredTagId* = 217 + DefinedTagId* = 218 + HighTagId* = 219 + LowTagId* = 220 + TypeofTagId* = 221 + UnpackTagId* = 222 + EnumtostrTagId* = 223 + IsmainmoduleTagId* = 224 + DefaultobjTagId* = 225 + DefaulttupTagId* = 226 + ExprTagId* = 227 + ArratTagId* = 228 + TupatTagId* = 229 + PlussetTagId* = 230 + MinussetTagId* = 231 + MulsetTagId* = 232 + XorsetTagId* = 233 + EqsetTagId* = 234 + LesetTagId* = 235 + LtsetTagId* = 236 + InsetTagId* = 237 + CardTagId* = 238 + EmoveTagId* = 239 + DestroyTagId* = 240 + DupTagId* = 241 + CopyTagId* = 242 + WasmovedTagId* = 243 + SinkhTagId* = 244 + TraceTagId* = 245 + ErrvTagId* = 246 diff --git a/src/nifc/genexprs.nim b/src/nifc/genexprs.nim index 39e9f3a6..4ef7c664 100644 --- a/src/nifc/genexprs.nim +++ b/src/nifc/genexprs.nim @@ -80,6 +80,19 @@ proc genCallCanRaise(c: var GeneratedCode; n: var Cursor) = c.add ParRi skipParRi n +proc genDeref(c: var GeneratedCode; n: var Cursor) = + inc n + c.add ParLe + let starAt = c.code.len + c.add "*" + genx c, n + c.add ParRi + if n.kind != ParRi and n.typeQual == CppRefQ: + if c.m.config.backend == backendCpp: + c.code[starAt] = Token EmptyToken + skip n + skipParRi n + proc genLvalue(c: var GeneratedCode; n: var Cursor) = case n.exprKind of NoExpr: @@ -90,7 +103,7 @@ proc genLvalue(c: var GeneratedCode; n: var Cursor) = inc n else: error c.m, "expected expression but got: ", n - of DerefC: unOp c, n, "*" + of DerefC: genDeref c, n of AtC: inc n let arrType = getType(c.m, n) @@ -186,11 +199,16 @@ proc genAddr(c: var GeneratedCode; n: var Cursor) = inc n let arrType = getType(c.m, n) c.add ParLe + let ampAt = c.code.len c.add "&" genx c, n if arrType.typeKind == ArrayT and not c.m.isImportC(arrType): c.add ".a" c.add ParRi + if n.kind != ParRi and n.typeQual == CppRefQ: + if c.m.config.backend == backendCpp: + c.code[ampAt] = Token EmptyToken + skip n skipParRi n proc genx(c: var GeneratedCode; n: var Cursor) = diff --git a/src/nifc/gentypes.nim b/src/nifc/gentypes.nim index 8b999f31..bc295a55 100644 --- a/src/nifc/gentypes.nim +++ b/src/nifc/gentypes.nim @@ -212,10 +212,10 @@ proc getNumberQualifier(c: var GeneratedCode; n: Cursor): string = else: # TODO: cpp doesn't support _Atomic result = "" - of RestrictQ, NoQualifier: + of RestrictQ, NoQualifier, CppRefQ: error c.m, "expected number qualifier but got: ", n -proc getPtrQualifier(c: var GeneratedCode; n: Cursor): string = +proc getPtrQualifier(c: var GeneratedCode; n: Cursor; isCppRef: var bool): string = case n.typeQual of RoQ: result = "const " @@ -227,6 +227,10 @@ proc getPtrQualifier(c: var GeneratedCode; n: Cursor): string = result = "" of RestrictQ: result = "restrict " + of CppRefQ: + if c.m.config.backend == backendCpp: + isCppRef = true + result = "" of NoQualifier: error c.m, "expected pointer qualifier but got: ", n @@ -265,12 +269,16 @@ proc atomPointer(c: var GeneratedCode; n: var Cursor; name: string) = inc n var elem = n skip n # element type + var isCppRef = false while n.kind != ParRi: - c.add getPtrQualifier(c, n) + c.add getPtrQualifier(c, n, isCppRef) skip n inc n # ParRi genType c, elem - c.add Star + if isCppRef: + c.add "&" + else: + c.add Star maybeAddName(c, name) proc genProcType(c: var GeneratedCode; n: var Cursor; name = "") =