This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[PATCH] Support || and && in preprocessor's conditions.
- From: Przemyslaw Pawelczyk <przemyslaw at pawelczyk dot it>
- To: systemtap at sourceware dot org
- Date: Sat, 20 Jun 2009 15:17:42 +0200
- Subject: [PATCH] Support || and && in preprocessor's conditions.
- Mail-from: c7826ba6c0c6469df0369d5e8c1a7950cd78aa3a Mon Sep 17 00:00:00 2001
- References: <1245456101.314490.18432@debian>
---
parse.cxx | 30 ++++++++++++++++++++++++++++--
1 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/parse.cxx b/parse.cxx
index a26d594..a74b513 100644
--- a/parse.cxx
+++ b/parse.cxx
@@ -332,16 +332,42 @@ parser::scan_pp (bool wildcard)
// 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);
+ bool and_result = eval_pp_conditional (session, l, op, r);
delete l;
delete op;
delete r;
+ bool result = false;
+ const token *n;
+ while ((n = input.scan ()) && n->type == tok_operator)
+ {
+ if (n->content == "||")
+ {
+ result |= and_result;
+ and_result = true;
+ }
+ else if (n->content != "&&")
+ break;
+ l = input.scan (false);
+ op = input.scan (false);
+ r = input.scan (false);
+ if (l == 0 || op == 0 || r == 0)
+ throw parse_error ("incomplete condition after '%('", t);
+
+ and_result &= eval_pp_conditional (session, l, op, r);
+ delete l;
+ delete op;
+ delete r;
+ delete n;
+ }
+
+ result |= and_result;
+
/*
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; // "%?"
--
1.5.6.5