Skip to content

Commit

Permalink
Add Method.IsVolatile property.
Browse files Browse the repository at this point in the history
Fixes mono#1761
  • Loading branch information
tritao authored and JordanL8 committed Oct 2, 2023
1 parent 1e88ea5 commit b206cd5
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/AST/Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions src/CppParser/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ Method::Method()
, isStatic(false)
, isConst(false)
, isExplicit(false)
, isVolatile(false)
, isDefaultConstructor(false)
, isCopyConstructor(false)
, isMoveConstructor(false)
Expand Down
10 changes: 10 additions & 0 deletions src/CppParser/Bindings/CLI/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/CppParser/Bindings/CLI/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/CppParser/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ namespace CppSharp
bool isStatic;
bool isConst;
bool isExplicit;
bool isVolatile;

CXXMethodKind methodKind;

Expand Down
1 change: 1 addition & 0 deletions src/CppParser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/Generator.Tests/AST/TestAST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
1 change: 1 addition & 0 deletions src/Parser/ASTConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,7 @@ public override AST.Declaration VisitMethod(Method decl)
_method.IsConst = decl.IsConst;
_method.IsImplicit = decl.IsImplicit;
_method.IsExplicit = decl.IsExplicit;
_method.IsVolatile = decl.IsVolatile;

switch (decl.RefQualifier)
{
Expand Down
6 changes: 6 additions & 0 deletions tests/dotnet/Native/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,9 @@ int non_deprecated_func(int num);
TestTemplateClass<double> returnIncompleteTemplateSpecialization();

#define MACRO(x, y, z) x##y##z

class HasMethods
{
public:
void isVolatileMethod() volatile {}
};

0 comments on commit b206cd5

Please sign in to comment.