Rename Selector::getName() to Selector::getAsString(), and add
a new NamedDecl::getAsString() method.
Change uses of Selector::getName() to just pass in a Selector
where possible (e.g. to diagnostics) instead of going through
an std::string.
This also adds new formatters for objcinstance and objcclass
as described in the dox.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59933 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index 70eeb94..d55d0f8 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -19,12 +19,9 @@
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
#include "llvm/ADT/StringExtras.h"
-
using namespace clang;
using namespace CodeGen;
-using llvm::utostr;
-
// FIXME: Name mangling should be moved to a separate class.
@@ -35,7 +32,7 @@
"Only one level of decl context mangling is currently supported!");
if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(D)) {
- S += utostr(FD->getIdentifier()->getLength());
+ S += llvm::utostr(FD->getIdentifier()->getLength());
S += FD->getIdentifier()->getName();
if (FD->param_size() == 0)
@@ -48,11 +45,11 @@
std::string Name;
Name += MD->isInstance() ? '-' : '+';
Name += '[';
- Name += MD->getClassInterface()->getName();
+ Name += MD->getClassInterface()->getNameAsString();
Name += ' ';
- Name += MD->getSelector().getName();
+ Name += MD->getSelector().getAsString();
Name += ']';
- S += utostr(Name.length());
+ S += llvm::utostr(Name.length());
S += Name;
} else
assert(0 && "Unsupported decl type!");
@@ -64,7 +61,7 @@
mangleDeclContextInternal(D.getDeclContext(), S);
S += 'E';
- S += utostr(D.getIdentifier()->getLength());
+ S += llvm::utostr(D.getIdentifier()->getLength());
S += D.getIdentifier()->getName();
}
diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp
index 25e3915..9bcd816 100644
--- a/lib/CodeGen/CGObjCGNU.cpp
+++ b/lib/CodeGen/CGObjCGNU.cpp
@@ -205,7 +205,7 @@
/// GetSelector - Return the pointer to the unique'd string for this selector.
llvm::Value *CGObjCGNU::GetSelector(CGBuilderTy &Builder, Selector Sel) {
// FIXME: uniquing on the string is wasteful, unique on Sel instead!
- llvm::GlobalAlias *&US = UntypedSelectors[Sel.getName()];
+ llvm::GlobalAlias *&US = UntypedSelectors[Sel.getAsString()];
if (US == 0)
US = new llvm::GlobalAlias(llvm::PointerType::getUnqual(SelectorTy),
llvm::GlobalValue::InternalLinkage,
@@ -370,13 +370,14 @@
std::vector<llvm::Constant*> Elements;
for (unsigned int i = 0, e = MethodTypes.size(); i < e; ++i) {
Elements.clear();
- llvm::Constant *C = CGM.GetAddrOfConstantCString(MethodSels[i].getName());
+ llvm::Constant *C =
+ CGM.GetAddrOfConstantCString(MethodSels[i].getAsString());
Elements.push_back(llvm::ConstantExpr::getGetElementPtr(C, Zeros, 2));
Elements.push_back(
llvm::ConstantExpr::getGetElementPtr(MethodTypes[i], Zeros, 2));
llvm::Constant *Method =
TheModule.getFunction(SymbolNameForMethod(ClassName, CategoryName,
- MethodSels[i].getName(),
+ MethodSels[i].getAsString(),
isClassMethodList));
Method = llvm::ConstantExpr::getBitCast(Method,
llvm::PointerType::getUnqual(IMPTy));
@@ -581,7 +582,7 @@
std::string TypeStr;
Context.getObjCEncodingForMethodDecl(*iter, TypeStr);
InstanceMethodNames.push_back(
- CGM.GetAddrOfConstantCString((*iter)->getSelector().getName()));
+ CGM.GetAddrOfConstantCString((*iter)->getSelector().getAsString()));
InstanceMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
}
// Collect information about class methods:
@@ -592,7 +593,7 @@
std::string TypeStr;
Context.getObjCEncodingForMethodDecl((*iter),TypeStr);
ClassMethodNames.push_back(
- CGM.GetAddrOfConstantCString((*iter)->getSelector().getName()));
+ CGM.GetAddrOfConstantCString((*iter)->getSelector().getAsString()));
ClassMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
}
@@ -932,9 +933,9 @@
llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD) {
const ObjCCategoryImplDecl *OCD =
dyn_cast<ObjCCategoryImplDecl>(OMD->getMethodContext());
- const std::string &CategoryName = OCD ? OCD->getName() : "";
- const std::string &ClassName = OMD->getClassInterface()->getName();
- const std::string &MethodName = OMD->getSelector().getName();
+ std::string CategoryName = OCD ? OCD->getNameAsString() : "";
+ std::string ClassName = OMD->getClassInterface()->getNameAsString();
+ std::string MethodName = OMD->getSelector().getAsString();
bool isClassMethod = !OMD->isInstance();
const llvm::FunctionType *MethodTy =
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index 8eb81a4..f9a4d77 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -2065,7 +2065,8 @@
llvm::GlobalVariable *&Entry = MethodVarNames[Sel];
if (!Entry) {
- llvm::Constant *C = llvm::ConstantArray::get(Sel.getName());
+ // FIXME: Avoid std::string copying.
+ llvm::Constant *C = llvm::ConstantArray::get(Sel.getAsString());
Entry =
new llvm::GlobalVariable(C->getType(), false,
llvm::GlobalValue::InternalLinkage,
@@ -2143,14 +2144,12 @@
void CGObjCMac::GetNameForMethod(const ObjCMethodDecl *D,
std::string &NameOut) {
// FIXME: Find the mangling GCC uses.
- std::stringstream s;
- s << (D->isInstance() ? "-" : "+");
- s << "[";
- s << D->getClassInterface()->getName();
- s << " ";
- s << D->getSelector().getName();
- s << "]";
- NameOut = s.str();
+ NameOut = (D->isInstance() ? "-" : "+");
+ NameOut += '[';
+ NameOut += D->getClassInterface()->getName();
+ NameOut += ' ';
+ NameOut += D->getSelector().getAsString();
+ NameOut += ']';
}
void CGObjCMac::FinishModule() {