NumFunctionP*sizeof(FunctionTypeProto)+
NumFunctionNP*sizeof(FunctionTypeNoProto)+
NumTypeName*sizeof(TypedefType)+NumTagged*sizeof(TagType)));
-
- if (Selectors)
- Selectors->PrintStats();
}
return getTagDeclType(CFConstantStringTypeDecl);
}
-
-SelectorInfo &ASTContext::getSelectorInfo(const char *NameStart,
- const char *NameEnd) {
- if (!Selectors) // create the table lazily
- Selectors = new SelectorTable();
- return Selectors->get(NameStart, NameEnd);
-}
-
// constructor for unary messages.
ObjCMessageExpr::ObjCMessageExpr(
- IdentifierInfo *clsName, SelectorInfo &methName, QualType retType,
+ IdentifierInfo *clsName, IdentifierInfo &methName, QualType retType,
SourceLocation LBrac, SourceLocation RBrac)
: Expr(ObjCMessageExprClass, retType), Selector(methName) {
ClassName = clsName;
}
ObjCMessageExpr::ObjCMessageExpr(
- Expr *fn, SelectorInfo &methName, QualType retType,
+ Expr *fn, IdentifierInfo &methName, QualType retType,
SourceLocation LBrac, SourceLocation RBrac)
: Expr(ObjCMessageExprClass, retType), Selector(methName), ClassName(0) {
SubExprs = new Expr*[1];
// constructor for keyword messages.
ObjCMessageExpr::ObjCMessageExpr(
- Expr *fn, SelectorInfo &selInfo, ObjcKeywordMessage *keys, unsigned numargs,
+ Expr *fn, IdentifierInfo &selInfo, ObjcKeywordMessage *keys, unsigned numargs,
QualType retType, SourceLocation LBrac, SourceLocation RBrac)
: Expr(ObjCMessageExprClass, retType), Selector(selInfo), ClassName(0) {
SubExprs = new Expr*[numargs+1];
}
ObjCMessageExpr::ObjCMessageExpr(
- IdentifierInfo *clsName, SelectorInfo &selInfo, ObjcKeywordMessage *keys,
+ IdentifierInfo *clsName, IdentifierInfo &selInfo, ObjcKeywordMessage *keys,
unsigned numargs, QualType retType, SourceLocation LBrac, SourceLocation RBrac)
: Expr(ObjCMessageExprClass, retType), Selector(selInfo), ClassName(clsName) {
SubExprs = new Expr*[numargs+1];
// Compute statistics about the memory allocated for identifiers.
HashTable.getAllocator().PrintStats();
}
-
-/// PrintStats - Print statistics about how well the identifier table is doing
-/// at hashing identifiers.
-void SelectorTable::PrintStats() const {
- unsigned NumBuckets = HashTable.getNumBuckets();
- unsigned NumIdentifiers = HashTable.getNumItems();
- unsigned NumEmptyBuckets = NumBuckets-NumIdentifiers;
- unsigned AverageIdentifierSize = 0;
- unsigned MaxIdentifierLength = 0;
-
- // TODO: Figure out maximum times an identifier had to probe for -stats.
- for (llvm::StringMap<SelectorInfo, llvm::BumpPtrAllocator>::const_iterator
- I = HashTable.begin(), E = HashTable.end(); I != E; ++I) {
- unsigned IdLen = I->getKeyLength();
- AverageIdentifierSize += IdLen;
- if (MaxIdentifierLength < IdLen)
- MaxIdentifierLength = IdLen;
- }
-
- fprintf(stderr, "\n*** Selector Table Stats:\n");
- fprintf(stderr, "# Selectors: %d\n", NumIdentifiers);
- fprintf(stderr, "# Empty Buckets: %d\n", NumEmptyBuckets);
- fprintf(stderr, "Hash density (#selectors per bucket): %f\n",
- NumIdentifiers/(double)NumBuckets);
- fprintf(stderr, "Ave selector length: %f\n",
- (AverageIdentifierSize/(double)NumIdentifiers));
- fprintf(stderr, "Max selector length: %d\n", MaxIdentifierLength);
-
- // Compute statistics about the memory allocated for identifiers.
- HashTable.getAllocator().PrintStats();
-}
methodName += ":";
}
methodName[len] = '\0';
- SelectorInfo &SelName = Context.getSelectorInfo(&methodName[0],
- &methodName[0]+len);
+ IdentifierInfo &SelName = Context.Idents.get(&methodName[0],
+ &methodName[0]+len);
llvm::SmallVector<ParmVarDecl*, 16> Params;
for (unsigned i = 0; i < NumKeywords; i++) {
IdentifierInfo *SelectorName, AttributeList *AttrList,
tok::ObjCKeywordKind MethodDeclKind) {
const char *methodName = SelectorName->getName();
- SelectorInfo &SelName = Context.getSelectorInfo(methodName,
- methodName+strlen(methodName));
+ IdentifierInfo &SelName = Context.Idents.get(methodName,
+ methodName+strlen(methodName));
QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType);
ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc,
SelName, resultDeclType, 0, -1,
return new ObjCEncodeExpr(t, EncodedType, AtLoc, RParenLoc);
}
-static SelectorInfo &DeriveSelector(ObjcKeywordMessage *Keywords,
+static IdentifierInfo &DeriveSelector(ObjcKeywordMessage *Keywords,
unsigned NumKeywords,
ASTContext &Context) {
// Derive the selector name from the keyword declarations.
methodName += ":";
}
methodName[len] = '\0';
- return Context.getSelectorInfo(&methodName[0], &methodName[0]+len);
+ return Context.Idents.get(&methodName[0], &methodName[0]+len);
}
// This actions handles keyword message to classes.
ObjcKeywordMessage *Keywords, unsigned NumKeywords,
SourceLocation lbrac, SourceLocation rbrac)
{
- SelectorInfo &SelName = DeriveSelector(Keywords, NumKeywords, Context);
+ IdentifierInfo &SelName = DeriveSelector(Keywords, NumKeywords, Context);
assert(receivingClassName && "missing receiver class name");
return new ObjCMessageExpr(receivingClassName, SelName, Keywords, NumKeywords,
Sema::ExprResult Sema::ActOnKeywordMessage(
ExprTy *receiver, ObjcKeywordMessage *Keywords, unsigned NumKeywords,
SourceLocation lbrac, SourceLocation rbrac) {
- SelectorInfo &SelName = DeriveSelector(Keywords, NumKeywords, Context);
+ IdentifierInfo &SelName = DeriveSelector(Keywords, NumKeywords, Context);
assert(receiver && "missing receiver expression");
Expr *RExpr = static_cast<Expr *>(receiver);
assert(receivingClassName && "missing receiver class name");
// FIXME: this should be passed in...
- SelectorInfo &SName = Context.getSelectorInfo(
+ IdentifierInfo &SName = Context.Idents.get(
selName->getName(), selName->getName()+strlen(selName->getName()));
return new ObjCMessageExpr(receivingClassName, SName,
Context.IntTy/*FIXME*/, lbrac, rbrac);
Expr *RExpr = static_cast<Expr *>(receiver);
// FIXME: this should be passed in...
- SelectorInfo &SName = Context.getSelectorInfo(
+ IdentifierInfo &SName = Context.Idents.get(
selName->getName(), selName->getName()+strlen(selName->getName()));
return new ObjCMessageExpr(RExpr, SName,
Context.IntTy/*FIXME*/, lbrac, rbrac);
namespace clang {
class TargetInfo;
- class SelectorTable;
/// ASTContext - This class holds long-lived AST nodes (such as types and
/// decls) that can be referred to throughout the semantic analysis of a file.
llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos;
llvm::DenseMap<const RecordDecl*, const RecordLayout*> RecordLayoutInfo;
RecordDecl *CFConstantStringTypeDecl;
- SelectorTable *Selectors;
public:
SourceManager &SourceMgr;
TargetInfo &Target;
QualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
ASTContext(SourceManager &SM, TargetInfo &t, IdentifierTable &idents) :
- CFConstantStringTypeDecl(0), Selectors(0),
- SourceMgr(SM), Target(t), Idents(idents) {
+ CFConstantStringTypeDecl(0), SourceMgr(SM), Target(t), Idents(idents) {
InitBuiltinTypes();
BuiltinInfo.InitializeBuiltins(idents, Target);
}
/// 'typeSize' is a real floating point or complex type.
QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
QualType typeDomain) const;
-
- //===--------------------------------------------------------------------===//
- // Objective-C
- //===--------------------------------------------------------------------===//
-
- /// getSelectorInfo - Return a uniqued character string for the selector.
- SelectorInfo &getSelectorInfo(const char *NameStart, const char *NameEnd);
-
private:
ASTContext(const ASTContext&); // DO NOT IMPLEMENT
void operator=(const ASTContext&); // DO NOT IMPLEMENT
class AttributeList;
class ObjcIvarDecl;
class ObjcMethodDecl;
-class SelectorInfo;
/// Decl - This represents one declaration (or definition), e.g. a variable,
enum ImplementationControl { None, Required, Optional };
private:
// A unigue name for this method.
- SelectorInfo &Selector;
+ IdentifierInfo &Selector;
// Type of this method.
QualType MethodDeclType;
ImplementationControl DeclImplementation : 2;
public:
- ObjcMethodDecl(SourceLocation L, SelectorInfo &SelId, QualType T,
+ ObjcMethodDecl(SourceLocation L, IdentifierInfo &SelId, QualType T,
ParmVarDecl **paramInfo = 0, int numParams=-1,
AttributeList *M = 0, bool isInstance = true,
Decl *PrevDecl = 0)
ParamInfo(paramInfo), NumMethodParams(numParams),
MethodAttrs(M), IsInstance(isInstance) {}
- ObjcMethodDecl(Kind DK, SourceLocation L, SelectorInfo &SelId, QualType T,
+ ObjcMethodDecl(Kind DK, SourceLocation L, IdentifierInfo &SelId, QualType T,
ParmVarDecl **paramInfo = 0, int numParams=-1,
AttributeList *M = 0, bool isInstance = true,
Decl *PrevDecl = 0)
unsigned NumArgs;
// A unigue name for this message.
- SelectorInfo &Selector;
+ IdentifierInfo &Selector;
IdentifierInfo **KeyIdents;
public:
// constructor for unary messages.
// FIXME: clsName should be typed to ObjCInterfaceType
- ObjCMessageExpr(IdentifierInfo *clsName, SelectorInfo &selInfo,
+ ObjCMessageExpr(IdentifierInfo *clsName, IdentifierInfo &selInfo,
QualType retType, SourceLocation LBrac, SourceLocation RBrac);
- ObjCMessageExpr(Expr *receiver, SelectorInfo &selInfo,
+ ObjCMessageExpr(Expr *receiver, IdentifierInfo &selInfo,
QualType retType, SourceLocation LBrac, SourceLocation RBrac);
// constructor for keyword messages.
// FIXME: clsName should be typed to ObjCInterfaceType
- ObjCMessageExpr(IdentifierInfo *clsName, SelectorInfo &selInfo,
+ ObjCMessageExpr(IdentifierInfo *clsName, IdentifierInfo &selInfo,
ObjcKeywordMessage *keys, unsigned numargs, QualType retType,
SourceLocation LBrac, SourceLocation RBrac);
- ObjCMessageExpr(Expr *receiver, SelectorInfo &selInfo,
+ ObjCMessageExpr(Expr *receiver, IdentifierInfo &selInfo,
ObjcKeywordMessage *keys, unsigned numargs, QualType retType,
SourceLocation LBrac, SourceLocation RBrac);
~ObjCMessageExpr() {
void AddKeywords(const LangOptions &LangOpts);
};
-/// SelectorInfo - One of these records is kept for each selector. Selectors
-/// are created as a by-product of parsing a method declaration/definition,
-/// message expression, or @selector expression.
-class SelectorInfo {
- void *ObjcMethodDecl; // FIXME: add setter/getter.
-
- SelectorInfo(const SelectorInfo&); // NONCOPYABLE.
-public:
- SelectorInfo() : ObjcMethodDecl(0) {}
-
- /// getName - Return the actual string for this selector. The returned
- /// string is properly null terminated.
- ///
- const char *getName() const {
- // String data is stored immediately after the IdentifierInfo object.
- return (const char*)(this+1);
- }
-};
-
-/// SelectorTable - This table implements an efficient mapping from strings to
-/// SelectorInfo nodes.
-class SelectorTable {
- // Shark shows that using MallocAllocator is *much* slower than using this
- // BumpPtrAllocator!
- typedef llvm::StringMap<SelectorInfo, llvm::BumpPtrAllocator> HashTableTy;
- HashTableTy HashTable;
-public:
- SelectorTable() : HashTable(4096) { }
-
- /// get - Return the selector info for the specified name.
- ///
- SelectorInfo &get(const char *NameStart, const char *NameEnd) {
- return HashTable.GetOrCreateValue(NameStart, NameEnd).getValue();
- }
- SelectorInfo &get(const char *Name) {
- return get(Name, Name+strlen(Name));
- }
- typedef HashTableTy::const_iterator iterator;
- typedef HashTableTy::const_iterator const_iterator;
-
- iterator begin() const { return HashTable.begin(); }
- iterator end() const { return HashTable.end(); }
-
- /// PrintStats - Print some statistics to stderr that indicate how well the
- /// hashing is doing.
- void PrintStats() const;
-};
-
} // end namespace clang
#endif