Browse Source

Implement parsing and AST processing of C++ deprecated attributes.

pull/1332/head
João Matos 6 years ago committed by João Matos
parent
commit
c21ddcca1e
  1. 3
      src/AST/Declaration.cs
  2. 2
      src/CppParser/AST.cpp
  3. 1
      src/CppParser/Decl.h
  4. 16
      src/CppParser/Parser.cpp
  5. 12
      src/Generator.Tests/AST/TestAST.cs
  6. 1
      src/Parser/ASTConverter.cs
  7. 3
      tests/Native/AST.h

3
src/AST/Declaration.cs

@ -294,6 +294,9 @@ namespace CppSharp.AST @@ -294,6 +294,9 @@ namespace CppSharp.AST
// True if the declaration is dependent.
public bool IsDependent;
// True if the declaration is deprecated.
public bool IsDeprecated;
// Keeps a reference to the complete version of this declaration.
public Declaration CompleteDeclaration;

2
src/CppParser/AST.cpp

@ -250,6 +250,7 @@ Declaration::Declaration(DeclarationKind kind) @@ -250,6 +250,7 @@ Declaration::Declaration(DeclarationKind kind)
, isDependent(false)
, isImplicit(false)
, isInvalid(false)
, isDeprecated(false)
, completeDeclaration(0)
, definitionOrder(0)
, originalPtr(0)
@ -271,6 +272,7 @@ Declaration::Declaration(const Declaration& rhs) @@ -271,6 +272,7 @@ Declaration::Declaration(const Declaration& rhs)
, isDependent(rhs.isDependent)
, isImplicit(rhs.isImplicit)
, isInvalid(rhs.isInvalid)
, isDeprecated(false)
, completeDeclaration(rhs.completeDeclaration)
, definitionOrder(rhs.definitionOrder)
, PreprocessedEntities(rhs.PreprocessedEntities)

1
src/CppParser/Decl.h

@ -84,6 +84,7 @@ public: @@ -84,6 +84,7 @@ public:
bool isDependent;
bool isImplicit;
bool isInvalid;
bool isDeprecated;
Declaration* completeDeclaration;
unsigned definitionOrder;
VECTOR(PreprocessedEntity*, PreprocessedEntities)

16
src/CppParser/Parser.cpp

@ -4080,10 +4080,20 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D) @@ -4080,10 +4080,20 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D)
for (auto it = D->attr_begin(); it != D->attr_end(); ++it)
{
Attr* Attr = (*it);
if (Attr->getKind() == clang::attr::Kind::MaxFieldAlignment)
switch(Attr->getKind())
{
auto MFA = cast<clang::MaxFieldAlignmentAttr>(Attr);
Decl->maxFieldAlignment = MFA->getAlignment() / 8; // bits to bytes.
case clang::attr::Kind::MaxFieldAlignment:
{
auto MFA = cast<clang::MaxFieldAlignmentAttr>(Attr);
Decl->maxFieldAlignment = MFA->getAlignment() / 8; // bits to bytes.
break;
}
case clang::attr::Kind::Deprecated:
{
auto DA = cast<clang::DeprecatedAttr>(Attr);
Decl->isDeprecated = true;
break;
}
}
}
}

12
src/Generator.Tests/AST/TestAST.cs

@ -308,6 +308,18 @@ namespace CppSharp.Generator.Tests.AST @@ -308,6 +308,18 @@ namespace CppSharp.Generator.Tests.AST
Assert.AreSame(classTemplateSpecialization.TemplatedDecl.TemplatedClass, template.TemplatedClass);
}
[Test]
public void TestDeprecatedAttrs()
{
var deprecated_func = AstContext.FindFunction("deprecated_func");
Assert.IsNotNull(deprecated_func);
Assert.IsTrue(deprecated_func.First().IsDeprecated);
var non_deprecated_func = AstContext.FindFunction("non_deprecated_func");
Assert.IsNotNull(non_deprecated_func);
Assert.IsFalse(non_deprecated_func.First().IsDeprecated);
}
[Test]
public void TestFindClassInNamespace()
{

1
src/Parser/ASTConverter.cs

@ -985,6 +985,7 @@ namespace CppSharp @@ -985,6 +985,7 @@ namespace CppSharp
_decl.IsInvalid = decl.IsInvalid;
_decl.DefinitionOrder = decl.DefinitionOrder;
_decl.MaxFieldAlignment = decl.MaxFieldAlignment;
_decl.IsDeprecated = decl.IsDeprecated;
if (decl.CompleteDeclaration != null)
_decl.CompleteDeclaration = Visit(decl.CompleteDeclaration);

3
tests/Native/AST.h

@ -245,3 +245,6 @@ private: @@ -245,3 +245,6 @@ private:
HasPrivateCCtorCopyAssignment(const HasPrivateCCtorCopyAssignment&) = delete;
HasPrivateCCtorCopyAssignment& operator=(const HasPrivateCCtorCopyAssignment&) = delete;
};
__attribute__((deprecated)) int deprecated_func(int num);
int non_deprecated_func(int num);

Loading…
Cancel
Save