[svn] r7442: nemerle/trunk: . macros/Logging.n macros/io.n macros/operators.n ncc/CompilationOptions.n ncc...

VladD2 svnadmin at nemerle.org
Sun Feb 18 22:36:11 CET 2007


Log:
1. Fix location of spliced string literal.
2. Improve sprint/sprintf macro (improve performance and add warnings).
3. Sync compiler code changes in sprint/sprintf macro.

Author: VladD2
Date: Sun Feb 18 22:35:38 2007
New Revision: 7442

Modified:
   nemerle/trunk/   (props changed)
   nemerle/trunk/macros/Logging.n
   nemerle/trunk/macros/io.n
   nemerle/trunk/macros/operators.n
   nemerle/trunk/ncc/CompilationOptions.n
   nemerle/trunk/ncc/generation/Typer4.n
   nemerle/trunk/ncc/hierarchy/ClassMembers.n
   nemerle/trunk/ncc/parsing/Lexer.n
   nemerle/trunk/ncc/parsing/MainParser.n
   nemerle/trunk/ncc/passes.n
   nemerle/trunk/ncc/testsuite/   (props changed)
   nemerle/trunk/ncc/testsuite/negative/cg-post.n
   nemerle/trunk/ncc/testsuite/negative/tyenf.n
   nemerle/trunk/ncc/testsuite/positive/macroprog.n
   nemerle/trunk/ncc/testsuite/positive/valuetype-conv.n
   nemerle/trunk/ncc/typing/Typer-PatternTyper.n
   nemerle/trunk/ncc/typing/Typer.n
   nemerle/trunk/ncc/typing/Typer2.n
   nemerle/trunk/tools/msbuild-task/MSBuildTask.n

Modified: nemerle/trunk/macros/Logging.n
==============================================================================
--- nemerle/trunk/macros/Logging.n	(original)
+++ nemerle/trunk/macros/Logging.n	Sun Feb 18 22:35:38 2007
@@ -95,13 +95,15 @@
               FlagsToFunctions [verb.Id] = fn;
               
             | _ =>
-              Message.Error ($ "expected mapping of VERB to print function, like `DEBUG => My.DebugFunction' got $f");
+              Message.Error ($ "expected mapping of VERB to print function, like "
+                               "`DEBUG => My.DebugFunction' got $f");
           }
                   
         | [fn] =>
           FlagsToFunctions [""] = fn;
           
-        | _ => Message.Error ($ "expected single logging function or set of mappings from VERB to print functions");
+        | _ => Message.Error ("expected single logging function or set of mappings"
+                              " from VERB to print functions");
       }  
     }
 

Modified: nemerle/trunk/macros/io.n
==============================================================================
--- nemerle/trunk/macros/io.n	(original)
+++ nemerle/trunk/macros/io.n	Sun Feb 18 22:35:38 2007
@@ -29,6 +29,7 @@
 using Nemerle; 
 using Nemerle.Compiler;
 using Nemerle.Collections;
+using Nemerle.Utility;
 
 using System;
 using System.Text;
@@ -50,15 +51,17 @@
 
   macro sprintf (format : string, params parms : array [expr])
   {
+    when (parms.Length == 0)
+      Message.Warning ("sprintf whith no parametrs");
+    
     def (evals, refs) = make_evaluation_exprs (parse_format (format), parms);
-    def seq = List.Append (evals, List.Map (refs, fun (x) { 
-      <[ ignore (result.Append ($x)) ]> 
-    }));
-    <[ 
-      def result = StringBuilder ();
-      {.. $seq } 
-      result.ToString ();
-    ]>
+    def exprs = match (refs)
+    {
+        | []     => Message.Warning ("empty format"); [<[ "" ]>]
+      | [expr] => evals + [<[ if ($expr == null) string.Empty else $expr.ToString () ]>]
+      | _ :: _ => evals + [<[ string.Concat (..$refs) ]>]
+    }
+    <[ { ..$exprs } ]>
   }
 
   /** Writes output to given System.IO.TextWriter */
@@ -124,10 +127,24 @@
 
   macro sprint (str : string)
   {
-    def seq = List.RevMap (make_splice_distribution (str, Macros.ImplicitCTX().Env), fun (x) {
-      <[ ignore (result.Append ($x)) ]> 
-    });
-    <[ def result = StringBuilder (); {.. $seq }; result.ToString () ]>
+    if (string.IsNullOrEmpty (str))
+    {
+      Message.Warning ("empty spliced string");
+      <[ string.Empty ]>
+    }
+    else
+    {
+      def seq = make_splice_distribution (str, Macros.ImplicitCTX().Env).Rev ();
+
+      match (seq)
+      {
+        | [PT.PExpr.Literal as lit] =>
+          Message.Warning ($"spliced string without splices: '$str'");
+          lit
+
+        | _ => <[ string.Concat (..$seq) ]>
+      }
+    }
   }
 
   /** Writes text to given System.IO.TextWriter */
@@ -253,7 +270,6 @@
                            Globalization.NumberFormatInfo.InvariantInfo) ]>, xs)
 
           | FormatToken.Str :: xs => continue (<[ $(parms[i - 1]) : string ]>, xs)
-
           | FormatToken.Chr :: xs => continue (<[ $(parms[i - 1]) : char ]>, xs)
 
           | [] => 

Modified: nemerle/trunk/macros/operators.n
==============================================================================
--- nemerle/trunk/macros/operators.n	(original)
+++ nemerle/trunk/macros/operators.n	Sun Feb 18 22:35:38 2007
@@ -248,7 +248,7 @@
       | None 
       | Some (Class (tiA, _)) when tiA.IsValueType && !isNullable(tiA) =>
           Message.FatalError (exprA.Location, 
-                              $"Left operand of the `??' operator should be "
+                              $"Left operand ($exprA) of the `??' operator should be "
                               "reference or nullable type ");
       | Some (Class (tiA, _)) when isNullable (tiA) => resolve (tiA, isNullable)
       | Some (Class (tiA, _)) when isOption (tiA) => resolve (tiA, isOption)

Modified: nemerle/trunk/ncc/CompilationOptions.n
==============================================================================
--- nemerle/trunk/ncc/CompilationOptions.n	(original)
+++ nemerle/trunk/ncc/CompilationOptions.n	Sun Feb 18 22:35:38 2007
@@ -544,14 +544,14 @@
                      aliases = ["-Obcm"],
                      help = "NOHELP",
                      handler = fun () {
-                       Message.Warning ($"This command line option (-Obcm) has beed removed, it is"
+                       Message.Warning ("This command line option (-Obcm) has beed removed, it is"
                                         " enabled by default")
                      }),
         Getopt.CliOption.Flag (name = "-ordinal-constant-matching-opt",
                      aliases = ["-Oocm"],
                      help = "NOHELP",
                      handler = fun () {
-                       Message.Warning ($"This command line option (-Oocm) has been removed - "
+                       Message.Warning ("This command line option (-Oocm) has been removed - "
                                         "it didn't work correctly. If you would like to contribute"
                                         " code for optimized integer constants matching, please contact us.")
                      }),
@@ -559,7 +559,7 @@
                      aliases = ["-Oscm"],
                      help = "NOHELP",
                      handler = fun () {
-                       Message.Warning ($"This command line option (-Oscm) has been removed - "
+                       Message.Warning ("This command line option (-Oscm) has been removed - "
                                         "it didn't work correctly. If you would like to contribute"
                                         " code for optimized string matching, please contact us.")
                      }),

Modified: nemerle/trunk/ncc/generation/Typer4.n
==============================================================================
--- nemerle/trunk/ncc/generation/Typer4.n	(original)
+++ nemerle/trunk/ncc/generation/Typer4.n	Sun Feb 18 22:35:38 2007
@@ -646,8 +646,7 @@
                             parm.expr = Box (t, parm.expr);
                       } else {
                         unless (parm.expr.IsAddressable && parm.expr.setNeedAddress (is_instance_ctor))
-                          Message.Error ($ "non-addressable expression passed "
-                                           "as a ref/out parameter");
+                          Message.Error ("a ref or out argument must be an assignable variable");
                       }
                       formals = fs;
                     | [] => Util.ice ();

Modified: nemerle/trunk/ncc/hierarchy/ClassMembers.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/ClassMembers.n	(original)
+++ nemerle/trunk/ncc/hierarchy/ClassMembers.n	Sun Feb 18 22:35:38 2007
@@ -226,7 +226,7 @@
          parent);
 
     when (count_access (parent) < count_access (child))
-      Message.Error ($ "accessor is more accessible than containing entity")
+      Message.Error ("accessor is more accessible than containing entity")
   }
 
   public override ToString () : string

Modified: nemerle/trunk/ncc/parsing/Lexer.n
==============================================================================
--- nemerle/trunk/ncc/parsing/Lexer.n	(original)
+++ nemerle/trunk/ncc/parsing/Lexer.n	Sun Feb 18 22:35:38 2007
@@ -1040,8 +1040,13 @@
            else Token.Operator ("+")
 
       | '$' =>
+        Fake();
+        def startLine = this.Location.Line;
+        def startCol  = this.Location.Column;
+
         if (eat_whitespace () && (peek_or_white () == '"' || peek_or_white () == '@')) {
           // we will not warn about $ in string literal in this mode
+          def strStartLoc = this.Location;
           def c = read ();
           
           def str =
@@ -1053,10 +1058,13 @@
           
               get_monkey_string ()
             }
-          def dol_tok = Token.Operator (this.Location, "$");
-          dol_tok.Next = str;
-          str.Location = dol_tok.Location;
-          Token.RoundGroup (this.Location, Token.LooseGroup (this.Location, dol_tok))
+
+          def dolLoc = Location(strStartLoc.FileIndex, startLine, startCol - 1, startLine, startCol);
+          str.Location = strStartLoc + str.Location;
+          def groupLok = dolLoc + str.Location;
+          def dolTok = Token.Operator (dolLoc, "$");
+          dolTok.Next = str;
+          Token.RoundGroup (groupLok, Token.LooseGroup (groupLok, dolTok))
         }
         else get_op (ch)
                               
@@ -1087,6 +1095,10 @@
     }
   }
   
+  Fake() : void
+  {
+    assert(true);
+  }
 
   public virtual GetToken () : Token
   {

Modified: nemerle/trunk/ncc/parsing/MainParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/MainParser.n	(original)
+++ nemerle/trunk/ncc/parsing/MainParser.n	Sun Feb 18 22:35:38 2007
@@ -2096,7 +2096,8 @@
               | Token.StringLiteral (str) as stok =>
                 shift ();
                 // the sprint macro must get current location and global context...
-                Util.locate (stok.Location, <[ $(mkname ("Nemerle") : name).IO.sprint ($(str : string)) ]>)
+                Util.locate (loc + stok.Location, 
+                  <[ $(mkname ("Nemerle") : name).IO.sprint ($(str : string)) ]>)
 
               | Token.SquareGroup (group) as grp =>
                 shift ();

Modified: nemerle/trunk/ncc/passes.n
==============================================================================
--- nemerle/trunk/ncc/passes.n	(original)
+++ nemerle/trunk/ncc/passes.n	Sun Feb 18 22:35:38 2007
@@ -280,7 +280,7 @@
     [Accessor] protected mutable _isIntelliSenseMode    : bool = false;
     /// True if now completion word in progress. This enable additional checks
     /// of completion tokens.
-    [Accessor] protected mutable _isCompletioInProgress : bool = false;
+    [Accessor] protected mutable _isCompletionInProgress : bool = false;
     
     ProgressBar (stage : int) : void
     {

Modified: nemerle/trunk/ncc/testsuite/negative/cg-post.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/negative/cg-post.n	(original)
+++ nemerle/trunk/ncc/testsuite/negative/cg-post.n	Sun Feb 18 22:35:38 2007
@@ -46,6 +46,6 @@
   {
     X ().x = 3; // E: cannot load value type address
 
-    foo (ref (X ().x)); // E: non-addressable expression passed as a ref/out parameter
+    foo (ref (X ().x)); // E: a ref or out argument must be an assignable variable
   }
 }

Modified: nemerle/trunk/ncc/testsuite/negative/tyenf.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/negative/tyenf.n	(original)
+++ nemerle/trunk/ncc/testsuite/negative/tyenf.n	Sun Feb 18 22:35:38 2007
@@ -30,6 +30,7 @@
     _ = $ "$(foo"; // E: runaway .* in format string
     _ = $ "$(foo +)"; // E: parse error near operator
     _ = $ "$()"; // E: expression without content
-    _ = $ ""; // OK
+    _ = $ ""; // W: empty spliced string
+    _ = $ " foo "; // W: spliced string without splices: ' foo '
   }
 }

Modified: nemerle/trunk/ncc/testsuite/positive/macroprog.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/macroprog.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/macroprog.n	Sun Feb 18 22:35:38 2007
@@ -225,7 +225,7 @@
   
     public static Go () : void
     {
-      log (VERB, $ "verb logging");
+      log (VERB, "verb logging");
 
       whenlogging (VERB)
         def qux = "foobar";

Modified: nemerle/trunk/ncc/testsuite/positive/valuetype-conv.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/valuetype-conv.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/valuetype-conv.n	Sun Feb 18 22:35:38 2007
@@ -31,7 +31,7 @@
     }
 
     def g () {
-      Write ($ "g called\n");
+      Write ("g called\n");
       
     }
 

Modified: nemerle/trunk/ncc/typing/Typer-PatternTyper.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer-PatternTyper.n	(original)
+++ nemerle/trunk/ncc/typing/Typer-PatternTyper.n	Sun Feb 18 22:35:38 2007
@@ -357,8 +357,7 @@
                 def typed_pats = List.Map2 (types, pats, TypePattern);
                 Pattern.Tuple (typed_pats)
               } else {
-                ReportError (messenger,
-                             $ "type clash in pattern typing");
+                ReportError (messenger, "type clash in pattern typing");
                 Pattern.Error ()
               }
           }
@@ -561,7 +560,7 @@
 
       DoTypePattern (matched_value_type : TyVar, pattern : PT.PExpr) : Pattern
       {
-        when (Manager.IsCompletioInProgress)
+        when (Manager.IsCompletionInProgress)
           Manager.CompletePattern (pattern, matched_value_type, this, typer.env);
 
         def pat = match (pattern) {
@@ -775,7 +774,7 @@
             Pattern.Error ()
 
           | PT.PExpr.ToComplete =>
-            Util.ice ("The completion tokens allowed only if Manager.IsCompletioInProgress is true.")
+            Util.ice ("The completion tokens allowed only if Manager.IsCompletionInProgress is true.")
 
           | _ =>
             ReportError (messenger, "invalid pattern");

Modified: nemerle/trunk/ncc/typing/Typer.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer.n	(original)
+++ nemerle/trunk/ncc/typing/Typer.n	Sun Feb 18 22:35:38 2007
@@ -1150,7 +1150,7 @@
    
     DoType (expression : PT.PExpr, expected : TyVar, is_toplevel_in_seq : bool) : TExpr
     {
-      when (Manager.IsCompletioInProgress)
+      when (Manager.IsCompletionInProgress)
       {
         assert(true);
         Manager.Complete (expression, expected, this, env);
@@ -1731,7 +1731,7 @@
           Util.ice ("typed pattern in raw expr")
 
         | PT.PExpr.ToComplete => 
-          Util.ice ("The completion tokens allowed only if Manager.IsCompletioInProgress is true.")
+          Util.ice ("The completion tokens allowed only if Manager.IsCompletionInProgress is true.")
       }
 
       when (expression.typed_object == null)
@@ -2991,8 +2991,7 @@
                                            operator_name,
                                            name.GetEnv (env));
             when (parm1.kind != ParmKind.Normal)
-              ReportError (messenger, 
-                           $ "ref/out parameters not supported with ++/--");
+              ReportError (messenger, "ref/out parameters not supported with ++/--");
             
             Delay (kind, FreshTyVar ())
             

Modified: nemerle/trunk/ncc/typing/Typer2.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer2.n	(original)
+++ nemerle/trunk/ncc/typing/Typer2.n	Sun Feb 18 22:35:38 2007
@@ -36,7 +36,7 @@
 namespace Nemerle.Compiler
 {
   [ManagerAccess]
-  internal class Typer2
+  public class Typer2
   {
     top_level_fun : MethodBuilder;
     mutable this_ptr_decl : LocalValue;
@@ -1078,7 +1078,7 @@
                           
                           | _ => 
                             ReportError (messenger, 
-                                         $ "Comparison of two nullable instances is not yet supported.");
+                                         "Comparison of two nullable instances is not yet supported.");
                             Message.HintOnce ("You can compare only with null or use Equals method.");
                             TExpr.Call (Unfold (func), parms, false)
                         }

Modified: nemerle/trunk/tools/msbuild-task/MSBuildTask.n
==============================================================================
--- nemerle/trunk/tools/msbuild-task/MSBuildTask.n	(original)
+++ nemerle/trunk/tools/msbuild-task/MSBuildTask.n	Sun Feb 18 22:35:38 2007
@@ -105,6 +105,8 @@
 
     protected override LogEventsFromTextOutput(singleLine : string, _ : MessageImportance) : void
     {
+      // System.Diagnostics.Trace.Assert(false);
+
       def get_location (before) : p {
         def str = singleLine.Substring (0, singleLine.IndexOf (before));
         if (string.IsNullOrEmpty (str)) p(null, 0,0,0,0)



More information about the svn mailing list