Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/typechecker/typechecker.sml
ViewVC logotype

Diff of /branches/vis12/src/compiler/typechecker/typechecker.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2651, Thu May 29 21:31:37 2014 UTC revision 2652, Thu May 29 23:14:49 2014 UTC
# Line 21  Line 21 
21      structure TU = TypeUtil      structure TU = TypeUtil
22      structure U = Util      structure U = Util
23    
   (* variable properties to support warnings etc. *)  
     val {getFn=isUsed, setFn=markUsed} = Var.newFlag()          (* for unused variable warning *)  
     val {getFn=isShadowed, setFn=marShadowed} = Var.newFlag()   (* for shadowed decl warning *)  
   
24    (* exception to abort typechecking when we hit an error.  Eventually, we should continue    (* exception to abort typechecking when we hit an error.  Eventually, we should continue
25     * checking for more errors and not use this.     * checking for more errors and not use this.
26     *)     *)
27      exception TypeError      exception TypeError
28    
29      (* variable properties to support unused variable warning *)
30        val {getFn=isUsed, setFn=markUsed} = Var.newFlag()
31        val {setFn=(setLoc : AST.var * Error.location -> unit), getFn=getLoc, ...} =
32              Var.newProp(fn x => raise Fail("no location for " ^ Var.nameOf x))
33    
34      datatype scope      datatype scope
35        = GlobalScope        = GlobalScope
36        | FunctionScope of Ty.ty * Atom.atom        | FunctionScope of Ty.ty * Atom.atom
# Line 44  Line 45 
45        | scopeToString InitScope = "initialization"        | scopeToString InitScope = "initialization"
46    
47      type env = {      type env = {
48          scope : scope,          scope : scope,                          (* current scope *)
49          bindings : Error.location AtomMap.map,          bindings : Error.location AtomMap.map,  (* map from atoms to innermost binding location *)
50          env : Env.env          env : Env.env                           (* variable environment *)
51        }        }
52    
53      type context = Error.err_stream * Error.span      type context = Error.err_stream * Error.span
# Line 77  Line 78 
78              bindings = AtomMap.insert(bindings, f, Error.location cxt),              bindings = AtomMap.insert(bindings, f, Error.location cxt),
79              env=Env.insertFunc(env, f, Env.UserFun f')              env=Env.insertFunc(env, f, Env.UserFun f')
80            }            }
81      fun insertLocal ({scope, bindings, env}, cxt, x, x') = {      fun insertLocal ({scope, bindings, env}, cxt, x, x') = let
82              val loc = Error.location cxt
83              in
84                setLoc(x', loc);
85                {
86              scope=scope,              scope=scope,
87              bindings = AtomMap.insert(bindings, x, Error.location cxt),              bindings = AtomMap.insert(bindings, x, Error.location cxt),
88              env=Env.insertLocal(env, x, x')              env=Env.insertLocal(env, x, x')
89            }            }
90      fun insertGlobal ({scope, bindings, env}, cxt, x, x') = {            end
91        fun insertGlobal ({scope, bindings, env}, cxt, x, x') = let
92              val loc = Error.location cxt
93              in
94                setLoc(x', loc);
95                {
96              scope=scope,              scope=scope,
97              bindings = AtomMap.insert(bindings, x, Error.location cxt),                bindings = AtomMap.insert(bindings, x, loc),
98              env=Env.insertGlobal(env, x, x')              env=Env.insertGlobal(env, x, x')
99            }            }
100              end
101    
102      fun withContext ((errStrm, _), {span, tree}) =      fun withContext ((errStrm, _), {span, tree}) =
103            ((errStrm, span), tree)            ((errStrm, span), tree)
# Line 116  Line 127 
127            raise TypeError)            raise TypeError)
128      end (* local *)      end (* local *)
129    
130      (* check for redefinition of an identifier in the same scope *)
131    (* TODO: check for shadowing too? *)
132      fun checkForRedef (env : env, cxt : context, x) = (case AtomMap.find(#bindings env,x)      fun checkForRedef (env : env, cxt : context, x) = (case AtomMap.find(#bindings env,x)
133             of SOME loc => err (cxt, [             of SOME loc => err (cxt, [
134                    S "redefinition of ", A x, S ", previous definition at ",                    S "redefinition of ", A x, S ", previous definition at ",
# Line 124  Line 137 
137              | NONE => ()              | NONE => ()
138            (* end case *))            (* end case *))
139    
140      (* check for unused variables *)
141        fun checkUnused (cxt, x) = if not(isUsed x)
142              then warn (cxt, [
143                  S(Var.kindToString x), S " ", V x, S " declared at ",
144                  S(Error.locToString(getLoc x)), S " is unused"
145                ])
146              else ()
147    
148      val realZero = AST.E_Lit(Literal.Float(FloatLit.zero true))      val realZero = AST.E_Lit(Literal.Float(FloatLit.zero true))
149    
150    (* check a differentiation level, which must be >= 0 *)    (* check a differentiation level, which must be >= 0 *)

Legend:
Removed from v.2651  
changed lines
  Added in v.2652

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