Lines Matching defs:SM

214 Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc) {
218 std::tie(FID, Offset) = SM.getDecomposedSpellingLoc(Loc);
220 P.line = static_cast<int>(SM.getLineNumber(FID, Offset)) - 1;
222 llvm::StringRef Code = SM.getBufferData(FID, &Invalid);
224 auto ColumnInBytes = SM.getColumnNumber(FID, Offset) - 1;
231 bool isSpelledInSource(SourceLocation Loc, const SourceManager &SM) {
234 auto Spelling = SM.getDecomposedSpellingLoc(Loc);
236 const auto SLocEntry = SM.getSLocEntry(Spelling.first, &InvalidSLocEntry);
244 return !SM.isWrittenInCommandLineFile(
245 SM.getComposedLoc(Spelling.first, Spelling.second));
264 SourceLocation includeHashLoc(FileID IncludedFile, const SourceManager &SM) {
265 assert(SM.getLocForEndOfFile(IncludedFile).isFileID());
269 SM.getDecomposedExpansionLoc(SM.getIncludeLoc(IncludedFile));
271 llvm::StringRef Buf = SM.getBufferData(IncludingFile, &Invalid);
280 return SM.getComposedLoc(IncludingFile, Offset);
286 static unsigned getTokenLengthAtLoc(SourceLocation Loc, const SourceManager &SM,
289 if (Lexer::getRawToken(Loc, TheTok, SM, LangOpts))
303 const SourceManager &SM,
305 unsigned Len = getTokenLengthAtLoc(BeginLoc, SM, LangOpts);
311 const SourceManager &SM,
314 -(signed)getTokenLengthAtLoc(EndLoc, SM, LangOpts));
318 static SourceRange toTokenRange(CharSourceRange Range, const SourceManager &SM,
321 Range.setEnd(getLocForTokenBegin(Range.getEnd(), SM, LangOpts));
328 const SourceManager &SM,
331 SM.isBeforeInTranslationUnit(R1.getBegin(), R2.getBegin())
335 SM.isBeforeInTranslationUnit(getLocForTokenEnd(R1.getEnd(), SM, LangOpts),
336 getLocForTokenEnd(R2.getEnd(), SM, LangOpts))
345 static SourceRange rangeInCommonFile(SourceRange R, const SourceManager &SM,
348 if (SM.isWrittenInSameFile(R.getBegin(), R.getEnd()))
354 ? includeHashLoc(SM.getFileID(Begin), SM)
355 : SM.getImmediateExpansionRange(Begin).getBegin()) {
356 BeginExpansions[SM.getFileID(Begin)] = Begin;
361 End = End.isFileID() ? includeHashLoc(SM.getFileID(End), SM)
362 : toTokenRange(SM.getImmediateExpansionRange(End),
363 SM, LangOpts)
365 auto It = BeginExpansions.find(SM.getFileID(End));
367 if (SM.getFileOffset(It->second) > SM.getFileOffset(End))
378 getExpansionTokenRangeInSameFile(SourceLocation Loc, const SourceManager &SM,
381 toTokenRange(SM.getImmediateExpansionRange(Loc), SM, LangOpts), SM,
396 const SourceManager &SM,
400 if (SM.isMacroArgExpansion(FileRange.getBegin())) {
402 SM.getImmediateSpellingLoc(FileRange.getBegin()),
403 SM.getImmediateSpellingLoc(FileRange.getEnd()), SM, LangOpts);
404 assert(SM.isWrittenInSameFile(FileRange.getBegin(), FileRange.getEnd()));
407 getExpansionTokenRangeInSameFile(FileRange.getBegin(), SM, LangOpts);
409 getExpansionTokenRangeInSameFile(FileRange.getEnd(), SM, LangOpts);
413 assert(SM.isWrittenInSameFile(ExpansionRangeForBegin.getBegin(),
417 SM, LangOpts);
423 bool isInsideMainFile(SourceLocation Loc, const SourceManager &SM) {
426 FileID FID = SM.getFileID(SM.getExpansionLoc(Loc));
427 return FID == SM.getMainFileID() || FID == SM.getPreambleFileID();
430 std::optional<SourceRange> toHalfOpenFileRange(const SourceManager &SM,
433 SourceRange R1 = getTokenFileRange(R.getBegin(), SM, LangOpts);
434 if (!isValidFileRange(SM, R1))
437 SourceRange R2 = getTokenFileRange(R.getEnd(), SM, LangOpts);
438 if (!isValidFileRange(SM, R2))
442 rangeInCommonFile(unionTokenRange(R1, R2, SM, LangOpts), SM, LangOpts);
443 unsigned TokLen = getTokenLengthAtLoc(Result.getEnd(), SM, LangOpts);
446 if (!isValidFileRange(SM, Result))
452 llvm::StringRef toSourceCode(const SourceManager &SM, SourceRange R) {
453 assert(isValidFileRange(SM, R));
454 auto Buf = SM.getBufferOrNone(SM.getFileID(R.getBegin()));
457 size_t BeginOffset = SM.getFileOffset(R.getBegin());
458 size_t EndOffset = SM.getFileOffset(R.getEnd());
462 llvm::Expected<SourceLocation> sourceLocationInMainFile(const SourceManager &SM,
464 llvm::StringRef Code = SM.getBufferOrFake(SM.getMainFileID()).getBuffer();
469 return SM.getLocForStartOfFile(SM.getMainFileID()).getLocWithOffset(*Offset);
472 Range halfOpenToRange(const SourceManager &SM, CharSourceRange R) {
474 Position Begin = sourceLocToPosition(SM, R.getBegin());
475 Position End = sourceLocToPosition(SM, R.getEnd());
575 std::optional<FileDigest> digestFile(const SourceManager &SM, FileID FID) {
577 llvm::StringRef Content = SM.getBufferData(FID, &Invalid);
622 llvm::function_ref<void(const syntax::Token &, const SourceManager &SM)>
627 auto &SM = FileSM.get();
628 for (const auto &Tok : syntax::tokenize(SM.getMainFileID(), SM, LangOpts))
629 Action(Tok, SM);
636 lex(Content, LangOpt, [&](const syntax::Token &Tok, const SourceManager &SM) {
638 ++Identifiers[Tok.text(SM)];
651 [&](const syntax::Token &Tok, const SourceManager &SM) {
652 if (Tok.kind() != tok::identifier || Tok.text(SM) != Identifier)
654 Ranges.push_back(halfOpenToRange(SM, Tok.range(SM).toCharRange(SM)));
696 lex(Code, LangOpts, [&](const syntax::Token &Tok, const SourceManager &SM) {
697 Event.Pos = sourceLocToPosition(SM, Tok.location());
721 NSName.append(Tok.text(SM).str());
728 NSName.append(Tok.text(SM).str());
816 bool isMainFile(llvm::StringRef FileName, const SourceManager &SM) {
817 auto FE = SM.getFileManager().getOptionalFileRef(FileName);
818 return FE && FE == SM.getFileEntryRefForID(SM.getMainFileID());
952 const auto &SM = TB.sourceManager();
959 Result.Text = T.text(SM);
964 TB.expandedTokens(SM.getMacroArgExpandedLocation(T.location()));
965 if (Expanded.size() == 1 && Expanded.front().text(SM) == Result.Text)
972 std::tie(File, Offset) = SM.getDecomposedLoc(SpelledLoc);
974 llvm::StringRef Code = SM.getBufferData(File, &Invalid);
986 Result.Location = SM.getComposedLoc(File, B);
1005 const auto &SM = PP.getSourceManager();
1006 IdentifierInfo *IdentifierInfo = PP.getIdentifierInfo(SpelledTok.text(SM));
1018 FileID FID = SM.getFileID(Loc);
1019 assert(Loc != SM.getLocForEndOfFile(FID));
1023 if (!MacroInfo && SM.getLocForStartOfFile(FID) != Loc) {
1033 translatePreamblePatchLocation(MacroInfo->getDefinitionLoc(), SM)};
1232 bool isProtoFile(SourceLocation Loc, const SourceManager &SM) {
1233 auto FileName = SM.getFilename(Loc);
1236 auto FID = SM.getFileID(Loc);
1241 return SM.getBufferData(FID).starts_with(ProtoHeaderComment);
1245 const SourceManager &SM) {
1246 auto DefFile = SM.getFileID(Loc);
1247 if (auto FE = SM.getFileEntryRefForID(DefFile)) {
1248 auto IncludeLoc = SM.getIncludeLoc(DefFile);
1250 if (IncludeLoc.isValid() && SM.isWrittenInBuiltinFile(IncludeLoc) &&
1252 auto Presumed = SM.getPresumedLoc(Loc);
1255 isMainFile(Presumed.getFilename(), SM)) {
1256 Loc = SM.translateLineCol(SM.getMainFileID(), Presumed.getLine(),