本文整理汇总了C++中clang::SourceRange::getBegin方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceRange::getBegin方法的具体用法?C++ SourceRange::getBegin怎么用?C++ SourceRange::getBegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clang::SourceRange
的用法示例。
在下文中一共展示了SourceRange::getBegin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tag
void tag(llvm::StringRef className, clang::SourceRange range, llvm::StringRef ref = llvm::StringRef()) {
int len = range.getEnd().getRawEncoding() - range.getBegin().getRawEncoding() + 1;
if (len > 0) {
std::string attr;
if (ref.empty()) {
attr = "class=\"" % className % "\"";
} else {
attr = "class=\"" % className % "\" data-ref=\"" % ref % "\"";
}
generator.addTag("span", attr, range.getBegin().getRawEncoding(), len);
}
}
示例2: HandleComment
bool CommentSaver::HandleComment(clang::Preprocessor &PP, clang::SourceRange Comment) {
//Comment.getBegin().dump(sm) ;
//if ( ! sm.isInSystemHeader(Comment.getBegin()) ) {
if ( isInUserOrTrickCode( ci , Comment.getBegin() , hsd ) ) {
std::string file_name = ci.getSourceManager().getBufferName(Comment.getBegin()) ;
unsigned int line_no = ci.getSourceManager().getSpellingLineNumber(Comment.getBegin()) ;
comment_map[file_name][line_no] = Comment ;
}
// returning false means we did not push any text back to the stream for further reads.
return false ;
}
示例3: HandleComment
virtual bool HandleComment( clang::Preprocessor &pp, clang::SourceRange rng)
{
clang::SourceManager &sm = pp.getSourceManager();
if( sm.getFilename(rng.getBegin()) == m_inFile)
{
std::pair<FileID, unsigned int> startLoc = sm.getDecomposedLoc(rng.getBegin());
std::pair<FileID, unsigned int> endLoc = sm.getDecomposedLoc(rng.getEnd());
llvm::StringRef fileData = sm.getBufferData(startLoc.first);
std::cout << fileData.substr(startLoc.second, endLoc.second - startLoc.second).str();
std::cout << std::endl;
}
return false;
}
示例4: HandleComment
bool MetricPPCustomer::HandleComment(clang::Preprocessor &PP, clang::SourceRange Loc) {
clang::SourceLocation Start = Loc.getBegin();
clang::SourceManager &SM = PP.getSourceManager();
std::string fileName = SM.getFilename( Start ).str();
/* Excude comments that are not:
- Not in the main file and
- Not in the file we're currently processing and
- Are in a file we've already processed comments for
*/
if(( SM.getFileID( Start ) == SM.getMainFileID() ) ||
( fileName == m_commentFile ) ||
( m_commentFileList->find( fileName ) == m_commentFileList->end() ))
{
std::string C(SM.getCharacterData(Start),
SM.getCharacterData(Loc.getEnd()));
if( m_options.ShouldIncludeFile( fileName ))
{
MetricUnit* unit = m_topUnit->getSubUnit(fileName, METRIC_UNIT_FILE);
unit->increment(METRIC_TYPE_COMMENT_BYTE_COUNT, getFileAndLine( SM, &Start ), C.length());
unit->increment(METRIC_TYPE_COMMENT_COUNT, getFileAndLine( SM, &Start ));
}
m_commentFile = fileName;
m_commentFileList->insert( fileName );
}
else
{
m_commentFile = "";
}
return false;
}
示例5: MacroExpands
void FMacroCallback::MacroExpands(const clang::Token &MacroNameTok, const clang::MacroDirective *MD, clang::SourceRange Range, const clang::MacroArgs *Args)
{
auto MacroName = MacroNameTok.getIdentifierInfo()->getName();
if (IsBuiltInMacro(MD) || IsMacroDefinedInCommandLine(MacroName) || IsPredefinedMacro(MacroName))
{
return;
}
if (MacroDefinitionToFile.Contains(FString(MacroName.data())))
{
auto MacroDefinitionFilename = FString(*MacroDefinitionToFile[MacroName.data()]);
MacroDefinitionFilename.ReplaceInline(TEXT("\\"), TEXT("/"));
auto MacroDefinitionFilenameHash = FIncludeSetMapKeyFuncs::GetKeyHash(MacroDefinitionFilename);
auto MacroExpansionFilename = FString(SourceManager.getFilename(Range.getBegin()).data());
MacroExpansionFilename.ReplaceInline(TEXT("\\"), TEXT("/"));
auto MacroExpansionFilenameHash = FIncludeSetMapKeyFuncs::GetKeyHash(MacroExpansionFilename);
if (!Includes.Contains(MacroExpansionFilenameHash))
{
Includes.FindOrAdd(MacroExpansionFilenameHash).Add(MacroDefinitionFilenameHash);
}
GHashToFilename.Add(MacroDefinitionFilenameHash, MacroDefinitionFilename);
GHashToFilename.Add(MacroExpansionFilenameHash, MacroExpansionFilename);
return;
}
OutputFileContents.Logf(TEXT("Internal error. Found usage of unknown macro %s."), ANSI_TO_TCHAR(MacroName.data()));
}
示例6: getLineCount
int getLineCount(clang::SourceRange sourceRange, const clang::SourceManager& sourceManager)
{
clang::SourceLocation startLocation = sourceRange.getBegin();
clang::SourceLocation endLocation = sourceRange.getEnd();
unsigned startLineNumber = sourceManager.getPresumedLineNumber(startLocation);
unsigned endLineNumber = sourceManager.getPresumedLineNumber(endLocation);
return endLineNumber - startLineNumber + 1;
}
示例7: sst
std::string
NamedDeclMatcher::range(clang::SourceRange R)
{
std::string src;
llvm::raw_string_ostream sst(src);
sst << "(";
R.getBegin().print(sst, ci->getSourceManager());
sst << ", ";
R.getEnd().print(sst, ci->getSourceManager());
sst << ")";
return sst.str();
}
示例8: createFileAstNode
model::CppAstNodePtr PPIncludeCallback::createFileAstNode(
const model::FilePtr& file_,
const clang::SourceRange& srcRange_)
{
model::CppAstNodePtr astNode(new model::CppAstNode());
astNode->astValue = file_->path;
astNode->mangledName = std::to_string(file_->id);
astNode->mangledNameHash = util::fnvHash(astNode->mangledName);
astNode->symbolType = model::CppAstNode::SymbolType::File;
astNode->astType = model::CppAstNode::AstType::Usage;
model::FileLoc& fileLoc = astNode->location;
_fileLocUtil.setRange(
srcRange_.getBegin(), srcRange_.getEnd(), fileLoc.range);
fileLoc.file = _ctx.srcMgr.getFile(
_fileLocUtil.getFilePath(srcRange_.getBegin()));
astNode->id = model::createIdentifier(*astNode);
return astNode;
}
示例9: appendArgument
// Append a SourceRange argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
clang::SourceRange Value) {
if (DisableTrace)
return;
if (Value.isInvalid()) {
appendArgument(Name, "(invalid)");
return;
}
std::string Str;
llvm::raw_string_ostream SS(Str);
SS << "[" << getSourceLocationString(PP, Value.getBegin()) << ", "
<< getSourceLocationString(PP, Value.getEnd()) << "]";
appendArgument(Name, SS.str());
}
示例10: report
ReportStream Reporter::report(const clang::SourceRange &range)
{
// Track this report
mTotalReports++;
// Print the expansion location
const clang::SourceLocation expansionLoc(mSourceManager.getExpansionLoc(range.getBegin()));
std::cerr << boldCode() << expansionLoc.printToString(mSourceManager) << ": ";
// Print the "connect" in a different color than warnings or errors
std::cerr << connectColorCode() << "connect:" << defaultColorCode();
return ReportStream();
}
示例11: getComment
std::string CommentSaver::getComment( clang::SourceRange sr ) {
if ( sr.isValid() ) {
/* fsl_begin and fsl_end are two pointers into the header file. We want the text between the two pointers. */
clang::FullSourceLoc fsl_begin(sr.getBegin() , ci.getSourceManager()) ;
clang::FullSourceLoc fsl_end(sr.getEnd() , ci.getSourceManager()) ;
std::string comment_text( fsl_begin.getCharacterData() ,
(size_t)(fsl_end.getCharacterData() - fsl_begin.getCharacterData())) ;
return comment_text ;
}
/* return an empty string if no comment found on this line of the file. */
return std::string() ;
}
示例12: HandleComment
virtual bool HandleComment(clang::Preprocessor& pp, clang::SourceRange range) override
{
auto FID = pp.getSourceManager().getMainFileID();
int start = range.getBegin().getRawEncoding();
int end = range.getEnd().getRawEncoding();
int length = end - start;
auto bufferStart = pp.getSourceManager().getBuffer(FID)->getBufferStart();
int fileOffset = pp.getSourceManager().getLocForStartOfFile(FID).getRawEncoding();
const char* data = bufferStart + start - fileOffset;
string str(data, length);
cout << str << endl;
return false;
}
示例13: MacroExpands
void PreprocessorCallback::MacroExpands(const clang::Token& MacroNameTok,
const clang::MacroInfo* MI,
clang::SourceRange Range)
{
if (disabled)
return;
clang::SourceLocation loc = MacroNameTok.getLocation();
if (!loc.isValid() || !loc.isFileID())
return;
clang::SourceManager &sm = annotator.getSourceMgr();
clang::FileID FID = sm.getFileID(loc);
if (!annotator.shouldProcess(FID))
return;
const char *begin = sm.getCharacterData(Range.getBegin());
int len = sm.getCharacterData(Range.getEnd()) - begin;
len += clang::Lexer::MeasureTokenLength(Range.getEnd(), sm, PP.getLangOpts());
std::string copy(begin, len);
begin = copy.c_str();
clang::Lexer lex(loc, PP.getLangOpts(), begin, begin, begin + len);
std::vector<clang::Token> tokens;
std::string expansion;
//Lousely based on code from clang::html::HighlightMacros
// Lex all the tokens in raw mode, to avoid entering #includes or expanding
// macros.
clang::Token tok;
do {
lex.LexFromRawLexer(tok);
// If this is a # at the start of a line, discard it from the token stream.
// We don't want the re-preprocess step to see #defines, #includes or other
// preprocessor directives.
if (tok.is(clang::tok::hash) && tok.isAtStartOfLine())
continue;
// If this is a ## token, change its kind to unknown so that repreprocessing
// it will not produce an error.
if (tok.is(clang::tok::hashhash))
tok.setKind(clang::tok::unknown);
// If this raw token is an identifier, the raw lexer won't have looked up
// the corresponding identifier info for it. Do this now so that it will be
// macro expanded when we re-preprocess it.
if (tok.is(clang::tok::raw_identifier))
PP.LookUpIdentifierInfo(tok);
tokens.push_back(tok);
} while(!tok.is(clang::tok::eof));
// Temporarily change the diagnostics object so that we ignore any generated
// diagnostics from this pass.
clang::DiagnosticsEngine TmpDiags(PP.getDiagnostics().getDiagnosticIDs(),
#if CLANG_VERSION_MAJOR!=3 || CLANG_VERSION_MINOR>=2
&PP.getDiagnostics().getDiagnosticOptions(),
#endif
new clang::IgnoringDiagConsumer);
disabled = true;
clang::DiagnosticsEngine *OldDiags = &PP.getDiagnostics();
PP.setDiagnostics(TmpDiags);
PP.EnterTokenStream(tokens.data(), tokens.size(), false, false);
PP.Lex(tok);
while(tok.isNot(clang::tok::eof)) {
// If the tokens were already space separated, or if they must be to avoid
// them being implicitly pasted, add a space between them.
if (tok.hasLeadingSpace())
expansion += ' ';
// ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok)) //FIXME
// Escape any special characters in the token text.
expansion += PP.getSpelling(tok);
PP.Lex(tok);
}
PP.setDiagnostics(*OldDiags);
disabled = false;
expansion = Generator::escapeAttr(expansion);
clang::SourceLocation defLoc = MI->getDefinitionLoc();
clang::FileID defFID = sm.getFileID(defLoc);
std::string link;
if (defFID != FID)
link = annotator.pathTo(FID, defFID);
std::string tag = "class=\"macro\" href=\"" % link % "#" % llvm::Twine(sm.getExpansionLineNumber(defLoc)).str()
% "\" title=\"" % expansion % "\"";
annotator.generator(FID).addTag("a", tag, sm.getFileOffset(loc), MacroNameTok.getLength());
}
示例14: RemoveText
void ParentTransform::RemoveText(clang::SourceRange rng) {
rewriter->RemoveText(rng);
insertions->AppendToDiagnostics("RemoveTextBegin", rng.getBegin(), "", *SM);
insertions->AppendToDiagnostics("RemoveTextEnd", rng.getEnd(), "", *SM);
}
示例15: ReplaceText
void ParentTransform::ReplaceText(clang::SourceRange range, std::string s) {
rewriter->ReplaceText(range, s);
insertions->AppendToDiagnostics("ReplaceTextStart", range.getBegin(), s, *SM);
insertions->AppendToDiagnostics("ReplaceTextEnd", range.getEnd(), "", *SM);
}