# HG changeset patch # User unc0rr # Date 1334001312 -14400 # Node ID 6528171ce36d9f30bcf167310967f4fb78d7ea04 # Parent b9e2e509a42dd374d776d622934b32b7a104afba First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source. diff -r b9e2e509a42d -r 6528171ce36d hedgewars/pas2c.h --- /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; + diff -r b9e2e509a42d -r 6528171ce36d tools/PascalParser.hs --- 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 diff -r b9e2e509a42d -r 6528171ce36d tools/pas2c.hs --- 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 "<>" type2C' (Sequence ids) = do mapM_ (id2C IOInsert) ids