 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
71.7% |
763 / 1064 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
91.4% |
972 / 1064 |
| |
|
Line Coverage: |
88.2% |
1469 / 1666 |
| |
 |
|
 |
1 : //===---------------- SemaCodeComplete.cpp - Code Completion ----*- C++ -*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This file defines the code-completion semantic actions.
11 : //
12 : //===----------------------------------------------------------------------===//
13 : #include "Sema.h"
14 : #include "Lookup.h"
15 : #include "clang/Sema/CodeCompleteConsumer.h"
16 : #include "clang/AST/ExprCXX.h"
17 : #include "clang/AST/ExprObjC.h"
18 : #include "clang/Lex/MacroInfo.h"
19 : #include "clang/Lex/Preprocessor.h"
20 : #include "llvm/ADT/SmallPtrSet.h"
21 : #include "llvm/ADT/StringExtras.h"
22 : #include <list>
23 : #include <map>
24 : #include <vector>
25 :
26 : using namespace clang;
27 :
28 : namespace {
29 : /// \brief A container of code-completion results.
30 81: class ResultBuilder {
31 : public:
32 : /// \brief The type of a name-lookup filter, which can be provided to the
33 : /// name-lookup routines to specify which declarations should be included in
34 : /// the result set (when it returns true) and which declarations should be
35 : /// filtered out (returns false).
36 : typedef bool (ResultBuilder::*LookupFilter)(NamedDecl *) const;
37 :
38 : typedef CodeCompleteConsumer::Result Result;
39 :
40 : private:
41 : /// \brief The actual results we have found.
42 : std::vector<Result> Results;
43 :
44 : /// \brief A record of all of the declarations we have found and placed
45 : /// into the result set, used to ensure that no declaration ever gets into
46 : /// the result set twice.
47 : llvm::SmallPtrSet<Decl*, 16> AllDeclsFound;
48 :
49 : typedef std::pair<NamedDecl *, unsigned> DeclIndexPair;
50 :
51 : /// \brief An entry in the shadow map, which is optimized to store
52 : /// a single (declaration, index) mapping (the common case) but
53 : /// can also store a list of (declaration, index) mappings.
54 64: class ShadowMapEntry {
55 : typedef llvm::SmallVector<DeclIndexPair, 4> DeclIndexPairVector;
56 :
57 : /// \brief Contains either the solitary NamedDecl * or a vector
58 : /// of (declaration, index) pairs.
59 : llvm::PointerUnion<NamedDecl *, DeclIndexPairVector*> DeclOrVector;
60 :
61 : /// \brief When the entry contains a single declaration, this is
62 : /// the index associated with that entry.
63 : unsigned SingleDeclIndex;
64 :
65 : public:
66 64: ShadowMapEntry() : DeclOrVector(), SingleDeclIndex(0) { }
67 :
68 65: void Add(NamedDecl *ND, unsigned Index) {
64: branch 1 taken
1: branch 2 taken
69 65: if (DeclOrVector.isNull()) {
70 : // 0 - > 1 elements: just set the single element information.
71 64: DeclOrVector = ND;
72 64: SingleDeclIndex = Index;
73 64: return;
74 : }
75 :
1: branch 1 taken
0: branch 2 not taken
76 1: if (NamedDecl *PrevND = DeclOrVector.dyn_cast<NamedDecl *>()) {
77 : // 1 -> 2 elements: create the vector of results and push in the
78 : // existing declaration.
79 1: DeclIndexPairVector *Vec = new DeclIndexPairVector;
80 1: Vec->push_back(DeclIndexPair(PrevND, SingleDeclIndex));
81 1: DeclOrVector = Vec;
82 : }
83 :
84 : // Add the new element to the end of the vector.
85 : DeclOrVector.get<DeclIndexPairVector*>()->push_back(
86 1: DeclIndexPair(ND, Index));
87 : }
88 :
89 64: void Destroy() {
1: branch 0 taken
63: branch 1 taken
90 64: if (DeclIndexPairVector *Vec
91 64: = DeclOrVector.dyn_cast<DeclIndexPairVector *>()) {
1: branch 0 taken
0: branch 1 not taken
92 1: delete Vec;
93 1: DeclOrVector = ((NamedDecl *)0);
94 : }
95 64: }
96 :
97 : // Iteration.
98 : class iterator;
99 : iterator begin() const;
100 : iterator end() const;
101 : };
102 :
103 : /// \brief A mapping from declaration names to the declarations that have
104 : /// this name within a particular scope and their index within the list of
105 : /// results.
106 : typedef llvm::DenseMap<DeclarationName, ShadowMapEntry> ShadowMap;
107 :
108 : /// \brief The semantic analysis object for which results are being
109 : /// produced.
110 : Sema &SemaRef;
111 :
112 : /// \brief If non-NULL, a filter function used to remove any code-completion
113 : /// results that are not desirable.
114 : LookupFilter Filter;
115 :
116 : /// \brief Whether we should allow declarations as
117 : /// nested-name-specifiers that would otherwise be filtered out.
118 : bool AllowNestedNameSpecifiers;
119 :
120 : /// \brief A list of shadow maps, which is used to model name hiding at
121 : /// different levels of, e.g., the inheritance hierarchy.
122 : std::list<ShadowMap> ShadowMaps;
123 :
124 : public:
125 81: explicit ResultBuilder(Sema &SemaRef, LookupFilter Filter = 0)
126 81: : SemaRef(SemaRef), Filter(Filter), AllowNestedNameSpecifiers(false) { }
127 :
128 : /// \brief Set the filter used for code-completion results.
129 13: void setFilter(LookupFilter Filter) {
130 13: this->Filter = Filter;
131 13: }
132 :
133 : typedef std::vector<Result>::iterator iterator;
134 : iterator begin() { return Results.begin(); }
135 : iterator end() { return Results.end(); }
136 :
0: branch 1 not taken
81: branch 2 taken
137 81: Result *data() { return Results.empty()? 0 : &Results.front(); }
138 81: unsigned size() const { return Results.size(); }
139 8: bool empty() const { return Results.empty(); }
140 :
141 : /// \brief Specify whether nested-name-specifiers are allowed.
142 13: void allowNestedNameSpecifiers(bool Allow = true) {
143 13: AllowNestedNameSpecifiers = Allow;
144 13: }
145 :
146 : /// \brief Determine whether the given declaration is at all interesting
147 : /// as a code-completion result.
148 : ///
149 : /// \param ND the declaration that we are inspecting.
150 : ///
151 : /// \param AsNestedNameSpecifier will be set true if this declaration is
152 : /// only interesting when it is a nested-name-specifier.
153 : bool isInterestingDecl(NamedDecl *ND, bool &AsNestedNameSpecifier) const;
154 :
155 : /// \brief Check whether the result is hidden by the Hiding declaration.
156 : ///
157 : /// \returns true if the result is hidden and cannot be found, false if
158 : /// the hidden result could still be found. When false, \p R may be
159 : /// modified to describe how the result can be found (e.g., via extra
160 : /// qualification).
161 : bool CheckHiddenResult(Result &R, DeclContext *CurContext,
162 : NamedDecl *Hiding);
163 :
164 : /// \brief Add a new result to this result set (if it isn't already in one
165 : /// of the shadow maps), or replace an existing result (for, e.g., a
166 : /// redeclaration).
167 : ///
168 : /// \param CurContext the result to add (if it is unique).
169 : ///
170 : /// \param R the context in which this result will be named.
171 : void MaybeAddResult(Result R, DeclContext *CurContext = 0);
172 :
173 : /// \brief Add a new result to this result set, where we already know
174 : /// the hiding declation (if any).
175 : ///
176 : /// \param R the result to add (if it is unique).
177 : ///
178 : /// \param CurContext the context in which this result will be named.
179 : ///
180 : /// \param Hiding the declaration that hides the result.
181 : ///
182 : /// \param InBaseClass whether the result was found in a base
183 : /// class of the searched context.
184 : void AddResult(Result R, DeclContext *CurContext, NamedDecl *Hiding,
185 : bool InBaseClass);
186 :
187 : /// \brief Add a new non-declaration result to this result set.
188 : void AddResult(Result R);
189 :
190 : /// \brief Enter into a new scope.
191 : void EnterNewScope();
192 :
193 : /// \brief Exit from the current scope.
194 : void ExitScope();
195 :
196 : /// \brief Ignore this declaration, if it is seen again.
197 6: void Ignore(Decl *D) { AllDeclsFound.insert(D->getCanonicalDecl()); }
198 :
199 : /// \name Name lookup predicates
200 : ///
201 : /// These predicates can be passed to the name lookup functions to filter the
202 : /// results of name lookup. All of the predicates have the same type, so that
203 : ///
204 : //@{
205 : bool IsOrdinaryName(NamedDecl *ND) const;
206 : bool IsOrdinaryNonValueName(NamedDecl *ND) const;
207 : bool IsNestedNameSpecifier(NamedDecl *ND) const;
208 : bool IsEnum(NamedDecl *ND) const;
209 : bool IsClassOrStruct(NamedDecl *ND) const;
210 : bool IsUnion(NamedDecl *ND) const;
211 : bool IsNamespace(NamedDecl *ND) const;
212 : bool IsNamespaceOrAlias(NamedDecl *ND) const;
213 : bool IsType(NamedDecl *ND) const;
214 : bool IsMember(NamedDecl *ND) const;
215 : bool IsObjCIvar(NamedDecl *ND) const;
216 : //@}
217 : };
218 : }
219 :
220 : class ResultBuilder::ShadowMapEntry::iterator {
221 : llvm::PointerUnion<NamedDecl*, const DeclIndexPair*> DeclOrIterator;
222 : unsigned SingleDeclIndex;
223 :
224 : public:
225 : typedef DeclIndexPair value_type;
226 : typedef value_type reference;
227 : typedef std::ptrdiff_t difference_type;
228 : typedef std::input_iterator_tag iterator_category;
229 :
230 : class pointer {
231 : DeclIndexPair Value;
232 :
233 : public:
234 8: pointer(const DeclIndexPair &Value) : Value(Value) { }
235 :
236 8: const DeclIndexPair *operator->() const {
237 8: return &Value;
238 : }
239 : };
240 :
241 148: iterator() : DeclOrIterator((NamedDecl *)0), SingleDeclIndex(0) { }
242 :
243 4: iterator(NamedDecl *SingleDecl, unsigned Index)
244 4: : DeclOrIterator(SingleDecl), SingleDeclIndex(Index) { }
245 :
246 0: iterator(const DeclIndexPair *Iterator)
247 0: : DeclOrIterator(Iterator), SingleDeclIndex(0) { }
248 :
249 1: iterator &operator++() {
1: branch 1 taken
0: branch 2 not taken
250 1: if (DeclOrIterator.is<NamedDecl *>()) {
251 1: DeclOrIterator = (NamedDecl *)0;
252 1: SingleDeclIndex = 0;
253 1: return *this;
254 : }
255 :
256 0: const DeclIndexPair *I = DeclOrIterator.get<const DeclIndexPair*>();
257 0: ++I;
258 0: DeclOrIterator = I;
259 0: return *this;
260 : }
261 :
262 : iterator operator++(int) {
263 : iterator tmp(*this);
264 : ++(*this);
265 : return tmp;
266 : }
267 :
268 8: reference operator*() const {
8: branch 1 taken
0: branch 2 not taken
269 8: if (NamedDecl *ND = DeclOrIterator.dyn_cast<NamedDecl *>())
270 8: return reference(ND, SingleDeclIndex);
271 :
272 0: return *DeclOrIterator.get<const DeclIndexPair*>();
273 : }
274 :
275 8: pointer operator->() const {
276 8: return pointer(**this);
277 : }
278 :
279 73: friend bool operator==(const iterator &X, const iterator &Y) {
280 : return X.DeclOrIterator.getOpaqueValue()
281 : == Y.DeclOrIterator.getOpaqueValue() &&
69: branch 2 taken
4: branch 3 taken
69: branch 4 taken
0: branch 5 not taken
282 73: X.SingleDeclIndex == Y.SingleDeclIndex;
283 : }
284 :
285 73: friend bool operator!=(const iterator &X, const iterator &Y) {
286 73: return !(X == Y);
287 : }
288 : };
289 :
290 : ResultBuilder::ShadowMapEntry::iterator
291 4: ResultBuilder::ShadowMapEntry::begin() const {
0: branch 1 not taken
4: branch 2 taken
292 4: if (DeclOrVector.isNull())
293 0: return iterator();
294 :
4: branch 1 taken
0: branch 2 not taken
295 4: if (NamedDecl *ND = DeclOrVector.dyn_cast<NamedDecl *>())
296 4: return iterator(ND, SingleDeclIndex);
297 :
298 0: return iterator(DeclOrVector.get<DeclIndexPairVector *>()->begin());
299 : }
300 :
301 : ResultBuilder::ShadowMapEntry::iterator
302 4: ResultBuilder::ShadowMapEntry::end() const {
0: branch 1 not taken
4: branch 2 taken
0: branch 4 not taken
0: branch 5 not taken
4: branch 6 taken
0: branch 7 not taken
303 4: if (DeclOrVector.is<NamedDecl *>() || DeclOrVector.isNull())
304 4: return iterator();
305 :
306 0: return iterator(DeclOrVector.get<DeclIndexPairVector *>()->end());
307 : }
308 :
309 : /// \brief Compute the qualification required to get from the current context
310 : /// (\p CurContext) to the target context (\p TargetContext).
311 : ///
312 : /// \param Context the AST context in which the qualification will be used.
313 : ///
314 : /// \param CurContext the context where an entity is being named, which is
315 : /// typically based on the current scope.
316 : ///
317 : /// \param TargetContext the context in which the named entity actually
318 : /// resides.
319 : ///
320 : /// \returns a nested name specifier that refers into the target context, or
321 : /// NULL if no qualification is needed.
322 : static NestedNameSpecifier *
323 : getRequiredQualification(ASTContext &Context,
324 : DeclContext *CurContext,
325 14: DeclContext *TargetContext) {
326 14: llvm::SmallVector<DeclContext *, 4> TargetParents;
327 :
27: branch 1 taken
0: branch 2 not taken
13: branch 4 taken
14: branch 5 taken
13: branch 6 taken
14: branch 7 taken
328 27: for (DeclContext *CommonAncestor = TargetContext;
329 : CommonAncestor && !CommonAncestor->Encloses(CurContext);
330 : CommonAncestor = CommonAncestor->getLookupParent()) {
13: branch 1 taken
0: branch 2 not taken
0: branch 4 not taken
13: branch 5 taken
0: branch 6 not taken
13: branch 7 taken
331 13: if (CommonAncestor->isTransparentContext() ||
332 : CommonAncestor->isFunctionOrMethod())
333 0: continue;
334 :
335 13: TargetParents.push_back(CommonAncestor);
336 : }
337 :
338 14: NestedNameSpecifier *Result = 0;
13: branch 1 taken
14: branch 2 taken
339 41: while (!TargetParents.empty()) {
340 13: DeclContext *Parent = TargetParents.back();
341 13: TargetParents.pop_back();
342 :
3: branch 1 taken
10: branch 2 taken
343 13: if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Parent))
344 3: Result = NestedNameSpecifier::Create(Context, Result, Namespace);
10: branch 1 taken
0: branch 2 not taken
345 10: else if (TagDecl *TD = dyn_cast<TagDecl>(Parent))
346 : Result = NestedNameSpecifier::Create(Context, Result,
347 : false,
348 10: Context.getTypeDeclType(TD).getTypePtr());
349 : else
0: branch 1 not taken
0: branch 2 not taken
350 0: assert(Parent->isTranslationUnit());
351 : }
352 14: return Result;
353 : }
354 :
355 : bool ResultBuilder::isInterestingDecl(NamedDecl *ND,
356 449: bool &AsNestedNameSpecifier) const {
357 449: AsNestedNameSpecifier = false;
358 :
359 449: ND = ND->getUnderlyingDecl();
360 449: unsigned IDNS = ND->getIdentifierNamespace();
361 :
362 : // Skip unnamed entities.
0: branch 2 not taken
449: branch 3 taken
363 449: if (!ND->getDeclName())
364 0: return false;
365 :
366 : // Friend declarations and declarations introduced due to friends are never
367 : // added as results.
449: branch 1 taken
0: branch 2 not taken
0: branch 3 not taken
449: branch 4 taken
0: branch 5 not taken
449: branch 6 taken
368 449: if (isa<FriendDecl>(ND) ||
369 : (IDNS & (Decl::IDNS_OrdinaryFriend | Decl::IDNS_TagFriend)))
370 0: return false;
371 :
372 : // Class template (partial) specializations are never added as results.
449: branch 1 taken
0: branch 2 not taken
0: branch 4 not taken
449: branch 5 taken
0: branch 6 not taken
449: branch 7 taken
373 449: if (isa<ClassTemplateSpecializationDecl>(ND) ||
374 : isa<ClassTemplatePartialSpecializationDecl>(ND))
375 0: return false;
376 :
377 : // Using declarations themselves are never added as results.
0: branch 1 not taken
449: branch 2 taken
378 449: if (isa<UsingDecl>(ND))
379 0: return false;
380 :
381 : // Some declarations have reserved names that we don't want to ever show.
353: branch 1 taken
96: branch 2 taken
382 449: if (const IdentifierInfo *Id = ND->getIdentifier()) {
383 : // __va_list_tag is a freak of nature. Find it and skip it.
353: branch 1 taken
0: branch 2 not taken
33: branch 4 taken
320: branch 5 taken
33: branch 6 taken
320: branch 7 taken
384 353: if (Id->isStr("__va_list_tag") || Id->isStr("__builtin_va_list"))
385 33: return false;
386 :
387 : // Filter out names reserved for the implementation (C99 7.1.3,
388 : // C++ [lib.global.names]). Users don't need to see those.
389 : //
390 : // FIXME: Add predicate for this.
237: branch 1 taken
83: branch 2 taken
391 320: if (Id->getLength() >= 2) {
392 237: const char *Name = Id->getNameStart();
2: branch 0 taken
235: branch 1 taken
2: branch 2 taken
0: branch 3 not taken
2: branch 4 taken
0: branch 5 not taken
0: branch 6 not taken
2: branch 7 taken
393 237: if (Name[0] == '_' &&
394 : (Name[1] == '_' || (Name[1] >= 'A' && Name[1] <= 'Z')))
395 0: return false;
396 : }
397 : }
398 :
399 : // C++ constructors are never found by name lookup.
20: branch 1 taken
396: branch 2 taken
400 416: if (isa<CXXConstructorDecl>(ND))
401 20: return false;
402 :
403 : // Filter out any unwanted results.
246: branch 0 taken
150: branch 1 taken
0: branch 2 not taken
246: branch 3 taken
32: branch 5 taken
214: branch 6 taken
32: branch 7 taken
364: branch 8 taken
404 396: if (Filter && !(this->*Filter)(ND)) {
405 : // Check whether it is interesting as a nested-name-specifier.
22: branch 0 taken
10: branch 1 taken
20: branch 3 taken
2: branch 4 taken
17: branch 6 taken
3: branch 7 taken
10: branch 8 taken
7: branch 9 taken
0: branch 10 not taken
10: branch 11 taken
10: branch 12 taken
10: branch 13 taken
10: branch 15 taken
0: branch 16 not taken
10: branch 19 taken
0: branch 20 not taken
17: branch 21 taken
15: branch 22 taken
406 32: if (AllowNestedNameSpecifiers && SemaRef.getLangOptions().CPlusPlus &&
407 : IsNestedNameSpecifier(ND) &&
408 : (Filter != &ResultBuilder::IsMember ||
409 : (isa<CXXRecordDecl>(ND) &&
410 : cast<CXXRecordDecl>(ND)->isInjectedClassName()))) {
411 17: AsNestedNameSpecifier = true;
412 17: return true;
413 : }
414 :
415 15: return false;
416 : }
417 :
418 : // ... then it must be interesting!
419 364: return true;
420 : }
421 :
422 : bool ResultBuilder::CheckHiddenResult(Result &R, DeclContext *CurContext,
423 73: NamedDecl *Hiding) {
424 : // In C, there is no way to refer to a hidden name.
425 : // FIXME: This isn't true; we can find a tag name hidden by an ordinary
426 : // name if we introduce the tag type.
32: branch 1 taken
41: branch 2 taken
427 73: if (!SemaRef.getLangOptions().CPlusPlus)
428 32: return true;
429 :
430 41: DeclContext *HiddenCtx = R.Declaration->getDeclContext()->getLookupContext();
431 :
432 : // There is no way to qualify a name declared in a function or method.
0: branch 1 not taken
41: branch 2 taken
433 41: if (HiddenCtx->isFunctionOrMethod())
434 0: return true;
435 :
28: branch 2 taken
13: branch 3 taken
436 41: if (HiddenCtx == Hiding->getDeclContext()->getLookupContext())
437 28: return true;
438 :
439 : // We can refer to the result with the appropriate qualification. Do it.
440 13: R.Hidden = true;
441 13: R.QualifierIsInformative = false;
442 :
13: branch 0 taken
0: branch 1 not taken
443 13: if (!R.Qualifier)
444 : R.Qualifier = getRequiredQualification(SemaRef.Context,
445 : CurContext,
446 13: R.Declaration->getDeclContext());
447 13: return false;
448 : }
449 :
450 72: void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) {
72: branch 1 taken
0: branch 2 not taken
451 72: assert(!ShadowMaps.empty() && "Must enter into a results scope");
452 :
0: branch 0 not taken
72: branch 1 taken
453 72: if (R.Kind != Result::RK_Declaration) {
454 : // For non-declaration results, just add the result.
455 0: Results.push_back(R);
456 0: return;
457 : }
458 :
459 : // Look through using declarations.
0: branch 1 not taken
72: branch 2 taken
460 72: if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) {
461 0: MaybeAddResult(Result(Using->getTargetDecl(), R.Qualifier), CurContext);
462 0: return;
463 : }
464 :
465 72: Decl *CanonDecl = R.Declaration->getCanonicalDecl();
466 72: unsigned IDNS = CanonDecl->getIdentifierNamespace();
467 :
468 72: bool AsNestedNameSpecifier = false;
0: branch 1 not taken
72: branch 2 taken
469 72: if (!isInterestingDecl(R.Declaration, AsNestedNameSpecifier))
470 0: return;
471 :
472 72: ShadowMap &SMap = ShadowMaps.back();
473 72: ShadowMapEntry::iterator I, IEnd;
474 72: ShadowMap::iterator NamePos = SMap.find(R.Declaration->getDeclName());
4: branch 3 taken
68: branch 4 taken
475 72: if (NamePos != SMap.end()) {
476 4: I = NamePos->second.begin();
477 4: IEnd = NamePos->second.end();
478 : }
479 :
4: branch 2 taken
69: branch 3 taken
480 73: for (; I != IEnd; ++I) {
481 4: NamedDecl *ND = I->first;
482 4: unsigned Index = I->second;
3: branch 1 taken
1: branch 2 taken
483 4: if (ND->getCanonicalDecl() == CanonDecl) {
484 : // This is a redeclaration. Always pick the newer declaration.
485 3: Results[Index].Declaration = R.Declaration;
486 :
487 : // We're done.
488 3: return;
489 : }
490 : }
491 :
492 : // This is a new declaration in this scope. However, check whether this
493 : // declaration name is hidden by a similarly-named declaration in an outer
494 : // scope.
495 69: std::list<ShadowMap>::iterator SM, SMEnd = ShadowMaps.end();
496 69: --SMEnd;
0: branch 3 not taken
69: branch 4 taken
497 69: for (SM = ShadowMaps.begin(); SM != SMEnd; ++SM) {
498 0: ShadowMapEntry::iterator I, IEnd;
499 0: ShadowMap::iterator NamePos = SM->find(R.Declaration->getDeclName());
0: branch 4 not taken
0: branch 5 not taken
500 0: if (NamePos != SM->end()) {
501 0: I = NamePos->second.begin();
502 0: IEnd = NamePos->second.end();
503 : }
0: branch 2 not taken
0: branch 3 not taken
504 0: for (; I != IEnd; ++I) {
505 : // A tag declaration does not hide a non-tag declaration.
0: branch 3 not taken
0: branch 4 not taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 7 not taken
0: branch 8 not taken
506 0: if (I->first->getIdentifierNamespace() == Decl::IDNS_Tag &&
507 : (IDNS & (Decl::IDNS_Member | Decl::IDNS_Ordinary |
508 : Decl::IDNS_ObjCProtocol)))
509 0: continue;
510 :
511 : // Protocols are in distinct namespaces from everything else.
0: branch 3 not taken
0: branch 4 not taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 10 not taken
0: branch 11 not taken
0: branch 12 not taken
0: branch 13 not taken
512 0: if (((I->first->getIdentifierNamespace() & Decl::IDNS_ObjCProtocol)
513 : || (IDNS & Decl::IDNS_ObjCProtocol)) &&
514 : I->first->getIdentifierNamespace() != IDNS)
515 0: continue;
516 :
517 : // The newly-added result is hidden by an entry in the shadow map.
0: branch 3 not taken
0: branch 4 not taken
518 0: if (CheckHiddenResult(R, CurContext, I->first))
519 0: return;
520 :
521 0: break;
522 : }
523 : }
524 :
525 : // Make sure that any given declaration only shows up in the result set once.
4: branch 1 taken
65: branch 2 taken
526 69: if (!AllDeclsFound.insert(CanonDecl))
527 4: return;
528 :
529 : // If the filter is for nested-name-specifiers, then this result starts a
530 : // nested-name-specifier.
0: branch 0 not taken
65: branch 1 taken
531 65: if (AsNestedNameSpecifier)
532 0: R.StartsNestedNameSpecifier = true;
533 :
534 : // If this result is supposed to have an informative qualifier, add one.
0: branch 0 not taken
65: branch 1 taken
65: branch 2 taken
65: branch 3 taken
65: branch 4 taken
65: branch 5 taken
535 65: if (R.QualifierIsInformative && !R.Qualifier &&
536 : !R.StartsNestedNameSpecifier) {
537 0: DeclContext *Ctx = R.Declaration->getDeclContext();
0: branch 1 not taken
0: branch 2 not taken
538 0: if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx))
539 0: R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, Namespace);
0: branch 1 not taken
0: branch 2 not taken
540 0: else if (TagDecl *Tag = dyn_cast<TagDecl>(Ctx))
541 : R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, false,
542 0: SemaRef.Context.getTypeDeclType(Tag).getTypePtr());
543 : else
544 0: R.QualifierIsInformative = false;
545 : }
546 :
547 : // Insert this result into the set of results and into the current shadow
548 : // map.
549 65: SMap[R.Declaration->getDeclName()].Add(R.Declaration, Results.size());
550 65: Results.push_back(R);
551 : }
552 :
553 : void ResultBuilder::AddResult(Result R, DeclContext *CurContext,
554 379: NamedDecl *Hiding, bool InBaseClass = false) {
0: branch 0 not taken
379: branch 1 taken
555 379: if (R.Kind != Result::RK_Declaration) {
556 : // For non-declaration results, just add the result.
557 0: Results.push_back(R);
558 0: return;
559 : }
560 :
561 : // Look through using declarations.
2: branch 1 taken
377: branch 2 taken
562 379: if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) {
563 2: AddResult(Result(Using->getTargetDecl(), R.Qualifier), CurContext, Hiding);
564 2: return;
565 : }
566 :
567 377: bool AsNestedNameSpecifier = false;
68: branch 1 taken
309: branch 2 taken
568 377: if (!isInterestingDecl(R.Declaration, AsNestedNameSpecifier))
569 68: return;
570 :
73: branch 0 taken
236: branch 1 taken
60: branch 3 taken
13: branch 4 taken
60: branch 5 taken
249: branch 6 taken
571 309: if (Hiding && CheckHiddenResult(R, CurContext, Hiding))
572 60: return;
573 :
574 : // Make sure that any given declaration only shows up in the result set once.
21: branch 2 taken
228: branch 3 taken
575 249: if (!AllDeclsFound.insert(R.Declaration->getCanonicalDecl()))
576 21: return;
577 :
578 : // If the filter is for nested-name-specifiers, then this result starts a
579 : // nested-name-specifier.
13: branch 0 taken
215: branch 1 taken
580 228: if (AsNestedNameSpecifier)
581 13: R.StartsNestedNameSpecifier = true;
53: branch 0 taken
162: branch 1 taken
0: branch 2 not taken
53: branch 3 taken
53: branch 4 taken
53: branch 5 taken
44: branch 6 taken
9: branch 7 taken
16: branch 8 taken
28: branch 9 taken
16: branch 13 taken
0: branch 14 not taken
16: branch 15 taken
199: branch 16 taken
582 215: else if (Filter == &ResultBuilder::IsMember && !R.Qualifier && InBaseClass &&
583 : isa<CXXRecordDecl>(R.Declaration->getDeclContext()
584 : ->getLookupContext()))
585 16: R.QualifierIsInformative = true;
586 :
587 : // If this result is supposed to have an informative qualifier, add one.
16: branch 0 taken
212: branch 1 taken
16: branch 2 taken
0: branch 3 not taken
16: branch 4 taken
0: branch 5 not taken
588 228: if (R.QualifierIsInformative && !R.Qualifier &&
589 : !R.StartsNestedNameSpecifier) {
590 16: DeclContext *Ctx = R.Declaration->getDeclContext();
0: branch 1 not taken
16: branch 2 taken
591 16: if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx))
592 0: R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, Namespace);
16: branch 1 taken
0: branch 2 not taken
593 16: else if (TagDecl *Tag = dyn_cast<TagDecl>(Ctx))
594 : R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, false,
595 16: SemaRef.Context.getTypeDeclType(Tag).getTypePtr());
596 : else
597 0: R.QualifierIsInformative = false;
598 : }
599 :
600 : // Insert this result into the set of results.
601 228: Results.push_back(R);
602 : }
603 :
604 2288: void ResultBuilder::AddResult(Result R) {
605 : assert(R.Kind != Result::RK_Declaration &&
0: branch 0 not taken
2288: branch 1 taken
606 2288: "Declaration results need more context");
607 2288: Results.push_back(R);
608 2288: }
609 :
610 : /// \brief Enter into a new scope.
611 87: void ResultBuilder::EnterNewScope() {
612 87: ShadowMaps.push_back(ShadowMap());
613 87: }
614 :
615 : /// \brief Exit from the current scope.
616 87: void ResultBuilder::ExitScope() {
64: branch 5 taken
87: branch 6 taken
617 238: for (ShadowMap::iterator E = ShadowMaps.back().begin(),
618 87: EEnd = ShadowMaps.back().end();
619 : E != EEnd;
620 : ++E)
621 64: E->second.Destroy();
622 :
623 87: ShadowMaps.pop_back();
624 87: }
625 :
626 : /// \brief Determines whether this given declaration will be found by
627 : /// ordinary name lookup.
628 67: bool ResultBuilder::IsOrdinaryName(NamedDecl *ND) const {
629 67: unsigned IDNS = Decl::IDNS_Ordinary;
22: branch 1 taken
45: branch 2 taken
630 67: if (SemaRef.getLangOptions().CPlusPlus)
631 22: IDNS |= Decl::IDNS_Tag;
30: branch 1 taken
15: branch 2 taken
1: branch 4 taken
29: branch 5 taken
1: branch 6 taken
44: branch 7 taken
632 45: else if (SemaRef.getLangOptions().ObjC1 && isa<ObjCIvarDecl>(ND))
633 1: return true;
634 :
635 66: return ND->getIdentifierNamespace() & IDNS;
636 : }
637 :
638 : /// \brief Determines whether this given declaration will be found by
639 : /// ordinary name lookup.
640 37: bool ResultBuilder::IsOrdinaryNonValueName(NamedDecl *ND) const {
641 37: unsigned IDNS = Decl::IDNS_Ordinary;
12: branch 1 taken
25: branch 2 taken
642 37: if (SemaRef.getLangOptions().CPlusPlus)
643 12: IDNS |= Decl::IDNS_Tag;
644 :
645 : return (ND->getIdentifierNamespace() & IDNS) &&
36: branch 1 taken
1: branch 2 taken
34: branch 4 taken
2: branch 5 taken
34: branch 7 taken
0: branch 8 not taken
646 37: !isa<ValueDecl>(ND) && !isa<FunctionTemplateDecl>(ND);
647 : }
648 :
649 : /// \brief Determines whether the given declaration is suitable as the
650 : /// start of a C++ nested-name-specifier, e.g., a class or namespace.
651 32: bool ResultBuilder::IsNestedNameSpecifier(NamedDecl *ND) const {
652 : // Allow us to find class templates, too.
0: branch 1 not taken
32: branch 2 taken
653 32: if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
654 0: ND = ClassTemplate->getTemplatedDecl();
655 :
656 32: return SemaRef.isAcceptableNestedNameSpecifier(ND);
657 : }
658 :
659 : /// \brief Determines whether the given declaration is an enumeration.
660 7: bool ResultBuilder::IsEnum(NamedDecl *ND) const {
661 7: return isa<EnumDecl>(ND);
662 : }
663 :
664 : /// \brief Determines whether the given declaration is a class or struct.
665 23: bool ResultBuilder::IsClassOrStruct(NamedDecl *ND) const {
666 : // Allow us to find class templates, too.
1: branch 1 taken
22: branch 2 taken
667 23: if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
668 1: ND = ClassTemplate->getTemplatedDecl();
669 :
18: branch 1 taken
5: branch 2 taken
670 23: if (RecordDecl *RD = dyn_cast<RecordDecl>(ND))
671 : return RD->getTagKind() == TagDecl::TK_class ||
12: branch 1 taken
6: branch 2 taken
12: branch 4 taken
0: branch 5 not taken
672 18: RD->getTagKind() == TagDecl::TK_struct;
673 :
674 5: return false;
675 : }
676 :
677 : /// \brief Determines whether the given declaration is a union.
678 0: bool ResultBuilder::IsUnion(NamedDecl *ND) const {
679 : // Allow us to find class templates, too.
0: branch 1 not taken
0: branch 2 not taken
680 0: if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
681 0: ND = ClassTemplate->getTemplatedDecl();
682 :
0: branch 1 not taken
0: branch 2 not taken
683 0: if (RecordDecl *RD = dyn_cast<RecordDecl>(ND))
684 0: return RD->getTagKind() == TagDecl::TK_union;
685 :
686 0: return false;
687 : }
688 :
689 : /// \brief Determines whether the given declaration is a namespace.
690 2: bool ResultBuilder::IsNamespace(NamedDecl *ND) const {
691 2: return isa<NamespaceDecl>(ND);
692 : }
693 :
694 : /// \brief Determines whether the given declaration is a namespace or
695 : /// namespace alias.
696 21: bool ResultBuilder::IsNamespaceOrAlias(NamedDecl *ND) const {
7: branch 1 taken
14: branch 2 taken
2: branch 4 taken
5: branch 5 taken
697 21: return isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND);
698 : }
699 :
700 : /// \brief Determines whether the given declaration is a type.
701 9: bool ResultBuilder::IsType(NamedDecl *ND) const {
702 9: return isa<TypeDecl>(ND);
703 : }
704 :
705 : /// \brief Determines which members of a class should be visible via
706 : /// "." or "->". Only value declarations, nested name specifiers, and
707 : /// using declarations thereof should show up.
708 66: bool ResultBuilder::IsMember(NamedDecl *ND) const {
0: branch 1 not taken
66: branch 2 taken
709 66: if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(ND))
710 0: ND = Using->getTargetDecl();
711 :
712 : return isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND) ||
14: branch 1 taken
52: branch 2 taken
13: branch 4 taken
1: branch 5 taken
2: branch 7 taken
11: branch 8 taken
713 66: isa<ObjCPropertyDecl>(ND);
714 : }
715 :
716 : /// \rief Determines whether the given declaration is an Objective-C
717 : /// instance variable.
718 2: bool ResultBuilder::IsObjCIvar(NamedDecl *ND) const {
719 2: return isa<ObjCIvarDecl>(ND);
720 : }
721 :
722 : namespace {
723 : /// \brief Visible declaration consumer that adds a code-completion result
724 : /// for each visible declaration.
0: branch 1 not taken
0: branch 2 not taken
0: branch 5 not taken
33: branch 6 taken
725 33: class CodeCompletionDeclConsumer : public VisibleDeclConsumer {
726 : ResultBuilder &Results;
727 : DeclContext *CurContext;
728 :
729 : public:
730 33: CodeCompletionDeclConsumer(ResultBuilder &Results, DeclContext *CurContext)
731 33: : Results(Results), CurContext(CurContext) { }
732 :
733 305: virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, bool InBaseClass) {
734 305: Results.AddResult(ND, CurContext, Hiding, InBaseClass);
735 305: }
736 : };
737 : }
738 :
739 : /// \brief Add type specifiers for the current language as keyword results.
740 : static void AddTypeSpecifierResults(const LangOptions &LangOpts,
741 13: ResultBuilder &Results) {
742 : typedef CodeCompleteConsumer::Result Result;
743 13: Results.AddResult(Result("short"));
744 13: Results.AddResult(Result("long"));
745 13: Results.AddResult(Result("signed"));
746 13: Results.AddResult(Result("unsigned"));
747 13: Results.AddResult(Result("void"));
748 13: Results.AddResult(Result("char"));
749 13: Results.AddResult(Result("int"));
750 13: Results.AddResult(Result("float"));
751 13: Results.AddResult(Result("double"));
752 13: Results.AddResult(Result("enum"));
753 13: Results.AddResult(Result("struct"));
754 13: Results.AddResult(Result("union"));
755 13: Results.AddResult(Result("const"));
756 13: Results.AddResult(Result("volatile"));
757 :
8: branch 0 taken
5: branch 1 taken
758 13: if (LangOpts.C99) {
759 : // C99-specific
760 8: Results.AddResult(Result("_Complex"));
761 8: Results.AddResult(Result("_Imaginary"));
762 8: Results.AddResult(Result("_Bool"));
763 8: Results.AddResult(Result("restrict"));
764 : }
765 :
5: branch 0 taken
8: branch 1 taken
766 13: if (LangOpts.CPlusPlus) {
767 : // C++-specific
768 5: Results.AddResult(Result("bool"));
769 5: Results.AddResult(Result("class"));
770 5: Results.AddResult(Result("wchar_t"));
771 :
772 : // typename qualified-id
773 5: CodeCompletionString *Pattern = new CodeCompletionString;
774 5: Pattern->AddTypedTextChunk("typename");
775 5: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
776 5: Pattern->AddPlaceholderChunk("qualified-id");
777 5: Results.AddResult(Result(Pattern));
778 :
0: branch 0 not taken
5: branch 1 taken
779 5: if (LangOpts.CPlusPlus0x) {
780 0: Results.AddResult(Result("auto"));
781 0: Results.AddResult(Result("char16_t"));
782 0: Results.AddResult(Result("char32_t"));
783 0: Results.AddResult(Result("decltype"));
784 : }
785 : }
786 :
787 : // GNU extensions
13: branch 0 taken
0: branch 1 not taken
788 13: if (LangOpts.GNUMode) {
789 : // FIXME: Enable when we actually support decimal floating point.
790 : // Results.AddResult(Result("_Decimal32"));
791 : // Results.AddResult(Result("_Decimal64"));
792 : // Results.AddResult(Result("_Decimal128"));
793 :
794 13: CodeCompletionString *Pattern = new CodeCompletionString;
795 13: Pattern->AddTypedTextChunk("typeof");
796 13: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
797 13: Pattern->AddPlaceholderChunk("expression-or-type");
798 13: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
799 13: Results.AddResult(Result(Pattern));
800 : }
801 13: }
802 :
803 : static void AddStorageSpecifiers(Action::CodeCompletionContext CCC,
804 : const LangOptions &LangOpts,
805 9: ResultBuilder &Results) {
806 : typedef CodeCompleteConsumer::Result Result;
807 : // Note: we don't suggest either "auto" or "register", because both
808 : // are pointless as storage specifiers. Elsewhere, we suggest "auto"
809 : // in C++0x as a type specifier.
810 9: Results.AddResult(Result("extern"));
811 9: Results.AddResult(Result("static"));
812 9: }
813 :
814 : static void AddFunctionSpecifiers(Action::CodeCompletionContext CCC,
815 : const LangOptions &LangOpts,
816 4: ResultBuilder &Results) {
817 : typedef CodeCompleteConsumer::Result Result;
1: branch 0 taken
3: branch 1 taken
0: branch 2 not taken
818 4: switch (CCC) {
819 : case Action::CCC_Class:
820 : case Action::CCC_MemberTemplate:
1: branch 0 taken
0: branch 1 not taken
821 1: if (LangOpts.CPlusPlus) {
822 1: Results.AddResult(Result("explicit"));
823 1: Results.AddResult(Result("friend"));
824 1: Results.AddResult(Result("mutable"));
825 1: Results.AddResult(Result("virtual"));
826 : }
827 : // Fall through
828 :
829 : case Action::CCC_ObjCInterface:
830 : case Action::CCC_ObjCImplementation:
831 : case Action::CCC_Namespace:
832 : case Action::CCC_Template:
2: branch 0 taken
2: branch 1 taken
2: branch 2 taken
0: branch 3 not taken
833 4: if (LangOpts.CPlusPlus || LangOpts.C99)
834 4: Results.AddResult(Result("inline"));
835 : break;
836 :
837 : case Action::CCC_ObjCInstanceVariableList:
838 : case Action::CCC_Expression:
839 : case Action::CCC_Statement:
840 : case Action::CCC_ForInit:
841 : case Action::CCC_Condition:
842 : break;
843 : }
844 4: }
845 :
846 : static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt);
847 : static void AddObjCStatementResults(ResultBuilder &Results, bool NeedAt);
848 : static void AddObjCVisibilityResults(const LangOptions &LangOpts,
849 : ResultBuilder &Results,
850 : bool NeedAt);
851 : static void AddObjCImplementationResults(const LangOptions &LangOpts,
852 : ResultBuilder &Results,
853 : bool NeedAt);
854 : static void AddObjCInterfaceResults(const LangOptions &LangOpts,
855 : ResultBuilder &Results,
856 : bool NeedAt);
857 : static void AddObjCTopLevelResults(ResultBuilder &Results, bool NeedAt);
858 :
859 : /// \brief Add language constructs that show up for "ordinary" names.
860 : static void AddOrdinaryNameResults(Action::CodeCompletionContext CCC,
861 : Scope *S,
862 : Sema &SemaRef,
863 12: ResultBuilder &Results) {
864 : typedef CodeCompleteConsumer::Result Result;
2: branch 0 taken
1: branch 1 taken
0: branch 2 not taken
1: branch 3 taken
0: branch 4 not taken
1: branch 5 taken
5: branch 6 taken
0: branch 7 not taken
2: branch 8 taken
0: branch 9 not taken
865 12: switch (CCC) {
866 : case Action::CCC_Namespace:
1: branch 1 taken
1: branch 2 taken
867 2: if (SemaRef.getLangOptions().CPlusPlus) {
868 : // namespace <identifier> { }
869 1: CodeCompletionString *Pattern = new CodeCompletionString;
870 1: Pattern->AddTypedTextChunk("namespace");
871 1: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
872 1: Pattern->AddPlaceholderChunk("identifier");
873 1: Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
874 1: Pattern->AddPlaceholderChunk("declarations");
875 1: Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
876 1: Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
877 1: Results.AddResult(Result(Pattern));
878 :
879 : // namespace identifier = identifier ;
880 1: Pattern = new CodeCompletionString;
881 1: Pattern->AddTypedTextChunk("namespace");
882 1: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
883 1: Pattern->AddPlaceholderChunk("identifier");
884 1: Pattern->AddChunk(CodeCompletionString::CK_Equal);
885 1: Pattern->AddPlaceholderChunk("identifier");
886 1: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
887 1: Results.AddResult(Result(Pattern));
888 :
889 : // Using directives
890 1: Pattern = new CodeCompletionString;
891 1: Pattern->AddTypedTextChunk("using");
892 1: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
893 1: Pattern->AddTextChunk("namespace");
894 1: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
895 1: Pattern->AddPlaceholderChunk("identifier");
896 1: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
897 1: Results.AddResult(Result(Pattern));
898 :
899 : // asm(string-literal)
900 1: Pattern = new CodeCompletionString;
901 1: Pattern->AddTypedTextChunk("asm");
902 1: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
903 1: Pattern->AddPlaceholderChunk("string-literal");
904 1: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
905 1: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
906 1: Results.AddResult(Result(Pattern));
907 :
908 : // Explicit template instantiation
909 1: Pattern = new CodeCompletionString;
910 1: Pattern->AddTypedTextChunk("template");
911 1: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
912 1: Pattern->AddPlaceholderChunk("declaration");
913 1: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
914 1: Results.AddResult(Result(Pattern));
915 : }
916 :
1: branch 1 taken
1: branch 2 taken
917 2: if (SemaRef.getLangOptions().ObjC1)
918 1: AddObjCTopLevelResults(Results, true);
919 :
920 : // Fall through
921 :
922 : case Action::CCC_Class:
923 3: Results.AddResult(Result("typedef"));
2: branch 1 taken
1: branch 2 taken
924 3: if (SemaRef.getLangOptions().CPlusPlus) {
925 : // Using declaration
926 2: CodeCompletionString *Pattern = new CodeCompletionString;
927 2: Pattern->AddTypedTextChunk("using");
928 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
929 2: Pattern->AddPlaceholderChunk("qualified-id");
930 2: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
931 2: Results.AddResult(Result(Pattern));
932 :
933 : // using typename qualified-id; (only in a dependent context)
0: branch 1 not taken
2: branch 2 taken
934 2: if (SemaRef.CurContext->isDependentContext()) {
935 0: Pattern = new CodeCompletionString;
936 0: Pattern->AddTypedTextChunk("using");
937 0: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
938 0: Pattern->AddTextChunk("typename");
939 0: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
940 0: Pattern->AddPlaceholderChunk("qualified-id");
941 0: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
942 0: Results.AddResult(Result(Pattern));
943 : }
944 :
1: branch 0 taken
1: branch 1 taken
945 2: if (CCC == Action::CCC_Class) {
946 : // public:
947 1: Pattern = new CodeCompletionString;
948 1: Pattern->AddTypedTextChunk("public");
949 1: Pattern->AddChunk(CodeCompletionString::CK_Colon);
950 1: Results.AddResult(Result(Pattern));
951 :
952 : // protected:
953 1: Pattern = new CodeCompletionString;
954 1: Pattern->AddTypedTextChunk("protected");
955 1: Pattern->AddChunk(CodeCompletionString::CK_Colon);
956 1: Results.AddResult(Result(Pattern));
957 :
958 : // private:
959 1: Pattern = new CodeCompletionString;
960 1: Pattern->AddTypedTextChunk("private");
961 1: Pattern->AddChunk(CodeCompletionString::CK_Colon);
962 1: Results.AddResult(Result(Pattern));
963 : }
964 : }
965 : // Fall through
966 :
967 : case Action::CCC_Template:
968 : case Action::CCC_MemberTemplate:
2: branch 1 taken
1: branch 2 taken
969 3: if (SemaRef.getLangOptions().CPlusPlus) {
970 : // template < parameters >
971 2: CodeCompletionString *Pattern = new CodeCompletionString;
972 2: Pattern->AddTypedTextChunk("template");
973 2: Pattern->AddChunk(CodeCompletionString::CK_LeftAngle);
974 2: Pattern->AddPlaceholderChunk("parameters");
975 2: Pattern->AddChunk(CodeCompletionString::CK_RightAngle);
976 2: Results.AddResult(Result(Pattern));
977 : }
978 :
979 3: AddStorageSpecifiers(CCC, SemaRef.getLangOptions(), Results);
980 3: AddFunctionSpecifiers(CCC, SemaRef.getLangOptions(), Results);
981 3: break;
982 :
983 : case Action::CCC_ObjCInterface:
984 1: AddObjCInterfaceResults(SemaRef.getLangOptions(), Results, true);
985 1: AddStorageSpecifiers(CCC, SemaRef.getLangOptions(), Results);
986 1: AddFunctionSpecifiers(CCC, SemaRef.getLangOptions(), Results);
987 1: break;
988 :
989 : case Action::CCC_ObjCImplementation:
990 0: AddObjCImplementationResults(SemaRef.getLangOptions(), Results, true);
991 0: AddStorageSpecifiers(CCC, SemaRef.getLangOptions(), Results);
992 0: AddFunctionSpecifiers(CCC, SemaRef.getLangOptions(), Results);
993 0: break;
994 :
995 : case Action::CCC_ObjCInstanceVariableList:
996 1: AddObjCVisibilityResults(SemaRef.getLangOptions(), Results, true);
997 1: break;
998 :
999 : case Action::CCC_Statement: {
1000 5: Results.AddResult(Result("typedef"));
1001 :
1002 5: CodeCompletionString *Pattern = 0;
1: branch 1 taken
4: branch 2 taken
1003 5: if (SemaRef.getLangOptions().CPlusPlus) {
1004 1: Pattern = new CodeCompletionString;
1005 1: Pattern->AddTypedTextChunk("try");
1006 1: Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
1007 1: Pattern->AddPlaceholderChunk("statements");
1008 1: Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
1009 1: Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
1010 1: Pattern->AddTextChunk("catch");
1011 1: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1012 1: Pattern->AddPlaceholderChunk("declaration");
1013 1: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1014 1: Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
1015 1: Pattern->AddPlaceholderChunk("statements");
1016 1: Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
1017 1: Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
1018 1: Results.AddResult(Result(Pattern));
1019 : }
1: branch 1 taken
4: branch 2 taken
1020 5: if (SemaRef.getLangOptions().ObjC1)
1021 1: AddObjCStatementResults(Results, true);
1022 :
1023 : // if (condition) { statements }
1024 5: Pattern = new CodeCompletionString;
1025 5: Pattern->AddTypedTextChunk("if");
1026 5: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1: branch 1 taken
4: branch 2 taken
1027 5: if (SemaRef.getLangOptions().CPlusPlus)
1028 1: Pattern->AddPlaceholderChunk("condition");
1029 : else
1030 4: Pattern->AddPlaceholderChunk("expression");
1031 5: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1032 5: Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
1033 5: Pattern->AddPlaceholderChunk("statements");
1034 5: Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
1035 5: Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
1036 5: Results.AddResult(Result(Pattern));
1037 :
1038 : // switch (condition) { }
1039 5: Pattern = new CodeCompletionString;
1040 5: Pattern->AddTypedTextChunk("switch");
1041 5: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1: branch 1 taken
4: branch 2 taken
1042 5: if (SemaRef.getLangOptions().CPlusPlus)
1043 1: Pattern->AddPlaceholderChunk("condition");
1044 : else
1045 4: Pattern->AddPlaceholderChunk("expression");
1046 5: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1047 5: Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
1048 5: Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
1049 5: Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
1050 5: Results.AddResult(Result(Pattern));
1051 :
1052 : // Switch-specific statements.
0: branch 2 not taken
5: branch 3 taken
1053 5: if (!SemaRef.getSwitchStack().empty()) {
1054 : // case expression:
1055 0: Pattern = new CodeCompletionString;
1056 0: Pattern->AddTypedTextChunk("case");
1057 0: Pattern->AddPlaceholderChunk("expression");
1058 0: Pattern->AddChunk(CodeCompletionString::CK_Colon);
1059 0: Results.AddResult(Result(Pattern));
1060 :
1061 : // default:
1062 0: Pattern = new CodeCompletionString;
1063 0: Pattern->AddTypedTextChunk("default");
1064 0: Pattern->AddChunk(CodeCompletionString::CK_Colon);
1065 0: Results.AddResult(Result(Pattern));
1066 : }
1067 :
1068 : /// while (condition) { statements }
1069 5: Pattern = new CodeCompletionString;
1070 5: Pattern->AddTypedTextChunk("while");
1071 5: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1: branch 1 taken
4: branch 2 taken
1072 5: if (SemaRef.getLangOptions().CPlusPlus)
1073 1: Pattern->AddPlaceholderChunk("condition");
1074 : else
1075 4: Pattern->AddPlaceholderChunk("expression");
1076 5: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1077 5: Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
1078 5: Pattern->AddPlaceholderChunk("statements");
1079 5: Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
1080 5: Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
1081 5: Results.AddResult(Result(Pattern));
1082 :
1083 : // do { statements } while ( expression );
1084 5: Pattern = new CodeCompletionString;
1085 5: Pattern->AddTypedTextChunk("do");
1086 5: Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
1087 5: Pattern->AddPlaceholderChunk("statements");
1088 5: Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
1089 5: Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
1090 5: Pattern->AddTextChunk("while");
1091 5: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1092 5: Pattern->AddPlaceholderChunk("expression");
1093 5: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1094 5: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
1095 5: Results.AddResult(Result(Pattern));
1096 :
1097 : // for ( for-init-statement ; condition ; expression ) { statements }
1098 5: Pattern = new CodeCompletionString;
1099 5: Pattern->AddTypedTextChunk("for");
1100 5: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
4: branch 1 taken
1: branch 2 taken
4: branch 4 taken
0: branch 5 not taken
5: branch 6 taken
0: branch 7 not taken
1101 5: if (SemaRef.getLangOptions().CPlusPlus || SemaRef.getLangOptions().C99)
1102 5: Pattern->AddPlaceholderChunk("init-statement");
1103 : else
1104 0: Pattern->AddPlaceholderChunk("init-expression");
1105 5: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
1106 5: Pattern->AddPlaceholderChunk("condition");
1107 5: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
1108 5: Pattern->AddPlaceholderChunk("inc-expression");
1109 5: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1110 5: Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
1111 5: Pattern->AddPlaceholderChunk("statements");
1112 5: Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
1113 5: Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
1114 5: Results.AddResult(Result(Pattern));
1115 :
0: branch 1 not taken
5: branch 2 taken
1116 5: if (S->getContinueParent()) {
1117 : // continue ;
1118 0: Pattern = new CodeCompletionString;
1119 0: Pattern->AddTypedTextChunk("continue");
1120 0: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
1121 0: Results.AddResult(Result(Pattern));
1122 : }
1123 :
0: branch 1 not taken
5: branch 2 taken
1124 5: if (S->getBreakParent()) {
1125 : // break ;
1126 0: Pattern = new CodeCompletionString;
1127 0: Pattern->AddTypedTextChunk("break");
1128 0: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
1129 0: Results.AddResult(Result(Pattern));
1130 : }
1131 :
1132 : // "return expression ;" or "return ;", depending on whether we
1133 : // know the function is void or not.
1134 5: bool isVoid = false;
4: branch 1 taken
1: branch 2 taken
1135 5: if (FunctionDecl *Function = dyn_cast<FunctionDecl>(SemaRef.CurContext))
1136 4: isVoid = Function->getResultType()->isVoidType();
1: branch 0 taken
0: branch 1 not taken
1137 1: else if (ObjCMethodDecl *Method
1138 1: = dyn_cast<ObjCMethodDecl>(SemaRef.CurContext))
1139 1: isVoid = Method->getResultType()->isVoidType();
0: branch 0 not taken
0: branch 1 not taken
0: branch 3 not taken
0: branch 4 not taken
0: branch 5 not taken
0: branch 6 not taken
1140 0: else if (SemaRef.CurBlock && !SemaRef.CurBlock->ReturnType.isNull())
1141 0: isVoid = SemaRef.CurBlock->ReturnType->isVoidType();
1142 5: Pattern = new CodeCompletionString;
1143 5: Pattern->AddTypedTextChunk("return");
1: branch 0 taken
4: branch 1 taken
1144 5: if (!isVoid)
1145 1: Pattern->AddPlaceholderChunk("expression");
1146 5: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
1147 5: Results.AddResult(Result(Pattern));
1148 :
1149 : // goto identifier ;
1150 5: Pattern = new CodeCompletionString;
1151 5: Pattern->AddTypedTextChunk("goto");
1152 5: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
1153 5: Pattern->AddPlaceholderChunk("identifier");
1154 5: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
1155 5: Results.AddResult(Result(Pattern));
1156 :
1157 : // Using directives
1158 5: Pattern = new CodeCompletionString;
1159 5: Pattern->AddTypedTextChunk("using");
1160 5: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
1161 5: Pattern->AddTextChunk("namespace");
1162 5: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
1163 5: Pattern->AddPlaceholderChunk("identifier");
1164 5: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
1165 5: Results.AddResult(Result(Pattern));
1166 : }
1167 :
1168 : // Fall through (for statement expressions).
1169 : case Action::CCC_ForInit:
1170 : case Action::CCC_Condition:
1171 5: AddStorageSpecifiers(CCC, SemaRef.getLangOptions(), Results);
1172 : // Fall through: conditions and statements can have expressions.
1173 :
1174 : case Action::CCC_Expression: {
1175 7: CodeCompletionString *Pattern = 0;
2: branch 1 taken
5: branch 2 taken
1176 7: if (SemaRef.getLangOptions().CPlusPlus) {
1177 : // 'this', if we're in a non-static member function.
0: branch 1 not taken
2: branch 2 taken
1178 2: if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(SemaRef.CurContext))
0: branch 1 not taken
0: branch 2 not taken
1179 0: if (!Method->isStatic())
1180 0: Results.AddResult(Result("this"));
1181 :
1182 : // true, false
1183 2: Results.AddResult(Result("true"));
1184 2: Results.AddResult(Result("false"));
1185 :
1186 : // dynamic_cast < type-id > ( expression )
1187 2: Pattern = new CodeCompletionString;
1188 2: Pattern->AddTypedTextChunk("dynamic_cast");
1189 2: Pattern->AddChunk(CodeCompletionString::CK_LeftAngle);
1190 2: Pattern->AddPlaceholderChunk("type-id");
1191 2: Pattern->AddChunk(CodeCompletionString::CK_RightAngle);
1192 2: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1193 2: Pattern->AddPlaceholderChunk("expression");
1194 2: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1195 2: Results.AddResult(Result(Pattern));
1196 :
1197 : // static_cast < type-id > ( expression )
1198 2: Pattern = new CodeCompletionString;
1199 2: Pattern->AddTypedTextChunk("static_cast");
1200 2: Pattern->AddChunk(CodeCompletionString::CK_LeftAngle);
1201 2: Pattern->AddPlaceholderChunk("type-id");
1202 2: Pattern->AddChunk(CodeCompletionString::CK_RightAngle);
1203 2: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1204 2: Pattern->AddPlaceholderChunk("expression");
1205 2: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1206 2: Results.AddResult(Result(Pattern));
1207 :
1208 : // reinterpret_cast < type-id > ( expression )
1209 2: Pattern = new CodeCompletionString;
1210 2: Pattern->AddTypedTextChunk("reinterpret_cast");
1211 2: Pattern->AddChunk(CodeCompletionString::CK_LeftAngle);
1212 2: Pattern->AddPlaceholderChunk("type-id");
1213 2: Pattern->AddChunk(CodeCompletionString::CK_RightAngle);
1214 2: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1215 2: Pattern->AddPlaceholderChunk("expression");
1216 2: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1217 2: Results.AddResult(Result(Pattern));
1218 :
1219 : // const_cast < type-id > ( expression )
1220 2: Pattern = new CodeCompletionString;
1221 2: Pattern->AddTypedTextChunk("const_cast");
1222 2: Pattern->AddChunk(CodeCompletionString::CK_LeftAngle);
1223 2: Pattern->AddPlaceholderChunk("type-id");
1224 2: Pattern->AddChunk(CodeCompletionString::CK_RightAngle);
1225 2: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1226 2: Pattern->AddPlaceholderChunk("expression");
1227 2: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1228 2: Results.AddResult(Result(Pattern));
1229 :
1230 : // typeid ( expression-or-type )
1231 2: Pattern = new CodeCompletionString;
1232 2: Pattern->AddTypedTextChunk("typeid");
1233 2: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1234 2: Pattern->AddPlaceholderChunk("expression-or-type");
1235 2: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1236 2: Results.AddResult(Result(Pattern));
1237 :
1238 : // new T ( ... )
1239 2: Pattern = new CodeCompletionString;
1240 2: Pattern->AddTypedTextChunk("new");
1241 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
1242 2: Pattern->AddPlaceholderChunk("type-id");
1243 2: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1244 2: Pattern->AddPlaceholderChunk("expressions");
1245 2: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1246 2: Results.AddResult(Result(Pattern));
1247 :
1248 : // new T [ ] ( ... )
1249 2: Pattern = new CodeCompletionString;
1250 2: Pattern->AddTypedTextChunk("new");
1251 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
1252 2: Pattern->AddPlaceholderChunk("type-id");
1253 2: Pattern->AddChunk(CodeCompletionString::CK_LeftBracket);
1254 2: Pattern->AddPlaceholderChunk("size");
1255 2: Pattern->AddChunk(CodeCompletionString::CK_RightBracket);
1256 2: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1257 2: Pattern->AddPlaceholderChunk("expressions");
1258 2: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1259 2: Results.AddResult(Result(Pattern));
1260 :
1261 : // delete expression
1262 2: Pattern = new CodeCompletionString;
1263 2: Pattern->AddTypedTextChunk("delete");
1264 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
1265 2: Pattern->AddPlaceholderChunk("expression");
1266 2: Results.AddResult(Result(Pattern));
1267 :
1268 : // delete [] expression
1269 2: Pattern = new CodeCompletionString;
1270 2: Pattern->AddTypedTextChunk("delete");
1271 2: Pattern->AddChunk(CodeCompletionString::CK_LeftBracket);
1272 2: Pattern->AddChunk(CodeCompletionString::CK_RightBracket);
1273 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
1274 2: Pattern->AddPlaceholderChunk("expression");
1275 2: Results.AddResult(Result(Pattern));
1276 :
1277 : // throw expression
1278 2: Pattern = new CodeCompletionString;
1279 2: Pattern->AddTypedTextChunk("throw");
1280 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
1281 2: Pattern->AddPlaceholderChunk("expression");
1282 2: Results.AddResult(Result(Pattern));
1283 : }
1284 :
2: branch 1 taken
5: branch 2 taken
1285 7: if (SemaRef.getLangOptions().ObjC1) {
1286 : // Add "super", if we're in an Objective-C class with a superclass.
2: branch 1 taken
0: branch 2 not taken
1287 2: if (ObjCMethodDecl *Method = SemaRef.getCurMethodDecl())
1: branch 2 taken
1: branch 3 taken
1288 2: if (Method->getClassInterface()->getSuperClass())
1289 1: Results.AddResult(Result("super"));
1290 :
1291 2: AddObjCExpressionResults(Results, true);
1292 : }
1293 :
1294 : // sizeof expression
1295 7: Pattern = new CodeCompletionString;
1296 7: Pattern->AddTypedTextChunk("sizeof");
1297 7: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
1298 7: Pattern->AddPlaceholderChunk("expression-or-type");
1299 7: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
1300 7: Results.AddResult(Result(Pattern));
1301 : break;
1302 : }
1303 : }
1304 :
1305 12: AddTypeSpecifierResults(SemaRef.getLangOptions(), Results);
1306 :
4: branch 1 taken
8: branch 2 taken
1307 12: if (SemaRef.getLangOptions().CPlusPlus)
1308 4: Results.AddResult(Result("operator"));
1309 12: }
1310 :
1311 : /// \brief If the given declaration has an associated type, add it as a result
1312 : /// type chunk.
1313 : static void AddResultTypeChunk(ASTContext &Context,
1314 : NamedDecl *ND,
1315 290: CodeCompletionString *Result) {
0: branch 0 not taken
290: branch 1 taken
1316 290: if (!ND)
1317 0: return;
1318 :
1319 : // Determine the type of the declaration (if it has a type).
1320 290: QualType T;
52: branch 1 taken
238: branch 2 taken
1321 290: if (FunctionDecl *Function = dyn_cast<FunctionDecl>(ND))
1322 52: T = Function->getResultType();
52: branch 1 taken
186: branch 2 taken
1323 238: else if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND))
1324 52: T = Method->getResultType();
3: branch 1 taken
183: branch 2 taken
1325 186: else if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(ND))
1326 3: T = FunTmpl->getTemplatedDecl()->getResultType();
24: branch 1 taken
159: branch 2 taken
1327 183: else if (EnumConstantDecl *Enumerator = dyn_cast<EnumConstantDecl>(ND))
1328 24: T = Context.getTypeDeclType(cast<TypeDecl>(Enumerator->getDeclContext()));
159: branch 1 taken
0: branch 2 not taken
1329 159: else if (isa<UnresolvedUsingValueDecl>(ND)) {
1330 : /* Do nothing: ignore unresolved using declarations*/
36: branch 1 taken
123: branch 2 taken
1331 159: } else if (ValueDecl *Value = dyn_cast<ValueDecl>(ND))
1332 36: T = Value->getType();
13: branch 1 taken
110: branch 2 taken
1333 123: else if (ObjCPropertyDecl *Property = dyn_cast<ObjCPropertyDecl>(ND))
1334 13: T = Property->getType();
1335 :
180: branch 1 taken
110: branch 2 taken
0: branch 5 not taken
180: branch 6 taken
110: branch 7 taken
180: branch 8 taken
1336 290: if (T.isNull() || Context.hasSameType(T, Context.DependentTy))
1337 110: return;
1338 :
1339 180: std::string TypeStr;
1340 180: T.getAsStringInternal(TypeStr, Context.PrintingPolicy);
1341 180: Result->AddResultTypeChunk(TypeStr);
1342 : }
1343 :
1344 : /// \brief Add function parameter chunks to the given code completion string.
1345 : static void AddFunctionParameterChunks(ASTContext &Context,
1346 : FunctionDecl *Function,
1347 45: CodeCompletionString *Result) {
1348 : typedef CodeCompletionString::Chunk Chunk;
1349 :
1350 45: CodeCompletionString *CCStr = Result;
1351 :
28: branch 2 taken
45: branch 3 taken
1352 73: for (unsigned P = 0, N = Function->getNumParams(); P != N; ++P) {
1353 28: ParmVarDecl *Param = Function->getParamDecl(P);
1354 :
3: branch 1 taken
25: branch 2 taken
1355 28: if (Param->hasDefaultArg()) {
1356 : // When we see an optional default argument, put that argument and
1357 : // the remaining default arguments into a new, optional string.
1358 3: CodeCompletionString *Opt = new CodeCompletionString;
1359 3: CCStr->AddOptionalChunk(std::auto_ptr<CodeCompletionString>(Opt));
1360 3: CCStr = Opt;
1361 : }
1362 :
5: branch 0 taken
23: branch 1 taken
1363 28: if (P != 0)
1364 5: CCStr->AddChunk(Chunk(CodeCompletionString::CK_Comma));
1365 :
1366 : // Format the placeholder string.
1367 28: std::string PlaceholderStr;
11: branch 1 taken
17: branch 2 taken
1368 28: if (Param->getIdentifier())
1369 11: PlaceholderStr = Param->getIdentifier()->getName();
1370 :
1371 : Param->getType().getAsStringInternal(PlaceholderStr,
1372 28: Context.PrintingPolicy);
1373 :
1374 : // Add the placeholder string.
1375 28: CCStr->AddPlaceholderChunk(PlaceholderStr);
1376 : }
1377 :
41: branch 0 taken
4: branch 1 taken
1378 45: if (const FunctionProtoType *Proto
1379 45: = Function->getType()->getAs<FunctionProtoType>())
1: branch 1 taken
40: branch 2 taken
1380 41: if (Proto->isVariadic())
1381 1: CCStr->AddPlaceholderChunk(", ...");
1382 45: }
1383 :
1384 : /// \brief Add template parameter chunks to the given code completion string.
1385 : static void AddTemplateParameterChunks(ASTContext &Context,
1386 : TemplateDecl *Template,
1387 : CodeCompletionString *Result,
1388 5: unsigned MaxParameters = 0) {
1389 : typedef CodeCompletionString::Chunk Chunk;
1390 :
1391 5: CodeCompletionString *CCStr = Result;
1392 5: bool FirstParameter = true;
1393 :
1394 5: TemplateParameterList *Params = Template->getTemplateParameters();
1395 5: TemplateParameterList::iterator PEnd = Params->end();
2: branch 0 taken
3: branch 1 taken
1396 5: if (MaxParameters)
1397 2: PEnd = Params->begin() + MaxParameters;
6: branch 2 taken
5: branch 3 taken
1398 11: for (TemplateParameterList::iterator P = Params->begin(); P != PEnd; ++P) {
1399 6: bool HasDefaultArg = false;
1400 6: std::string PlaceholderStr;
6: branch 1 taken
0: branch 2 not taken
1401 6: if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) {
5: branch 1 taken
1: branch 2 taken
1402 6: if (TTP->wasDeclaredWithTypename())
1403 5: PlaceholderStr = "typename";
1404 : else
1405 1: PlaceholderStr = "class";
1406 :
5: branch 1 taken
1: branch 2 taken
1407 6: if (TTP->getIdentifier()) {
1408 5: PlaceholderStr += ' ';
1409 5: PlaceholderStr += TTP->getIdentifier()->getName();
1410 : }
1411 :
1412 6: HasDefaultArg = TTP->hasDefaultArgument();
0: branch 0 not taken
0: branch 1 not taken
1413 0: } else if (NonTypeTemplateParmDecl *NTTP
1414 0: = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
0: branch 1 not taken
0: branch 2 not taken
1415 0: if (NTTP->getIdentifier())
1416 0: PlaceholderStr = NTTP->getIdentifier()->getName();
1417 : NTTP->getType().getAsStringInternal(PlaceholderStr,
1418 0: Context.PrintingPolicy);
1419 0: HasDefaultArg = NTTP->hasDefaultArgument();
1420 : } else {
0: branch 1 not taken
0: branch 2 not taken
1421 0: assert(isa<TemplateTemplateParmDecl>(*P));
1422 0: TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*P);
1423 :
1424 : // Since putting the template argument list into the placeholder would
1425 : // be very, very long, we just use an abbreviation.
1426 0: PlaceholderStr = "template<...> class";
0: branch 1 not taken
0: branch 2 not taken
1427 0: if (TTP->getIdentifier()) {
1428 0: PlaceholderStr += ' ';
1429 0: PlaceholderStr += TTP->getIdentifier()->getName();
1430 : }
1431 :
1432 0: HasDefaultArg = TTP->hasDefaultArgument();
1433 : }
1434 :
1: branch 0 taken
5: branch 1 taken
1435 6: if (HasDefaultArg) {
1436 : // When we see an optional default argument, put that argument and
1437 : // the remaining default arguments into a new, optional string.
1438 1: CodeCompletionString *Opt = new CodeCompletionString;
1439 1: CCStr->AddOptionalChunk(std::auto_ptr<CodeCompletionString>(Opt));
1440 1: CCStr = Opt;
1441 : }
1442 :
5: branch 0 taken
1: branch 1 taken
1443 6: if (FirstParameter)
1444 5: FirstParameter = false;
1445 : else
1446 1: CCStr->AddChunk(Chunk(CodeCompletionString::CK_Comma));
1447 :
1448 : // Add the placeholder string.
1449 6: CCStr->AddPlaceholderChunk(PlaceholderStr);
1450 : }
1451 5: }
1452 :
1453 : /// \brief Add a qualifier to the given code-completion string, if the
1454 : /// provided nested-name-specifier is non-NULL.
1455 : static void
1456 : AddQualifierToCompletionString(CodeCompletionString *Result,
1457 : NestedNameSpecifier *Qualifier,
1458 : bool QualifierIsInformative,
1459 67: ASTContext &Context) {
30: branch 0 taken
37: branch 1 taken
1460 67: if (!Qualifier)
1461 30: return;
1462 :
1463 37: std::string PrintedNNS;
1464 : {
1465 37: llvm::raw_string_ostream OS(PrintedNNS);
1466 37: Qualifier->print(OS, Context.PrintingPolicy);
1467 : }
16: branch 0 taken
21: branch 1 taken
1468 37: if (QualifierIsInformative)
1469 16: Result->AddInformativeChunk(PrintedNNS);
1470 : else
1471 21: Result->AddTextChunk(PrintedNNS);
1472 : }
1473 :
1474 : static void AddFunctionTypeQualsToCompletionString(CodeCompletionString *Result,
1475 45: FunctionDecl *Function) {
1476 : const FunctionProtoType *Proto
1477 45: = Function->getType()->getAs<FunctionProtoType>();
41: branch 0 taken
4: branch 1 taken
39: branch 3 taken
2: branch 4 taken
43: branch 5 taken
2: branch 6 taken
1478 45: if (!Proto || !Proto->getTypeQuals())
1479 43: return;
1480 :
1481 2: std::string QualsStr;
2: branch 1 taken
0: branch 2 not taken
1482 2: if (Proto->getTypeQuals() & Qualifiers::Const)
1483 2: QualsStr += " const";
0: branch 1 not taken
2: branch 2 taken
1484 2: if (Proto->getTypeQuals() & Qualifiers::Volatile)
1485 0: QualsStr += " volatile";
0: branch 1 not taken
2: branch 2 taken
1486 2: if (Proto->getTypeQuals() & Qualifiers::Restrict)
1487 0: QualsStr += " restrict";
1488 2: Result->AddInformativeChunk(QualsStr);
1489 : }
1490 :
1491 : /// \brief If possible, create a new code completion string for the given
1492 : /// result.
1493 : ///
1494 : /// \returns Either a new, heap-allocated code completion string describing
1495 : /// how to use this result, or NULL to indicate that the string or name of the
1496 : /// result is all that is needed.
1497 : CodeCompletionString *
1498 2346: CodeCompleteConsumer::Result::CreateCodeCompletionString(Sema &S) {
1499 : typedef CodeCompletionString::Chunk Chunk;
1500 :
69: branch 0 taken
2277: branch 1 taken
1501 2346: if (Kind == RK_Pattern)
1502 69: return Pattern->Clone();
1503 :
1504 2277: CodeCompletionString *Result = new CodeCompletionString;
1505 :
168: branch 0 taken
2109: branch 1 taken
1506 2277: if (Kind == RK_Keyword) {
1507 168: Result->AddTypedTextChunk(Keyword);
1508 168: return Result;
1509 : }
1510 :
1816: branch 0 taken
293: branch 1 taken
1511 2109: if (Kind == RK_Macro) {
1512 1816: MacroInfo *MI = S.PP.getMacroInfo(Macro);
0: branch 0 not taken
1816: branch 1 taken
1513 1816: assert(MI && "Not a macro?");
1514 :
1515 1816: Result->AddTypedTextChunk(Macro->getName());
1516 :
1804: branch 1 taken
12: branch 2 taken
1517 1816: if (!MI->isFunctionLike())
1518 1804: return Result;
1519 :
1520 : // Format a function-like macro with placeholders for the arguments.
1521 12: Result->AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
16: branch 2 taken
12: branch 3 taken
1522 28: for (MacroInfo::arg_iterator A = MI->arg_begin(), AEnd = MI->arg_end();
1523 : A != AEnd; ++A) {
4: branch 1 taken
12: branch 2 taken
1524 16: if (A != MI->arg_begin())
1525 4: Result->AddChunk(Chunk(CodeCompletionString::CK_Comma));
1526 :
4: branch 1 taken
12: branch 2 taken
0: branch 3 not taken
4: branch 4 taken
12: branch 5 taken
4: branch 6 taken
1527 16: if (!MI->isVariadic() || A != AEnd - 1) {
1528 : // Non-variadic argument.
1529 12: Result->AddPlaceholderChunk((*A)->getName());
1530 12: continue;
1531 : }
1532 :
1533 : // Variadic argument; cope with the different between GNU and C99
1534 : // variadic macros, providing a single placeholder for the rest of the
1535 : // arguments.
4: branch 1 taken
0: branch 2 not taken
1536 4: if ((*A)->isStr("__VA_ARGS__"))
1537 4: Result->AddPlaceholderChunk("...");
1538 : else {
1539 0: std::string Arg = (*A)->getName();
1540 0: Arg += "...";
1541 0: Result->AddPlaceholderChunk(Arg);
1542 : }
1543 : }
1544 12: Result->AddChunk(Chunk(CodeCompletionString::CK_RightParen));
1545 12: return Result;
1546 : }
1547 :
0: branch 0 not taken
293: branch 1 taken
1548 293: assert(Kind == RK_Declaration && "Missed a macro kind?");
1549 293: NamedDecl *ND = Declaration;
1550 :
13: branch 0 taken
280: branch 1 taken
1551 293: if (StartsNestedNameSpecifier) {
1552 13: Result->AddTypedTextChunk(ND->getNameAsString());
1553 13: Result->AddTextChunk("::");
1554 13: return Result;
1555 : }
1556 :
1557 280: AddResultTypeChunk(S.Context, ND, Result);
1558 :
42: branch 1 taken
238: branch 2 taken
1559 280: if (FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) {
1560 : AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
1561 42: S.Context);
1562 42: Result->AddTypedTextChunk(Function->getNameAsString());
1563 42: Result->AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
1564 42: AddFunctionParameterChunks(S.Context, Function, Result);
1565 42: Result->AddChunk(Chunk(CodeCompletionString::CK_RightParen));
1566 42: AddFunctionTypeQualsToCompletionString(Result, Function);
1567 42: return Result;
1568 : }
1569 :
3: branch 1 taken
235: branch 2 taken
1570 238: if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(ND)) {
1571 : AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
1572 3: S.Context);
1573 3: FunctionDecl *Function = FunTmpl->getTemplatedDecl();
1574 3: Result->AddTypedTextChunk(Function->getNameAsString());
1575 :
1576 : // Figure out which template parameters are deduced (or have default
1577 : // arguments).
1578 3: llvm::SmallVector<bool, 16> Deduced;
1579 3: S.MarkDeducedTemplateParameters(FunTmpl, Deduced);
1580 : unsigned LastDeducibleArgument;
4: branch 1 taken
1: branch 2 taken
1581 5: for (LastDeducibleArgument = Deduced.size(); LastDeducibleArgument > 0;
1582 : --LastDeducibleArgument) {
2: branch 1 taken
2: branch 2 taken
1583 4: if (!Deduced[LastDeducibleArgument - 1]) {
1584 : // C++0x: Figure out if the template argument has a default. If so,
1585 : // the user doesn't need to type this argument.
1586 : // FIXME: We need to abstract template parameters better!
1587 2: bool HasDefaultArg = false;
1588 : NamedDecl *Param = FunTmpl->getTemplateParameters()->getParam(
1589 2: LastDeducibleArgument - 1);
2: branch 1 taken
0: branch 2 not taken
1590 2: if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
1591 2: HasDefaultArg = TTP->hasDefaultArgument();
0: branch 0 not taken
0: branch 1 not taken
1592 0: else if (NonTypeTemplateParmDecl *NTTP
1593 0: = dyn_cast<NonTypeTemplateParmDecl>(Param))
1594 0: HasDefaultArg = NTTP->hasDefaultArgument();
1595 : else {
0: branch 1 not taken
0: branch 2 not taken
1596 0: assert(isa<TemplateTemplateParmDecl>(Param));
1597 : HasDefaultArg
1598 0: = cast<TemplateTemplateParmDecl>(Param)->hasDefaultArgument();
1599 : }
1600 :
2: branch 0 taken
0: branch 1 not taken
1601 2: if (!HasDefaultArg)
1602 2: break;
1603 : }
1604 : }
1605 :
2: branch 0 taken
1: branch 1 taken
1606 3: if (LastDeducibleArgument) {
1607 : // Some of the function template arguments cannot be deduced from a
1608 : // function call, so we introduce an explicit template argument list
1609 : // containing all of the arguments up to the first deducible argument.
1610 2: Result->AddChunk(Chunk(CodeCompletionString::CK_LeftAngle));
1611 : AddTemplateParameterChunks(S.Context, FunTmpl, Result,
1612 2: LastDeducibleArgument);
1613 2: Result->AddChunk(Chunk(CodeCompletionString::CK_RightAngle));
1614 : }
1615 :
1616 : // Add the function parameters
1617 3: Result->AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
1618 3: AddFunctionParameterChunks(S.Context, Function, Result);
1619 3: Result->AddChunk(Chunk(CodeCompletionString::CK_RightParen));
1620 3: AddFunctionTypeQualsToCompletionString(Result, Function);
1621 3: return Result;
1622 : }
1623 :
3: branch 1 taken
232: branch 2 taken
1624 235: if (TemplateDecl *Template = dyn_cast<TemplateDecl>(ND)) {
1625 : AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
1626 3: S.Context);
1627 3: Result->AddTypedTextChunk(Template->getNameAsString());
1628 3: Result->AddChunk(Chunk(CodeCompletionString::CK_LeftAngle));
1629 3: AddTemplateParameterChunks(S.Context, Template, Result);
1630 3: Result->AddChunk(Chunk(CodeCompletionString::CK_RightAngle));
1631 3: return Result;
1632 : }
1633 :
52: branch 1 taken
180: branch 2 taken
1634 232: if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND)) {
1635 52: Selector Sel = Method->getSelector();
24: branch 1 taken
28: branch 2 taken
1636 52: if (Sel.isUnarySelector()) {
1637 24: Result->AddTypedTextChunk(Sel.getIdentifierInfoForSlot(0)->getName());
1638 24: return Result;
1639 : }
1640 :
1641 28: std::string SelName = Sel.getIdentifierInfoForSlot(0)->getName().str();
1642 28: SelName += ':';
22: branch 0 taken
6: branch 1 taken
1643 28: if (StartParameter == 0)
1644 22: Result->AddTypedTextChunk(SelName);
1645 : else {
1646 6: Result->AddInformativeChunk(SelName);
1647 :
1648 : // If there is only one parameter, and we're past it, add an empty
1649 : // typed-text chunk since there is nothing to type.
1: branch 1 taken
5: branch 2 taken
1650 6: if (Method->param_size() == 1)
1651 1: Result->AddTypedTextChunk("");
1652 : }
1653 28: unsigned Idx = 0;
51: branch 2 taken
28: branch 3 taken
1654 99: for (ObjCMethodDecl::param_iterator P = Method->param_begin(),
1655 28: PEnd = Method->param_end();
1656 : P != PEnd; (void)++P, ++Idx) {
23: branch 0 taken
28: branch 1 taken
1657 51: if (Idx > 0) {
1658 23: std::string Keyword;
16: branch 0 taken
7: branch 1 taken
1659 23: if (Idx > StartParameter)
1660 16: Result->AddChunk(CodeCompletionString::CK_HorizontalSpace);
23: branch 1 taken
0: branch 2 not taken
1661 23: if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(Idx))
1662 23: Keyword += II->getName().str();
1663 23: Keyword += ":";
21: branch 0 taken
2: branch 1 taken
0: branch 2 not taken
21: branch 3 taken
1664 25: if (Idx < StartParameter || AllParametersAreInformative) {
1665 2: Result->AddInformativeChunk(Keyword);
5: branch 0 taken
16: branch 1 taken
1666 21: } else if (Idx == StartParameter)
1667 5: Result->AddTypedTextChunk(Keyword);
1668 : else
1669 16: Result->AddTextChunk(Keyword);
1670 : }
1671 :
1672 : // If we're before the starting parameter, skip the placeholder.
8: branch 0 taken
43: branch 1 taken
1673 51: if (Idx < StartParameter)
1674 8: continue;
1675 :
1676 43: std::string Arg;
1677 43: (*P)->getType().getAsStringInternal(Arg, S.Context.PrintingPolicy);
1678 43: Arg = "(" + Arg + ")";
43: branch 1 taken
0: branch 2 not taken
1679 43: if (IdentifierInfo *II = (*P)->getIdentifier())
1680 43: Arg += II->getName().str();
7: branch 0 taken
36: branch 1 taken
1681 43: if (AllParametersAreInformative)
1682 7: Result->AddInformativeChunk(Arg);
1683 : else
1684 36: Result->AddPlaceholderChunk(Arg);
1685 : }
1686 :
1: branch 1 taken
27: branch 2 taken
1687 28: if (Method->isVariadic()) {
0: branch 0 not taken
1: branch 1 taken
1688 1: if (AllParametersAreInformative)
1689 0: Result->AddInformativeChunk(", ...");
1690 : else
1691 1: Result->AddPlaceholderChunk(", ...");
1692 : }
1693 :
1694 28: return Result;
1695 : }
1696 :
19: branch 0 taken
161: branch 1 taken
1697 180: if (Qualifier)
1698 : AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
1699 19: S.Context);
1700 :
1701 180: Result->AddTypedTextChunk(ND->getNameAsString());
1702 180: return Result;
1703 : }
1704 :
1705 : CodeCompletionString *
1706 : CodeCompleteConsumer::OverloadCandidate::CreateSignatureString(
1707 : unsigned CurrentArg,
1708 10: Sema &S) const {
1709 : typedef CodeCompletionString::Chunk Chunk;
1710 :
1711 10: CodeCompletionString *Result = new CodeCompletionString;
1712 10: FunctionDecl *FDecl = getFunction();
1713 10: AddResultTypeChunk(S.Context, FDecl, Result);
1714 : const FunctionProtoType *Proto
1715 10: = dyn_cast<FunctionProtoType>(getFunctionType());
0: branch 0 not taken
10: branch 1 taken
10: branch 2 taken
10: branch 3 taken
1716 10: if (!FDecl && !Proto) {
1717 : // Function without a prototype. Just give the return type and a
1718 : // highlighted ellipsis.
1719 0: const FunctionType *FT = getFunctionType();
1720 : Result->AddTextChunk(
1721 0: FT->getResultType().getAsString(S.Context.PrintingPolicy));
1722 0: Result->AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
1723 0: Result->AddChunk(Chunk(CodeCompletionString::CK_CurrentParameter, "..."));
1724 0: Result->AddChunk(Chunk(CodeCompletionString::CK_RightParen));
1725 0: return Result;
1726 : }
1727 :
10: branch 0 taken
0: branch 1 not taken
1728 10: if (FDecl)
1729 10: Result->AddTextChunk(FDecl->getNameAsString());
1730 : else
1731 : Result->AddTextChunk(
1732 0: Proto->getResultType().getAsString(S.Context.PrintingPolicy));
1733 :
1734 10: Result->AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
10: branch 0 taken
0: branch 1 not taken
1735 10: unsigned NumParams = FDecl? FDecl->getNumParams() : Proto->getNumArgs();
20: branch 1 taken
10: branch 2 taken
1736 30: for (unsigned I = 0; I != NumParams; ++I) {
11: branch 0 taken
9: branch 1 taken
1737 20: if (I)
1738 11: Result->AddChunk(Chunk(CodeCompletionString::CK_Comma));
1739 :
1740 20: std::string ArgString;
1741 20: QualType ArgType;
1742 :
20: branch 0 taken
0: branch 1 not taken
1743 20: if (FDecl) {
1744 20: ArgString = FDecl->getParamDecl(I)->getNameAsString();
1745 20: ArgType = FDecl->getParamDecl(I)->getOriginalType();
1746 : } else {
1747 0: ArgType = Proto->getArgType(I);
1748 : }
1749 :
1750 20: ArgType.getAsStringInternal(ArgString, S.Context.PrintingPolicy);
1751 :
9: branch 0 taken
11: branch 1 taken
1752 20: if (I == CurrentArg)
1753 : Result->AddChunk(Chunk(CodeCompletionString::CK_CurrentParameter,
1754 9: ArgString));
1755 : else
1756 11: Result->AddTextChunk(ArgString);
1757 : }
1758 :
9: branch 0 taken
1: branch 1 taken
0: branch 3 not taken
9: branch 4 taken
0: branch 5 not taken
10: branch 6 taken
1759 10: if (Proto && Proto->isVariadic()) {
1760 0: Result->AddChunk(Chunk(CodeCompletionString::CK_Comma));
0: branch 0 not taken
0: branch 1 not taken
1761 0: if (CurrentArg < NumParams)
1762 0: Result->AddTextChunk("...");
1763 : else
1764 0: Result->AddChunk(Chunk(CodeCompletionString::CK_CurrentParameter, "..."));
1765 : }
1766 10: Result->AddChunk(Chunk(CodeCompletionString::CK_RightParen));
1767 :
1768 10: return Result;
1769 : }
1770 :
1771 : namespace {
1772 : struct SortCodeCompleteResult {
1773 : typedef CodeCompleteConsumer::Result Result;
1774 :
1775 : bool isEarlierDeclarationName(DeclarationName X, DeclarationName Y) const {
1776 : Selector XSel = X.getObjCSelector();
1777 : Selector YSel = Y.getObjCSelector();
1778 : if (!XSel.isNull() && !YSel.isNull()) {
1779 : // We are comparing two selectors.
1780 : unsigned N = std::min(XSel.getNumArgs(), YSel.getNumArgs());
1781 : if (N == 0)
1782 : ++N;
1783 : for (unsigned I = 0; I != N; ++I) {
1784 : IdentifierInfo *XId = XSel.getIdentifierInfoForSlot(I);
1785 : IdentifierInfo *YId = YSel.getIdentifierInfoForSlot(I);
1786 : if (!XId || !YId)
1787 : return XId && !YId;
1788 :
1789 : switch (XId->getName().compare_lower(YId->getName())) {
1790 : case -1: return true;
1791 : case 1: return false;
1792 : default: break;
1793 : }
1794 : }
1795 :
1796 : return XSel.getNumArgs() < YSel.getNumArgs();
1797 : }
1798 :
1799 : // For non-selectors, order by kind.
1800 : if (X.getNameKind() != Y.getNameKind())
1801 : return X.getNameKind() < Y.getNameKind();
1802 :
1803 : // Order identifiers by comparison of their lowercased names.
1804 : if (IdentifierInfo *XId = X.getAsIdentifierInfo())
1805 : return XId->getName().compare_lower(
1806 : Y.getAsIdentifierInfo()->getName()) < 0;
1807 :
1808 : // Order overloaded operators by the order in which they appear
1809 : // in our list of operators.
1810 : if (OverloadedOperatorKind XOp = X.getCXXOverloadedOperator())
1811 : return XOp < Y.getCXXOverloadedOperator();
1812 :
1813 : // Order C++0x user-defined literal operators lexically by their
1814 : // lowercased suffixes.
1815 : if (IdentifierInfo *XLit = X.getCXXLiteralIdentifier())
1816 : return XLit->getName().compare_lower(
1817 : Y.getCXXLiteralIdentifier()->getName()) < 0;
1818 :
1819 : // The only stable ordering we have is to turn the name into a
1820 : // string and then compare the lower-case strings. This is
1821 : // inefficient, but thankfully does not happen too often.
1822 : return llvm::StringRef(X.getAsString()).compare_lower(
1823 : Y.getAsString()) < 0;
1824 : }
1825 :
1826 : /// \brief Retrieve the name that should be used to order a result.
1827 : ///
1828 : /// If the name needs to be constructed as a string, that string will be
1829 : /// saved into Saved and the returned StringRef will refer to it.
1830 : static llvm::StringRef getOrderedName(const Result &R,
1831 29918: std::string &Saved) {
3484: branch 0 taken
1173: branch 1 taken
23597: branch 2 taken
1664: branch 3 taken
1832 29918: switch (R.Kind) {
1833 : case Result::RK_Keyword:
1834 3484: return R.Keyword;
1835 :
1836 : case Result::RK_Pattern:
1837 1173: return R.Pattern->getTypedText();
1838 :
1839 : case Result::RK_Macro:
1840 23597: return R.Macro->getName();
1841 :
1842 : case Result::RK_Declaration:
1843 : // Handle declarations below.
1844 : break;
1845 : }
1846 :
1847 1664: DeclarationName Name = R.Declaration->getDeclName();
1848 :
1849 : // If the name is a simple identifier (by far the common case), or a
1850 : // zero-argument selector, just return a reference to that identifier.
1371: branch 1 taken
293: branch 2 taken
1851 1664: if (IdentifierInfo *Id = Name.getAsIdentifierInfo())
1852 1371: return Id->getName();
63: branch 1 taken
230: branch 2 taken
1853 293: if (Name.isObjCZeroArgSelector())
63: branch 0 taken
0: branch 1 not taken
1854 63: if (IdentifierInfo *Id
1855 63: = Name.getObjCSelector().getIdentifierInfoForSlot(0))
1856 63: return Id->getName();
1857 :
1858 230: Saved = Name.getAsString();
1859 230: return Saved;
1860 : }
1861 :
1862 14959: bool operator()(const Result &X, const Result &Y) const {
1863 14959: std::string XSaved, YSaved;
1864 14959: llvm::StringRef XStr = getOrderedName(X, XSaved);
1865 14959: llvm::StringRef YStr = getOrderedName(Y, YSaved);
1866 14959: int cmp = XStr.compare_lower(YStr);
14925: branch 0 taken
34: branch 1 taken
1867 14959: if (cmp)
1868 14925: return cmp < 0;
1869 :
1870 : // Non-hidden names precede hidden names.
10: branch 0 taken
24: branch 1 taken
1871 34: if (X.Hidden != Y.Hidden)
1872 10: return !X.Hidden;
1873 :
1874 : // Non-nested-name-specifiers precede nested-name-specifiers.
0: branch 0 not taken
24: branch 1 taken
1875 24: if (X.StartsNestedNameSpecifier != Y.StartsNestedNameSpecifier)
1876 0: return !X.StartsNestedNameSpecifier;
1877 :
1878 24: return false;
1879 : }
1880 : };
1881 : }
1882 :
1883 15: static void AddMacroResults(Preprocessor &PP, ResultBuilder &Results) {
1884 15: Results.EnterNewScope();
1816: branch 3 taken
15: branch 4 taken
1885 1846: for (Preprocessor::macro_iterator M = PP.macro_begin(),
1886 15: MEnd = PP.macro_end();
1887 : M != MEnd; ++M)
1888 1816: Results.AddResult(M->first);
1889 15: Results.ExitScope();
1890 15: }
1891 :
1892 : static void HandleCodeCompleteResults(Sema *S,
1893 : CodeCompleteConsumer *CodeCompleter,
1894 : CodeCompleteConsumer::Result *Results,
1895 81: unsigned NumResults) {
1896 81: std::stable_sort(Results, Results + NumResults, SortCodeCompleteResult());
1897 :
81: branch 0 taken
0: branch 1 not taken
1898 81: if (CodeCompleter)
1899 81: CodeCompleter->ProcessCodeCompleteResults(*S, Results, NumResults);
1900 :
2581: branch 0 taken
81: branch 1 taken
1901 2662: for (unsigned I = 0; I != NumResults; ++I)
1902 2581: Results[I].Destroy();
1903 81: }
1904 :
1905 : void Sema::CodeCompleteOrdinaryName(Scope *S,
1906 12: CodeCompletionContext CompletionContext) {
1907 : typedef CodeCompleteConsumer::Result Result;
1908 12: ResultBuilder Results(*this);
1909 :
1910 : // Determine how to filter results, e.g., so that the names of
1911 : // values (functions, enumerators, function templates, etc.) are
1912 : // only allowed where we can have an expression.
5: branch 0 taken
7: branch 1 taken
0: branch 2 not taken
1913 12: switch (CompletionContext) {
1914 : case CCC_Namespace:
1915 : case CCC_Class:
1916 : case CCC_ObjCInterface:
1917 : case CCC_ObjCImplementation:
1918 : case CCC_ObjCInstanceVariableList:
1919 : case CCC_Template:
1920 : case CCC_MemberTemplate:
1921 5: Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
1922 5: break;
1923 :
1924 : case CCC_Expression:
1925 : case CCC_Statement:
1926 : case CCC_ForInit:
1927 : case CCC_Condition:
1928 7: Results.setFilter(&ResultBuilder::IsOrdinaryName);
1929 : break;
1930 : }
1931 :
1932 12: CodeCompletionDeclConsumer Consumer(Results, CurContext);
1933 12: LookupVisibleDecls(S, LookupOrdinaryName, Consumer);
1934 :
1935 12: Results.EnterNewScope();
1936 12: AddOrdinaryNameResults(CompletionContext, S, *this, Results);
1937 12: Results.ExitScope();
1938 :
7: branch 1 taken
5: branch 2 taken
1939 12: if (CodeCompleter->includeMacros())
1940 7: AddMacroResults(PP, Results);
1941 12: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
1942 12: }
1943 :
1944 : static void AddObjCProperties(ObjCContainerDecl *Container,
1945 : bool AllowCategories,
1946 : DeclContext *CurContext,
1947 9: ResultBuilder &Results) {
1948 : typedef CodeCompleteConsumer::Result Result;
1949 :
1950 : // Add properties in this container.
17: branch 3 taken
9: branch 4 taken
1951 35: for (ObjCContainerDecl::prop_iterator P = Container->prop_begin(),
1952 9: PEnd = Container->prop_end();
1953 : P != PEnd;
1954 : ++P)
1955 17: Results.MaybeAddResult(Result(*P, 0), CurContext);
1956 :
1957 : // Add properties in referenced protocols.
1: branch 1 taken
8: branch 2 taken
1958 9: if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
0: branch 1 not taken
1: branch 2 taken
1959 2: for (ObjCProtocolDecl::protocol_iterator P = Protocol->protocol_begin(),
1960 1: PEnd = Protocol->protocol_end();
1961 : P != PEnd; ++P)
1962 0: AddObjCProperties(*P, AllowCategories, CurContext, Results);
8: branch 1 taken
0: branch 2 not taken
1963 8: } else if (ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Container)){
2: branch 0 taken
6: branch 1 taken
1964 8: if (AllowCategories) {
1965 : // Look through categories.
0: branch 2 not taken
2: branch 3 taken
1966 2: for (ObjCCategoryDecl *Category = IFace->getCategoryList();
1967 : Category; Category = Category->getNextClassCategory())
1968 0: AddObjCProperties(Category, AllowCategories, CurContext, Results);
1969 : }
1970 :
1971 : // Look through protocols.
1: branch 1 taken
8: branch 2 taken
1972 17: for (ObjCInterfaceDecl::protocol_iterator I = IFace->protocol_begin(),
1973 8: E = IFace->protocol_end();
1974 : I != E; ++I)
1975 1: AddObjCProperties(*I, AllowCategories, CurContext, Results);
1976 :
1977 : // Look in the superclass.
4: branch 1 taken
4: branch 2 taken
1978 8: if (IFace->getSuperClass())
1979 : AddObjCProperties(IFace->getSuperClass(), AllowCategories, CurContext,
1980 4: Results);
0: branch 0 not taken
0: branch 1 not taken
1981 0: } else if (const ObjCCategoryDecl *Category
1982 0: = dyn_cast<ObjCCategoryDecl>(Container)) {
1983 : // Look through protocols.
0: branch 1 not taken
0: branch 2 not taken
1984 0: for (ObjCInterfaceDecl::protocol_iterator P = Category->protocol_begin(),
1985 0: PEnd = Category->protocol_end();
1986 : P != PEnd; ++P)
1987 0: AddObjCProperties(*P, AllowCategories, CurContext, Results);
1988 : }
1989 9: }
1990 :
1991 : void Sema::CodeCompleteMemberReferenceExpr(Scope *S, ExprTy *BaseE,
1992 : SourceLocation OpLoc,
1993 10: bool IsArrow) {
10: branch 0 taken
0: branch 1 not taken
0: branch 2 not taken
10: branch 3 taken
1994 10: if (!BaseE || !CodeCompleter)
1995 0: return;
1996 :
1997 : typedef CodeCompleteConsumer::Result Result;
1998 :
1999 10: Expr *Base = static_cast<Expr *>(BaseE);
2000 10: QualType BaseType = Base->getType();
2001 :
6: branch 0 taken
4: branch 1 taken
2002 10: if (IsArrow) {
5: branch 2 taken
1: branch 3 taken
2003 6: if (const PointerType *Ptr = BaseType->getAs<PointerType>())
2004 5: BaseType = Ptr->getPointeeType();
0: branch 2 not taken
1: branch 3 taken
2005 1: else if (BaseType->isObjCObjectPointerType())
2006 : /*Do nothing*/ ;
2007 : else
2008 0: return;
2009 : }
2010 :
2011 10: ResultBuilder Results(*this, &ResultBuilder::IsMember);
2012 10: Results.EnterNewScope();
8: branch 2 taken
2: branch 3 taken
2013 10: if (const RecordType *Record = BaseType->getAs<RecordType>()) {
2014 : // Access to a C/C++ class, struct, or union.
2015 8: Results.allowNestedNameSpecifiers();
2016 8: CodeCompletionDeclConsumer Consumer(Results, CurContext);
8: branch 1 taken
0: branch 2 not taken
2017 8: LookupVisibleDecls(Record->getDecl(), LookupMemberName, Consumer);
2018 :
4: branch 1 taken
4: branch 2 taken
2019 8: if (getLangOptions().CPlusPlus) {
4: branch 1 taken
0: branch 2 not taken
2020 4: if (!Results.empty()) {
2021 : // The "template" keyword can follow "->" or "." in the grammar.
2022 : // However, we only want to suggest the template keyword if something
2023 : // is dependent.
2024 4: bool IsDependent = BaseType->isDependentType();
4: branch 0 taken
0: branch 1 not taken
2025 4: if (!IsDependent) {
4: branch 1 taken
0: branch 2 not taken
2026 4: for (Scope *DepScope = S; DepScope; DepScope = DepScope->getParent())
4: branch 1 taken
0: branch 2 not taken
2027 4: if (DeclContext *Ctx = (DeclContext *)DepScope->getEntity()) {
2028 4: IsDependent = Ctx->isDependentContext();
2029 4: break;
2030 : }
2031 : }
2032 :
0: branch 0 not taken
4: branch 1 taken
2033 4: if (IsDependent)
2034 0: Results.AddResult(Result("template"));
2035 : }
2036 8: }
1: branch 0 taken
1: branch 1 taken
1: branch 4 taken
0: branch 5 not taken
1: branch 6 taken
1: branch 7 taken
2037 2: } else if (!IsArrow && BaseType->getAsObjCInterfacePointerType()) {
2038 : // Objective-C property reference.
2039 :
2040 : // Add property results based on our interface.
2041 : const ObjCObjectPointerType *ObjCPtr
2042 1: = BaseType->getAsObjCInterfacePointerType();
0: branch 0 not taken
1: branch 1 taken
2043 1: assert(ObjCPtr && "Non-NULL pointer guaranteed above!");
2044 1: AddObjCProperties(ObjCPtr->getInterfaceDecl(), true, CurContext, Results);
2045 :
2046 : // Add properties from the protocols in a qualified interface.
0: branch 1 not taken
1: branch 2 taken
2047 2: for (ObjCObjectPointerType::qual_iterator I = ObjCPtr->qual_begin(),
2048 1: E = ObjCPtr->qual_end();
2049 : I != E; ++I)
2050 0: AddObjCProperties(*I, true, CurContext, Results);
1: branch 0 taken
0: branch 1 not taken
0: branch 4 not taken
1: branch 5 taken
1: branch 6 taken
1: branch 7 taken
0: branch 10 not taken
0: branch 11 not taken
1: branch 12 taken
0: branch 13 not taken
2051 1: } else if ((IsArrow && BaseType->isObjCObjectPointerType()) ||
2052 : (!IsArrow && BaseType->isObjCInterfaceType())) {
2053 : // Objective-C instance variable access.
2054 1: ObjCInterfaceDecl *Class = 0;
1: branch 0 taken
0: branch 1 not taken
2055 1: if (const ObjCObjectPointerType *ObjCPtr
2056 1: = BaseType->getAs<ObjCObjectPointerType>())
2057 1: Class = ObjCPtr->getInterfaceDecl();
2058 : else
2059 0: Class = BaseType->getAs<ObjCInterfaceType>()->getDecl();
2060 :
2061 : // Add all ivars from this class and its superclasses.
1: branch 0 taken
0: branch 1 not taken
2062 1: if (Class) {
2063 1: CodeCompletionDeclConsumer Consumer(Results, CurContext);
2064 1: Results.setFilter(&ResultBuilder::IsObjCIvar);
1: branch 0 taken
0: branch 1 not taken
2065 1: LookupVisibleDecls(Class, LookupMemberName, Consumer);
2066 : }
2067 : }
2068 :
2069 : // FIXME: How do we cope with isa?
2070 :
2071 10: Results.ExitScope();
2072 :
2073 : // Add macros
6: branch 1 taken
4: branch 2 taken
2074 10: if (CodeCompleter->includeMacros())
2075 6: AddMacroResults(PP, Results);
2076 :
2077 : // Hand off the results found for code completion.
2078 10: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2079 : }
2080 :
2081 4: void Sema::CodeCompleteTag(Scope *S, unsigned TagSpec) {
0: branch 0 not taken
4: branch 1 taken
2082 4: if (!CodeCompleter)
2083 0: return;
2084 :
2085 : typedef CodeCompleteConsumer::Result Result;
2086 4: ResultBuilder::LookupFilter Filter = 0;
1: branch 0 taken
0: branch 1 not taken
3: branch 2 taken
0: branch 3 not taken
2087 4: switch ((DeclSpec::TST)TagSpec) {
2088 : case DeclSpec::TST_enum:
2089 1: Filter = &ResultBuilder::IsEnum;
2090 1: break;
2091 :
2092 : case DeclSpec::TST_union:
2093 0: Filter = &ResultBuilder::IsUnion;
2094 0: break;
2095 :
2096 : case DeclSpec::TST_struct:
2097 : case DeclSpec::TST_class:
2098 3: Filter = &ResultBuilder::IsClassOrStruct;
2099 3: break;
2100 :
2101 : default:
2102 0: assert(false && "Unknown type specifier kind in CodeCompleteTag");
2103 : return;
2104 : }
2105 :
2106 4: ResultBuilder Results(*this, Filter);
2107 4: Results.allowNestedNameSpecifiers();
2108 4: CodeCompletionDeclConsumer Consumer(Results, CurContext);
2109 4: LookupVisibleDecls(S, LookupTagName, Consumer);
2110 :
0: branch 1 not taken
4: branch 2 taken
2111 4: if (CodeCompleter->includeMacros())
2112 0: AddMacroResults(PP, Results);
2113 4: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2114 : }
2115 :
2116 5: void Sema::CodeCompleteCase(Scope *S) {
5: branch 2 taken
0: branch 3 not taken
0: branch 4 not taken
5: branch 5 taken
0: branch 6 not taken
5: branch 7 taken
2117 5: if (getSwitchStack().empty() || !CodeCompleter)
2118 0: return;
2119 :
2120 5: SwitchStmt *Switch = getSwitchStack().back();
0: branch 4 not taken
5: branch 5 taken
2121 5: if (!Switch->getCond()->getType()->isEnumeralType())
2122 0: return;
2123 :
2124 : // Code-complete the cases of a switch statement over an enumeration type
2125 : // by providing the list of
2126 5: EnumDecl *Enum = Switch->getCond()->getType()->getAs<EnumType>()->getDecl();
2127 :
2128 : // Determine which enumerators we have already seen in the switch statement.
2129 : // FIXME: Ideally, we would also be able to look *past* the code-completion
2130 : // token, in case we are code-completing in the middle of the switch and not
2131 : // at the end. However, we aren't able to do so at the moment.
2132 5: llvm::SmallPtrSet<EnumConstantDecl *, 8> EnumeratorsSeen;
2133 5: NestedNameSpecifier *Qualifier = 0;
4: branch 2 taken
5: branch 3 taken
2134 9: for (SwitchCase *SC = Switch->getSwitchCaseList(); SC;
2135 : SC = SC->getNextSwitchCase()) {
2136 4: CaseStmt *Case = dyn_cast<CaseStmt>(SC);
0: branch 0 not taken
4: branch 1 taken
2137 4: if (!Case)
2138 0: continue;
2139 :
2140 4: Expr *CaseVal = Case->getLHS()->IgnoreParenCasts();
4: branch 1 taken
0: branch 2 not taken
2141 4: if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CaseVal))
4: branch 0 taken
0: branch 1 not taken
2142 4: if (EnumConstantDecl *Enumerator
2143 4: = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
2144 : // We look into the AST of the case statement to determine which
2145 : // enumerator was named. Alternatively, we could compute the value of
2146 : // the integral constant expression, then compare it against the
2147 : // values of each enumerator. However, value-based approach would not
2148 : // work as well with C++ templates where enumerators declared within a
2149 : // template are type- and value-dependent.
2150 4: EnumeratorsSeen.insert(Enumerator);
2151 :
2152 : // If this is a qualified-id, keep track of the nested-name-specifier
2153 : // so that we can reproduce it as part of code completion, e.g.,
2154 : //
2155 : // switch (TagD.getKind()) {
2156 : // case TagDecl::TK_enum:
2157 : // break;
2158 : // case XXX
2159 : //
2160 : // At the XXX, our completions are TagDecl::TK_union,
2161 : // TagDecl::TK_struct, and TagDecl::TK_class, rather than TK_union,
2162 : // TK_struct, and TK_class.
2163 4: Qualifier = DRE->getQualifier();
2164 : }
2165 : }
2166 :
2: branch 1 taken
3: branch 2 taken
1: branch 3 taken
1: branch 4 taken
1: branch 6 taken
0: branch 7 not taken
1: branch 8 taken
4: branch 9 taken
2167 5: if (getLangOptions().CPlusPlus && !Qualifier && EnumeratorsSeen.empty()) {
2168 : // If there are no prior enumerators in C++, check whether we have to
2169 : // qualify the names of the enumerators that we suggest, because they
2170 : // may not be visible in this scope.
2171 : Qualifier = getRequiredQualification(Context, CurContext,
2172 1: Enum->getDeclContext());
2173 :
2174 : // FIXME: Scoped enums need to start with "EnumDecl" as the context!
2175 : }
2176 :
2177 : // Add any enumerators that have not yet been mentioned.
2178 5: ResultBuilder Results(*this);
2179 5: Results.EnterNewScope();
27: branch 3 taken
5: branch 4 taken
2180 37: for (EnumDecl::enumerator_iterator E = Enum->enumerator_begin(),
2181 5: EEnd = Enum->enumerator_end();
2182 : E != EEnd; ++E) {
4: branch 2 taken
23: branch 3 taken
2183 27: if (EnumeratorsSeen.count(*E))
2184 4: continue;
2185 :
2186 : Results.AddResult(CodeCompleteConsumer::Result(*E, Qualifier),
2187 23: CurContext, 0, false);
2188 : }
2189 5: Results.ExitScope();
2190 :
2: branch 1 taken
3: branch 2 taken
2191 5: if (CodeCompleter->includeMacros())
2192 2: AddMacroResults(PP, Results);
2193 5: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2194 : }
2195 :
2196 : namespace {
2197 : struct IsBetterOverloadCandidate {
2198 : Sema &S;
2199 : SourceLocation Loc;
2200 :
2201 : public:
2202 5: explicit IsBetterOverloadCandidate(Sema &S, SourceLocation Loc)
2203 5: : S(S), Loc(Loc) { }
2204 :
2205 : bool
2206 19: operator()(const OverloadCandidate &X, const OverloadCandidate &Y) const {
2207 19: return S.isBetterOverloadCandidate(X, Y, Loc);
2208 : }
2209 : };
2210 : }
2211 :
2212 : void Sema::CodeCompleteCall(Scope *S, ExprTy *FnIn,
2213 6: ExprTy **ArgsIn, unsigned NumArgs) {
0: branch 0 not taken
6: branch 1 taken
2214 6: if (!CodeCompleter)
2215 0: return;
2216 :
2217 : // When we're code-completing for a call, we fall back to ordinary
2218 : // name code-completion whenever we can't produce specific
2219 : // results. We may want to revisit this strategy in the future,
2220 : // e.g., by merging the two kinds of results.
2221 :
2222 6: Expr *Fn = (Expr *)FnIn;
2223 6: Expr **Args = (Expr **)ArgsIn;
2224 :
2225 : // Ignore type-dependent call expressions entirely.
6: branch 1 taken
0: branch 2 not taken
0: branch 4 not taken
6: branch 5 taken
0: branch 6 not taken
6: branch 7 taken
2226 6: if (Fn->isTypeDependent() ||
2227 : Expr::hasAnyTypeDependentArguments(Args, NumArgs)) {
2228 0: CodeCompleteOrdinaryName(S, CCC_Expression);
2229 0: return;
2230 : }
2231 :
2232 : // Build an overload candidate set based on the functions we find.
2233 6: SourceLocation Loc = Fn->getExprLoc();
2234 6: OverloadCandidateSet CandidateSet(Loc);
2235 :
2236 : // FIXME: What if we're calling something that isn't a function declaration?
2237 : // FIXME: What if we're calling a pseudo-destructor?
2238 : // FIXME: What if we're calling a member function?
2239 :
2240 : typedef CodeCompleteConsumer::OverloadCandidate ResultCandidate;
2241 6: llvm::SmallVector<ResultCandidate, 8> Results;
2242 :
2243 6: Expr *NakedFn = Fn->IgnoreParenCasts();
3: branch 1 taken
3: branch 2 taken
2244 6: if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(NakedFn))
2245 : AddOverloadedCallCandidates(ULE, Args, NumArgs, CandidateSet,
2246 3: /*PartialOverloading=*/ true);
3: branch 1 taken
0: branch 2 not taken
2247 3: else if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(NakedFn)) {
2248 3: FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl());
3: branch 0 taken
0: branch 1 not taken
2249 3: if (FDecl) {
1: branch 3 taken
2: branch 4 taken
2250 3: if (!FDecl->getType()->getAs<FunctionProtoType>())
2251 1: Results.push_back(ResultCandidate(FDecl));
2252 : else
2253 : // FIXME: access?
2254 : AddOverloadCandidate(FDecl, AS_none, Args, NumArgs, CandidateSet,
2255 2: false, false, /*PartialOverloading*/ true);
2256 : }
2257 : }
2258 :
5: branch 1 taken
1: branch 2 taken
2259 6: if (!CandidateSet.empty()) {
2260 : // Sort the overload candidate set by placing the best overloads first.
2261 : std::stable_sort(CandidateSet.begin(), CandidateSet.end(),
2262 5: IsBetterOverloadCandidate(*this, Loc));
2263 :
2264 : // Add the remaining viable overload candidates as code-completion reslults.
15: branch 1 taken
5: branch 2 taken
2265 25: for (OverloadCandidateSet::iterator Cand = CandidateSet.begin(),
2266 5: CandEnd = CandidateSet.end();
2267 : Cand != CandEnd; ++Cand) {
9: branch 0 taken
6: branch 1 taken
2268 15: if (Cand->Viable)
2269 9: Results.push_back(ResultCandidate(Cand->Function));
2270 : }
2271 : }
2272 :
0: branch 1 not taken
6: branch 2 taken
2273 6: if (Results.empty())
2274 0: CodeCompleteOrdinaryName(S, CCC_Expression);
2275 : else
2276 : CodeCompleter->ProcessOverloadCandidates(*this, NumArgs, Results.data(),
2277 6: Results.size());
2278 : }
2279 :
2280 : void Sema::CodeCompleteQualifiedId(Scope *S, const CXXScopeSpec &SS,
2281 4: bool EnteringContext) {
4: branch 1 taken
0: branch 2 not taken
0: branch 3 not taken
4: branch 4 taken
0: branch 5 not taken
4: branch 6 taken
2282 4: if (!SS.getScopeRep() || !CodeCompleter)
2283 0: return;
2284 :
2285 4: DeclContext *Ctx = computeDeclContext(SS, EnteringContext);
0: branch 0 not taken
4: branch 1 taken
2286 4: if (!Ctx)
2287 0: return;
2288 :
2289 : // Try to instantiate any non-dependent declaration contexts before
2290 : // we look in them.
4: branch 1 taken
0: branch 2 not taken
0: branch 4 not taken
4: branch 5 taken
0: branch 6 not taken
4: branch 7 taken
2291 4: if (!isDependentScopeSpecifier(SS) && RequireCompleteDeclContext(SS))
2292 0: return;
2293 :
2294 4: ResultBuilder Results(*this);
2295 4: CodeCompletionDeclConsumer Consumer(Results, CurContext);
2296 4: LookupVisibleDecls(Ctx, LookupOrdinaryName, Consumer);
2297 :
2298 : // The "template" keyword can follow "::" in the grammar, but only
2299 : // put it into the grammar if the nested-name-specifier is dependent.
2300 4: NestedNameSpecifier *NNS = (NestedNameSpecifier *)SS.getScopeRep();
4: branch 1 taken
0: branch 2 not taken
0: branch 4 not taken
4: branch 5 taken
0: branch 6 not taken
4: branch 7 taken
2301 4: if (!Results.empty() && NNS->isDependent())
2302 0: Results.AddResult("template");
2303 :
0: branch 1 not taken
4: branch 2 taken
2304 4: if (CodeCompleter->includeMacros())
2305 0: AddMacroResults(PP, Results);
2306 4: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2307 : }
2308 :
2309 1: void Sema::CodeCompleteUsing(Scope *S) {
0: branch 0 not taken
1: branch 1 taken
2310 1: if (!CodeCompleter)
2311 0: return;
2312 :
2313 1: ResultBuilder Results(*this, &ResultBuilder::IsNestedNameSpecifier);
2314 1: Results.EnterNewScope();
2315 :
2316 : // If we aren't in class scope, we could see the "namespace" keyword.
1: branch 1 taken
0: branch 2 not taken
2317 1: if (!S->isClassScope())
2318 1: Results.AddResult(CodeCompleteConsumer::Result("namespace"));
2319 :
2320 : // After "using", we can see anything that would start a
2321 : // nested-name-specifier.
2322 1: CodeCompletionDeclConsumer Consumer(Results, CurContext);
2323 1: LookupVisibleDecls(S, LookupOrdinaryName, Consumer);
2324 1: Results.ExitScope();
2325 :
0: branch 1 not taken
1: branch 2 taken
2326 1: if (CodeCompleter->includeMacros())
2327 0: AddMacroResults(PP, Results);
2328 1: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2329 : }
2330 :
2331 1: void Sema::CodeCompleteUsingDirective(Scope *S) {
0: branch 0 not taken
1: branch 1 taken
2332 1: if (!CodeCompleter)
2333 0: return;
2334 :
2335 : // After "using namespace", we expect to see a namespace name or namespace
2336 : // alias.
2337 1: ResultBuilder Results(*this, &ResultBuilder::IsNamespaceOrAlias);
2338 1: Results.EnterNewScope();
2339 1: CodeCompletionDeclConsumer Consumer(Results, CurContext);
2340 1: LookupVisibleDecls(S, LookupOrdinaryName, Consumer);
2341 1: Results.ExitScope();
0: branch 1 not taken
1: branch 2 taken
2342 1: if (CodeCompleter->includeMacros())
2343 0: AddMacroResults(PP, Results);
2344 1: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2345 : }
2346 :
2347 1: void Sema::CodeCompleteNamespaceDecl(Scope *S) {
0: branch 0 not taken
1: branch 1 taken
2348 1: if (!CodeCompleter)
2349 0: return;
2350 :
2351 1: ResultBuilder Results(*this, &ResultBuilder::IsNamespace);
2352 1: DeclContext *Ctx = (DeclContext *)S->getEntity();
0: branch 1 not taken
1: branch 2 taken
2353 1: if (!S->getParent())
0: branch 1 not taken
0: branch 2 not taken
2354 0: Ctx = Context.getTranslationUnitDecl();
2355 :
1: branch 0 taken
0: branch 1 not taken
1: branch 3 taken
0: branch 4 not taken
1: branch 5 taken
0: branch 6 not taken
2356 1: if (Ctx && Ctx->isFileContext()) {
2357 : // We only want to see those namespaces that have already been defined
2358 : // within this scope, because its likely that the user is creating an
2359 : // extended namespace declaration. Keep track of the most recent
2360 : // definition of each namespace.
2361 1: std::map<NamespaceDecl *, NamespaceDecl *> OrigToLatest;
3: branch 2 taken
1: branch 3 taken
2362 4: for (DeclContext::specific_decl_iterator<NamespaceDecl>
2363 1: NS(Ctx->decls_begin()), NSEnd(Ctx->decls_end());
2364 : NS != NSEnd; ++NS)
2365 3: OrigToLatest[NS->getOriginalNamespace()] = *NS;
2366 :
2367 : // Add the most recent definition (or extended definition) of each
2368 : // namespace to the list of results.
2369 1: Results.EnterNewScope();
2: branch 2 taken
1: branch 3 taken
2370 3: for (std::map<NamespaceDecl *, NamespaceDecl *>::iterator
2371 1: NS = OrigToLatest.begin(), NSEnd = OrigToLatest.end();
2372 : NS != NSEnd; ++NS)
2373 : Results.AddResult(CodeCompleteConsumer::Result(NS->second, 0),
2374 2: CurContext, 0, false);
2375 1: Results.ExitScope();
2376 : }
2377 :
0: branch 1 not taken
1: branch 2 taken
2378 1: if (CodeCompleter->includeMacros())
2379 0: AddMacroResults(PP, Results);
2380 1: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2381 : }
2382 :
2383 1: void Sema::CodeCompleteNamespaceAliasDecl(Scope *S) {
0: branch 0 not taken
1: branch 1 taken
2384 1: if (!CodeCompleter)
2385 0: return;
2386 :
2387 : // After "namespace", we expect to see a namespace or alias.
2388 1: ResultBuilder Results(*this, &ResultBuilder::IsNamespaceOrAlias);
2389 1: CodeCompletionDeclConsumer Consumer(Results, CurContext);
2390 1: LookupVisibleDecls(S, LookupOrdinaryName, Consumer);
0: branch 1 not taken
1: branch 2 taken
2391 1: if (CodeCompleter->includeMacros())
2392 0: AddMacroResults(PP, Results);
2393 1: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2394 : }
2395 :
2396 1: void Sema::CodeCompleteOperatorName(Scope *S) {
0: branch 0 not taken
1: branch 1 taken
2397 1: if (!CodeCompleter)
2398 0: return;
2399 :
2400 : typedef CodeCompleteConsumer::Result Result;
2401 1: ResultBuilder Results(*this, &ResultBuilder::IsType);
2402 1: Results.EnterNewScope();
2403 :
2404 : // Add the names of overloadable operators.
2405 : #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2406 : if (std::strcmp(Spelling, "?")) \
2407 : Results.AddResult(Result(Spelling));
2408 : #include "clang/Basic/OperatorKinds.def"
2409 :
2410 : // Add any type names visible from the current scope
2411 1: Results.allowNestedNameSpecifiers();
2412 1: CodeCompletionDeclConsumer Consumer(Results, CurContext);
2413 1: LookupVisibleDecls(S, LookupOrdinaryName, Consumer);
2414 :
2415 : // Add any type specifiers
2416 1: AddTypeSpecifierResults(getLangOptions(), Results);
2417 1: Results.ExitScope();
2418 :
0: branch 1 not taken
1: branch 2 taken
2419 1: if (CodeCompleter->includeMacros())
2420 0: AddMacroResults(PP, Results);
2421 1: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2422 : }
2423 :
2424 : // Macro that expands to @Keyword or Keyword, depending on whether NeedAt is
2425 : // true or false.
2426 : #define OBJC_AT_KEYWORD_NAME(NeedAt,Keyword) NeedAt? "@" #Keyword : #Keyword
2427 : static void AddObjCImplementationResults(const LangOptions &LangOpts,
2428 : ResultBuilder &Results,
2429 1: bool NeedAt) {
2430 : typedef CodeCompleteConsumer::Result Result;
2431 : // Since we have an implementation, we can end it.
0: branch 0 not taken
1: branch 1 taken
2432 1: Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,end)));
2433 :
2434 1: CodeCompletionString *Pattern = 0;
1: branch 0 taken
0: branch 1 not taken
2435 1: if (LangOpts.ObjC2) {
2436 : // @dynamic
2437 1: Pattern = new CodeCompletionString;
0: branch 0 not taken
1: branch 1 taken
2438 1: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,dynamic));
2439 1: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
2440 1: Pattern->AddPlaceholderChunk("property");
2441 1: Results.AddResult(Result(Pattern));
2442 :
2443 : // @synthesize
2444 1: Pattern = new CodeCompletionString;
0: branch 0 not taken
1: branch 1 taken
2445 1: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,synthesize));
2446 1: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
2447 1: Pattern->AddPlaceholderChunk("property");
2448 1: Results.AddResult(Result(Pattern));
2449 : }
2450 1: }
2451 :
2452 : static void AddObjCInterfaceResults(const LangOptions &LangOpts,
2453 : ResultBuilder &Results,
2454 2: bool NeedAt) {
2455 : typedef CodeCompleteConsumer::Result Result;
2456 :
2457 : // Since we have an interface or protocol, we can end it.
1: branch 0 taken
1: branch 1 taken
2458 2: Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,end)));
2459 :
2: branch 0 taken
0: branch 1 not taken
2460 2: if (LangOpts.ObjC2) {
2461 : // @property
1: branch 0 taken
1: branch 1 taken
2462 2: Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,property)));
2463 :
2464 : // @required
1: branch 0 taken
1: branch 1 taken
2465 2: Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,required)));
2466 :
2467 : // @optional
1: branch 0 taken
1: branch 1 taken
2468 2: Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,optional)));
2469 : }
2470 2: }
2471 :
2472 2: static void AddObjCTopLevelResults(ResultBuilder &Results, bool NeedAt) {
2473 : typedef CodeCompleteConsumer::Result Result;
2474 2: CodeCompletionString *Pattern = 0;
2475 :
2476 : // @class name ;
2477 2: Pattern = new CodeCompletionString;
1: branch 0 taken
1: branch 1 taken
2478 2: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,class));
2479 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
2480 2: Pattern->AddPlaceholderChunk("identifier");
2481 2: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
2482 2: Results.AddResult(Result(Pattern));
2483 :
2484 : // @interface name
2485 : // FIXME: Could introduce the whole pattern, including superclasses and
2486 : // such.
2487 2: Pattern = new CodeCompletionString;
1: branch 0 taken
1: branch 1 taken
2488 2: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,interface));
2489 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
2490 2: Pattern->AddPlaceholderChunk("class");
2491 2: Results.AddResult(Result(Pattern));
2492 :
2493 : // @protocol name
2494 2: Pattern = new CodeCompletionString;
1: branch 0 taken
1: branch 1 taken
2495 2: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,protocol));
2496 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
2497 2: Pattern->AddPlaceholderChunk("protocol");
2498 2: Results.AddResult(Result(Pattern));
2499 :
2500 : // @implementation name
2501 2: Pattern = new CodeCompletionString;
1: branch 0 taken
1: branch 1 taken
2502 2: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,implementation));
2503 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
2504 2: Pattern->AddPlaceholderChunk("class");
2505 2: Results.AddResult(Result(Pattern));
2506 :
2507 : // @compatibility_alias name
2508 2: Pattern = new CodeCompletionString;
1: branch 0 taken
1: branch 1 taken
2509 2: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,compatibility_alias));
2510 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
2511 2: Pattern->AddPlaceholderChunk("alias");
2512 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
2513 2: Pattern->AddPlaceholderChunk("class");
2514 2: Results.AddResult(Result(Pattern));
2515 2: }
2516 :
2517 : void Sema::CodeCompleteObjCAtDirective(Scope *S, DeclPtrTy ObjCImpDecl,
2518 3: bool InInterface) {
2519 : typedef CodeCompleteConsumer::Result Result;
2520 3: ResultBuilder Results(*this);
2521 3: Results.EnterNewScope();
1: branch 1 taken
2: branch 2 taken
2522 3: if (ObjCImpDecl)
2523 1: AddObjCImplementationResults(getLangOptions(), Results, false);
1: branch 0 taken
1: branch 1 taken
2524 2: else if (InInterface)
2525 1: AddObjCInterfaceResults(getLangOptions(), Results, false);
2526 : else
2527 1: AddObjCTopLevelResults(Results, false);
2528 3: Results.ExitScope();
2529 3: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2530 3: }
2531 :
2532 4: static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt) {
2533 : typedef CodeCompleteConsumer::Result Result;
2534 4: CodeCompletionString *Pattern = 0;
2535 :
2536 : // @encode ( type-name )
2537 4: Pattern = new CodeCompletionString;
2: branch 0 taken
2: branch 1 taken
2538 4: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,encode));
2539 4: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
2540 4: Pattern->AddPlaceholderChunk("type-name");
2541 4: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
2542 4: Results.AddResult(Result(Pattern));
2543 :
2544 : // @protocol ( protocol-name )
2545 4: Pattern = new CodeCompletionString;
2: branch 0 taken
2: branch 1 taken
2546 4: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,protocol));
2547 4: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
2548 4: Pattern->AddPlaceholderChunk("protocol-name");
2549 4: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
2550 4: Results.AddResult(Result(Pattern));
2551 :
2552 : // @selector ( selector )
2553 4: Pattern = new CodeCompletionString;
2: branch 0 taken
2: branch 1 taken
2554 4: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,selector));
2555 4: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
2556 4: Pattern->AddPlaceholderChunk("selector");
2557 4: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
2558 4: Results.AddResult(Result(Pattern));
2559 4: }
2560 :
2561 2: static void AddObjCStatementResults(ResultBuilder &Results, bool NeedAt) {
2562 : typedef CodeCompleteConsumer::Result Result;
2563 2: CodeCompletionString *Pattern = 0;
2564 :
2565 : // @try { statements } @catch ( declaration ) { statements } @finally
2566 : // { statements }
2567 2: Pattern = new CodeCompletionString;
1: branch 0 taken
1: branch 1 taken
2568 2: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,try));
2569 2: Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
2570 2: Pattern->AddPlaceholderChunk("statements");
2571 2: Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
2572 2: Pattern->AddTextChunk("@catch");
2573 2: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
2574 2: Pattern->AddPlaceholderChunk("parameter");
2575 2: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
2576 2: Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
2577 2: Pattern->AddPlaceholderChunk("statements");
2578 2: Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
2579 2: Pattern->AddTextChunk("@finally");
2580 2: Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
2581 2: Pattern->AddPlaceholderChunk("statements");
2582 2: Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
2583 2: Results.AddResult(Result(Pattern));
2584 :
2585 : // @throw
2586 2: Pattern = new CodeCompletionString;
1: branch 0 taken
1: branch 1 taken
2587 2: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,throw));
2588 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
2589 2: Pattern->AddPlaceholderChunk("expression");
2590 2: Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
2591 2: Results.AddResult(Result(Pattern));
2592 :
2593 : // @synchronized ( expression ) { statements }
2594 2: Pattern = new CodeCompletionString;
1: branch 0 taken
1: branch 1 taken
2595 2: Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,synchronized));
2596 2: Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
2597 2: Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
2598 2: Pattern->AddPlaceholderChunk("expression");
2599 2: Pattern->AddChunk(CodeCompletionString::CK_RightParen);
2600 2: Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
2601 2: Pattern->AddPlaceholderChunk("statements");
2602 2: Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
2603 2: Results.AddResult(Result(Pattern));
2604 2: }
2605 :
2606 : static void AddObjCVisibilityResults(const LangOptions &LangOpts,
2607 : ResultBuilder &Results,
2608 2: bool NeedAt) {
2609 : typedef CodeCompleteConsumer::Result Result;
1: branch 0 taken
1: branch 1 taken
2610 2: Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,private)));
1: branch 0 taken
1: branch 1 taken
2611 2: Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,protected)));
1: branch 0 taken
1: branch 1 taken
2612 2: Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,public)));
2: branch 0 taken
0: branch 1 not taken
2613 2: if (LangOpts.ObjC2)
1: branch 0 taken
1: branch 1 taken
2614 2: Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,package)));
2615 2: }
2616 :
2617 1: void Sema::CodeCompleteObjCAtVisibility(Scope *S) {
2618 1: ResultBuilder Results(*this);
2619 1: Results.EnterNewScope();
2620 1: AddObjCVisibilityResults(getLangOptions(), Results, false);
2621 1: Results.ExitScope();
2622 1: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2623 1: }
2624 :
2625 1: void Sema::CodeCompleteObjCAtStatement(Scope *S) {
2626 1: ResultBuilder Results(*this);
2627 1: Results.EnterNewScope();
2628 1: AddObjCStatementResults(Results, false);
2629 1: AddObjCExpressionResults(Results, false);
2630 1: Results.ExitScope();
2631 1: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2632 1: }
2633 :
2634 1: void Sema::CodeCompleteObjCAtExpression(Scope *S) {
2635 1: ResultBuilder Results(*this);
2636 1: Results.EnterNewScope();
2637 1: AddObjCExpressionResults(Results, false);
2638 1: Results.ExitScope();
2639 1: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2640 1: }
2641 :
2642 : /// \brief Determine whether the addition of the given flag to an Objective-C
2643 : /// property's attributes will cause a conflict.
2644 16: static bool ObjCPropertyFlagConflicts(unsigned Attributes, unsigned NewFlag) {
2645 : // Check if we've already added this flag.
1: branch 0 taken
15: branch 1 taken
2646 16: if (Attributes & NewFlag)
2647 1: return true;
2648 :
2649 15: Attributes |= NewFlag;
2650 :
2651 : // Check for collisions with "readonly".
2: branch 0 taken
13: branch 1 taken
1: branch 2 taken
1: branch 3 taken
2652 15: if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
2653 : (Attributes & (ObjCDeclSpec::DQ_PR_readwrite |
2654 : ObjCDeclSpec::DQ_PR_assign |
2655 : ObjCDeclSpec::DQ_PR_copy |
2656 : ObjCDeclSpec::DQ_PR_retain)))
2657 1: return true;
2658 :
2659 : // Check for more than one of { assign, copy, retain }.
2660 : unsigned AssignCopyRetMask = Attributes & (ObjCDeclSpec::DQ_PR_assign |
2661 : ObjCDeclSpec::DQ_PR_copy |
2662 14: ObjCDeclSpec::DQ_PR_retain);
9: branch 0 taken
5: branch 1 taken
8: branch 2 taken
1: branch 3 taken
7: branch 4 taken
1: branch 5 taken
2: branch 6 taken
5: branch 7 taken
2663 14: if (AssignCopyRetMask &&
2664 : AssignCopyRetMask != ObjCDeclSpec::DQ_PR_assign &&
2665 : AssignCopyRetMask != ObjCDeclSpec::DQ_PR_copy &&
2666 : AssignCopyRetMask != ObjCDeclSpec::DQ_PR_retain)
2667 2: return true;
2668 :
2669 12: return false;
2670 : }
2671 :
2672 2: void Sema::CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS) {
0: branch 0 not taken
2: branch 1 taken
2673 2: if (!CodeCompleter)
2674 0: return;
2675 :
2676 2: unsigned Attributes = ODS.getPropertyAttributes();
2677 :
2678 : typedef CodeCompleteConsumer::Result Result;
2679 2: ResultBuilder Results(*this);
2680 2: Results.EnterNewScope();
1: branch 1 taken
1: branch 2 taken
2681 2: if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_readonly))
2682 1: Results.AddResult(CodeCompleteConsumer::Result("readonly"));
1: branch 1 taken
1: branch 2 taken
2683 2: if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_assign))
2684 1: Results.AddResult(CodeCompleteConsumer::Result("assign"));
2: branch 1 taken
0: branch 2 not taken
2685 2: if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_readwrite))
2686 2: Results.AddResult(CodeCompleteConsumer::Result("readwrite"));
1: branch 1 taken
1: branch 2 taken
2687 2: if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_retain))
2688 1: Results.AddResult(CodeCompleteConsumer::Result("retain"));
1: branch 1 taken
1: branch 2 taken
2689 2: if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_copy))
2690 1: Results.AddResult(CodeCompleteConsumer::Result("copy"));
2: branch 1 taken
0: branch 2 not taken
2691 2: if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_nonatomic))
2692 2: Results.AddResult(CodeCompleteConsumer::Result("nonatomic"));
2: branch 1 taken
0: branch 2 not taken
2693 2: if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_setter)) {
2694 2: CodeCompletionString *Setter = new CodeCompletionString;
2695 2: Setter->AddTypedTextChunk("setter");
2696 2: Setter->AddTextChunk(" = ");
2697 2: Setter->AddPlaceholderChunk("method");
2698 2: Results.AddResult(CodeCompleteConsumer::Result(Setter));
2699 : }
2: branch 1 taken
0: branch 2 not taken
2700 2: if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_getter)) {
2701 2: CodeCompletionString *Getter = new CodeCompletionString;
2702 2: Getter->AddTypedTextChunk("getter");
2703 2: Getter->AddTextChunk(" = ");
2704 2: Getter->AddPlaceholderChunk("method");
2705 2: Results.AddResult(CodeCompleteConsumer::Result(Getter));
2706 : }
2707 2: Results.ExitScope();
2708 2: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2709 : }
2710 :
2711 : /// \brief Descripts the kind of Objective-C method that we want to find
2712 : /// via code completion.
2713 : enum ObjCMethodKind {
2714 : MK_Any, //< Any kind of method, provided it means other specified criteria.
2715 : MK_ZeroArgSelector, //< Zero-argument (unary) selector.
2716 : MK_OneArgSelector //< One-argument selector.
2717 : };
2718 :
2719 : static bool isAcceptableObjCMethod(ObjCMethodDecl *Method,
2720 : ObjCMethodKind WantKind,
2721 : IdentifierInfo **SelIdents,
2722 73: unsigned NumSelIdents) {
2723 73: Selector Sel = Method->getSelector();
3: branch 1 taken
70: branch 2 taken
2724 73: if (NumSelIdents > Sel.getNumArgs())
2725 3: return false;
2726 :
46: branch 0 taken
12: branch 1 taken
12: branch 2 taken
0: branch 3 not taken
2727 70: switch (WantKind) {
2728 46: case MK_Any: break;
2729 12: case MK_ZeroArgSelector: return Sel.isUnarySelector();
2730 12: case MK_OneArgSelector: return Sel.getNumArgs() == 1;
2731 : }
2732 :
12: branch 0 taken
43: branch 1 taken
2733 55: for (unsigned I = 0; I != NumSelIdents; ++I)
3: branch 1 taken
9: branch 2 taken
2734 12: if (SelIdents[I] != Sel.getIdentifierInfoForSlot(I))
2735 3: return false;
2736 :
2737 43: return true;
2738 : }
2739 :
2740 : /// \brief Add all of the Objective-C methods in the given Objective-C
2741 : /// container to the set of results.
2742 : ///
2743 : /// The container will be a class, protocol, category, or implementation of
2744 : /// any of the above. This mether will recurse to include methods from
2745 : /// the superclasses of classes along with their categories, protocols, and
2746 : /// implementations.
2747 : ///
2748 : /// \param Container the container in which we'll look to find methods.
2749 : ///
2750 : /// \param WantInstance whether to add instance methods (only); if false, this
2751 : /// routine will add factory methods (only).
2752 : ///
2753 : /// \param CurContext the context in which we're performing the lookup that
2754 : /// finds methods.
2755 : ///
2756 : /// \param Results the structure into which we'll add results.
2757 : static void AddObjCMethods(ObjCContainerDecl *Container,
2758 : bool WantInstanceMethods,
2759 : ObjCMethodKind WantKind,
2760 : IdentifierInfo **SelIdents,
2761 : unsigned NumSelIdents,
2762 : DeclContext *CurContext,
2763 32: ResultBuilder &Results) {
2764 : typedef CodeCompleteConsumer::Result Result;
94: branch 3 taken
32: branch 4 taken
2765 158: for (ObjCContainerDecl::method_iterator M = Container->meth_begin(),
2766 32: MEnd = Container->meth_end();
2767 : M != MEnd; ++M) {
59: branch 2 taken
35: branch 3 taken
2768 94: if ((*M)->isInstanceMethod() == WantInstanceMethods) {
2769 : // Check whether the selector identifiers we've been given are a
2770 : // subset of the identifiers for this particular method.
11: branch 2 taken
48: branch 3 taken
2771 59: if (!isAcceptableObjCMethod(*M, WantKind, SelIdents, NumSelIdents))
2772 11: continue;
2773 :
2774 48: Result R = Result(*M, 0);
2775 48: R.StartParameter = NumSelIdents;
2776 48: R.AllParametersAreInformative = (WantKind != MK_Any);
2777 48: Results.MaybeAddResult(R, CurContext);
2778 : }
2779 : }
2780 :
2781 32: ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Container);
14: branch 0 taken
18: branch 1 taken
2782 32: if (!IFace)
2783 14: return;
2784 :
2785 : // Add methods in protocols.
2786 18: const ObjCList<ObjCProtocolDecl> &Protocols= IFace->getReferencedProtocols();
4: branch 1 taken
18: branch 2 taken
2787 40: for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
2788 18: E = Protocols.end();
2789 : I != E; ++I)
2790 : AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, NumSelIdents,
2791 4: CurContext, Results);
2792 :
2793 : // Add methods in categories.
4: branch 2 taken
18: branch 3 taken
2794 22: for (ObjCCategoryDecl *CatDecl = IFace->getCategoryList(); CatDecl;
2795 : CatDecl = CatDecl->getNextClassCategory()) {
2796 : AddObjCMethods(CatDecl, WantInstanceMethods, WantKind, SelIdents,
2797 4: NumSelIdents, CurContext, Results);
2798 :
2799 : // Add a categories protocol methods.
2800 : const ObjCList<ObjCProtocolDecl> &Protocols
2801 4: = CatDecl->getReferencedProtocols();
0: branch 1 not taken
4: branch 2 taken
2802 8: for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
2803 4: E = Protocols.end();
2804 : I != E; ++I)
2805 : AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents,
2806 0: NumSelIdents, CurContext, Results);
2807 :
2808 : // Add methods in category implementations.
0: branch 1 not taken
4: branch 2 taken
2809 4: if (ObjCCategoryImplDecl *Impl = CatDecl->getImplementation())
2810 : AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents,
2811 0: NumSelIdents, CurContext, Results);
2812 : }
2813 :
2814 : // Add methods in superclass.
3: branch 1 taken
15: branch 2 taken
2815 18: if (IFace->getSuperClass())
2816 : AddObjCMethods(IFace->getSuperClass(), WantInstanceMethods, WantKind,
2817 3: SelIdents, NumSelIdents, CurContext, Results);
2818 :
2819 : // Add methods in our implementation, if any.
4: branch 1 taken
14: branch 2 taken
2820 18: if (ObjCImplementationDecl *Impl = IFace->getImplementation())
2821 : AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents,
2822 4: NumSelIdents, CurContext, Results);
2823 : }
2824 :
2825 :
2826 : void Sema::CodeCompleteObjCPropertyGetter(Scope *S, DeclPtrTy ClassDecl,
2827 : DeclPtrTy *Methods,
2828 2: unsigned NumMethods) {
2829 : typedef CodeCompleteConsumer::Result Result;
2830 :
2831 : // Try to find the interface where getters might live.
2832 : ObjCInterfaceDecl *Class
2833 2: = dyn_cast_or_null<ObjCInterfaceDecl>(ClassDecl.getAs<Decl>());
0: branch 0 not taken
2: branch 1 taken
2834 2: if (!Class) {
0: branch 0 not taken
0: branch 1 not taken
2835 0: if (ObjCCategoryDecl *Category
2836 0: = dyn_cast_or_null<ObjCCategoryDecl>(ClassDecl.getAs<Decl>()))
2837 0: Class = Category->getClassInterface();
2838 :
0: branch 0 not taken
0: branch 1 not taken
2839 0: if (!Class)
2840 0: return;
2841 : }
2842 :
2843 : // Find all of the potential getters.
2844 2: ResultBuilder Results(*this);
2845 2: Results.EnterNewScope();
2846 :
2847 : // FIXME: We need to do this because Objective-C methods don't get
2848 : // pushed into DeclContexts early enough. Argh!
10: branch 0 taken
2: branch 1 taken
2849 12: for (unsigned I = 0; I != NumMethods; ++I) {
10: branch 0 taken
0: branch 1 not taken
2850 10: if (ObjCMethodDecl *Method
2851 10: = dyn_cast_or_null<ObjCMethodDecl>(Methods[I].getAs<Decl>()))
7: branch 1 taken
3: branch 2 taken
3: branch 4 taken
4: branch 5 taken
3: branch 6 taken
7: branch 7 taken
2852 10: if (Method->isInstanceMethod() &&
2853 : isAcceptableObjCMethod(Method, MK_ZeroArgSelector, 0, 0)) {
2854 3: Result R = Result(Method, 0);
2855 3: R.AllParametersAreInformative = true;
2856 3: Results.MaybeAddResult(R, CurContext);
2857 : }
2858 : }
2859 :
2860 2: AddObjCMethods(Class, true, MK_ZeroArgSelector, 0, 0, CurContext, Results);
2861 2: Results.ExitScope();
2862 2: HandleCodeCompleteResults(this, CodeCompleter,Results.data(),Results.size());
2863 : }
2864 :
2865 : void Sema::CodeCompleteObjCPropertySetter(Scope *S, DeclPtrTy ObjCImplDecl,
2866 : DeclPtrTy *Methods,
2867 2: unsigned NumMethods) {
2868 : typedef CodeCompleteConsumer::Result Result;
2869 :
2870 : // Try to find the interface where setters might live.
2871 : ObjCInterfaceDecl *Class
2872 2: = dyn_cast_or_null<ObjCInterfaceDecl>(ObjCImplDecl.getAs<Decl>());
0: branch 0 not taken
2: branch 1 taken
2873 2: if (!Class) {
0: branch 0 not taken
0: branch 1 not taken
2874 0: if (ObjCCategoryDecl *Category
2875 0: = dyn_cast_or_null<ObjCCategoryDecl>(ObjCImplDecl.getAs<Decl>()))
2876 0: Class = Category->getClassInterface();
2877 :
0: branch 0 not taken
0: branch 1 not taken
2878 0: if (!Class)
2879 0: return;
2880 : }
2881 :
2882 : // Find all of the potential getters.
2883 2: ResultBuilder Results(*this);
2884 2: Results.EnterNewScope();
2885 :
2886 : // FIXME: We need to do this because Objective-C methods don't get
2887 : // pushed into DeclContexts early enough. Argh!
10: branch 0 taken
2: branch 1 taken
2888 12: for (unsigned I = 0; I != NumMethods; ++I) {
10: branch 0 taken
0: branch 1 not taken
2889 10: if (ObjCMethodDecl *Method
2890 10: = dyn_cast_or_null<ObjCMethodDecl>(Methods[I].getAs<Decl>()))
7: branch 1 taken
3: branch 2 taken
4: branch 4 taken
3: branch 5 taken
4: branch 6 taken
6: branch 7 taken
2891 10: if (Method->isInstanceMethod() &&
2892 : isAcceptableObjCMethod(Method, MK_OneArgSelector, 0, 0)) {
2893 4: Result R = Result(Method, 0);
2894 4: R.AllParametersAreInformative = true;
2895 4: Results.MaybeAddResult(R, CurContext);
2896 : }
2897 : }
2898 :
2899 2: AddObjCMethods(Class, true, MK_OneArgSelector, 0, 0, CurContext, Results);
2900 :
2901 2: Results.ExitScope();
2902 2: HandleCodeCompleteResults(this, CodeCompleter,Results.data(),Results.size());
2903 : }
2904 :
2905 : void Sema::CodeCompleteObjCClassMessage(Scope *S, IdentifierInfo *FName,
2906 : SourceLocation FNameLoc,
2907 : IdentifierInfo **SelIdents,
2908 5: unsigned NumSelIdents) {
2909 : typedef CodeCompleteConsumer::Result Result;
2910 5: ObjCInterfaceDecl *CDecl = 0;
2911 :
3: branch 1 taken
2: branch 2 taken
2912 5: if (FName->isStr("super")) {
2913 : // We're sending a message to "super".
2: branch 1 taken
1: branch 2 taken
2914 3: if (ObjCMethodDecl *CurMethod = getCurMethodDecl()) {
2915 : // Figure out which interface we're in.
2916 2: CDecl = CurMethod->getClassInterface();
0: branch 0 not taken
2: branch 1 taken
2917 2: if (!CDecl)
2918 0: return;
2919 :
2920 : // Find the superclass of this class.
2921 2: CDecl = CDecl->getSuperClass();
0: branch 0 not taken
2: branch 1 taken
2922 2: if (!CDecl)
2923 0: return;
2924 :
1: branch 1 taken
1: branch 2 taken
2925 2: if (CurMethod->isInstanceMethod()) {
2926 : // We are inside an instance method, which means that the message
2927 : // send [super ...] is actually calling an instance method on the
2928 : // current object. Build the super expression and handle this like
2929 : // an instance method.
2930 1: QualType SuperTy = Context.getObjCInterfaceType(CDecl);
2931 1: SuperTy = Context.getObjCObjectPointerType(SuperTy);
2932 : OwningExprResult Super
1: branch 1 taken
0: branch 2 not taken
2933 1: = Owned(new (Context) ObjCSuperExpr(FNameLoc, SuperTy));
2934 : return CodeCompleteObjCInstanceMessage(S, (Expr *)Super.get(),
2935 1: SelIdents, NumSelIdents);
2936 : }
2937 :
2938 : // Okay, we're calling a factory method in our superclass.
2939 : }
2940 : }
2941 :
2942 : // If the given name refers to an interface type, retrieve the
2943 : // corresponding declaration.
3: branch 0 taken
1: branch 1 taken
2944 4: if (!CDecl)
2: branch 1 taken
1: branch 2 taken
2945 3: if (TypeTy *Ty = getTypeName(*FName, FNameLoc, S, 0, false)) {
2946 2: QualType T = GetTypeFromParser(Ty, 0);
2: branch 1 taken
0: branch 2 not taken
2947 2: if (!T.isNull())
2: branch 2 taken
0: branch 3 not taken
2948 2: if (const ObjCInterfaceType *Interface = T->getAs<ObjCInterfaceType>())
2949 2: CDecl = Interface->getDecl();
2950 : }
2951 :
1: branch 0 taken
3: branch 1 taken
1: branch 3 taken
0: branch 4 not taken
1: branch 5 taken
3: branch 6 taken
2952 4: if (!CDecl && FName->isStr("super")) {
2953 : // "super" may be the name of a variable, in which case we are
2954 : // probably calling an instance method.
2955 1: CXXScopeSpec SS;
2956 1: UnqualifiedId id;
2957 1: id.setIdentifier(FName, FNameLoc);
2958 1: OwningExprResult Super = ActOnIdExpression(S, SS, id, false, false);
2959 : return CodeCompleteObjCInstanceMessage(S, (Expr *)Super.get(),
2960 1: SelIdents, NumSelIdents);
2961 : }
2962 :
2963 : // Add all of the factory methods in this Objective-C class, its protocols,
2964 : // superclasses, categories, implementation, etc.
2965 3: ResultBuilder Results(*this);
2966 3: Results.EnterNewScope();
2967 : AddObjCMethods(CDecl, false, MK_Any, SelIdents, NumSelIdents, CurContext,
2968 3: Results);
2969 3: Results.ExitScope();
2970 :
2971 : // This also suppresses remaining diagnostics.
2972 3: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
2973 : }
2974 :
2975 : void Sema::CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver,
2976 : IdentifierInfo **SelIdents,
2977 9: unsigned NumSelIdents) {
2978 : typedef CodeCompleteConsumer::Result Result;
2979 :
2980 9: Expr *RecExpr = static_cast<Expr *>(Receiver);
2981 :
2982 : // If necessary, apply function/array conversion to the receiver.
2983 : // C99 6.7.5.3p[7,8].
2984 9: DefaultFunctionArrayLvalueConversion(RecExpr);
2985 9: QualType ReceiverType = RecExpr->getType();
2986 :
9: branch 2 taken
0: branch 3 not taken
0: branch 6 not taken
9: branch 7 taken
0: branch 8 not taken
9: branch 9 taken
2987 9: if (ReceiverType->isObjCIdType() || ReceiverType->isBlockPointerType()) {
2988 : // FIXME: We're messaging 'id'. Do we actually want to look up every method
2989 : // in the universe?
2990 0: return;
2991 : }
2992 :
2993 : // Build the set of methods we can see.
2994 9: ResultBuilder Results(*this);
2995 9: Results.EnterNewScope();
2996 :
2997 : // Handle messages to Class. This really isn't a message to an instance
2998 : // method, so we treat it the same way we would treat a message send to a
2999 : // class method.
9: branch 2 taken
0: branch 3 not taken
0: branch 6 not taken
9: branch 7 taken
0: branch 8 not taken
9: branch 9 taken
3000 9: if (ReceiverType->isObjCClassType() ||
3001 : ReceiverType->isObjCQualifiedClassType()) {
0: branch 1 not taken
0: branch 2 not taken
3002 0: if (ObjCMethodDecl *CurMethod = getCurMethodDecl()) {
0: branch 1 not taken
0: branch 2 not taken
3003 0: if (ObjCInterfaceDecl *ClassDecl = CurMethod->getClassInterface())
3004 : AddObjCMethods(ClassDecl, false, MK_Any, SelIdents, NumSelIdents,
3005 0: CurContext, Results);
3006 : }
3007 : }
3008 : // Handle messages to a qualified ID ("id<foo>").
1: branch 0 taken
8: branch 1 taken
3009 9: else if (const ObjCObjectPointerType *QualID
3010 9: = ReceiverType->getAsObjCQualifiedIdType()) {
3011 : // Search protocols for instance methods.
2: branch 1 taken
1: branch 2 taken
3012 4: for (ObjCObjectPointerType::qual_iterator I = QualID->qual_begin(),
3013 1: E = QualID->qual_end();
3014 : I != E; ++I)
3015 : AddObjCMethods(*I, true, MK_Any, SelIdents, NumSelIdents, CurContext,
3016 2: Results);
3017 : }
3018 : // Handle messages to a pointer to interface type.
8: branch 0 taken
0: branch 1 not taken
3019 8: else if (const ObjCObjectPointerType *IFacePtr
3020 8: = ReceiverType->getAsObjCInterfacePointerType()) {
3021 : // Search the class, its superclasses, etc., for instance methods.
3022 : AddObjCMethods(IFacePtr->getInterfaceDecl(), true, MK_Any, SelIdents,
3023 8: NumSelIdents, CurContext, Results);
3024 :
3025 : // Search protocols for instance methods.
0: branch 1 not taken
8: branch 2 taken
3026 16: for (ObjCObjectPointerType::qual_iterator I = IFacePtr->qual_begin(),
3027 8: E = IFacePtr->qual_end();
3028 : I != E; ++I)
3029 : AddObjCMethods(*I, true, MK_Any, SelIdents, NumSelIdents, CurContext,
3030 0: Results);
3031 : }
3032 :
3033 9: Results.ExitScope();
3034 9: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
3035 : }
3036 :
3037 : /// \brief Add all of the protocol declarations that we find in the given
3038 : /// (translation unit) context.
3039 : static void AddProtocolResults(DeclContext *Ctx, DeclContext *CurContext,
3040 : bool OnlyForwardDeclarations,
3041 3: ResultBuilder &Results) {
3042 : typedef CodeCompleteConsumer::Result Result;
3043 :
24: branch 3 taken
3: branch 4 taken
3044 30: for (DeclContext::decl_iterator D = Ctx->decls_begin(),
3045 3: DEnd = Ctx->decls_end();
3046 : D != DEnd; ++D) {
3047 : // Record any protocols we find.
7: branch 2 taken
17: branch 3 taken
3048 24: if (ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(*D))
3: branch 0 taken
4: branch 1 taken
2: branch 3 taken
1: branch 4 taken
6: branch 5 taken
1: branch 6 taken
3049 7: if (!OnlyForwardDeclarations || Proto->isForwardDecl())
3050 6: Results.AddResult(Result(Proto, 0), CurContext, 0, false);
3051 :
3052 : // Record any forward-declared protocols we find.
4: branch 0 taken
20: branch 1 taken
3053 24: if (ObjCForwardProtocolDecl *Forward
3054 24: = dyn_cast<ObjCForwardProtocolDecl>(*D)) {
4: branch 0 taken
4: branch 1 taken
3055 8: for (ObjCForwardProtocolDecl::protocol_iterator
3056 4: P = Forward->protocol_begin(),
3057 4: PEnd = Forward->protocol_end();
3058 : P != PEnd; ++P)
2: branch 0 taken
2: branch 1 taken
2: branch 3 taken
0: branch 4 not taken
4: branch 5 taken
0: branch 6 not taken
3059 4: if (!OnlyForwardDeclarations || (*P)->isForwardDecl())
3060 4: Results.AddResult(Result(*P, 0), CurContext, 0, false);
3061 : }
3062 : }
3063 3: }
3064 :
3065 : void Sema::CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
3066 2: unsigned NumProtocols) {
3067 2: ResultBuilder Results(*this);
3068 2: Results.EnterNewScope();
3069 :
3070 : // Tell the result set to ignore all of the protocols we have
3071 : // already seen.
1: branch 0 taken
2: branch 1 taken
3072 3: for (unsigned I = 0; I != NumProtocols; ++I)
1: branch 1 taken
0: branch 2 not taken
3073 1: if (ObjCProtocolDecl *Protocol = LookupProtocol(Protocols[I].first))
3074 1: Results.Ignore(Protocol);
3075 :
3076 : // Add all protocols.
3077 : AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, false,
2: branch 1 taken
0: branch 2 not taken
3078 2: Results);
3079 :
3080 2: Results.ExitScope();
3081 2: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
3082 2: }
3083 :
3084 1: void Sema::CodeCompleteObjCProtocolDecl(Scope *) {
3085 1: ResultBuilder Results(*this);
3086 1: Results.EnterNewScope();
3087 :
3088 : // Add all protocols.
3089 : AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, true,
1: branch 1 taken
0: branch 2 not taken
3090 1: Results);
3091 :
3092 1: Results.ExitScope();
3093 1: HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
3094 1: }
3095 :
3096 : /// \brief Add all of the Objective-C interface declarations that we find in
3097 : /// the given (translation unit) context.
3098 : static void AddInterfaceResults(DeclContext *Ctx, DeclContext *CurContext,
3099 : bool OnlyForwardDeclarations,
3100 : bool OnlyUnimplemented,
3101 5: ResultBuilder &Results) {
3102 : typedef CodeCompleteConsumer::Result Result;
3103 :
32: branch 3 taken
5: branch 4 taken
3104 42: for (DeclContext::decl_iterator D = Ctx->decls_begin(),
3105 5: DEnd = Ctx->decls_end();
3106 : D != DEnd; ++D) {
3107 : // Record any interfaces we find.
6: branch 2 taken
26: branch 3 taken
3108 32: if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(*D))
1: branch 0 taken
5: branch 1 taken
0: branch 3 not taken
1: branch 4 taken
4: branch 5 taken
1: branch 6 taken
3: branch 8 taken
1: branch 9 taken
4: branch 10 taken
2: branch 11 taken
3109 6: if ((!OnlyForwardDeclarations || Class->isForwardDecl()) &&
3110 : (!OnlyUnimplemented || !Class->getImplementation()))
3111 4: Results.AddResult(Result(Class, 0), CurContext, 0, false);