aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/anarres/cpp/Preprocessor.java
diff options
context:
space:
mode:
authorShevek <[email protected]>2014-09-11 12:20:05 -0700
committerShevek <[email protected]>2014-09-11 12:20:05 -0700
commitcccd60f37a31113a42372672670ce2a2bc529684 (patch)
tree479b0bb354da25cdb8707e8b27baa49e2f9b12c5 /src/main/java/org/anarres/cpp/Preprocessor.java
parent2db1eafd535d8db92f76db8ccf45b1b80f6152e3 (diff)
Handle conditionals in preprocessor statements.
Diffstat (limited to 'src/main/java/org/anarres/cpp/Preprocessor.java')
-rw-r--r--src/main/java/org/anarres/cpp/Preprocessor.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/main/java/org/anarres/cpp/Preprocessor.java b/src/main/java/org/anarres/cpp/Preprocessor.java
index 0d14b53..192ac45 100644
--- a/src/main/java/org/anarres/cpp/Preprocessor.java
+++ b/src/main/java/org/anarres/cpp/Preprocessor.java
@@ -1514,7 +1514,7 @@ public class Preprocessor implements Closeable {
tok = expr_token();
if (tok.getType() != ')') {
expr_untoken(tok);
- error(tok, "missing ) in expression");
+ error(tok, "Missing ) in expression. Got " + tok.getText());
return 0;
}
break;
@@ -1628,8 +1628,17 @@ public class Preprocessor implements Closeable {
lhs = (lhs != 0) || (rhs != 0) ? 1 : 0;
break;
- case '?':
- /* XXX Handle this? */
+ case '?': {
+ tok = expr_token();
+ if (tok.getType() != ':') {
+ expr_untoken(tok);
+ error(tok, "Missing : in conditional expression. Got " + tok.getText());
+ return 0;
+ }
+ long falseResult = expr(0);
+ lhs = (lhs != 0) ? rhs : falseResult;
+ }
+ break;
default:
error(op,