33#include "llvm/ADT/ArrayRef.h"
34#include "llvm/ADT/DenseMap.h"
35#include "llvm/ADT/PointerUnion.h"
36#include "llvm/ADT/STLExtras.h"
37#include "llvm/ADT/ScopeExit.h"
38#include "llvm/ADT/SmallVector.h"
39#include "llvm/Support/Allocator.h"
40#include "llvm/Support/Casting.h"
41#include "llvm/Support/Compiler.h"
42#include "llvm/Support/FormatVariadic.h"
43#include "llvm/Support/MemoryBuffer.h"
44#include "llvm/Support/raw_ostream.h"
54 if (
auto *
C = dyn_cast<CXXConstructExpr>(E)) {
55 auto NumArgs =
C->getNumArgs();
56 if (NumArgs == 1 || (NumArgs > 1 && isa<CXXDefaultArgExpr>(
C->getArg(1)))) {
57 Expr *A =
C->getArg(0);
58 if (
C->getParenOrBraceRange().isInvalid())
73 if (
auto *F = dyn_cast<CXXFunctionalCastExpr>(E)) {
74 if (F->getCastKind() == CK_ConstructorConversion)
75 return F->getSubExpr();
112 return HandlePointer(T);
116 return HandlePointer(T);
120 return HandlePointer(T);
124 return HandlePointer(T);
128 return HandlePointer(T);
150 auto L =
Visit(T.getPointeeLoc());
153 return T.getLocalSourceRange().getBegin();
159 auto FirstDefaultArg =
160 llvm::find_if(Args, [](
auto It) {
return isa<CXXDefaultArgExpr>(It); });
161 return llvm::make_range(Args.begin(), FirstDefaultArg);
168 case OO_ExclaimEqual:
170 case OO_GreaterEqual:
177 case OO_PercentEqual:
180 case OO_LessLessEqual:
181 case OO_GreaterGreaterEqual:
192 case OO_GreaterGreater:
197 return syntax::NodeKind::BinaryOperatorExpression;
200 return syntax::NodeKind::PrefixUnaryOperatorExpression;
206 return syntax::NodeKind::PrefixUnaryOperatorExpression;
208 return syntax::NodeKind::PostfixUnaryOperatorExpression;
210 llvm_unreachable(
"Invalid number of arguments for operator");
219 return syntax::NodeKind::PrefixUnaryOperatorExpression;
221 return syntax::NodeKind::BinaryOperatorExpression;
223 llvm_unreachable(
"Invalid number of arguments for operator");
225 return syntax::NodeKind::BinaryOperatorExpression;
230 case OO_Array_Delete:
234 return syntax::NodeKind::UnknownExpression;
236 return syntax::NodeKind::CallExpression;
240 llvm_unreachable(
"Not an overloadable operator");
242 llvm_unreachable(
"Unknown OverloadedOperatorKind enum");
251 assert((isa<DeclaratorDecl, TypedefNameDecl>(D)) &&
252 "only DeclaratorDecl and TypedefNameDecl are supported.");
255 bool IsAnonymous = DN.
isIdentifier() && !DN.getAsIdentifierInfo();
259 if (
const auto *DD = dyn_cast<DeclaratorDecl>(D)) {
260 if (DD->getQualifierLoc()) {
261 return DD->getQualifierLoc().getBeginLoc();
274 if (
auto *
V = dyn_cast<VarDecl>(D)) {
275 auto *I =
V->getInit();
277 if (I && !
V->isCXXForRangeDecl())
278 return I->getSourceRange();
297 if (Name.isValid()) {
302 if (End.isInvalid() ||
SM.isBeforeInTranslationUnit(End, Name))
307 assert(
SM.isBeforeInTranslationUnit(End, InitializerEnd) ||
308 End == InitializerEnd);
309 End = InitializerEnd;
316using ASTPtr = llvm::PointerUnion<Stmt *, Decl *>;
320class ASTToSyntaxMapping {
323 assert(To !=
nullptr);
324 assert(!From.isNull());
326 bool Added =
Nodes.insert({From, To}).second;
328 assert(Added &&
"mapping added twice");
332 assert(To !=
nullptr);
335 bool Added = NNSNodes.insert({From, To}).second;
337 assert(Added &&
"mapping added twice");
343 return NNSNodes.lookup(
P);
347 llvm::DenseMap<ASTPtr, syntax::Tree *>
Nodes;
348 llvm::DenseMap<NestedNameSpecifierLoc, syntax::Tree *> NNSNodes;
372 Pending(
Arena, TBTM.tokenBuffer()) {
374 LocationToToken.insert({T.location(), &T});
386 Pending.foldChildren(TBTM.
tokenBuffer(), Range, New);
388 Mapping.add(From, New);
399 Pending.foldChildren(TBTM.
tokenBuffer(), Range, New);
401 Mapping.add(From, New);
409 auto ListRange = Pending.shrinkToFitList(SuperRange);
410 Pending.foldChildren(TBTM.
tokenBuffer(), ListRange, New);
412 Mapping.add(From, New);
442 assert(!Tokens.empty());
443 assert(Tokens.back().kind() == tok::eof);
446 Pending.foldChildren(TBTM.
tokenBuffer(), Tokens.drop_back(),
449 auto *TU = cast<syntax::TranslationUnit>(std::move(Pending).
finalize());
450 TU->assertInvariantsRecursive();
459 assert(Range.isValid());
460 return getRange(Range.getBegin(), Range.getEnd());
468 assert(
First.isValid());
469 assert(
Last.isValid());
478 return maybeAppendSemicolon(Tokens, D);
484 assert((isa<DeclaratorDecl, TypedefNameDecl>(D)) &&
485 "only DeclaratorDecl and TypedefNameDecl are supported.");
490 if (Next ==
nullptr) {
495 if (D->
getKind() != Next->getKind()) {
512 if (
const auto *S = dyn_cast<TagDecl>(D))
513 Tokens =
getRange(S->TypeDecl::getBeginLoc(), S->getEndLoc());
516 return maybeAppendSemicolon(Tokens, D);
526 auto Tokens =
getRange(S->getSourceRange());
527 if (isa<CompoundStmt>(S))
532 if (Tokens.back().kind() == tok::semi)
534 return withTrailingSemicolon(Tokens);
539 const Decl *D)
const {
540 if (isa<NamespaceDecl>(D))
542 if (DeclsWithoutSemicolons.count(D))
546 return withTrailingSemicolon(Tokens);
551 assert(!Tokens.empty());
552 assert(Tokens.back().kind() != tok::eof);
554 if (Tokens.back().kind() != tok::semi && Tokens.end()->kind() == tok::semi)
581 Trees.insert(Trees.end(), {&T, L});
586 assert(!
Range.empty());
587 auto It = Trees.lower_bound(
Range.begin());
588 assert(It != Trees.end() &&
"no node found");
589 assert(It->first ==
Range.begin() &&
"no child with the specified range");
590 assert((std::next(It) == Trees.end() ||
591 std::next(It)->first ==
Range.end()) &&
592 "no child with the specified range");
594 "re-assigning role for a child");
595 It->second->setRole(Role);
601 auto BeginChildren = Trees.lower_bound(
Range.begin());
602 assert((BeginChildren == Trees.end() ||
603 BeginChildren->first ==
Range.begin()) &&
604 "Range crosses boundaries of existing subtrees");
606 auto EndChildren = Trees.lower_bound(
Range.end());
608 (EndChildren == Trees.end() || EndChildren->first ==
Range.end()) &&
609 "Range crosses boundaries of existing subtrees");
611 auto BelongsToList = [](
decltype(Trees)::value_type KV) {
612 auto Role = KV.second->getRole();
617 auto BeginListChildren =
618 std::find_if(BeginChildren, EndChildren, BelongsToList);
620 auto EndListChildren =
621 std::find_if_not(BeginListChildren, EndChildren, BelongsToList);
624 EndListChildren->first);
631 assert(
Node->getFirstChild() ==
nullptr &&
"node already has children");
633 auto *FirstToken = Tokens.begin();
634 auto BeginChildren = Trees.lower_bound(FirstToken);
636 assert((BeginChildren == Trees.end() ||
637 BeginChildren->first == FirstToken) &&
638 "fold crosses boundaries of existing subtrees");
639 auto EndChildren = Trees.lower_bound(Tokens.end());
641 (EndChildren == Trees.end() || EndChildren->first == Tokens.end()) &&
642 "fold crosses boundaries of existing subtrees");
644 for (
auto It = BeginChildren; It != EndChildren; ++It) {
645 auto *
C = It->second;
648 Node->appendChildLowLevel(
C);
652 Node->Original =
true;
656 Trees.erase(BeginChildren, EndChildren);
657 Trees.insert({FirstToken,
Node});
662 assert(Trees.size() == 1);
663 auto *Root = Trees.begin()->second;
670 for (
auto It = Trees.begin(); It != Trees.end(); ++It) {
671 unsigned CoveredTokens =
673 ? (std::next(It)->first - It->first)
677 formatv(
"- '{0}' covers '{1}'+{2} tokens\n", It->second->getKind(),
679 R += It->second->dump(STM);
688 std::map<const syntax::Token *, syntax::Node *> Trees;
692 std::string str() {
return Pending.str(TBTM); }
695 TokenBufferTokenManager& TBTM;
697 llvm::DenseMap<SourceLocation, const syntax::Token *> LocationToToken;
700 ASTToSyntaxMapping Mapping;
707 : Builder(Builder), Context(Context) {}
712 return processDeclaratorAndDeclaration(DD);
716 return processDeclaratorAndDeclaration(TD);
721 Builder.foldNode(Builder.getDeclarationRange(D),
731 if (!RecursiveASTVisitor::TraverseClassTemplateSpecializationDecl(
C))
733 if (
C->isExplicitSpecialization())
736 cast<syntax::SimpleDeclaration>(handleFreeStandingTagDecl(
C));
737 foldExplicitTemplateInstantiation(
738 Builder.getTemplateRange(
C), Builder.findToken(
C->getExternLoc()),
739 Builder.findToken(
C->getTemplateKeywordLoc()),
Declaration,
C);
744 foldTemplateDeclaration(
745 Builder.getDeclarationRange(S),
746 Builder.findToken(S->getTemplateParameters()->getTemplateLoc()),
747 Builder.getDeclarationRange(S->getTemplatedDecl()), S);
751 bool WalkUpFromTagDecl(
TagDecl *
C) {
753 if (!
C->isFreeStanding()) {
754 assert(
C->getNumTemplateParameterLists() == 0);
757 handleFreeStandingTagDecl(
C);
762 assert(
C->isFreeStanding());
764 auto DeclarationRange = Builder.getDeclarationRange(
C);
766 Builder.foldNode(DeclarationRange, Result,
nullptr);
770 const auto *TemplateKW = Builder.findToken(L.getTemplateLoc());
773 foldTemplateDeclaration(R, TemplateKW, DeclarationRange,
nullptr);
774 DeclarationRange = R;
776 if (
auto *S = dyn_cast<ClassTemplatePartialSpecializationDecl>(
C))
777 ConsumeTemplateParameters(*S->getTemplateParameters());
778 for (
unsigned I =
C->getNumTemplateParameterLists(); 0 < I; --I)
779 ConsumeTemplateParameters(*
C->getTemplateParameterList(I - 1));
792 Builder.markChildToken(S->getLBracLoc(), NodeRole::OpenParen);
793 for (
auto *Child : S->body())
794 Builder.markStmtChild(Child, NodeRole::Statement);
795 Builder.markChildToken(S->getRBracLoc(), NodeRole::CloseParen);
797 Builder.foldNode(Builder.getStmtRange(S),
804 Builder.foldNode(Builder.getStmtRange(S),
809 bool TraverseIfStmt(
IfStmt *S) {
810 bool Result = [&,
this]() {
817 if (S->hasVarStorage()) {
838 bool Result = [&,
this]() {
841 if (S->getLoopVariable() && !
TraverseDecl(S->getLoopVariable()))
843 if (S->getRangeInit() && !
TraverseStmt(S->getRangeInit()))
849 WalkUpFromCXXForRangeStmt(S);
854 if (
auto *DS = dyn_cast_or_null<DeclStmt>(S)) {
856 for (
auto *D : DS->decls())
857 Builder.noticeDeclWithoutSemicolon(D);
858 }
else if (
auto *E = dyn_cast_or_null<Expr>(S)) {
870 bool WalkUpFromExpr(
Expr *E) {
871 assert(!
isImplicitExpr(E) &&
"should be handled by TraverseStmt");
872 Builder.foldNode(Builder.getExprRange(E),
883 return WalkUpFromUserDefinedLiteral(S);
886 syntax::UserDefinedLiteralExpression *
888 switch (S->getLiteralOperatorKind()) {
890 return new (allocator()) syntax::IntegerUserDefinedLiteralExpression;
892 return new (allocator()) syntax::FloatUserDefinedLiteralExpression;
894 return new (allocator()) syntax::CharUserDefinedLiteralExpression;
896 return new (allocator()) syntax::StringUserDefinedLiteralExpression;
903 auto TokLoc = S->getBeginLoc();
910 if (
Literal.isIntegerLiteral())
911 return new (allocator()) syntax::IntegerUserDefinedLiteralExpression;
913 assert(
Literal.isFloatingLiteral());
914 return new (allocator()) syntax::FloatUserDefinedLiteralExpression;
917 llvm_unreachable(
"Unknown literal operator kind.");
921 Builder.markChildToken(S->getBeginLoc(), syntax::NodeRole::LiteralToken);
922 Builder.foldNode(Builder.getExprRange(S), buildUserDefinedLiteral(S), S);
941 if (
auto DependentTL =
946 SR.
setBegin(DependentTL.getTemplateKeywordLoc());
956 return syntax::NodeKind::GlobalNameSpecifier;
960 return syntax::NodeKind::IdentifierNameSpecifier;
962 return syntax::NodeKind::SimpleTemplateNameSpecifier;
966 if (isa<DecltypeType>(NNSType))
967 return syntax::NodeKind::DecltypeNameSpecifier;
968 if (isa<TemplateSpecializationType, DependentTemplateSpecializationType>(
970 return syntax::NodeKind::SimpleTemplateNameSpecifier;
971 return syntax::NodeKind::IdentifierNameSpecifier;
975 llvm::report_fatal_error(
"We don't yet support the __super specifier",
980 syntax::NameSpecifier *
983 auto NameSpecifierTokens =
984 Builder.getRange(getLocalSourceRange(NNSLoc)).drop_back();
986 case syntax::NodeKind::GlobalNameSpecifier:
987 return new (allocator()) syntax::GlobalNameSpecifier;
988 case syntax::NodeKind::IdentifierNameSpecifier: {
989 assert(NameSpecifierTokens.size() == 1);
990 Builder.markChildToken(NameSpecifierTokens.begin(),
991 syntax::NodeRole::Unknown);
992 auto *NS =
new (allocator()) syntax::IdentifierNameSpecifier;
993 Builder.foldNode(NameSpecifierTokens, NS,
nullptr);
996 case syntax::NodeKind::SimpleTemplateNameSpecifier: {
1002 auto *NS =
new (allocator()) syntax::SimpleTemplateNameSpecifier;
1003 Builder.foldNode(NameSpecifierTokens, NS,
nullptr);
1006 case syntax::NodeKind::DecltypeNameSpecifier: {
1008 if (!RecursiveASTVisitor::TraverseDecltypeTypeLoc(TL))
1010 auto *NS =
new (allocator()) syntax::DecltypeNameSpecifier;
1015 Builder.foldNode(NameSpecifierTokens, NS,
nullptr);
1019 llvm_unreachable(
"getChildKind() does not return this value");
1030 for (
auto It = QualifierLoc; It; It = It.getPrefix()) {
1031 auto *NS = buildNameSpecifier(It);
1034 Builder.markChild(NS, syntax::NodeRole::ListElement);
1035 Builder.markChildToken(It.getEndLoc(), syntax::NodeRole::ListDelimiter);
1037 Builder.foldNode(Builder.getRange(QualifierLoc.
getSourceRange()),
1048 Builder.markChild(QualifierLoc, syntax::NodeRole::Qualifier);
1049 if (TemplateKeywordLoc.
isValid())
1050 Builder.markChildToken(TemplateKeywordLoc,
1051 syntax::NodeRole::TemplateKeyword);
1055 Builder.foldNode(Builder.getRange(UnqualifiedIdLoc), TheUnqualifiedId,
1057 Builder.markChild(TheUnqualifiedId, syntax::NodeRole::UnqualifiedId);
1059 auto IdExpressionBeginLoc =
1062 auto *TheIdExpression =
new (allocator()) syntax::IdExpression;
1064 Builder.getRange(IdExpressionBeginLoc, UnqualifiedIdLoc.
getEnd()),
1065 TheIdExpression, From);
1067 return TheIdExpression;
1074 if (S->isImplicitAccess()) {
1075 buildIdExpression(S->getQualifierLoc(), S->getTemplateKeywordLoc(),
1076 SourceRange(S->getMemberLoc(), S->getEndLoc()), S);
1080 auto *TheIdExpression = buildIdExpression(
1081 S->getQualifierLoc(), S->getTemplateKeywordLoc(),
1082 SourceRange(S->getMemberLoc(), S->getEndLoc()),
nullptr);
1084 Builder.markChild(TheIdExpression, syntax::NodeRole::Member);
1086 Builder.markExprChild(S->getBase(), syntax::NodeRole::Object);
1087 Builder.markChildToken(S->getOperatorLoc(), syntax::NodeRole::AccessToken);
1089 Builder.foldNode(Builder.getExprRange(S),
1090 new (allocator()) syntax::MemberExpression, S);
1095 buildIdExpression(S->getQualifierLoc(), S->getTemplateKeywordLoc(),
1096 SourceRange(S->getLocation(), S->getEndLoc()), S);
1103 buildIdExpression(S->getQualifierLoc(), S->getTemplateKeywordLoc(),
1104 SourceRange(S->getLocation(), S->getEndLoc()), S);
1110 if (!S->isImplicit()) {
1111 Builder.markChildToken(S->getLocation(),
1112 syntax::NodeRole::IntroducerKeyword);
1113 Builder.foldNode(Builder.getExprRange(S),
1114 new (allocator()) syntax::ThisExpression, S);
1119 bool WalkUpFromParenExpr(
ParenExpr *S) {
1120 Builder.markChildToken(S->getLParen(), syntax::NodeRole::OpenParen);
1121 Builder.markExprChild(S->getSubExpr(), syntax::NodeRole::SubExpression);
1122 Builder.markChildToken(S->getRParen(), syntax::NodeRole::CloseParen);
1123 Builder.foldNode(Builder.getExprRange(S),
1124 new (allocator()) syntax::ParenExpression, S);
1129 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1130 Builder.foldNode(Builder.getExprRange(S),
1131 new (allocator()) syntax::IntegerLiteralExpression, S);
1136 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1137 Builder.foldNode(Builder.getExprRange(S),
1138 new (allocator()) syntax::CharacterLiteralExpression, S);
1143 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1144 Builder.foldNode(Builder.getExprRange(S),
1145 new (allocator()) syntax::FloatingLiteralExpression, S);
1150 Builder.markChildToken(S->getBeginLoc(), syntax::NodeRole::LiteralToken);
1151 Builder.foldNode(Builder.getExprRange(S),
1152 new (allocator()) syntax::StringLiteralExpression, S);
1157 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1158 Builder.foldNode(Builder.getExprRange(S),
1159 new (allocator()) syntax::BoolLiteralExpression, S);
1164 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1165 Builder.foldNode(Builder.getExprRange(S),
1166 new (allocator()) syntax::CxxNullPtrExpression, S);
1171 Builder.markChildToken(S->getOperatorLoc(),
1172 syntax::NodeRole::OperatorToken);
1173 Builder.markExprChild(S->getSubExpr(), syntax::NodeRole::Operand);
1176 Builder.foldNode(Builder.getExprRange(S),
1180 Builder.foldNode(Builder.getExprRange(S),
1188 Builder.markExprChild(S->getLHS(), syntax::NodeRole::LeftHandSide);
1189 Builder.markChildToken(S->getOperatorLoc(),
1190 syntax::NodeRole::OperatorToken);
1191 Builder.markExprChild(S->getRHS(), syntax::NodeRole::RightHandSide);
1192 Builder.foldNode(Builder.getExprRange(S),
1202 for (
auto *Arg : Args) {
1203 Builder.markExprChild(Arg, syntax::NodeRole::ListElement);
1204 const auto *DelimiterToken =
1205 std::next(Builder.findToken(Arg->getEndLoc()));
1206 if (DelimiterToken->kind() == clang::tok::TokenKind::comma)
1207 Builder.markChildToken(DelimiterToken, syntax::NodeRole::ListDelimiter);
1212 Builder.foldNode(Builder.getRange((*Args.begin())->getBeginLoc(),
1213 (*(Args.end() - 1))->getEndLoc()),
1219 bool WalkUpFromCallExpr(
CallExpr *S) {
1220 Builder.markExprChild(S->getCallee(), syntax::NodeRole::Callee);
1222 const auto *LParenToken =
1223 std::next(Builder.findToken(S->getCallee()->getEndLoc()));
1226 if (LParenToken->kind() == clang::tok::l_paren)
1227 Builder.markChildToken(LParenToken, syntax::NodeRole::OpenParen);
1229 Builder.markChild(buildCallArguments(S->arguments()),
1230 syntax::NodeRole::Arguments);
1232 Builder.markChildToken(S->getRParenLoc(), syntax::NodeRole::CloseParen);
1234 Builder.foldNode(Builder.getRange(S->getSourceRange()),
1235 new (allocator()) syntax::CallExpression, S);
1241 if ((S->getNumArgs() == 0 || isa<CXXDefaultArgExpr>(S->getArg(0))) &&
1242 S->getParenOrBraceRange().isInvalid())
1244 return RecursiveASTVisitor::WalkUpFromCXXConstructExpr(S);
1252 for (
auto *child : S->arguments()) {
1259 if (child->getSourceRange().isInvalid()) {
1261 syntax::NodeKind::PostfixUnaryOperatorExpression);
1267 return WalkUpFromCXXOperatorCallExpr(S);
1272 case syntax::NodeKind::BinaryOperatorExpression:
1273 Builder.markExprChild(S->getArg(0), syntax::NodeRole::LeftHandSide);
1274 Builder.markChildToken(S->getOperatorLoc(),
1275 syntax::NodeRole::OperatorToken);
1276 Builder.markExprChild(S->getArg(1), syntax::NodeRole::RightHandSide);
1277 Builder.foldNode(Builder.getExprRange(S),
1280 case syntax::NodeKind::PrefixUnaryOperatorExpression:
1281 Builder.markChildToken(S->getOperatorLoc(),
1282 syntax::NodeRole::OperatorToken);
1283 Builder.markExprChild(S->getArg(0), syntax::NodeRole::Operand);
1284 Builder.foldNode(Builder.getExprRange(S),
1288 case syntax::NodeKind::PostfixUnaryOperatorExpression:
1289 Builder.markChildToken(S->getOperatorLoc(),
1290 syntax::NodeRole::OperatorToken);
1291 Builder.markExprChild(S->getArg(0), syntax::NodeRole::Operand);
1292 Builder.foldNode(Builder.getExprRange(S),
1296 case syntax::NodeKind::CallExpression: {
1297 Builder.markExprChild(S->getArg(0), syntax::NodeRole::Callee);
1299 const auto *LParenToken =
1300 std::next(Builder.findToken(S->getArg(0)->getEndLoc()));
1303 if (LParenToken->kind() == clang::tok::l_paren)
1304 Builder.markChildToken(LParenToken, syntax::NodeRole::OpenParen);
1307 S->arg_begin() + 1, S->arg_end())),
1308 syntax::NodeRole::Arguments);
1310 Builder.markChildToken(S->getRParenLoc(), syntax::NodeRole::CloseParen);
1312 Builder.foldNode(Builder.getRange(S->getSourceRange()),
1313 new (allocator()) syntax::CallExpression, S);
1316 case syntax::NodeKind::UnknownExpression:
1317 return WalkUpFromExpr(S);
1319 llvm_unreachable(
"getOperatorNodeKind() does not return this value");
1326 auto Tokens = Builder.getDeclarationRange(S);
1327 if (Tokens.front().kind() == tok::coloncolon) {
1341 if (!WalkUpFromParenTypeLoc(L))
1347 Builder.markChildToken(L.
getLParenLoc(), syntax::NodeRole::OpenParen);
1348 Builder.markChildToken(L.
getRParenLoc(), syntax::NodeRole::CloseParen);
1356 Builder.markChildToken(L.
getLBracketLoc(), syntax::NodeRole::OpenParen);
1357 Builder.markExprChild(L.
getSizeExpr(), syntax::NodeRole::Size);
1358 Builder.markChildToken(L.
getRBracketLoc(), syntax::NodeRole::CloseParen);
1366 for (
auto *
P : Params) {
1367 Builder.markChild(
P, syntax::NodeRole::ListElement);
1368 const auto *DelimiterToken = std::next(Builder.findToken(
P->getEndLoc()));
1369 if (DelimiterToken->kind() == clang::tok::TokenKind::comma)
1370 Builder.markChildToken(DelimiterToken, syntax::NodeRole::ListDelimiter);
1373 if (!Params.empty())
1374 Builder.foldNode(Builder.getRange(Params.front()->getBeginLoc(),
1375 Params.back()->getEndLoc()),
1381 Builder.markChildToken(L.
getLParenLoc(), syntax::NodeRole::OpenParen);
1383 Builder.markChild(buildParameterDeclarationList(L.
getParams()),
1384 syntax::NodeRole::Parameters);
1386 Builder.markChildToken(L.
getRParenLoc(), syntax::NodeRole::CloseParen);
1394 return WalkUpFromFunctionTypeLoc(L);
1396 auto *TrailingReturnTokens = buildTrailingReturn(L);
1398 Builder.markChild(TrailingReturnTokens, syntax::NodeRole::TrailingReturn);
1399 return WalkUpFromFunctionTypeLoc(L);
1407 if (!WalkUpFromMemberPointerTypeLoc(L))
1414 Builder.foldNode(Builder.getRange(SR),
1422 bool WalkUpFromDeclStmt(
DeclStmt *S) {
1423 Builder.foldNode(Builder.getStmtRange(S),
1428 bool WalkUpFromNullStmt(
NullStmt *S) {
1429 Builder.foldNode(Builder.getStmtRange(S),
1435 Builder.markChildToken(S->getSwitchLoc(),
1436 syntax::NodeRole::IntroducerKeyword);
1437 Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
1438 Builder.foldNode(Builder.getStmtRange(S),
1443 bool WalkUpFromCaseStmt(
CaseStmt *S) {
1444 Builder.markChildToken(S->getKeywordLoc(),
1445 syntax::NodeRole::IntroducerKeyword);
1446 Builder.markExprChild(S->getLHS(), syntax::NodeRole::CaseValue);
1447 Builder.markStmtChild(S->getSubStmt(), syntax::NodeRole::BodyStatement);
1448 Builder.foldNode(Builder.getStmtRange(S),
1454 Builder.markChildToken(S->getKeywordLoc(),
1455 syntax::NodeRole::IntroducerKeyword);
1456 Builder.markStmtChild(S->getSubStmt(), syntax::NodeRole::BodyStatement);
1457 Builder.foldNode(Builder.getStmtRange(S),
1462 bool WalkUpFromIfStmt(
IfStmt *S) {
1463 Builder.markChildToken(S->getIfLoc(), syntax::NodeRole::IntroducerKeyword);
1464 Stmt *ConditionStatement = S->getCond();
1465 if (S->hasVarStorage())
1466 ConditionStatement = S->getConditionVariableDeclStmt();
1467 Builder.markStmtChild(ConditionStatement, syntax::NodeRole::Condition);
1468 Builder.markStmtChild(S->getThen(), syntax::NodeRole::ThenStatement);
1469 Builder.markChildToken(S->getElseLoc(), syntax::NodeRole::ElseKeyword);
1470 Builder.markStmtChild(S->getElse(), syntax::NodeRole::ElseStatement);
1471 Builder.foldNode(Builder.getStmtRange(S),
1476 bool WalkUpFromForStmt(
ForStmt *S) {
1477 Builder.markChildToken(S->getForLoc(), syntax::NodeRole::IntroducerKeyword);
1478 Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
1479 Builder.foldNode(Builder.getStmtRange(S),
1484 bool WalkUpFromWhileStmt(
WhileStmt *S) {
1485 Builder.markChildToken(S->getWhileLoc(),
1486 syntax::NodeRole::IntroducerKeyword);
1487 Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
1488 Builder.foldNode(Builder.getStmtRange(S),
1494 Builder.markChildToken(S->getContinueLoc(),
1495 syntax::NodeRole::IntroducerKeyword);
1496 Builder.foldNode(Builder.getStmtRange(S),
1501 bool WalkUpFromBreakStmt(
BreakStmt *S) {
1502 Builder.markChildToken(S->getBreakLoc(),
1503 syntax::NodeRole::IntroducerKeyword);
1504 Builder.foldNode(Builder.getStmtRange(S),
1510 Builder.markChildToken(S->getReturnLoc(),
1511 syntax::NodeRole::IntroducerKeyword);
1512 Builder.markExprChild(S->getRetValue(), syntax::NodeRole::ReturnValue);
1513 Builder.foldNode(Builder.getStmtRange(S),
1519 Builder.markChildToken(S->getForLoc(), syntax::NodeRole::IntroducerKeyword);
1520 Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
1521 Builder.foldNode(Builder.getStmtRange(S),
1526 bool WalkUpFromEmptyDecl(
EmptyDecl *S) {
1527 Builder.foldNode(Builder.getDeclarationRange(S),
1533 Builder.markExprChild(S->getAssertExpr(), syntax::NodeRole::Condition);
1534 Builder.markExprChild(S->getMessage(), syntax::NodeRole::Message);
1535 Builder.foldNode(Builder.getDeclarationRange(S),
1541 Builder.foldNode(Builder.getDeclarationRange(S),
1548 Builder.foldNode(Builder.getDeclarationRange(S),
1554 Builder.foldNode(Builder.getDeclarationRange(S),
1559 bool WalkUpFromUsingDecl(
UsingDecl *S) {
1560 Builder.foldNode(Builder.getDeclarationRange(S),
1566 Builder.foldNode(Builder.getDeclarationRange(S),
1572 Builder.foldNode(Builder.getDeclarationRange(S),
1578 Builder.foldNode(Builder.getDeclarationRange(S),
1586 template <
class T>
bool processDeclaratorAndDeclaration(T *D) {
1588 Builder.sourceManager(), D->getTypeSourceInfo()->getTypeLoc(),
1593 if (!
Range.getBegin().isValid()) {
1595 syntax::NodeRole::Declarators);
1596 Builder.foldNode(Builder.getDeclarationRange(D),
1602 Builder.foldNode(Builder.getRange(Range), N,
nullptr);
1603 Builder.markChild(N, syntax::NodeRole::ListElement);
1605 if (!Builder.isResponsibleForCreatingDeclaration(D)) {
1608 const auto *DelimiterToken = std::next(Builder.findToken(
Range.getEnd()));
1609 if (DelimiterToken->kind() == clang::tok::TokenKind::comma)
1610 Builder.markChildToken(DelimiterToken, syntax::NodeRole::ListDelimiter);
1613 auto DeclarationRange = Builder.getDeclarationRange(D);
1614 Builder.foldList(DeclarationRange, DL,
nullptr);
1616 Builder.markChild(DL, syntax::NodeRole::Declarators);
1617 Builder.foldNode(DeclarationRange,
1629 auto ReturnDeclaratorRange =
SourceRange(GetStartLoc().Visit(ReturnedType),
1630 ReturnedType.getEndLoc());
1632 if (ReturnDeclaratorRange.isValid()) {
1634 Builder.foldNode(Builder.getRange(ReturnDeclaratorRange),
1635 ReturnDeclarator,
nullptr);
1639 auto Return = Builder.getRange(ReturnedType.getSourceRange());
1640 const auto *Arrow = Return.begin() - 1;
1641 assert(Arrow->kind() == tok::arrow);
1643 Builder.markChildToken(Arrow, syntax::NodeRole::ArrowToken);
1644 if (ReturnDeclarator)
1645 Builder.markChild(ReturnDeclarator, syntax::NodeRole::Declarator);
1647 Builder.foldNode(Tokens, R, L);
1651 void foldExplicitTemplateInstantiation(
1655 assert(!ExternKW || ExternKW->
kind() == tok::kw_extern);
1656 assert(TemplateKW && TemplateKW->
kind() == tok::kw_template);
1657 Builder.markChildToken(ExternKW, syntax::NodeRole::ExternKeyword);
1658 Builder.markChildToken(TemplateKW, syntax::NodeRole::IntroducerKeyword);
1659 Builder.markChild(InnerDeclaration, syntax::NodeRole::Declaration);
1667 assert(TemplateKW && TemplateKW->
kind() == tok::kw_template);
1668 Builder.markChildToken(TemplateKW, syntax::NodeRole::IntroducerKeyword);
1671 Builder.foldNode(Range, N, From);
1672 Builder.markChild(N, syntax::NodeRole::Declaration);
1677 llvm::BumpPtrAllocator &allocator() {
return Builder.allocator(); }
1685 DeclsWithoutSemicolons.insert(D);
1691 Pending.assignRole(*findToken(Loc), Role);
1697 Pending.assignRole(*T, R);
1706 auto *SN = Mapping.find(N);
1707 assert(SN !=
nullptr);
1711 auto *SN = Mapping.find(NNSLoc);
1712 assert(SN !=
nullptr);
1721 if (
Expr *ChildExpr = dyn_cast<Expr>(Child)) {
1727 Pending.foldChildren(TBTM.tokenBuffer(), getStmtRange(Child), ChildNode);
1729 ChildNode = Mapping.find(Child);
1731 assert(ChildNode !=
nullptr);
1732 setRole(ChildNode, Role);
1741 assert(ChildNode !=
nullptr);
1742 setRole(ChildNode, Role);
1748 auto It = LocationToToken.find(L);
1749 assert(It != LocationToToken.end());
1757 BuildTreeVisitor(Context, Builder).TraverseAST(Context);
1758 return std::move(Builder).finalize();
Forward declaration of all AST node types.
BoundNodesTreeBuilder Nodes
static SourceRange getDeclaratorRange(const SourceManager &SM, TypeLoc T, SourceLocation Name, SourceRange Initializer)
Gets the range of declarator as defined by the C++ grammar.
static Expr * IgnoreImplicit(Expr *E)
static CallExpr::arg_range dropDefaultArgs(CallExpr::arg_range Args)
static LLVM_ATTRIBUTE_UNUSED bool isImplicitExpr(Expr *E)
static Expr * IgnoreCXXFunctionalCastExprWrappingConstructor(Expr *E)
static syntax::NodeKind getOperatorNodeKind(const CXXOperatorCallExpr &E)
static SourceLocation getQualifiedNameStart(NamedDecl *D)
Get the start of the qualified name.
static SourceRange getInitializerRange(Decl *D)
Gets the range of the initializer inside an init-declarator C++ [dcl.decl].
static Expr * IgnoreImplicitConstructorSingleStep(Expr *E)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the clang::TokenKind enum and support functions.
Defines the clang::TypeLoc interface and its subclasses.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
const LangOptions & getLangOpts() const
DiagnosticsEngine & getDiagnostics() const
const TargetInfo & getTargetInfo() const
Wrapper for source info for arrays.
SourceLocation getLBracketLoc() const
Expr * getSizeExpr() const
SourceLocation getRBracketLoc() const
A builtin binary operation expression such as "x + y" or "x <= y".
Wrapper for source info for block pointers.
BreakStmt - This represents a break.
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a call to a C++ constructor.
A default argument (C++ [dcl.fct.default]).
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
The null pointer literal (C++11 [lex.nullptr])
A call to an overloaded operator written using operator syntax.
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Represents the this expression in C++.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
llvm::iterator_range< arg_iterator > arg_range
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
CaseStmt - Represent a case statement.
Represents a class template specialization, which refers to a class template with a given set of temp...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
CompoundStmt - This represents a group of statements like { stmt stmt }.
ContinueStmt - This represents a continue.
A reference to a declared variable, function, enum, etc.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Decl * getNextDeclInContext()
SourceLocation getLocation() const
SourceLocation getBeginLoc() const LLVM_READONLY
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
bool isIdentifier() const
Predicate functions for querying what type of name this is.
Represents a ValueDecl that came out of a declarator.
A qualified reference to a name whose declaration cannot yet be resolved.
Represents an empty-declaration.
This represents one expression.
ForStmt - This represents a 'for (init;cond;inc)' stmt.
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Wrapper for source info for functions.
ArrayRef< ParmVarDecl * > getParams() const
TypeLoc getReturnLoc() const
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
IfStmt - This represents an if/then/else.
const TypeClass * getTypePtr() const
Represents a linkage specification.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Wrapper for source info for member pointers.
SourceRange getLocalSourceRange() const
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a C++ namespace alias.
Represent a C++ namespace.
A C++ nested-name-specifier augmented with source location information.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
SourceRange getLocalSourceRange() const
Retrieve the source range covering just the last part of this nested-name-specifier,...
bool hasQualifier() const
Evaluates true when this nested-name-specifier location is empty.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
NullStmt - This is the null statement ";": C99 6.8.3p3.
NumericLiteralParser - This performs strict semantic analysis of the content of a ppnumber,...
Wraps an ObjCPointerType with source location information.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
ParenExpr - This represents a parethesized expression, e.g.
SourceLocation getRParenLoc() const
SourceLocation getLParenLoc() const
TypeLoc getInnerLoc() const
TypeLoc getPointeeLoc() const
Wrapper for source info for pointers.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
Recursively visit a C++ nested-name-specifier with location information.
bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue=nullptr)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
bool TraverseDecl(Decl *D)
Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic ty...
bool WalkUpFromStmt(Stmt *S)
bool TraverseTypeLoc(TypeLoc TL)
Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument ty...
bool shouldTraversePostOrder() const
Return whether this visitor should traverse post-order.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getEnd() const
SourceLocation getBegin() const
Represents a C++11 static_assert declaration.
Stmt - This represents one statement.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
StringLiteral - This represents a string literal expression, e.g.
SwitchStmt - This represents a 'switch' stmt.
Represents the declaration of a struct/union/class/enum.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Stores a list of template parameters for a TemplateDecl and its derived classes.
The top declaration context.
Represents the declaration of a typedef-name via a C++11 alias-declaration.
RetTy Visit(TypeLoc TyLoc)
RetTy VisitTypeLoc(TypeLoc TyLoc)
Base wrapper for a particular "section" of type source info.
TypeLoc getNextTypeLoc() const
Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the TypeLoc is a PointerLoc and next Typ...
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
SourceLocation getEndLoc() const
Get the end source location.
Base class for declarations which introduce a typedef-name.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Represents a dependent using declaration which was marked with typename.
Represents a dependent using declaration which was not marked with typename.
A call to a literal operator (C++11 [over.literal]) written as a user-defined literal (C++11 [lit....
@ LOK_String
operator "" X (const CharT *, size_t)
@ LOK_Raw
Raw form: operator "" X (const char *)
@ LOK_Floating
operator "" X (long double)
@ LOK_Integer
operator "" X (unsigned long long)
@ LOK_Template
Raw form: operator "" X<cs...> ()
@ LOK_Character
operator "" X (CharT)
Represents a C++ using-declaration.
Represents C++ using-directive.
WhileStmt - This represents a 'while' stmt.
A memory arena for syntax trees.
llvm::BumpPtrAllocator & getAllocator()
Array size specified inside a declarator.
Models arguments of a function call.
{ statement1; statement2; … }
A declaration that can appear at the top-level.
A semicolon in the top-level context. Does not declare anything.
The no-op statement, i.e. ';'.
template <declaration> Examples: template struct X<int> template void foo<int>() template int var<dou...
Expression in a statement position, e.g.
for (<init>; <cond>; <increment>) <body>
if (cond) <then-statement> else <else-statement> FIXME: add condition that models 'expression or vari...
A leaf node points to a single token.
extern <string-literal> declaration extern <string-literal> { <decls> }
A list of Elements separated or terminated by a fixed token.
Member pointer inside a declarator E.g.
namespace <name> = <namespace-reference>
namespace <name> { <decls> }
Models a nested-name-specifier.
Models a parameter-declaration-list which appears within parameters-and-qualifiers.
Parameter list for a function type and a trailing return type, if the function has one.
Declarator inside parentheses.
for (<decl> : <init>) <body>
Groups multiple declarators (e.g.
A top-level declarator without parentheses.
static_assert(<condition>, <message>) static_assert(<condition>)
template <template-parameters> <declaration>
A TokenBuffer-powered token manager.
const TokenBuffer & tokenBuffer() const
SourceManager & sourceManager()
A list of tokens obtained by preprocessing a text buffer and operations to map between the expanded a...
llvm::ArrayRef< syntax::Token > expandedTokens() const
All tokens produced by the preprocessor after all macro replacements, directives, etc.
std::optional< llvm::ArrayRef< syntax::Token > > spelledForExpanded(llvm::ArrayRef< syntax::Token > Expanded) const
Returns the subrange of spelled tokens corresponding to AST node spanning Expanded.
uintptr_t Key
A key to identify a specific token.
A token coming directly from a file or from a macro invocation.
tok::TokenKind kind() const
Trailing return type after the parameter list, including the arrow token.
A node that has children and represents a syntactic language construct.
Declaration of an unknown kind, e.g. not yet supported in syntax trees.
An expression of an unknown kind, i.e.
A statement of an unknown kind, i.e.
Models an unqualified-id.
using <scope>::<name> using typename <scope>::<name>
A helper class for constructing the syntax tree while traversing a clang AST.
ArrayRef< syntax::Token > getRange(SourceLocation First, SourceLocation Last) const
Finds the syntax tokens corresponding to the passed source locations.
ArrayRef< syntax::Token > getStmtRange(const Stmt *S) const
Find the adjusted range for the statement, consuming the trailing semicolon when needed.
void foldList(ArrayRef< syntax::Token > SuperRange, syntax::List *New, ASTPtr From)
Populate children for New list, assuming it covers tokens from a subrange of SuperRange.
void markExprChild(Expr *Child, NodeRole Role)
Should be called for expressions in non-statement position to avoid wrapping into expression statemen...
const SourceManager & sourceManager() const
void markChildToken(SourceLocation Loc, NodeRole R)
Set role for a token starting at Loc.
ArrayRef< syntax::Token > getDeclarationRange(Decl *D)
void markChild(syntax::Node *N, NodeRole R)
Set role for N.
void foldNode(ArrayRef< syntax::Token > Range, syntax::Tree *New, TypeLoc L)
const syntax::Token * findToken(SourceLocation L) const
Finds a token starting at L. The token must exist if L is valid.
void noticeDeclWithoutSemicolon(Decl *D)
Notifies that we should not consume trailing semicolon when computing token range of D.
ArrayRef< syntax::Token > getRange(SourceRange Range) const
Finds the syntax tokens corresponding to the SourceRange.
bool isResponsibleForCreatingDeclaration(const Decl *D) const
Returns true if D is the last declarator in a chain and is thus reponsible for creating SimpleDeclara...
syntax::TranslationUnit * finalize() &&
Finish building the tree and consume the root node.
void foldNode(ArrayRef< syntax::Token > Range, syntax::Tree *New, ASTPtr From)
Populate children for New node, assuming it covers tokens from Range.
TreeBuilder(syntax::Arena &Arena, TokenBufferTokenManager &TBTM)
ArrayRef< syntax::Token > getTemplateRange(const ClassTemplateSpecializationDecl *D) const
void foldNode(llvm::ArrayRef< syntax::Token > Range, syntax::Tree *New, NestedNameSpecifierLoc From)
ArrayRef< syntax::Token > getExprRange(const Expr *E) const
void markStmtChild(Stmt *Child, NodeRole Role)
Mark the Child node with a corresponding Role.
llvm::BumpPtrAllocator & allocator()
uint32_t Literal
Literals are represented as positive integers.
NodeRole
A relation between a parent and child node, e.g.
@ ListElement
List API roles.
@ Detached
A node without a parent.
@ Unknown
Children of an unknown semantic nature, e.g. skipped tokens, comments.
syntax::TranslationUnit * buildSyntaxTree(Arena &A, TokenBufferTokenManager &TBTM, ASTContext &Context)
Build a syntax tree for the main file.
NodeKind
A kind of a syntax node, used for implementing casts.
@ OO_None
Not an overloaded operator.
@ NUM_OVERLOADED_OPERATORS
Expr * IgnoreExprNodes(Expr *E, FnTys &&... Fns)
Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *, Recursively apply each of the f...
@ C
Languages that the frontend can parse and compile.
@ Result
The result type of a method or function.
Expr * IgnoreImplicitSingleStep(Expr *E)
void finalize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)