Properly track type in ref2CF, this fixes issues with functions returning strings used in expression (like "a" + line())
authorunc0rr
Fri, 11 May 2012 23:03:28 +0400
changeset 7060 861d6897917f
parent 7059 800dcaf979bf
child 7061 4e0fc59ab1ce
Properly track type in ref2CF, this fixes issues with functions returning strings used in expression (like "a" + line())
hedgewars/pas2c.h
tools/pas2c.hs
--- a/hedgewars/pas2c.h	Fri May 11 22:54:19 2012 +0400
+++ b/hedgewars/pas2c.h	Fri May 11 23:03:28 2012 +0400
@@ -47,6 +47,7 @@
 typedef Byte * PByte;
 typedef char * PChar;
 typedef LongInt * PLongInt;
+typedef LongWord * PLongWord;
 typedef Integer * PInteger;
 typedef int * PtrInt;
 
--- a/tools/pas2c.hs	Fri May 11 22:54:19 2012 +0400
+++ b/tools/pas2c.hs	Fri May 11 23:03:28 2012 +0400
@@ -664,7 +664,7 @@
 
 expr2C :: Expression -> State RenderState Doc
 expr2C (Expression s) = return $ text s
-expr2C (BinOp op expr1 expr2) = do
+expr2C b@(BinOp op expr1 expr2) = do
     e1 <- expr2C expr1
     t1 <- gets lastType
     e2 <- expr2C expr2
@@ -764,13 +764,17 @@
     i <- id2C IOLookup name
     t <- gets lastType
     case t of
-         BTFunction {} -> return $ i <> parens empty
+         BTFunction _ rt -> do
+             modify(\s -> s{lastType = rt})
+             return $ i <> parens empty
          _ -> return $ i
 ref2CF r@(RecordField (SimpleReference _) (SimpleReference _)) = do
     i <- ref2C r
     t <- gets lastType
     case t of
-         BTFunction {} -> return $ i <> parens empty
+         BTFunction _ rt -> do
+             modify(\s -> s{lastType = rt})
+             return $ i <> parens empty
          _ -> return $ i
 ref2CF r = ref2C r