summaryrefslogtreecommitdiff
path: root/lib/AST/Decl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r--lib/AST/Decl.cpp129
1 files changed, 63 insertions, 66 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 3b9b85a20af6f..8030dd0c2f41a 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -633,7 +633,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
// equivalent in C99)
// The C++ modules TS adds "non-exported" to this list.
if (Context.getLangOpts().CPlusPlus &&
- Var->getType().isConstQualified() &&
+ Var->getType().isConstQualified() &&
!Var->getType().isVolatileQualified() &&
!Var->isInline() &&
!isExportedFromModuleIntefaceUnit(Var)) {
@@ -1049,7 +1049,7 @@ bool NamedDecl::isLinkageValid() const {
ObjCStringFormatFamily NamedDecl::getObjCFStringFormattingFamily() const {
StringRef name = getName();
if (name.empty()) return SFF_None;
-
+
if (name.front() == 'C')
if (name == "CFStringCreateWithFormat" ||
name == "CFStringCreateWithFormatAndArguments" ||
@@ -1338,7 +1338,7 @@ LinkageInfo LinkageComputer::computeLVForDecl(const NamedDecl *D,
case Decl::ObjCPropertyImpl:
case Decl::ObjCProtocol:
return getExternalLinkageFor(D);
-
+
case Decl::CXXRecord: {
const auto *Record = cast<CXXRecordDecl>(D);
if (Record->isLambda()) {
@@ -1348,25 +1348,25 @@ LinkageInfo LinkageComputer::computeLVForDecl(const NamedDecl *D,
}
// This lambda has its linkage/visibility determined:
- // - either by the outermost lambda if that lambda has no mangling
- // number.
+ // - either by the outermost lambda if that lambda has no mangling
+ // number.
// - or by the parent of the outer most lambda
- // This prevents infinite recursion in settings such as nested lambdas
- // used in NSDMI's, for e.g.
+ // This prevents infinite recursion in settings such as nested lambdas
+ // used in NSDMI's, for e.g.
// struct L {
// int t{};
- // int t2 = ([](int a) { return [](int b) { return b; };})(t)(t);
+ // int t2 = ([](int a) { return [](int b) { return b; };})(t)(t);
// };
- const CXXRecordDecl *OuterMostLambda =
+ const CXXRecordDecl *OuterMostLambda =
getOutermostEnclosingLambda(Record);
if (!OuterMostLambda->getLambdaManglingNumber())
return getInternalLinkageFor(D);
-
+
return getLVForClosure(
OuterMostLambda->getDeclContext()->getRedeclContext(),
OuterMostLambda->getLambdaContextDecl(), computation);
}
-
+
break;
}
}
@@ -1374,7 +1374,7 @@ LinkageInfo LinkageComputer::computeLVForDecl(const NamedDecl *D,
// Handle linkage for namespace-scope names.
if (D->getDeclContext()->getRedeclContext()->isFileContext())
return getLVForNamespaceScopeDecl(D, computation, IgnoreVarTypeLinkage);
-
+
// C++ [basic.link]p5:
// In addition, a member function, static data member, a named
// class or enumeration of class scope, or an unnamed class or
@@ -1718,7 +1718,7 @@ NamedDecl *NamedDecl::getUnderlyingDeclImpl() {
bool NamedDecl::isCXXInstanceMember() const {
if (!isCXXClassMember())
return false;
-
+
const NamedDecl *D = this;
if (isa<UsingShadowDecl>(D))
D = cast<UsingShadowDecl>(D)->getTargetDecl();
@@ -1938,7 +1938,7 @@ VarDecl::TLSKind VarDecl::getTLSKind() const {
SourceRange VarDecl::getSourceRange() const {
if (const Expr *Init = getInit()) {
SourceLocation InitEnd = Init->getLocEnd();
- // If Init is implicit, ignore its source range and fallback on
+ // If Init is implicit, ignore its source range and fallback on
// DeclaratorDecl::getSourceRange() to handle postfix elements.
if (InitEnd.isValid() && InitEnd != getLocation())
return SourceRange(getOuterLocStart(), InitEnd);
@@ -2174,11 +2174,11 @@ bool VarDecl::isOutOfLine() const {
return false;
// If this static data member was instantiated from a static data member of
- // a class template, check whether that static data member was defined
+ // a class template, check whether that static data member was defined
// out-of-line.
if (VarDecl *VD = getInstantiatedFromStaticDataMember())
return VD->isOutOfLine();
-
+
return false;
}
@@ -2891,7 +2891,7 @@ FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) {
assert((!PrevDecl || PrevFunTmpl) && "Function/function template mismatch");
FunTmpl->setPreviousDecl(PrevFunTmpl);
}
-
+
if (PrevDecl && PrevDecl->IsInline)
IsInline = true;
}
@@ -3043,7 +3043,7 @@ static bool RedeclForcesDefC99(const FunctionDecl *Redecl) {
if (Redecl->isImplicit())
return false;
- if (!Redecl->isInlineSpecified() || Redecl->getStorageClass() == SC_Extern)
+ if (!Redecl->isInlineSpecified() || Redecl->getStorageClass() == SC_Extern)
return true; // Not an inline definition
return false;
@@ -3088,7 +3088,7 @@ bool FunctionDecl::doesDeclarationForceExternallyVisibleDefinition() const {
if (!Prev->isInlineSpecified() ||
Prev->getStorageClass() != SC_Extern)
return false;
- } else if (Prev->isInlineSpecified() &&
+ } else if (Prev->isInlineSpecified() &&
Prev->getStorageClass() != SC_Extern) {
return false;
}
@@ -3100,8 +3100,8 @@ bool FunctionDecl::doesDeclarationForceExternallyVisibleDefinition() const {
return false;
// C99 6.7.4p6:
- // [...] If all of the file scope declarations for a function in a
- // translation unit include the inline function specifier without extern,
+ // [...] If all of the file scope declarations for a function in a
+ // translation unit include the inline function specifier without extern,
// then the definition in that translation unit is an inline definition.
if (isInlineSpecified() && getStorageClass() != SC_Extern)
return false;
@@ -3149,12 +3149,9 @@ SourceRange FunctionDecl::getExceptionSpecSourceRange() const {
const Attr *FunctionDecl::getUnusedResultAttr() const {
QualType RetType = getReturnType();
- if (RetType->isRecordType()) {
- if (const auto *Ret =
- dyn_cast_or_null<RecordDecl>(RetType->getAsTagDecl())) {
- if (const auto *R = Ret->getAttr<WarnUnusedResultAttr>())
- return R;
- }
+ if (const auto *Ret = RetType->getAsRecordDecl()) {
+ if (const auto *R = Ret->getAttr<WarnUnusedResultAttr>())
+ return R;
} else if (const auto *ET = RetType->getAs<EnumType>()) {
if (const EnumDecl *ED = ET->getDecl()) {
if (const auto *R = ED->getAttr<WarnUnusedResultAttr>())
@@ -3177,16 +3174,16 @@ const Attr *FunctionDecl::getUnusedResultAttr() const {
/// inline definition becomes externally visible (C99 6.7.4p6).
///
/// In GNU89 mode, or if the gnu_inline attribute is attached to the function
-/// definition, we use the GNU semantics for inline, which are nearly the
-/// opposite of C99 semantics. In particular, "inline" by itself will create
-/// an externally visible symbol, but "extern inline" will not create an
+/// definition, we use the GNU semantics for inline, which are nearly the
+/// opposite of C99 semantics. In particular, "inline" by itself will create
+/// an externally visible symbol, but "extern inline" will not create an
/// externally visible symbol.
bool FunctionDecl::isInlineDefinitionExternallyVisible() const {
assert((doesThisDeclarationHaveABody() || willHaveBody()) &&
"Must be a function definition");
assert(isInlined() && "Function must be inline");
ASTContext &Context = getASTContext();
-
+
if (Context.getLangOpts().GNUInline || hasAttr<GNUInlineAttr>()) {
// Note: If you change the logic here, please change
// doesDeclarationForceExternallyVisibleDefinition as well.
@@ -3196,15 +3193,15 @@ bool FunctionDecl::isInlineDefinitionExternallyVisible() const {
// externally visible.
if (!(isInlineSpecified() && getStorageClass() == SC_Extern))
return true;
-
+
// If any declaration is 'inline' but not 'extern', then this definition
// is externally visible.
for (auto Redecl : redecls()) {
- if (Redecl->isInlineSpecified() &&
+ if (Redecl->isInlineSpecified() &&
Redecl->getStorageClass() != SC_Extern)
return true;
- }
-
+ }
+
return false;
}
@@ -3213,17 +3210,17 @@ bool FunctionDecl::isInlineDefinitionExternallyVisible() const {
"should not use C inline rules in C++");
// C99 6.7.4p6:
- // [...] If all of the file scope declarations for a function in a
- // translation unit include the inline function specifier without extern,
+ // [...] If all of the file scope declarations for a function in a
+ // translation unit include the inline function specifier without extern,
// then the definition in that translation unit is an inline definition.
for (auto Redecl : redecls()) {
if (RedeclForcesDefC99(Redecl))
return true;
}
-
+
// C99 6.7.4p6:
- // An inline definition does not provide an external definition for the
- // function, and does not forbid an external definition in another
+ // An inline definition does not provide an external definition for the
+ // function, and does not forbid an external definition in another
// translation unit.
return false;
}
@@ -3273,13 +3270,13 @@ MemberSpecializationInfo *FunctionDecl::getMemberSpecializationInfo() const {
return TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo *>();
}
-void
+void
FunctionDecl::setInstantiationOfMemberFunction(ASTContext &C,
FunctionDecl *FD,
TemplateSpecializationKind TSK) {
- assert(TemplateOrSpecialization.isNull() &&
+ assert(TemplateOrSpecialization.isNull() &&
"Member function is already a specialization");
- MemberSpecializationInfo *Info
+ MemberSpecializationInfo *Info
= new (C) MemberSpecializationInfo(FD, TSK);
TemplateOrSpecialization = Info;
}
@@ -3296,12 +3293,12 @@ bool FunctionDecl::isImplicitlyInstantiable() const {
// If the function is invalid, it can't be implicitly instantiated.
if (isInvalidDecl())
return false;
-
+
switch (getTemplateSpecializationKind()) {
case TSK_Undeclared:
case TSK_ExplicitInstantiationDefinition:
return false;
-
+
case TSK_ImplicitInstantiation:
return true;
@@ -3320,12 +3317,12 @@ bool FunctionDecl::isImplicitlyInstantiable() const {
bool HasPattern = false;
if (PatternDecl)
HasPattern = PatternDecl->hasBody(PatternDecl);
-
+
// C++0x [temp.explicit]p9:
// Except for inline functions, other explicit instantiation declarations
// have the effect of suppressing the implicit instantiation of the entity
- // to which they refer.
- if (!HasPattern || !PatternDecl)
+ // to which they refer.
+ if (!HasPattern || !PatternDecl)
return true;
return PatternDecl->isInlined();
@@ -3335,7 +3332,7 @@ bool FunctionDecl::isTemplateInstantiation() const {
switch (getTemplateSpecializationKind()) {
case TSK_Undeclared:
case TSK_ExplicitSpecialization:
- return false;
+ return false;
case TSK_ImplicitInstantiation:
case TSK_ExplicitInstantiationDeclaration:
case TSK_ExplicitInstantiationDefinition:
@@ -3343,7 +3340,7 @@ bool FunctionDecl::isTemplateInstantiation() const {
}
llvm_unreachable("All TSK values handled.");
}
-
+
FunctionDecl *FunctionDecl::getTemplateInstantiationPattern() const {
// Handle class scope explicit specialization special case.
if (getTemplateSpecializationKind() == TSK_ExplicitSpecialization) {
@@ -3352,13 +3349,13 @@ FunctionDecl *FunctionDecl::getTemplateInstantiationPattern() const {
return nullptr;
}
- // If this is a generic lambda call operator specialization, its
+ // If this is a generic lambda call operator specialization, its
// instantiation pattern is always its primary template's pattern
- // even if its primary template was instantiated from another
+ // even if its primary template was instantiated from another
// member template (which happens with nested generic lambdas).
- // Since a lambda's call operator's body is transformed eagerly,
- // we don't have to go hunting for a prototype definition template
- // (i.e. instantiated-from-member-template) to use as an instantiation
+ // Since a lambda's call operator's body is transformed eagerly,
+ // we don't have to go hunting for a prototype definition template
+ // (i.e. instantiated-from-member-template) to use as an instantiation
// pattern.
if (isGenericLambdaCallOperatorSpecialization(
@@ -3377,7 +3374,7 @@ FunctionDecl *FunctionDecl::getTemplateInstantiationPattern() const {
}
return getDefinitionOrSelf(Primary->getTemplatedDecl());
- }
+ }
if (auto *MFD = getInstantiatedFromMemberFunction())
return getDefinitionOrSelf(MFD);
@@ -3432,7 +3429,7 @@ FunctionDecl::setFunctionTemplateSpecialization(ASTContext &C,
TemplateSpecializationKind TSK,
const TemplateArgumentListInfo *TemplateArgsAsWritten,
SourceLocation PointOfInstantiation) {
- assert(TSK != TSK_Undeclared &&
+ assert(TSK != TSK_Undeclared &&
"Must specify the type of function template specialization");
FunctionTemplateSpecializationInfo *Info
= TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>();
@@ -3500,7 +3497,7 @@ TemplateSpecializationKind FunctionDecl::getTemplateSpecializationKind() const {
= TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>();
if (MSInfo)
return MSInfo->getTemplateSpecializationKind();
-
+
return TSK_Undeclared;
}
@@ -3540,22 +3537,22 @@ SourceLocation FunctionDecl::getPointOfInstantiation() const {
else if (MemberSpecializationInfo *MSInfo
= TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>())
return MSInfo->getPointOfInstantiation();
-
+
return SourceLocation();
}
bool FunctionDecl::isOutOfLine() const {
if (Decl::isOutOfLine())
return true;
-
- // If this function was instantiated from a member function of a
+
+ // If this function was instantiated from a member function of a
// class template, check whether that member function was defined out-of-line.
if (FunctionDecl *FD = getInstantiatedFromMemberFunction()) {
const FunctionDecl *Definition;
if (FD->hasBody(Definition))
return Definition->isOutOfLine();
}
-
+
// If this function was instantiated from a function template,
// check whether that function template was defined out-of-line.
if (FunctionTemplateDecl *FunTmpl = getPrimaryTemplate()) {
@@ -3563,7 +3560,7 @@ bool FunctionDecl::isOutOfLine() const {
if (FunTmpl->getTemplatedDecl()->hasBody(Definition))
return Definition->isOutOfLine();
}
-
+
return false;
}
@@ -3576,7 +3573,7 @@ unsigned FunctionDecl::getMemoryFunctionKind() const {
if (!FnInfo)
return 0;
-
+
// Builtin handling.
switch (getBuiltinID()) {
case Builtin::BI__builtin_memset:
@@ -4525,7 +4522,7 @@ static unsigned getNumModuleIdentifiers(Module *Mod) {
return Result;
}
-ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
+ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
Module *Imported,
ArrayRef<SourceLocation> IdentifierLocs)
: Decl(Import, DC, StartLoc), ImportedAndComplete(Imported, true) {
@@ -4535,7 +4532,7 @@ ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
StoredLocs);
}
-ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
+ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
Module *Imported, SourceLocation EndLoc)
: Decl(Import, DC, StartLoc), ImportedAndComplete(Imported, false) {
*getTrailingObjects<SourceLocation>() = EndLoc;