tools/pas2c.hs
changeset 6399 a904c735979c
parent 6391 bd5851ab3157
child 6417 eae5900fd8a4
equal deleted inserted replaced
6397:6eb58ae8b510 6399:a904c735979c
    32 
    32 
    33 
    33 
    34 tvar2C :: TypeVarDeclaration -> Doc
    34 tvar2C :: TypeVarDeclaration -> Doc
    35 tvar2C (FunctionDeclaration (Identifier name) returnType Nothing) = 
    35 tvar2C (FunctionDeclaration (Identifier name) returnType Nothing) = 
    36     type2C returnType <+> text (name ++ "();")
    36     type2C returnType <+> text (name ++ "();")
    37 tvar2C (FunctionDeclaration (Identifier name) returnType (Just phrase)) = 
    37 tvar2C (FunctionDeclaration (Identifier name) returnType (Just (tvars, phrase))) = 
    38     type2C returnType <+> text (name ++ "()") 
    38     type2C returnType <+> text (name ++ "()") 
    39     $$
    39     $$
       
    40     text "{" $+$ (nest 4 $ typesAndVars2C tvars)
       
    41     $+$
    40     phrase2C phrase
    42     phrase2C phrase
       
    43     $+$ 
       
    44     text "}"
    41 tvar2C (TypeDeclaration (Identifier i) t) = text "type" <+> text i <+> type2C t <> text ";"
    45 tvar2C (TypeDeclaration (Identifier i) t) = text "type" <+> text i <+> type2C t <> text ";"
    42 tvar2C (VarDeclaration isConst (ids, t) mInitExpr) = 
    46 tvar2C (VarDeclaration isConst (ids, t) mInitExpr) = 
    43     if isConst then text "const" else empty
    47     if isConst then text "const" else empty
    44     <+>
    48     <+>
    45     type2C t
    49     type2C t
    64 
    68 
    65 initExpr2C _ = text "<<expression>>"
    69 initExpr2C _ = text "<<expression>>"
    66 
    70 
    67 type2C :: TypeDecl -> Doc
    71 type2C :: TypeDecl -> Doc
    68 type2C UnknownType = text "void"
    72 type2C UnknownType = text "void"
    69 type2C String = text "string"
    73 type2C (String l) = text $ "string" ++ show l
    70 type2C (SimpleType (Identifier i)) = text i
    74 type2C (SimpleType (Identifier i)) = text i
    71 type2C (PointerTo t) = type2C t <> text "*"
    75 type2C (PointerTo t) = type2C t <> text "*"
    72 type2C (RecordType tvs) = text "{" $+$ (nest 4 . vcat . map tvar2C $ tvs) $+$ text "}"
    76 type2C (RecordType tvs) = text "{" $+$ (nest 4 . vcat . map tvar2C $ tvs) $+$ text "}"
    73 type2C (RangeType r) = text "<<range type>>"
    77 type2C (RangeType r) = text "<<range type>>"
    74 type2C (Sequence ids) = text "<<sequence type>>"
    78 type2C (Sequence ids) = text "<<sequence type>>"