clang  9.0.0svn
Namespaces | Enumerations | Functions
SemaDeclAttr.cpp File Reference
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTMutationListener.h"
#include "clang/AST/CXXInheritance.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/Mangle.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/DelayedDiagnostic.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaInternal.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/MathExtras.h"
Include dependency graph for SemaDeclAttr.cpp:

Go to the source code of this file.

Namespaces

 AttributeLangSupport
 

Enumerations

enum  AttributeLangSupport::LANG { AttributeLangSupport::C, AttributeLangSupport::Cpp, AttributeLangSupport::ObjC }
 

Functions

static bool isFunctionOrMethod (const Decl *D)
 isFunctionOrMethod - Return true if the given decl has function type (function or function-typed variable) or an Objective-C method. More...
 
static bool isFunctionOrMethodOrBlock (const Decl *D)
 Return true if the given decl has function type (function or function-typed variable) or an Objective-C method or a block. More...
 
static bool hasDeclarator (const Decl *D)
 Return true if the given decl has a declarator that should have been processed by Sema::GetTypeForDeclarator. More...
 
static bool hasFunctionProto (const Decl *D)
 hasFunctionProto - Return true if the given decl has a argument information. More...
 
static unsigned getFunctionOrMethodNumParams (const Decl *D)
 getFunctionOrMethodNumParams - Return number of function or method parameters. More...
 
static const ParmVarDeclgetFunctionOrMethodParam (const Decl *D, unsigned Idx)
 
static QualType getFunctionOrMethodParamType (const Decl *D, unsigned Idx)
 
static SourceRange getFunctionOrMethodParamRange (const Decl *D, unsigned Idx)
 
static QualType getFunctionOrMethodResultType (const Decl *D)
 
static SourceRange getFunctionOrMethodResultSourceRange (const Decl *D)
 
static bool isFunctionOrMethodVariadic (const Decl *D)
 
static bool isInstanceMethod (const Decl *D)
 
static bool isNSStringType (QualType T, ASTContext &Ctx)
 
static bool isCFStringType (QualType T, ASTContext &Ctx)
 
static unsigned getNumAttributeArgs (const ParsedAttr &AL)
 
template<typename Compare >
static bool checkAttributeNumArgsImpl (Sema &S, const ParsedAttr &AL, unsigned Num, unsigned Diag, Compare Comp)
 
static bool checkAttributeNumArgs (Sema &S, const ParsedAttr &AL, unsigned Num)
 Check if the attribute has exactly as many args as Num. More...
 
static bool checkAttributeAtLeastNumArgs (Sema &S, const ParsedAttr &AL, unsigned Num)
 Check if the attribute has at least as many args as Num. More...
 
static bool checkAttributeAtMostNumArgs (Sema &S, const ParsedAttr &AL, unsigned Num)
 Check if the attribute has at most as many args as Num. More...
 
template<typename AttrInfo >
static std::enable_if< std::is_base_of< Attr, AttrInfo >::value, SourceLocation >::type getAttrLoc (const AttrInfo &AL)
 A helper function to provide Attribute Location for the Attr types AND the ParsedAttr. More...
 
static SourceLocation getAttrLoc (const ParsedAttr &AL)
 
template<typename AttrInfo >
static bool checkUInt32Argument (Sema &S, const AttrInfo &AI, const Expr *Expr, uint32_t &Val, unsigned Idx=UINT_MAX, bool StrictlyUnsigned=false)
 If Expr is a valid integer constant, get the value of the integer expression and return success or failure. More...
 
template<typename AttrInfo >
static bool checkPositiveIntArgument (Sema &S, const AttrInfo &AI, const Expr *Expr, int &Val, unsigned Idx=UINT_MAX)
 Wrapper around checkUInt32Argument, with an extra check to be sure that the result will fit into a regular (signed) int. More...
 
template<typename AttrTy >
static bool checkAttrMutualExclusion (Sema &S, Decl *D, const ParsedAttr &AL)
 Diagnose mutually exclusive attributes when present on a given declaration. More...
 
template<typename AttrTy >
static bool checkAttrMutualExclusion (Sema &S, Decl *D, const Attr &AL)
 
template<typename AttrInfo >
static bool checkFunctionOrMethodParameterIndex (Sema &S, const Decl *D, const AttrInfo &AI, unsigned AttrArgNum, const Expr *IdxExpr, ParamIdx &Idx, bool CanIndexImplicitThis=false)
 Check if IdxExpr is a valid parameter index for a function or instance method D. More...
 
template<typename AttrType >
static void handleSimpleAttribute (Sema &S, Decl *D, SourceRange SR, unsigned SpellingIndex)
 Applies the given attribute to the Decl without performing any additional semantic checking. More...
 
template<typename AttrType >
static void handleSimpleAttribute (Sema &S, Decl *D, const ParsedAttr &AL)
 
template<typename... DiagnosticArgs>
static const Sema::SemaDiagnosticBuilderappendDiagnostics (const Sema::SemaDiagnosticBuilder &Bldr)
 
template<typename T , typename... DiagnosticArgs>
static const Sema::SemaDiagnosticBuilderappendDiagnostics (const Sema::SemaDiagnosticBuilder &Bldr, T &&ExtraArg, DiagnosticArgs &&... ExtraArgs)
 

Function Documentation

◆ appendDiagnostics() [1/2]

template<typename... DiagnosticArgs>
static const Sema::SemaDiagnosticBuilder& appendDiagnostics ( const Sema::SemaDiagnosticBuilder Bldr)
static

Definition at line 415 of file SemaDeclAttr.cpp.

Referenced by appendDiagnostics().

◆ appendDiagnostics() [2/2]

template<typename T , typename... DiagnosticArgs>
static const Sema::SemaDiagnosticBuilder& appendDiagnostics ( const Sema::SemaDiagnosticBuilder Bldr,
T &&  ExtraArg,
DiagnosticArgs &&...  ExtraArgs 
)
static

Definition at line 421 of file SemaDeclAttr.cpp.

References appendDiagnostics().

◆ checkAttributeAtLeastNumArgs()

static bool checkAttributeAtLeastNumArgs ( Sema S,
const ParsedAttr AL,
unsigned  Num 
)
static

Check if the attribute has at least as many args as Num.

May output an error.

Definition at line 208 of file SemaDeclAttr.cpp.

◆ checkAttributeAtMostNumArgs()

static bool checkAttributeAtMostNumArgs ( Sema S,
const ParsedAttr AL,
unsigned  Num 
)
static

Check if the attribute has at most as many args as Num.

May output an error.

Definition at line 217 of file SemaDeclAttr.cpp.

◆ checkAttributeNumArgs()

static bool checkAttributeNumArgs ( Sema S,
const ParsedAttr AL,
unsigned  Num 
)
static

Check if the attribute has exactly as many args as Num.

May output an error.

Definition at line 200 of file SemaDeclAttr.cpp.

◆ checkAttributeNumArgsImpl()

template<typename Compare >
static bool checkAttributeNumArgsImpl ( Sema S,
const ParsedAttr AL,
unsigned  Num,
unsigned  Diag,
Compare  Comp 
)
static

Definition at line 187 of file SemaDeclAttr.cpp.

◆ checkAttrMutualExclusion() [1/2]

template<typename AttrTy >
static bool checkAttrMutualExclusion ( Sema S,
Decl D,
const ParsedAttr AL 
)
static

Diagnose mutually exclusive attributes when present on a given declaration.

Returns true if diagnosed.

Definition at line 297 of file SemaDeclAttr.cpp.

◆ checkAttrMutualExclusion() [2/2]

template<typename AttrTy >
static bool checkAttrMutualExclusion ( Sema S,
Decl D,
const Attr AL 
)
static

Definition at line 307 of file SemaDeclAttr.cpp.

◆ checkFunctionOrMethodParameterIndex()

template<typename AttrInfo >
static bool checkFunctionOrMethodParameterIndex ( Sema S,
const Decl D,
const AttrInfo &  AI,
unsigned  AttrArgNum,
const Expr IdxExpr,
ParamIdx Idx,
bool  CanIndexImplicitThis = false 
)
static

Check if IdxExpr is a valid parameter index for a function or instance method D.

May output an error.

Returns
true if IdxExpr is a valid index.

Definition at line 322 of file SemaDeclAttr.cpp.

◆ checkPositiveIntArgument()

template<typename AttrInfo >
static bool checkPositiveIntArgument ( Sema S,
const AttrInfo &  AI,
const Expr Expr,
int &  Val,
unsigned  Idx = UINT_MAX 
)
static

Wrapper around checkUInt32Argument, with an extra check to be sure that the result will fit into a regular (signed) int.

All args have the same purpose as they do in checkUInt32Argument.

Definition at line 276 of file SemaDeclAttr.cpp.

◆ checkUInt32Argument()

template<typename AttrInfo >
static bool checkUInt32Argument ( Sema S,
const AttrInfo &  AI,
const Expr Expr,
uint32_t &  Val,
unsigned  Idx = UINT_MAX,
bool  StrictlyUnsigned = false 
)
static

If Expr is a valid integer constant, get the value of the integer expression and return success or failure.

May output an error.

Negative argument is implicitly converted to unsigned, unless StrictlyUnsigned is true.

Definition at line 240 of file SemaDeclAttr.cpp.

◆ getAttrLoc() [1/2]

template<typename AttrInfo >
static std::enable_if<std::is_base_of<Attr, AttrInfo>::value, SourceLocation>::type getAttrLoc ( const AttrInfo &  AL)
static

A helper function to provide Attribute Location for the Attr types AND the ParsedAttr.

Definition at line 229 of file SemaDeclAttr.cpp.

Referenced by clang::AttributedStmt::getBeginLoc().

◆ getAttrLoc() [2/2]

static SourceLocation getAttrLoc ( const ParsedAttr AL)
static

Definition at line 232 of file SemaDeclAttr.cpp.

References clang::ParsedAttr::getLoc().

◆ getFunctionOrMethodNumParams()

static unsigned getFunctionOrMethodNumParams ( const Decl D)
static

getFunctionOrMethodNumParams - Return number of function or method parameters.

It is an error to call this on a K&R function (use hasFunctionProto first).

Definition at line 87 of file SemaDeclAttr.cpp.

References clang::Decl::getFunctionType().

◆ getFunctionOrMethodParam()

static const ParmVarDecl* getFunctionOrMethodParam ( const Decl D,
unsigned  Idx 
)
static

Definition at line 95 of file SemaDeclAttr.cpp.

Referenced by getFunctionOrMethodParamRange().

◆ getFunctionOrMethodParamRange()

static SourceRange getFunctionOrMethodParamRange ( const Decl D,
unsigned  Idx 
)
static

Definition at line 115 of file SemaDeclAttr.cpp.

References getFunctionOrMethodParam().

◆ getFunctionOrMethodParamType()

static QualType getFunctionOrMethodParamType ( const Decl D,
unsigned  Idx 
)
static

Definition at line 106 of file SemaDeclAttr.cpp.

References clang::Decl::getFunctionType().

◆ getFunctionOrMethodResultSourceRange()

static SourceRange getFunctionOrMethodResultSourceRange ( const Decl D)
static

Definition at line 127 of file SemaDeclAttr.cpp.

◆ getFunctionOrMethodResultType()

static QualType getFunctionOrMethodResultType ( const Decl D)
static

Definition at line 121 of file SemaDeclAttr.cpp.

References clang::Decl::getFunctionType().

◆ getNumAttributeArgs()

static unsigned getNumAttributeArgs ( const ParsedAttr AL)
static

◆ handleSimpleAttribute() [1/2]

template<typename AttrType >
static void handleSimpleAttribute ( Sema S,
Decl D,
SourceRange  SR,
unsigned  SpellingIndex 
)
static

Applies the given attribute to the Decl without performing any additional semantic checking.

Definition at line 401 of file SemaDeclAttr.cpp.

◆ handleSimpleAttribute() [2/2]

template<typename AttrType >
static void handleSimpleAttribute ( Sema S,
Decl D,
const ParsedAttr AL 
)
static

Definition at line 407 of file SemaDeclAttr.cpp.

◆ hasDeclarator()

static bool hasDeclarator ( const Decl D)
static

Return true if the given decl has a declarator that should have been processed by Sema::GetTypeForDeclarator.

Definition at line 69 of file SemaDeclAttr.cpp.

◆ hasFunctionProto()

static bool hasFunctionProto ( const Decl D)
static

hasFunctionProto - Return true if the given decl has a argument information.

This decl should have already passed isFunctionOrMethod or isFunctionOrMethodOrBlock.

Definition at line 78 of file SemaDeclAttr.cpp.

References clang::Decl::getFunctionType().

◆ isCFStringType()

static bool isCFStringType ( QualType  T,
ASTContext Ctx 
)
inlinestatic

◆ isFunctionOrMethod()

static bool isFunctionOrMethod ( const Decl D)
static

isFunctionOrMethod - Return true if the given decl has function type (function or function-typed variable) or an Objective-C method.

Definition at line 57 of file SemaDeclAttr.cpp.

References clang::Decl::getFunctionType().

Referenced by isFunctionOrMethodOrBlock(), clang::DeclContext::isLookupContext(), and LookupVisibleDecls().

◆ isFunctionOrMethodOrBlock()

static bool isFunctionOrMethodOrBlock ( const Decl D)
static

Return true if the given decl has function type (function or function-typed variable) or an Objective-C method or a block.

Definition at line 63 of file SemaDeclAttr.cpp.

References isFunctionOrMethod().

◆ isFunctionOrMethodVariadic()

static bool isFunctionOrMethodVariadic ( const Decl D)
static

Definition at line 135 of file SemaDeclAttr.cpp.

References clang::Decl::getFunctionType().

◆ isInstanceMethod()

static bool isInstanceMethod ( const Decl D)
static

◆ isNSStringType()

static bool isNSStringType ( QualType  T,
ASTContext Ctx 
)
inlinestatic