Skip to content
Snippets Groups Projects
Commit 7a61f1e5 authored by Benjamin Kramer's avatar Benjamin Kramer
Browse files

Format: ArrayRefize some implicit copies away.

NFC.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219000 91177308-0d34-0410-b5e6-96231b3b80d8
parent 84b6e851
No related branches found
No related tags found
No related merge requests found
...@@ -505,7 +505,7 @@ std::string configurationAsText(const FormatStyle &Style); ...@@ -505,7 +505,7 @@ std::string configurationAsText(const FormatStyle &Style);
/// DEPRECATED: Do not use. /// DEPRECATED: Do not use.
tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex, tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
SourceManager &SourceMgr, SourceManager &SourceMgr,
std::vector<CharSourceRange> Ranges); ArrayRef<CharSourceRange> Ranges);
/// \brief Reformats the given \p Ranges in the file \p ID. /// \brief Reformats the given \p Ranges in the file \p ID.
/// ///
...@@ -517,13 +517,13 @@ tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex, ...@@ -517,13 +517,13 @@ tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
/// \p Style. /// \p Style.
tooling::Replacements reformat(const FormatStyle &Style, tooling::Replacements reformat(const FormatStyle &Style,
SourceManager &SourceMgr, FileID ID, SourceManager &SourceMgr, FileID ID,
std::vector<CharSourceRange> Ranges); ArrayRef<CharSourceRange> Ranges);
/// \brief Reformats the given \p Ranges in \p Code. /// \brief Reformats the given \p Ranges in \p Code.
/// ///
/// Otherwise identical to the reformat() function consuming a \c Lexer. /// Otherwise identical to the reformat() function consuming a \c Lexer.
tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
std::vector<tooling::Range> Ranges, ArrayRef<tooling::Range> Ranges,
StringRef FileName = "<stdin>"); StringRef FileName = "<stdin>");
/// \brief Returns the \c LangOpts that the formatter expects you to set. /// \brief Returns the \c LangOpts that the formatter expects you to set.
......
...@@ -1085,7 +1085,7 @@ private: ...@@ -1085,7 +1085,7 @@ private:
/// \p IndentForLevel must contain the indent for the level \c l /// \p IndentForLevel must contain the indent for the level \c l
/// at \p IndentForLevel[l], or a value < 0 if the indent for /// at \p IndentForLevel[l], or a value < 0 if the indent for
/// that level is unknown. /// that level is unknown.
unsigned getIndent(const std::vector<int> IndentForLevel, unsigned Level) { unsigned getIndent(ArrayRef<int> IndentForLevel, unsigned Level) {
if (IndentForLevel[Level] != -1) if (IndentForLevel[Level] != -1)
return IndentForLevel[Level]; return IndentForLevel[Level];
if (Level == 0) if (Level == 0)
...@@ -1775,7 +1775,7 @@ static StringRef getLanguageName(FormatStyle::LanguageKind Language) { ...@@ -1775,7 +1775,7 @@ static StringRef getLanguageName(FormatStyle::LanguageKind Language) {
class Formatter : public UnwrappedLineConsumer { class Formatter : public UnwrappedLineConsumer {
public: public:
Formatter(const FormatStyle &Style, SourceManager &SourceMgr, FileID ID, Formatter(const FormatStyle &Style, SourceManager &SourceMgr, FileID ID,
const std::vector<CharSourceRange> &Ranges) ArrayRef<CharSourceRange> Ranges)
: Style(Style), ID(ID), SourceMgr(SourceMgr), : Style(Style), ID(ID), SourceMgr(SourceMgr),
Whitespaces(SourceMgr, Style, Whitespaces(SourceMgr, Style,
inputUsesCRLF(SourceMgr.getBufferData(ID))), inputUsesCRLF(SourceMgr.getBufferData(ID))),
...@@ -2059,7 +2059,7 @@ private: ...@@ -2059,7 +2059,7 @@ private:
tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex, tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
SourceManager &SourceMgr, SourceManager &SourceMgr,
std::vector<CharSourceRange> Ranges) { ArrayRef<CharSourceRange> Ranges) {
if (Style.DisableFormat) if (Style.DisableFormat)
return tooling::Replacements(); return tooling::Replacements();
return reformat(Style, SourceMgr, return reformat(Style, SourceMgr,
...@@ -2068,7 +2068,7 @@ tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex, ...@@ -2068,7 +2068,7 @@ tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
tooling::Replacements reformat(const FormatStyle &Style, tooling::Replacements reformat(const FormatStyle &Style,
SourceManager &SourceMgr, FileID ID, SourceManager &SourceMgr, FileID ID,
std::vector<CharSourceRange> Ranges) { ArrayRef<CharSourceRange> Ranges) {
if (Style.DisableFormat) if (Style.DisableFormat)
return tooling::Replacements(); return tooling::Replacements();
Formatter formatter(Style, SourceMgr, ID, Ranges); Formatter formatter(Style, SourceMgr, ID, Ranges);
...@@ -2076,7 +2076,7 @@ tooling::Replacements reformat(const FormatStyle &Style, ...@@ -2076,7 +2076,7 @@ tooling::Replacements reformat(const FormatStyle &Style,
} }
tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
std::vector<tooling::Range> Ranges, ArrayRef<tooling::Range> Ranges,
StringRef FileName) { StringRef FileName) {
if (Style.DisableFormat) if (Style.DisableFormat)
return tooling::Replacements(); return tooling::Replacements();
...@@ -2095,9 +2095,9 @@ tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, ...@@ -2095,9 +2095,9 @@ tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
SourceMgr.createFileID(Entry, SourceLocation(), clang::SrcMgr::C_User); SourceMgr.createFileID(Entry, SourceLocation(), clang::SrcMgr::C_User);
SourceLocation StartOfFile = SourceMgr.getLocForStartOfFile(ID); SourceLocation StartOfFile = SourceMgr.getLocForStartOfFile(ID);
std::vector<CharSourceRange> CharRanges; std::vector<CharSourceRange> CharRanges;
for (unsigned i = 0, e = Ranges.size(); i != e; ++i) { for (const tooling::Range &Range : Ranges) {
SourceLocation Start = StartOfFile.getLocWithOffset(Ranges[i].getOffset()); SourceLocation Start = StartOfFile.getLocWithOffset(Range.getOffset());
SourceLocation End = Start.getLocWithOffset(Ranges[i].getLength()); SourceLocation End = Start.getLocWithOffset(Range.getLength());
CharRanges.push_back(CharSourceRange::getCharRange(Start, End)); CharRanges.push_back(CharSourceRange::getCharRange(Start, End));
} }
return reformat(Style, SourceMgr, ID, CharRanges); return reformat(Style, SourceMgr, ID, CharRanges);
......
...@@ -608,10 +608,9 @@ void CommentASTToXMLConverter::formatTextOfDeclaration( ...@@ -608,10 +608,9 @@ void CommentASTToXMLConverter::formatTextOfDeclaration(
.getLocWithOffset(0); .getLocWithOffset(0);
unsigned Length = Declaration.size(); unsigned Length = Declaration.size();
std::vector<CharSourceRange> Ranges(
1, CharSourceRange::getCharRange(Start, Start.getLocWithOffset(Length)));
tooling::Replacements Replace = reformat( tooling::Replacements Replace = reformat(
format::getLLVMStyle(), FormatRewriterContext.Sources, ID, Ranges); format::getLLVMStyle(), FormatRewriterContext.Sources, ID,
CharSourceRange::getCharRange(Start, Start.getLocWithOffset(Length)));
applyAllReplacements(Replace, FormatRewriterContext.Rewrite); applyAllReplacements(Replace, FormatRewriterContext.Rewrite);
Declaration = FormatRewriterContext.getRewrittenText(ID); Declaration = FormatRewriterContext.getRewrittenText(ID);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment