Support operator 'in', replace it with equality checks against each element of set
authorunc0rr
Fri, 11 May 2012 22:35:09 +0400
changeset 7057 c3eba84d1a98
parent 7056 2884c7be6691
child 7058 56596f3531d9
Support operator 'in', replace it with equality checks against each element of set
tools/pas2c.hs
--- a/tools/pas2c.hs	Fri May 11 22:17:39 2012 +0400
+++ b/tools/pas2c.hs	Fri May 11 22:35:09 2012 +0400
@@ -685,6 +685,12 @@
             -- aw, "LongInt" here is hwengine-specific hack
             i <- op2CTyped op [SimpleType (Identifier t1 undefined), SimpleType (Identifier "LongInt" undefined)]
             ref2C $ FunCall [expr1, expr2] (SimpleReference i)
+        ("in", _, _) -> 
+            case expr2 of
+                 SetExpression set -> do
+                     ids <- mapM (id2C IOLookup) set
+                     return . parens . hcat . punctuate (text " || ") . map (\i -> parens $ e1 <+> text "==" <+> i) $ ids
+                 _ -> error "'in' against not set expression"
         (o, _, _) | o `elem` boolOps -> do
                         modify(\s -> s{lastType = BTBool})
                         return $ parens e1 <+> text o <+> parens e2