/// DEPRECATED: Do not use.
tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
SourceManager &SourceMgr,
- std::vector<CharSourceRange> Ranges);
+ ArrayRef<CharSourceRange> Ranges);
/// \brief Reformats the given \p Ranges in the file \p ID.
///
/// \p Style.
tooling::Replacements reformat(const FormatStyle &Style,
SourceManager &SourceMgr, FileID ID,
- std::vector<CharSourceRange> Ranges);
+ ArrayRef<CharSourceRange> Ranges);
/// \brief Reformats the given \p Ranges in \p Code.
///
/// Otherwise identical to the reformat() function consuming a \c Lexer.
tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
- std::vector<tooling::Range> Ranges,
+ ArrayRef<tooling::Range> Ranges,
StringRef FileName = "<stdin>");
/// \brief Returns the \c LangOpts that the formatter expects you to set.
/// \p IndentForLevel must contain the indent for the level \c l
/// at \p IndentForLevel[l], or a value < 0 if the indent for
/// that level is unknown.
- unsigned getIndent(const std::vector<int> IndentForLevel, unsigned Level) {
+ unsigned getIndent(ArrayRef<int> IndentForLevel, unsigned Level) {
if (IndentForLevel[Level] != -1)
return IndentForLevel[Level];
if (Level == 0)
class Formatter : public UnwrappedLineConsumer {
public:
Formatter(const FormatStyle &Style, SourceManager &SourceMgr, FileID ID,
- const std::vector<CharSourceRange> &Ranges)
+ ArrayRef<CharSourceRange> Ranges)
: Style(Style), ID(ID), SourceMgr(SourceMgr),
Whitespaces(SourceMgr, Style,
inputUsesCRLF(SourceMgr.getBufferData(ID))),
tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
SourceManager &SourceMgr,
- std::vector<CharSourceRange> Ranges) {
+ ArrayRef<CharSourceRange> Ranges) {
if (Style.DisableFormat)
return tooling::Replacements();
return reformat(Style, SourceMgr,
tooling::Replacements reformat(const FormatStyle &Style,
SourceManager &SourceMgr, FileID ID,
- std::vector<CharSourceRange> Ranges) {
+ ArrayRef<CharSourceRange> Ranges) {
if (Style.DisableFormat)
return tooling::Replacements();
Formatter formatter(Style, SourceMgr, ID, Ranges);
}
tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
- std::vector<tooling::Range> Ranges,
+ ArrayRef<tooling::Range> Ranges,
StringRef FileName) {
if (Style.DisableFormat)
return tooling::Replacements();
SourceMgr.createFileID(Entry, SourceLocation(), clang::SrcMgr::C_User);
SourceLocation StartOfFile = SourceMgr.getLocForStartOfFile(ID);
std::vector<CharSourceRange> CharRanges;
- for (unsigned i = 0, e = Ranges.size(); i != e; ++i) {
- SourceLocation Start = StartOfFile.getLocWithOffset(Ranges[i].getOffset());
- SourceLocation End = Start.getLocWithOffset(Ranges[i].getLength());
+ for (const tooling::Range &Range : Ranges) {
+ SourceLocation Start = StartOfFile.getLocWithOffset(Range.getOffset());
+ SourceLocation End = Start.getLocWithOffset(Range.getLength());
CharRanges.push_back(CharSourceRange::getCharRange(Start, End));
}
return reformat(Style, SourceMgr, ID, CharRanges);
.getLocWithOffset(0);
unsigned Length = Declaration.size();
- std::vector<CharSourceRange> Ranges(
- 1, CharSourceRange::getCharRange(Start, Start.getLocWithOffset(Length)));
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);
Declaration = FormatRewriterContext.getRewrittenText(ID);
}