CSharp preprocessor definitions

This commit is contained in:
Oiltanker
2022-04-25 17:55:53 +03:00
parent 370c0e3288
commit 6a23dece35
3 changed files with 6 additions and 11 deletions

View File

@@ -16,7 +16,6 @@ namespace Barotrauma
{
class CsScriptBase : AssemblyLoadContext
{
public static readonly List<string> PreprocessingSymbols = new List<string>();
public const string NET_ONE_TIME_SCRIPT_ASSEMBLY = "NetOneTimeScriptAssembly";
public const string NET_SCRIPT_ASSEMBLY = "NetScriptAssembly";
@@ -27,15 +26,11 @@ namespace Barotrauma
{ NET_ONE_TIME_SCRIPT_ASSEMBLY, 0}
};
public CsScriptBase() : base(isCollectible: true) { }
public CSharpParseOptions ParseOptions { get; protected set; }
static CsScriptBase()
{
#if SERVER
PreprocessingSymbols.Add("SERVER");
#else
PreprocessingSymbols.Add("CLIENT");
#endif
public CsScriptBase() : base(isCollectible: true) {
ParseOptions = CSharpParseOptions.Default
.WithPreprocessorSymbols(new[] { LuaCsSetup.IsServer ? "SERVER" : (LuaCsSetup.IsClient ? "CLIENT" : "UNDEFINED") });
}
public static SyntaxTree AssemblyInfoSyntaxTree(string asmName = null)

View File

@@ -69,7 +69,7 @@ namespace Barotrauma
{
foreach (var file in src)
{
var tree = SyntaxFactory.ParseSyntaxTree(File.ReadAllText(file), CSharpParseOptions.Default.WithPreprocessorSymbols(PreprocessingSymbols), file);
var tree = SyntaxFactory.ParseSyntaxTree(File.ReadAllText(file), ParseOptions, file);
var error = CsScriptFilter.FilterSyntaxTree(tree as CSharpSyntaxTree); // Check file content for prohibited stuff
if (error != null) throw new Exception(error);

View File

@@ -55,7 +55,7 @@ namespace Barotrauma
try
{
code = ToOneTimeScript(code);
var syntaxTree = SyntaxFactory.ParseSyntaxTree(code, CSharpParseOptions.Default.WithPreprocessorSymbols(PreprocessingSymbols));
var syntaxTree = SyntaxFactory.ParseSyntaxTree(code, ParseOptions);
var compilation = CSharpCompilation.Create(NET_ONE_TIME_SCRIPT_ASSEMBLY, new[] { AssemblyInfoSyntaxTree(NET_ONE_TIME_SCRIPT_ASSEMBLY), syntaxTree }, defaultReferences, compileOptions);
Assembly assembly = null;