From 2887c5979b50ebfd4b9c50c5674cf3a0465bf0d9 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Sat, 30 Sep 2023 10:35:07 +0100 Subject: [PATCH] Add Method.IsVolatile property. Fixes https://github.com/mono/CppSharp/issues/1761 --- src/AST/Method.cs | 5 ++++- src/CppParser/AST.cpp | 1 + src/CppParser/Bindings/CLI/Decl.cpp | 10 ++++++++++ src/CppParser/Bindings/CLI/Decl.h | 6 ++++++ .../CppSharp.CppParser.cs | 16 +++++++++++++++- .../i686-pc-win32-msvc/CppSharp.CppParser.cs | 16 +++++++++++++++- .../CppSharp.CppParser.cs | 14 ++++++++++++++ .../CppSharp.CppParser.cs | 14 ++++++++++++++ .../x86_64-linux-gnu/CppSharp.CppParser.cs | 14 ++++++++++++++ .../x86_64-pc-win32-msvc/CppSharp.CppParser.cs | 14 ++++++++++++++ src/CppParser/Decl.h | 1 + src/CppParser/Parser.cpp | 1 + src/Generator.Tests/AST/TestAST.cs | 8 ++++++++ src/Parser/ASTConverter.cs | 3 +++ tests/dotnet/Native/AST.h | 6 ++++++ 15 files changed, 126 insertions(+), 3 deletions(-) diff --git a/src/AST/Method.cs b/src/AST/Method.cs index 286eb01af9..1898510cc4 100644 --- a/src/AST/Method.cs +++ b/src/AST/Method.cs @@ -94,10 +94,12 @@ public Method(Method method) { Access = method.Access; IsVirtual = method.IsVirtual; + IsStatic = method.IsStatic; IsConst = method.IsConst; + IsExplicit = method.IsExplicit; + IsVolatile = method.IsVolatile; IsFinal = method.IsFinal; IsProxy = method.IsProxy; - IsStatic = method.IsStatic; Kind = method.Kind; IsDefaultConstructor = method.IsDefaultConstructor; IsCopyConstructor = method.IsCopyConstructor; @@ -119,6 +121,7 @@ public Method(Function function) public bool IsStatic { get; set; } public bool IsConst { get; set; } public bool IsExplicit { get; set; } + public bool IsVolatile { get; set; } public bool IsOverride { diff --git a/src/CppParser/AST.cpp b/src/CppParser/AST.cpp index 2e67759824..b01cb8debd 100644 --- a/src/CppParser/AST.cpp +++ b/src/CppParser/AST.cpp @@ -674,6 +674,7 @@ Method::Method() , isStatic(false) , isConst(false) , isExplicit(false) + , isVolatile(false) , isDefaultConstructor(false) , isCopyConstructor(false) , isMoveConstructor(false) diff --git a/src/CppParser/Bindings/CLI/Decl.cpp b/src/CppParser/Bindings/CLI/Decl.cpp index 36772ac7ca..6afab65ea7 100644 --- a/src/CppParser/Bindings/CLI/Decl.cpp +++ b/src/CppParser/Bindings/CLI/Decl.cpp @@ -2028,6 +2028,16 @@ void CppSharp::Parser::AST::Method::IsExplicit::set(bool value) ((class ::CppSharp::CppParser::AST::Method*)NativePtr)->isExplicit = value; } +bool CppSharp::Parser::AST::Method::IsVolatile::get() +{ + return ((class ::CppSharp::CppParser::AST::Method*)NativePtr)->isVolatile; +} + +void CppSharp::Parser::AST::Method::IsVolatile::set(bool value) +{ + ((class ::CppSharp::CppParser::AST::Method*)NativePtr)->isVolatile = value; +} + CppSharp::Parser::AST::CXXMethodKind CppSharp::Parser::AST::Method::MethodKind::get() { return (CppSharp::Parser::AST::CXXMethodKind)((class ::CppSharp::CppParser::AST::Method*)NativePtr)->methodKind; diff --git a/src/CppParser/Bindings/CLI/Decl.h b/src/CppParser/Bindings/CLI/Decl.h index 8c9044c774..cfc54e8565 100644 --- a/src/CppParser/Bindings/CLI/Decl.h +++ b/src/CppParser/Bindings/CLI/Decl.h @@ -1120,6 +1120,12 @@ namespace CppSharp void set(bool); } + property bool IsVolatile + { + bool get(); + void set(bool); + } + property CppSharp::Parser::AST::CXXMethodKind MethodKind { CppSharp::Parser::AST::CXXMethodKind get(); diff --git a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs index 71c74eac5c..fe8c0db530 100644 --- a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs @@ -9350,7 +9350,7 @@ public uint ParametersCount public unsafe partial class Method : global::CppSharp.Parser.AST.Function, IDisposable { - [StructLayout(LayoutKind.Sequential, Size = 372)] + [StructLayout(LayoutKind.Sequential, Size = 376)] public new partial struct __Internal { internal global::CppSharp.Parser.AST.DeclarationKind kind; @@ -9410,6 +9410,7 @@ public unsafe partial class Method : global::CppSharp.Parser.AST.Function, IDisp internal byte isStatic; internal byte isConst; internal byte isExplicit; + internal byte isVolatile; internal global::CppSharp.Parser.AST.CXXMethodKind methodKind; internal byte isDefaultConstructor; internal byte isCopyConstructor; @@ -9592,6 +9593,19 @@ public bool IsExplicit } } + public bool IsVolatile + { + get + { + return ((__Internal*)__Instance)->isVolatile != 0; + } + + set + { + ((__Internal*)__Instance)->isVolatile = (byte) (value ? 1 : 0); + } + } + public global::CppSharp.Parser.AST.CXXMethodKind MethodKind { get diff --git a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs index b83d0f97ed..076c7153e9 100644 --- a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs @@ -9350,7 +9350,7 @@ public uint ParametersCount public unsafe partial class Method : global::CppSharp.Parser.AST.Function, IDisposable { - [StructLayout(LayoutKind.Sequential, Size = 440)] + [StructLayout(LayoutKind.Sequential, Size = 444)] public new partial struct __Internal { internal global::CppSharp.Parser.AST.DeclarationKind kind; @@ -9410,6 +9410,7 @@ public unsafe partial class Method : global::CppSharp.Parser.AST.Function, IDisp internal byte isStatic; internal byte isConst; internal byte isExplicit; + internal byte isVolatile; internal global::CppSharp.Parser.AST.CXXMethodKind methodKind; internal byte isDefaultConstructor; internal byte isCopyConstructor; @@ -9592,6 +9593,19 @@ public bool IsExplicit } } + public bool IsVolatile + { + get + { + return ((__Internal*)__Instance)->isVolatile != 0; + } + + set + { + ((__Internal*)__Instance)->isVolatile = (byte) (value ? 1 : 0); + } + } + public global::CppSharp.Parser.AST.CXXMethodKind MethodKind { get diff --git a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs index fe3ab591a7..0aee6b458e 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs @@ -9410,6 +9410,7 @@ public unsafe partial class Method : global::CppSharp.Parser.AST.Function, IDisp internal byte isStatic; internal byte isConst; internal byte isExplicit; + internal byte isVolatile; internal global::CppSharp.Parser.AST.CXXMethodKind methodKind; internal byte isDefaultConstructor; internal byte isCopyConstructor; @@ -9592,6 +9593,19 @@ public bool IsExplicit } } + public bool IsVolatile + { + get + { + return ((__Internal*)__Instance)->isVolatile != 0; + } + + set + { + ((__Internal*)__Instance)->isVolatile = (byte) (value ? 1 : 0); + } + } + public global::CppSharp.Parser.AST.CXXMethodKind MethodKind { get diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs index edb1b55cb1..5c0c7a9d4d 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs @@ -9410,6 +9410,7 @@ public unsafe partial class Method : global::CppSharp.Parser.AST.Function, IDisp internal byte isStatic; internal byte isConst; internal byte isExplicit; + internal byte isVolatile; internal global::CppSharp.Parser.AST.CXXMethodKind methodKind; internal byte isDefaultConstructor; internal byte isCopyConstructor; @@ -9592,6 +9593,19 @@ public bool IsExplicit } } + public bool IsVolatile + { + get + { + return ((__Internal*)__Instance)->isVolatile != 0; + } + + set + { + ((__Internal*)__Instance)->isVolatile = (byte) (value ? 1 : 0); + } + } + public global::CppSharp.Parser.AST.CXXMethodKind MethodKind { get diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs index ec7ffd9ebe..58d27ea063 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs @@ -9410,6 +9410,7 @@ public unsafe partial class Method : global::CppSharp.Parser.AST.Function, IDisp internal byte isStatic; internal byte isConst; internal byte isExplicit; + internal byte isVolatile; internal global::CppSharp.Parser.AST.CXXMethodKind methodKind; internal byte isDefaultConstructor; internal byte isCopyConstructor; @@ -9592,6 +9593,19 @@ public bool IsExplicit } } + public bool IsVolatile + { + get + { + return ((__Internal*)__Instance)->isVolatile != 0; + } + + set + { + ((__Internal*)__Instance)->isVolatile = (byte) (value ? 1 : 0); + } + } + public global::CppSharp.Parser.AST.CXXMethodKind MethodKind { get diff --git a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs index f884b3abb9..e8e7233f1d 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs @@ -9410,6 +9410,7 @@ public unsafe partial class Method : global::CppSharp.Parser.AST.Function, IDisp internal byte isStatic; internal byte isConst; internal byte isExplicit; + internal byte isVolatile; internal global::CppSharp.Parser.AST.CXXMethodKind methodKind; internal byte isDefaultConstructor; internal byte isCopyConstructor; @@ -9592,6 +9593,19 @@ public bool IsExplicit } } + public bool IsVolatile + { + get + { + return ((__Internal*)__Instance)->isVolatile != 0; + } + + set + { + ((__Internal*)__Instance)->isVolatile = (byte) (value ? 1 : 0); + } + } + public global::CppSharp.Parser.AST.CXXMethodKind MethodKind { get diff --git a/src/CppParser/Decl.h b/src/CppParser/Decl.h index b51929c45d..40a2128bb0 100644 --- a/src/CppParser/Decl.h +++ b/src/CppParser/Decl.h @@ -380,6 +380,7 @@ namespace CppSharp bool isStatic; bool isConst; bool isExplicit; + bool isVolatile; CXXMethodKind methodKind; diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index 85be06a181..8821ae03ed 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -1898,6 +1898,7 @@ Method* Parser::WalkMethodCXX(const clang::CXXMethodDecl* MD) Method->isStatic = MD->isStatic(); Method->isVirtual = MD->isVirtual(); Method->isConst = MD->isConst(); + Method->isVolatile = MD->isVolatile(); for (auto OverriddenMethod : MD->overridden_methods()) { auto OM = WalkMethodCXX(OverriddenMethod); diff --git a/src/Generator.Tests/AST/TestAST.cs b/src/Generator.Tests/AST/TestAST.cs index 098057e74a..b04a6f0c94 100644 --- a/src/Generator.Tests/AST/TestAST.cs +++ b/src/Generator.Tests/AST/TestAST.cs @@ -564,5 +564,13 @@ public void TestPreprocessedEntities() Assert.NotNull(macro); Assert.AreEqual("(x, y, z) x##y##z", macro.Expression); } + + [Test] + public void TestMethods() + { + var hasMethodsClass = AstContext.FindClass("HasMethods").First(); + var isVolatileMethod = hasMethodsClass.FindMethod("isVolatileMethod"); + Assert.That(isVolatileMethod.IsVolatile, Is.EqualTo(true)); + } } } diff --git a/src/Parser/ASTConverter.cs b/src/Parser/ASTConverter.cs index 8c4a82fb04..4ebeece899 100644 --- a/src/Parser/ASTConverter.cs +++ b/src/Parser/ASTConverter.cs @@ -1309,6 +1309,9 @@ public override AST.Declaration VisitMethod(Method decl) _method.IsConst = decl.IsConst; _method.IsImplicit = decl.IsImplicit; _method.IsExplicit = decl.IsExplicit; + _method.IsVolatile = decl.IsVolatile; + if (decl.IsVolatile == true) + System.Diagnostics.Debugger.Break(); switch (decl.RefQualifier) { diff --git a/tests/dotnet/Native/AST.h b/tests/dotnet/Native/AST.h index 8899a5a987..29ff076283 100644 --- a/tests/dotnet/Native/AST.h +++ b/tests/dotnet/Native/AST.h @@ -185,3 +185,9 @@ int non_deprecated_func(int num); TestTemplateClass returnIncompleteTemplateSpecialization(); #define MACRO(x, y, z) x##y##z + +class HasMethods +{ +public: + void isVolatileMethod() volatile {} +}; \ No newline at end of file