当前位置: 首页>>代码示例>>C++>>正文


C++ SourceLocation::isMacroID方法代码示例

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


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

示例1: location

	std::string location(clang::SourceLocation const& l, clang::SourceManager const& sm) {
		if(l.isValid()) {
			if(l.isFileID()) {
				// if (sm.isLoadedFileID (sm.getFileID(l))) return "PRELOADED MODULE";
				if(sm.isLoadedSourceLocation(l)) { return "PRELOADED MODULE"; }

				return l.printToString(sm);
			}

			if(l.isMacroID()) {
				// FIXME: what do we do here? somehow clang fails
				/*
				std::cout << "SLoc isMacroID\n";

				auto sl = sm.getSpellingLoc(l);
				if (sm.isLoadedSourceLocation(sl) ) { return "PRELOADED MODULE"; }
				if(sl.isValid()) {
				    return sl.printToString(sm);
				}

				PresumedLoc pl = sm.getPresumedLoc(l);
				if (pl.isValid()){
				    return string(pl.getFilename());
				}
				*/
			}
			return string("UNKNOWN FILE");
		}
		return string("INVALID LOC");
	}
开发者ID:zmanchun,项目名称:insieme,代码行数:30,代码来源:source_locations.cpp

示例2: FSL

void
NamedDeclMatcher::renameLocation(clang::SourceLocation L, std::string& N)
{
    if (L.isValid()) {
      if (L.isMacroID()) {
        // TODO: emit error using diagnostics
        clang::SourceManager &SM = ci->getSourceManager();
        if (SM.isMacroArgExpansion(L) || SM.isInSystemMacro(L)) {
          // see if it's the macro expansion we can handle
          // e.g.
          //   #define call(x) x
          //   call(y());   // if we want to rename y()
          L = SM.getSpellingLoc(L);

          // this falls through to the rename routine below
        }
        else {
          // if the spelling location is from an actual file that we can
          // touch, then do the replacement, but show a warning
          clang::SourceManager &SM = ci->getSourceManager();
          auto SL = SM.getSpellingLoc(L);
          clang::FullSourceLoc FSL(SL, SM);
          const clang::FileEntry *FE = SM.getFileEntryForID(FSL.getFileID());
          if (FE) {
            llvm::errs() << "Warning: Rename attempted as a result of macro "
                         << "expansion may break things, at: " << loc(L) << "\n";
            L = SL;
            // this falls through to the rename routine below
          }
          else {
            // cannot handle this case
            llvm::errs() << "Error: Token is resulted from macro expansion"
              " and is therefore not renamed, at: " << loc(L) << "\n";
            return;
          }
        }
      }

      if (!canChangeLocation(L)) {
        return;
      }

      clang::Preprocessor &P = ci->getPreprocessor();
      auto LE = P.getLocForEndOfToken(L);
      if (LE.isValid()) {

        // getLocWithOffset returns the location *past* the token, hence -1
        auto E = LE.getLocWithOffset(-1);

        // TODO: Determine if it's a writable file

        // TODO: Determine if the location has already been touched or
        // needs skipping (such as in refactoring API user's code, then
        // the API headers need no changing since later the new API will be
        // in place)

        Replacer::instance().replace(clang::SourceRange(L, E), N, ci->getSourceManager());
      }
    }
}
开发者ID:ryanwersal,项目名称:refactorial,代码行数:60,代码来源:NamedDeclMatcher.cpp

示例3: Add

void EditTracker::Add(const clang::SourceManager& source_manager,
                      clang::SourceLocation location,
                      llvm::StringRef original_text,
                      llvm::StringRef new_text) {
  llvm::StringRef filename;
  for (int i = 0; i < 10; i++) {
    filename = source_manager.getFilename(location);
    if (!filename.empty() || !location.isMacroID())
      break;
    // Otherwise, no filename and the SourceLocation is a macro ID. Look one
    // level up the stack...
    location = source_manager.getImmediateMacroCallerLoc(location);
  }
  assert(!filename.empty() && "Can't track edit with no filename!");
  auto result = tracked_edits_.try_emplace(original_text);
  if (result.second) {
    result.first->getValue().new_text = new_text;
  }
  result.first->getValue().filenames.try_emplace(filename);
}
开发者ID:MIPS,项目名称:external-v8,代码行数:20,代码来源:EditTracker.cpp


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