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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/typechecker/check-stmt.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/typechecker/check-stmt.sml

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

revision 4465, Tue Aug 30 13:07:08 2016 UTC revision 4466, Tue Aug 30 13:49:58 2016 UTC
# Line 101  Line 101 
101     * by simplify.     * by simplify.
102     *)     *)
103      fun chkCtlFlow (cxt, scope, stm) = let      fun chkCtlFlow (cxt, scope, stm) = let
104            val (inFun, inCreateOrUpdate, funName) = (case scope            val (inFun, inCreateOrUpdate, inGlobalBlock, funName) = (case scope
105                   of E.FunctionScope(_, f) => (true, false, Atom.toString f)                   of E.FunctionScope(_, f) => (true, false, false, Atom.toString f)
106                    | E.MethodScope(_, StrandUtil.Initially) => (false, true, "")                    | E.MethodScope(_, StrandUtil.Initially) => (false, true, false, "")
107                    | E.MethodScope(_, StrandUtil.Update) => (false, true, "")                    | E.MethodScope(_, StrandUtil.Update) => (false, true, false, "")
108                    | E.CreateScope => (false, true, "")                    | E.CreateScope => (false, true, false, "")
109                    | _ => (false, false, "")                    | E.InitiallyScope => (false, true, true, "")
110                      | E.UpdateScope => (false, true, true, "")
111                      | _ => (false, false, false, "")
112                  (* end case *))                  (* end case *))
113              val hasDieOrStabilize = ref false
114          (* checks a statement for correct control flow; it returns false if control may          (* checks a statement for correct control flow; it returns false if control may
115           * flow from the statement to the next in a sequence and true if control cannot           * flow from the statement to the next in a sequence and true if control cannot
116           * flow to the next statement.  The parameter flags have the following meaning:           * flow to the next statement.  The parameter flags have the following meaning:
# Line 158  Line 161 
161                    then err(cxt, [S "\"new\" statement outside of initially/update method"])                    then err(cxt, [S "\"new\" statement outside of initially/update method"])
162                    else ();                    else ();
163                  false)                  false)
             | chk (cxt, hasSucc, isJoin, unreachable, PT.S_Die) = (  
                 if not inCreateOrUpdate  
                   then err(cxt, [S "\"die\" statment outside of initially/update method"])  
                 else if hasSucc andalso not isJoin andalso not unreachable  
                   then warn(cxt, [S "statements following \"die\" statment are unreachable"])  
                   else ();  
                 true)  
164              | chk (cxt, hasSucc, isJoin, unreachable, PT.S_Continue) = (              | chk (cxt, hasSucc, isJoin, unreachable, PT.S_Continue) = (
165  (* QUESTION: should we allow "continue" in loops? *)  (* QUESTION: should we allow "continue" in loops? *)
166                  if not inCreateOrUpdate                  if not inCreateOrUpdate
# Line 174  Line 170 
170                    else ();                    else ();
171                  true)                  true)
172              | chk (cxt, hasSucc, isJoin, unreachable, PT.S_Stabilize) = (              | chk (cxt, hasSucc, isJoin, unreachable, PT.S_Stabilize) = (
173                    if (not unreachable) then hasDieOrStabilize := true else ();
174                  if not inCreateOrUpdate                  if not inCreateOrUpdate
175                    then err(cxt, [S "\"stabilize\" statment outside of initially/update method"])                    then err(cxt, [S "\"stabilize\" statment outside of initially/update method/block"])
176                  else if hasSucc andalso not isJoin andalso not unreachable                  else if hasSucc andalso not isJoin andalso not unreachable
177                    then warn(cxt, [S "statements following \"stabilize\" statment are unreachable"])                    then warn(cxt, [S "statements following \"stabilize\" statment are unreachable"])
178                    else ();                    else ();
179                  true)                  true)
180                | chk (cxt, hasSucc, isJoin, unreachable, PT.S_Die) = (
181                    if (not unreachable) then hasDieOrStabilize := true else ();
182                    if not inCreateOrUpdate orelse inGlobalBlock
183                      then err(cxt, [S "\"die\" statment outside of initially/update method"])
184                    else if hasSucc andalso not isJoin andalso not unreachable
185                      then warn(cxt, [S "statements following \"die\" statment are unreachable"])
186                      else ();
187                    true)
188              | chk (cxt, hasSucc, isJoin, unreachable, PT.S_Return _) = (              | chk (cxt, hasSucc, isJoin, unreachable, PT.S_Return _) = (
189                  if not inFun                  if not inFun
190                    then err(cxt, [S "\"return\" statment outside of function body"])                    then err(cxt, [S "\"return\" statment outside of function body"])
# Line 195  Line 200 
200                    else ();                    else ();
201                  false)                  false)
202            in            in
203              ignore (chk (cxt, false, false, false, stm))              ignore (chk (cxt, false, false, false, stm));
204                case (!hasDieOrStabilize, scope)
205                 of (false, E.MethodScope(_, StrandUtil.Update)) =>
206                      warn (cxt, [S "update method does not have reachable die or stabilize statement"])
207                  | _ => ()
208                (* end case *)
209            end            end
210    
211    (* check the type of a statement *)    (* check the type of a statement *)

Legend:
Removed from v.4465  
changed lines
  Added in v.4466

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