tools/pas2c.hs
changeset 8442 535a00ca0d35
parent 7529 058fcb451b37
equal deleted inserted replaced
8441:a00b0fa0dbd7 8442:535a00ca0d35
   500 tvar2C _ _ _ _ (VarDeclaration True _ (ids, t) Nothing) = do
   500 tvar2C _ _ _ _ (VarDeclaration True _ (ids, t) Nothing) = do
   501     t' <- liftM ((empty <+>) . ) $ type2C t
   501     t' <- liftM ((empty <+>) . ) $ type2C t
   502     liftM (map(\i -> t' i)) $ mapM (id2CTyped2 (Just $ t' empty) (VarParamType t)) ids
   502     liftM (map(\i -> t' i)) $ mapM (id2CTyped2 (Just $ t' empty) (VarParamType t)) ids
   503 
   503 
   504 tvar2C _ externVar includeType ignoreInit (VarDeclaration _ isConst (ids, t) mInitExpr) = do
   504 tvar2C _ externVar includeType ignoreInit (VarDeclaration _ isConst (ids, t) mInitExpr) = do
   505     t' <- liftM (((if isConst then text "static const" else if externVar 
   505     t' <- liftM (((if isConst then text "static const" else if externVar
   506                                                                 then text "extern"
   506                                                                 then text "extern"
   507                                                                 else empty)
   507                                                                 else empty)
   508                    <+>) . ) $ type2C t
   508                    <+>) . ) $ type2C t
   509     ie <- initExpr mInitExpr
   509     ie <- initExpr mInitExpr
   510     lt <- gets lastType
   510     lt <- gets lastType
   520          (_, BTArray r _ _, [i], _) -> do
   520          (_, BTArray r _ _, [i], _) -> do
   521             i' <- id2CTyped t i
   521             i' <- id2CTyped t i
   522             ie' <- return $ case (r, mInitExpr, ignoreInit) of
   522             ie' <- return $ case (r, mInitExpr, ignoreInit) of
   523                 (RangeInfinite, Nothing, False) -> text "= NULL" -- force dynamic array to be initialized as NULL if not initialized at all
   523                 (RangeInfinite, Nothing, False) -> text "= NULL" -- force dynamic array to be initialized as NULL if not initialized at all
   524                 (_, _, _) -> ie
   524                 (_, _, _) -> ie
   525             result <- liftM (map(\i -> varDeclDecision isConst includeType (t' i) ie')) $ mapM (id2CTyped t) ids           
   525             result <- liftM (map(\i -> varDeclDecision isConst includeType (t' i) ie')) $ mapM (id2CTyped t) ids
   526             case (r, ignoreInit) of
   526             case (r, ignoreInit) of
   527                 (RangeInfinite, False) -> 
   527                 (RangeInfinite, False) ->
   528                     -- if the array is dynamic, add dimension info to it
   528                     -- if the array is dynamic, add dimension info to it
   529                     return $ [dimDecl] ++ result
   529                     return $ [dimDecl] ++ result
   530                     where 
   530                     where
   531                         arrayDimStr = show $ arrayDimension t
   531                         arrayDimStr = show $ arrayDimension t
   532                         arrayDimInitExp = text ("={" ++ ".dim = " ++ arrayDimStr ++ ", .a = {0, 0, 0, 0}}")
   532                         arrayDimInitExp = text ("={" ++ ".dim = " ++ arrayDimStr ++ ", .a = {0, 0, 0, 0}}")
   533                         dimDecl = varDeclDecision isConst includeType (text "fpcrtl_dimension_t" <+>  i' <> text "_dimension_info") arrayDimInitExp
   533                         dimDecl = varDeclDecision isConst includeType (text "fpcrtl_dimension_t" <+>  i' <> text "_dimension_info") arrayDimInitExp
   534                     
   534 
   535                 (_, _) -> return result
   535                 (_, _) -> return result
   536             
   536 
   537          _ -> liftM (map(\i -> varDeclDecision isConst includeType (t' i) ie)) $ mapM (id2CTyped2 (Just $ t' empty) t) ids
   537          _ -> liftM (map(\i -> varDeclDecision isConst includeType (t' i) ie)) $ mapM (id2CTyped2 (Just $ t' empty) t) ids
   538     where
   538     where
   539     initExpr Nothing = return $ empty
   539     initExpr Nothing = return $ empty
   540     initExpr (Just e) = liftM (text "=" <+>) (initExpr2C e)
   540     initExpr (Just e) = liftM (text "=" <+>) (initExpr2C e)
   541     varDeclDecision True True varStr expStr = varStr <+> expStr
   541     varDeclDecision True True varStr expStr = varStr <+> expStr
   813     ph <- phrase2C . appendPhrase (BuiltInFunctionCall [Reference $ SimpleReference i'] (SimpleReference (Identifier inc BTUnknown))) $ wrapPhrase p
   813     ph <- phrase2C . appendPhrase (BuiltInFunctionCall [Reference $ SimpleReference i'] (SimpleReference (Identifier inc BTUnknown))) $ wrapPhrase p
   814     return . braces $
   814     return . braces $
   815         i <+> text "=" <+> e1 <> semi
   815         i <+> text "=" <+> e1 <> semi
   816         $$
   816         $$
   817         iType <+> iEnd <+> text "=" <+> e2 <> semi
   817         iType <+> iEnd <+> text "=" <+> e2 <> semi
   818         $$ 
   818         $$
   819         text "if" <+> (parens $ i <+> text "<=" <+> iEnd) <+> text "do" <+> ph <+>
   819         text "if" <+> (parens $ i <+> text "<=" <+> iEnd) <+> text "do" <+> ph <+>
   820         text "while" <> parens (i <+> text "!=" <+> iEnd <+> text add) <> semi
   820         text "while" <> parens (i <+> text "!=" <+> iEnd <+> text add) <> semi
   821     where
   821     where
   822         appendPhrase p (Phrases ps) = Phrases $ ps ++ [p]
   822         appendPhrase p (Phrases ps) = Phrases $ ps ++ [p]
   823 phrase2C (RepeatCycle e' p') = do
   823 phrase2C (RepeatCycle e' p') = do