[svn] r6418: nemerle/trunk/ncc: parsing/AST.n parsing/MainParser.n testsuite/positive/macrolib.n testsuite...

nazgul svnadmin at nemerle.org
Sun Jul 2 15:20:43 CEST 2006


Log:
Allow enum as splicing type

Author: nazgul
Date: Sun Jul  2 15:20:15 2006
New Revision: 6418

Modified:
   nemerle/trunk/ncc/parsing/AST.n
   nemerle/trunk/ncc/parsing/MainParser.n
   nemerle/trunk/ncc/testsuite/positive/macrolib.n
   nemerle/trunk/ncc/testsuite/positive/macroprog.n
   nemerle/trunk/ncc/typing/Macros.n

Modified: nemerle/trunk/ncc/parsing/AST.n
==============================================================================
--- nemerle/trunk/ncc/parsing/AST.n	(original)
+++ nemerle/trunk/ncc/parsing/AST.n	Sun Jul  2 15:20:15 2006
@@ -654,7 +654,10 @@
           | o is System.Enum =>
             def s = o.ToString ("d");
             def tyname = NString.Split (o.GetType ().FullName, '+', '.');
-            def tc = ManagerClass.Instance.NameTree.LookupInternalType (tyname);
+            def tc = match (ManagerClass.Instance.NameTree.LookupExactType (tyname)) {
+              | Some (tc) => tc
+              | None => Message.FatalError ($"type `$(tyname.ToString (\".\"))' is not available - it is either not public or not referenced properly");
+            }
             def t = tc.GetMemType ();
             def int_lit =
               if (s [0] == '-')

Modified: nemerle/trunk/ncc/parsing/MainParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/MainParser.n	(original)
+++ nemerle/trunk/ncc/parsing/MainParser.n	Sun Jul  2 15:20:15 2006
@@ -445,6 +445,7 @@
                   def tok = get_token ();
                   pop_stream ("spliced expression");
                   match (tok) {
+                    | Token.Keyword ("enum" as ty)
                     | Token.Identifier (ty) =>
                       Splicable.Expression (loc, PExpr.TypeEnforcement
                         (loc, expr, PExpr.Ref (loc, mkname (ty))))

Modified: nemerle/trunk/ncc/testsuite/positive/macrolib.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/macrolib.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/macrolib.n	Sun Jul  2 15:20:15 2006
@@ -11,6 +11,12 @@
   Foo () : void;
 }
 
+public enum MyEnum {
+  | A
+  | B
+  | C
+}
+
 public class MyAttribute : Attribute  { }
 
 macro generateIFoo ()
@@ -398,3 +404,10 @@
    tb.TyManager.AddAssemblyAttribute (tb.GlobalEnv, <[ System.Reflection.AssemblyCompany("foo") ]>);
 }
 
+macro create_enum (val) {
+  match (val) {
+    | <[ 1 ]> => <[ $(MyEnum.A : enum) ]> 
+    | <[ 2 ]> => <[ $(MyEnum.B : enum) ]> 
+    | _ => <[ $(MyEnum.C : enum) ]> 
+  } 
+}
\ No newline at end of file

Modified: nemerle/trunk/ncc/testsuite/positive/macroprog.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/macroprog.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/macroprog.n	Sun Jul  2 15:20:15 2006
@@ -76,6 +76,8 @@
     System.Console.WriteLine (ulongLiteral ());
     
     assert ((typeof(M).Assembly.GetCustomAttributes (typeof(System.Reflection.AssemblyCompanyAttribute), false)[0] :> System.Reflection.AssemblyCompanyAttribute).Company == "foo");
+    
+    assert (create_enum (1) == MyEnum.A);
   }
 }
 

Modified: nemerle/trunk/ncc/typing/Macros.n
==============================================================================
--- nemerle/trunk/ncc/typing/Macros.n	(original)
+++ nemerle/trunk/ncc/typing/Macros.n	Sun Jul  2 15:20:15 2006
@@ -761,6 +761,7 @@
           | "float" => <[ PExpr.Literal (Literal.Float ($val)) ]>
           | "double" => <[ PExpr.Literal (Literal.Double ($val)) ]>
           | "decimal" => <[ PExpr.Literal (Literal.Decimal ($val)) ]>
+          | "enum" => <[ PExpr.Literal (Literal.FromObject ($val)) ]>
 
           | "typed" => <[ Macros.TypedChoose ($val) ]>
           | x =>



More information about the svn mailing list