Skip to content

Commit c21ddcc

Browse files
committed
Implement parsing and AST processing of C++ deprecated attributes.
1 parent 083bcd8 commit c21ddcc

File tree

7 files changed

+35
-3
lines changed

7 files changed

+35
-3
lines changed

src/AST/Declaration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ private static string GetDeclName(Declaration decl, string name)
294294
// True if the declaration is dependent.
295295
public bool IsDependent;
296296

297+
// True if the declaration is deprecated.
298+
public bool IsDeprecated;
299+
297300
// Keeps a reference to the complete version of this declaration.
298301
public Declaration CompleteDeclaration;
299302

src/CppParser/AST.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ Declaration::Declaration(DeclarationKind kind)
250250
, isDependent(false)
251251
, isImplicit(false)
252252
, isInvalid(false)
253+
, isDeprecated(false)
253254
, completeDeclaration(0)
254255
, definitionOrder(0)
255256
, originalPtr(0)
@@ -271,6 +272,7 @@ Declaration::Declaration(const Declaration& rhs)
271272
, isDependent(rhs.isDependent)
272273
, isImplicit(rhs.isImplicit)
273274
, isInvalid(rhs.isInvalid)
275+
, isDeprecated(false)
274276
, completeDeclaration(rhs.completeDeclaration)
275277
, definitionOrder(rhs.definitionOrder)
276278
, PreprocessedEntities(rhs.PreprocessedEntities)

src/CppParser/Decl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class CS_API Declaration
8484
bool isDependent;
8585
bool isImplicit;
8686
bool isInvalid;
87+
bool isDeprecated;
8788
Declaration* completeDeclaration;
8889
unsigned definitionOrder;
8990
VECTOR(PreprocessedEntity*, PreprocessedEntities)

src/CppParser/Parser.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4080,10 +4080,20 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D)
40804080
for (auto it = D->attr_begin(); it != D->attr_end(); ++it)
40814081
{
40824082
Attr* Attr = (*it);
4083-
if (Attr->getKind() == clang::attr::Kind::MaxFieldAlignment)
4083+
switch(Attr->getKind())
40844084
{
4085-
auto MFA = cast<clang::MaxFieldAlignmentAttr>(Attr);
4086-
Decl->maxFieldAlignment = MFA->getAlignment() / 8; // bits to bytes.
4085+
case clang::attr::Kind::MaxFieldAlignment:
4086+
{
4087+
auto MFA = cast<clang::MaxFieldAlignmentAttr>(Attr);
4088+
Decl->maxFieldAlignment = MFA->getAlignment() / 8; // bits to bytes.
4089+
break;
4090+
}
4091+
case clang::attr::Kind::Deprecated:
4092+
{
4093+
auto DA = cast<clang::DeprecatedAttr>(Attr);
4094+
Decl->isDeprecated = true;
4095+
break;
4096+
}
40874097
}
40884098
}
40894099
}

src/Generator.Tests/AST/TestAST.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,18 @@ public void TestASTClassTemplates()
308308
Assert.AreSame(classTemplateSpecialization.TemplatedDecl.TemplatedClass, template.TemplatedClass);
309309
}
310310

311+
[Test]
312+
public void TestDeprecatedAttrs()
313+
{
314+
var deprecated_func = AstContext.FindFunction("deprecated_func");
315+
Assert.IsNotNull(deprecated_func);
316+
Assert.IsTrue(deprecated_func.First().IsDeprecated);
317+
318+
var non_deprecated_func = AstContext.FindFunction("non_deprecated_func");
319+
Assert.IsNotNull(non_deprecated_func);
320+
Assert.IsFalse(non_deprecated_func.First().IsDeprecated);
321+
}
322+
311323
[Test]
312324
public void TestFindClassInNamespace()
313325
{

src/Parser/ASTConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ void VisitDeclaration(Declaration decl, AST.Declaration _decl)
985985
_decl.IsInvalid = decl.IsInvalid;
986986
_decl.DefinitionOrder = decl.DefinitionOrder;
987987
_decl.MaxFieldAlignment = decl.MaxFieldAlignment;
988+
_decl.IsDeprecated = decl.IsDeprecated;
988989

989990
if (decl.CompleteDeclaration != null)
990991
_decl.CompleteDeclaration = Visit(decl.CompleteDeclaration);

tests/Native/AST.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,6 @@ class HasPrivateCCtorCopyAssignment
245245
HasPrivateCCtorCopyAssignment(const HasPrivateCCtorCopyAssignment&) = delete;
246246
HasPrivateCCtorCopyAssignment& operator=(const HasPrivateCCtorCopyAssignment&) = delete;
247247
};
248+
249+
__attribute__((deprecated)) int deprecated_func(int num);
250+
int non_deprecated_func(int num);

0 commit comments

Comments
 (0)