Fix RecursiveASTVisitor to visit types in ObjCPropertyDecl

Patch by Mathieu Baudet!

llvm-svn: 210339
This commit is contained in:
Alp Toker 2014-06-06 15:05:09 +00:00
parent 8bbb8446f3
commit 62438dab83
4 changed files with 25 additions and 5 deletions

View File

@ -1322,8 +1322,13 @@ DEF_TRAVERSE_DECL(ObjCMethodDecl, {
return true;
})
DEF_TRAVERSE_DECL(ObjCPropertyDecl, {// FIXME: implement
})
DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
if (D->getTypeSourceInfo())
TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
else
TRY_TO(TraverseType(D->getType()));
return true;
})
DEF_TRAVERSE_DECL(UsingDecl, {
TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));

View File

@ -1394,8 +1394,13 @@ DEF_TRAVERSE_DECL(ObjCMethodDecl, {
return true;
})
DEF_TRAVERSE_DECL(ObjCPropertyDecl, {// FIXME: implement
})
DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
if (D->getTypeSourceInfo())
TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
else
TRY_TO(TraverseType(D->getType()));
return true;
})
DEF_TRAVERSE_DECL(UsingDecl, {
TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));

View File

@ -531,6 +531,15 @@ TEST(RecursiveASTVisitor, VisitsCompoundLiteralType) {
TypeLocVisitor::Lang_C));
}
TEST(RecursiveASTVisitor, VisitsObjCPropertyType) {
TypeLocVisitor Visitor;
Visitor.ExpectMatch("NSNumber", 2, 33);
EXPECT_TRUE(Visitor.runOver(
"@class NSNumber; \n"
"@interface A @property (retain) NSNumber *x; @end\n",
TypeLocVisitor::Lang_OBJC));
}
TEST(RecursiveASTVisitor, VisitsLambdaExpr) {
LambdaExprVisitor Visitor;
Visitor.ExpectMatch("", 1, 12);

View File

@ -39,7 +39,7 @@ public:
virtual ~TestVisitor() { }
enum Language { Lang_C, Lang_CXX98, Lang_CXX11, Lang_CXX=Lang_CXX98 };
enum Language { Lang_C, Lang_CXX98, Lang_CXX11, Lang_OBJC, Lang_CXX=Lang_CXX98 };
/// \brief Runs the current AST visitor over the given code.
bool runOver(StringRef Code, Language L = Lang_CXX) {
@ -48,6 +48,7 @@ public:
case Lang_C: Args.push_back("-std=c99"); break;
case Lang_CXX98: Args.push_back("-std=c++98"); break;
case Lang_CXX11: Args.push_back("-std=c++11"); break;
case Lang_OBJC: Args.push_back("-ObjC"); break;
}
return tooling::runToolOnCodeWithArgs(CreateTestAction(), Code, Args);
}