[svn] r7187: vs-plugin/trunk/Nemerle.Compiler.Utils/CodeDomHelper.n

akhropov svnadmin at nemerle.org
Mon Jan 1 18:32:11 CET 2007


Log:
various additions

Author: akhropov
Date: Mon Jan  1 18:31:58 2007
New Revision: 7187

Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/CodeDomHelper.n

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/CodeDomHelper.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/CodeDomHelper.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/CodeDomHelper.n	Mon Jan  1 18:31:58 2007
@@ -1,8 +1,13 @@
 using System;
 using System.CodeDom;
+using System.CodeDom.Compiler;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
 using System.Reflection;
 
 using Nemerle.Compiler;
+using Nemerle.Compiler.Typedtree;
 
 namespace Nemerle.Compiler.Utils
 {
@@ -65,5 +70,62 @@
 				res;
 			}
 		}
+
+    public GetLinePragma(expr: TExpr) : CodeLinePragma
+    {
+      def loc = expr.Location;
+      CodeLinePragma(loc.File,loc.Line)
+    }
+
+    public MapFilterByType[T1,T2](this collection: IEnumerable[T1]) : list[T2]
+    {
+      mutable res = [];
+      foreach(e is T2 in collection)
+        res = e :: res;
+
+      res.Reverse()
+    }
+
+    public MapFilterByType[T2](this collection: IEnumerable) : list[T2]
+    {
+      mutable res = [];
+      foreach(e is T2 in collection)
+        res = e :: res;
+
+      res.Reverse()
+    }
+
+    public StringToListOfLines(s: string) : List[string]
+    {
+      def res = List.[string]();
+      using(def sr = StringReader(s))
+      {
+        for(mutable s1 = sr.ReadLine(); s1 != null; s1 = sr.ReadLine())
+          res.Add(s1);
+      }
+      res
+    }
+
+    // Debug output method
+    public ToString(unit: CodeCompileUnit, generator: ICodeGenerator) : string 
+    {
+      mutable s : string = null;
+      using (def sw = StringWriter())
+      {
+        //def codeGen = NemerleCodeGenerator() : ICodeGenerator;
+        generator.GenerateCodeFromCompileUnit(unit,sw,null);
+        s = sw.ToString();
+      }
+      s
+    }
+
+    public PrintMacro(the_macro: IMacro) : string
+    {
+      $"[Macro:\n GetName = $(the_macro.GetName())\n"
+        " GetNamespace () = $(the_macro.GetNamespace ())\n"
+        " Keywords = $(the_macro.Keywords)\n"
+        " Usage = $(the_macro.Usage)\n";
+        //" SyntaxExtension = $(the_macro.SyntaxExtension())]";
+    }
 	}
 }
\ No newline at end of file



More information about the svn mailing list