clang API Documentation

Classes | Namespaces | 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/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 dependency graph for Decl.cpp:

Go to the source code of this file.

Classes

class  clang::LinkageComputer

Namespaces

namespace  clang

Enumerations

enum  LVComputationKind {
  LVForType = NamedDecl::VisibilityForType, LVForValue = NamedDecl::VisibilityForValue, LVForExplicitType = (LVForType | IgnoreExplicitVisibilityBit), LVForExplicitValue = (LVForValue | IgnoreExplicitVisibilityBit),
  LVForLinkageOnly
}

Functions

static bool hasExplicitVisibilityAlready (LVComputationKind computation)
static LVComputationKind withExplicitVisibilityAlready (LVComputationKind oldKind)
static Optional< VisibilitygetExplicitVisibility (const NamedDecl *D, LVComputationKind kind)
static bool usesTypeVisibility (const NamedDecl *D)
template<class T >
static std::enable_if
<!std::is_base_of
< RedeclarableTemplateDecl, T >
::value, bool >::type 
isExplicitMemberSpecialization (const T *D)
static bool isExplicitMemberSpecialization (const RedeclarableTemplateDecl *D)
template<class T >
static Visibility getVisibilityFromAttr (const T *attr)
static Optional< VisibilitygetVisibilityOf (const NamedDecl *D, NamedDecl::ExplicitVisibilityKind kind)
 Return the explicit visibility of the given declaration.
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. For visibility purposes, template parameters are part of the signature of a template.
static LinkageInfo getLVForDecl (const NamedDecl *D, LVComputationKind computation)
 getLVForDecl - Get the linkage and visibility for the given declaration.
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.
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)
static bool hasDirectVisibilityAttribute (const NamedDecl *D, LVComputationKind computation)
static bool shouldConsiderTemplateVisibility (const ClassTemplateSpecializationDecl *spec, LVComputationKind computation)
static void mergeTemplateLV (LinkageInfo &LV, const ClassTemplateSpecializationDecl *spec, LVComputationKind computation)
static bool shouldConsiderTemplateVisibility (const VarTemplateSpecializationDecl *spec, LVComputationKind computation)
static void mergeTemplateLV (LinkageInfo &LV, const VarTemplateSpecializationDecl *spec, LVComputationKind computation)
static bool useInlineVisibilityHidden (const NamedDecl *D)
template<typename T >
static bool isFirstInExternCContext (T *D)
static bool isSingleLineLanguageLinkage (const Decl &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 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<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 bool isFieldOrIndirectField (Decl::Kind K)
static unsigned getNumModuleIdentifiers (Module *Mod)
 Retrieve the number of module identifiers needed to name the given module.

Variables

const unsigned IgnoreExplicitVisibilityBit = 2
const unsigned IgnoreAllVisibilityBit = 4

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 103 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]
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 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 310 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]
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 3932 of file Decl.cpp.

References clang::Module::Parent.

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

static const CXXRecordDecl* getOutermostEnclosingLambda ( const CXXRecordDecl Record) [inline, static]

Definition at line 1204 of file Decl.cpp.

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

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 186 of file Decl.cpp.

References 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 399 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 131 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 168 of file Decl.cpp.

Referenced by getLVForClassMember().

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 179 of file Decl.cpp.

References clang::RedeclarableTemplateDecl::isMemberSpecialization().

static bool isFieldOrIndirectField ( Decl::Kind  K) [static]
template<typename T >
static bool isFirstInExternCContext ( T *  D) [static]

Definition at line 560 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 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 379 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 420 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 484 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 158 of file Decl.cpp.

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

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

Definition at line 138 of file Decl.cpp.

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

Referenced by getLVForClassMember().


Variable Documentation

Definition at line 98 of file Decl.cpp.

Definition at line 97 of file Decl.cpp.

Referenced by hasExplicitVisibilityAlready(), and withExplicitVisibilityAlready().