[w32handle] Stop returning 0 in every cases for locking/unlocking (#3926)
[mono.git] / mcs / tools / linker / Mono.Linker.Steps / ResolveFromAssemblyStep.cs
index 44cb2d26a0b62014c8b254d0a1fc55cba539f63d..6219bc92ffc27d21e83361e511e2dce69db5508e 100644 (file)
@@ -33,56 +33,105 @@ namespace Mono.Linker.Steps {
 
        public class ResolveFromAssemblyStep : ResolveStep {
 
-               string _assembly;
+               AssemblyDefinition _assembly;
+               string _file;
 
                public ResolveFromAssemblyStep (string assembly)
+               {
+                       _file = assembly;
+               }
+
+               public ResolveFromAssemblyStep (AssemblyDefinition assembly)
                {
                        _assembly = assembly;
                }
 
-               public override void Process (LinkContext context)
+               protected override void Process ()
                {
-                       AssemblyDefinition assembly = context.Resolve (_assembly);
+                       if (_assembly != null)
+                               Context.Resolver.CacheAssembly (_assembly);
 
-                       switch (assembly.Kind) {
-                       case AssemblyKind.Dll:
-                               ProcessLibrary (assembly);
-                               return;
+                       AssemblyDefinition assembly = _assembly ?? Context.Resolve (_file);
+
+                       switch (assembly.MainModule.Kind) {
+                       case ModuleKind.Dll:
+                               ProcessLibrary (Context, assembly);
+                               break;
                        default:
                                ProcessExecutable (assembly);
-                               return;
+                               break;
                        }
                }
 
-               static void ProcessLibrary (AssemblyDefinition assembly)
+               static void SetAction (LinkContext context, AssemblyDefinition assembly, AssemblyAction action)
                {
-                       Annotations.SetAction (assembly, AssemblyAction.Copy);
+                       TryReadSymbols (context, assembly);
 
-                       foreach (TypeDefinition type in assembly.MainModule.Types) {
-                               Annotations.Mark (type);
+                       context.Annotations.SetAction (assembly, action);
+               }
 
-                               MarkMethods (type.Methods);
-                               MarkMethods (type.Constructors);
-                       }
+               static void TryReadSymbols (LinkContext context, AssemblyDefinition assembly)
+               {
+                       context.SafeReadSymbols (assembly);
+               }
+
+               public static void ProcessLibrary (LinkContext context, AssemblyDefinition assembly)
+               {
+                       SetAction (context, assembly, AssemblyAction.Copy);
+
+                       context.Annotations.Push (assembly);
+
+                       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 ();
                }
 
-               static void ProcessExecutable (AssemblyDefinition assembly)
+               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);
 
-                       MarkMethod (assembly.EntryPoint);
+                       Annotations.Pop ();
+               }
+
+               static void MarkFields (LinkContext context, ICollection fields)
+               {
+                       foreach (FieldDefinition field in fields)
+                               context.Annotations.Mark (field);
                }
 
-               static void MarkMethods (ICollection methods)
+               static void MarkMethods (LinkContext context, ICollection methods)
                {
                        foreach (MethodDefinition method in methods)
-                               MarkMethod (method);
+                               MarkMethod (context, method, MethodAction.ForceParse);
                }
 
-               static void MarkMethod (MethodDefinition method)
+               static void MarkMethod (LinkContext context, MethodDefinition method, MethodAction action)
                {
-                       Annotations.Mark (method);
-                       Annotations.SetAction (method, MethodAction.ForceParse);
+                       context.Annotations.Mark (method);
+                       context.Annotations.SetAction (method, action);
                }
        }
 }