Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 89cf425

Browse files
committed
Use 'const Decl *' throughout code completion in Sema
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173277 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8441fff commit 89cf425

File tree

7 files changed

+160
-149
lines changed

7 files changed

+160
-149
lines changed

Diff for: include/clang/Sema/CodeCompleteConsumer.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T);
121121

122122
/// \brief Determine the type that this declaration will have if it is used
123123
/// as a type or in an expression.
124-
QualType getDeclUsageType(ASTContext &C, NamedDecl *ND);
124+
QualType getDeclUsageType(ASTContext &C, const NamedDecl *ND);
125125

126126
/// \brief Determine the priority to be given to a macro code completion result
127127
/// with the given name.
@@ -530,7 +530,7 @@ class GlobalCodeCompletionAllocator
530530
};
531531

532532
class CodeCompletionTUInfo {
533-
llvm::DenseMap<DeclContext *, StringRef> ParentNames;
533+
llvm::DenseMap<const DeclContext *, StringRef> ParentNames;
534534
IntrusiveRefCntPtr<GlobalCodeCompletionAllocator> AllocatorRef;
535535

536536
public:
@@ -546,7 +546,7 @@ class CodeCompletionTUInfo {
546546
return *AllocatorRef;
547547
}
548548

549-
StringRef getParentName(DeclContext *DC);
549+
StringRef getParentName(const DeclContext *DC);
550550
};
551551

552552
} // end namespace clang
@@ -629,7 +629,7 @@ class CodeCompletionBuilder {
629629
void AddAnnotation(const char *A) { Annotations.push_back(A); }
630630

631631
/// \brief Add the parent context information to this code completion.
632-
void addParentContext(DeclContext *DC);
632+
void addParentContext(const DeclContext *DC);
633633

634634
void addBriefComment(StringRef Comment);
635635

@@ -649,7 +649,7 @@ class CodeCompletionResult {
649649

650650
/// \brief When Kind == RK_Declaration or RK_Pattern, the declaration we are
651651
/// referring to. In the latter case, the declaration might be NULL.
652-
NamedDecl *Declaration;
652+
const NamedDecl *Declaration;
653653

654654
union {
655655
/// \brief When Kind == RK_Keyword, the string representing the keyword
@@ -704,7 +704,7 @@ class CodeCompletionResult {
704704
NestedNameSpecifier *Qualifier;
705705

706706
/// \brief Build a result that refers to a declaration.
707-
CodeCompletionResult(NamedDecl *Declaration,
707+
CodeCompletionResult(const NamedDecl *Declaration,
708708
NestedNameSpecifier *Qualifier = 0,
709709
bool QualifierIsInformative = false,
710710
bool Accessible = true)
@@ -764,7 +764,7 @@ class CodeCompletionResult {
764764
}
765765

766766
/// \brief Retrieve the declaration stored in this result.
767-
NamedDecl *getDeclaration() const {
767+
const NamedDecl *getDeclaration() const {
768768
assert(Kind == RK_Declaration && "Not a declaration result");
769769
return Declaration;
770770
}
@@ -793,7 +793,7 @@ class CodeCompletionResult {
793793
bool IncludeBriefComments);
794794

795795
/// \brief Determine a base priority for the given declaration.
796-
static unsigned getPriorityFromDecl(NamedDecl *ND);
796+
static unsigned getPriorityFromDecl(const NamedDecl *ND);
797797

798798
private:
799799
void computeCursorKindAndAvailability(bool Accessible = true);

Diff for: include/clang/Sema/Sema.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -4013,7 +4013,7 @@ class Sema {
40134013
bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc,
40144014
CXXScopeSpec &SS);
40154015

4016-
bool isAcceptableNestedNameSpecifier(NamedDecl *SD);
4016+
bool isAcceptableNestedNameSpecifier(const NamedDecl *SD);
40174017
NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
40184018

40194019
bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
@@ -5557,13 +5557,14 @@ class Sema {
55575557
bool OnlyDeduced,
55585558
unsigned Depth,
55595559
llvm::SmallBitVector &Used);
5560-
void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate,
5561-
llvm::SmallBitVector &Deduced) {
5560+
void MarkDeducedTemplateParameters(
5561+
const FunctionTemplateDecl *FunctionTemplate,
5562+
llvm::SmallBitVector &Deduced) {
55625563
return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced);
55635564
}
55645565
static void MarkDeducedTemplateParameters(ASTContext &Ctx,
5565-
FunctionTemplateDecl *FunctionTemplate,
5566-
llvm::SmallBitVector &Deduced);
5566+
const FunctionTemplateDecl *FunctionTemplate,
5567+
llvm::SmallBitVector &Deduced);
55675568

55685569
//===--------------------------------------------------------------------===//
55695570
// C++ Template Instantiation

Diff for: lib/Frontend/ASTUnit.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ void ASTUnit::setPreprocessor(Preprocessor *pp) { PP = pp; }
270270

271271
/// \brief Determine the set of code-completion contexts in which this
272272
/// declaration should be shown.
273-
static unsigned getDeclShowContexts(NamedDecl *ND,
273+
static unsigned getDeclShowContexts(const NamedDecl *ND,
274274
const LangOptions &LangOpts,
275275
bool &IsNestedNameSpecifier) {
276276
IsNestedNameSpecifier = false;
@@ -312,7 +312,7 @@ static unsigned getDeclShowContexts(NamedDecl *ND,
312312
// Part of the nested-name-specifier in C++0x.
313313
if (LangOpts.CPlusPlus11)
314314
IsNestedNameSpecifier = true;
315-
} else if (RecordDecl *Record = dyn_cast<RecordDecl>(ND)) {
315+
} else if (const RecordDecl *Record = dyn_cast<RecordDecl>(ND)) {
316316
if (Record->isUnion())
317317
Contexts |= (1LL << CodeCompletionContext::CCC_UnionTag);
318318
else

Diff for: lib/Sema/CodeCompleteConsumer.cpp

+16-15
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ const char *CodeCompletionAllocator::CopyString(Twine String) {
267267
return CopyString(String.toStringRef(Data));
268268
}
269269

270-
StringRef CodeCompletionTUInfo::getParentName(DeclContext *DC) {
271-
NamedDecl *ND = dyn_cast<NamedDecl>(DC);
270+
StringRef CodeCompletionTUInfo::getParentName(const DeclContext *DC) {
271+
const NamedDecl *ND = dyn_cast<NamedDecl>(DC);
272272
if (!ND)
273273
return StringRef();
274274

@@ -283,9 +283,9 @@ StringRef CodeCompletionTUInfo::getParentName(DeclContext *DC) {
283283
return StringRef();
284284

285285
// Find the interesting names.
286-
SmallVector<DeclContext *, 2> Contexts;
286+
SmallVector<const DeclContext *, 2> Contexts;
287287
while (DC && !DC->isFunctionOrMethod()) {
288-
if (NamedDecl *ND = dyn_cast<NamedDecl>(DC)) {
288+
if (const NamedDecl *ND = dyn_cast<NamedDecl>(DC)) {
289289
if (ND->getIdentifier())
290290
Contexts.push_back(DC);
291291
}
@@ -304,12 +304,12 @@ StringRef CodeCompletionTUInfo::getParentName(DeclContext *DC) {
304304
OS << "::";
305305
}
306306

307-
DeclContext *CurDC = Contexts[I-1];
308-
if (ObjCCategoryImplDecl *CatImpl = dyn_cast<ObjCCategoryImplDecl>(CurDC))
307+
const DeclContext *CurDC = Contexts[I-1];
308+
if (const ObjCCategoryImplDecl *CatImpl = dyn_cast<ObjCCategoryImplDecl>(CurDC))
309309
CurDC = CatImpl->getCategoryDecl();
310310

311-
if (ObjCCategoryDecl *Cat = dyn_cast<ObjCCategoryDecl>(CurDC)) {
312-
ObjCInterfaceDecl *Interface = Cat->getClassInterface();
311+
if (const ObjCCategoryDecl *Cat = dyn_cast<ObjCCategoryDecl>(CurDC)) {
312+
const ObjCInterfaceDecl *Interface = Cat->getClassInterface();
313313
if (!Interface) {
314314
// Assign an empty StringRef but with non-null data to distinguish
315315
// between empty because we didn't process the DeclContext yet.
@@ -377,15 +377,15 @@ void CodeCompletionBuilder::AddChunk(CodeCompletionString::ChunkKind CK,
377377
Chunks.push_back(Chunk(CK, Text));
378378
}
379379

380-
void CodeCompletionBuilder::addParentContext(DeclContext *DC) {
380+
void CodeCompletionBuilder::addParentContext(const DeclContext *DC) {
381381
if (DC->isTranslationUnit()) {
382382
return;
383383
}
384384

385385
if (DC->isFunctionOrMethod())
386386
return;
387387

388-
NamedDecl *ND = dyn_cast<NamedDecl>(DC);
388+
const NamedDecl *ND = dyn_cast<NamedDecl>(DC);
389389
if (!ND)
390390
return;
391391

@@ -396,15 +396,16 @@ void CodeCompletionBuilder::addBriefComment(StringRef Comment) {
396396
BriefComment = Allocator.CopyString(Comment);
397397
}
398398

399-
unsigned CodeCompletionResult::getPriorityFromDecl(NamedDecl *ND) {
399+
unsigned CodeCompletionResult::getPriorityFromDecl(const NamedDecl *ND) {
400400
if (!ND)
401401
return CCP_Unlikely;
402402

403403
// Context-based decisions.
404-
DeclContext *DC = ND->getDeclContext()->getRedeclContext();
404+
const DeclContext *DC = ND->getDeclContext()->getRedeclContext();
405405
if (DC->isFunctionOrMethod() || isa<BlockDecl>(DC)) {
406406
// _cmd is relatively rare
407-
if (ImplicitParamDecl *ImplicitParam = dyn_cast<ImplicitParamDecl>(ND))
407+
if (const ImplicitParamDecl *ImplicitParam =
408+
dyn_cast<ImplicitParamDecl>(ND))
408409
if (ImplicitParam->getIdentifier() &&
409410
ImplicitParam->getIdentifier()->isStr("_cmd"))
410411
return CCP_ObjC_cmd;
@@ -526,7 +527,7 @@ PrintingCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef,
526527
}
527528

528529
/// \brief Retrieve the effective availability of the given declaration.
529-
static AvailabilityResult getDeclAvailability(Decl *D) {
530+
static AvailabilityResult getDeclAvailability(const Decl *D) {
530531
AvailabilityResult AR = D->getAvailability();
531532
if (isa<EnumConstantDecl>(D))
532533
AR = std::max(AR, cast<Decl>(D->getDeclContext())->getAvailability());
@@ -559,7 +560,7 @@ void CodeCompletionResult::computeCursorKindAndAvailability(bool Accessible) {
559560
break;
560561
}
561562

562-
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Declaration))
563+
if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(Declaration))
563564
if (Function->isDeleted())
564565
Availability = CXAvailability_NotAvailable;
565566

Diff for: lib/Sema/SemaCXXScopeSpec.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ bool Sema::ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc,
263263

264264
/// \brief Determines whether the given declaration is an valid acceptable
265265
/// result for name lookup of a nested-name-specifier.
266-
bool Sema::isAcceptableNestedNameSpecifier(NamedDecl *SD) {
266+
bool Sema::isAcceptableNestedNameSpecifier(const NamedDecl *SD) {
267267
if (!SD)
268268
return false;
269269

@@ -279,7 +279,7 @@ bool Sema::isAcceptableNestedNameSpecifier(NamedDecl *SD) {
279279
QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD));
280280
if (T->isDependentType())
281281
return true;
282-
else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(SD)) {
282+
else if (const TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(SD)) {
283283
if (TD->getUnderlyingType()->isRecordType() ||
284284
(Context.getLangOpts().CPlusPlus11 &&
285285
TD->getUnderlyingType()->isEnumeralType()))

0 commit comments

Comments
 (0)