[PATCH qbe2c 1/2] Use binary search for keyword detection
Export this patch
Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
unparse.ha | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/unparse.ha b/unparse.ha
index 95fb32f..fcba5b1 100644
--- a/unparse.ha
+++ b/unparse.ha
@@ -68,11 +68,7 @@ const keywords: [_]str = [
"while",
];
-fn iskeyword(n: str) bool = {
- let i = 0z;
- for (i < len(keywords) && strings::compare(keywords[i], n) < 0) i += 1;
- return i < len(keywords) && keywords[i] == n;
-};
+fn iskeyword(n: str) bool = sort::searchstrings(keywords, n) is size;
fn name(c: *ctx, n: (str | qbe::temp | datatype)) (void | io::error) = {
if (!(n is qbe::temp || n is datatype || strings::contains(n: str, '.', '$') ||
--
2.38.1
[PATCH qbe2c 2/2] Add C23 keywords
Export this patch
Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
unparse.ha | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/unparse.ha b/unparse.ha
index fcba5b1..923800e 100644
--- a/unparse.ha
+++ b/unparse.ha
@@ -13,6 +13,7 @@ const keywords: [_]str = [
"_Alignas",
"_Alignof",
"_Atomic",
+ "_BitInt",
"_Bool",
"_Complex",
"_Generic",
@@ -32,11 +33,15 @@ const keywords: [_]str = [
"__typeof",
"__typeof__",
"__volatile__",
+ "alignas",
+ "alignof",
"auto",
+ "bool",
"break",
"case",
"char",
"const",
+ "constexpr",
"continue",
"default",
"do",
@@ -44,6 +49,7 @@ const keywords: [_]str = [
"else",
"enum",
"extern",
+ "false",
"float",
"for",
"goto",
@@ -51,6 +57,7 @@ const keywords: [_]str = [
"inline",
"int",
"long",
+ "nullexpr",
"register",
"restrict",
"return",
@@ -60,7 +67,11 @@ const keywords: [_]str = [
"static",
"struct",
"switch",
+ "thread_local",
+ "true",
"typedef",
+ "typeof",
+ "typeof_unqual",
"union",
"unsigned",
"void",
--
2.38.1