Skip to content

Commit

Permalink
[hl/c] fix reserved keywords (#11408)
Browse files Browse the repository at this point in the history
* [tests] update test for 11378

* [hlc] fix reserved keywords
  • Loading branch information
kLabz committed Nov 23, 2023
1 parent e60332d commit 92c197b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/generators/hl2c.ml
Expand Up @@ -98,13 +98,13 @@ let keywords =
"typeof";
(* C11 *)
"_Alignas";"_Alignof";"_Atomic";"_Bool";"_Complex";"_Generic";"_Imaginary";"_Noreturn";"_Static_assert";"_Thread_local";"_Pragma";
"inline";"restrict"
"inline";"restrict";"_restrict"
] in
let h = Hashtbl.create 0 in
List.iter (fun i -> Hashtbl.add h i ()) c_kwds;
h

let ident i = if (Hashtbl.mem keywords i) || (ExtString.String.starts_with "__" i) then "_hx_" ^ i else i
let ident i = if (Hashtbl.mem keywords i) || (ExtString.String.starts_with i "__") then "_hx_" ^ i else i

let s_comp = function
| CLt -> "<"
Expand Down
12 changes: 10 additions & 2 deletions tests/misc/hl/reservedKeywords/Macro.macro.hx
Expand Up @@ -19,19 +19,27 @@ class Macro {
"typeof",
// C11
"_Alignas", "_Alignof", "_Atomic", "_Bool", "_Complex", "_Generic", "_Imaginary", "_Noreturn", "_Static_assert", "_Thread_local", "_Pragma",
"inline", "restrict"
"inline", "restrict", "_restrict"
];

var pos = Context.currentPos();

for (k in keywords)
for (k in keywords) {
fields.push({
pos: pos,
name: "_test_" + k,
meta: [{pos: pos, name: ":native", params: [macro $v{k}]}],
kind: FVar(macro :String, null)
});

fields.push({
pos: pos,
name: "_test2_" + k,
meta: [{pos: pos, name: ":native", params: [macro $v{'__' + k}]}],
kind: FVar(macro :String, null)
});
}

return fields;
}
}

0 comments on commit 92c197b

Please sign in to comment.