Commits

kevinclancy committed 4e83ba0

negations of conditions in if statements now affect the context refinements in succeeding
clauses. parser now appends an empty else clause onto if statements without else clauses for
uniformity.

Comments (0)

Files changed (3)

LoveStudio/LuaAnalyzer/HandParser.fs

     if it.Peek() = Token.ELSE then
         it.Skip()
         ifThens := (True(0,0), chunk it) :: !ifThens
-    
+    else
+        ifThens := (True(0,0), DoNothing(0,0)) :: !ifThens
+
     it.Consume(Token.END)
 
     If(List.rev !ifThens, (0,0))

LoveStudio/LuaAnalyzer/Type.fs

         | OverloadTy(tyList) ->
             "overload: " + tyList.ToString()
         | DeducedTy(perm,temp) ->
-            "Deduced Type: (perm = " + perm.ToString() + ", temp = " + temp.ToString() + ")"
+            "accumulated (perm = " + perm.ToString() + ", temp = " + temp.ToString() + ")"
         | ErrorTy(_) ->
             "Error"
         | UnknownTy ->
     member this.Item (name : string) =
         match this with
         | RecordTy(_,_,_,_,fields,_,_)
-        | OpenRecordTy(_,_,_,_,fields,_,_) ->
+        | OpenRecordTy(_,_,_,_,fields,_,_)
+        | DeducedTy(_,RecordTy(_,_,_,_,fields,_,_))
+        | DeducedTy(_,OpenRecordTy(_,_,_,_,fields,_,_)) ->
             fields.[name]
         | _ ->
             failwith "tried to access a field of some non-record type"

LoveStudio/LuaAnalyzer/Typechecker.fs

     else
         undoRefinement ctxt path (Field.OfType(UnknownTy))
 
+let rec getRefsFromNegCond (ctxt : Context) (cond : TypedExpr) : List<List<string>*Field> =
+    let venv, tenv = ctxt.venv, ctxt.tenv
+    match cond with
+    | BinOpExpr(OpEq, exp, Nil(_),_)
+    | BinOpExpr(OpEq, Nil(_), exp, _) ->
+        let expTy,expField = typeCheckExpr ctxt.DontTrackErrors.IsNotLeftExpr exp
+        match expTy with
+        | NillableTy(underlyingTy) ->
+            let desc = if expField.IsSome then expField.Value.desc else ""
+            let isConst = if expField.IsSome then expField.Value.isConst else false
+            let ref = contextRefinement ctxt exp underlyingTy desc isConst
+            if ref.IsSome then [ref.Value] else []
+        | _ ->
+            []
+    | BinOpExpr(OpNe, exp, Nil(_),_)
+    | BinOpExpr(OpNe, Nil(_), exp, _) ->
+        let expTy,expField = typeCheckExpr ctxt.DontTrackErrors.IsNotLeftExpr exp
+        match expTy with
+        | NillableTy(underlyingTy) ->
+            let desc = if expField.IsSome then expField.Value.desc else ""
+            let isConst = if expField.IsSome then expField.Value.isConst else false
+            let ref = contextRefinement ctxt exp NilTy desc isConst
+            if ref.IsSome then [ref.Value] else [] 
+        | _ ->
+            []
+    | BinOpExpr(OpNe, expA, expB,_) ->
+        let tyA,fieldA = typeCheckExpr ctxt.DontTrackErrors.IsNotLeftExpr expA
+        let tyB,fieldB = typeCheckExpr ctxt.DontTrackErrors.IsNotLeftExpr expB
+        let rA = contextRefinement ctxt expA tyB "" false
+        let rB = contextRefinement ctxt expB tyA "" false
+
+        if rA.IsSome then
+            [rA.Value]
+        elif rB.IsSome then
+            [rB.Value]
+        else
+            []
+    | BinOpExpr(OpOr, a, b,_) ->
+        List.append (getRefsFromNegCond ctxt a) 
+                    (getRefsFromNegCond ctxt b)
+    | BinOpExpr(OpAnd, a, b, _) ->
+        //TODO: too lazy to implement this now; it will be semi-tricky
+        []
+    | _ ->
+        []
+
 /// Given a context and condition expression, returns the
 /// supplied context updated with inferences that can be made from the fact that
 /// the condition expression evaluates to true under the given context.
         // could be assigned to nil in some clause, in which case the refinement
         // must be removed.
         let clauseRefinements = List.map (getAllRefinements ctxt Set.empty) (List.map snd clauses)
+        
+        // Maps a set of clause refinements extracted from the body to
+        // that set unioned with those refinements made by negating
+        // the conditions in all clauses preceding it.
+        let addNegCondRefinements (i : int) (refs : Map<List<string>,Field>) =
+            let condRefs = List.collect (fun j -> getRefsFromNegCond ctxt (fst clauses.[j])) [0..i-1]
+            List.fold (fun (m : Map<List<string>,Field>) ref -> m.Add ref) refs condRefs 
+
+        let clauseRefinements = List.mapi addNegCondRefinements clauseRefinements
         let merged = mergeClauseRefinements ctxt clauseRefinements
         Map.fold handleRefinementUpdate ctxt merged
     | Sequence(s0, s1, rng) ->
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.