[w32handle] Stop returning 0 in every cases for locking/unlocking (#3926)
[mono.git] / mcs / tools / linker / Mono.Linker.Steps / ResolveFromAssemblyStep.cs
index f9aa7a117b4ad41b442443cb7e3710e4f09db49c..6219bc92ffc27d21e83361e511e2dce69db5508e 100644 (file)
@@ -48,43 +48,72 @@ namespace Mono.Linker.Steps {
 
                protected override void Process ()
                {
-                       if (_assembly != null) {
-                               Context.SafeLoadSymbols (_assembly);
+                       if (_assembly != null)
                                Context.Resolver.CacheAssembly (_assembly);
-                       }
 
                        AssemblyDefinition assembly = _assembly ?? Context.Resolve (_file);
 
                        switch (assembly.MainModule.Kind) {
                        case ModuleKind.Dll:
                                ProcessLibrary (Context, assembly);
-                               return;
+                               break;
                        default:
                                ProcessExecutable (assembly);
-                               return;
+                               break;
                        }
                }
 
+               static void SetAction (LinkContext context, AssemblyDefinition assembly, AssemblyAction action)
+               {
+                       TryReadSymbols (context, assembly);
+
+                       context.Annotations.SetAction (assembly, action);
+               }
+
+               static void TryReadSymbols (LinkContext context, AssemblyDefinition assembly)
+               {
+                       context.SafeReadSymbols (assembly);
+               }
+
                public static void ProcessLibrary (LinkContext context, AssemblyDefinition assembly)
                {
-                       context.Annotations.SetAction (assembly, AssemblyAction.Copy);
+                       SetAction (context, assembly, AssemblyAction.Copy);
 
-                       foreach (TypeDefinition type in assembly.MainModule.Types) {
-                               context.Annotations.Mark (type);
+                       context.Annotations.Push (assembly);
 
-                               if (type.HasFields)
-                                       MarkFields (context, type.Fields);
-                               if (type.HasMethods)
-                                       MarkMethods (context, type.Methods);
-                       }
+                       foreach (TypeDefinition type in assembly.MainModule.Types)
+                               MarkType (context, type);
+
+                       context.Annotations.Pop ();
+               }
+
+               static void MarkType (LinkContext context, TypeDefinition type)
+               {
+                       context.Annotations.Mark (type);
+
+                       context.Annotations.Push (type);
+
+                       if (type.HasFields)
+                               MarkFields (context, type.Fields);
+                       if (type.HasMethods)
+                               MarkMethods (context, type.Methods);
+                       if (type.HasNestedTypes)
+                               foreach (var nested in type.NestedTypes)
+                                       MarkType (context, nested);
+
+                       context.Annotations.Pop ();
                }
 
                void ProcessExecutable (AssemblyDefinition assembly)
                {
-                       Annotations.SetAction (assembly, AssemblyAction.Link);
+                       SetAction (Context, assembly, AssemblyAction.Link);
+
+                       Annotations.Push (assembly);
 
                        Annotations.Mark (assembly.EntryPoint.DeclaringType);
                        MarkMethod (Context, assembly.EntryPoint, MethodAction.Parse);
+
+                       Annotations.Pop ();
                }
 
                static void MarkFields (LinkContext context, ICollection fields)