tools/pas2c.hs
changeset 7040 4aff2da0d0b3
parent 7039 e7dc6ddd1e29
child 7042 de20086a6bcc
equal deleted inserted replaced
7039:e7dc6ddd1e29 7040:4aff2da0d0b3
   522              BTRecord _ -> return $ \a -> text "struct __" <> i' <+> text "*" <+> a
   522              BTRecord _ -> return $ \a -> text "struct __" <> i' <+> text "*" <+> a
   523              BTUnknown -> return $ \a -> text "struct __" <> i' <+> text "*" <+> a
   523              BTUnknown -> return $ \a -> text "struct __" <> i' <+> text "*" <+> a
   524              _ -> return $ \a -> i' <+> text "*" <+> a
   524              _ -> return $ \a -> i' <+> text "*" <+> a
   525     type2C' (PointerTo t) = liftM (\t a -> t (parens $ text "*" <> a)) $ type2C t
   525     type2C' (PointerTo t) = liftM (\t a -> t (parens $ text "*" <> a)) $ type2C t
   526     type2C' (RecordType tvs union) = do
   526     type2C' (RecordType tvs union) = do
   527         t <- withState' id $ mapM (tvar2C False) tvs
   527         t <- withState' f $ mapM (tvar2C False) tvs
   528         u <- unions
   528         u <- unions
   529         return $ \i -> text "struct __" <> i <+> lbrace $+$ nest 4 ((vcat . map (<> semi) . concat $ t) $$ u) $+$ rbrace <+> i
   529         return $ \i -> text "struct __" <> i <+> lbrace $+$ nest 4 ((vcat . map (<> semi) . concat $ t) $$ u) $+$ rbrace <+> i
   530         where
   530         where
       
   531             f s = s{currentUnit = ""}
   531             unions = case union of
   532             unions = case union of
   532                      Nothing -> return empty
   533                      Nothing -> return empty
   533                      Just a -> do
   534                      Just a -> do
   534                          structs <- mapM struct2C a
   535                          structs <- mapM struct2C a
   535                          return $ text "union" $+$ braces (nest 4 $ vcat structs) <> semi
   536                          return $ text "union" $+$ braces (nest 4 $ vcat structs) <> semi
   536             struct2C tvs = do
   537             struct2C tvs = do
   537                 t <- withState' id $ mapM (tvar2C False) tvs
   538                 t <- withState' f $ mapM (tvar2C False) tvs
   538                 return $ text "struct" $+$ braces (nest 4 (vcat . map (<> semi) . concat $ t)) <> semi
   539                 return $ text "struct" $+$ braces (nest 4 (vcat . map (<> semi) . concat $ t)) <> semi
   539     type2C' (RangeType r) = return (text "int" <+>)
   540     type2C' (RangeType r) = return (text "int" <+>)
   540     type2C' (Sequence ids) = do
   541     type2C' (Sequence ids) = do
   541         is <- mapM (id2C IOInsert . setBaseType bt) ids
   542         is <- mapM (id2C IOInsert . setBaseType bt) ids
   542         return (text "enum" <+> (braces . vcat . punctuate comma . map (\(a, b) -> a <+> equals <+> text "0x" <> text (showHex b "")) $ zip is [1..]) <+>)
   543         return (text "enum" <+> (braces . vcat . punctuate comma . map (\(a, b) -> a <+> equals <+> text "0x" <> text (showHex b "")) $ zip is [1..]) <+>)