Commits

kevinclancy committed dd75e8e

Cleaned up the crufty interface of getStubContextInProject. Removed the
type environment return value, since that is kept inside the context now.

Comments (0)

Files changed (5)

LoveStudio/Forms/Studio/Studio.cs

             return;
 
           // If no errors were found at this position, query for a description
-          var res = ProjectChecker.queryDesc(_currentProject.GetModules(), _files[(Editor)sender], pos);
+          var res = ProjectChecker.queryDescAndLoc(_currentProject.GetModules(), _files[(Editor)sender], pos);
           var desc = res.Item1;
           var ty = res.Item3;
 
           delegate(object gotoDefSender, EventArgs gotoDefArgs)
           {
             
-            var query = ProjectChecker.queryDesc(
+            var query = ProjectChecker.queryDescAndLoc(
               _currentProject.GetModules(),
               _files[editor],
               editor.PositionFromPoint(e.X, e.Y)

LoveStudio/LuaAnalyzer/LuaAnalyzer.fs

         failwith "API definition error: overloads should only contain callable types"
 
 let getFieldOrMethodInfo (modules : seq<string*string*string*int64>) (lexp : Expr) (fieldOrMethodName : string) (targetFileName : string) =
-    let opEnv,stubCtxt = getStubContextInProject modules targetFileName
+    let stubCtxt = getStubContextInProject modules targetFileName
     let typed = typeExpr lexp
-    match opEnv with
-    | Some env ->
-        let ctxt = stubCtxt.DontTrackErrors.IsNotLeftExpr
-        match Type.Coerce env (fst (typeCheckExpr ctxt typed)) with
-        | RecordTy(name,desc,_,_,fields,methods,loc) ->
-            let isMethod, (fieldDesc, fieldTy, loc) = 
-                if fields.ContainsKey fieldOrMethodName then
-                    let field = fields.Item fieldOrMethodName
-                    false, (field.desc,field.ty,field.loc)
-                else if methods.ContainsKey fieldOrMethodName then
-                    let desc,ty,_,loc = methods.Item fieldOrMethodName
-                    true, (desc,ty,loc)
-                else
-                    false, ("", UnknownTy, NoLocation)
+    let ctxt = stubCtxt.DontTrackErrors.IsNotLeftExpr
+    match Type.Coerce ctxt.tenv (fst (typeCheckExpr ctxt typed)) with
+    | RecordTy(name,desc,_,_,fields,methods,loc) ->
+        let isMethod, (fieldDesc, fieldTy, loc) = 
+            if fields.ContainsKey fieldOrMethodName then
+                let field = fields.Item fieldOrMethodName
+                false, (field.desc,field.ty,field.loc)
+            else if methods.ContainsKey fieldOrMethodName then
+                let desc,ty,_,loc = methods.Item fieldOrMethodName
+                true, (desc,ty,loc)
+            else
+                false, ("", UnknownTy, NoLocation)
 
-            match fieldTy with
-            | FunctionTy(_,_,_,_,_) ->
-                new GenList<CSFunctionType>([makeCSFunction fieldDesc fieldTy])
-            | OverloadTy(overloads) ->
-                new GenList<CSFunctionType>(List.map (makeCSFunction fieldDesc) overloads)
-            | _ ->
-                new GenList<CSFunctionType>([])
+        match fieldTy with
+        | FunctionTy(_,_,_,_,_) ->
+            new GenList<CSFunctionType>([makeCSFunction fieldDesc fieldTy])
+        | OverloadTy(overloads) ->
+            new GenList<CSFunctionType>(List.map (makeCSFunction fieldDesc) overloads)
         | _ ->
             new GenList<CSFunctionType>([])
-    | None ->
+    | _ ->
         new GenList<CSFunctionType>([])
 
 let getCallInfo (modules : seq<string*string*string*int64>) (lexp : Expr) (targetFileName : string) : GenList<CSFunctionType> =
     let ret = new GenList<CSFunctionType>()
-    let opEnv,stubCtxt = getStubContextInProject modules targetFileName
+    let stubCtxt = getStubContextInProject modules targetFileName
     let typed = typeExpr lexp
-    match opEnv with
-    | Some env ->
-        let stubCtxt = stubCtxt.DontTrackErrors.IsNotLeftExpr
-        match Type.Coerce env (fst (typeCheckExpr stubCtxt typed)) with
-        | CallableTy(desc,formals,rets,varargs,defLocation) as ty ->
-            new GenList<CSFunctionType>([makeCSFunction "" ty])
-        | OverloadTy(overloads) ->
-            new GenList<CSFunctionType>(List.map (makeCSFunction "") overloads)        
-        | _ ->
-            new GenList<CSFunctionType>()
-    | None -> 
+    let exprTy,_ = typeCheckExpr stubCtxt.DontTrackErrors.IsNotLeftExpr typed 
+    match Type.Coerce stubCtxt.tenv exprTy with
+    | CallableTy(desc,formals,rets,varargs,defLocation) as ty ->
+        new GenList<CSFunctionType>([makeCSFunction "" ty])
+    | OverloadTy(overloads) ->
+        new GenList<CSFunctionType>(List.map (makeCSFunction "") overloads)        
+    | _ ->
         new GenList<CSFunctionType>()
 
 let getRecordInfo (modules : seq<string*string*string*int64>) (lexp : Expr) (targetFileName : string) : System.Object =
-    let opEnv,stubCtxt = getStubContextInProject modules targetFileName
+    let stubCtxt = getStubContextInProject modules targetFileName
     let typed = typeExpr lexp
-    match opEnv with
-    | Some env ->
-        let stubCtxt = stubCtxt.DontTrackErrors.IsNotLeftExpr
-        match Type.Coerce env (fst (typeCheckExpr stubCtxt typed)) with
-        | RecordTy(name,desc,_,_,fields,methods,_)
-        | OpenRecordTy(name,desc,_,_,fields,methods,_) ->
-            // fieldList/methodList entries represent (name/type/description)
-            let fieldList = new GenList<string*string*string>()
-            for kv in fields do
-                let name = kv.Key
-                let {desc = desc;ty=ty;loc=_} = kv.Value
-                fieldList.Add(name,ty.ToString(),desc)
+    let stubCtxt = stubCtxt.DontTrackErrors.IsNotLeftExpr
+    let exprTy,_ = typeCheckExpr stubCtxt typed
+    match Type.Coerce stubCtxt.tenv exprTy with
+    | RecordTy(name,desc,_,_,fields,methods,_)
+    | OpenRecordTy(name,desc,_,_,fields,methods,_) ->
+        // fieldList/methodList entries represent (name/type/description)
+        let fieldList = new GenList<string*string*string>()
+        for kv in fields do
+            let name = kv.Key
+            let {desc = desc;ty=ty;loc=_} = kv.Value
+            fieldList.Add(name,ty.ToString(),desc)
         
-            let methodList = new GenList<string*string*string>()
-            for kv in methods do
-                let name = kv.Key
-                let (desc,ty,_,_) = kv.Value
-                methodList.Add(name,ty.ToString(),desc)            
+        let methodList = new GenList<string*string*string>()
+        for kv in methods do
+            let name = kv.Key
+            let (desc,ty,_,_) = kv.Value
+            methodList.Add(name,ty.ToString(),desc)            
         
-            {
-                name = name
-                desc = desc
-                fields = fieldList
-                methods = methodList    
-            } :> System.Object
-        | _ ->
-            null
-    | None ->
+        {
+            name = name
+            desc = desc
+            fields = fieldList
+            methods = methodList    
+        } :> System.Object
+    | _ ->
         null
 
+
 let public plugins = ref []
 
 /// Copies all library modules from the UserData directory to the project directory

LoveStudio/LuaAnalyzer/ProjectChecker.fs

 /// file, recording the context when the typechecker reach a call to "lucbdnioua",
 /// It is assumed that exactly one call to lucbdnioua exists in the file.
 let getStubContextInProject (modules : seq<LuaModule>) (targetFile : string) =
-    let env = runTypeCollectors modules (Some(targetFile)) None
-    env,!refStubContext
-    
+    ignore (runTypeCollectors modules (Some(targetFile)) None)
+    !refStubContext
+
+/// ctxt - a context
+/// ast - a syntax tree
+///
+/// Typechecks 
 let getStubContext (ctxt : Context) (ast : TypedStatement) =
     ignore (typeCheckStat ctxt ast)
     !refStubContext

LoveStudio/LuaAnalyzer/ProjectChecker.fsi

 
 val queryDescAndLoc : seq<string*string*string*int64> -> string -> int -> string*DefinitionLocation*string
 
-val getStubContextInProject : seq<string*string*string*int64> -> string -> Option<TypeEnvironment>*Context
+val getStubContextInProject : seq<string*string*string*int64> -> string -> Context
 
 val getStubContext : Context -> TypedStatement -> Context

LoveStudio/LuaAnalyzer/Typechecker.fs

             | Some x ->
                 Some x
             | None ->
-                let ctxt' = updateCtxt ctxt s0 
+                let ctxt' = updateCtxt ctxt s0
                 findDef s1 ctxt'
         | Assign(
             _,