[llvm-branch-commits] [cfe-branch] r126117 - in /cfe/branches/Apple/whitney: include/clang/Basic/IdentifierTable.h lib/AST/DeclarationName.cpp lib/AST/StmtPrinter.cpp lib/Basic/IdentifierTable.cpp lib/Sema/SemaCodeComplete.cpp lib/Sema/SemaExpr.cpp test/Index/complete-method-decls.m
Daniel Dunbar
daniel at zuster.org
Mon Feb 21 08:19:23 PST 2011
Author: ddunbar
Date: Mon Feb 21 10:19:23 2011
New Revision: 126117
URL: http://llvm.org/viewvc/llvm-project?rev=126117&view=rev
Log:
Merge r125977:
--
Author: Douglas Gregor <dgregor at apple.com>
Date: Fri Feb 18 22:29:55 2011 +0000
Selector::getIdentifierInfoForSlot() can return NULL values, a fact
that was ignored in a few places (most notably, code
completion). Introduce Selector::getNameForSlot() for the common case
where we only care about the name. Audit all uses of
getIdentifierInfoForSlot(), switching many over to getNameForSlot(),
fixing a few crashers.
Fixed <rdar://problem/8939352>, a code-completion crasher.
*** CUSTOM MERGE ***
Modified:
cfe/branches/Apple/whitney/include/clang/Basic/IdentifierTable.h
cfe/branches/Apple/whitney/lib/AST/DeclarationName.cpp
cfe/branches/Apple/whitney/lib/AST/StmtPrinter.cpp
cfe/branches/Apple/whitney/lib/Basic/IdentifierTable.cpp
cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp
cfe/branches/Apple/whitney/lib/Sema/SemaExpr.cpp
cfe/branches/Apple/whitney/test/Index/complete-method-decls.m
Modified: cfe/branches/Apple/whitney/include/clang/Basic/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang/Basic/IdentifierTable.h?rev=126117&r1=126116&r2=126117&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/branches/Apple/whitney/include/clang/Basic/IdentifierTable.h Mon Feb 21 10:19:23 2011
@@ -509,8 +509,33 @@
return getIdentifierInfoFlag() == ZeroArg;
}
unsigned getNumArgs() const;
+
+
+ /// \brief Retrieve the identifier at a given position in the selector.
+ ///
+ /// Note that the identifier pointer returned may be NULL. Clients that only
+ /// care about the text of the identifier string, and not the specific,
+ /// uniqued identifier pointer, should use \c getNameForSlot(), which returns
+ /// an empty string when the identifier pointer would be NULL.
+ ///
+ /// \param argIndex The index for which we want to retrieve the identifier.
+ /// This index shall be less than \c getNumArgs() unless this is a keyword
+ /// selector, in which case 0 is the only permissible value.
+ ///
+ /// \returns the uniqued identifier for this slot, or NULL if this slot has
+ /// no corresponding identifier.
IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const;
-
+
+ /// \brief Retrieve the name at a given position in the selector.
+ ///
+ /// \param argIndex The index for which we want to retrieve the name.
+ /// This index shall be less than \c getNumArgs() unless this is a keyword
+ /// selector, in which case 0 is the only permissible value.
+ ///
+ /// \returns the name for this slot, which may be the empty string if no
+ /// name was supplied.
+ llvm::StringRef getNameForSlot(unsigned argIndex) const;
+
/// getAsString - Derive the full selector name (e.g. "foo:bar:") and return
/// it as an std::string.
std::string getAsString() const;
Modified: cfe/branches/Apple/whitney/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/AST/DeclarationName.cpp?rev=126117&r1=126116&r2=126117&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/AST/DeclarationName.cpp (original)
+++ cfe/branches/Apple/whitney/lib/AST/DeclarationName.cpp Mon Feb 21 10:19:23 2011
@@ -93,10 +93,8 @@
Selector RHSSelector = RHS.getObjCSelector();
unsigned LN = LHSSelector.getNumArgs(), RN = RHSSelector.getNumArgs();
for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) {
- IdentifierInfo *LHSId = LHSSelector.getIdentifierInfoForSlot(I);
- IdentifierInfo *RHSId = RHSSelector.getIdentifierInfoForSlot(I);
-
- switch (LHSId->getName().compare(RHSId->getName())) {
+ switch (LHSSelector.getNameForSlot(I).compare(
+ RHSSelector.getNameForSlot(I))) {
case -1: return true;
case 1: return false;
default: break;
Modified: cfe/branches/Apple/whitney/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/AST/StmtPrinter.cpp?rev=126117&r1=126116&r2=126117&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/AST/StmtPrinter.cpp (original)
+++ cfe/branches/Apple/whitney/lib/AST/StmtPrinter.cpp Mon Feb 21 10:19:23 2011
@@ -1285,7 +1285,7 @@
OS << ' ';
Selector selector = Mess->getSelector();
if (selector.isUnarySelector()) {
- OS << selector.getIdentifierInfoForSlot(0)->getName();
+ OS << selector.getNameForSlot(0);
} else {
for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) {
if (i < selector.getNumArgs()) {
Modified: cfe/branches/Apple/whitney/lib/Basic/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Basic/IdentifierTable.cpp?rev=126117&r1=126116&r2=126117&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Basic/IdentifierTable.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Basic/IdentifierTable.cpp Mon Feb 21 10:19:23 2011
@@ -324,6 +324,11 @@
return SI->getIdentifierInfoForSlot(argIndex);
}
+llvm::StringRef Selector::getNameForSlot(unsigned int argIndex) const {
+ IdentifierInfo *II = getIdentifierInfoForSlot(argIndex);
+ return II? II->getName() : llvm::StringRef();
+}
+
std::string MultiKeywordSelector::getName() const {
llvm::SmallString<256> Str;
llvm::raw_svector_ostream OS(Str);
Modified: cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp?rev=126117&r1=126116&r2=126117&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp Mon Feb 21 10:19:23 2011
@@ -2319,11 +2319,11 @@
if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND)) {
Selector Sel = Method->getSelector();
if (Sel.isUnarySelector()) {
- Result->AddTypedTextChunk(Sel.getIdentifierInfoForSlot(0)->getName());
+ Result->AddTypedTextChunk(Sel.getNameForSlot(0));
return Result;
}
- std::string SelName = Sel.getIdentifierInfoForSlot(0)->getName().str();
+ std::string SelName = Sel.getNameForSlot(0).str();
SelName += ':';
if (StartParameter == 0)
Result->AddTypedTextChunk(SelName);
@@ -4414,9 +4414,9 @@
Selector Sel = CurMethod->getSelector();
if (Sel.isUnarySelector()) {
if (NeedSuperKeyword)
- Pattern->AddTextChunk(Sel.getIdentifierInfoForSlot(0)->getName());
+ Pattern->AddTextChunk(Sel.getNameForSlot(0));
else
- Pattern->AddTypedTextChunk(Sel.getIdentifierInfoForSlot(0)->getName());
+ Pattern->AddTypedTextChunk(Sel.getNameForSlot(0));
} else {
ObjCMethodDecl::param_iterator CurP = CurMethod->param_begin();
for (unsigned I = 0, N = Sel.getNumArgs(); I != N; ++I, ++CurP) {
@@ -4424,15 +4424,14 @@
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
if (I < NumSelIdents)
- Pattern->AddInformativeChunk(
- Sel.getIdentifierInfoForSlot(I)->getName().str() + ":");
+ Pattern->AddInformativeChunk(Sel.getNameForSlot(I).str() + ":");
else if (NeedSuperKeyword || I > NumSelIdents) {
Pattern->AddTextChunk(
- Sel.getIdentifierInfoForSlot(I)->getName().str() + ":");
+ Sel.getNameForSlot(I).str() + ":");
Pattern->AddPlaceholderChunk((*CurP)->getIdentifier()->getName());
} else {
Pattern->AddTypedTextChunk(
- Sel.getIdentifierInfoForSlot(I)->getName().str() + ":");
+ Sel.getNameForSlot(I).str() + ":");
Pattern->AddPlaceholderChunk((*CurP)->getIdentifier()->getName());
}
}
@@ -4874,7 +4873,7 @@
CodeCompletionString *Pattern = new CodeCompletionString;
if (Sel.isUnarySelector()) {
- Pattern->AddTypedTextChunk(Sel.getIdentifierInfoForSlot(0)->getName());
+ Pattern->AddTypedTextChunk(Sel.getNameForSlot(0));
Results.AddResult(Pattern);
continue;
}
@@ -4888,7 +4887,7 @@
}
}
- Accumulator += Sel.getIdentifierInfoForSlot(I)->getName().str();
+ Accumulator += Sel.getNameForSlot(I).str();
Accumulator += ':';
}
Pattern->AddTypedTextChunk(Accumulator);
@@ -5354,7 +5353,7 @@
Selector Sel = Method->getSelector();
// Add the first part of the selector to the pattern.
- Pattern->AddTypedTextChunk(Sel.getIdentifierInfoForSlot(0)->getName());
+ Pattern->AddTypedTextChunk(Sel.getNameForSlot(0));
// Add parameters to the pattern.
unsigned I = 0;
@@ -5366,8 +5365,7 @@
Pattern->AddTypedTextChunk(":");
else if (I < Sel.getNumArgs()) {
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
- Pattern->AddTypedTextChunk((Sel.getIdentifierInfoForSlot(I)->getName()
- + ":").str());
+ Pattern->AddTypedTextChunk((Sel.getNameForSlot(I) + ":").str());
} else
break;
Modified: cfe/branches/Apple/whitney/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaExpr.cpp?rev=126117&r1=126116&r2=126117&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaExpr.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaExpr.cpp Mon Feb 21 10:19:23 2011
@@ -8238,13 +8238,11 @@
Selector Sel = ME->getSelector();
// self = [<foo> init...]
- if (isSelfExpr(Op->getLHS())
- && Sel.getIdentifierInfoForSlot(0)->getName().startswith("init"))
+ if (isSelfExpr(Op->getLHS()) && Sel.getNameForSlot(0).startswith("init"))
diagnostic = diag::warn_condition_is_idiomatic_assignment;
// <foo> = [<bar> nextObject]
- else if (Sel.isUnarySelector() &&
- Sel.getIdentifierInfoForSlot(0)->getName() == "nextObject")
+ else if (Sel.isUnarySelector() && Sel.getNameForSlot(0) == "nextObject")
diagnostic = diag::warn_condition_is_idiomatic_assignment;
}
Modified: cfe/branches/Apple/whitney/test/Index/complete-method-decls.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/complete-method-decls.m?rev=126117&r1=126116&r2=126117&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/complete-method-decls.m (original)
+++ cfe/branches/Apple/whitney/test/Index/complete-method-decls.m Mon Feb 21 10:19:23 2011
@@ -60,6 +60,14 @@
- (oneway void)method:(in id x);
@end
+ at interface Gaps
+- (void)method:(int)x :(int)y;
+ at end
+
+ at implementation Gaps
+- (void)method:(int)x :(int)y;
+ at end
+
// RUN: c-index-test -code-completion-at=%s:17:3 %s | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText abc}
// CHECK-CC1: ObjCInstanceMethodDecl:{LeftParen (}{Text int}{RightParen )}{TypedText getInt}
@@ -158,3 +166,7 @@
// CHECK-CCH: NotImplemented:{TypedText unsigned} (50)
// CHECK-CCH: NotImplemented:{TypedText void} (50)
// CHECK-CCH: NotImplemented:{TypedText volatile} (50)
+
+// <rdar://problem/8939352>
+// RUN: c-index-test -code-completion-at=%s:68:9 %s | FileCheck -check-prefix=CHECK-8939352 %s
+// CHECK-8939352: ObjCInstanceMethodDecl:{TypedText method}{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text x}{HorizontalSpace }{TypedText :}{LeftParen (}{Text int}{RightParen )}{Text y} (40)
More information about the llvm-branch-commits
mailing list