• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ clang::SourceRange类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中clang::SourceRange的典型用法代码示例。如果您正苦于以下问题:C++ SourceRange类的具体用法?C++ SourceRange怎么用?C++ SourceRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SourceRange类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: 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;
}
开发者ID:bright-tools,项目名称:ccsm,代码行数:35,代码来源:MetricPPCustomer.cpp


示例2: 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;
}
开发者ID:Jhana1,项目名称:CAPA,代码行数:9,代码来源:ASTUtil.cpp


示例3: 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();
}
开发者ID:greye,项目名称:refactorial,代码行数:12,代码来源:NamedDeclMatcher.cpp


示例4: 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);
     }
 }
开发者ID:abduld,项目名称:woboq_codebrowser,代码行数:12,代码来源:commenthandler.cpp


示例5: 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 ;
}
开发者ID:ibanezz,项目名称:trick,代码行数:13,代码来源:CommentSaver.cpp


示例6: 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() ;
}
开发者ID:ibanezz,项目名称:trick,代码行数:14,代码来源:CommentSaver.cpp


示例7: 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());
}
开发者ID:PdedP,项目名称:clang-tools-extra,代码行数:15,代码来源:PPCallbacksTracker.cpp


示例8: 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;
		}
开发者ID:ericaprhys,项目名称:clangAST-calltree,代码行数:15,代码来源:main.cpp


示例9: 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;
    }
开发者ID:7h3rAm,项目名称:Clang-tutorial,代码行数:15,代码来源:CommentHandling.cpp


示例10: 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()));
	}
开发者ID:RandomDeveloperM,项目名称:UE4_Hairworks,代码行数:31,代码来源:MacroCallback.cpp


示例11: 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;
}
开发者ID:Ericsson,项目名称:CodeCompass,代码行数:22,代码来源:ppincludecallback.cpp


示例12: 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();
}
开发者ID:etaoins,项目名称:qconnectlint,代码行数:14,代码来源:Reporter.cpp


示例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());
}
开发者ID:abigagli,项目名称:woboq_codebrowser,代码行数:94,代码来源:preprocessorcallback.cpp


示例14: RemoveText

void ParentTransform::RemoveText(clang::SourceRange rng) {
    rewriter->RemoveText(rng);
    insertions->AppendToDiagnostics("RemoveTextBegin", rng.getBegin(), "", *SM);
    insertions->AppendToDiagnostics("RemoveTextEnd", rng.getEnd(), "", *SM);
}
开发者ID:agrippa,项目名称:chimes,代码行数:5,代码来源:ParentTransform.cpp


示例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);
}
开发者ID:agrippa,项目名称:chimes,代码行数:6,代码来源:ParentTransform.cpp


示例16: removeText

void WebCLRewriter::removeText(clang::SourceRange range) {
  isFilteredRangesDirty_ = true;
  DEBUG( std::cerr << "Remove SourceLoc " << range.getBegin().getRawEncoding() << ":" << range.getEnd().getRawEncoding() << " " << getOriginalText(range) << "\n"; );
开发者ID:ChiahungTai,项目名称:webcl-validator,代码行数:3,代码来源:WebCLRewriter.cpp


示例17: Column

	std::pair<unsigned, unsigned> Column(clang::SourceRange const& r, SourceManager const& sm) {
		return std::make_pair(Column(r.getBegin(), sm), Column(r.getEnd(), sm));
	}
开发者ID:zmanchun,项目名称:insieme,代码行数:3,代码来源:source_locations.cpp


示例18: applySourceRange

void ClangToSageTranslator::applySourceRange(SgNode * node, clang::SourceRange source_range) {
    SgLocatedNode * located_node = isSgLocatedNode(node);
    SgInitializedName * init_name = isSgInitializedName(node);

#if DEBUG_SOURCE_LOCATION
    std::cerr << "Set File_Info for " << node << " of type " << node->class_name() << std::endl;
#endif

    if (located_node == NULL && init_name == NULL) {
        std::cerr << "Consistency error: try to apply a source range to a Sage node which is not a SgLocatedNode or a SgInitializedName." << std::endl;
        exit(-1);
    }
    else if (located_node != NULL) {
        Sg_File_Info * fi = located_node->get_startOfConstruct();
        if (fi != NULL) delete fi;
        fi = located_node->get_endOfConstruct();
        if (fi != NULL) delete fi;
    }
    else if (init_name != NULL) {
        Sg_File_Info * fi = init_name->get_startOfConstruct();
        if (fi != NULL) delete fi;
        fi = init_name->get_endOfConstruct();
        if (fi != NULL) delete fi;
    }

    Sg_File_Info * start_fi = NULL;
    Sg_File_Info * end_fi = NULL;

    if (source_range.isValid()) {
        clang::SourceLocation begin  = source_range.getBegin();
        clang::SourceLocation end    = source_range.getEnd();

        if (begin.isValid() && end.isValid()) {
            if (begin.isMacroID()) {
#if DEBUG_SOURCE_LOCATION
                std::cerr << "\tDump SourceLocation begin as it is a MacroID: ";
                begin.dump(p_compiler_instance->getSourceManager());
                std::cerr << std::endl;
#endif
                begin = p_compiler_instance->getSourceManager().getExpansionLoc(begin);
                ROSE_ASSERT(begin.isValid());
            }

            if (end.isMacroID()) {
#if DEBUG_SOURCE_LOCATION
                std::cerr << "\tDump SourceLocation end as it is a MacroID: ";
                end.dump(p_compiler_instance->getSourceManager());
                std::cerr << std::endl;
#endif
                end = p_compiler_instance->getSourceManager().getExpansionLoc(end);
                ROSE_ASSERT(end.isValid());
            }

            clang::FileID file_begin = p_compiler_instance->getSourceManager().getFileID(begin);
            clang::FileID file_end   = p_compiler_instance->getSourceManager().getFileID(end);

            bool inv_begin_line;
            bool inv_begin_col;
            bool inv_end_line;
            bool inv_end_col;

            unsigned ls = p_compiler_instance->getSourceManager().getSpellingLineNumber(begin, &inv_begin_line);
            unsigned cs = p_compiler_instance->getSourceManager().getSpellingColumnNumber(begin, &inv_begin_col);
            unsigned le = p_compiler_instance->getSourceManager().getSpellingLineNumber(end, &inv_end_line);
            unsigned ce = p_compiler_instance->getSourceManager().getSpellingColumnNumber(end, &inv_end_col);

            if (file_begin.isInvalid() || file_end.isInvalid() || inv_begin_line || inv_begin_col || inv_end_line || inv_end_col) {
                ROSE_ASSERT(!"Should not happen as everything have been check before...");
            }

            if (p_compiler_instance->getSourceManager().getFileEntryForID(file_begin) != NULL) {
                std::string file = p_compiler_instance->getSourceManager().getFileEntryForID(file_begin)->getName();

                start_fi = new Sg_File_Info(file, ls, cs);
                end_fi   = new Sg_File_Info(file, le, ce);
#if DEBUG_SOURCE_LOCATION
                std::cerr << "\tCreate FI for node in " << file << ":" << ls << ":" << cs << std::endl;
#endif
            }
#if DEBUG_SOURCE_LOCATION
            else {
                std::cerr << "\tDump SourceLocation for \"Invalid FileID\": " << std::endl << "\t";
                begin.dump(p_compiler_instance->getSourceManager());
                std::cerr << std::endl << "\t";
                end.dump(p_compiler_instance->getSourceManager());
                std::cerr << std::endl;
            }
#endif
        }
    }

    if (start_fi == NULL && end_fi == NULL) {
        start_fi = Sg_File_Info::generateDefaultFileInfoForCompilerGeneratedNode();
        end_fi   = Sg_File_Info::generateDefaultFileInfoForCompilerGeneratedNode();

        start_fi->setCompilerGenerated();
        end_fi->setCompilerGenerated();
#if DEBUG_SOURCE_LOCATION
        std::cerr << "Create FI for compiler generated node" << std::endl;
#endif
//.........这里部分代码省略.........
开发者ID:KurSh,项目名称:rose,代码行数:101,代码来源:clang-frontend.cpp



注:本文中的clang::SourceRange类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ clang::Token类代码示例发布时间:2022-05-31
下一篇:
C++ clang::SourceManager类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap