[svn] r5845: nemerle/trunk/ncc: CompilationOptions.n completion/CodeCompletionEngine.n parsing/Lexer.n

nazgul svnadmin at nemerle.org
Mon Oct 24 19:43:44 CEST 2005


Log:
Reorganize command_defines. There is a nice API to access it in Nemerle.Compiler.Options now.

Author: nazgul
Date: Mon Oct 24 19:43:35 2005
New Revision: 5845

Modified:
   nemerle/trunk/ncc/CompilationOptions.n
   nemerle/trunk/ncc/completion/CodeCompletionEngine.n
   nemerle/trunk/ncc/parsing/Lexer.n

Modified: nemerle/trunk/ncc/CompilationOptions.n
==============================================================================
--- nemerle/trunk/ncc/CompilationOptions.n	(original)
+++ nemerle/trunk/ncc/CompilationOptions.n	Mon Oct 24 19:43:35 2005
@@ -64,6 +64,7 @@
     public mutable Sources : list [string];
 
     private disabled_keywords : Hashtable [string, list [NamespaceTree.Node]] = Hashtable ();
+    internal mutable CommandDefines : Map [string, bool];
     
     internal Validate () : void {
       when (System.IO.Path.GetExtension (OutputFileName) == "")
@@ -106,6 +107,7 @@
       MacrosToLoad = [];
       Sources = [];
       disabled_keywords.Clear ();
+      CommandDefines = Map ();
     }
 
     /// default null value for [in_namespace] means that keyword 
@@ -143,6 +145,22 @@
       }
     }
     
+    /// Adds given name as a command-line defined constant.
+    /// It is then visible in all files just like defined preprocessor constant.
+    public DefineConstant (name : string) : void
+    {
+      CommandDefines = CommandDefines.Replace (name, true);
+    }
+    
+    /// Checks if given name was specified as command-line defined constant.
+    public IsConstantDefined (name : string) : bool
+    {
+      match (CommandDefines.Find (name)) {
+        | Some (x) => x
+        | _ => false
+      }
+    }
+    
     public ShouldDump (fn : Typedtree.Fun_header) : bool
     {
       DumpTypedTree &&
@@ -307,7 +325,7 @@
                        help = "Define preprocessor symbol for conditional compilation",
                        handler = fun (x) { 
                          foreach (constant in x.Split (array [';']))
-                           LexerFile.command_defines.Set (constant, true) 
+                           DefineConstant (constant) 
                        }),
 
         Getopt.CliOption.String (name = "-doc", 

Modified: nemerle/trunk/ncc/completion/CodeCompletionEngine.n
==============================================================================
--- nemerle/trunk/ncc/completion/CodeCompletionEngine.n	(original)
+++ nemerle/trunk/ncc/completion/CodeCompletionEngine.n	Mon Oct 24 19:43:35 2005
@@ -220,8 +220,6 @@
             PreParser.Init ();
             Passes.Solver = Solver ();
             
-            LexerFile.command_defines.Clear();
-
             Options.Clear();
             Options.GreedyReferences = true;
             Options.ColorMessages = false;
@@ -267,7 +265,7 @@
             Init ();
             
             foreach (define in Defines.defines)
-                LexerFile.command_defines.Set (define, true);
+                Options.DefineConstant (define);
             
             foreach (references in References.references.Values)
             {
@@ -656,7 +654,7 @@
             Init ();
             
             foreach (define in Defines.defines)
-                LexerFile.command_defines.Set (define, true);
+                Options.DefineConstant (define);
             
             foreach (references in References.references.Values)
             {

Modified: nemerle/trunk/ncc/parsing/Lexer.n
==============================================================================
--- nemerle/trunk/ncc/parsing/Lexer.n	(original)
+++ nemerle/trunk/ncc/parsing/Lexer.n	Mon Oct 24 19:43:35 2005
@@ -253,8 +253,7 @@
   mutable line_start : int; // how to compute real line after `#line default' occurence
   protected file_real : string;           // real filename to revert after `#line 4 "bla"'
   
-  protected defines : Hashtable [string, bool];
-  public static command_defines : Hashtable [string, bool] = Hashtable ();
+  protected mutable defines : Map [string, bool];
 
   #endregion PREPROCESSOR VARIABLES
   
@@ -272,8 +271,7 @@
     isPendingChar = false;
 
     white_beginning = true;
-    defines = Hashtable (25);
-    command_defines.Iter (fun (key, _) { defines.Add (key, true) });
+    defines = Options.CommandDefines;
     eating_stack = Stack ();
     eating_now = 0;
     line_stack = -1;
@@ -1094,11 +1092,11 @@
         _ = read_to_the_end_of_line ();
 
       | "define" =>
-        defines.Set (read_word (), true);
+        defines = defines.Replace (read_word (), true);
         _ = read_to_the_end_of_line ()
 
       | "undef" =>
-        defines.Set (read_word (), false);
+        defines = defines.Replace (read_word (), false);
         _ = read_to_the_end_of_line ()
 
       | "pragma" =>
@@ -1171,7 +1169,7 @@
           when (j == 0)
             throw LexerBase.Error ("bad preprocessing condition format");
           def val = 
-            match (defines.Get (x.Substring (0, j))) {
+            match (defines.Find (x.Substring (0, j))) {
               | Some (v) => v
               | None => false
             };



More information about the svn mailing list