Skip to content

Commit f937c02

Browse files
committed
Rename TagDecl::isDefinition -> isCompleteDefinition
for better self-documenting code, since the semantics are subtly different from getDefinition(). llvm-svn: 141355
1 parent bf13676 commit f937c02

25 files changed

+80
-75
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,9 +2359,10 @@ class TagDecl
23592359
/// TagDeclKind - The TagKind enum.
23602360
unsigned TagDeclKind : 2;
23612361

2362-
/// IsDefinition - True if this is a definition ("struct foo {};"), false if
2363-
/// it is a declaration ("struct foo;").
2364-
bool IsDefinition : 1;
2362+
/// IsCompleteDefinition - True if this is a definition ("struct foo
2363+
/// {};"), false if it is a declaration ("struct foo;"). It is not
2364+
/// a definition until the definition has been fully processed.
2365+
bool IsCompleteDefinition : 1;
23652366

23662367
/// IsBeingDefined - True if this is currently being defined.
23672368
bool IsBeingDefined : 1;
@@ -2421,7 +2422,7 @@ class TagDecl
24212422
assert((DK != Enum || TK == TTK_Enum) &&
24222423
"EnumDecl not matched with TTK_Enum");
24232424
TagDeclKind = TK;
2424-
IsDefinition = false;
2425+
IsCompleteDefinition = false;
24252426
IsBeingDefined = false;
24262427
IsEmbeddedInDeclarator = false;
24272428
IsFreeStanding = false;
@@ -2463,14 +2464,15 @@ class TagDecl
24632464
}
24642465

24652466
/// isThisDeclarationADefinition() - Return true if this declaration
2466-
/// defines the type. Provided for consistency.
2467+
/// is a completion definintion of the type. Provided for consistency.
24672468
bool isThisDeclarationADefinition() const {
2468-
return isDefinition();
2469+
return isCompleteDefinition();
24692470
}
24702471

2471-
/// isDefinition - Return true if this decl has its body specified.
2472-
bool isDefinition() const {
2473-
return IsDefinition;
2472+
/// isCompleteDefinition - Return true if this decl has its body
2473+
/// fully specified.
2474+
bool isCompleteDefinition() const {
2475+
return IsCompleteDefinition;
24742476
}
24752477

24762478
/// isBeingDefined - Return true if this decl is currently being defined.
@@ -2504,14 +2506,15 @@ class TagDecl
25042506

25052507
/// getDefinition - Returns the TagDecl that actually defines this
25062508
/// struct/union/class/enum. When determining whether or not a
2507-
/// struct/union/class/enum is completely defined, one should use this method
2508-
/// as opposed to 'isDefinition'. 'isDefinition' indicates whether or not a
2509-
/// specific TagDecl is defining declaration, not whether or not the
2510-
/// struct/union/class/enum type is defined. This method returns NULL if
2511-
/// there is no TagDecl that defines the struct/union/class/enum.
2512-
TagDecl* getDefinition() const;
2509+
/// struct/union/class/enum has a definition, one should use this
2510+
/// method as opposed to 'isDefinition'. 'isDefinition' indicates
2511+
/// whether or not a specific TagDecl is defining declaration, not
2512+
/// whether or not the struct/union/class/enum type is defined.
2513+
/// This method returns NULL if there is no TagDecl that defines
2514+
/// the struct/union/class/enum.
2515+
TagDecl *getDefinition() const;
25132516

2514-
void setDefinition(bool V) { IsDefinition = V; }
2517+
void setCompleteDefinition(bool V) { IsCompleteDefinition = V; }
25152518

25162519
const char *getKindName() const {
25172520
return TypeWithKeyword::getTagTypeKindName(getTagKind());
@@ -2751,7 +2754,7 @@ class EnumDecl : public TagDecl {
27512754

27522755
/// \brief Returns true if this can be considered a complete type.
27532756
bool isComplete() const {
2754-
return isDefinition() || isFixed();
2757+
return isCompleteDefinition() || isFixed();
27552758
}
27562759

27572760
/// \brief Returns the enumeration (declared within the template)
@@ -2854,14 +2857,15 @@ class RecordDecl : public TagDecl {
28542857
/// \endcode
28552858
bool isInjectedClassName() const;
28562859

2857-
/// getDefinition - Returns the RecordDecl that actually defines this
2858-
/// struct/union/class. When determining whether or not a struct/union/class
2859-
/// is completely defined, one should use this method as opposed to
2860-
/// 'isDefinition'. 'isDefinition' indicates whether or not a specific
2861-
/// RecordDecl is defining declaration, not whether or not the record
2862-
/// type is defined. This method returns NULL if there is no RecordDecl
2863-
/// that defines the struct/union/tag.
2864-
RecordDecl* getDefinition() const {
2860+
/// getDefinition - Returns the RecordDecl that actually defines
2861+
/// this struct/union/class. When determining whether or not a
2862+
/// struct/union/class is completely defined, one should use this
2863+
/// method as opposed to 'isCompleteDefinition'.
2864+
/// 'isCompleteDefinition' indicates whether or not a specific
2865+
/// RecordDecl is a completed definition, not whether or not the
2866+
/// record type is defined. This method returns NULL if there is
2867+
/// no RecordDecl that defines the struct/union/tag.
2868+
RecordDecl *getDefinition() const {
28652869
return cast_or_null<RecordDecl>(TagDecl::getDefinition());
28662870
}
28672871

clang/include/clang/AST/TypeLoc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ class TagTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
568568

569569
/// \brief True if the tag was defined in this type specifier.
570570
bool isDefinition() const {
571-
return getDecl()->isDefinition() &&
571+
return getDecl()->isCompleteDefinition() &&
572572
(getNameLoc().isInvalid() || getNameLoc() == getDecl()->getLocation());
573573
}
574574
};

clang/lib/AST/ASTImporter.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,7 @@ Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) {
22332233
D2->setIntegerType(ToIntegerType);
22342234

22352235
// Import the definition
2236-
if (D->isDefinition() && ImportDefinition(D, D2))
2236+
if (D->isCompleteDefinition() && ImportDefinition(D, D2))
22372237
return 0;
22382238

22392239
return D2;
@@ -2286,7 +2286,7 @@ Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
22862286

22872287
if (RecordDecl *FoundRecord = dyn_cast<RecordDecl>(Found)) {
22882288
if (RecordDecl *FoundDef = FoundRecord->getDefinition()) {
2289-
if (!D->isDefinition() || IsStructuralMatch(D, FoundDef)) {
2289+
if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) {
22902290
// The record types structurally match, or the "from" translation
22912291
// unit only had a forward declaration anyway; call it the same
22922292
// function.
@@ -2334,7 +2334,7 @@ Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
23342334

23352335
Importer.Imported(D, D2);
23362336

2337-
if (D->isDefinition() && ImportDefinition(D, D2))
2337+
if (D->isCompleteDefinition() && ImportDefinition(D, D2))
23382338
return 0;
23392339

23402340
return D2;
@@ -3713,7 +3713,8 @@ Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
37133713
Importer.Imported(D, D2);
37143714
Importer.Imported(DTemplated, D2Templated);
37153715

3716-
if (DTemplated->isDefinition() && !D2Templated->isDefinition()) {
3716+
if (DTemplated->isCompleteDefinition() &&
3717+
!D2Templated->isCompleteDefinition()) {
37173718
// FIXME: Import definition!
37183719
}
37193720

@@ -3775,7 +3776,7 @@ Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl(
37753776
// FIXME: Check for specialization vs. instantiation errors.
37763777

37773778
if (RecordDecl *FoundDef = D2->getDefinition()) {
3778-
if (!D->isDefinition() || IsStructuralMatch(D, FoundDef)) {
3779+
if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) {
37793780
// The record types structurally match, or the "from" translation
37803781
// unit only had a forward declaration anyway; call it the same
37813782
// function.
@@ -3805,7 +3806,7 @@ Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl(
38053806
}
38063807
Importer.Imported(D, D2);
38073808

3808-
if (D->isDefinition() && ImportDefinition(D, D2))
3809+
if (D->isCompleteDefinition() && ImportDefinition(D, D2))
38093810
return 0;
38103811

38113812
return D2;

clang/lib/AST/Decl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,22 +2271,22 @@ void TagDecl::completeDefinition() {
22712271
cast<CXXRecordDecl>(this)->hasDefinition()) &&
22722272
"definition completed but not started");
22732273

2274-
IsDefinition = true;
2274+
IsCompleteDefinition = true;
22752275
IsBeingDefined = false;
22762276

22772277
if (ASTMutationListener *L = getASTMutationListener())
22782278
L->CompletedTagDefinition(this);
22792279
}
22802280

2281-
TagDecl* TagDecl::getDefinition() const {
2282-
if (isDefinition())
2281+
TagDecl *TagDecl::getDefinition() const {
2282+
if (isCompleteDefinition())
22832283
return const_cast<TagDecl *>(this);
22842284
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(this))
22852285
return CXXRD->getDefinition();
22862286

22872287
for (redecl_iterator R = redecls_begin(), REnd = redecls_end();
22882288
R != REnd; ++R)
2289-
if (R->isDefinition())
2289+
if (R->isCompleteDefinition())
22902290
return *R;
22912291

22922292
return 0;
@@ -2348,7 +2348,7 @@ void EnumDecl::completeDefinition(QualType NewType,
23482348
QualType NewPromotionType,
23492349
unsigned NumPositiveBits,
23502350
unsigned NumNegativeBits) {
2351-
assert(!isDefinition() && "Cannot redefine enums!");
2351+
assert(!isCompleteDefinition() && "Cannot redefine enums!");
23522352
if (!IntegerType)
23532353
IntegerType = NewType.getTypePtr();
23542354
PromotionType = NewPromotionType;
@@ -2401,7 +2401,7 @@ RecordDecl::field_iterator RecordDecl::field_begin() const {
24012401
/// completeDefinition - Notes that the definition of this type is now
24022402
/// complete.
24032403
void RecordDecl::completeDefinition() {
2404-
assert(!isDefinition() && "Cannot redefine record!");
2404+
assert(!isCompleteDefinition() && "Cannot redefine record!");
24052405
TagDecl::completeDefinition();
24062406
}
24072407

clang/lib/AST/DeclPrinter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void Decl::printGroup(Decl** Begin, unsigned NumDecls,
141141
++Begin;
142142

143143
PrintingPolicy SubPolicy(Policy);
144-
if (TD && TD->isDefinition()) {
144+
if (TD && TD->isCompleteDefinition()) {
145145
TD->print(Out, Policy, Indentation);
146146
Out << " ";
147147
SubPolicy.SuppressTag = true;
@@ -345,7 +345,7 @@ void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
345345
Out << " : " << Underlying;
346346
}
347347

348-
if (D->isDefinition()) {
348+
if (D->isCompleteDefinition()) {
349349
Out << " {\n";
350350
VisitDeclContext(D);
351351
Indent() << "}";
@@ -359,7 +359,7 @@ void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
359359
if (D->getIdentifier())
360360
Out << ' ' << D;
361361

362-
if (D->isDefinition()) {
362+
if (D->isCompleteDefinition()) {
363363
Out << " {\n";
364364
VisitDeclContext(D);
365365
Indent() << "}";
@@ -670,7 +670,7 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
670670
if (D->getIdentifier())
671671
Out << ' ' << D;
672672

673-
if (D->isDefinition()) {
673+
if (D->isCompleteDefinition()) {
674674
// Print the base classes
675675
if (D->getNumBases()) {
676676
Out << " : ";

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2013,7 +2013,7 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
20132013
// until we *finish* parsing the definition.
20142014
D = D->getDefinition();
20152015
assert(D && "Cannot get layout of forward declarations!");
2016-
assert(D->isDefinition() && "Cannot layout type before complete!");
2016+
assert(D->isCompleteDefinition() && "Cannot layout type before complete!");
20172017

20182018
// Look up this layout, if already laid out, return what we have.
20192019
// Note that we can't save a reference to the entry because this function

clang/lib/AST/Type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ bool Type::isIncompleteType() const {
905905
case Record:
906906
// A tagged type (struct/union/enum/class) is incomplete if the decl is a
907907
// forward declaration, but not a full definition (C99 6.2.5p22).
908-
return !cast<TagType>(CanonicalType)->getDecl()->isDefinition();
908+
return !cast<TagType>(CanonicalType)->getDecl()->isCompleteDefinition();
909909
case ConstantArray:
910910
// An array is incomplete if its element type is incomplete
911911
// (C++ [dcl.array]p1).
@@ -1747,7 +1747,7 @@ static TagDecl *getInterestingTagDecl(TagDecl *decl) {
17471747
for (TagDecl::redecl_iterator I = decl->redecls_begin(),
17481748
E = decl->redecls_end();
17491749
I != E; ++I) {
1750-
if (I->isDefinition() || I->isBeingDefined())
1750+
if (I->isCompleteDefinition() || I->isBeingDefined())
17511751
return *I;
17521752
}
17531753
// If there's no definition (not even in progress), return what we have.

clang/lib/AST/VTableBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ void VTableContext::ComputeMethodVTableIndices(const CXXRecordDecl *RD) {
22002200
const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
22012201

22022202
if (PrimaryBase) {
2203-
assert(PrimaryBase->isDefinition() &&
2203+
assert(PrimaryBase->isCompleteDefinition() &&
22042204
"Should have the definition decl of the primary base!");
22052205

22062206
// Since the record decl shares its vtable pointer with the primary base

clang/lib/CodeGen/CGRTTI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ static bool ShouldUseExternalRTTIDescriptor(CodeGenModule &CGM, QualType Ty) {
267267

268268
/// IsIncompleteClassType - Returns whether the given record type is incomplete.
269269
static bool IsIncompleteClassType(const RecordType *RecordTy) {
270-
return !RecordTy->getDecl()->isDefinition();
270+
return !RecordTy->getDecl()->isCompleteDefinition();
271271
}
272272

273273
/// ContainsIncompleteClassType - Returns whether the given type contains an

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
526526

527527
case Type::Enum: {
528528
const EnumDecl *ED = cast<EnumType>(Ty)->getDecl();
529-
if (ED->isDefinition() || ED->isFixed())
529+
if (ED->isCompleteDefinition() || ED->isFixed())
530530
return ConvertType(ED->getIntegerType());
531531
// Return a placeholder 'i32' type. This can be changed later when the
532532
// type is defined (see UpdateCompletedType), but is likely to be the
@@ -579,7 +579,7 @@ llvm::StructType *CodeGenTypes::ConvertRecordDeclType(const RecordDecl *RD) {
579579
// If this is still a forward declaration, or the LLVM type is already
580580
// complete, there's nothing more to do.
581581
RD = RD->getDefinition();
582-
if (RD == 0 || !RD->isDefinition() || !Ty->isOpaque())
582+
if (RD == 0 || !RD->isCompleteDefinition() || !Ty->isOpaque())
583583
return Ty;
584584

585585
// If converting this type would cause us to infinitely loop, don't do it!

clang/lib/Frontend/ASTConsumers.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC,
123123
}
124124
case Decl::Enum: {
125125
const EnumDecl* ED = cast<EnumDecl>(DC);
126-
if (ED->isDefinition())
126+
if (ED->isCompleteDefinition())
127127
Out << "[enum] ";
128128
else
129129
Out << "<enum> ";
@@ -132,7 +132,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC,
132132
}
133133
case Decl::Record: {
134134
const RecordDecl* RD = cast<RecordDecl>(DC);
135-
if (RD->isDefinition())
135+
if (RD->isCompleteDefinition())
136136
Out << "[struct] ";
137137
else
138138
Out << "<struct> ";
@@ -141,7 +141,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC,
141141
}
142142
case Decl::CXXRecord: {
143143
const CXXRecordDecl* RD = cast<CXXRecordDecl>(DC);
144-
if (RD->isDefinition())
144+
if (RD->isCompleteDefinition())
145145
Out << "[class] ";
146146
else
147147
Out << "<class> ";

clang/lib/Rewrite/RewriteObjC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5979,7 +5979,7 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
59795979
}
59805980
} else if (VD->getType()->isRecordType()) {
59815981
RecordDecl *RD = VD->getType()->getAs<RecordType>()->getDecl();
5982-
if (RD->isDefinition())
5982+
if (RD->isCompleteDefinition())
59835983
RewriteRecordBody(RD);
59845984
}
59855985
if (VD->getInit()) {
@@ -6011,7 +6011,7 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
60116011
return;
60126012
}
60136013
if (RecordDecl *RD = dyn_cast<RecordDecl>(D)) {
6014-
if (RD->isDefinition())
6014+
if (RD->isCompleteDefinition())
60156015
RewriteRecordBody(RD);
60166016
return;
60176017
}

clang/lib/Sema/SemaCXXScopeSpec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ bool Sema::RequireCompleteDeclContext(CXXScopeSpec &SS,
237237
// until we see a definition, so awkwardly pull out this special
238238
// case.
239239
if (const EnumType *enumType = dyn_cast_or_null<EnumType>(tagType)) {
240-
if (!enumType->getDecl()->isDefinition()) {
240+
if (!enumType->getDecl()->isCompleteDefinition()) {
241241
Diag(loc, diag::err_incomplete_nested_name_spec)
242242
<< type << SS.getRange();
243243
SS.SetInvalid(SS.getRange());

clang/lib/Sema/SemaChecking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2592,7 +2592,7 @@ struct IntRange {
25922592
// For enum types, use the known bit width of the enumerators.
25932593
if (const EnumType *ET = dyn_cast<EnumType>(T)) {
25942594
EnumDecl *Enum = ET->getDecl();
2595-
if (!Enum->isDefinition())
2595+
if (!Enum->isCompleteDefinition())
25962596
return IntRange(C.getIntWidth(QualType(T, 0)), false);
25972597

25982598
unsigned NumPositive = Enum->getNumPositiveBits();

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
22922292
if (RecordDecl *Record = dyn_cast_or_null<RecordDecl>(Tag)) {
22932293
ProcessDeclAttributeList(S, Record, DS.getAttributes().getList());
22942294

2295-
if (!Record->getDeclName() && Record->isDefinition() &&
2295+
if (!Record->getDeclName() && Record->isCompleteDefinition() &&
22962296
DS.getStorageClassSpec() != DeclSpec::SCS_typedef) {
22972297
if (getLangOptions().CPlusPlus ||
22982298
Record->getDeclContext()->isRecord())
@@ -2313,7 +2313,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
23132313
// and
23142314
// STRUCT_TYPE; <- where STRUCT_TYPE is a typedef struct.
23152315
RecordDecl *Record = dyn_cast_or_null<RecordDecl>(Tag);
2316-
if ((Record && Record->getDeclName() && !Record->isDefinition()) ||
2316+
if ((Record && Record->getDeclName() && !Record->isCompleteDefinition()) ||
23172317
(DS.getTypeSpecType() == DeclSpec::TST_typename &&
23182318
DS.getRepAsType().get()->isStructureType())) {
23192319
Diag(DS.getSourceRange().getBegin(), diag::ext_ms_anonymous_struct)

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,7 @@ static void handleTransparentUnionAttr(Sema &S, Decl *D,
24492449
return;
24502450
}
24512451

2452-
if (!RD->isDefinition()) {
2452+
if (!RD->isCompleteDefinition()) {
24532453
S.Diag(Attr.getLoc(),
24542454
diag::warn_transparent_union_attribute_not_definition);
24552455
return;

0 commit comments

Comments
 (0)