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 :: forall s. String -> CST s (AttrC, String)
loadAttrC String
fname = do
String -> CST s ()
forall {s}. String -> CST s ()
traceInfoRead String
fname
contents <- String -> PreCST SwitchBoard s String
forall e s. String -> PreCST e s String
readFileCIO String
fname
traceInfoParse
rawHeader <- parseC contents (Position fname 1 1)
let header = CHeader -> AttrC
attrC CHeader
rawHeader
traceInfoNA
headerWithAttrs <- nameAnalysis header
errs <- errorsPresent
if errs
then do
traceInfoErr
errmsgs <- showErrors
fatal ("C header contains \
\errors:\n\n" ++ errmsgs)
else do
traceInfoOK
warnmsgs <- showErrors
return (headerWithAttrs, 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")