From d34b4d4f287a62de915a4bf75caf18d236e9b7e4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 5 Aug 2003 13:05:30 +0000 Subject: * Conditionals. --- src/fix.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src') diff --git a/src/fix.cc b/src/fix.cc index 8f72d531c..9111cd372 100644 --- a/src/fix.cc +++ b/src/fix.cc @@ -146,6 +146,8 @@ static Expr evalExpr2(EvalState & state, Expr e) /* Normal forms. */ if (ATmatch(e, "", &s1) || ATmatch(e, "[]", &e1) || + ATmatch(e, "True") || + ATmatch(e, "False") || ATmatch(e, "Function([], )", &e1, &e2) || ATmatch(e, "FSId()", &s1)) return e; @@ -167,6 +169,37 @@ static Expr evalExpr2(EvalState & state, Expr e) substExprMany((ATermList) e3, (ATermList) e2, e4)); } + /* Conditional. */ + if (ATmatch(e, "If(, , )", &e1, &e2, &e3)) { + e1 = evalExpr(state, e1); + Expr x; + if (ATmatch(e1, "True")) x = e2; + else if (ATmatch(e1, "False")) x = e3; + else throw badTerm("expecting a boolean", e1); + return evalExpr(state, x); + } + + /* Ad-hoc function for string matching. */ + if (ATmatch(e, "HasSubstr(, )", &e1, &e2)) { + e1 = evalExpr(state, e1); + e2 = evalExpr(state, e2); + + char * s1, * s2; + if (!ATmatch(e1, "", &s1)) + throw badTerm("expecting a string", e1); + if (!ATmatch(e2, "", &s2)) + throw badTerm("expecting a string", e2); + + return + string(s1).find(string(s2)) != string::npos ? + ATmake("True") : ATmake("False"); + } + + /* Platform constant. */ + if (ATmatch(e, "Platform")) { + return ATmake("", SYSTEM); + } + /* Fix inclusion. */ if (ATmatch(e, "IncludeFix()", &s1)) { string fileName(s1); -- cgit v1.2.3