зеркало из https://github.com/microsoft/clang-1.git
Introduce Decl::getParentFunctionOrMethod which if the decl is defined inside
a function/method/block it returns the corresponding DeclContext, otherwise it returns null. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140672 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
4f8de278b7
Коммит
c8680f4697
|
@ -567,7 +567,13 @@ public:
|
|||
/// scoped decl is defined outside the current function or method. This is
|
||||
/// roughly global variables and functions, but also handles enums (which
|
||||
/// could be defined inside or outside a function etc).
|
||||
bool isDefinedOutsideFunctionOrMethod() const;
|
||||
bool isDefinedOutsideFunctionOrMethod() const {
|
||||
return getParentFunctionOrMethod() == 0;
|
||||
}
|
||||
|
||||
/// \brief If this decl is defined inside a function/method/block it returns
|
||||
/// the corresponding DeclContext, otherwise it returns null.
|
||||
const DeclContext *getParentFunctionOrMethod() const;
|
||||
|
||||
/// \brief Retrieves the "canonical" declaration of the given declaration.
|
||||
virtual Decl *getCanonicalDecl() { return this; }
|
||||
|
|
|
@ -137,14 +137,14 @@ bool Decl::isTemplateDecl() const {
|
|||
return isa<TemplateDecl>(this);
|
||||
}
|
||||
|
||||
bool Decl::isDefinedOutsideFunctionOrMethod() const {
|
||||
const DeclContext *Decl::getParentFunctionOrMethod() const {
|
||||
for (const DeclContext *DC = getDeclContext();
|
||||
DC && !DC->isTranslationUnit();
|
||||
DC && !DC->isTranslationUnit() && !DC->isNamespace();
|
||||
DC = DC->getParent())
|
||||
if (DC->isFunctionOrMethod())
|
||||
return false;
|
||||
return DC;
|
||||
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче