Debian Codegraph @

c2hs/state/C2HSState.hs

raw symbols SCIP
1 -- C -> Haskell Compiler: C2HS's state
2 --
3 -- Author : Manuel M. T. Chakravarty
4 -- Created: 6 March 1999
5 --
6 -- Version $Revision: 1.1 $ from $Date: 2004/11/21 21:05:41 $
7 --
8 -- Copyright (c) 1999 Manuel M. T. Chakravarty
9 --
10 -- This file is free software; you can redistribute it and/or modify
11 -- it under the terms of the GNU General Public License as published by
12 -- the Free Software Foundation; either version 2 of the License, or
13 -- (at your option) any later version.
14 --
15 -- This file is distributed in the hope that it will be useful,
16 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
17 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 -- GNU General Public License for more details.
19 --
20 --- DESCRIPTION ---------------------------------------------------------------
21 --
22 -- This module instantiates the Compiler Toolkit's extra state with C2HS's
23 -- uncommon state information that should be stored in the Toolkit's base
24 -- state.
25 --
26 -- This modules re-exports everything provided by `State', and thus, should be
27 -- used as the single reference to state related functionality within C2HS.
28 --
29 --- DOCU ----------------------------------------------------------------------
30 --
31 -- language: Haskell 98
32 --
33 -- State components:
34 --
35 -- - compiler switches
36 --
37 --- TODO ----------------------------------------------------------------------
38 --
39
40 module C2HSState (-- re-exports all of `State'
41 --
42 module State,
43 --
44 -- instantiation of `PreCST' with C2HS's extra state
45 --
46 CST, runC2HS,
47 --
48 -- switches
49 --
50 SwitchBoard(..), Traces(..), setTraces, traceSet,
51 putTraceStr, setSwitch, getSwitch)
52 where
53
54 import Control.Monad (when)
55
56 import State
57
58 import Switches (SwitchBoard(..), Traces(..),
59 initialSwitchBoard)
60
61
62 -- instantiation of the extra state
63 -- --------------------------------
64
65 -- the extra state consists of the `SwitchBoard' (EXPORTED)
66 --
67 type CST s a = PreCST SwitchBoard s a
68
69 -- execution of c2hs starts with the initial `SwitchBoard'
70 --
71 runC2HS :: (String, String, String) -> CST () a -> IO a
72 runC2HS vcd = run vcd initialSwitchBoard
73
74
75 -- switch management
76 -- -----------------
77
78 -- set traces according to the given transformation function
79 --
80 setTraces :: (Traces -> Traces) -> CST s ()
81 setTraces t = updExtra (\es -> es {tracesSB = t (tracesSB es)})
82
83 -- inquire the status a trace using the given inquiry function
84 --
85 traceSet :: (Traces -> Bool) -> CST s Bool
86 traceSet t = readExtra (t . tracesSB)
87
88 -- output the given string to `stderr' when the trace determined by the inquiry
89 -- function is activated
90 --
91 putTraceStr :: (Traces -> Bool) -> String -> CST s ()
92 putTraceStr t msg = do
93 set <- traceSet t
94 when set $
95 hPutStrCIO stderr msg
96
97 -- set a switch value
98 --
99 setSwitch :: (SwitchBoard -> SwitchBoard) -> CST s ()
100 setSwitch = updExtra
101
102 -- get a switch values
103 --
104 getSwitch :: (SwitchBoard -> a) -> CST s a
105 getSwitch = readExtra