Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hl/c] fix reserved keywords #11408

Merged
merged 2 commits into from Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}