[svn] r6857: vs-plugin/trunk: Nemerle.Compiler.Utils/CodeDomParser.n Nemerle.Compiler.Utils/Nemerle.Compil...

VladD2 svnadmin at nemerle.org
Thu Nov 9 02:09:33 CET 2006


Log:
Change error reporting logic.

Author: VladD2
Date: Thu Nov  9 02:09:28 2006
New Revision: 6857

Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/CodeDomParser.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.CompilerMessages.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Init.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/CodeDomParser.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/CodeDomParser.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/CodeDomParser.n	Thu Nov  9 02:09:28 2006
@@ -10,7 +10,7 @@
 using Nemerle.Collections; 
 using Nemerle.Compiler;
 using Nemerle.Compiler.Parsetree;
-using Nemerle.Completion;
+using Nemerle.Completion2;
 
 namespace Nemerle.Compiler.Utils
 {
@@ -25,19 +25,24 @@
 
 		public Parse(codeReader: TextReader) :  CodeCompileUnit
 		{
-			def code = codeReader.ReadToEnd();
-			def fileName = GetFileName(codeReader);
+			//def code = codeReader.ReadToEnd();
+			//def fileName = GetFileName(codeReader);
 
-      //TODO: Ïåðåâåñòè CodeDomParser íà Nemerle.Completion2.Engine.
-			def engine = Engine();
-			// áåç ýòîé ñòðîêè âàëèòñÿ exception â Location.Init()
-			ManagerClass.Instance = engine;
-			engine.Init();
+   //   def projectInfo = ProjectInfo.FindProject(fileName);
 
-			def location = Location(Location.AddFile(fileName), 1, 1);
-			def decls = MainParser.Parse(LexerString(engine, code, location));
-			
-			CreateCodeCompileUnit(decls);
+   //   if (projectInfo == null)
+			//	null
+   //   else
+   //   {
+			//  //def decls = MainParser.Parse(LexerString(engine, code, location));
+  	//		
+			//  //CreateCodeCompileUnit(decls);
+   //     throw NotImplementedException();
+   //   }
+        _ = codeReader;
+        _ = GetFileName;
+        _ = CreateCodeCompileUnit;
+        throw NotImplementedException();
 		}
 
 		private GetFileName(rd: TextReader) : string

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj	Thu Nov  9 02:09:28 2006
@@ -48,8 +48,6 @@
     <Compile Include="Properties\AssemblyInfo.n" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Nemerle.Completion2\CompilerMessage.n" />
-    <Compile Include="Nemerle.Completion2\MessageKind.n" />
     <Compile Include="Nemerle.Completion2\EngineState.n" />
     <Compile Include="Nemerle.Completion2\CodeCompletionEngineException.n" />
     <Compile Include="Nemerle.Completion2\InternalReference.n" />

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n	Thu Nov  9 02:09:28 2006
@@ -245,8 +245,7 @@
           if (loc.Contains(line, col)) // completion in method body
           {
             def bodyCode = source.GetRegion(loc.Line, loc.Column, loc.EndLine, loc.EndColumn);
-            def groups   = _engine.PreParse(bodyCode, loc);
-            def tokens   = TokenFinder().Find(groups, line, col);
+            def tokens = TokenFinder().Find(method.BodyTokens, line, col);
 
             match (tokens.Find(t => t is Token.RoundGroup))
             {

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n	Thu Nov  9 02:09:28 2006
@@ -24,6 +24,7 @@
     [Accessor] _engine        : Engine;
     [Accessor] _compileUnits  : CompileUnitCollection;
     [Accessor] _namespaceTree : NamespaceTree.Node;
+    [Accessor] _errors        : list[CompilerMessage];
 
     public CompleteWord(
       [NotNull] filePath : string, 
@@ -143,6 +144,51 @@
       _ = obj.ToString();
     }
 
+    private GetAllCompilerMessageForFile(fileIndex : int) : SCG.IEnumerable[CompilerMessage]
+    {
+      foreach (cm when cm.Location.FileIndex == fileIndex in Errors)
+        yield cm;
+
+      foreach (method in GetAllMetodsDefinedInFile(fileIndex))
+      {
+        method.EnsureCompiled();
+        foreach (cm in method.BodyMessages)
+          yield cm;
+      }
+    }
+
+    private GetAllMetodsDefinedInFile(fileIndex : int) : SCG.List[MethodBuilder]
+    {
+      def ns = CompileUnits[fileIndex];
+      def seq = SCG.List();
+
+      def scanType(ty : TypeBuilder)
+      {
+        when (ty.PartsLocation.Exists(x => x.FileIndex == fileIndex))
+          foreach (member in ty.GetDirectMembers())
+          {
+            | tb is TypeBuilder => scanType(tb)
+            | mb is MethodBuilder when mb.Location.FileIndex == fileIndex =>
+              seq.Add(mb);
+            | _ => ()
+          }
+      }
+
+      def scanDecl(decl : Decl)
+      {
+        | Namespace as ns when ns.BodyLocation.FileIndex == fileIndex =>
+          foreach (subDecl in ns.Decls)
+            scanDecl(subDecl);
+
+        | Type(tb) => scanType(tb);
+        | _ => ()
+      }
+
+      scanDecl(ns);
+
+      seq
+    }
+
     public Check(
       /*[NotNull]*/ fileName        : string,
       /*[NotNull]*/ source          : ISource,
@@ -153,7 +199,7 @@
     {
       def fileIndex = _compileUnits.GetFileIndex(fileName);
 
-      foreach (cm when cm.Location.FileIndex == fileIndex in _engine.CompilerMessages)
+      foreach (cm in GetAllCompilerMessageForFile(fileIndex))
         addError(cm);
 
       def isNext(line, col, ch)
@@ -248,9 +294,6 @@
                   }
                 });
               }
-
-              foreach (cm in _engine.CompilerMessages)
-                addError(cm);
 #if !DEBUG
             }
 #endif

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine-main.n	Thu Nov  9 02:09:28 2006
@@ -25,8 +25,11 @@
     /// Makes the typed tree and constructs compile unit collection.
     private BuildTypedtreeAndInitProject() : void
     {
+      try
+      {
+        _currentMessages = SCG.List(32);
+
       Trace.WriteLine("### Build types tree!");
-      ClearCompilerMessages();
       Instance = this;
       Init();
 
@@ -112,7 +115,16 @@
         when (_fileInfos[i] != null)
           AddTypeBilders(_fileInfos[i], i, nsTree);
 
-      _project = Project(this, CompileUnitCollection(this, _fileInfos, regionsMap), nsTree);
+        _project = Project(
+          this, 
+          CompileUnitCollection(this, _fileInfos, regionsMap),
+          nsTree,
+          _currentMessages.ToList());
+      }
+      finally
+      {
+        _currentMessages = null;
+      }
     }
 
     public RunCompletionEngine (
@@ -123,7 +135,7 @@
       : CompletionResult
       requires completionPosition <= content.Length
     {
-        ClearCompilerMessages();
+        _currentMessages = SCG.List(32);
         // Tell the methods we are in completion mode
         _isInCompletionMode = true;
 
@@ -156,7 +168,7 @@
           | e => Trace.WriteLine (e.Message);
         }
 
-        //_isInCompletionMode = false;
+        _currentMessages = null;
 
         completionList
     }
@@ -171,41 +183,9 @@
       body
     }
 
-    public CompileMethod(
-      /*[NotNull]*/ method   : MethodBuilder,
-      /*[NotNull]*/ content  : string,
-                    location : Location
-    )
-      : PExpr * TExpr * Exception
-    {
-        ClearCompilerMessages();
-        _isInCompletionMode = true;
-
-        def lexer = LexerString(this, content, location);
-        def pBody = ParseMethodBody(method, lexer);
-
-        if (pBody != null && pBody.expr != null)
-        {
-          try
-          {
-            method.RunBodyTyper();
-
-            def tExpr = method.GetHeader().body :> FunBody.Typed;
-
-            (pBody.expr, if (tExpr != null) tExpr.expr else null, null)
-          }
-          catch { | ex => (pBody.expr, null, ex) }
-        }
-        else
-          (null, null, null)
-    }
-
-    public PreParse([NotNull] content : string, location : Location) : Token.BracesGroup
+    protected override SetCompiletMessages (messages : SCG.List[CompilerMessage]) : void
     {
-        def lexer     = LexerString(this, content, location);
-        def preparser = PreParser(lexer);
-
-        preparser.PreParse();
+      _currentMessages = messages;
     }
 
     protected override PreParseMethodBody (method : MethodBuilder) : Token.BracesGroup

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.CompilerMessages.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.CompilerMessages.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.CompilerMessages.n	Thu Nov  9 02:09:28 2006
@@ -8,23 +8,16 @@
 {
   public partial class Engine
   {
-    [Accessor(flags=WantSetter)] mutable _processMessages : bool;
+    //[Accessor(flags=WantSetter)] mutable _processMessages : bool;
 
-    _listMessages : SCG.List[CompilerMessage] = SCG.List();
-
-    public ClearCompilerMessages() : void
-    {
-      when (_processMessages)
-        _listMessages.Clear();
-    }
+    mutable _currentMessages : SCG.List[CompilerMessage];
 
     public AddCompilerMessage(message : string, location : Location, kind : MessageKind, ) : void
     {
-      when (_processMessages)
-        _listMessages.Add(CompilerMessage(message, location, kind));
+      _currentMessages.Add(CompilerMessage(message, location, kind));
     }
 
-    ProcessCompilerMessage(location : Location, message : string) : void
+    ProcessTopLevelCompilerMessage(location : Location, message : string) : void
     {
       def check(text, add)
       {

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Init.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Init.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Init.n	Thu Nov  9 02:09:28 2006
@@ -39,7 +39,7 @@
       _defines = DefineCollection (this);
       _references = ReferenceCollection (this);
       _sources = SourceCollection (this);
-      MessageOccured += ProcessCompilerMessage;
+      MessageOccured += ProcessTopLevelCompilerMessage;
       Options.GreedyReferences = true;
       Options.ColorMessages = false;
       Options.IgnoreConfusion = true;

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n	Thu Nov  9 02:09:28 2006
@@ -48,10 +48,5 @@
       get { Message_output }
       set { Message_output = value }
     }
-    
-    public CompilerMessages : array[CompilerMessage]
-    {
-      get { _listMessages.ToArray() }
-    }
   } // end class Engine
 } // end namespace

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n	Thu Nov  9 02:09:28 2006
@@ -9,6 +9,7 @@
 
 using Nemerle.Compiler.Parsetree;
 using TExpr = Nemerle.Compiler.Typedtree.TExpr;
+using SCG   = System.Collections.Generic;
 
 namespace Nemerle.Compiler.Utils
 {

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs	Thu Nov  9 02:09:28 2006
@@ -219,12 +219,8 @@
 			if (projectInfo == null)
 				return null;
 
-			try
-			{
 				request.Sink.ProcessHiddenRegions = true;
 
-				projectInfo.Engine.ProcessMessages = true;
-				projectInfo.Engine.ClearCompilerMessages();
 				projectInfo.UpdateFile(request);
 
 				projectInfo.Project.Check(
@@ -257,11 +253,6 @@
 							cm.MessageKind == MessageKind.Warning ? Severity.Warning :
 							                                        Severity.Hint);
 					});
-			}
-			finally
-			{
-				projectInfo.Engine.ProcessMessages = false;
-			}
 
 			return GetDefaultScope(request);
 		}



More information about the svn mailing list