summaryrefslogtreecommitdiffstats
path: root/include/clang/Basic/IdentifierTable.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/Basic/IdentifierTable.h')
-rw-r--r--include/clang/Basic/IdentifierTable.h103
1 files changed, 59 insertions, 44 deletions
diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h
index cc0080b..dc6acda 100644
--- a/include/clang/Basic/IdentifierTable.h
+++ b/include/clang/Basic/IdentifierTable.h
@@ -6,10 +6,11 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-//
-// This file defines the IdentifierInfo, IdentifierTable, and Selector
-// interfaces.
-//
+///
+/// \file
+/// \brief Defines the clang::IdentifierInfo, clang::IdentifierTable, and
+/// clang::Selector interfaces.
+///
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
@@ -37,12 +38,12 @@ namespace clang {
class MultiKeywordSelector; // private class used by Selector
class DeclarationName; // AST class that stores declaration names
- /// IdentifierLocPair - A simple pair of identifier info and location.
+ /// \brief A simple pair of identifier info and location.
typedef std::pair<IdentifierInfo*, SourceLocation> IdentifierLocPair;
-/// IdentifierInfo - One of these records is kept for each identifier that
-/// is lexed. This contains information about whether the token was #define'd,
+/// One of these records is kept for each identifier that
+/// is lexed. This contains information about whether the token was \#define'd,
/// is a language keyword, or if it is a front-end token of some sort (e.g. a
/// variable or function name). The preprocessor keeps this information in a
/// set, and all tok::identifier tokens have a pointer to one of these.
@@ -67,7 +68,7 @@ class IdentifierInfo {
bool OutOfDate : 1; // True if there may be additional
// information about this identifier
// stored externally.
- bool IsModulesImport : 1; // True if this is the 'import' contextual
+ bool IsModulesImport : 1; // True if this is the 'import' contextual
// keyword.
// 1 bit left in 32-bit word.
@@ -83,15 +84,16 @@ public:
IdentifierInfo();
- /// isStr - Return true if this is the identifier for the specified string.
+ /// \brief Return true if this is the identifier for the specified string.
+ ///
/// This is intended to be used for string literals only: II->isStr("foo").
template <std::size_t StrLen>
bool isStr(const char (&Str)[StrLen]) const {
return getLength() == StrLen-1 && !memcmp(getNameStart(), Str, StrLen-1);
}
- /// getNameStart - Return the beginning of the actual string for this
- /// identifier. The returned string is properly null terminated.
+ /// \brief Return the beginning of the actual null-terminated string for this
+ /// identifier.
///
const char *getNameStart() const {
if (Entry) return Entry->getKeyData();
@@ -104,7 +106,7 @@ public:
return ((const actualtype*) this)->second;
}
- /// getLength - Efficiently return the length of this identifier info.
+ /// \brief Efficiently return the length of this identifier info.
///
unsigned getLength() const {
if (Entry) return Entry->getKeyLength();
@@ -118,13 +120,12 @@ public:
return (((unsigned) p[0]) | (((unsigned) p[1]) << 8)) - 1;
}
- /// getName - Return the actual identifier string.
+ /// \brief Return the actual identifier string.
StringRef getName() const {
return StringRef(getNameStart(), getLength());
}
- /// hasMacroDefinition - Return true if this identifier is #defined to some
- /// other value.
+ /// \brief Return true if this identifier is \#defined to some other value.
bool hasMacroDefinition() const {
return HasMacro;
}
@@ -158,13 +159,14 @@ public:
RevertedTokenID = true;
}
- /// getPPKeywordID - Return the preprocessor keyword ID for this identifier.
+ /// \brief Return the preprocessor keyword ID for this identifier.
+ ///
/// For example, "define" will return tok::pp_define.
tok::PPKeywordKind getPPKeywordID() const;
- /// getObjCKeywordID - Return the Objective-C keyword ID for the this
- /// identifier. For example, 'class' will return tok::objc_class if ObjC is
- /// enabled.
+ /// \brief Return the Objective-C keyword ID for the this identifier.
+ ///
+ /// For example, 'class' will return tok::objc_class if ObjC is enabled.
tok::ObjCKeywordKind getObjCKeywordID() const {
if (ObjCOrBuiltinID < tok::NUM_OBJC_KEYWORDS)
return tok::ObjCKeywordKind(ObjCOrBuiltinID);
@@ -400,10 +402,11 @@ public:
virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0;
};
-/// IdentifierTable - This table implements an efficient mapping from strings to
-/// IdentifierInfo nodes. It has no other purpose, but this is an
-/// extremely performance-critical piece of the code, as each occurrence of
-/// every identifier goes through here when lexed.
+/// \brief Implements an efficient mapping from strings to IdentifierInfo nodes.
+///
+/// This has no other purpose, but this is an extremely performance-critical
+/// piece of the code, as each occurrence of every identifier goes through
+/// here when lexed.
class IdentifierTable {
// Shark shows that using MallocAllocator is *much* slower than using this
// BumpPtrAllocator!
@@ -413,8 +416,8 @@ class IdentifierTable {
IdentifierInfoLookup* ExternalLookup;
public:
- /// IdentifierTable ctor - Create the identifier table, populating it with
- /// info about the language keywords for the language specified by LangOpts.
+ /// \brief Create the identifier table, populating it with info about the
+ /// language keywords for the language specified by \p LangOpts.
IdentifierTable(const LangOptions &LangOpts,
IdentifierInfoLookup* externalLookup = 0);
@@ -432,8 +435,8 @@ public:
return HashTable.getAllocator();
}
- /// get - Return the identifier token info for the specified named identifier.
- ///
+ /// \brief Return the identifier token info for the specified named
+ /// identifier.
IdentifierInfo &get(StringRef Name) {
llvm::StringMapEntry<IdentifierInfo*> &Entry =
HashTable.GetOrCreateValue(Name);
@@ -507,15 +510,16 @@ public:
iterator end() const { return HashTable.end(); }
unsigned size() const { return HashTable.size(); }
- /// PrintStats - Print some statistics to stderr that indicate how well the
+ /// \brief Print some statistics to stderr that indicate how well the
/// hashing is doing.
void PrintStats() const;
void AddKeywords(const LangOptions &LangOpts);
};
-/// ObjCMethodFamily - A family of Objective-C methods. These
-/// families have no inherent meaning in the language, but are
+/// \brief A family of Objective-C methods.
+///
+/// These families have no inherent meaning in the language, but are
/// nonetheless central enough in the existing implementations to
/// merit direct AST support. While, in theory, arbitrary methods can
/// be considered to form families, we focus here on the methods
@@ -562,11 +566,13 @@ enum ObjCMethodFamily {
/// InvalidObjCMethodFamily.
enum { ObjCMethodFamilyBitWidth = 4 };
-/// An invalid value of ObjCMethodFamily.
+/// \brief An invalid value of ObjCMethodFamily.
enum { InvalidObjCMethodFamily = (1 << ObjCMethodFamilyBitWidth) - 1 };
-/// Selector - This smart pointer class efficiently represents Objective-C
-/// method names. This class will either point to an IdentifierInfo or a
+/// \brief Smart pointer class that efficiently represents Objective-C method
+/// names.
+///
+/// This class will either point to an IdentifierInfo or a
/// MultiKeywordSelector (which is private). This enables us to optimize
/// selectors that take no arguments and selectors that take 1 argument, which
/// accounts for 78% of all selectors in Cocoa.h.
@@ -574,9 +580,10 @@ class Selector {
friend class Diagnostic;
enum IdentifierInfoFlag {
- // MultiKeywordSelector = 0.
+ // Empty selector = 0.
ZeroArg = 0x1,
OneArg = 0x2,
+ MultiArg = 0x3,
ArgFlags = ZeroArg|OneArg
};
uintptr_t InfoPtr; // a pointer to the MultiKeywordSelector or IdentifierInfo.
@@ -590,13 +597,18 @@ class Selector {
Selector(MultiKeywordSelector *SI) {
InfoPtr = reinterpret_cast<uintptr_t>(SI);
assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
+ InfoPtr |= MultiArg;
}
IdentifierInfo *getAsIdentifierInfo() const {
- if (getIdentifierInfoFlag())
+ if (getIdentifierInfoFlag() < MultiArg)
return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags);
return 0;
}
+ MultiKeywordSelector *getMultiKeywordSelector() const {
+ return reinterpret_cast<MultiKeywordSelector *>(InfoPtr & ~ArgFlags);
+ }
+
unsigned getIdentifierInfoFlag() const {
return InfoPtr & ArgFlags;
}
@@ -661,11 +673,12 @@ public:
/// name was supplied.
StringRef getNameForSlot(unsigned argIndex) const;
- /// getAsString - Derive the full selector name (e.g. "foo:bar:") and return
+ /// \brief Derive the full selector name (e.g. "foo:bar:") and return
/// it as an std::string.
+ // FIXME: Add a print method that uses a raw_ostream.
std::string getAsString() const;
- /// getMethodFamily - Derive the conventional family of this method.
+ /// \brief Derive the conventional family of this method.
ObjCMethodFamily getMethodFamily() const {
return getMethodFamilyImpl(*this);
}
@@ -678,7 +691,7 @@ public:
}
};
-/// SelectorTable - This table allows us to fully hide how we implement
+/// \brief This table allows us to fully hide how we implement
/// multi-keyword caching.
class SelectorTable {
void *Impl; // Actually a SelectorTableImpl
@@ -688,9 +701,10 @@ public:
SelectorTable();
~SelectorTable();
- /// getSelector - This can create any sort of selector. NumArgs indicates
- /// whether this is a no argument selector "foo", a single argument selector
- /// "foo:" or multi-argument "foo:bar:".
+ /// \brief Can create any sort of selector.
+ ///
+ /// \p NumArgs indicates whether this is a no argument selector "foo", a
+ /// single argument selector "foo:" or multi-argument "foo:bar:".
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV);
Selector getUnarySelector(IdentifierInfo *ID) {
@@ -700,11 +714,12 @@ public:
return Selector(ID, 0);
}
- /// Return the total amount of memory allocated for managing selectors.
+ /// \brief Return the total amount of memory allocated for managing selectors.
size_t getTotalMemory() const;
- /// constructSetterName - Return the setter name for the given
- /// identifier, i.e. "set" + Name where the initial character of Name
+ /// \brief Return the setter name for the given identifier.
+ ///
+ /// This is "set" + \p Name where the initial character of \p Name
/// has been capitalized.
static Selector constructSetterName(IdentifierTable &Idents,
SelectorTable &SelTable,
OpenPOWER on IntegriCloud