mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-19 11:35:51 -04:00
[clangd] NFC, add getLangOpts helper to ParsedAST
The addition of the helper is split out from https://reviews.llvm.org/D69543 as suggested by Kadir. I also updated the existing uses to use the new API.
This commit is contained in:
parent
acda2bc0ad
commit
c0ee0224c4
@ -312,8 +312,8 @@ void ClangdServer::prepareRename(PathRef File, Position Pos,
|
|||||||
const auto &SM = AST.getSourceManager();
|
const auto &SM = AST.getSourceManager();
|
||||||
SourceLocation Loc =
|
SourceLocation Loc =
|
||||||
SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
|
SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
|
||||||
Pos, AST.getSourceManager(), AST.getASTContext().getLangOpts()));
|
Pos, AST.getSourceManager(), AST.getLangOpts()));
|
||||||
auto Range = getTokenRange(SM, AST.getASTContext().getLangOpts(), Loc);
|
auto Range = getTokenRange(SM, AST.getLangOpts(), Loc);
|
||||||
if (!Range)
|
if (!Range)
|
||||||
return CB(llvm::None); // "rename" is not valid at the position.
|
return CB(llvm::None); // "rename" is not valid at the position.
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ llvm::Optional<Path> getCorrespondingHeaderOrSource(const Path &OriginalFile,
|
|||||||
//
|
//
|
||||||
// For each symbol in the original file, we get its target location (decl or
|
// For each symbol in the original file, we get its target location (decl or
|
||||||
// def) from the index, then award that target file.
|
// def) from the index, then award that target file.
|
||||||
bool IsHeader = isHeaderFile(OriginalFile, AST.getASTContext().getLangOpts());
|
bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts());
|
||||||
Index->lookup(Request, [&](const Symbol &Sym) {
|
Index->lookup(Request, [&](const Symbol &Sym) {
|
||||||
if (IsHeader)
|
if (IsHeader)
|
||||||
AwardTarget(Sym.Definition.FileURI);
|
AwardTarget(Sym.Definition.FileURI);
|
||||||
|
@ -367,8 +367,7 @@ HoverInfo getHoverContents(const DefinedMacro &Macro, ParsedAST &AST) {
|
|||||||
SourceLocation StartLoc = Macro.Info->getDefinitionLoc();
|
SourceLocation StartLoc = Macro.Info->getDefinitionLoc();
|
||||||
SourceLocation EndLoc = Macro.Info->getDefinitionEndLoc();
|
SourceLocation EndLoc = Macro.Info->getDefinitionEndLoc();
|
||||||
if (EndLoc.isValid()) {
|
if (EndLoc.isValid()) {
|
||||||
EndLoc = Lexer::getLocForEndOfToken(EndLoc, 0, SM,
|
EndLoc = Lexer::getLocForEndOfToken(EndLoc, 0, SM, AST.getLangOpts());
|
||||||
AST.getASTContext().getLangOpts());
|
|
||||||
bool Invalid;
|
bool Invalid;
|
||||||
StringRef Buffer = SM.getBufferData(SM.getFileID(StartLoc), &Invalid);
|
StringRef Buffer = SM.getBufferData(SM.getFileID(StartLoc), &Invalid);
|
||||||
if (!Invalid) {
|
if (!Invalid) {
|
||||||
@ -391,7 +390,7 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
|
|||||||
const SourceManager &SM = AST.getSourceManager();
|
const SourceManager &SM = AST.getSourceManager();
|
||||||
llvm::Optional<HoverInfo> HI;
|
llvm::Optional<HoverInfo> HI;
|
||||||
SourceLocation SourceLocationBeg = SM.getMacroArgExpandedLocation(
|
SourceLocation SourceLocationBeg = SM.getMacroArgExpandedLocation(
|
||||||
getBeginningOfIdentifier(Pos, SM, AST.getASTContext().getLangOpts()));
|
getBeginningOfIdentifier(Pos, SM, AST.getLangOpts()));
|
||||||
|
|
||||||
if (auto Deduced = getDeducedType(AST.getASTContext(), SourceLocationBeg)) {
|
if (auto Deduced = getDeducedType(AST.getASTContext(), SourceLocationBeg)) {
|
||||||
// Find the corresponding decl to populate kind and fetch documentation.
|
// Find the corresponding decl to populate kind and fetch documentation.
|
||||||
@ -435,9 +434,8 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
|
|||||||
tooling::applyAllReplacements(HI->Definition, Replacements))
|
tooling::applyAllReplacements(HI->Definition, Replacements))
|
||||||
HI->Definition = *Formatted;
|
HI->Definition = *Formatted;
|
||||||
|
|
||||||
HI->SymRange =
|
HI->SymRange = getTokenRange(AST.getASTContext().getSourceManager(),
|
||||||
getTokenRange(AST.getASTContext().getSourceManager(),
|
AST.getLangOpts(), SourceLocationBeg);
|
||||||
AST.getASTContext().getLangOpts(), SourceLocationBeg);
|
|
||||||
return HI;
|
return HI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +77,10 @@ public:
|
|||||||
return getASTContext().getSourceManager();
|
return getASTContext().getSourceManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LangOptions &getLangOpts() const {
|
||||||
|
return getASTContext().getLangOpts();
|
||||||
|
}
|
||||||
|
|
||||||
/// This function returns top-level decls present in the main file of the AST.
|
/// This function returns top-level decls present in the main file of the AST.
|
||||||
/// The result does not include the decls that come from the preamble.
|
/// The result does not include the decls that come from the preamble.
|
||||||
/// (These should be const, but RecursiveASTVisitor requires Decl*).
|
/// (These should be const, but RecursiveASTVisitor requires Decl*).
|
||||||
|
@ -30,7 +30,7 @@ llvm::Expected<std::vector<Range>> getSemanticRanges(ParsedAST &AST,
|
|||||||
Position Pos) {
|
Position Pos) {
|
||||||
std::vector<Range> Result;
|
std::vector<Range> Result;
|
||||||
const auto &SM = AST.getSourceManager();
|
const auto &SM = AST.getSourceManager();
|
||||||
const auto &LangOpts = AST.getASTContext().getLangOpts();
|
const auto &LangOpts = AST.getLangOpts();
|
||||||
|
|
||||||
auto FID = SM.getMainFileID();
|
auto FID = SM.getMainFileID();
|
||||||
auto Offset = positionToOffset(SM.getBufferData(FID), Pos);
|
auto Offset = positionToOffset(SM.getBufferData(FID), Pos);
|
||||||
|
@ -191,9 +191,8 @@ std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
|
|||||||
|
|
||||||
// Macros are simple: there's no declaration/definition distinction.
|
// Macros are simple: there's no declaration/definition distinction.
|
||||||
// As a consequence, there's no need to look them up in the index either.
|
// As a consequence, there's no need to look them up in the index either.
|
||||||
SourceLocation MaybeMacroLocation =
|
SourceLocation MaybeMacroLocation = SM.getMacroArgExpandedLocation(
|
||||||
SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
|
getBeginningOfIdentifier(Pos, AST.getSourceManager(), AST.getLangOpts()));
|
||||||
Pos, AST.getSourceManager(), AST.getASTContext().getLangOpts()));
|
|
||||||
std::vector<LocatedSymbol> Result;
|
std::vector<LocatedSymbol> Result;
|
||||||
if (auto M = locateMacroAt(MaybeMacroLocation, AST.getPreprocessor())) {
|
if (auto M = locateMacroAt(MaybeMacroLocation, AST.getPreprocessor())) {
|
||||||
if (auto Loc = makeLocation(AST.getASTContext(),
|
if (auto Loc = makeLocation(AST.getASTContext(),
|
||||||
@ -366,7 +365,7 @@ std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST,
|
|||||||
auto References = findRefs(
|
auto References = findRefs(
|
||||||
getDeclAtPosition(AST,
|
getDeclAtPosition(AST,
|
||||||
SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
|
SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
|
||||||
Pos, SM, AST.getASTContext().getLangOpts())),
|
Pos, SM, AST.getLangOpts())),
|
||||||
Relations),
|
Relations),
|
||||||
AST);
|
AST);
|
||||||
|
|
||||||
@ -374,9 +373,8 @@ std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST,
|
|||||||
// different kinds, deduplicate them.
|
// different kinds, deduplicate them.
|
||||||
std::vector<DocumentHighlight> Result;
|
std::vector<DocumentHighlight> Result;
|
||||||
for (const auto &Ref : References) {
|
for (const auto &Ref : References) {
|
||||||
if (auto Range =
|
if (auto Range = getTokenRange(AST.getASTContext().getSourceManager(),
|
||||||
getTokenRange(AST.getASTContext().getSourceManager(),
|
AST.getLangOpts(), Ref.Loc)) {
|
||||||
AST.getASTContext().getLangOpts(), Ref.Loc)) {
|
|
||||||
DocumentHighlight DH;
|
DocumentHighlight DH;
|
||||||
DH.range = *Range;
|
DH.range = *Range;
|
||||||
if (Ref.Role & index::SymbolRoleSet(index::SymbolRole::Write))
|
if (Ref.Role & index::SymbolRoleSet(index::SymbolRole::Write))
|
||||||
@ -404,7 +402,7 @@ ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
|
|||||||
return Results;
|
return Results;
|
||||||
}
|
}
|
||||||
auto Loc = SM.getMacroArgExpandedLocation(
|
auto Loc = SM.getMacroArgExpandedLocation(
|
||||||
getBeginningOfIdentifier(Pos, SM, AST.getASTContext().getLangOpts()));
|
getBeginningOfIdentifier(Pos, SM, AST.getLangOpts()));
|
||||||
// TODO: should we handle macros, too?
|
// TODO: should we handle macros, too?
|
||||||
// We also show references to the targets of using-decls, so we include
|
// We also show references to the targets of using-decls, so we include
|
||||||
// DeclRelation::Underlying.
|
// DeclRelation::Underlying.
|
||||||
@ -424,8 +422,7 @@ ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
|
|||||||
}),
|
}),
|
||||||
MainFileRefs.end());
|
MainFileRefs.end());
|
||||||
for (const auto &Ref : MainFileRefs) {
|
for (const auto &Ref : MainFileRefs) {
|
||||||
if (auto Range =
|
if (auto Range = getTokenRange(SM, AST.getLangOpts(), Ref.Loc)) {
|
||||||
getTokenRange(SM, AST.getASTContext().getLangOpts(), Ref.Loc)) {
|
|
||||||
Location Result;
|
Location Result;
|
||||||
Result.range = *Range;
|
Result.range = *Range;
|
||||||
Result.uri = URIForFile::canonicalize(*MainFilePath, *MainFilePath);
|
Result.uri = URIForFile::canonicalize(*MainFilePath, *MainFilePath);
|
||||||
@ -470,7 +467,7 @@ ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
|
|||||||
std::vector<SymbolDetails> getSymbolInfo(ParsedAST &AST, Position Pos) {
|
std::vector<SymbolDetails> getSymbolInfo(ParsedAST &AST, Position Pos) {
|
||||||
const SourceManager &SM = AST.getSourceManager();
|
const SourceManager &SM = AST.getSourceManager();
|
||||||
auto Loc = SM.getMacroArgExpandedLocation(
|
auto Loc = SM.getMacroArgExpandedLocation(
|
||||||
getBeginningOfIdentifier(Pos, SM, AST.getASTContext().getLangOpts()));
|
getBeginningOfIdentifier(Pos, SM, AST.getLangOpts()));
|
||||||
|
|
||||||
std::vector<SymbolDetails> Results;
|
std::vector<SymbolDetails> Results;
|
||||||
|
|
||||||
@ -646,7 +643,7 @@ static void fillSuperTypes(const CXXRecordDecl &CXXRD, ASTContext &ASTCtx,
|
|||||||
const CXXRecordDecl *findRecordTypeAt(ParsedAST &AST, Position Pos) {
|
const CXXRecordDecl *findRecordTypeAt(ParsedAST &AST, Position Pos) {
|
||||||
const SourceManager &SM = AST.getSourceManager();
|
const SourceManager &SM = AST.getSourceManager();
|
||||||
SourceLocation SourceLocationBeg = SM.getMacroArgExpandedLocation(
|
SourceLocation SourceLocationBeg = SM.getMacroArgExpandedLocation(
|
||||||
getBeginningOfIdentifier(Pos, SM, AST.getASTContext().getLangOpts()));
|
getBeginningOfIdentifier(Pos, SM, AST.getLangOpts()));
|
||||||
DeclRelationSet Relations =
|
DeclRelationSet Relations =
|
||||||
DeclRelation::TemplatePattern | DeclRelation::Underlying;
|
DeclRelation::TemplatePattern | DeclRelation::Underlying;
|
||||||
auto Decls = getDeclAtPosition(AST, SourceLocationBeg, Relations);
|
auto Decls = getDeclAtPosition(AST, SourceLocationBeg, Relations);
|
||||||
|
@ -397,9 +397,8 @@ llvm::Expected<FileEdits> rename(const RenameInputs &RInputs) {
|
|||||||
|
|
||||||
return (*Content)->getBuffer().str();
|
return (*Content)->getBuffer().str();
|
||||||
};
|
};
|
||||||
SourceLocation SourceLocationBeg =
|
SourceLocation SourceLocationBeg = SM.getMacroArgExpandedLocation(
|
||||||
SM.getMacroArgExpandedLocation(getBeginningOfIdentifier(
|
getBeginningOfIdentifier(RInputs.Pos, SM, AST.getLangOpts()));
|
||||||
RInputs.Pos, SM, AST.getASTContext().getLangOpts()));
|
|
||||||
// FIXME: Renaming macros is not supported yet, the macro-handling code should
|
// FIXME: Renaming macros is not supported yet, the macro-handling code should
|
||||||
// be moved to rename tooling library.
|
// be moved to rename tooling library.
|
||||||
if (locateMacroAt(SourceLocationBeg, AST.getPreprocessor()))
|
if (locateMacroAt(SourceLocationBeg, AST.getPreprocessor()))
|
||||||
|
@ -238,7 +238,7 @@ public:
|
|||||||
// FIXME: We might want to consider moving method definitions below class
|
// FIXME: We might want to consider moving method definitions below class
|
||||||
// definition even if we are inside a source file.
|
// definition even if we are inside a source file.
|
||||||
if (!isHeaderFile(Sel.AST.getSourceManager().getFilename(Sel.Cursor),
|
if (!isHeaderFile(Sel.AST.getSourceManager().getFilename(Sel.Cursor),
|
||||||
Sel.AST.getASTContext().getLangOpts()))
|
Sel.AST.getLangOpts()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Source = getSelectedFunction(Sel.ASTSelection.commonAncestor());
|
Source = getSelectedFunction(Sel.ASTSelection.commonAncestor());
|
||||||
@ -306,9 +306,8 @@ public:
|
|||||||
// FIXME: We should also get rid of inline qualifier.
|
// FIXME: We should also get rid of inline qualifier.
|
||||||
const tooling::Replacement DeleteFuncBody(
|
const tooling::Replacement DeleteFuncBody(
|
||||||
Sel.AST.getSourceManager(),
|
Sel.AST.getSourceManager(),
|
||||||
CharSourceRange::getTokenRange(
|
CharSourceRange::getTokenRange(*toHalfOpenFileRange(
|
||||||
*toHalfOpenFileRange(SM, Sel.AST.getASTContext().getLangOpts(),
|
SM, Sel.AST.getLangOpts(), Source->getBody()->getSourceRange())),
|
||||||
Source->getBody()->getSourceRange())),
|
|
||||||
";");
|
";");
|
||||||
auto HeaderFE = Effect::fileEdit(SM, SM.getMainFileID(),
|
auto HeaderFE = Effect::fileEdit(SM, SM.getMainFileID(),
|
||||||
tooling::Replacements(DeleteFuncBody));
|
tooling::Replacements(DeleteFuncBody));
|
||||||
|
@ -645,7 +645,7 @@ tooling::Replacement createFunctionDefinition(const NewFunction &ExtractedFunc,
|
|||||||
bool ExtractFunction::prepare(const Selection &Inputs) {
|
bool ExtractFunction::prepare(const Selection &Inputs) {
|
||||||
const Node *CommonAnc = Inputs.ASTSelection.commonAncestor();
|
const Node *CommonAnc = Inputs.ASTSelection.commonAncestor();
|
||||||
const SourceManager &SM = Inputs.AST.getSourceManager();
|
const SourceManager &SM = Inputs.AST.getSourceManager();
|
||||||
const LangOptions &LangOpts = Inputs.AST.getASTContext().getLangOpts();
|
const LangOptions &LangOpts = Inputs.AST.getLangOpts();
|
||||||
if (auto MaybeExtZone = findExtractionZone(CommonAnc, SM, LangOpts)) {
|
if (auto MaybeExtZone = findExtractionZone(CommonAnc, SM, LangOpts)) {
|
||||||
ExtZone = std::move(*MaybeExtZone);
|
ExtZone = std::move(*MaybeExtZone);
|
||||||
return true;
|
return true;
|
||||||
@ -655,7 +655,7 @@ bool ExtractFunction::prepare(const Selection &Inputs) {
|
|||||||
|
|
||||||
Expected<Tweak::Effect> ExtractFunction::apply(const Selection &Inputs) {
|
Expected<Tweak::Effect> ExtractFunction::apply(const Selection &Inputs) {
|
||||||
const SourceManager &SM = Inputs.AST.getSourceManager();
|
const SourceManager &SM = Inputs.AST.getSourceManager();
|
||||||
const LangOptions &LangOpts = Inputs.AST.getASTContext().getLangOpts();
|
const LangOptions &LangOpts = Inputs.AST.getLangOpts();
|
||||||
auto ExtractedFunc = getExtractedFunction(ExtZone, SM, LangOpts);
|
auto ExtractedFunc = getExtractedFunction(ExtZone, SM, LangOpts);
|
||||||
// FIXME: Add more types of errors.
|
// FIXME: Add more types of errors.
|
||||||
if (!ExtractedFunc)
|
if (!ExtractedFunc)
|
||||||
|
@ -91,7 +91,7 @@ Expected<Tweak::Effect> RawStringLiteral::apply(const Selection &Inputs) {
|
|||||||
auto &SM = Inputs.AST.getSourceManager();
|
auto &SM = Inputs.AST.getSourceManager();
|
||||||
auto Reps = tooling::Replacements(
|
auto Reps = tooling::Replacements(
|
||||||
tooling::Replacement(SM, Str, ("R\"(" + Str->getBytes() + ")\"").str(),
|
tooling::Replacement(SM, Str, ("R\"(" + Str->getBytes() + ")\"").str(),
|
||||||
Inputs.AST.getASTContext().getLangOpts()));
|
Inputs.AST.getLangOpts()));
|
||||||
return Effect::mainFileEdit(SM, std::move(Reps));
|
return Effect::mainFileEdit(SM, std::move(Reps));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ TEST(CollectMainFileMacros, SelectedMacros) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
auto Loc = getBeginningOfIdentifier(ExpectedRefs.begin()->start, SM,
|
auto Loc = getBeginningOfIdentifier(ExpectedRefs.begin()->start, SM,
|
||||||
AST.getASTContext().getLangOpts());
|
AST.getLangOpts());
|
||||||
auto Macro = locateMacroAt(Loc, PP);
|
auto Macro = locateMacroAt(Loc, PP);
|
||||||
assert(Macro);
|
assert(Macro);
|
||||||
auto SID = getSymbolID(Macro->Name, Macro->Info, SM);
|
auto SID = getSymbolID(Macro->Name, Macro->Info, SM);
|
||||||
|
@ -40,7 +40,7 @@ Range nodeRange(const SelectionTree::Node *N, ParsedAST &AST) {
|
|||||||
if (!N)
|
if (!N)
|
||||||
return Range{};
|
return Range{};
|
||||||
const SourceManager &SM = AST.getSourceManager();
|
const SourceManager &SM = AST.getSourceManager();
|
||||||
const LangOptions &LangOpts = AST.getASTContext().getLangOpts();
|
const LangOptions &LangOpts = AST.getLangOpts();
|
||||||
StringRef Buffer = SM.getBufferData(SM.getMainFileID());
|
StringRef Buffer = SM.getBufferData(SM.getMainFileID());
|
||||||
if (llvm::isa_and_nonnull<TranslationUnitDecl>(N->ASTNode.get<Decl>()))
|
if (llvm::isa_and_nonnull<TranslationUnitDecl>(N->ASTNode.get<Decl>()))
|
||||||
return Range{Position{}, offsetToPosition(Buffer, Buffer.size())};
|
return Range{Position{}, offsetToPosition(Buffer, Buffer.size())};
|
||||||
|
@ -358,7 +358,7 @@ Bar* bar;
|
|||||||
auto AST = TestTU::withCode(TestCase.code()).build();
|
auto AST = TestTU::withCode(TestCase.code()).build();
|
||||||
const auto &SourceMgr = AST.getSourceManager();
|
const auto &SourceMgr = AST.getSourceManager();
|
||||||
SourceLocation Actual = getBeginningOfIdentifier(
|
SourceLocation Actual = getBeginningOfIdentifier(
|
||||||
TestCase.points().back(), SourceMgr, AST.getASTContext().getLangOpts());
|
TestCase.points().back(), SourceMgr, AST.getLangOpts());
|
||||||
Position ActualPos = offsetToPosition(
|
Position ActualPos = offsetToPosition(
|
||||||
TestCase.code(),
|
TestCase.code(),
|
||||||
SourceMgr.getFileOffset(SourceMgr.getSpellingLoc(Actual)));
|
SourceMgr.getFileOffset(SourceMgr.getSpellingLoc(Actual)));
|
||||||
@ -482,7 +482,7 @@ TEST(SourceCodeTests, GetMacros) {
|
|||||||
TestTU TU = TestTU::withCode(Code.code());
|
TestTU TU = TestTU::withCode(Code.code());
|
||||||
auto AST = TU.build();
|
auto AST = TU.build();
|
||||||
auto Loc = getBeginningOfIdentifier(Code.point(), AST.getSourceManager(),
|
auto Loc = getBeginningOfIdentifier(Code.point(), AST.getSourceManager(),
|
||||||
AST.getASTContext().getLangOpts());
|
AST.getLangOpts());
|
||||||
auto Result = locateMacroAt(Loc, AST.getPreprocessor());
|
auto Result = locateMacroAt(Loc, AST.getPreprocessor());
|
||||||
ASSERT_TRUE(Result);
|
ASSERT_TRUE(Result);
|
||||||
EXPECT_THAT(*Result, MacroName("MACRO"));
|
EXPECT_THAT(*Result, MacroName("MACRO"));
|
||||||
@ -548,7 +548,7 @@ TEST(SourceCodeTests, HalfOpenFileRange) {
|
|||||||
ParsedAST AST = TestTU::withCode(Test.code()).build();
|
ParsedAST AST = TestTU::withCode(Test.code()).build();
|
||||||
llvm::errs() << Test.code();
|
llvm::errs() << Test.code();
|
||||||
const SourceManager &SM = AST.getSourceManager();
|
const SourceManager &SM = AST.getSourceManager();
|
||||||
const LangOptions &LangOpts = AST.getASTContext().getLangOpts();
|
const LangOptions &LangOpts = AST.getLangOpts();
|
||||||
// Turn a SourceLocation into a pair of positions
|
// Turn a SourceLocation into a pair of positions
|
||||||
auto SourceRangeToRange = [&SM](SourceRange SrcRange) {
|
auto SourceRangeToRange = [&SM](SourceRange SrcRange) {
|
||||||
return Range{sourceLocToPosition(SM, SrcRange.getBegin()),
|
return Range{sourceLocToPosition(SM, SrcRange.getBegin()),
|
||||||
@ -588,8 +588,7 @@ TEST(SourceCodeTests, HalfOpenFileRangePathologicalPreprocessor) {
|
|||||||
const auto &Body = cast<CompoundStmt>(Func.getBody());
|
const auto &Body = cast<CompoundStmt>(Func.getBody());
|
||||||
const auto &Loop = cast<WhileStmt>(*Body->child_begin());
|
const auto &Loop = cast<WhileStmt>(*Body->child_begin());
|
||||||
llvm::Optional<SourceRange> Range = toHalfOpenFileRange(
|
llvm::Optional<SourceRange> Range = toHalfOpenFileRange(
|
||||||
AST.getSourceManager(), AST.getASTContext().getLangOpts(),
|
AST.getSourceManager(), AST.getLangOpts(), Loop->getSourceRange());
|
||||||
Loop->getSourceRange());
|
|
||||||
ASSERT_TRUE(Range) << "Failed to get file range";
|
ASSERT_TRUE(Range) << "Failed to get file range";
|
||||||
EXPECT_EQ(AST.getSourceManager().getFileOffset(Range->getBegin()),
|
EXPECT_EQ(AST.getSourceManager().getFileOffset(Range->getBegin()),
|
||||||
Test.llvm::Annotations::range().Begin);
|
Test.llvm::Annotations::range().Begin);
|
||||||
|
Loading…
Reference in New Issue
Block a user