aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/CodeCompleteConsumer.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2011-10-20 21:14:49 +0000
committerDimitry Andric <dim@FreeBSD.org>2011-10-20 21:14:49 +0000
commit36981b17ed939300f6f8fc2355a255f711fcef71 (patch)
treeee2483e98b09cac943dc93a6969d83ca737ff139 /lib/Sema/CodeCompleteConsumer.cpp
parent180abc3db9ae3b4fc63cd65b15697e6ffcc8a657 (diff)
downloadsrc-36981b17ed939300f6f8fc2355a255f711fcef71.tar.gz
src-36981b17ed939300f6f8fc2355a255f711fcef71.zip
Notes
Diffstat (limited to 'lib/Sema/CodeCompleteConsumer.cpp')
-rw-r--r--lib/Sema/CodeCompleteConsumer.cpp52
1 files changed, 39 insertions, 13 deletions
diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp
index d7dc5b2538c6..da9860361bc3 100644
--- a/lib/Sema/CodeCompleteConsumer.cpp
+++ b/lib/Sema/CodeCompleteConsumer.cpp
@@ -26,7 +26,6 @@
#include <functional>
using namespace clang;
-using llvm::StringRef;
//===----------------------------------------------------------------------===//
// Code completion context implementation
@@ -68,7 +67,7 @@ bool CodeCompletionContext::wantConstructorResults() const {
case CCC_OtherWithMacros:
case CCC_ObjCInstanceMessage:
case CCC_ObjCClassMessage:
- case CCC_ObjCSuperclass:
+ case CCC_ObjCInterfaceName:
case CCC_ObjCCategoryName:
return false;
}
@@ -191,14 +190,36 @@ CodeCompletionString::Chunk::CreateCurrentParameter(
CodeCompletionString::CodeCompletionString(const Chunk *Chunks,
unsigned NumChunks,
unsigned Priority,
- CXAvailabilityKind Availability)
- : NumChunks(NumChunks), Priority(Priority), Availability(Availability)
+ CXAvailabilityKind Availability,
+ const char **Annotations,
+ unsigned NumAnnotations)
+ : NumChunks(NumChunks), NumAnnotations(NumAnnotations)
+ , Priority(Priority), Availability(Availability)
{
+ assert(NumChunks <= 0xffff);
+ assert(NumAnnotations <= 0xffff);
+
Chunk *StoredChunks = reinterpret_cast<Chunk *>(this + 1);
for (unsigned I = 0; I != NumChunks; ++I)
StoredChunks[I] = Chunks[I];
+
+ const char **StoredAnnotations = reinterpret_cast<const char **>(StoredChunks + NumChunks);
+ for (unsigned I = 0; I != NumAnnotations; ++I)
+ StoredAnnotations[I] = Annotations[I];
+}
+
+unsigned CodeCompletionString::getAnnotationCount() const {
+ return NumAnnotations;
+}
+
+const char *CodeCompletionString::getAnnotation(unsigned AnnotationNr) const {
+ if (AnnotationNr < NumAnnotations)
+ return reinterpret_cast<const char * const*>(end())[AnnotationNr];
+ else
+ return 0;
}
+
std::string CodeCompletionString::getAsString() const {
std::string Result;
llvm::raw_string_ostream OS(Result);
@@ -228,14 +249,14 @@ const char *CodeCompletionString::getTypedText() const {
return 0;
}
-const char *CodeCompletionAllocator::CopyString(llvm::StringRef String) {
+const char *CodeCompletionAllocator::CopyString(StringRef String) {
char *Mem = (char *)Allocate(String.size() + 1, 1);
std::copy(String.begin(), String.end(), Mem);
Mem[String.size()] = 0;
return Mem;
}
-const char *CodeCompletionAllocator::CopyString(llvm::Twine String) {
+const char *CodeCompletionAllocator::CopyString(Twine String) {
// FIXME: It would be more efficient to teach Twine to tell us its size and
// then add a routine there to fill in an allocated char* with the contents
// of the string.
@@ -245,11 +266,13 @@ const char *CodeCompletionAllocator::CopyString(llvm::Twine String) {
CodeCompletionString *CodeCompletionBuilder::TakeString() {
void *Mem = Allocator.Allocate(
- sizeof(CodeCompletionString) + sizeof(Chunk) * Chunks.size(),
+ sizeof(CodeCompletionString) + sizeof(Chunk) * Chunks.size()
+ + sizeof(const char *) * Annotations.size(),
llvm::alignOf<CodeCompletionString>());
CodeCompletionString *Result
= new (Mem) CodeCompletionString(Chunks.data(), Chunks.size(),
- Priority, Availability);
+ Priority, Availability,
+ Annotations.data(), Annotations.size());
Chunks.clear();
return Result;
}
@@ -329,7 +352,7 @@ PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
OS << "COMPLETION: ";
switch (Results[I].Kind) {
case CodeCompletionResult::RK_Declaration:
- OS << Results[I].Declaration;
+ OS << *Results[I].Declaration;
if (Results[I].Hidden)
OS << " (Hidden)";
if (CodeCompletionString *CCS
@@ -377,7 +400,7 @@ PrintingCodeCompleteConsumer::ProcessOverloadCandidates(Sema &SemaRef,
}
}
-void CodeCompletionResult::computeCursorKindAndAvailability() {
+void CodeCompletionResult::computeCursorKindAndAvailability(bool Accessible) {
switch (Kind) {
case RK_Declaration:
// Set the availability based on attributes.
@@ -419,13 +442,16 @@ void CodeCompletionResult::computeCursorKindAndAvailability() {
// Do nothing: Patterns can come with cursor kinds!
break;
}
+
+ if (!Accessible)
+ Availability = CXAvailability_NotAccessible;
}
/// \brief Retrieve the name that should be used to order a result.
///
/// If the name needs to be constructed as a string, that string will be
/// saved into Saved and the returned StringRef will refer to it.
-static llvm::StringRef getOrderedName(const CodeCompletionResult &R,
+static StringRef getOrderedName(const CodeCompletionResult &R,
std::string &Saved) {
switch (R.Kind) {
case CodeCompletionResult::RK_Keyword:
@@ -460,8 +486,8 @@ static llvm::StringRef getOrderedName(const CodeCompletionResult &R,
bool clang::operator<(const CodeCompletionResult &X,
const CodeCompletionResult &Y) {
std::string XSaved, YSaved;
- llvm::StringRef XStr = getOrderedName(X, XSaved);
- llvm::StringRef YStr = getOrderedName(Y, YSaved);
+ StringRef XStr = getOrderedName(X, XSaved);
+ StringRef YStr = getOrderedName(Y, YSaved);
int cmp = XStr.compare_lower(YStr);
if (cmp)
return cmp < 0;