[svn] r6209: nemerle/trunk/ncc: external/InternalTypes.n
external/LibrariesLoader.n passes.n testsuite/pos...
malekith
svnadmin at nemerle.org
Mon May 1 11:11:27 CEST 2006
Log:
Look for types with ExtensionAttribute early, and load them right away. Fixes #661. Accomodate for more than one AssemblyConfAttr.
Author: malekith
Date: Mon May 1 11:11:25 2006
New Revision: 6209
Modified:
nemerle/trunk/ncc/external/InternalTypes.n
nemerle/trunk/ncc/external/LibrariesLoader.n
nemerle/trunk/ncc/passes.n
nemerle/trunk/ncc/testsuite/positive/extension-methods-lib.n
nemerle/trunk/ncc/testsuite/positive/extension-methods.n
Modified: nemerle/trunk/ncc/external/InternalTypes.n
==============================================================================
--- nemerle/trunk/ncc/external/InternalTypes.n (original)
+++ nemerle/trunk/ncc/external/InternalTypes.n Mon May 1 11:11:25 2006
@@ -70,6 +70,9 @@
public mutable Void : System.Type;
public mutable ParamArrayAttribute : System.Type;
+ // set in LibrariesLoader upon first possiblity
+ public mutable ExtensionAttribute : System.Type;
+
public mutable Decimal_ctors : Hashtable [string, SR.ConstructorInfo];
public mutable Type_GetTypeFromHandle : SR.MethodInfo;
public mutable AssemblyBuilder_EmbedResourceFile : SR.MethodInfo;
@@ -131,16 +134,6 @@
get { InternalType.ImmutableAttribute_tc.SystemType }
}
- public ExtensionAttribute : System.Type
- {
- get {
- if (InternalType.ExtensionAttribute_tc == null ||
- InternalType.ExtensionAttribute_tc is TypeBuilder) null
- else
- InternalType.ExtensionAttribute_tc.SystemType
- }
- }
-
public ConstantVariantOptionAttribute : System.Type
{
get { InternalType.ConstantVariantOptionAttribute_tc.SystemType }
Modified: nemerle/trunk/ncc/external/LibrariesLoader.n
==============================================================================
--- nemerle/trunk/ncc/external/LibrariesLoader.n (original)
+++ nemerle/trunk/ncc/external/LibrariesLoader.n Mon May 1 11:11:25 2006
@@ -81,6 +81,7 @@
unless (Options.PersistentLibraries) {
_loaded_assemblies_by_name.Clear ();
_assemblies_loaded_by_hand.Clear ();
+ AllowLoadingExtensions = false;
}
}
@@ -118,6 +119,8 @@
{
unless (_loaded_assemblies_by_name.Contains (assembly.FullName)) {
_ = LibraryReference (assembly);
+ when (AllowLoadingExtensions)
+ LoadExtensions ();
_loaded_assemblies_by_name.Set (assembly.FullName, assembly);
when (Options.GreedyReferences) {
@@ -297,10 +300,20 @@
private _assemblies_loaded_by_hand : Hashtable [string, object] = Hashtable (20);
private namespace_nodes : Hashtable [string, NamespaceTree.Node] = Hashtable (300);
+ private mutable _construct_right_away : list [NamespaceTree.Node] = [];
/* -- TYPE CACHE ----- */
+ internal mutable AllowLoadingExtensions : bool;
+
+ internal LoadExtensions () : void
+ {
+ foreach (n in _construct_right_away)
+ _ = n.LookupValue ();
+ _construct_right_away = [];
+ }
+
[Record]
public class ExternalType {
internal system_type : System.Type;
@@ -320,6 +333,12 @@
def assembly = lib.GetAssembly ();
def types = assembly.GetExportedTypes ();
+ when (SystemType.ExtensionAttribute == null) {
+ def t = assembly.GetType ("Nemerle.Internal.ExtensionAttribute");
+ when (t != null)
+ SystemType.ExtensionAttribute = t;
+ }
+
mutable i = 0;
for (; i < types.Length; ++i) {
def t = types[i];
@@ -331,6 +350,10 @@
def mainnode = ns_node.Path (path_to_type);
+ when (SystemType.ExtensionAttribute != null &&
+ t.IsDefined (SystemType.ExtensionAttribute, false))
+ _construct_right_away ::= mainnode;
+
mutable tinfo_cache = null;
// check if we have met such type before
@@ -344,7 +367,7 @@
| _ =>
tinfo_cache = NamespaceTree.TypeInfoCache.NotLoaded (e);
- };
+ }
// assign wrappers for future loading of typecons
mainnode.Value = tinfo_cache;
@@ -469,7 +492,7 @@
// Scans the assembly custom attributes looking for something interesting...
foreach (x :> SR.AssemblyConfigurationAttribute in
_library.GetCustomAttributes (typeof (SR.AssemblyConfigurationAttribute), false))
- _is_generated_by_nemerle = x.Configuration == "ContainsNemerleTypes";
+ _is_generated_by_nemerle = _is_generated_by_nemerle || x.Configuration == "ContainsNemerleTypes";
LibraryReferenceManager.LoadTypesFrom (this);
LibraryReferenceManager.LoadMacrosFrom (_library);
Modified: nemerle/trunk/ncc/passes.n
==============================================================================
--- nemerle/trunk/ncc/passes.n (original)
+++ nemerle/trunk/ncc/passes.n Mon May 1 11:11:25 2006
@@ -172,6 +172,8 @@
SystemType.Init ();
InternalType.InitSystemTypes ();
unless (Options.DoNotLoadStdlib) InternalType.InitNemerleTypes ();
+ LibraryReferenceManager.LoadExtensions ();
+ LibraryReferenceManager.AllowLoadingExtensions = true;
unless (Options.DoNotLoadMacros)
LibraryReferenceManager.LoadMacrosFrom ("Nemerle.Macros");
Modified: nemerle/trunk/ncc/testsuite/positive/extension-methods-lib.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/extension-methods-lib.n (original)
+++ nemerle/trunk/ncc/testsuite/positive/extension-methods-lib.n Mon May 1 11:11:25 2006
@@ -14,6 +14,11 @@
public class C : A
x : string
+namespace SomeDeepNamespace
+ public class OtherwiseUnusedClass
+ public static ToList[T] (this a : array [T]) : list [T]
+ List.FromArray (a)
+
public class B
public static foo (this a : A, p : int) : void
Write ($"foo($(a.v),$p)\n")
Modified: nemerle/trunk/ncc/testsuite/positive/extension-methods.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/extension-methods.n (original)
+++ nemerle/trunk/ncc/testsuite/positive/extension-methods.n Mon May 1 11:11:25 2006
@@ -18,7 +18,7 @@
a.Rev ()
System.Console.WriteLine (List.FromArray (a))
B.Rev (a)
-System.Console.WriteLine (List.FromArray (a))
+System.Console.WriteLine (a.ToList ())
/*
BEGIN-OUTPUT
More information about the svn
mailing list