aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2020-03-16 02:09:59 -0700
committerMichael Forney <mforney@mforney.org>2020-03-17 15:22:51 -0700
commitbad98e94caf37db71f8114bdb8562a7caa4fb256 (patch)
treee238ce199becccaf9f940685ba8cb27c2c74737d /test
parent19b816b032dfc01a49f7f86ae7c411a0f15fd2bc (diff)
downloadcproc-bad98e94caf37db71f8114bdb8562a7caa4fb256.tar.xz
pp: Add support for macro definition and expansion
The token pasting operator `##` still needs to be implemented.
Diffstat (limited to 'test')
-rw-r--r--test/preprocess-macro-function-paren.c4
-rw-r--r--test/preprocess-macro-function-paren.pp2
-rw-r--r--test/preprocess-macro-function.c2
-rw-r--r--test/preprocess-macro-function.pp1
-rw-r--r--test/preprocess-macro-hide.c2
-rw-r--r--test/preprocess-macro-hide.pp1
-rw-r--r--test/preprocess-macro-object.c2
-rw-r--r--test/preprocess-macro-object.pp1
-rw-r--r--test/preprocess-macro-stringize.c2
-rw-r--r--test/preprocess-macro-stringize.pp1
-rw-r--r--test/preprocess-standard-example-1.c4
-rw-r--r--test/preprocess-standard-example-1.pp1
-rw-r--r--test/preprocess-standard-example-2.c20
-rw-r--r--test/preprocess-standard-example-2.pp4
-rw-r--r--test/preprocess-undef.c3
-rw-r--r--test/preprocess-undef.pp1
16 files changed, 51 insertions, 0 deletions
diff --git a/test/preprocess-macro-function-paren.c b/test/preprocess-macro-function-paren.c
new file mode 100644
index 0000000..c7c7639
--- /dev/null
+++ b/test/preprocess-macro-function-paren.c
@@ -0,0 +1,4 @@
+#define g(x) [x]
+#define f(a) g a (def)
+f((abc))
+f()
diff --git a/test/preprocess-macro-function-paren.pp b/test/preprocess-macro-function-paren.pp
new file mode 100644
index 0000000..6d86709
--- /dev/null
+++ b/test/preprocess-macro-function-paren.pp
@@ -0,0 +1,2 @@
+[abc] (def)
+[def]
diff --git a/test/preprocess-macro-function.c b/test/preprocess-macro-function.c
new file mode 100644
index 0000000..87b4c07
--- /dev/null
+++ b/test/preprocess-macro-function.c
@@ -0,0 +1,2 @@
+#define f(a, b) a, abc, b
+f(foo, bar)
diff --git a/test/preprocess-macro-function.pp b/test/preprocess-macro-function.pp
new file mode 100644
index 0000000..c8109cd
--- /dev/null
+++ b/test/preprocess-macro-function.pp
@@ -0,0 +1 @@
+foo, abc, bar
diff --git a/test/preprocess-macro-hide.c b/test/preprocess-macro-hide.c
new file mode 100644
index 0000000..22671c7
--- /dev/null
+++ b/test/preprocess-macro-hide.c
@@ -0,0 +1,2 @@
+#define foo foo bar
+foo
diff --git a/test/preprocess-macro-hide.pp b/test/preprocess-macro-hide.pp
new file mode 100644
index 0000000..d675fa4
--- /dev/null
+++ b/test/preprocess-macro-hide.pp
@@ -0,0 +1 @@
+foo bar
diff --git a/test/preprocess-macro-object.c b/test/preprocess-macro-object.c
new file mode 100644
index 0000000..f4c8b21
--- /dev/null
+++ b/test/preprocess-macro-object.c
@@ -0,0 +1,2 @@
+#define foo bar
+foo
diff --git a/test/preprocess-macro-object.pp b/test/preprocess-macro-object.pp
new file mode 100644
index 0000000..5716ca5
--- /dev/null
+++ b/test/preprocess-macro-object.pp
@@ -0,0 +1 @@
+bar
diff --git a/test/preprocess-macro-stringize.c b/test/preprocess-macro-stringize.c
new file mode 100644
index 0000000..528c88e
--- /dev/null
+++ b/test/preprocess-macro-stringize.c
@@ -0,0 +1,2 @@
+#define stringize(a) #a
+stringize(hello)
diff --git a/test/preprocess-macro-stringize.pp b/test/preprocess-macro-stringize.pp
new file mode 100644
index 0000000..3580093
--- /dev/null
+++ b/test/preprocess-macro-stringize.pp
@@ -0,0 +1 @@
+"hello"
diff --git a/test/preprocess-standard-example-1.c b/test/preprocess-standard-example-1.c
new file mode 100644
index 0000000..84447e0
--- /dev/null
+++ b/test/preprocess-standard-example-1.c
@@ -0,0 +1,4 @@
+/* C11 6.10.3.4p4 */
+#define f(a) a*g
+#define g(a) f(a)
+f(2)(9)
diff --git a/test/preprocess-standard-example-1.pp b/test/preprocess-standard-example-1.pp
new file mode 100644
index 0000000..738d396
--- /dev/null
+++ b/test/preprocess-standard-example-1.pp
@@ -0,0 +1 @@
+2*9*g
diff --git a/test/preprocess-standard-example-2.c b/test/preprocess-standard-example-2.c
new file mode 100644
index 0000000..0deb2ad
--- /dev/null
+++ b/test/preprocess-standard-example-2.c
@@ -0,0 +1,20 @@
+/* C11 6.10.3.5p5 with token concatenation disabled for now */
+#define x 3
+#define f(a) f(x * (a))
+#undef x
+#define x 2
+#define g f
+#define z z[0]
+#define h g(~
+#define m(a) a(w)
+#define w 0,1
+#define t(a) a
+#define p() int
+#define q(x) x
+//#define r(x,y) x ## y
+#define str(x) # x
+f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);
+g(x+(3,4)-w) | h 5) & m
+ (f)^m(m);
+p() i[q()] = { q(1), /*r(2,3), r(4,), r(,5), r(,)*/ };
+char c[2][6] = { str(hello), str() };
diff --git a/test/preprocess-standard-example-2.pp b/test/preprocess-standard-example-2.pp
new file mode 100644
index 0000000..3a52eb0
--- /dev/null
+++ b/test/preprocess-standard-example-2.pp
@@ -0,0 +1,4 @@
+f(2 * (y+1)) +f(2 * (f(2 * (z[0])))) %f(2 * (0)) + t(1);
+f(2 * (2+(3,4)-0,1)) |f(2 * (~ 5)) &f(2 * (0,1))^m(0,1);
+int i[] = {1, };
+char c[2][6] = {"hello","" };
diff --git a/test/preprocess-undef.c b/test/preprocess-undef.c
new file mode 100644
index 0000000..c43f9ea
--- /dev/null
+++ b/test/preprocess-undef.c
@@ -0,0 +1,3 @@
+#define foo bar
+#undef foo
+foo
diff --git a/test/preprocess-undef.pp b/test/preprocess-undef.pp
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/test/preprocess-undef.pp
@@ -0,0 +1 @@
+foo