(PointerTo (SimpleType _)) could be a pointer to a non-struct type
authorunc0rr
Thu, 10 May 2012 00:58:05 +0400
changeset 7034 e3639ce1d4f8
parent 7033 583049a98113
child 7035 823caba67738
(PointerTo (SimpleType _)) could be a pointer to a non-struct type
hedgewars/uTypes.pas
tools/pas2c.hs
--- a/hedgewars/uTypes.pas	Tue May 08 00:17:02 2012 +0400
+++ b/hedgewars/uTypes.pas	Thu May 10 00:58:05 2012 +0400
@@ -322,8 +322,8 @@
         voicepack: PVoicePack;
         end;
 
+    THHAmmo = array[0..cMaxSlotIndex, 0..cMaxSlotAmmoIndex] of TAmmo;
     PHHAmmo = ^THHAmmo;
-    THHAmmo = array[0..cMaxSlotIndex, 0..cMaxSlotAmmoIndex] of TAmmo;
 
     THedgehog = record
             Name: shortstring;
--- a/tools/pas2c.hs	Tue May 08 00:17:02 2012 +0400
+++ b/tools/pas2c.hs	Thu May 10 00:58:05 2012 +0400
@@ -270,9 +270,9 @@
     let i' = map toLower i
     v <- gets $ Map.lookup i' . currentScope
     if (isNothing v) then
-        return $ text i
+        modify (\s -> s{lastType = BTUnknown, lastIdentifier = i}) >> return (text i)
         else
-        return . text . fst . head . fromJust $ v
+        let vv = head $ fromJust v in modify (\s -> s{lastType = snd vv, lastIdentifier = fst vv}) >> (return . text . fst $ vv)
 
 id2CTyped :: TypeDecl -> Identifier -> State RenderState Doc
 id2CTyped t (Identifier i _) = do
@@ -517,7 +517,13 @@
     where
     type2C' VoidType = return (text "void" <+>)
     type2C' (String l) = return (text "string255" <+>)--return (text ("string" ++ show l) <+>)
-    type2C' (PointerTo (SimpleType i)) = liftM (\i a -> text "struct __" <> i <+> text "*" <+> a) $ id2C IODeferred i
+    type2C' (PointerTo (SimpleType i)) = do
+        i' <- id2C IODeferred i
+        lt <- gets lastType
+        case lt of
+             BTRecord _ -> return $ \a -> text "struct __" <> i' <+> text "*" <+> a
+             BTUnknown -> return $ \a -> text "struct __" <> i' <+> text "*" <+> a
+             _ -> return $ \a -> i' <+> text "*" <+> a
     type2C' (PointerTo t) = liftM (\t a -> t (parens $ text "*" <> a)) $ type2C t
     type2C' (RecordType tvs union) = do
         t <- withState' id $ mapM (tvar2C False) tvs