[svn] r6058: nemerle/trunk: macros/Logging.n
ncc/testsuite/positive/macroprog.n
malekith
svnadmin at nemerle.org
Sun Jan 15 14:38:35 CET 2006
Log:
Add LogCondition to Nemerle.Logging.
Author: malekith
Date: Sun Jan 15 14:36:45 2006
New Revision: 6058
Modified:
nemerle/trunk/macros/Logging.n
nemerle/trunk/ncc/testsuite/positive/macroprog.n
Modified: nemerle/trunk/macros/Logging.n
==============================================================================
--- nemerle/trunk/macros/Logging.n (original)
+++ nemerle/trunk/macros/Logging.n Sun Jan 15 14:36:45 2006
@@ -42,6 +42,7 @@
// empty string holds default print function (also set when no VERB=>expr mapping is specified)
public FlagsToFunctions : Hashtable [string, PExpr] = Hashtable ();
public mutable SetPrintExpression = false;
+ public mutable AdditionalLoggingCondition : PExpr = null;
public GetName (expr : PExpr) : string
{
@@ -92,6 +93,15 @@
| _ => Message.Error ($ "expected single logging function or set of mappings from VERB to print functions");
}
}
+
+ public AddCondition (body : PExpr) : PExpr
+ {
+ if (AdditionalLoggingCondition == null) body
+ else <[
+ when ($AdditionalLoggingCondition)
+ $body
+ ]>
+ }
}
[Nemerle.MacroUsage (Nemerle.MacroPhase.BeforeInheritance,
@@ -122,6 +132,15 @@
LogFunction (fn);
}
+ [Nemerle.MacroUsage (Nemerle.MacroPhase.BeforeInheritance,
+ Nemerle.MacroTargets.Assembly)]
+ macro LogCondition (expr)
+ {
+ when (AdditionalLoggingCondition != null)
+ Message.Error ("LogCondition already set");
+ AdditionalLoggingCondition = expr;
+ }
+
macro log (flag, params exprs : list [PExpr])
{
def name = GetName (flag);
@@ -133,7 +152,7 @@
if (Flags.Contains (name))
if (Flags [name])
- <[ $print_expr (.. $exprs) ]>
+ AddCondition (<[ $print_expr (.. $exprs) ]>)
else <[ {} ]>
else {
Message.Error ($ "there is no debug flag named `$(name)'");
Modified: nemerle/trunk/ncc/testsuite/positive/macroprog.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/macroprog.n (original)
+++ nemerle/trunk/ncc/testsuite/positive/macroprog.n Sun Jan 15 14:36:45 2006
@@ -181,6 +181,8 @@
using Nemerle.Logging;
+[assembly: LogCondition (LogEnabled)]
+
[LogFunction (LogTest.dolog)]
[LogFlag (VERB, true),
@@ -188,6 +190,8 @@
public class LogTest
{
+ public mutable static LogEnabled = true;
+
public static dolog (s : string) : void
{
System.Console.WriteLine ("LOG: " + s);
@@ -204,6 +208,11 @@
log (DEBUG, "debug logging");
+ LogEnabled = false;
+ log (VERB, "hide me");
+ LogEnabled = true;
+ log (VERB, "show me");
+
def x = generateIFoo ();
(x : IFoo).Foo();
}
@@ -252,6 +261,7 @@
2
LOG: verb logging
LOG: verb logging foobar
+LOG: show me
Hello!
END-OUTPUT
*/
More information about the svn
mailing list