Add some comments to MultiKeywordSelector, make all methods private, add a friend, move some methods around.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42456 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Steve Naroff 2007-09-28 23:39:26 +00:00
Родитель eb19188e66
Коммит 5b6b72f53a
3 изменённых файлов: 60 добавлений и 58 удалений

Просмотреть файл

@ -33,36 +33,6 @@ tok::ObjCKeywordKind Token::getObjCKeywordID() const {
return specId ? specId->getObjCKeywordID() : tok::objc_not_keyword;
}
char *MultiKeywordSelector::getName(llvm::SmallVectorImpl<char> &methodName) {
methodName[0] = '\0';
keyword_iterator KeyIter = keyword_begin();
for (unsigned int i = 0; i < NumArgs; i++) {
if (KeyIter[i]) {
unsigned KeyLen = strlen(KeyIter[i]->getName());
methodName.append(KeyIter[i]->getName(), KeyIter[i]->getName()+KeyLen);
}
methodName.push_back(':');
}
methodName.push_back('\0');
return &methodName[0];
}
char *Selector::getName(llvm::SmallVectorImpl<char> &methodName) {
methodName[0] = '\0';
IdentifierInfo *II = getAsIdentifierInfo();
if (II) {
unsigned NameLen = strlen(II->getName());
methodName.append(II->getName(), II->getName()+NameLen);
if (getNumArgs() == 1)
methodName.push_back(':');
methodName.push_back('\0');
} else { // We have a multiple keyword selector (no embedded flags).
MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
SI->getName(methodName);
}
return &methodName[0];
}
//===----------------------------------------------------------------------===//
// IdentifierInfo Implementation
//===----------------------------------------------------------------------===//

Просмотреть файл

@ -502,6 +502,58 @@ Parser::TypeTy *Parser::ParseObjCTypeName() {
return Ty;
}
unsigned Selector::getNumArgs() const {
unsigned IIF = getIdentifierInfoFlag();
if (IIF == ZeroArg)
return 0;
if (IIF == OneArg)
return 1;
// We point to a MultiKeywordSelector (pointer doesn't contain any flags).
MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
return SI->getNumArgs();
}
IdentifierInfo *Selector::getIdentifierInfoForSlot(unsigned argIndex) {
IdentifierInfo *II = getAsIdentifierInfo();
if (II) {
assert(((argIndex == 0) || (argIndex == 1)) && "illegal keyword index");
return II;
}
// We point to a MultiKeywordSelector (pointer doesn't contain any flags).
MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
return SI->getIdentifierInfoForSlot(argIndex);
}
char *MultiKeywordSelector::getName(llvm::SmallVectorImpl<char> &methodName) {
methodName[0] = '\0';
keyword_iterator KeyIter = keyword_begin();
for (unsigned int i = 0; i < NumArgs; i++) {
if (KeyIter[i]) {
unsigned KeyLen = strlen(KeyIter[i]->getName());
methodName.append(KeyIter[i]->getName(), KeyIter[i]->getName()+KeyLen);
}
methodName.push_back(':');
}
methodName.push_back('\0');
return &methodName[0];
}
char *Selector::getName(llvm::SmallVectorImpl<char> &methodName) {
methodName[0] = '\0';
IdentifierInfo *II = getAsIdentifierInfo();
if (II) {
unsigned NameLen = strlen(II->getName());
methodName.append(II->getName(), II->getName()+NameLen);
if (getNumArgs() == 1)
methodName.push_back(':');
methodName.push_back('\0');
} else { // We have a multiple keyword selector (no embedded flags).
MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
SI->getName(methodName);
}
return &methodName[0];
}
Selector Parser::ObjcGetUnarySelector(IdentifierInfo *unarySel)
{
return Selector(unarySel, 0);

Просмотреть файл

@ -171,8 +171,10 @@ private:
};
/// MultiKeywordSelector - One of these variable length records is kept for each
/// parsed selector (similar in spirit to IdentifierInfo). We use a folding set
/// to unique aggregate names (keyword selectors in ObjC parlance).
/// selector containing more than one keyword. We use a folding set
/// to unique aggregate names (keyword selectors in ObjC parlance). Access to
/// this class is provided strictly through Selector. All methods are private.
/// The only reason it appears in this header is FoldingSet needs to see it:-(
class MultiKeywordSelector : public llvm::FoldingSetNode {
friend class Selector; // Only Selector can access me.
friend class Parser; // Only Parser can instantiate me.
@ -206,7 +208,7 @@ class MultiKeywordSelector : public llvm::FoldingSetNode {
assert((i < NumArgs) && "getIdentifierInfoForSlot(): illegal index");
return keyword_begin()[i];
}
public:
friend class llvm::FoldingSet<MultiKeywordSelector>;
static void Profile(llvm::FoldingSetNodeID &ID,
keyword_iterator ArgTys, unsigned NumArgs) {
ID.AddInteger(NumArgs);
@ -248,11 +250,6 @@ class Selector {
return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags);
return 0;
}
MultiKeywordSelector *getAsMultiKeywordSelector() const {
if (InfoPtr & ArgFlags)
return 0;
return reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
}
public:
unsigned getIdentifierInfoFlag() const {
return InfoPtr & ArgFlags;
@ -274,26 +271,9 @@ public:
bool isUnarySelector() const {
return getIdentifierInfoFlag() == ZeroArg;
}
unsigned getNumArgs() const {
unsigned IIF = getIdentifierInfoFlag();
if (IIF == ZeroArg)
return 0;
if (IIF == OneArg)
return 1;
// We point to a MultiKeywordSelector (pointer doesn't contain any flags).
MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
return SI->getNumArgs();
}
IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) {
IdentifierInfo *II = getAsIdentifierInfo();
if (II) {
assert(((argIndex == 0) || (argIndex == 1)) && "illegal keyword index");
return II;
}
// We point to a MultiKeywordSelector (pointer doesn't contain any flags).
MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
return SI->getIdentifierInfoForSlot(argIndex);
}
unsigned getNumArgs() const;
IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex);
// Derive the full selector name, placing the result into methodBuffer.
// As a convenience, a pointer to the first character is returned.
// Example usage: llvm::SmallString<128> mbuf; Selector->getName(mbuf);