clang  5.0.0
Classes | Namespaces | Macros | Enumerations | Functions | Variables
Decl.cpp File Reference
#include "clang/AST/Decl.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTLambda.h"
#include "clang/AST/ASTMutationListener.h"
#include "clang/AST/Attr.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclOpenMP.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/Module.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "llvm/Support/ErrorHandling.h"
#include <algorithm>
#include "clang/AST/DeclNodes.inc"
Include dependency graph for Decl.cpp:

Go to the source code of this file.

Classes

class  clang::LinkageComputer
 

Namespaces

 clang
 /file This file defines classes for searching and anlyzing source code clones.
 

Macros

#define DECL(Type, Base)
 
#define ABSTRACT_DECL(DECL)
 

Enumerations

enum  LVComputationKind {
  LVForType = NamedDecl::VisibilityForType, LVForValue = NamedDecl::VisibilityForValue, LVForExplicitType = (LVForType | IgnoreExplicitVisibilityBit), LVForExplicitValue = (LVForValue | IgnoreExplicitVisibilityBit),
  LVForLinkageOnly
}
 Kinds of LV computation. More...
 

Functions

static bool hasExplicitVisibilityAlready (LVComputationKind computation)
 Does this computation kind permit us to consider additional visibility settings from attributes and the like? More...
 
static LVComputationKind withExplicitVisibilityAlready (LVComputationKind oldKind)
 Given an LVComputationKind, return one of the same type/value sort that records that it already has explicit visibility. More...
 
static Optional< VisibilitygetExplicitVisibility (const NamedDecl *D, LVComputationKind kind)
 
static bool usesTypeVisibility (const NamedDecl *D)
 Is the given declaration a "type" or a "value" for the purposes of visibility computation? More...
 
template<class T >
static std::enable_if
<!std::is_base_of
< RedeclarableTemplateDecl, T >
::value, bool >::type 
isExplicitMemberSpecialization (const T *D)
 Does the given declaration have member specialization information, and if so, is it an explicit specialization? More...
 
static bool isExplicitMemberSpecialization (const RedeclarableTemplateDecl *D)
 For templates, this question is easier: a member template can't be explicitly instantiated, so there's a single bit indicating whether or not this is an explicit member specialization. More...
 
template<class T >
static Visibility getVisibilityFromAttr (const T *attr)
 Given a visibility attribute, return the explicit visibility associated with it. More...
 
static Optional< VisibilitygetVisibilityOf (const NamedDecl *D, NamedDecl::ExplicitVisibilityKind kind)
 Return the explicit visibility of the given declaration. More...
 
static LinkageInfo getLVForType (const Type &T, LVComputationKind computation)
 
static LinkageInfo getLVForTemplateParameterList (const TemplateParameterList *Params, LVComputationKind computation)
 Get the most restrictive linkage for the types in the given template parameter list. More...
 
static LinkageInfo getLVForDecl (const NamedDecl *D, LVComputationKind computation)
 getLVForDecl - Get the linkage and visibility for the given declaration. More...
 
static const DeclgetOutermostFuncOrBlockContext (const Decl *D)
 
static LinkageInfo getLVForTemplateArgumentList (ArrayRef< TemplateArgument > Args, LVComputationKind computation)
 Get the most restrictive linkage for the types and declarations in the given template argument list. More...
 
static LinkageInfo getLVForTemplateArgumentList (const TemplateArgumentList &TArgs, LVComputationKind computation)
 
static bool shouldConsiderTemplateVisibility (const FunctionDecl *fn, const FunctionTemplateSpecializationInfo *specInfo)
 
static void mergeTemplateLV (LinkageInfo &LV, const FunctionDecl *fn, const FunctionTemplateSpecializationInfo *specInfo, LVComputationKind computation)
 Merge in template-related linkage and visibility for the given function template specialization. More...
 
static bool hasDirectVisibilityAttribute (const NamedDecl *D, LVComputationKind computation)
 Does the given declaration have a direct visibility attribute that would match the given rules? More...
 
static bool shouldConsiderTemplateVisibility (const ClassTemplateSpecializationDecl *spec, LVComputationKind computation)
 Should we consider visibility associated with the template arguments and parameters of the given class template specialization? More...
 
static void mergeTemplateLV (LinkageInfo &LV, const ClassTemplateSpecializationDecl *spec, LVComputationKind computation)
 Merge in template-related linkage and visibility for the given class template specialization. More...
 
static bool shouldConsiderTemplateVisibility (const VarTemplateSpecializationDecl *spec, LVComputationKind computation)
 Should we consider visibility associated with the template arguments and parameters of the given variable template specialization? As usual, follow class template specialization logic up to initialization. More...
 
static void mergeTemplateLV (LinkageInfo &LV, const VarTemplateSpecializationDecl *spec, LVComputationKind computation)
 Merge in template-related linkage and visibility for the given variable template specialization. More...
 
static bool useInlineVisibilityHidden (const NamedDecl *D)
 
template<typename T >
static bool isFirstInExternCContext (T *D)
 
static bool isSingleLineLanguageLinkage (const Decl &D)
 
static bool isExportedFromModuleIntefaceUnit (const NamedDecl *D)
 
static LinkageInfo getInternalLinkageFor (const NamedDecl *D)
 
static LinkageInfo getExternalLinkageFor (const NamedDecl *D)
 
static LinkageInfo getLVForNamespaceScopeDecl (const NamedDecl *D, LVComputationKind computation)
 
static LinkageInfo getLVForClassMember (const NamedDecl *D, LVComputationKind computation)
 
static LinkageInfo computeLVForDecl (const NamedDecl *D, LVComputationKind computation)
 
static Optional< VisibilitygetExplicitVisibilityAux (const NamedDecl *ND, NamedDecl::ExplicitVisibilityKind kind, bool IsMostRecent)
 
static LinkageInfo getLVForClosure (const DeclContext *DC, Decl *ContextDecl, LVComputationKind computation)
 
static LinkageInfo getLVForLocalDecl (const NamedDecl *D, LVComputationKind computation)
 
static const CXXRecordDeclgetOutermostEnclosingLambda (const CXXRecordDecl *Record)
 
template<typename T >
static bool isRedeclarableImpl (Redeclarable< T > *)
 
static bool isRedeclarableImpl (...)
 
static bool isRedeclarable (Decl::Kind K)
 
template<typename DeclT >
static SourceLocation getTemplateOrInnerLocStart (const DeclT *decl)
 
template<typename T >
static LanguageLinkage getDeclLanguageLinkage (const T &D)
 
template<typename T >
static bool isDeclExternC (const T &D)
 
template<typename DeclT >
static DeclT * getDefinitionOrSelf (DeclT *D)
 
template<std::size_t Len>
static bool isNamed (const NamedDecl *ND, const char(&Str)[Len])
 
static bool redeclForcesDefMSVC (const FunctionDecl *Redecl)
 
static bool RedeclForcesDefC99 (const FunctionDecl *Redecl)
 
static unsigned getNumModuleIdentifiers (Module *Mod)
 Retrieve the number of module identifiers needed to name the given module. More...
 

Variables

const unsigned IgnoreExplicitVisibilityBit = 2
 
const unsigned IgnoreAllVisibilityBit = 4
 

Macro Definition Documentation

#define ABSTRACT_DECL (   DECL)
#define DECL (   Type,
  Base 
)
Value:
case Decl::Type: \
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
The base class of the type hierarchy.
Definition: Type.h:1303
return(__x >> __y)|(__x<< (32-__y))
static bool isRedeclarableImpl(Redeclarable< T > *)
Definition: Decl.cpp:1557

Enumeration Type Documentation

Kinds of LV computation.

The linkage side of the computation is always the same, but different things can change how visibility is computed.

Enumerator
LVForType 

Do an LV computation for, ultimately, a type.

Visibility may be restricted by type visibility settings and the visibility of template arguments.

LVForValue 

Do an LV computation for, ultimately, a non-type declaration.

Visibility may be restricted by value visibility settings and the visibility of template arguments.

LVForExplicitType 

Do an LV computation for, ultimately, a type that already has some sort of explicit visibility.

Visibility may only be restricted by the visibility of template arguments.

LVForExplicitValue 

Do an LV computation for, ultimately, a non-type declaration that already has some sort of explicit visibility.

Visibility may only be restricted by the visibility of template arguments.

LVForLinkageOnly 

Do an LV computation when we only care about the linkage.

Definition at line 108 of file Decl.cpp.

Function Documentation

static LinkageInfo computeLVForDecl ( const NamedDecl D,
LVComputationKind  computation 
)
static
template<typename T >
static LanguageLinkage getDeclLanguageLinkage ( const T &  D)
static
template<typename DeclT >
static DeclT* getDefinitionOrSelf ( DeclT *  D)
static
static Optional<Visibility> getExplicitVisibility ( const NamedDecl D,
LVComputationKind  kind 
)
static
static Optional<Visibility> getExplicitVisibilityAux ( const NamedDecl ND,
NamedDecl::ExplicitVisibilityKind  kind,
bool  IsMostRecent 
)
static
static LinkageInfo getExternalLinkageFor ( const NamedDecl D)
static
static LinkageInfo getInternalLinkageFor ( const NamedDecl D)
static
static LinkageInfo getLVForClassMember ( const NamedDecl D,
LVComputationKind  computation 
)
static
static LinkageInfo getLVForClosure ( const DeclContext DC,
Decl ContextDecl,
LVComputationKind  computation 
)
static
static LinkageInfo getLVForDecl ( const NamedDecl D,
LVComputationKind  computation 
)
static
static LinkageInfo getLVForLocalDecl ( const NamedDecl D,
LVComputationKind  computation 
)
static
static LinkageInfo getLVForNamespaceScopeDecl ( const NamedDecl D,
LVComputationKind  computation 
)
static
static LinkageInfo getLVForTemplateArgumentList ( ArrayRef< TemplateArgument Args,
LVComputationKind  computation 
)
static

Get the most restrictive linkage for the types and declarations in the given template argument list.

Note that we don't take an LVComputationKind because we always want to honor the visibility of template arguments in the same way.

Definition at line 314 of file Decl.cpp.

References clang::TemplateArgument::Declaration, clang::TemplateArgument::Expression, getLVForDecl(), getLVForType(), clang::TemplateArgument::Integral, clang::LinkageInfo::merge(), clang::TemplateArgument::Null, clang::TemplateArgument::NullPtr, clang::TemplateArgument::Pack, clang::TemplateArgument::Template, clang::TemplateArgument::TemplateExpansion, clang::TemplateArgument::Type, and usesTypeVisibility().

Referenced by getLVForTemplateArgumentList(), and mergeTemplateLV().

static LinkageInfo getLVForTemplateArgumentList ( const TemplateArgumentList TArgs,
LVComputationKind  computation 
)
static
static LinkageInfo getLVForTemplateParameterList ( const TemplateParameterList Params,
LVComputationKind  computation 
)
static

Get the most restrictive linkage for the types in the given template parameter list.

For visibility purposes, template parameters are part of the signature of a template.

Definition at line 241 of file Decl.cpp.

References clang::Type::getLinkageAndVisibility(), getLVForType(), clang::Type::isDependentType(), clang::LinkageInfo::merge(), P, and clang::ast_matchers::type.

Referenced by getLVForClassMember(), getLVForNamespaceScopeDecl(), and mergeTemplateLV().

static LinkageInfo getLVForType ( const Type T,
LVComputationKind  computation 
)
static
static unsigned getNumModuleIdentifiers ( Module Mod)
static

Retrieve the number of module identifiers needed to name the given module.

Definition at line 4389 of file Decl.cpp.

References clang::Module::Parent, and Result.

Referenced by clang::ImportDecl::getIdentifierLocs().

static const CXXRecordDecl* getOutermostEnclosingLambda ( const CXXRecordDecl Record)
inlinestatic

Definition at line 1263 of file Decl.cpp.

References clang::DeclContext::getParent(), and clang::CXXRecordDecl::isLambda().

Referenced by computeLVForDecl().

static const Decl* getOutermostFuncOrBlockContext ( const Decl D)
static
template<typename DeclT >
static SourceLocation getTemplateOrInnerLocStart ( const DeclT *  decl)
static
template<class T >
static Visibility getVisibilityFromAttr ( const T *  attr)
static

Given a visibility attribute, return the explicit visibility associated with it.

Definition at line 191 of file Decl.cpp.

References clang::LangAS::Default, clang::DefaultVisibility, clang::HiddenVisibility, and clang::ProtectedVisibility.

Referenced by getVisibilityOf().

static Optional<Visibility> getVisibilityOf ( const NamedDecl D,
NamedDecl::ExplicitVisibilityKind  kind 
)
static
static bool hasDirectVisibilityAttribute ( const NamedDecl D,
LVComputationKind  computation 
)
static

Does the given declaration have a direct visibility attribute that would match the given rules?

Definition at line 403 of file Decl.cpp.

References clang::Decl::hasAttr(), LVForExplicitType, LVForExplicitValue, LVForLinkageOnly, LVForType, and LVForValue.

Referenced by getLVForClassMember(), and shouldConsiderTemplateVisibility().

static bool hasExplicitVisibilityAlready ( LVComputationKind  computation)
static

Does this computation kind permit us to consider additional visibility settings from attributes and the like?

Definition at line 136 of file Decl.cpp.

References IgnoreExplicitVisibilityBit.

Referenced by getExplicitVisibility(), getLVForClassMember(), getLVForLocalDecl(), getLVForNamespaceScopeDecl(), mergeTemplateLV(), and shouldConsiderTemplateVisibility().

template<typename T >
static bool isDeclExternC ( const T &  D)
static
template<class T >
static std::enable_if<!std::is_base_of<RedeclarableTemplateDecl, T>::value, bool>::type isExplicitMemberSpecialization ( const T *  D)
static

Does the given declaration have member specialization information, and if so, is it an explicit specialization?

Definition at line 173 of file Decl.cpp.

Referenced by getLVForClassMember().

static bool isExplicitMemberSpecialization ( const RedeclarableTemplateDecl D)
static

For templates, this question is easier: a member template can't be explicitly instantiated, so there's a single bit indicating whether or not this is an explicit member specialization.

Definition at line 184 of file Decl.cpp.

References clang::RedeclarableTemplateDecl::isMemberSpecialization().

static bool isExportedFromModuleIntefaceUnit ( const NamedDecl D)
static
template<typename T >
static bool isFirstInExternCContext ( T *  D)
static

Definition at line 564 of file Decl.cpp.

Referenced by getDeclLanguageLinkage(), and getLVForNamespaceScopeDecl().

template<std::size_t Len>
static bool isNamed ( const NamedDecl ND,
const char(&)  Str[Len] 
)
static
static bool isRedeclarable ( Decl::Kind  K)
static

Definition at line 1561 of file Decl.cpp.

Referenced by clang::NamedDecl::declarationReplaces().

template<typename T >
static bool isRedeclarableImpl ( Redeclarable< T > *  )
static

Definition at line 1557 of file Decl.cpp.

static bool isRedeclarableImpl (   ...)
static

Definition at line 1560 of file Decl.cpp.

static bool isSingleLineLanguageLinkage ( const Decl D)
static
static void mergeTemplateLV ( LinkageInfo LV,
const FunctionDecl fn,
const FunctionTemplateSpecializationInfo specInfo,
LVComputationKind  computation 
)
static

Merge in template-related linkage and visibility for the given function template specialization.

We don't need a computation kind here because we can assume LVForValue.

Parameters
[out]LVthe computation to use for the parent

Definition at line 383 of file Decl.cpp.

References getLVForTemplateArgumentList(), getLVForTemplateParameterList(), clang::FunctionTemplateSpecializationInfo::getTemplate(), clang::TemplateDecl::getTemplateParameters(), clang::LinkageInfo::mergeMaybeWithVisibility(), shouldConsiderTemplateVisibility(), and clang::FunctionTemplateSpecializationInfo::TemplateArguments.

Referenced by getLVForClassMember(), and getLVForNamespaceScopeDecl().

static void mergeTemplateLV ( LinkageInfo LV,
const ClassTemplateSpecializationDecl spec,
LVComputationKind  computation 
)
static
static void mergeTemplateLV ( LinkageInfo LV,
const VarTemplateSpecializationDecl spec,
LVComputationKind  computation 
)
static
static bool RedeclForcesDefC99 ( const FunctionDecl Redecl)
static
static bool redeclForcesDefMSVC ( const FunctionDecl Redecl)
static
static bool shouldConsiderTemplateVisibility ( const FunctionDecl fn,
const FunctionTemplateSpecializationInfo specInfo 
)
static
static bool shouldConsiderTemplateVisibility ( const ClassTemplateSpecializationDecl spec,
LVComputationKind  computation 
)
static

Should we consider visibility associated with the template arguments and parameters of the given class template specialization?

Definition at line 424 of file Decl.cpp.

References hasDirectVisibilityAttribute(), hasExplicitVisibilityAlready(), clang::ClassTemplateSpecializationDecl::isExplicitInstantiationOrSpecialization(), and clang::ClassTemplateSpecializationDecl::isExplicitSpecialization().

static bool shouldConsiderTemplateVisibility ( const VarTemplateSpecializationDecl spec,
LVComputationKind  computation 
)
static

Should we consider visibility associated with the template arguments and parameters of the given variable template specialization? As usual, follow class template specialization logic up to initialization.

Definition at line 488 of file Decl.cpp.

References hasDirectVisibilityAttribute(), hasExplicitVisibilityAlready(), clang::VarTemplateSpecializationDecl::isExplicitInstantiationOrSpecialization(), and clang::VarTemplateSpecializationDecl::isExplicitSpecialization().

static bool useInlineVisibilityHidden ( const NamedDecl D)
static
static bool usesTypeVisibility ( const NamedDecl D)
static

Is the given declaration a "type" or a "value" for the purposes of visibility computation?

Definition at line 163 of file Decl.cpp.

Referenced by clang::NamedDecl::getLinkageAndVisibility(), and getLVForTemplateArgumentList().

static LVComputationKind withExplicitVisibilityAlready ( LVComputationKind  oldKind)
static

Given an LVComputationKind, return one of the same type/value sort that records that it already has explicit visibility.

Definition at line 143 of file Decl.cpp.

References IgnoreExplicitVisibilityBit, LVForExplicitType, LVForExplicitValue, LVForType, and LVForValue.

Referenced by getLVForClassMember().

Variable Documentation

const unsigned IgnoreAllVisibilityBit = 4

Definition at line 103 of file Decl.cpp.

const unsigned IgnoreExplicitVisibilityBit = 2

Definition at line 102 of file Decl.cpp.

Referenced by hasExplicitVisibilityAlready(), and withExplicitVisibilityAlready().