本文整理汇总了C++中ClangNode::getSourceRange方法的典型用法代码示例。如果您正苦于以下问题:C++ ClangNode::getSourceRange方法的具体用法?C++ ClangNode::getSourceRange怎么用?C++ ClangNode::getSourceRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClangNode
的用法示例。
在下文中一共展示了ClangNode::getSourceRange方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shouldPrintNewLineBefore
bool ClangCommentPrinter::shouldPrintNewLineBefore(ClangNode Node) const {
assert(Node);
const auto &Ctx = ClangLoader.getClangASTContext();
const auto &SM = Ctx.getSourceManager();
clang::SourceLocation NodeLoc =
SM.getFileLoc(Node.getSourceRange().getBegin());
if (NodeLoc.isInvalid())
return false;
unsigned NodeLineNo = SM.getSpellingLineNumber(NodeLoc);
clang::FileID FID = SM.getFileID(NodeLoc);
if (FID.isInvalid())
return false;
unsigned LastEntiyLine = 0;
auto It = LastEntityLines.find(FID);
if (It != LastEntityLines.end())
LastEntiyLine = It->second;
return (NodeLineNo > LastEntiyLine) && NodeLineNo - LastEntiyLine > 1;
}
示例2: printCommentsUntil
void ClangCommentPrinter::printCommentsUntil(ClangNode Node) {
const auto &Ctx = ClangLoader.getClangASTContext();
const auto &SM = Ctx.getSourceManager();
clang::SourceLocation NodeLoc =
SM.getFileLoc(Node.getSourceRange().getBegin());
if (NodeLoc.isInvalid())
return;
unsigned NodeLineNo = SM.getSpellingLineNumber(NodeLoc);
clang::FileID FID = SM.getFileID(NodeLoc);
if (FID.isInvalid())
return;
clang::SourceLocation FileLoc = SM.getLocForStartOfFile(FID);
StringRef Text = SM.getBufferData(FID);
if (Text.empty())
return;
const char *BufStart = Text.data();
const char *BufPtr = BufStart + getResumeOffset(FID);
const char *BufEnd = BufStart + Text.size();
assert(BufPtr <= BufEnd);
if (BufPtr == BufEnd)
return; // nothing left.
clang::Lexer Lex(FileLoc, Ctx.getLangOpts(), BufStart, BufPtr, BufEnd);
Lex.SetCommentRetentionState(true);
unsigned &LastPrintedLineNo = LastEntityLines[FID];
clang::Token Tok;
do {
BufPtr = Lex.getBufferLocation();
Lex.LexFromRawLexer(Tok);
if (Tok.is(clang::tok::eof))
break;
if (Tok.isNot(clang::tok::comment))
continue;
// Reached a comment.
clang::SourceLocation CommentLoc = Tok.getLocation();
std::pair<clang::FileID, unsigned> LocInfo =
SM.getDecomposedLoc(CommentLoc);
assert(LocInfo.first == FID);
unsigned LineNo = SM.getLineNumber(LocInfo.first, LocInfo.second);
if (LineNo > NodeLineNo)
break; // Comment is past the clang node.
bool IsDocComment = isDocumentationComment(CommentLoc, Node);
// Print out the comment.
StringRef CommentText(BufStart + LocInfo.second, Tok.getLength());
// Check if comment is on same line but after the declaration.
if (SM.isBeforeInTranslationUnit(NodeLoc, Tok.getLocation())) {
if (!IsDocComment)
PendingComments.push_back(CommentText);
continue;
}
if (LastPrintedLineNo && LineNo - LastPrintedLineNo > 1) {
*this << "\n";
printIndent();
}
if (!IsDocComment) {
unsigned StartLocCol = SM.getSpellingColumnNumber(Tok.getLocation());
printComment(CommentText, StartLocCol);
}
LastPrintedLineNo =
SM.getLineNumber(LocInfo.first, LocInfo.second + Tok.getLength());
} while (true);
// Resume printing comments from this point.
setResumeOffset(FID, BufPtr - BufStart);
}