aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2022-08-09 15:40:31 -0700
committerMichael Forney <mforney@mforney.org>2022-11-29 11:41:26 -0800
commit830cf3293387ce41325d32308d024ad273ba4ef0 (patch)
treeff2268764b7e6f1ec516c4c9fd6f3a3b8e8f79b8
parent8a3ed28569f14bfde94cd7a75fa89c356caf459c (diff)
Implement C23 predefined bool constants
-rw-r--r--expr.c6
-rw-r--r--test/const-false.c2
-rw-r--r--test/const-false.qbe1
-rw-r--r--test/const-true.c2
-rw-r--r--test/const-true.qbe1
5 files changed, 12 insertions, 0 deletions
diff --git a/expr.c b/expr.c
index 1fe280c..1423248 100644
--- a/expr.c
+++ b/expr.c
@@ -688,6 +688,12 @@ primaryexpr(struct scope *s)
}
next();
break;
+ case TTRUE:
+ case TFALSE:
+ e = mkexpr(EXPRCONST, &typebool, NULL);
+ e->u.constant.u = tok.kind == TTRUE;
+ next();
+ break;
case TLPAREN:
next();
e = expr(s);
diff --git a/test/const-false.c b/test/const-false.c
new file mode 100644
index 0000000..65e743d
--- /dev/null
+++ b/test/const-false.c
@@ -0,0 +1,2 @@
+bool x = false;
+typeof(false) x;
diff --git a/test/const-false.qbe b/test/const-false.qbe
new file mode 100644
index 0000000..90a4475
--- /dev/null
+++ b/test/const-false.qbe
@@ -0,0 +1 @@
+export data $x = align 1 { b 0, }
diff --git a/test/const-true.c b/test/const-true.c
new file mode 100644
index 0000000..971963f
--- /dev/null
+++ b/test/const-true.c
@@ -0,0 +1,2 @@
+bool x = true;
+typeof(true) x;
diff --git a/test/const-true.qbe b/test/const-true.qbe
new file mode 100644
index 0000000..4fe9ed9
--- /dev/null
+++ b/test/const-true.qbe
@@ -0,0 +1 @@
+export data $x = align 1 { b 1, }