summaryrefslogtreecommitdiffstats
path: root/parse.cxx
diff options
context:
space:
mode:
authorPrzemyslaw Pawelczyk <przemyslaw@pawelczyk.it>2009-08-28 02:11:47 +0200
committerJosh Stone <jistone@redhat.com>2009-08-28 11:21:24 -0700
commit2d7881bf6e14d14fa1394f65f11b4d1dce4e2623 (patch)
tree85ca79b32737d42779c3b02fe0d290f6f9f25579 /parse.cxx
parenta4433a9da1f21c6536266531308ba231e5efae81 (diff)
downloadsystemtap-steved-2d7881bf6e14d14fa1394f65f11b4d1dce4e2623.tar.gz
systemtap-steved-2d7881bf6e14d14fa1394f65f11b4d1dce4e2623.tar.xz
systemtap-steved-2d7881bf6e14d14fa1394f65f11b4d1dce4e2623.zip
Support || and && in preprocessor's conditions.
* parse.cxx (parser::scan_pp): Add || and &&. * stap.1.in: Document || and && in PREPROCESSING. * testsuite/parseok/twenty.stp: Test case. * testsuite/parseko/preprocess14.stp: Ditto. * testsuite/parseko/preprocess15.stp: Ditto. Signed-off-by: Josh Stone <jistone@redhat.com>
Diffstat (limited to 'parse.cxx')
-rw-r--r--parse.cxx46
1 files changed, 30 insertions, 16 deletions
diff --git a/parse.cxx b/parse.cxx
index 41a13ca5..a2e2b656 100644
--- a/parse.cxx
+++ b/parse.cxx
@@ -321,27 +321,41 @@ parser::scan_pp (bool wildcard)
// We have a %( - it's time to throw a preprocessing party!
- const token *l, *op, *r;
- l = input.scan (false); // NB: not recursive, though perhaps could be
- op = input.scan (false);
- r = input.scan (false);
- if (l == 0 || op == 0 || r == 0)
- throw parse_error ("incomplete condition after '%('", t);
- // NB: consider generalizing to consume all tokens until %?, and
- // passing that as a vector to an evaluator.
-
- // Do not evaluate the condition if we haven't expanded everything.
- // This may occur when having several recursive conditionals.
- bool result = eval_pp_conditional (session, l, op, r);
- delete l;
- delete op;
- delete r;
+ bool result = false;
+ bool and_result = true;
+ const token *n = NULL;
+ do {
+ const token *l, *op, *r;
+ l = input.scan (false); // NB: not recursive, though perhaps could be
+ op = input.scan (false);
+ r = input.scan (false);
+ if (l == 0 || op == 0 || r == 0)
+ throw parse_error ("incomplete condition after '%('", t);
+ // NB: consider generalizing to consume all tokens until %?, and
+ // passing that as a vector to an evaluator.
+
+ // Do not evaluate the condition if we haven't expanded everything.
+ // This may occur when having several recursive conditionals.
+ and_result &= eval_pp_conditional (session, l, op, r);
+ delete l;
+ delete op;
+ delete r;
+ delete n;
+
+ n = input.scan ();
+ if (n && n->type == tok_operator && n->content == "&&")
+ continue;
+ result |= and_result;
+ and_result = true;
+ if (! (n && n->type == tok_operator && n->content == "||"))
+ break;
+ } while (true);
/*
clog << "PP eval (" << *t << ") == " << result << endl;
*/
- const token *m = input.scan (); // NB: not recursive
+ const token *m = n; // NB: not recursive
if (! (m && m->type == tok_operator && m->content == "%?"))
throw parse_error ("expected '%?' marker for conditional", t);
delete m; // "%?"