forked from OSchip/llvm-project
[clang][NFC] Use SmallString instead of SmallVector<char
Simplifies code in some places and is more explicit about what is being used. No additional includes were added here so no impact on compile time.
This commit is contained in:
parent
0765d78a41
commit
d44edfc109
|
@ -150,7 +150,7 @@ void State::addCallStack(unsigned Limit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SmallVector<char, 128> Buffer;
|
SmallString<128> Buffer;
|
||||||
llvm::raw_svector_ostream Out(Buffer);
|
llvm::raw_svector_ostream Out(Buffer);
|
||||||
F->describe(Out);
|
F->describe(Out);
|
||||||
addDiag(CallLocation, diag::note_constexpr_call_here) << Out.str();
|
addDiag(CallLocation, diag::note_constexpr_call_here) << Out.str();
|
||||||
|
|
|
@ -1418,7 +1418,7 @@ void JSONNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *FPL) {
|
||||||
JOS.attribute("value", FPL->getValueAsString(/*Radix=*/10));
|
JOS.attribute("value", FPL->getValueAsString(/*Radix=*/10));
|
||||||
}
|
}
|
||||||
void JSONNodeDumper::VisitFloatingLiteral(const FloatingLiteral *FL) {
|
void JSONNodeDumper::VisitFloatingLiteral(const FloatingLiteral *FL) {
|
||||||
llvm::SmallVector<char, 16> Buffer;
|
llvm::SmallString<16> Buffer;
|
||||||
FL->getValue().toString(Buffer);
|
FL->getValue().toString(Buffer);
|
||||||
JOS.attribute("value", Buffer);
|
JOS.attribute("value", Buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -808,7 +808,7 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
|
||||||
/// QualTypeVals - Pass a vector of arrays so that QualType names can be
|
/// QualTypeVals - Pass a vector of arrays so that QualType names can be
|
||||||
/// compared to see if more information is needed to be printed.
|
/// compared to see if more information is needed to be printed.
|
||||||
SmallVector<intptr_t, 2> QualTypeVals;
|
SmallVector<intptr_t, 2> QualTypeVals;
|
||||||
SmallVector<char, 64> Tree;
|
SmallString<64> Tree;
|
||||||
|
|
||||||
for (unsigned i = 0, e = getNumArgs(); i < e; ++i)
|
for (unsigned i = 0, e = getNumArgs(); i < e; ++i)
|
||||||
if (getArgKind(i) == DiagnosticsEngine::ak_qualtype)
|
if (getArgKind(i) == DiagnosticsEngine::ak_qualtype)
|
||||||
|
|
|
@ -162,8 +162,7 @@ parseCrossTUIndex(StringRef IndexPath) {
|
||||||
StringRef LookupName = LineRef.substr(0, Delimiter);
|
StringRef LookupName = LineRef.substr(0, Delimiter);
|
||||||
|
|
||||||
// Store paths with posix-style directory separator.
|
// Store paths with posix-style directory separator.
|
||||||
SmallVector<char, 32> FilePath;
|
SmallString<32> FilePath(LineRef.substr(Delimiter + 1));
|
||||||
llvm::Twine{LineRef.substr(Delimiter + 1)}.toVector(FilePath);
|
|
||||||
llvm::sys::path::native(FilePath, llvm::sys::path::Style::posix);
|
llvm::sys::path::native(FilePath, llvm::sys::path::Style::posix);
|
||||||
|
|
||||||
bool InsertionOccured;
|
bool InsertionOccured;
|
||||||
|
@ -624,15 +623,14 @@ parseInvocationList(StringRef FileContent, llvm::sys::path::Style PathStyle) {
|
||||||
return llvm::make_error<IndexError>(
|
return llvm::make_error<IndexError>(
|
||||||
index_error_code::invocation_list_wrong_format);
|
index_error_code::invocation_list_wrong_format);
|
||||||
|
|
||||||
SmallVector<char, 32> ValueStorage;
|
SmallString<32> ValueStorage;
|
||||||
StringRef SourcePath = Key->getValue(ValueStorage);
|
StringRef SourcePath = Key->getValue(ValueStorage);
|
||||||
|
|
||||||
// Store paths with PathStyle directory separator.
|
// Store paths with PathStyle directory separator.
|
||||||
SmallVector<char, 32> NativeSourcePath;
|
SmallString<32> NativeSourcePath(SourcePath);
|
||||||
llvm::Twine{SourcePath}.toVector(NativeSourcePath);
|
|
||||||
llvm::sys::path::native(NativeSourcePath, PathStyle);
|
llvm::sys::path::native(NativeSourcePath, PathStyle);
|
||||||
|
|
||||||
StringRef InvocationKey{NativeSourcePath.begin(), NativeSourcePath.size()};
|
StringRef InvocationKey(NativeSourcePath);
|
||||||
|
|
||||||
if (InvocationList.find(InvocationKey) != InvocationList.end())
|
if (InvocationList.find(InvocationKey) != InvocationList.end())
|
||||||
return llvm::make_error<IndexError>(
|
return llvm::make_error<IndexError>(
|
||||||
|
|
|
@ -1818,7 +1818,7 @@ bool Sema::findMacroSpelling(SourceLocation &locref, StringRef name) {
|
||||||
loc = getSourceManager().getExpansionLoc(loc);
|
loc = getSourceManager().getExpansionLoc(loc);
|
||||||
|
|
||||||
// If that's written with the name, stop here.
|
// If that's written with the name, stop here.
|
||||||
SmallVector<char, 16> buffer;
|
SmallString<16> buffer;
|
||||||
if (getPreprocessor().getSpelling(loc, buffer) == name) {
|
if (getPreprocessor().getSpelling(loc, buffer) == name) {
|
||||||
locref = loc;
|
locref = loc;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -584,7 +584,7 @@ void Sema::PrintInstantiationStack() {
|
||||||
|
|
||||||
case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: {
|
case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: {
|
||||||
TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
|
TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
|
||||||
SmallVector<char, 128> TemplateArgsStr;
|
SmallString<128> TemplateArgsStr;
|
||||||
llvm::raw_svector_ostream OS(TemplateArgsStr);
|
llvm::raw_svector_ostream OS(TemplateArgsStr);
|
||||||
Template->printName(OS);
|
Template->printName(OS);
|
||||||
printTemplateArgumentList(OS, Active->template_arguments(),
|
printTemplateArgumentList(OS, Active->template_arguments(),
|
||||||
|
@ -650,7 +650,7 @@ void Sema::PrintInstantiationStack() {
|
||||||
ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
|
ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
|
||||||
FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext());
|
FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext());
|
||||||
|
|
||||||
SmallVector<char, 128> TemplateArgsStr;
|
SmallString<128> TemplateArgsStr;
|
||||||
llvm::raw_svector_ostream OS(TemplateArgsStr);
|
llvm::raw_svector_ostream OS(TemplateArgsStr);
|
||||||
FD->printName(OS);
|
FD->printName(OS);
|
||||||
printTemplateArgumentList(OS, Active->template_arguments(),
|
printTemplateArgumentList(OS, Active->template_arguments(),
|
||||||
|
@ -802,7 +802,7 @@ void Sema::PrintInstantiationStack() {
|
||||||
assert(isa<FunctionDecl>(Active->Entity));
|
assert(isa<FunctionDecl>(Active->Entity));
|
||||||
DiagID = diag::note_checking_constraints_for_function_here;
|
DiagID = diag::note_checking_constraints_for_function_here;
|
||||||
}
|
}
|
||||||
SmallVector<char, 128> TemplateArgsStr;
|
SmallString<128> TemplateArgsStr;
|
||||||
llvm::raw_svector_ostream OS(TemplateArgsStr);
|
llvm::raw_svector_ostream OS(TemplateArgsStr);
|
||||||
cast<NamedDecl>(Active->Entity)->printName(OS);
|
cast<NamedDecl>(Active->Entity)->printName(OS);
|
||||||
if (!isa<FunctionDecl>(Active->Entity))
|
if (!isa<FunctionDecl>(Active->Entity))
|
||||||
|
|
|
@ -1622,7 +1622,7 @@ namespace {
|
||||||
ASTWriter &Writer;
|
ASTWriter &Writer;
|
||||||
|
|
||||||
// Keep track of the framework names we've used during serialization.
|
// Keep track of the framework names we've used during serialization.
|
||||||
SmallVector<char, 128> FrameworkStringData;
|
SmallString<128> FrameworkStringData;
|
||||||
llvm::StringMap<unsigned> FrameworkNameOffset;
|
llvm::StringMap<unsigned> FrameworkNameOffset;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -1709,8 +1709,7 @@ namespace {
|
||||||
= FrameworkNameOffset.find(Data.HFI.Framework);
|
= FrameworkNameOffset.find(Data.HFI.Framework);
|
||||||
if (Pos == FrameworkNameOffset.end()) {
|
if (Pos == FrameworkNameOffset.end()) {
|
||||||
Offset = FrameworkStringData.size() + 1;
|
Offset = FrameworkStringData.size() + 1;
|
||||||
FrameworkStringData.append(Data.HFI.Framework.begin(),
|
FrameworkStringData.append(Data.HFI.Framework);
|
||||||
Data.HFI.Framework.end());
|
|
||||||
FrameworkStringData.push_back(0);
|
FrameworkStringData.push_back(0);
|
||||||
|
|
||||||
FrameworkNameOffset[Data.HFI.Framework] = Offset;
|
FrameworkNameOffset[Data.HFI.Framework] = Offset;
|
||||||
|
|
|
@ -905,7 +905,7 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The output buffer, into which the global index will be written.
|
// The output buffer, into which the global index will be written.
|
||||||
SmallVector<char, 16> OutputBuffer;
|
SmallString<16> OutputBuffer;
|
||||||
{
|
{
|
||||||
llvm::BitstreamWriter OutputStream(OutputBuffer);
|
llvm::BitstreamWriter OutputStream(OutputBuffer);
|
||||||
if (Builder.writeIndex(OutputStream))
|
if (Builder.writeIndex(OutputStream))
|
||||||
|
@ -913,9 +913,8 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr,
|
||||||
"failed writing index");
|
"failed writing index");
|
||||||
}
|
}
|
||||||
|
|
||||||
return llvm::writeFileAtomically(
|
return llvm::writeFileAtomically((IndexPath + "-%%%%%%%%").str(), IndexPath,
|
||||||
(IndexPath + "-%%%%%%%%").str(), IndexPath,
|
OutputBuffer);
|
||||||
llvm::StringRef(OutputBuffer.data(), OutputBuffer.size()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -93,7 +93,7 @@ StringRef CheckerContext::getMacroNameOrSpelling(SourceLocation &Loc) {
|
||||||
if (Loc.isMacroID())
|
if (Loc.isMacroID())
|
||||||
return Lexer::getImmediateMacroName(Loc, getSourceManager(),
|
return Lexer::getImmediateMacroName(Loc, getSourceManager(),
|
||||||
getLangOpts());
|
getLangOpts());
|
||||||
SmallVector<char, 16> buf;
|
SmallString<16> buf;
|
||||||
return Lexer::getSpelling(Loc, buf, getSourceManager(), getLangOpts());
|
return Lexer::getSpelling(Loc, buf, getSourceManager(), getLangOpts());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,13 +133,13 @@ const NamedDecl *getNamedDeclFor(const ASTContext &Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getUSRForDecl(const Decl *Decl) {
|
std::string getUSRForDecl(const Decl *Decl) {
|
||||||
llvm::SmallVector<char, 128> Buff;
|
llvm::SmallString<128> Buff;
|
||||||
|
|
||||||
// FIXME: Add test for the nullptr case.
|
// FIXME: Add test for the nullptr case.
|
||||||
if (Decl == nullptr || index::generateUSRForDecl(Decl, Buff))
|
if (Decl == nullptr || index::generateUSRForDecl(Decl, Buff))
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
return std::string(Buff.data(), Buff.size());
|
return std::string(Buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace tooling
|
} // end namespace tooling
|
||||||
|
|
Loading…
Reference in New Issue