tools/pas2c/Pas2C.hs
branchwebgl
changeset 8444 75db7bb8dce8
parent 8442 535a00ca0d35
parent 8020 00b1facf2805
child 8446 c18ba8726f5a
equal deleted inserted replaced
8340:46a9fde631f4 8444:75db7bb8dce8
   553 tvar2C _ _ _ _ (VarDeclaration True _ (ids, t) Nothing) = do
   553 tvar2C _ _ _ _ (VarDeclaration True _ (ids, t) Nothing) = do
   554     t' <- liftM ((empty <+>) . ) $ type2C t
   554     t' <- liftM ((empty <+>) . ) $ type2C t
   555     liftM (map(\i -> t' i)) $ mapM (id2CTyped2 (Just $ t' empty) (VarParamType t)) ids
   555     liftM (map(\i -> t' i)) $ mapM (id2CTyped2 (Just $ t' empty) (VarParamType t)) ids
   556 
   556 
   557 tvar2C _ externVar includeType ignoreInit (VarDeclaration _ isConst (ids, t) mInitExpr) = do
   557 tvar2C _ externVar includeType ignoreInit (VarDeclaration _ isConst (ids, t) mInitExpr) = do
   558     t' <- liftM (((if isConst then text "static const" else if externVar 
   558     t' <- liftM (((if isConst then text "static const" else if externVar
   559                                                                 then text "extern"
   559                                                                 then text "extern"
   560                                                                 else empty)
   560                                                                 else empty)
   561                    <+>) . ) $ type2C t
   561                    <+>) . ) $ type2C t
   562     ie <- initExpr mInitExpr
   562     ie <- initExpr mInitExpr
   563     lt <- gets lastType
   563     lt <- gets lastType
   573          (_, BTArray r _ _, [i], _) -> do
   573          (_, BTArray r _ _, [i], _) -> do
   574             i' <- id2CTyped t i
   574             i' <- id2CTyped t i
   575             ie' <- return $ case (r, mInitExpr, ignoreInit) of
   575             ie' <- return $ case (r, mInitExpr, ignoreInit) of
   576                 (RangeInfinite, Nothing, False) -> text "= NULL" -- force dynamic array to be initialized as NULL if not initialized at all
   576                 (RangeInfinite, Nothing, False) -> text "= NULL" -- force dynamic array to be initialized as NULL if not initialized at all
   577                 (_, _, _) -> ie
   577                 (_, _, _) -> ie
   578             result <- liftM (map(\i -> varDeclDecision isConst includeType (t' i) ie')) $ mapM (id2CTyped t) ids           
   578             result <- liftM (map(\i -> varDeclDecision isConst includeType (t' i) ie')) $ mapM (id2CTyped t) ids
   579             case (r, ignoreInit) of
   579             case (r, ignoreInit) of
   580                 (RangeInfinite, False) -> 
   580                 (RangeInfinite, False) ->
   581                     -- if the array is dynamic, add dimension info to it
   581                     -- if the array is dynamic, add dimension info to it
   582                     return $ [dimDecl] ++ result
   582                     return $ [dimDecl] ++ result
   583                     where 
   583                     where
   584                         arrayDimStr = show $ arrayDimension t
   584                         arrayDimStr = show $ arrayDimension t
   585                         arrayDimInitExp = text ("={" ++ ".dim = " ++ arrayDimStr ++ ", .a = {0, 0, 0, 0}}")
   585                         arrayDimInitExp = text ("={" ++ ".dim = " ++ arrayDimStr ++ ", .a = {0, 0, 0, 0}}")
   586                         dimDecl = varDeclDecision isConst includeType (text "fpcrtl_dimension_t" <+>  i' <> text "_dimension_info") arrayDimInitExp
   586                         dimDecl = varDeclDecision isConst includeType (text "fpcrtl_dimension_t" <+>  i' <> text "_dimension_info") arrayDimInitExp
   587                     
   587 
   588                 (_, _) -> return result
   588                 (_, _) -> return result
   589             
   589 
   590          _ -> liftM (map(\i -> varDeclDecision isConst includeType (t' i) ie)) $ mapM (id2CTyped2 (Just $ t' empty) t) ids
   590          _ -> liftM (map(\i -> varDeclDecision isConst includeType (t' i) ie)) $ mapM (id2CTyped2 (Just $ t' empty) t) ids
   591     where
   591     where
   592     initExpr Nothing = return $ empty
   592     initExpr Nothing = return $ empty
   593     initExpr (Just e) = liftM (text "=" <+>) (initExpr2C e)
   593     initExpr (Just e) = liftM (text "=" <+>) (initExpr2C e)
   594     varDeclDecision True True varStr expStr = varStr <+> expStr
   594     varDeclDecision True True varStr expStr = varStr <+> expStr