mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 01:41:18 -10:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
feaf598cf9 | ||
|
|
42830053e9 | ||
|
|
96eb32c659 |
No files matched your search
@@ -672,6 +672,34 @@ namespace Mono.CSharp
|
||||
|
||||
#endregion
|
||||
|
||||
#region Hooks
|
||||
|
||||
CompilerHooks hooks = new CompilerHooks ();
|
||||
public CompilerHooks Hooks {
|
||||
get { return hooks; }
|
||||
}
|
||||
|
||||
public class CompilerHooks {
|
||||
public Func<bool> DriverEnter { get; set; }
|
||||
public Func<bool> DriverExit { get; set; }
|
||||
public Func<bool> BeforeModuleLoaded { get; set; }
|
||||
public Func<ModuleContainer, bool> AfterModuleLoaded { get; set; }
|
||||
public Func<bool> BeforeParsed { get; set; }
|
||||
public Func<bool> AfterParsed { get; set; }
|
||||
public Func<bool> BeforeTypesResolved { get; set; }
|
||||
public Func<AssemblyDefinition, bool> AfterTypesResolved { get; set; }
|
||||
public Func<bool> BeforeAssemblyEmitted { get; set; }
|
||||
public Func<bool> AfterAssemblyEmitted { get; set; }
|
||||
public Func<bool> BeforeModuleClosed { get; set; }
|
||||
public Func<bool> AfterModuleClosed { get; set; }
|
||||
public Func<bool> BeforeEmbedResources { get; set; }
|
||||
public Func<bool> AfterEmbedResources { get; set; }
|
||||
public Func<bool> BeforeAssemblySaved { get; set; }
|
||||
public Func<bool> AfterAssemblySaved { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//
|
||||
// This is used when we encounter a #line preprocessing directive during parsing
|
||||
// to register additional source file names
|
||||
|
||||
@@ -221,6 +221,8 @@ namespace Mono.CSharp {
|
||||
[System.Diagnostics.DebuggerDisplay ("{GetSignatureForError()}")]
|
||||
public abstract class MemberCore : Attributable, IMemberContext, IMemberDefinition
|
||||
{
|
||||
public object Tag { get; set; }
|
||||
|
||||
string IMemberDefinition.Name {
|
||||
get {
|
||||
return member_name.Name;
|
||||
|
||||
@@ -248,6 +248,16 @@ namespace Mono.CSharp
|
||||
{
|
||||
var settings = ctx.Settings;
|
||||
|
||||
if (settings.CompilerHooksAssembly != null) {
|
||||
var hooks_assembly = Assembly.LoadFile (settings.CompilerHooksAssembly);
|
||||
var hooks_factory = hooks_assembly.GetType ("CompilerHooksEntry", true);
|
||||
var hooks_factory_create = hooks_factory.GetMethod ("ContextCreated");
|
||||
hooks_factory_create.Invoke (null, new [] { ctx });
|
||||
}
|
||||
|
||||
if (ctx.Hooks.DriverEnter != null && !ctx.Hooks.DriverEnter ())
|
||||
return false;
|
||||
|
||||
//
|
||||
// If we are an exe, require a source file for the entry point or
|
||||
// if there is nothing to put in the assembly, and we are not a library
|
||||
@@ -268,13 +278,26 @@ namespace Mono.CSharp
|
||||
ctx.TimeReporter = tr;
|
||||
tr.StartTotal ();
|
||||
|
||||
if (ctx.Hooks.BeforeModuleLoaded != null && !ctx.Hooks.BeforeModuleLoaded ())
|
||||
return false;
|
||||
|
||||
var module = new ModuleContainer (ctx);
|
||||
|
||||
if (ctx.Hooks.AfterModuleLoaded != null && !ctx.Hooks.AfterModuleLoaded (module))
|
||||
return false;
|
||||
|
||||
RootContext.ToplevelTypes = module;
|
||||
|
||||
if (ctx.Hooks.BeforeParsed != null && !ctx.Hooks.BeforeParsed ())
|
||||
return false;
|
||||
|
||||
tr.Start (TimeReporter.TimerType.ParseTotal);
|
||||
Parse (module);
|
||||
tr.Stop (TimeReporter.TimerType.ParseTotal);
|
||||
|
||||
if (ctx.Hooks.AfterParsed != null && !ctx.Hooks.AfterParsed ())
|
||||
return false;
|
||||
|
||||
if (Report.Errors > 0)
|
||||
return false;
|
||||
|
||||
@@ -312,6 +335,9 @@ namespace Mono.CSharp
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx.Hooks.BeforeTypesResolved != null && !ctx.Hooks.BeforeTypesResolved ())
|
||||
return false;
|
||||
|
||||
#if STATIC
|
||||
var importer = new StaticImporter (module);
|
||||
var references_loader = new StaticLoader (importer, ctx);
|
||||
@@ -375,38 +401,67 @@ namespace Mono.CSharp
|
||||
|
||||
assembly.Resolve ();
|
||||
|
||||
if (ctx.Hooks.AfterTypesResolved != null && !ctx.Hooks.AfterTypesResolved (assembly))
|
||||
return false;
|
||||
|
||||
if (Report.Errors > 0)
|
||||
return false;
|
||||
|
||||
if (ctx.Hooks.BeforeAssemblyEmitted != null && !ctx.Hooks.BeforeAssemblyEmitted ())
|
||||
return false;
|
||||
|
||||
tr.Start (TimeReporter.TimerType.EmitTotal);
|
||||
assembly.Emit ();
|
||||
tr.Stop (TimeReporter.TimerType.EmitTotal);
|
||||
|
||||
if (ctx.Hooks.AfterAssemblyEmitted != null && !ctx.Hooks.AfterAssemblyEmitted ())
|
||||
return false;
|
||||
|
||||
if (Report.Errors > 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ctx.Hooks.BeforeModuleClosed != null && !ctx.Hooks.BeforeModuleClosed ())
|
||||
return false;
|
||||
|
||||
tr.Start (TimeReporter.TimerType.CloseTypes);
|
||||
module.CloseContainer ();
|
||||
tr.Stop (TimeReporter.TimerType.CloseTypes);
|
||||
|
||||
if (ctx.Hooks.AfterModuleClosed != null && !ctx.Hooks.AfterModuleClosed ())
|
||||
return false;
|
||||
|
||||
if (ctx.Hooks.BeforeEmbedResources != null && !ctx.Hooks.BeforeEmbedResources ())
|
||||
return false;
|
||||
|
||||
tr.Start (TimeReporter.TimerType.Resouces);
|
||||
if (!settings.WriteMetadataOnly)
|
||||
assembly.EmbedResources ();
|
||||
tr.Stop (TimeReporter.TimerType.Resouces);
|
||||
|
||||
if (ctx.Hooks.AfterEmbedResources != null && !ctx.Hooks.AfterEmbedResources ())
|
||||
return false;
|
||||
|
||||
if (Report.Errors > 0)
|
||||
return false;
|
||||
|
||||
if (ctx.Hooks.BeforeAssemblySaved != null && !ctx.Hooks.BeforeAssemblySaved ())
|
||||
return false;
|
||||
|
||||
assembly.Save ();
|
||||
|
||||
if (ctx.Hooks.AfterAssemblySaved != null && !ctx.Hooks.AfterAssemblySaved ())
|
||||
return false;
|
||||
|
||||
#if STATIC
|
||||
references_loader.Dispose ();
|
||||
#endif
|
||||
tr.StopTotal ();
|
||||
tr.ShowStats ();
|
||||
|
||||
if (ctx.Hooks.DriverExit != null && !ctx.Hooks.DriverExit ())
|
||||
return false;
|
||||
|
||||
return Report.Errors == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ namespace Mono.CSharp {
|
||||
public bool EnhancedWarnings;
|
||||
public bool LoadDefaultReferences;
|
||||
public string SdkVersion;
|
||||
public string CompilerHooksAssembly;
|
||||
|
||||
public string StrongNameKeyFile;
|
||||
public string StrongNameKeyContainer;
|
||||
@@ -1180,6 +1181,14 @@ namespace Mono.CSharp {
|
||||
}
|
||||
return ParseResult.Success;
|
||||
|
||||
case "/compilerhooks":
|
||||
if (value.Length == 0) {
|
||||
Error_RequiresFileName (option);
|
||||
return ParseResult.Error;
|
||||
}
|
||||
settings.CompilerHooksAssembly = value;
|
||||
return ParseResult.Success;
|
||||
|
||||
default:
|
||||
return ParseResult.UnknownOption;
|
||||
}
|
||||
@@ -1543,6 +1552,7 @@ namespace Mono.CSharp {
|
||||
" -warnaserror[+|-]:W1[,Wn] Treats one or more compiler warnings as errors\n" +
|
||||
" -warn:0-4 Sets warning level, the default is 4 (short -w:)\n" +
|
||||
" -helpinternal Shows internal and advanced compiler options\n" +
|
||||
" -compilerhooks:ASSEMBLY Load a compiler hooks assembly\n" +
|
||||
"\n" +
|
||||
"Resources:\n" +
|
||||
" -linkresource:FILE[,ID] Links FILE as a resource (short: -linkres)\n" +
|
||||
|
||||
Reference in new issue
Block a user