tools/pas2c/Pas2C.hs
changeset 15750 036263d63b05
parent 14357 3baee596a989
child 15752 f09db263bc2a
equal deleted inserted replaced
15749:82fd124e6512 15750:036263d63b05
   572 tvar2C _ _ _ _ (VarDeclaration True _ (ids, t) Nothing) = do
   572 tvar2C _ _ _ _ (VarDeclaration True _ (ids, t) Nothing) = do
   573     t' <- liftM ((empty <+>) . ) $ type2C t
   573     t' <- liftM ((empty <+>) . ) $ type2C t
   574     liftM (map(\i -> t' i)) $ mapM (id2CTyped2 (Just $ t' empty) (VarParamType t)) ids
   574     liftM (map(\i -> t' i)) $ mapM (id2CTyped2 (Just $ t' empty) (VarParamType t)) ids
   575 
   575 
   576 tvar2C _ externVar includeType ignoreInit (VarDeclaration _ isConst (ids, t) mInitExpr) = do
   576 tvar2C _ externVar includeType ignoreInit (VarDeclaration _ isConst (ids, t) mInitExpr) = do
   577     t' <- liftM (((if isConst then text "static const" else if externVar
   577     t' <- liftM ((declDetails <+>) . ) $ type2C t
   578                                                                 then text "extern"
       
   579                                                                 else empty)
       
   580                    <+>) . ) $ type2C t
       
   581     ie <- initExpr mInitExpr
   578     ie <- initExpr mInitExpr
   582     lt <- gets lastType
   579     lt <- gets lastType
   583     case (isConst, lt, ids, mInitExpr) of
   580     case (isConst, lt, ids, mInitExpr) of
   584          (True, BTInt _, [i], Just _) -> do
   581          (True, BTInt _, [i], Just _) -> do
   585              i' <- id2CTyped t i
   582              i' <- id2CTyped t i
   600                     -- if the array is dynamic, add dimension info to it
   597                     -- if the array is dynamic, add dimension info to it
   601                     return $ [dimDecl] ++ result
   598                     return $ [dimDecl] ++ result
   602                     where
   599                     where
   603                         arrayDimStr = show $ arrayDimension t
   600                         arrayDimStr = show $ arrayDimension t
   604                         arrayDimInitExp = text ("={" ++ ".dim = " ++ arrayDimStr ++ ", .a = {0, 0, 0, 0}}")
   601                         arrayDimInitExp = text ("={" ++ ".dim = " ++ arrayDimStr ++ ", .a = {0, 0, 0, 0}}")
   605                         dimDecl = varDeclDecision isConst includeType (text "fpcrtl_dimension_t" <+>  i' <> text "_dimension_info") arrayDimInitExp
   602                         dimDecl = varDeclDecision isConst includeType (declDetails <+> text "fpcrtl_dimension_t" <+>  i' <> text "_dimension_info") arrayDimInitExp
   606 
   603 
   607                 (_, _) -> return result
   604                 (_, _) -> return result
   608 
   605 
   609          _ -> liftM (map(\i -> varDeclDecision isConst includeType (t' i) ie)) $ mapM (id2CTyped2 (Just $ t' empty) t) ids
   606          _ -> liftM (map(\i -> varDeclDecision isConst includeType (t' i) ie)) $ mapM (id2CTyped2 (Just $ t' empty) t) ids
   610     where
   607     where
       
   608     declDetails = if isConst then text "static const" else if externVar
       
   609                                                             then text "extern"
       
   610                                                             else empty
   611     initExpr Nothing = return $ empty
   611     initExpr Nothing = return $ empty
   612     initExpr (Just e) = liftM (text "=" <+>) (initExpr2C e)
   612     initExpr (Just e) = liftM (text "=" <+>) (initExpr2C e)
   613     varDeclDecision True True varStr expStr = varStr <+> expStr
   613     varDeclDecision True True varStr expStr = varStr <+> expStr
   614     varDeclDecision False True varStr expStr = if externVar then varStr else varStr <+> expStr
   614     varDeclDecision False True varStr expStr = if externVar then varStr else varStr <+> expStr
   615     varDeclDecision False False varStr expStr = varStr <+> expStr
   615     varDeclDecision False False varStr expStr = varStr <+> expStr