Skip to content

Commit ced2485

Browse files
committed
ast-exporter: Cleanup VisitExpr, remove old Clang support
1 parent a5733bd commit ced2485

1 file changed

Lines changed: 11 additions & 23 deletions

File tree

c2rust-ast-exporter/src/AstExporter.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,49 +1413,37 @@ class TranslateASTVisitor final
14131413

14141414
// Check that we are only expanding a single macro call.
14151415
if (!Begin.isMacroID() || !End.isMacroID() ||
1416-
Mgr.getImmediateMacroCallerLoc(Begin) != Mgr.getImmediateMacroCallerLoc(End))
1416+
Mgr.getImmediateMacroCallerLoc(Begin) != Mgr.getImmediateMacroCallerLoc(End)) {
14171417
return true;
1418-
1419-
if (Begin.isMacroID()) {
1420-
#if CLANG_VERSION_MAJOR < 7
1421-
// getImmediateExpansionRange in LLVM<7 returns a
1422-
// std::pair<SourceLocation, SourceLocation>, which we need to
1423-
// translate to a CharSourceRange for Lexer::getSourceText
1424-
auto LocPair = Mgr.getImmediateExpansionRange(Begin);
1425-
auto ExpansionRange = CharSourceRange::getCharRange(LocPair.first, LocPair.second);
1426-
#else // CLANG_VERSION_MAJOR >= 7
1427-
auto ExpansionRange = Mgr.getImmediateExpansionRange(Begin);
1428-
#endif
1429-
curMacroExpansionSource =
1430-
Lexer::getSourceText(ExpansionRange, Mgr, Context->getLangOpts());
14311418
}
14321419

1420+
auto ExpansionRange = Mgr.getImmediateExpansionRange(Begin);
1421+
curMacroExpansionSource =
1422+
Lexer::getSourceText(ExpansionRange, Mgr, Context->getLangOpts());
1423+
14331424
// The macro stack unwound by getImmediateMacroCallerLoc and friends
14341425
// starts with literal replacement and works it's way to the macro call
14351426
// that was replaced.
14361427
while (Begin.isMacroID()) {
1437-
#if CLANG_VERSION_MAJOR < 7
1438-
auto ExpansionRange = Mgr.getImmediateExpansionRange(Begin);
1439-
auto ExpansionBegin = ExpansionRange.first;
1440-
auto ExpansionEnd = ExpansionRange.second;
1441-
#else // CLANG_VERSION_MAJOR >= 7
14421428
auto ExpansionRange = Mgr.getImmediateExpansionRange(Begin).getAsRange();
14431429
auto ExpansionBegin = ExpansionRange.getBegin();
14441430
auto ExpansionEnd = ExpansionRange.getEnd();
1445-
#endif
14461431
StringRef name;
14471432
MacroInfo *mac = getMacroInfo(ExpansionBegin, name);
14481433

1449-
if (!mac || mac->getNumTokens() == 0)
1434+
if (!mac || mac->getNumTokens() == 0) {
14501435
return true;
1436+
}
1437+
14511438
auto ReplacementBegin = mac->getReplacementToken(0).getLocation();
14521439
auto ReplacementEnd = mac->getDefinitionEndLoc();
14531440
// Verify that this expansion covers the entire macro replacement
14541441
// definition, i.e. E is not a subexpression of the macro
14551442
// replacement.
14561443
if (Mgr.getSpellingLoc(Begin) != ReplacementBegin ||
1457-
Mgr.getSpellingLoc(End) != ReplacementEnd)
1444+
Mgr.getSpellingLoc(End) != ReplacementEnd) {
14581445
return true;
1446+
}
14591447

14601448
Begin = ExpansionBegin;
14611449
End = ExpansionEnd;
@@ -1464,10 +1452,10 @@ class TranslateASTVisitor final
14641452
curMacroExpansionStack.push_back(mac);
14651453
}
14661454
}
1455+
14671456
return true;
14681457
}
14691458

1470-
14711459
bool VisitVAArgExpr(VAArgExpr *E) {
14721460
std::vector<void *> childIds{E->getSubExpr()};
14731461
encode_entry(E, TagVAArgExpr, childIds);

0 commit comments

Comments
 (0)