module C (
Pos(posOf),
module CAST,
AttrC, getCHeader,
CObj(..), CTag(..), CDef(..), lookupDefObjC, lookupDefTagC,
getDefOfIdentC,
module CTrav,
module CPretty,
loadAttrC,
Ident, Attrs, Attr(..),
csuffix, hsuffix, isuffix)
where
import Position (Position(..), Pos(posOf))
import Idents (Ident, lexemeToIdent)
import Attributes (Attrs, Attr(..))
import C2HSState (CST, IOMode(..),
readCST, transCST, runCST, nop,
readFileCIO, writeFileCIO, openFileCIO, hCloseCIO,
fatal, errorsPresent, showErrors,
Traces(..), putTraceStr)
import CAST
import CParser (parseC)
import CPretty
import CAttrs (AttrC, attrC, getCHeader,
CObj(..), CTag(..), CDef(..), lookupDefObjC, lookupDefTagC,
getDefOfIdentC)
import CNames (nameAnalysis)
import CTrav
csuffix, hsuffix, isuffix :: String
csuffix :: String
csuffix = String
".c"
hsuffix :: String
hsuffix = String
".h"
isuffix :: String
isuffix = String
".i"
loadAttrC :: String -> CST s (AttrC, String)
loadAttrC :: String -> CST s (AttrC, String)
loadAttrC String
fname = do
String -> CST s ()
forall s. String -> CST s ()
traceInfoRead String
fname
String
contents <- String -> PreCST SwitchBoard s String
forall e s. String -> PreCST e s String
readFileCIO String
fname
CST s ()
forall s. CST s ()
traceInfoParse
CHeader
rawHeader <- String -> Position -> PreCST SwitchBoard s CHeader
forall s s'. String -> Position -> PreCST s s' CHeader
parseC String
contents (String -> Int -> Int -> Position
Position String
fname Int
1 Int
1)
let header :: AttrC
header = CHeader -> AttrC
attrC CHeader
rawHeader
CST s ()
forall s. CST s ()
traceInfoNA
AttrC
headerWithAttrs <- AttrC -> CST s AttrC
forall s. AttrC -> CST s AttrC
nameAnalysis AttrC
header
Bool
errs <- PreCST SwitchBoard s Bool
forall e s. PreCST e s Bool
errorsPresent
if Bool
errs
then do
CST s ()
forall s. CST s ()
traceInfoErr
String
errmsgs <- PreCST SwitchBoard s String
forall e s. PreCST e s String
showErrors
String -> CST s (AttrC, String)
forall e s a. String -> PreCST e s a
fatal (String
"C header contains \
\errors:\n\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
errmsgs)
else do
CST s ()
forall s. CST s ()
traceInfoOK
String
warnmsgs <- PreCST SwitchBoard s String
forall e s. PreCST e s String
showErrors
(AttrC, String) -> CST s (AttrC, String)
forall (m :: * -> *) a. Monad m => a -> m a
return (AttrC
headerWithAttrs, String
warnmsgs)
where
traceInfoRead :: String -> CST s ()
traceInfoRead String
fname = (Traces -> Bool) -> String -> CST s ()
forall s. (Traces -> Bool) -> String -> CST s ()
putTraceStr Traces -> Bool
tracePhasesSW
(String
"Attempting to read file `"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fname String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"'...\n")
traceInfoParse :: CST s ()
traceInfoParse = (Traces -> Bool) -> String -> CST s ()
forall s. (Traces -> Bool) -> String -> CST s ()
putTraceStr Traces -> Bool
tracePhasesSW
(String
"...parsing `"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fname String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"'...\n")
traceInfoNA :: CST s ()
traceInfoNA = (Traces -> Bool) -> String -> CST s ()
forall s. (Traces -> Bool) -> String -> CST s ()
putTraceStr Traces -> Bool
tracePhasesSW
(String
"...name analysis of `"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fname String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"'...\n")
traceInfoErr :: CST s ()
traceInfoErr = (Traces -> Bool) -> String -> CST s ()
forall s. (Traces -> Bool) -> String -> CST s ()
putTraceStr Traces -> Bool
tracePhasesSW
(String
"...error(s) detected in `"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fname String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"'.\n")
traceInfoOK :: CST s ()
traceInfoOK = (Traces -> Bool) -> String -> CST s ()
forall s. (Traces -> Bool) -> String -> CST s ()
putTraceStr Traces -> Bool
tracePhasesSW
(String
"...successfully loaded `"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fname String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"'.\n")