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 2822, Sun Nov 9 02:36:50 2014 UTC revision 2823, Sun Nov 9 03:57:35 2014 UTC
# Line 1129  Line 1129 
1129                  end                  end
1130            (* end case *))            (* end case *))
1131    
1132    (* check AST for unused variables *)    (* check AST for unused variables.  Also check to make sure that there is a strand
1133      fun checkForUnused cxt dcl = let     * definition and exactly one initially clause.
1134            fun chkVar x = if not(isUsed x)     *)
1135        fun checkForUnused (cxt, dcls) = let
1136              val hasStrand = ref false
1137              val hasInitially = ref false
1138              fun check dcl = let
1139                    fun chkVar x = if not(isUsed x) andalso (Var.kindOf x <> AST.StrandOutputVar)
1140                  then warn (cxt, [                  then warn (cxt, [
1141                      S(Var.kindToString x), S " ", V x, S " declared at ",                      S(Var.kindToString x), S " ", V x, S " declared at ",
1142                      S(Error.locToString(getLoc x)), S " is unused"                      S(Error.locToString(getLoc x)), S " is unused"
# Line 1155  Line 1160 
1160                | AST.D_Strand(AST.Strand{state, methods, ...}) => let                | AST.D_Strand(AST.Strand{state, methods, ...}) => let
1161                    fun chkMeth (AST.M_Method(_, body)) = chkStm body                    fun chkMeth (AST.M_Method(_, body)) = chkStm body
1162                    in                    in
1163  (* FIXME: should skip output variables! *)                            hasStrand := true;
1164                      List.app chkVDcl state;                      List.app chkVDcl state;
1165                      List.app chkMeth methods                      List.app chkMeth methods
1166                    end                    end
1167                | AST.D_InitialArray _ => ()                      | AST.D_InitialArray _ => (
1168                | AST.D_InitialCollection _ => ()                          if !hasInitially then err(cxt, [S "multiple initially clauses in program"]) else ();
1169                            hasInitially := true)
1170                        | AST.D_InitialCollection _ => (
1171                            if !hasInitially then err(cxt, [S "multiple initially clauses in program"]) else ();
1172                            hasInitially := true)
1173              (* end case *)              (* end case *)
1174            end            end
1175              in
1176                List.app check dcls;
1177                if not(! hasStrand)
1178                  then err (cxt, [S "program does not have any strands"])
1179                  else ();
1180                if not(! hasInitially)
1181                  then err (cxt, [S "program does not have an initially clause"])
1182                  else ()
1183              end
1184    
1185    (* reorder the declarations so that the input variables come first *)    (* reorder the declarations so that the input variables come first *)
1186      fun reorderDecls dcls = let      fun reorderDecls dcls = let
# Line 1185  Line 1203 
1203            val dcls' = chk ({scope=GlobalScope, bindings=AtomMap.empty, env=env}, tree, [])            val dcls' = chk ({scope=GlobalScope, bindings=AtomMap.empty, env=env}, tree, [])
1204                  handle TypeError => []                  handle TypeError => []
1205            in            in
1206              List.app (checkForUnused cxt) dcls';              checkForUnused (cxt, dcls');
1207              AST.Program{              AST.Program{
1208                  props = Env.properties env,                  props = Env.properties env,
1209                  decls = dcls'                  decls = dcls'

Legend:
Removed from v.2822  
changed lines
  Added in v.2823

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