diff --git a/clang/Driver/RewriteBlocks.cpp b/clang/Driver/RewriteBlocks.cpp
index d8e347fafbac..535915344c66 100644
--- a/clang/Driver/RewriteBlocks.cpp
+++ b/clang/Driver/RewriteBlocks.cpp
@@ -618,7 +618,7 @@ void RewriteBlocks::SynthesizeBlockLiterals(SourceLocation FunLocStart,
void RewriteBlocks::InsertBlockLiteralsWithinFunction(FunctionDecl *FD) {
SourceLocation FunLocStart = FD->getTypeSpecStartLoc();
- const char *FuncName = FD->getName();
+ const char *FuncName = FD->getIdentifierName();
SynthesizeBlockLiterals(FunLocStart, FuncName);
}
@@ -675,13 +675,13 @@ std::string RewriteBlocks::SynthesizeBlockCall(CallExpr *Exp) {
const BlockPointerType *CPT = 0;
if (const DeclRefExpr *DRE = dyn_cast(Exp->getCallee())) {
- closureName = DRE->getDecl()->getName();
+ closureName = DRE->getDecl()->getIdentifierName();
CPT = DRE->getType()->getAsBlockPointerType();
} else if (BlockDeclRefExpr *CDRE = dyn_cast(Exp->getCallee())) {
- closureName = CDRE->getDecl()->getName();
+ closureName = CDRE->getDecl()->getIdentifierName();
CPT = CDRE->getType()->getAsBlockPointerType();
} else if (MemberExpr *MExpr = dyn_cast(Exp->getCallee())) {
- closureName = MExpr->getMemberDecl()->getName();
+ closureName = MExpr->getMemberDecl()->getIdentifierName();
CPT = MExpr->getType()->getAsBlockPointerType();
} else {
assert(1 && "RewriteBlockClass: Bad type");
@@ -1109,7 +1109,8 @@ void RewriteBlocks::HandleDeclInMainFile(Decl *D) {
std::string Init = SynthesizeBlockInitExpr(CBE, VD);
// Do the rewrite, using S.size() which contains the rewritten size.
ReplaceText(CBE->getLocStart(), S.size(), Init.c_str(), Init.size());
- SynthesizeBlockLiterals(VD->getTypeSpecStartLoc(), VD->getName());
+ SynthesizeBlockLiterals(VD->getTypeSpecStartLoc(),
+ VD->getIdentifierName());
} else if (CastExpr *CE = dyn_cast(VD->getInit())) {
RewriteCastExpr(CE);
}
diff --git a/clang/Driver/RewriteObjC.cpp b/clang/Driver/RewriteObjC.cpp
index 2903f998a05c..69aedcc2dd85 100644
--- a/clang/Driver/RewriteObjC.cpp
+++ b/clang/Driver/RewriteObjC.cpp
@@ -506,7 +506,7 @@ void RewriteObjC::HandleTopLevelDecl(Decl *D) {
RewriteFunctionDecl(FD);
} else if (VarDecl *FVD = dyn_cast(D)) {
// declared in
- if (strcmp(FVD->getName(), "_NSConstantStringClassReference") == 0) {
+ if (strcmp(FVD->getIdentifierName(), "_NSConstantStringClassReference") == 0) {
ConstantStringClassReference = FVD;
return;
}
@@ -1088,13 +1088,13 @@ Stmt *RewriteObjC::RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S,
elementTypeAsString = ElementType.getAsString();
buf += elementTypeAsString;
buf += " ";
- elementName = D->getName();
+ elementName = D->getIdentifierName();
buf += elementName;
buf += ";\n\t";
}
else {
DeclRefExpr *DR = cast(S->getElement());
- elementName = DR->getDecl()->getName();
+ elementName = DR->getDecl()->getIdentifierName();
elementTypeAsString
= cast(DR->getDecl())->getType().getAsString();
}
@@ -1694,7 +1694,7 @@ void RewriteObjC::SynthGetProtocolFunctionDecl() {
void RewriteObjC::RewriteFunctionDecl(FunctionDecl *FD) {
// declared in
- if (strcmp(FD->getName(), "sel_registerName") == 0) {
+ if (strcmp(FD->getIdentifierName(), "sel_registerName") == 0) {
SelGetUidFunctionDecl = FD;
return;
}
@@ -2299,8 +2299,8 @@ Stmt *RewriteObjC::RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp) {
// Create a call to objc_getProtocol("ProtocolName").
llvm::SmallVector ProtoExprs;
QualType argType = Context->getPointerType(Context->CharTy);
- ProtoExprs.push_back(new StringLiteral(Exp->getProtocol()->getName(),
- strlen(Exp->getProtocol()->getName()),
+ ProtoExprs.push_back(new StringLiteral(Exp->getProtocol()->getIdentifierName(),
+ strlen(Exp->getProtocol()->getIdentifierName()),
false, argType, SourceLocation(),
SourceLocation()));
CallExpr *ProtoExp = SynthesizeCallToFunctionDecl(GetProtocolFunctionDecl,
@@ -2343,7 +2343,8 @@ bool RewriteObjC::BufferContainsPPDirectives(const char *startBuf,
void RewriteObjC::SynthesizeObjCInternalStruct(ObjCInterfaceDecl *CDecl,
std::string &Result) {
assert(CDecl && "Class missing in SynthesizeObjCInternalStruct");
- assert(CDecl->getName() && "Name missing in SynthesizeObjCInternalStruct");
+ assert(CDecl->getIdentifierName() &&
+ "Name missing in SynthesizeObjCInternalStruct");
// Do not synthesize more than once.
if (ObjCSynthesizedStructs.count(CDecl))
return;
@@ -2922,15 +2923,15 @@ void RewriteObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
// Build _objc_method_list for class's instance methods if needed
RewriteObjCMethodsMetaData(IDecl->instmeth_begin(), IDecl->instmeth_end(),
- true, "", IDecl->getName(), Result);
+ true, "", IDecl->getIdentifierName(), Result);
// Build _objc_method_list for class's class methods if needed
RewriteObjCMethodsMetaData(IDecl->classmeth_begin(), IDecl->classmeth_end(),
- false, "", IDecl->getName(), Result);
+ false, "", IDecl->getIdentifierName(), Result);
// Protocols referenced in class declaration?
RewriteObjCProtocolsMetaData(CDecl->getReferencedProtocols(),
- "CLASS", CDecl->getName(), Result);
+ "CLASS", CDecl->getIdentifierName(), Result);
// Declaration of class/meta-class metadata
@@ -3429,7 +3430,7 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
void RewriteObjC::InsertBlockLiteralsWithinFunction(FunctionDecl *FD) {
SourceLocation FunLocStart = FD->getTypeSpecStartLoc();
- const char *FuncName = FD->getName();
+ const char *FuncName = FD->getIdentifierName();
SynthesizeBlockLiterals(FunLocStart, FuncName);
}
@@ -3489,13 +3490,13 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp) {
const BlockPointerType *CPT = 0;
if (const DeclRefExpr *DRE = dyn_cast(Exp->getCallee())) {
- closureName = DRE->getDecl()->getName();
+ closureName = DRE->getDecl()->getIdentifierName();
CPT = DRE->getType()->getAsBlockPointerType();
} else if (BlockDeclRefExpr *CDRE = dyn_cast(Exp->getCallee())) {
- closureName = CDRE->getDecl()->getName();
+ closureName = CDRE->getDecl()->getIdentifierName();
CPT = CDRE->getType()->getAsBlockPointerType();
} else if (MemberExpr *MExpr = dyn_cast(Exp->getCallee())) {
- closureName = MExpr->getMemberDecl()->getName();
+ closureName = MExpr->getMemberDecl()->getIdentifierName();
CPT = MExpr->getType()->getAsBlockPointerType();
} else {
assert(1 && "RewriteBlockClass: Bad type");
@@ -3812,15 +3813,15 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp) {
E = BlockByCopyDecls.end(); I != E; ++I) {
if (isObjCType((*I)->getType())) {
// FIXME: Conform to ABI ([[obj retain] autorelease]).
- FD = SynthBlockInitFunctionDecl((*I)->getName());
+ FD = SynthBlockInitFunctionDecl((*I)->getIdentifierName());
Exp = new DeclRefExpr(FD, FD->getType(), SourceLocation());
} else if (isBlockPointerType((*I)->getType())) {
- FD = SynthBlockInitFunctionDecl((*I)->getName());
+ FD = SynthBlockInitFunctionDecl((*I)->getIdentifierName());
Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
Exp = new CStyleCastExpr(Context->VoidPtrTy, Arg,
Context->VoidPtrTy, SourceLocation(), SourceLocation());
} else {
- FD = SynthBlockInitFunctionDecl((*I)->getName());
+ FD = SynthBlockInitFunctionDecl((*I)->getIdentifierName());
Exp = new DeclRefExpr(FD, FD->getType(), SourceLocation());
}
InitExprs.push_back(Exp);
@@ -3828,7 +3829,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp) {
// Output all "by ref" declarations.
for (llvm::SmallPtrSet::iterator I = BlockByRefDecls.begin(),
E = BlockByRefDecls.end(); I != E; ++I) {
- FD = SynthBlockInitFunctionDecl((*I)->getName());
+ FD = SynthBlockInitFunctionDecl((*I)->getIdentifierName());
Exp = new DeclRefExpr(FD, FD->getType(), SourceLocation());
Exp = new UnaryOperator(Exp, UnaryOperator::AddrOf,
Context->getPointerType(Exp->getType()),
@@ -4064,7 +4065,8 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
if (VD->getInit()) {
GlobalVarDecl = VD;
RewriteFunctionBodyOrGlobalInitializer(VD->getInit());
- SynthesizeBlockLiterals(VD->getTypeSpecStartLoc(), VD->getName());
+ SynthesizeBlockLiterals(VD->getTypeSpecStartLoc(),
+ VD->getIdentifierName());
GlobalVarDecl = 0;
// This is needed for blocks.
diff --git a/clang/docs/InternalsManual.html b/clang/docs/InternalsManual.html
index 1e1fc990adc5..adfa7c3e7481 100644
--- a/clang/docs/InternalsManual.html
+++ b/clang/docs/InternalsManual.html
@@ -37,6 +37,7 @@
@@ -442,6 +443,107 @@ the low bit of the pointer to the Type object. This means that QualType is
exactly the same size as a pointer, and this works fine on any system where
malloc'd objects are at least 8 byte aligned.
+
+Declaration names
+
+
+The DeclarationName class represents the name of a
+ declaration in Clang. Declarations in the C family of languages can
+ take several different forms. Most declarations are named by are
+ simple identifiers, e.g., "f
" and "x
" in
+ the function declaration f(int x)
. In C++, declaration
+ names can also name class constructors ("Class
"
+ in struct Class { Class(); }
), class destructors
+ ("~Class
"), overloaded operator names ("operator+"),
+ and conversion functions ("operator void const *
"). In
+ Objective-C, declaration names can refer to the names of Objective-C
+ methods, which involve the method name and the parameters,
+ collectively called a selector, e.g..,
+ "setWidth:height:
". Since all of these kinds of
+ entities--variables, functions, Objective-C methods, C++
+ constructors, destructors, and operators---are represented as
+ subclasses of Clang's common NamedDecl
+ class, DeclarationName
is designed to efficiently
+ represent any kind of name.
+
+Given
+ a DeclarationName
N
, N.getNameKind()
+ will produce a valid that describes what kind of name N
+ stores. There are 7 options (all of the names are inside
+ the DeclarationName
class)
+
+ - Identifier
+ - The name is a simple
+ identifier. Use
N.getAsIdentifierInfo()
to retrieve the
+ corresponding IdentifierInfo*
pointing to the actual
+ identifier. Note that C++ overloaded operators (e.g.,
+ "operator+
") are represented as special kinds of
+ identifiers. Use IdentifierInfo
's getOverloadedOperatorID
+ function to determine whether an identifier is an overloaded
+ operator name.
+
+ - ObjCZeroArgSelector, ObjCOneArgSelector,
+ ObjCMultiArgSelector
+ - The name is an Objective-C selector, which can be retrieved as a
+
Selector
instance
+ via N.getObjCSelector()
. The three possible name
+ kinds for Objective-C reflect an optimization within
+ the DeclarationName
class: both zero- and
+ one-argument selectors are stored as a
+ masked IdentifierInfo
pointer, and therefore require
+ very little space, since zero- and one-argument selectors are far
+ more common than multi-argument selectors (which use a different
+ structure).
+
+ - CXXConstructorName
+ - The name is a C++ constructor
+ name. Use
N.getCXXNameType()
to retrieve
+ the type that this constructor is meant to
+ construct. The type is always the canonical type, since all
+ constructors for a given type have the same name.
+
+ - CXXDestructorName
+ - The name is a C++ destructor
+ name. Use
N.getCXXNameType()
to retrieve
+ the type whose destructor is being
+ named. This type is always a canonical type.
+
+ - CXXConversionFunctionName
+ - The name is a C++ conversion function. Conversion functions are
+ named according to the type they convert to, e.g., "
operator void
+ const *
". Use N.getCXXNameType()
to retrieve
+ the type that this conversion function converts to. This type is
+ always a canonical type.
+
+
+DeclarationName
s are cheap to create, copy, and
+ compare. They require only a single pointer's worth of storage in
+ the common cases (identifiers, C++ overloaded operator names, zero-
+ and one-argument Objective-C selectors) and use dense, uniqued
+ storage for the other kinds of
+ names. Two DeclarationName
s can be compared for
+ equality (==
, !=
) using a simple bitwise
+ comparison, can be ordered
+ with <
, >
, <=
,
+ and >=
(which provide a lexicographical ordering for
+ normal identifiers but an unspecified ordering for other kinds of
+ names), and can be placed into LLVM DenseMap
s
+ and DenseSet
s.
+
+DeclarationName
instances can be created in different
+ ways depending on what kind of name the instance will store. Normal
+ identifiers (IdentifierInfo
pointers), including
+ overloaded operator names, and Objective-C selectors
+ (Selector
) can be implicitly converted
+ to DeclarationName
s. Names for C++ constructors,
+ destructors, and conversion functions can be retrieved from
+ the DeclarationNameTable
, an instance of which is
+ available as ASTContext::DeclarationNames
. The member
+ functions getCXXConstructorName
, getCXXDestructorName
,
+ and getCXXConversionFunctionName
, respectively,
+ return DeclarationName
instances for the three kinds of
+ C++ special function names.
+
The CFG class
@@ -736,4 +838,4 @@ interacts with constant evaluation: