diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-08-05T13·05+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-08-05T13·05+0000 |
commit | d34b4d4f287a62de915a4bf75caf18d236e9b7e4 (patch) | |
tree | 7b1200905f906e683b3d4ed03d328e646c0bb527 /src | |
parent | b9c9b461ea3a90d7344a76c072b1f9a3e9d77144 (diff) |
* Conditionals.
Diffstat (limited to 'src')
-rw-r--r-- | src/fix.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/fix.cc b/src/fix.cc index 8f72d531c8c7..9111cd372733 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, "<str>", &s1) || ATmatch(e, "[<list>]", &e1) || + ATmatch(e, "True") || + ATmatch(e, "False") || ATmatch(e, "Function([<list>], <term>)", &e1, &e2) || ATmatch(e, "FSId(<str>)", &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(<term>, <term>, <term>)", &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(<term>, <term>)", &e1, &e2)) { + e1 = evalExpr(state, e1); + e2 = evalExpr(state, e2); + + char * s1, * s2; + if (!ATmatch(e1, "<str>", &s1)) + throw badTerm("expecting a string", e1); + if (!ATmatch(e2, "<str>", &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("<str>", SYSTEM); + } + /* Fix inclusion. */ if (ATmatch(e, "IncludeFix(<str>)", &s1)) { string fileName(s1); |