Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/ckit/src/ast/state-sig.sml
ViewVC logotype

Annotation of /sml/trunk/ckit/src/ast/state-sig.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1347 - (view) (download)

1 : dbm 597 (* Copyright (c) 1998 by Lucent Technologies *)
2 :    
3 :     (* --------------------------------------------------------------------
4 :     * State: a local structure for operating on context state during the build-ast
5 :     * (elaboration) phase.
6 :     * State includes:
7 :     * - a global symbol table (#globalEnv envContext)
8 :     * - a stack of local symbol tables (#localEnv envContext)
9 :     * - a stack of locations for error reporting (#locStack locContext)
10 :     * - a table of named type identifiers (uidTables.ttab)
11 :     * - a table of adornment types (uidTables.atab) giving the type for each expression
12 :     * - a table of adornment types (uidTables.implicits)
13 :     giving implicit coercions for each expression (if any)
14 :     * - a list of type identifiers (defined in the current "context")
15 :     * (tidsContext.newTids)
16 :     * - a stack of tables of switch statement labels (switchContext.switchLabels)
17 :     * --------------------------------------------------------------------
18 :     *)
19 :    
20 :     signature STATE =
21 :     sig
22 :    
23 :     (* finite map structures *)
24 :    
25 :     structure ST : ORD_MAP where type Key.ord_key = Symbol.symbol
26 : mblume 1347 structure IT : ORD_MAP where type Key.ord_key = LargeInt.int
27 : dbm 597
28 :    
29 :     (* environments *)
30 :    
31 :     type symtab = Bindings.symBinding ST.map
32 :     type env = symtab list (* local environment stack *)
33 :    
34 :    
35 :     (* global context types *)
36 :    
37 :     type uidTables =
38 :     {ttab : Tables.tidtab, (* type name table *)
39 :     atab : Tables.aidtab, (* adornment table *)
40 :     implicits : Tables.aidtab} (* "optional" adornment table -- for special casts *)
41 :    
42 :     type envContext =
43 :     {globalEnv : symtab ref, (* the global symbol table *)
44 :     localEnv : env ref} (* the local environment stack *)
45 :    
46 :    
47 :     (* local context types : temporary information used during elaboration *)
48 :    
49 :     (* tidsContext: sequence of tids of types created while processing a phrase *)
50 :     type tidsContext =
51 :     {newTids : Tid.uid list ref}
52 :    
53 :     (* tmpVariables: sequence of (pid, ty) pairs created while processing a phrase *)
54 :     (* used when inserting explicit coercions in the case of ++, --, += *)
55 :     type tmpVariables =
56 :     {newVariables : Ast.id list ref}
57 :    
58 :     (* for use in D *)
59 :     type typeContext =
60 :     {typeCxts : Ast.ctype option list ref}
61 :    
62 :     (* funContext: information for the current function def *)
63 :     type funContext =
64 :     {labelTab : (Ast.label * bool) ST.map ref,
65 :     gotos : Symbol.symbol list ref,
66 :     returnTy : Ast.ctype option ref}
67 :    
68 :     (* table for collecting switch labels while processing switch statements *)
69 :     type switchContext =
70 :     {switchLabels : {switchTab : unit IT.map, default : bool} list ref}
71 :    
72 :     type locContext = (* location context *)
73 :     {locStack : SourceMap.location list ref}
74 :    
75 :     (* global state components *)
76 :     type globalState =
77 :     {uidTables : uidTables,
78 :     envContext : envContext, (* contains some local working state in localEnv *)
79 :     errorState : Error.errorState}
80 :    
81 :     (* local, "working", state components, holding temporary information *)
82 :     type localState =
83 :     {locContext: locContext,
84 :     tidsContext : tidsContext,
85 :     tmpVariables : tmpVariables,
86 :     funContext: funContext,
87 :     switchContext: switchContext,
88 :     typeContext: typeContext}
89 :    
90 :     (* initial information for calling makeAst *)
91 :     datatype stateInfo
92 :     = STATE of uidTables * symtab (* state carried over from previous translation unit *)
93 :     | INITIAL (* no previous state *)
94 :    
95 :    
96 :     (* packages of functions to manipulate state implicitly *)
97 :    
98 :     type stateFuns =
99 :     {globalState : globalState,
100 :     localState : localState,
101 :     (* the state records, included in case direct access to the
102 :     * state is required (probably shouldn't be) *)
103 :    
104 :     locFuns :
105 :     {pushLoc : SourceMap.location -> unit,
106 :     (* push location onto location stack *)
107 :     popLoc : unit -> unit,
108 :     (* pop location stack *)
109 :     getLoc : unit -> SourceMap.location,
110 :     (* get top location from location stack *)
111 :     error : string -> unit,
112 :     (* report an error and its location *)
113 :     warn : string -> unit},
114 :     (* (if warnings are on) report a warning and its location *)
115 :    
116 :     tidsFuns :
117 :     {pushTids : Tid.uid -> unit,
118 :     (* records tids from new structs/unions/typdefs
119 :     * introduced in declarations, casts, etc. *)
120 :     resetTids : unit -> Tid.uid list},
121 :     (* returns list of recently generated tids (since last resetTids call) *)
122 :    
123 :     tmpVarsFuns :
124 :     {pushTmpVars : Ast.id -> unit,
125 :     (* records pids for temporary introduced in decompilation of ++, --, +=, and their friends *)
126 :     resetTmpVars : unit -> Ast.id list},
127 :     (* returns list of recently generated pids (since last resetTmpVars call) *)
128 :    
129 :     envFuns :
130 :     {topLevel : unit -> bool,
131 :     (* are we at top level? *)
132 :     pushLocalEnv : unit -> unit,
133 :     (* push a fresh symbol table onto the stack *)
134 :     popLocalEnv : unit -> unit,
135 :     (* pop symbol table stack *)
136 :     lookSym : Symbol.symbol -> Bindings.symBinding option,
137 :     (* lookup type of a symbol in symbol table stack *)
138 :     bindSym : Symbol.symbol * Bindings.symBinding -> unit,
139 :     (* insert (i.e. bind) a symbol in the top (most local) symbol table *)
140 :     lookSymGlobal : Symbol.symbol -> Bindings.symBinding option,
141 :     (* lookup type of a symbol in the global symbol table *)
142 :     bindSymGlobal : Symbol.symbol * Bindings.symBinding -> unit,
143 :     (* insert (i.e. bind) a symbol in the global symbol table *)
144 :     lookLocalScope : Symbol.symbol -> Bindings.symBinding option,
145 :     (* look for a binding in the most local symbol table *)
146 :     getGlobalEnv : unit -> symtab},
147 :     (* return the global symbol table *)
148 :    
149 :     uidTabFuns :
150 :     {bindAid : Ast.ctype -> Aid.uid,
151 :     (* generate a new adornment identifier and bind it to the type *)
152 :     lookAid : Aid.uid -> Ast.ctype option,
153 :     (* lookup adornment identifier in state aidtab *)
154 :     bindTid : Tid.uid * Bindings.tidBinding -> unit,
155 :     (* insert a type identifier into the type symbol table *)
156 :     lookTid : Tid.uid -> Bindings.tidBinding option},
157 :     (* lookup a type identifier in the type symbol table *)
158 :    
159 :     funFuns : (* manipulate current function context *)
160 :     {newFunction : Ast.ctype -> unit,
161 :     (* enter a new function context with the given return type *)
162 :     getReturnTy : unit -> Ast.ctype option,
163 :     (* get the return type of the current function context *)
164 :     checkLabels : unit -> (Symbol.symbol * SourceMap.location) option,
165 :     (* verify that all goto targets are defined as labels *)
166 :     addLabel : Symbol.symbol * SourceMap.location -> Ast.label,
167 :     (* define a label, returning an error flag if multiple defs *)
168 :     addGoto : Symbol.symbol * SourceMap.location -> Ast.label},
169 :     (* record a label as a goto target *)
170 :    
171 :     switchFuns : (* manipulate current switch context *)
172 :     {pushSwitchLabels : unit -> unit, (* enter a switch statement *)
173 :     popSwitchLabels : unit -> unit, (* leave a switch statement *)
174 : mblume 1347 addSwitchLabel : LargeInt.int -> string option,
175 : dbm 597 (* record a new switch label; returns SOME errormsg if duplicate
176 :     * or not within a switch *)
177 :     addDefaultLabel : unit -> string option}}
178 :     (* record a default label; returns SOME errormsg if multiple defaults,
179 :     * or not within a switch *)
180 :    
181 :     (* state initialization functions *)
182 :     val initGlobal : (stateInfo * Error.errorState) -> globalState
183 :     val initLocal : unit -> localState
184 :    
185 :     val stateFuns : globalState * localState -> stateFuns
186 :     (* returns a collection of state functions specialized to
187 :     * operate on the state passed as argument *)
188 :    
189 :     end (* sigature STATE *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0