tools/pas2c.hs
changeset 6520 6fecdc5d182f
parent 6517 67ea290ea843
child 6552 91adc9ee7b8c
equal deleted inserted replaced
6519:b0dc69bb1f54 6520:6fecdc5d182f
    70     extractTVs (System tv) = tv
    70     extractTVs (System tv) = tv
    71     extractTVs (Program {}) = []
    71     extractTVs (Program {}) = []
    72     extractTVs (Unit _ (Interface _ (TypesAndVars tv)) _ _ _) = tv
    72     extractTVs (Unit _ (Interface _ (TypesAndVars tv)) _ _ _) = tv
    73     
    73     
    74     tv2id :: TypeVarDeclaration -> [(String, String)]
    74     tv2id :: TypeVarDeclaration -> [(String, String)]
       
    75     tv2id (TypeDeclaration i (Sequence ids)) = map (\(Identifier i _) -> fi i) $ i : ids
    75     tv2id (TypeDeclaration (Identifier i _) _) = [(map toLower i, i)]
    76     tv2id (TypeDeclaration (Identifier i _) _) = [(map toLower i, i)]
    76     tv2id (VarDeclaration _ (ids, _) _) = map (\(Identifier i _) -> (map toLower i, i)) ids
    77     tv2id (VarDeclaration _ (ids, _) _) = map (\(Identifier i _) -> fi i) ids
    77     tv2id (FunctionDeclaration (Identifier i _) _ _ _) = [(map toLower i, i)]
    78     tv2id (FunctionDeclaration (Identifier i _) _ _ _) = [fi i]
    78     tv2id (OperatorDeclaration i _ _ _ _) = [(map toLower i, i)]
    79     tv2id (OperatorDeclaration i _ _ _ _) = [fi i]
       
    80     fi i = (map toLower i, i)
    79     
    81     
    80     
    82     
    81 toCFiles :: Map.Map String [(String, String)] -> (String, PascalUnit) -> IO ()
    83 toCFiles :: Map.Map String [(String, String)] -> (String, PascalUnit) -> IO ()
    82 toCFiles _ (_, System _) = return ()
    84 toCFiles _ (_, System _) = return ()
    83 toCFiles ns p@(fn, pu) = do
    85 toCFiles ns p@(fn, pu) = do
   212 
   214 
   213 type2C :: TypeDecl -> State RenderState Doc
   215 type2C :: TypeDecl -> State RenderState Doc
   214 type2C UnknownType = return $ text "void"
   216 type2C UnknownType = return $ text "void"
   215 type2C (String l) = return $ text $ "string" ++ show l
   217 type2C (String l) = return $ text $ "string" ++ show l
   216 type2C (SimpleType i) = id2C False i
   218 type2C (SimpleType i) = id2C False i
       
   219 type2C (PointerTo (SimpleType i)) = liftM (<> text "*") $ id2C True i
   217 type2C (PointerTo t) = liftM (<> text "*") $ type2C t
   220 type2C (PointerTo t) = liftM (<> text "*") $ type2C t
   218 type2C (RecordType tvs union) = do
   221 type2C (RecordType tvs union) = do
   219     t <- mapM (tvar2C False) tvs
   222     t <- mapM (tvar2C False) tvs
   220     return $ text "{" $+$ (nest 4 . vcat $ t) $+$ text "}"
   223     return $ text "{" $+$ (nest 4 . vcat $ t) $+$ text "}"
   221 type2C (RangeType r) = return $ text "<<range type>>"
   224 type2C (RangeType r) = return $ text "<<range type>>"
   222 type2C (Sequence ids) = return $ text "<<sequence type>>"
   225 type2C (Sequence ids) = do
       
   226     mapM_ (id2C True) ids
       
   227     return $ text "<<sequence type>>"
   223 type2C (ArrayDecl r t) = return $ text "<<array type>>"
   228 type2C (ArrayDecl r t) = return $ text "<<array type>>"
   224 type2C (Set t) = return $ text "<<set>>"
   229 type2C (Set t) = return $ text "<<set>>"
   225 type2C (FunctionType returnType params) = return $ text "<<function>>"
   230 type2C (FunctionType returnType params) = return $ text "<<function>>"
   226 
   231 
   227 phrase2C :: Phrase -> State RenderState Doc
   232 phrase2C :: Phrase -> State RenderState Doc