diff --git a/Source/Engine/Core/Compiler.h b/Source/Engine/Core/Compiler.h index 1c072f07e..3fef41b26 100644 --- a/Source/Engine/Core/Compiler.h +++ b/Source/Engine/Core/Compiler.h @@ -19,7 +19,7 @@ #define ALIGN_BEGIN(_align) #define ALIGN_END(_align) __attribute__( (aligned(_align) ) ) #define OFFSET_OF(X, Y) __builtin_offsetof(X, Y) -#define DEPRECATED +#define DEPRECATED [[deprecated]] #pragma clang diagnostic ignored "-Wswitch" #pragma clang diagnostic ignored "-Wmacro-redefined" @@ -44,7 +44,7 @@ #define ALIGN_BEGIN(_align) #define ALIGN_END(_align) __attribute__( (aligned(_align) ) ) #define OFFSET_OF(X, Y) __builtin_offsetof(X, Y) -#define DEPRECATED __attribute__((deprecated)) +#define DEPRECATED [[deprecated]] #elif defined(__INTEL_COMPILER) diff --git a/Source/Tools/Flax.Build/Bindings/ApiTypeInfo.cs b/Source/Tools/Flax.Build/Bindings/ApiTypeInfo.cs index 6667aab9f..8b64f719d 100644 --- a/Source/Tools/Flax.Build/Bindings/ApiTypeInfo.cs +++ b/Source/Tools/Flax.Build/Bindings/ApiTypeInfo.cs @@ -18,6 +18,7 @@ namespace Flax.Build.Bindings public string Attributes; public string[] Comment; public bool IsInBuild; + public bool IsDeprecated; internal bool IsInited; public virtual bool IsClass => false; @@ -107,6 +108,7 @@ namespace Flax.Build.Bindings BindingsGenerator.Write(writer, Attributes); BindingsGenerator.Write(writer, Comment); writer.Write(IsInBuild); + writer.Write(IsDeprecated); BindingsGenerator.Write(writer, Children); } @@ -118,6 +120,7 @@ namespace Flax.Build.Bindings Attributes = BindingsGenerator.Read(reader, Attributes); Comment = BindingsGenerator.Read(reader, Comment); IsInBuild = reader.ReadBoolean(); + IsDeprecated = reader.ReadBoolean(); Children = BindingsGenerator.Read(reader, Children); // Fix hierarchy diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index 00cfc1c80..dc39322d3 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -475,7 +475,7 @@ namespace Flax.Build.Bindings } } - private static void GenerateCSharpAttributes(BuildData buildData, StringBuilder contents, string indent, ApiTypeInfo apiTypeInfo, string attributes, string[] comment, bool canUseTooltip, bool useUnmanaged, string defaultValue = null) + private static void GenerateCSharpAttributes(BuildData buildData, StringBuilder contents, string indent, ApiTypeInfo apiTypeInfo, string attributes, string[] comment, bool canUseTooltip, bool useUnmanaged, string defaultValue = null, bool isDeprecated = false) { var writeTooltip = true; var writeDefaultValue = true; @@ -492,6 +492,11 @@ namespace Flax.Build.Bindings // Write attribute for C++ calling code contents.Append(indent).AppendLine("[Unmanaged]"); } + if (isDeprecated || apiTypeInfo.IsDeprecated) + { + // Deprecated type + contents.Append(indent).AppendLine("[Obsolete]"); + } if (canUseTooltip && writeTooltip && @@ -537,7 +542,7 @@ namespace Flax.Build.Bindings private static void GenerateCSharpAttributes(BuildData buildData, StringBuilder contents, string indent, ApiTypeInfo apiTypeInfo, MemberInfo memberInfo, bool useUnmanaged, string defaultValue = null) { - GenerateCSharpAttributes(buildData, contents, indent, apiTypeInfo, memberInfo.Attributes, memberInfo.Comment, true, useUnmanaged, defaultValue); + GenerateCSharpAttributes(buildData, contents, indent, apiTypeInfo, memberInfo.Attributes, memberInfo.Comment, true, useUnmanaged, defaultValue, memberInfo.IsDeprecated); } private static void GenerateCSharpClass(BuildData buildData, StringBuilder contents, string indent, ClassInfo classInfo) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cache.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cache.cs index 079d9ea0a..ef959712a 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cache.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cache.cs @@ -19,7 +19,7 @@ namespace Flax.Build.Bindings partial class BindingsGenerator { private static readonly Dictionary TypeCache = new Dictionary(); - private const int CacheVersion = 9; + private const int CacheVersion = 10; internal static void Write(BinaryWriter writer, string e) { diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs index 9569c15c5..a240cc454 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs @@ -2062,6 +2062,8 @@ namespace Flax.Build.Bindings contents.AppendLine("// This code was auto-generated. Do not modify it."); contents.AppendLine(); + if (buildData.Platform is Platforms.WindowsPlatformBase) + contents.AppendLine("#pragma warning(disable: 4996)").AppendLine(); // Ignore deprecated warnings contents.AppendLine("#include \"Engine/Scripting/Scripting.h\""); contents.AppendLine("#include \"Engine/Scripting/InternalCalls.h\""); contents.AppendLine("#include \"Engine/Scripting/ManagedCLR/MUtils.h\""); diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs index 91fc60e16..e4097a1d1 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs @@ -496,6 +496,21 @@ namespace Flax.Build.Bindings if (token.Value != "class") throw new Exception($"Invalid API_CLASS usage (expected 'class' keyword but got '{token.Value} {context.Tokenizer.NextToken().Value}')."); + // Read specifiers + while (true) + { + token = context.Tokenizer.NextToken(); + if (!desc.IsDeprecated && token.Value == "DEPRECATED") + { + desc.IsDeprecated = true; + } + else + { + context.Tokenizer.PreviousToken(); + break; + } + } + // Read name desc.Name = desc.NativeName = ParseName(ref context); @@ -574,6 +589,21 @@ namespace Flax.Build.Bindings if (token.Value != "class") throw new Exception($"Invalid API_INTERFACE usage (expected 'class' keyword but got '{token.Value} {context.Tokenizer.NextToken().Value}')."); + // Read specifiers + while (true) + { + token = context.Tokenizer.NextToken(); + if (!desc.IsDeprecated && token.Value == "DEPRECATED") + { + desc.IsDeprecated = true; + } + else + { + context.Tokenizer.PreviousToken(); + break; + } + } + // Read name desc.Name = desc.NativeName = ParseName(ref context); @@ -629,7 +659,7 @@ namespace Flax.Build.Bindings var tagParams = ParseTagParameters(ref context); context.Tokenizer.SkipUntil(TokenType.Identifier); - // Read 'static' or 'FORCE_INLINE' or 'virtual' + // Read specifiers var isForceInline = false; while (true) { @@ -649,6 +679,11 @@ namespace Flax.Build.Bindings desc.IsVirtual = true; context.Tokenizer.NextToken(); } + else if (!desc.IsDeprecated && token.Value == "DEPRECATED") + { + desc.IsDeprecated = true; + context.Tokenizer.NextToken(); + } else { context.Tokenizer.PreviousToken(); @@ -781,6 +816,7 @@ namespace Flax.Build.Bindings propertyInfo.Getter = functionInfo; else propertyInfo.Setter = functionInfo; + propertyInfo.IsDeprecated |= functionInfo.IsDeprecated; if (propertyInfo.Getter != null && propertyInfo.Setter != null) { @@ -1044,9 +1080,9 @@ namespace Flax.Build.Bindings var tagParams = ParseTagParameters(ref context); context.Tokenizer.SkipUntil(TokenType.Identifier); - // Read 'static' or 'mutable' + // Read specifiers Token token; - var isMutable = false; + bool isMutable = false, isVolatile = false; while (true) { token = context.Tokenizer.CurrentToken; @@ -1060,6 +1096,16 @@ namespace Flax.Build.Bindings isMutable = true; context.Tokenizer.NextToken(); } + else if (!isVolatile && token.Value == "volatile") + { + isVolatile = true; + context.Tokenizer.NextToken(); + } + else if (!desc.IsDeprecated && token.Value == "DEPRECATED") + { + desc.IsDeprecated = true; + context.Tokenizer.NextToken(); + } else { context.Tokenizer.PreviousToken(); diff --git a/Source/Tools/Flax.Build/Bindings/MemberInfo.cs b/Source/Tools/Flax.Build/Bindings/MemberInfo.cs index 49187c101..a005a468a 100644 --- a/Source/Tools/Flax.Build/Bindings/MemberInfo.cs +++ b/Source/Tools/Flax.Build/Bindings/MemberInfo.cs @@ -12,6 +12,7 @@ namespace Flax.Build.Bindings public string Name; public string[] Comment; public bool IsStatic; + public bool IsDeprecated; public AccessLevel Access; public string Attributes; @@ -25,6 +26,7 @@ namespace Flax.Build.Bindings writer.Write(Name); BindingsGenerator.Write(writer, Comment); writer.Write(IsStatic); + writer.Write(IsDeprecated); writer.Write((byte)Access); BindingsGenerator.Write(writer, Attributes); } @@ -34,6 +36,7 @@ namespace Flax.Build.Bindings Name = reader.ReadString(); Comment = BindingsGenerator.Read(reader, Comment); IsStatic = reader.ReadBoolean(); + IsDeprecated = reader.ReadBoolean(); Access = (AccessLevel)reader.ReadByte(); Attributes = BindingsGenerator.Read(reader, Attributes); } diff --git a/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchainBase.cs b/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchainBase.cs index 5caf3e806..43f4bd6b7 100644 --- a/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchainBase.cs +++ b/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchainBase.cs @@ -455,10 +455,6 @@ namespace Flax.Build.Platforms if (compileEnvironment.RuntimeChecks && !compileEnvironment.CompileAsWinRT) commonArgs.Add("/RTC1"); - // Enable Additional Security Checks - if (compileEnvironment.RuntimeChecks) - commonArgs.Add("/sdl"); - // Inline Function Expansion if (compileEnvironment.Inlining) commonArgs.Add("/Ob2"); @@ -548,7 +544,6 @@ namespace Flax.Build.Platforms commonArgs.Add("/WX-"); // Show warnings - // TODO: compile with W4 and fix all warnings commonArgs.Add("/W3"); // Silence macro redefinition warning