本文整理汇总了C++中FileOffset::getOffset方法的典型用法代码示例。如果您正苦于以下问题:C++ FileOffset::getOffset方法的具体用法?C++ FileOffset::getOffset怎么用?C++ FileOffset::getOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileOffset
的用法示例。
在下文中一共展示了FileOffset::getOffset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSourceText
StringRef EditedSource::getSourceText(FileOffset BeginOffs, FileOffset EndOffs,
bool &Invalid) {
assert(BeginOffs.getFID() == EndOffs.getFID());
assert(BeginOffs <= EndOffs);
SourceLocation BLoc = SourceMgr.getLocForStartOfFile(BeginOffs.getFID());
BLoc = BLoc.getLocWithOffset(BeginOffs.getOffset());
assert(BLoc.isFileID());
SourceLocation
ELoc = BLoc.getLocWithOffset(EndOffs.getOffset() - BeginOffs.getOffset());
return Lexer::getSourceText(CharSourceRange::getCharRange(BLoc, ELoc),
SourceMgr, LangOpts, &Invalid);
}
示例2: applyRewrite
static void applyRewrite(EditsReceiver &receiver,
StringRef text, FileOffset offs, unsigned len,
const SourceManager &SM, const LangOptions &LangOpts) {
assert(!offs.getFID().isInvalid());
SourceLocation Loc = SM.getLocForStartOfFile(offs.getFID());
Loc = Loc.getLocWithOffset(offs.getOffset());
assert(Loc.isFileID());
if (text.empty())
adjustRemoval(SM, LangOpts, Loc, offs, len, text);
CharSourceRange range = CharSourceRange::getCharRange(Loc,
Loc.getLocWithOffset(len));
if (text.empty()) {
assert(len);
receiver.remove(range);
return;
}
if (len)
receiver.replace(range, text);
else
receiver.insert(Loc, text);
}
示例3: adjustRemoval
/// \brief Check the range that we are going to remove and:
/// -Remove any trailing whitespace if possible.
/// -Insert a space if removing the range is going to mess up the source tokens.
static void adjustRemoval(const SourceManager &SM, const LangOptions &LangOpts,
SourceLocation Loc, FileOffset offs,
unsigned &len, StringRef &text) {
assert(len && text.empty());
SourceLocation BeginTokLoc = Lexer::GetBeginningOfToken(Loc, SM, LangOpts);
if (BeginTokLoc != Loc)
return; // the range is not at the beginning of a token, keep the range.
bool Invalid = false;
StringRef buffer = SM.getBufferData(offs.getFID(), &Invalid);
if (Invalid)
return;
unsigned begin = offs.getOffset();
unsigned end = begin + len;
// Do not try to extend the removal if we're at the end of the buffer already.
if (end == buffer.size())
return;
assert(begin < buffer.size() && end < buffer.size() && "Invalid range!");
// FIXME: Remove newline.
if (begin == 0) {
if (buffer[end] == ' ')
++len;
return;
}
if (buffer[end] == ' ') {
assert((end + 1 != buffer.size() || buffer.data()[end + 1] == 0) &&
"buffer not zero-terminated!");
if (canRemoveWhitespace(/*left=*/buffer[begin-1],
/*beforeWSpace=*/buffer[end-1],
/*right=*/buffer.data()[end + 1], // zero-terminated
LangOpts))
++len;
return;
}
if (!canBeJoined(buffer[begin-1], buffer[end], LangOpts))
text = " ";
}
示例4: adjustRemoval
/// \brief Check the range that we are going to remove and:
/// -Remove any trailing whitespace if possible.
/// -Insert a space if removing the range is going to mess up the source tokens.
static void adjustRemoval(const SourceManager &SM, const LangOptions &LangOpts,
SourceLocation Loc, FileOffset offs,
unsigned &len, StringRef &text) {
assert(len && text.empty());
SourceLocation BeginTokLoc = Lexer::GetBeginningOfToken(Loc, SM, LangOpts);
if (BeginTokLoc != Loc)
return; // the range is not at the beginning of a token, keep the range.
bool Invalid = false;
StringRef buffer = SM.getBufferData(offs.getFID(), &Invalid);
if (Invalid)
return;
unsigned begin = offs.getOffset();
unsigned end = begin + len;
// FIXME: Remove newline.
if (begin == 0) {
if (buffer[end] == ' ')
++len;
return;
}
if (buffer[end] == ' ') {
if (canRemoveWhitespace(/*left=*/buffer[begin-1],
/*beforeWSpace=*/buffer[end-1],
/*right=*/buffer[end+1],
LangOpts))
++len;
return;
}
if (!canBeJoined(buffer[begin-1], buffer[end], LangOpts))
text = " ";
}
示例5: commitRemove
void EditedSource::commitRemove(SourceLocation OrigLoc,
FileOffset BeginOffs, unsigned Len) {
if (Len == 0)
return;
FileOffset EndOffs = BeginOffs.getWithOffset(Len);
FileEditsTy::iterator I = FileEdits.upper_bound(BeginOffs);
if (I != FileEdits.begin())
--I;
for (; I != FileEdits.end(); ++I) {
FileEdit &FA = I->second;
FileOffset B = I->first;
FileOffset E = B.getWithOffset(FA.RemoveLen);
if (BeginOffs < E)
break;
}
FileOffset TopBegin, TopEnd;
FileEdit *TopFA = nullptr;
if (I == FileEdits.end()) {
FileEditsTy::iterator
NewI = FileEdits.insert(I, std::make_pair(BeginOffs, FileEdit()));
NewI->second.RemoveLen = Len;
return;
}
FileEdit &FA = I->second;
FileOffset B = I->first;
FileOffset E = B.getWithOffset(FA.RemoveLen);
if (BeginOffs < B) {
FileEditsTy::iterator
NewI = FileEdits.insert(I, std::make_pair(BeginOffs, FileEdit()));
TopBegin = BeginOffs;
TopEnd = EndOffs;
TopFA = &NewI->second;
TopFA->RemoveLen = Len;
} else {
TopBegin = B;
TopEnd = E;
TopFA = &I->second;
if (TopEnd >= EndOffs)
return;
unsigned diff = EndOffs.getOffset() - TopEnd.getOffset();
TopEnd = EndOffs;
TopFA->RemoveLen += diff;
if (B == BeginOffs)
TopFA->Text = StringRef();
++I;
}
while (I != FileEdits.end()) {
FileEdit &FA = I->second;
FileOffset B = I->first;
FileOffset E = B.getWithOffset(FA.RemoveLen);
if (B >= TopEnd)
break;
if (E <= TopEnd) {
FileEdits.erase(I++);
continue;
}
if (B < TopEnd) {
unsigned diff = E.getOffset() - TopEnd.getOffset();
TopEnd = E;
TopFA->RemoveLen += diff;
FileEdits.erase(I);
}
break;
}
}