From: Daniel Dunbar Date: Sun, 18 Oct 2009 20:26:27 +0000 (+0000) Subject: Move misc clients to IdentifierInfo StringRef API. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ffe14ca96bd662de7820f6875d3f04789a640c1;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84437 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp index 4b31617f59..3ab9fa1904 100644 --- a/lib/AST/DeclarationName.cpp +++ b/lib/AST/DeclarationName.cpp @@ -51,7 +51,7 @@ public: 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(); } diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index cbd0691aad..205974b930 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -1254,7 +1254,7 @@ void FunctionProtoType::getAsStringInternal(std::string &S, const PrintingPolicy 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 @@ void TemplateTypeParmType::getAsStringInternal(std::string &InnerString, const P 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 @@ void TagType::getAsStringInternal(std::string &InnerString, const PrintingPolicy TemplateArgs.getFlatArgumentList(), TemplateArgs.flat_size(), Policy); - MyPart = Spec->getIdentifier()->getName() + TemplateArgsStr; + MyPart = Spec->getIdentifier()->getNameStr().str() + TemplateArgsStr; } else if (TagDecl *Tag = dyn_cast(DC)) { if (TypedefDecl *Typedef = Tag->getTypedefForAnonDecl()) MyPart = Typedef->getIdentifier()->getName(); diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index 46c5749189..a31260d4dd 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -207,7 +207,7 @@ const GRState* GRExprEngine::getInitialState(const LocationContext *InitLoc) { if (const FunctionDecl *FD = dyn_cast(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(); diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index 344ef06276..e4416ab42c 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/lib/CodeGen/Mangle.cpp @@ -1236,10 +1236,7 @@ static bool isCharSpecialization(QualType T, const char *Name) { 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) { diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index 492b31a0ec..3883228224 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -399,7 +399,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, } 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 @@ namespace { struct SortMacrosByID { typedef std::pair 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(); } }; } diff --git a/lib/Frontend/RewriteMacros.cpp b/lib/Frontend/RewriteMacros.cpp index d92f5c78e6..846d4767fa 100644 --- a/lib/Frontend/RewriteMacros.cpp +++ b/lib/Frontend/RewriteMacros.cpp @@ -128,13 +128,13 @@ void clang::RewriteMacrosInInput(Preprocessor &PP, llvm::raw_ostream *OS) { // 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()), "//"); } diff --git a/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp index bd3031aabe..f3ce9cda9f 100644 --- a/lib/Frontend/RewriteObjC.cpp +++ b/lib/Frontend/RewriteObjC.cpp @@ -675,7 +675,7 @@ static std::string getIvarAccessString(ObjCInterfaceDecl *ClassDecl, S = "((struct "; S += ClassDecl->getIdentifier()->getName(); S += "_IMPL *)self)->"; - S += OID->getNameAsCString(); + S += OID->getName(); return S; } @@ -2265,7 +2265,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp) { 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; diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 907ca802b4..6ef8d0db06 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -1256,6 +1256,8 @@ Parser::OwningStmtResult Parser::ParseAsmStatement(bool &msAsm) { /// asm-string-literal '(' expression ')' /// '[' identifier ']' asm-string-literal '(' expression ')' /// +// +// FIXME: Avoid unnecessary std::string trashing. bool Parser::ParseAsmOperandsOpt(llvm::SmallVectorImpl &Names, llvm::SmallVectorImpl &Constraints, llvm::SmallVectorImpl &Exprs) { @@ -1281,7 +1283,7 @@ bool Parser::ParseAsmOperandsOpt(llvm::SmallVectorImpl &Names, 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()); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 2893abbad2..531b6f344d 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3727,12 +3727,13 @@ void Sema::ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, 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.