First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/pas2c.h Mon Apr 09 23:55:12 2012 +0400
@@ -0,0 +1,13 @@
+#pragma once
+
+typedef char string255[];
+
+typedef int SmallInt;
+typedef int Word;
+typedef int LongInt;
+typedef int LongWord;
+typedef int Byte;
+typedef Byte * PByte;
+
+typedef void * pointer;
+
--- a/tools/PascalParser.hs Mon Apr 09 23:36:23 2012 +0400
+++ b/tools/PascalParser.hs Mon Apr 09 23:55:12 2012 +0400
@@ -113,7 +113,7 @@
comments
e <- initExpression
comments
- return $ VarDeclaration False ([i], fromMaybe (DeriveType e) t) (Just e)
+ return $ VarDeclaration (isNothing t) ([i], fromMaybe (DeriveType e) t) (Just e)
typeDecl = choice [
char '^' >> typeDecl >>= return . PointerTo
--- a/tools/pas2c.hs Mon Apr 09 23:36:23 2012 +0400
+++ b/tools/pas2c.hs Mon Apr 09 23:55:12 2012 +0400
@@ -305,13 +305,13 @@
tvar2C _ td@(TypeDeclaration i' t) = do
i <- id2CTyped t i'
tp <- type2C t
- return $ text "typedef" <+> i <+> tp <> semi
+ return $ text "typedef" <+> tp <+> i <> semi
tvar2C _ (VarDeclaration isConst (ids, t) mInitExpr) = do
t' <- type2C t
i <- mapM (id2CTyped t) ids
ie <- initExpr mInitExpr
- return $ if isConst then text "const" else empty
+ return $ (if isConst then text "const" else empty)
<+> t'
<+> (hsep . punctuate (char ',') $ i)
<+> ie
@@ -368,11 +368,11 @@
where
type2C' VoidType = return $ text "void"
type2C' (String l) = return $ text $ "string" ++ show l
- type2C' (PointerTo (SimpleType i)) = liftM (<> text "*") $ id2C IODeferred i
+ type2C' (PointerTo (SimpleType i)) = liftM (\i -> text "struct" <+> i <+> text "*") $ id2C IODeferred i
type2C' (PointerTo t) = liftM (<> text "*") $ type2C t
type2C' (RecordType tvs union) = do
t <- withState' id $ mapM (tvar2C False) tvs
- return $ lbrace $+$ (nest 4 . vcat $ t) $+$ rbrace
+ return $ text "struct" <+> lbrace $+$ (nest 4 . vcat $ t) $+$ rbrace
type2C' (RangeType r) = return $ text "<<range type>>"
type2C' (Sequence ids) = do
mapM_ (id2C IOInsert) ids