merge
authormikade <redgrinner@gmail.com>
Sun, 25 Mar 2012 21:17:01 +0200
changeset 6821 d4f75843cf5d
parent 6820 7db9e89b3f80 (current diff)
parent 6817 daaf0834c4d2 (diff)
child 6822 206db098f8c5
merge
--- a/hedgewars/LuaPas.pas	Sun Mar 25 17:37:07 2012 +0200
+++ b/hedgewars/LuaPas.pas	Sun Mar 25 21:17:01 2012 +0200
@@ -912,7 +912,7 @@
 
 function lua_tostring(L : Plua_State; idx : LongInt) : AnsiString;
 begin
-    lua_tostring := SysUtils.StrPas(lua_tolstring(L, idx, nil));
+    lua_tostring := StrPas(lua_tolstring(L, idx, nil));
 end;
 
 function lua_open : Plua_State;
--- a/tools/pas2c.hs	Sun Mar 25 17:37:07 2012 +0200
+++ b/tools/pas2c.hs	Sun Mar 25 21:17:01 2012 +0200
@@ -27,6 +27,7 @@
 data RenderState = RenderState 
     {
         currentScope :: [Record],
+        lastIdentifier :: String,
         lastType :: BaseType,
         namespaces :: Map.Map String [Record]
     }
@@ -74,12 +75,19 @@
     where
     toNamespace :: Map.Map String [Record] -> PascalUnit -> [Record]
     toNamespace nss (System tvs) = 
-        currentScope $ execState (mapM_ (tvar2C True) tvs) (RenderState [] BTUnknown nss)
+        currentScope $ execState (mapM_ (tvar2C True) tvs) (RenderState [] "" BTUnknown nss)
     toNamespace _ (Program {}) = []
     toNamespace nss (Unit _ interface _ _ _) = 
-        currentScope $ execState (interface2C interface) (RenderState [] BTUnknown nss)
+        currentScope $ execState (interface2C interface) (RenderState [] "" BTUnknown nss)
 
    
+withLastIdNamespace :: State RenderState Doc -> State RenderState Doc
+withLastIdNamespace f = do
+    li <- gets lastIdentifier
+    nss <- gets namespaces
+    st <- gets id
+    return $ evalState f st{currentScope = fromMaybe [] $ Map.lookup li (namespaces st)}
+
 toCFiles :: Map.Map String [Record] -> (String, PascalUnit) -> IO ()
 toCFiles _ (_, System _) = return ()
 toCFiles ns p@(fn, pu) = do
@@ -91,7 +99,7 @@
         let (a, s) = runState (interface2C interface) initialState
         writeFile (fn ++ ".h") $ "#pragma once\n" ++ (render a)
         writeFile (fn ++ ".c") $ (render2C s . implementation2C) implementation
-    initialState = RenderState [] BTUnknown ns
+    initialState = RenderState [] "" BTUnknown ns
 
     render2C :: RenderState -> State RenderState Doc -> String
     render2C a = render . flip evalState a
@@ -153,7 +161,7 @@
     if isNothing v then 
         error $ "Not defined: '" ++ i' ++ "'\n" -- ++ show ns
         else 
-        let vv = snd $ fromJust v in modify (\s -> s{lastType = snd vv}) >> (return . text . fst $ vv)
+        let vv = snd $ fromJust v in modify (\s -> s{lastType = snd vv, lastIdentifier = fst vv}) >> (return . text . fst $ vv)
 id2C IODeferred (Identifier i t) = do
     let i' = map toLower i
     v <- gets $ find (\(a, _) -> a == i') . currentScope
@@ -385,12 +393,10 @@
 ref2C rf@(RecordField ref1 ref2) = do
     r1 <- ref2C ref1
     t <- gets lastType
-    ns <- gets currentScope
-    case t of
+    r2 <- case t of
         r@(BTRecord _) -> error $ show r
-        r@(BTUnit) -> error $ show r
+        r@(BTUnit) -> withLastIdNamespace $ ref2C ref2
         a -> error $ "dereferencing from " ++ show a ++ " - " ++ show rf
-    r2 <- ref2C ref2
     return $ 
         r1 <> text "." <> r2
 ref2C (Dereference ref) = liftM ((parens $ text "*") <>) $ ref2C ref