[cfe-commits] r84437 - in /cfe/trunk/lib: AST/DeclarationName.cpp AST/Type.cpp Analysis/GRExprEngine.cpp CodeGen/Mangle.cpp Frontend/PrintPreprocessedOutput.cpp Frontend/RewriteMacros.cpp Frontend/RewriteObjC.cpp Parse/ParseStmt.cpp Sema/SemaDecl.cpp
Daniel Dunbar
daniel at zuster.org
Sun Oct 18 13:26:28 PDT 2009
Author: ddunbar
Date: Sun Oct 18 15:26:27 2009
New Revision: 84437
URL: http://llvm.org/viewvc/llvm-project?rev=84437&view=rev
Log:
Move misc clients to IdentifierInfo StringRef API.
- strcmp -> ==
- OS.write(II->getName() ...) -> OS << II->getNameStr()
- Avoid std::string concatenation
- Use getNameStr().str() when an std::string is really needed.
Modified:
cfe/trunk/lib/AST/DeclarationName.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Analysis/GRExprEngine.cpp
cfe/trunk/lib/CodeGen/Mangle.cpp
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/lib/Frontend/RewriteMacros.cpp
cfe/trunk/lib/Frontend/RewriteObjC.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=84437&r1=84436&r2=84437&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclarationName.cpp (original)
+++ cfe/trunk/lib/AST/DeclarationName.cpp Sun Oct 18 15:26:27 2009
@@ -51,7 +51,7 @@
bool operator<(DeclarationName LHS, DeclarationName RHS) {
if (IdentifierInfo *LhsId = LHS.getAsIdentifierInfo())
if (IdentifierInfo *RhsId = RHS.getAsIdentifierInfo())
- return strcmp(LhsId->getName(), RhsId->getName()) < 0;
+ return LhsId->getNameStr() < RhsId->getNameStr();
return LHS.getAsOpaqueInteger() < RHS.getAsOpaqueInteger();
}
Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=84437&r1=84436&r2=84437&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Sun Oct 18 15:26:27 2009
@@ -1254,7 +1254,7 @@
void TypedefType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const {
if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
InnerString = ' ' + InnerString;
- InnerString = getDecl()->getIdentifier()->getName() + InnerString;
+ InnerString = getDecl()->getIdentifier()->getNameStr().str() + InnerString;
}
void TemplateTypeParmType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const {
@@ -1265,7 +1265,7 @@
InnerString = "type-parameter-" + llvm::utostr_32(Depth) + '-' +
llvm::utostr_32(Index) + InnerString;
else
- InnerString = Name->getName() + InnerString;
+ InnerString = Name->getNameStr().str() + InnerString;
}
void SubstTemplateTypeParmType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const {
@@ -1541,7 +1541,7 @@
TemplateArgs.getFlatArgumentList(),
TemplateArgs.flat_size(),
Policy);
- MyPart = Spec->getIdentifier()->getName() + TemplateArgsStr;
+ MyPart = Spec->getIdentifier()->getNameStr().str() + TemplateArgsStr;
} else if (TagDecl *Tag = dyn_cast<TagDecl>(DC)) {
if (TypedefDecl *Typedef = Tag->getTypedefForAnonDecl())
MyPart = Typedef->getIdentifier()->getName();
Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=84437&r1=84436&r2=84437&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Sun Oct 18 15:26:27 2009
@@ -207,7 +207,7 @@
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
// Precondition: the first argument of 'main' is an integer guaranteed
// to be > 0.
- if (strcmp(FD->getIdentifier()->getName(), "main") == 0 &&
+ if (FD->getIdentifier()->getNameStr() == "main" &&
FD->getNumParams() > 0) {
const ParmVarDecl *PD = FD->getParamDecl(0);
QualType T = PD->getType();
Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=84437&r1=84436&r2=84437&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Sun Oct 18 15:26:27 2009
@@ -1236,10 +1236,7 @@
if (!isCharType(TemplateArgs[0].getAsType()))
return false;
- if (strcmp(SD->getIdentifier()->getName(), Name) != 0)
- return false;
-
- return true;
+ return SD->getIdentifier()->getNameStr() == Name;
}
bool CXXNameMangler::mangleStandardSubstitution(const NamedDecl *ND) {
Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=84437&r1=84436&r2=84437&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Sun Oct 18 15:26:27 2009
@@ -399,7 +399,7 @@
}
if (IdentifierInfo *II = Tok.getIdentifierInfo()) {
- OS.write(II->getName(), II->getLength());
+ OS << II->getNameStr();
} else if (Tok.isLiteral() && !Tok.needsCleaning() &&
Tok.getLiteralData()) {
OS.write(Tok.getLiteralData(), Tok.getLength());
@@ -434,7 +434,7 @@
struct SortMacrosByID {
typedef std::pair<IdentifierInfo*, MacroInfo*> id_macro_pair;
bool operator()(const id_macro_pair &LHS, const id_macro_pair &RHS) const {
- return strcmp(LHS.first->getName(), RHS.first->getName()) < 0;
+ return LHS.first->getNameStr() < RHS.first->getNameStr();
}
};
}
Modified: cfe/trunk/lib/Frontend/RewriteMacros.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteMacros.cpp?rev=84437&r1=84436&r2=84437&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/RewriteMacros.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteMacros.cpp Sun Oct 18 15:26:27 2009
@@ -128,13 +128,13 @@
// comment the line out.
if (RawTokens[CurRawTok].is(tok::identifier)) {
const IdentifierInfo *II = RawTokens[CurRawTok].getIdentifierInfo();
- if (!strcmp(II->getName(), "warning")) {
+ if (II->getNameStr() == "warning") {
// Comment out #warning.
RB.InsertTextAfter(SM.getFileOffset(RawTok.getLocation()), "//");
- } else if (!strcmp(II->getName(), "pragma") &&
+ } else if (II->getNameStr() == "pragma" &&
RawTokens[CurRawTok+1].is(tok::identifier) &&
- !strcmp(RawTokens[CurRawTok+1].getIdentifierInfo()->getName(),
- "mark")){
+ (RawTokens[CurRawTok+1].getIdentifierInfo()->getNameStr() ==
+ "mark")) {
// Comment out #pragma mark.
RB.InsertTextAfter(SM.getFileOffset(RawTok.getLocation()), "//");
}
Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=84437&r1=84436&r2=84437&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Sun Oct 18 15:26:27 2009
@@ -675,7 +675,7 @@
S = "((struct ";
S += ClassDecl->getIdentifier()->getName();
S += "_IMPL *)self)->";
- S += OID->getNameAsCString();
+ S += OID->getName();
return S;
}
@@ -2265,7 +2265,7 @@
if (clsName) { // class message.
// FIXME: We need to fix Sema (and the AST for ObjCMessageExpr) to handle
// the 'super' idiom within a class method.
- if (!strcmp(clsName->getName(), "super")) {
+ if (clsName->getNameStr() == "super") {
MsgSendFlavor = MsgSendSuperFunctionDecl;
if (MsgSendStretFlavor)
MsgSendStretFlavor = MsgSendSuperStretFunctionDecl;
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=84437&r1=84436&r2=84437&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Sun Oct 18 15:26:27 2009
@@ -1256,6 +1256,8 @@
/// asm-string-literal '(' expression ')'
/// '[' identifier ']' asm-string-literal '(' expression ')'
///
+//
+// FIXME: Avoid unnecessary std::string trashing.
bool Parser::ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names,
llvm::SmallVectorImpl<ExprTy*> &Constraints,
llvm::SmallVectorImpl<ExprTy*> &Exprs) {
@@ -1281,7 +1283,7 @@
IdentifierInfo *II = Tok.getIdentifierInfo();
ConsumeToken();
- Names.push_back(std::string(II->getName(), II->getLength()));
+ Names.push_back(II->getNameStr());
MatchRHSPunctuation(tok::r_square, Loc);
} else
Names.push_back(std::string());
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=84437&r1=84436&r2=84437&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Oct 18 15:26:27 2009
@@ -3727,12 +3727,13 @@
for (int i = FTI.NumArgs; i != 0; /* decrement in loop */) {
--i;
if (FTI.ArgInfo[i].Param == 0) {
- std::string Code = " int ";
- Code += FTI.ArgInfo[i].Ident->getName();
- Code += ";\n";
+ llvm::SmallString<256> Code;
+ llvm::raw_svector_ostream(Code) << " int "
+ << FTI.ArgInfo[i].Ident->getNameStr()
+ << ";\n";
Diag(FTI.ArgInfo[i].IdentLoc, diag::ext_param_not_declared)
<< FTI.ArgInfo[i].Ident
- << CodeModificationHint::CreateInsertion(LocAfterDecls, Code);
+ << CodeModificationHint::CreateInsertion(LocAfterDecls, Code.str());
// Implicitly declare the argument as type 'int' for lack of a better
// type.
More information about the cfe-commits
mailing list