;
54 if(
auto*
C= dyn_cast<CXXConstructExpr>(
E)) {
55 autoNumArgs =
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 returnF->getSubExpr();
102structGetStartLoc :
TypeLocVisitor<GetStartLoc, SourceLocation> {
104 autoL =
Visit(
T.getInnerLoc());
107 return T.getLParenLoc();
112 returnHandlePointer(
T);
116 returnHandlePointer(
T);
120 returnHandlePointer(
T);
124 returnHandlePointer(
T);
128 returnHandlePointer(
T);
136 autoN =
T.getNextTypeLoc();
150 autoL =
Visit(
T.getPointeeLoc());
153 return T.getLocalSourceRange().getBegin();
159 autoFirstDefaultArg =
160llvm::find_if(Args, [](
autoIt) {
returnisa<CXXDefaultArgExpr>(It); });
161 returnllvm::make_range(Args.begin(), FirstDefaultArg);
165 switch(
E.getOperator()) {
168 caseOO_ExclaimEqual:
170 caseOO_GreaterEqual:
177 caseOO_PercentEqual:
180 caseOO_LessLessEqual:
181 caseOO_GreaterGreaterEqual:
192 caseOO_GreaterGreater:
197 returnsyntax::NodeKind::BinaryOperatorExpression;
200 returnsyntax::NodeKind::PrefixUnaryOperatorExpression;
204 switch(
E.getNumArgs()) {
206 returnsyntax::NodeKind::PrefixUnaryOperatorExpression;
208 returnsyntax::NodeKind::PostfixUnaryOperatorExpression;
210llvm_unreachable(
"Invalid number of arguments for operator");
217 switch(
E.getNumArgs()) {
219 returnsyntax::NodeKind::PrefixUnaryOperatorExpression;
221 returnsyntax::NodeKind::BinaryOperatorExpression;
223llvm_unreachable(
"Invalid number of arguments for operator");
225 returnsyntax::NodeKind::BinaryOperatorExpression;
230 caseOO_Array_Delete:
234 returnsyntax::NodeKind::UnknownExpression;
236 returnsyntax::NodeKind::CallExpression;
240llvm_unreachable(
"Not an overloadable operator");
242llvm_unreachable(
"Unknown OverloadedOperatorKind enum");
251assert((isa<DeclaratorDecl, TypedefNameDecl>(
D)) &&
252 "only DeclaratorDecl and TypedefNameDecl are supported.");
254 autoDN =
D->getDeclName();
255 boolIsAnonymous = DN.isIdentifier() && !DN.getAsIdentifierInfo();
259 if(
const auto*DD = dyn_cast<DeclaratorDecl>(
D)) {
260 if(DD->getQualifierLoc()) {
261 returnDD->getQualifierLoc().getBeginLoc();
274 if(
auto*
V= dyn_cast<VarDecl>(
D)) {
275 auto*I =
V->getInit();
277 if(I && !
V->isCXXForRangeDecl())
278 returnI->getSourceRange();
297 if(Name.isValid()) {
302 if(End.isInvalid() ||
SM.isBeforeInTranslationUnit(End, Name))
307assert(
SM.isBeforeInTranslationUnit(End, InitializerEnd) ||
308End == InitializerEnd);
309End = InitializerEnd;
316usingASTPtr = llvm::PointerUnion<Stmt *, Decl *>;
320classASTToSyntaxMapping {
323assert(To !=
nullptr);
324assert(!From.isNull());
326 boolAdded =
Nodes.insert({From, To}).second;
328assert(Added &&
"mapping added twice");
332assert(To !=
nullptr);
335 boolAdded = NNSNodes.insert({From, To}).second;
337assert(Added &&
"mapping added twice");
343 returnNNSNodes.lookup(
P);
347llvm::DenseMap<ASTPtr, syntax::Tree *>
Nodes;
348llvm::DenseMap<NestedNameSpecifierLoc, syntax::Tree *> NNSNodes;
372Pending(
Arena, TBTM.tokenBuffer()) {
374LocationToToken.insert({
T.location(), &
T});
388Mapping.add(From, New);
401Mapping.add(From, New);
409 autoListRange = Pending.shrinkToFitList(SuperRange);
410Pending.foldChildren(TBTM.
tokenBuffer(), ListRange, New);
412Mapping.add(From, New);
442assert(!Tokens.empty());
443assert(Tokens.back().kind() == tok::eof);
446Pending.foldChildren(TBTM.
tokenBuffer(), Tokens.drop_back(),
449 auto*TU = cast<syntax::TranslationUnit>(std::move(Pending).
finalize());
450TU->assertInvariantsRecursive();
468assert(
First.isValid());
469assert(
Last.isValid());
478 returnmaybeAppendSemicolon(Tokens,
D);
484assert((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))
513Tokens =
getRange(S->TypeDecl::getBeginLoc(), S->getEndLoc());
516 returnmaybeAppendSemicolon(Tokens,
D);
526 autoTokens =
getRange(S->getSourceRange());
527 if(isa<CompoundStmt>(S))
532 if(Tokens.back().kind() == tok::semi)
534 returnwithTrailingSemicolon(Tokens);
539 const Decl*
D)
const{
540 if(isa<NamespaceDecl>(
D))
542 if(DeclsWithoutSemicolons.count(
D))
546 returnwithTrailingSemicolon(Tokens);
551assert(!Tokens.empty());
552assert(Tokens.back().kind() != tok::eof);
554 if(Tokens.back().kind() != tok::semi && Tokens.end()->kind() == tok::semi)
581Trees.insert(Trees.end(), {&
T, L});
586assert(!
Range.empty());
587 autoIt = Trees.lower_bound(
Range.begin());
588assert(It != Trees.end() &&
"no node found");
589assert(It->first ==
Range.begin() &&
"no child with the specified range");
590assert((std::next(It) == Trees.end() ||
591std::next(It)->first ==
Range.end()) &&
592 "no child with the specified range");
594 "re-assigning role for a child");
595It->second->setRole(Role);
601 autoBeginChildren = Trees.lower_bound(
Range.begin());
602assert((BeginChildren == Trees.end() ||
603BeginChildren->first ==
Range.begin()) &&
604 "Range crosses boundaries of existing subtrees");
606 autoEndChildren = Trees.lower_bound(
Range.end());
608(EndChildren == Trees.end() || EndChildren->first ==
Range.end()) &&
609 "Range crosses boundaries of existing subtrees");
611 autoBelongsToList = [](
decltype(Trees)::value_type KV) {
612 autoRole = KV.second->getRole();
617 autoBeginListChildren =
618std::find_if(BeginChildren, EndChildren, BelongsToList);
620 autoEndListChildren =
621std::find_if_not(BeginListChildren, EndChildren, BelongsToList);
624EndListChildren->first);
631assert(
Node->getFirstChild() ==
nullptr&&
"node already has children");
633 auto*FirstToken = Tokens.begin();
634 autoBeginChildren = Trees.lower_bound(FirstToken);
636assert((BeginChildren == Trees.end() ||
637BeginChildren->first == FirstToken) &&
638 "fold crosses boundaries of existing subtrees");
639 autoEndChildren = Trees.lower_bound(Tokens.end());
641(EndChildren == Trees.end() || EndChildren->first == Tokens.end()) &&
642 "fold crosses boundaries of existing subtrees");
644 for(
autoIt = BeginChildren; It != EndChildren; ++It) {
645 auto*
C= It->second;
648 Node->appendChildLowLevel(
C);
652 Node->Original =
true;
656Trees.erase(BeginChildren, EndChildren);
657Trees.insert({FirstToken,
Node});
662assert(Trees.size() == 1);
663 auto*Root = Trees.begin()->second;
670 for(
autoIt = Trees.begin(); It != Trees.end(); ++It) {
671 unsignedCoveredTokens =
673? (std::next(It)->first - It->first)
677formatv(
"- '{0}' covers '{1}'+{2} tokens\n", It->second->getKind(),
679R += It->second->dump(STM);
688std::map<const syntax::Token *, syntax::Node *> Trees;
692std::string str() {
returnPending.str(TBTM); }
695TokenBufferTokenManager& TBTM;
697llvm::DenseMap<SourceLocation, const syntax::Token *> LocationToToken;
699llvm::DenseSet<Decl *> DeclsWithoutSemicolons;
700ASTToSyntaxMapping Mapping;
707: Builder(Builder), Context(Context) {}
712 returnprocessDeclaratorAndDeclaration(DD);
716 returnprocessDeclaratorAndDeclaration(TD);
721Builder.foldNode(Builder.getDeclarationRange(
D),
731 if(!RecursiveASTVisitor::TraverseClassTemplateSpecializationDecl(
C))
733 if(
C->isExplicitSpecialization())
736cast<syntax::SimpleDeclaration>(handleFreeStandingTagDecl(
C));
737foldExplicitTemplateInstantiation(
738Builder.getTemplateRange(
C),
739Builder.findToken(
C->getExternKeywordLoc()),
740Builder.findToken(
C->getTemplateKeywordLoc()),
Declaration,
C);
745foldTemplateDeclaration(
746Builder.getDeclarationRange(S),
747Builder.findToken(S->getTemplateParameters()->getTemplateLoc()),
748Builder.getDeclarationRange(S->getTemplatedDecl()), S);
752 boolWalkUpFromTagDecl(
TagDecl*
C) {
754 if(!
C->isFreeStanding()) {
755assert(
C->getNumTemplateParameterLists() == 0);
758handleFreeStandingTagDecl(
C);
763assert(
C->isFreeStanding());
765 autoDeclarationRange = Builder.getDeclarationRange(
C);
767Builder.foldNode(DeclarationRange, Result,
nullptr);
771 const auto*TemplateKW = Builder.findToken(L.getTemplateLoc());
774foldTemplateDeclaration(R, TemplateKW, DeclarationRange,
nullptr);
775DeclarationRange = R;
777 if(
auto*S = dyn_cast<ClassTemplatePartialSpecializationDecl>(
C))
778ConsumeTemplateParameters(*S->getTemplateParameters());
779 for(
unsignedI =
C->getNumTemplateParameterLists(); 0 < I; --I)
780ConsumeTemplateParameters(*
C->getTemplateParameterList(I - 1));
793Builder.markChildToken(S->getLBracLoc(), NodeRole::OpenParen);
794 for(
auto*Child : S->body())
795Builder.markStmtChild(Child, NodeRole::Statement);
796Builder.markChildToken(S->getRBracLoc(), NodeRole::CloseParen);
798Builder.foldNode(Builder.getStmtRange(S),
805Builder.foldNode(Builder.getStmtRange(S),
810 boolTraverseIfStmt(
IfStmt*S) {
811 boolResult = [&,
this]() {
818 if(S->hasVarStorage()) {
821}
else if(S->getCond() && !
TraverseStmt(S->getCond()))
839 boolResult = [&,
this]() {
842 if(S->getLoopVariable() && !
TraverseDecl(S->getLoopVariable()))
844 if(S->getRangeInit() && !
TraverseStmt(S->getRangeInit()))
850WalkUpFromCXXForRangeStmt(S);
855 if(
auto*DS = dyn_cast_or_null<DeclStmt>(S)) {
857 for(
auto*
D: DS->decls())
858Builder.noticeDeclWithoutSemicolon(
D);
859}
else if(
auto*
E= dyn_cast_or_null<Expr>(S)) {
871 boolWalkUpFromExpr(
Expr*
E) {
872assert(!
isImplicitExpr(
E) &&
"should be handled by TraverseStmt");
873Builder.foldNode(Builder.getExprRange(
E),
884 returnWalkUpFromUserDefinedLiteral(S);
887syntax::UserDefinedLiteralExpression *
889 switch(S->getLiteralOperatorKind()) {
891 return new(allocator()) syntax::IntegerUserDefinedLiteralExpression;
893 return new(allocator()) syntax::FloatUserDefinedLiteralExpression;
895 return new(allocator()) syntax::CharUserDefinedLiteralExpression;
897 return new(allocator()) syntax::StringUserDefinedLiteralExpression;
904 autoTokLoc = S->getBeginLoc();
911 if(
Literal.isIntegerLiteral())
912 return new(allocator()) syntax::IntegerUserDefinedLiteralExpression;
914assert(
Literal.isFloatingLiteral());
915 return new(allocator()) syntax::FloatUserDefinedLiteralExpression;
918llvm_unreachable(
"Unknown literal operator kind.");
922Builder.markChildToken(S->getBeginLoc(), syntax::NodeRole::LiteralToken);
923Builder.foldNode(Builder.getExprRange(S), buildUserDefinedLiteral(S), S);
942 if(
autoDependentTL =
947SR.
setBegin(DependentTL.getTemplateKeywordLoc());
957 returnsyntax::NodeKind::GlobalNameSpecifier;
961 returnsyntax::NodeKind::IdentifierNameSpecifier;
963 returnsyntax::NodeKind::SimpleTemplateNameSpecifier;
967 if(isa<DecltypeType>(NNSType))
968 returnsyntax::NodeKind::DecltypeNameSpecifier;
969 if(isa<TemplateSpecializationType, DependentTemplateSpecializationType>(
971 returnsyntax::NodeKind::SimpleTemplateNameSpecifier;
972 returnsyntax::NodeKind::IdentifierNameSpecifier;
976llvm::report_fatal_error(
"We don't yet support the __super specifier",
981syntax::NameSpecifier *
984 autoNameSpecifierTokens =
985Builder.getRange(getLocalSourceRange(NNSLoc)).drop_back();
987 casesyntax::NodeKind::GlobalNameSpecifier:
988 return new(allocator()) syntax::GlobalNameSpecifier;
989 casesyntax::NodeKind::IdentifierNameSpecifier: {
990assert(NameSpecifierTokens.size() == 1);
991Builder.markChildToken(NameSpecifierTokens.begin(),
992syntax::NodeRole::Unknown);
993 auto*NS =
new(allocator()) syntax::IdentifierNameSpecifier;
994Builder.foldNode(NameSpecifierTokens, NS,
nullptr);
997 casesyntax::NodeKind::SimpleTemplateNameSpecifier: {
1003 auto*NS =
new(allocator()) syntax::SimpleTemplateNameSpecifier;
1004Builder.foldNode(NameSpecifierTokens, NS,
nullptr);
1007 casesyntax::NodeKind::DecltypeNameSpecifier: {
1009 if(!RecursiveASTVisitor::TraverseDecltypeTypeLoc(TL))
1011 auto*NS =
new(allocator()) syntax::DecltypeNameSpecifier;
1016Builder.foldNode(NameSpecifierTokens, NS,
nullptr);
1020llvm_unreachable(
"getChildKind() does not return this value");
1031 for(
autoIt = QualifierLoc; It; It = It.getPrefix()) {
1032 auto*NS = buildNameSpecifier(It);
1035Builder.markChild(NS, syntax::NodeRole::ListElement);
1036Builder.markChildToken(It.getEndLoc(), syntax::NodeRole::ListDelimiter);
1038Builder.foldNode(Builder.getRange(QualifierLoc.
getSourceRange()),
1049Builder.markChild(QualifierLoc, syntax::NodeRole::Qualifier);
1050 if(TemplateKeywordLoc.
isValid())
1051Builder.markChildToken(TemplateKeywordLoc,
1052syntax::NodeRole::TemplateKeyword);
1056Builder.foldNode(Builder.getRange(UnqualifiedIdLoc), TheUnqualifiedId,
1058Builder.markChild(TheUnqualifiedId, syntax::NodeRole::UnqualifiedId);
1060 autoIdExpressionBeginLoc =
1063 auto*TheIdExpression =
new(allocator()) syntax::IdExpression;
1065Builder.getRange(IdExpressionBeginLoc, UnqualifiedIdLoc.
getEnd()),
1066TheIdExpression, From);
1068 returnTheIdExpression;
1075 if(S->isImplicitAccess()) {
1076buildIdExpression(S->getQualifierLoc(), S->getTemplateKeywordLoc(),
1077 SourceRange(S->getMemberLoc(), S->getEndLoc()), S);
1081 auto*TheIdExpression = buildIdExpression(
1082S->getQualifierLoc(), S->getTemplateKeywordLoc(),
1083 SourceRange(S->getMemberLoc(), S->getEndLoc()),
nullptr);
1085Builder.markChild(TheIdExpression, syntax::NodeRole::Member);
1087Builder.markExprChild(S->getBase(), syntax::NodeRole::Object);
1088Builder.markChildToken(S->getOperatorLoc(), syntax::NodeRole::AccessToken);
1090Builder.foldNode(Builder.getExprRange(S),
1091new (allocator()) syntax::MemberExpression, S);
1096buildIdExpression(S->getQualifierLoc(), S->getTemplateKeywordLoc(),
1097 SourceRange(S->getLocation(), S->getEndLoc()), S);
1104buildIdExpression(S->getQualifierLoc(), S->getTemplateKeywordLoc(),
1105 SourceRange(S->getLocation(), S->getEndLoc()), S);
1111 if(!S->isImplicit()) {
1112Builder.markChildToken(S->getLocation(),
1113syntax::NodeRole::IntroducerKeyword);
1114Builder.foldNode(Builder.getExprRange(S),
1115new (allocator()) syntax::ThisExpression, S);
1120 boolWalkUpFromParenExpr(
ParenExpr*S) {
1121Builder.markChildToken(S->getLParen(), syntax::NodeRole::OpenParen);
1122Builder.markExprChild(S->getSubExpr(), syntax::NodeRole::SubExpression);
1123Builder.markChildToken(S->getRParen(), syntax::NodeRole::CloseParen);
1124Builder.foldNode(Builder.getExprRange(S),
1125new (allocator()) syntax::ParenExpression, S);
1130Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1131Builder.foldNode(Builder.getExprRange(S),
1132new (allocator()) syntax::IntegerLiteralExpression, S);
1137Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1138Builder.foldNode(Builder.getExprRange(S),
1139new (allocator()) syntax::CharacterLiteralExpression, S);
1144Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1145Builder.foldNode(Builder.getExprRange(S),
1146new (allocator()) syntax::FloatingLiteralExpression, S);
1151Builder.markChildToken(S->getBeginLoc(), syntax::NodeRole::LiteralToken);
1152Builder.foldNode(Builder.getExprRange(S),
1153new (allocator()) syntax::StringLiteralExpression, S);
1158Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1159Builder.foldNode(Builder.getExprRange(S),
1160new (allocator()) syntax::BoolLiteralExpression, S);
1165Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1166Builder.foldNode(Builder.getExprRange(S),
1167new (allocator()) syntax::CxxNullPtrExpression, S);
1172Builder.markChildToken(S->getOperatorLoc(),
1173syntax::NodeRole::OperatorToken);
1174Builder.markExprChild(S->getSubExpr(), syntax::NodeRole::Operand);
1177Builder.foldNode(Builder.getExprRange(S),
1181Builder.foldNode(Builder.getExprRange(S),
1189Builder.markExprChild(S->getLHS(), syntax::NodeRole::LeftHandSide);
1190Builder.markChildToken(S->getOperatorLoc(),
1191syntax::NodeRole::OperatorToken);
1192Builder.markExprChild(S->getRHS(), syntax::NodeRole::RightHandSide);
1193Builder.foldNode(Builder.getExprRange(S),
1203 for(
auto*Arg : Args) {
1204Builder.markExprChild(Arg, syntax::NodeRole::ListElement);
1205 const auto*DelimiterToken =
1206std::next(Builder.findToken(Arg->getEndLoc()));
1207 if(DelimiterToken->kind() == clang::tok::TokenKind::comma)
1208Builder.markChildToken(DelimiterToken, syntax::NodeRole::ListDelimiter);
1213Builder.foldNode(Builder.getRange((*Args.begin())->getBeginLoc(),
1214(*(Args.end() - 1))->getEndLoc()),
1220 boolWalkUpFromCallExpr(
CallExpr*S) {
1221Builder.markExprChild(S->getCallee(), syntax::NodeRole::Callee);
1223 const auto*LParenToken =
1224std::next(Builder.findToken(S->getCallee()->getEndLoc()));
1227 if(LParenToken->kind() == clang::tok::l_paren)
1228Builder.markChildToken(LParenToken, syntax::NodeRole::OpenParen);
1230Builder.markChild(buildCallArguments(S->arguments()),
1231syntax::NodeRole::Arguments);
1233Builder.markChildToken(S->getRParenLoc(), syntax::NodeRole::CloseParen);
1235Builder.foldNode(Builder.getRange(S->getSourceRange()),
1236new (allocator()) syntax::CallExpression, S);
1242 if((S->getNumArgs() == 0 || isa<CXXDefaultArgExpr>(S->getArg(0))) &&
1243S->getParenOrBraceRange().isInvalid())
1245 returnRecursiveASTVisitor::WalkUpFromCXXConstructExpr(S);
1253 for(
auto*child : S->arguments()) {
1260 if(child->getSourceRange().isInvalid()) {
1262syntax::NodeKind::PostfixUnaryOperatorExpression);
1268 returnWalkUpFromCXXOperatorCallExpr(S);
1273 casesyntax::NodeKind::BinaryOperatorExpression:
1274Builder.markExprChild(S->getArg(0), syntax::NodeRole::LeftHandSide);
1275Builder.markChildToken(S->getOperatorLoc(),
1276syntax::NodeRole::OperatorToken);
1277Builder.markExprChild(S->getArg(1), syntax::NodeRole::RightHandSide);
1278Builder.foldNode(Builder.getExprRange(S),
1281 casesyntax::NodeKind::PrefixUnaryOperatorExpression:
1282Builder.markChildToken(S->getOperatorLoc(),
1283syntax::NodeRole::OperatorToken);
1284Builder.markExprChild(S->getArg(0), syntax::NodeRole::Operand);
1285Builder.foldNode(Builder.getExprRange(S),
1289 casesyntax::NodeKind::PostfixUnaryOperatorExpression:
1290Builder.markChildToken(S->getOperatorLoc(),
1291syntax::NodeRole::OperatorToken);
1292Builder.markExprChild(S->getArg(0), syntax::NodeRole::Operand);
1293Builder.foldNode(Builder.getExprRange(S),
1297 casesyntax::NodeKind::CallExpression: {
1298Builder.markExprChild(S->getArg(0), syntax::NodeRole::Callee);
1300 const auto*LParenToken =
1301std::next(Builder.findToken(S->getArg(0)->getEndLoc()));
1304 if(LParenToken->kind() == clang::tok::l_paren)
1305Builder.markChildToken(LParenToken, syntax::NodeRole::OpenParen);
1308S->arg_begin() + 1, S->arg_end())),
1309syntax::NodeRole::Arguments);
1311Builder.markChildToken(S->getRParenLoc(), syntax::NodeRole::CloseParen);
1313Builder.foldNode(Builder.getRange(S->getSourceRange()),
1314new (allocator()) syntax::CallExpression, S);
1317 casesyntax::NodeKind::UnknownExpression:
1318 returnWalkUpFromExpr(S);
1320llvm_unreachable(
"getOperatorNodeKind() does not return this value");
1327 autoTokens = Builder.getDeclarationRange(S);
1328 if(Tokens.front().kind() == tok::coloncolon) {
1342 if(!WalkUpFromParenTypeLoc(L))
1348Builder.markChildToken(L.
getLParenLoc(), syntax::NodeRole::OpenParen);
1349Builder.markChildToken(L.
getRParenLoc(), syntax::NodeRole::CloseParen);
1357Builder.markChildToken(L.
getLBracketLoc(), syntax::NodeRole::OpenParen);
1358Builder.markExprChild(L.
getSizeExpr(), syntax::NodeRole::Size);
1359Builder.markChildToken(L.
getRBracketLoc(), syntax::NodeRole::CloseParen);
1367 for(
auto*
P: Params) {
1368Builder.markChild(
P, syntax::NodeRole::ListElement);
1369 const auto*DelimiterToken = std::next(Builder.findToken(
P->getEndLoc()));
1370 if(DelimiterToken->kind() == clang::tok::TokenKind::comma)
1371Builder.markChildToken(DelimiterToken, syntax::NodeRole::ListDelimiter);
1374 if(!Params.empty())
1375Builder.foldNode(Builder.getRange(Params.front()->getBeginLoc(),
1376Params.back()->getEndLoc()),
1382Builder.markChildToken(L.
getLParenLoc(), syntax::NodeRole::OpenParen);
1384Builder.markChild(buildParameterDeclarationList(L.
getParams()),
1385syntax::NodeRole::Parameters);
1387Builder.markChildToken(L.
getRParenLoc(), syntax::NodeRole::CloseParen);
1395 returnWalkUpFromFunctionTypeLoc(L);
1397 auto*TrailingReturnTokens = buildTrailingReturn(L);
1399Builder.markChild(TrailingReturnTokens, syntax::NodeRole::TrailingReturn);
1400 returnWalkUpFromFunctionTypeLoc(L);
1408 if(!WalkUpFromMemberPointerTypeLoc(L))
1415Builder.foldNode(Builder.getRange(SR),
1423 boolWalkUpFromDeclStmt(
DeclStmt*S) {
1424Builder.foldNode(Builder.getStmtRange(S),
1429 boolWalkUpFromNullStmt(
NullStmt*S) {
1430Builder.foldNode(Builder.getStmtRange(S),
1436Builder.markChildToken(S->getSwitchLoc(),
1437syntax::NodeRole::IntroducerKeyword);
1438Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
1439Builder.foldNode(Builder.getStmtRange(S),
1444 boolWalkUpFromCaseStmt(
CaseStmt*S) {
1445Builder.markChildToken(S->getKeywordLoc(),
1446syntax::NodeRole::IntroducerKeyword);
1447Builder.markExprChild(S->getLHS(), syntax::NodeRole::CaseValue);
1448Builder.markStmtChild(S->getSubStmt(), syntax::NodeRole::BodyStatement);
1449Builder.foldNode(Builder.getStmtRange(S),
1455Builder.markChildToken(S->getKeywordLoc(),
1456syntax::NodeRole::IntroducerKeyword);
1457Builder.markStmtChild(S->getSubStmt(), syntax::NodeRole::BodyStatement);
1458Builder.foldNode(Builder.getStmtRange(S),
1463 boolWalkUpFromIfStmt(
IfStmt*S) {
1464Builder.markChildToken(S->getIfLoc(), syntax::NodeRole::IntroducerKeyword);
1465 Stmt*ConditionStatement = S->getCond();
1466 if(S->hasVarStorage())
1467ConditionStatement = S->getConditionVariableDeclStmt();
1468Builder.markStmtChild(ConditionStatement, syntax::NodeRole::Condition);
1469Builder.markStmtChild(S->getThen(), syntax::NodeRole::ThenStatement);
1470Builder.markChildToken(S->getElseLoc(), syntax::NodeRole::ElseKeyword);
1471Builder.markStmtChild(S->getElse(), syntax::NodeRole::ElseStatement);
1472Builder.foldNode(Builder.getStmtRange(S),
1477 boolWalkUpFromForStmt(
ForStmt*S) {
1478Builder.markChildToken(S->getForLoc(), syntax::NodeRole::IntroducerKeyword);
1479Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
1480Builder.foldNode(Builder.getStmtRange(S),
1485 boolWalkUpFromWhileStmt(
WhileStmt*S) {
1486Builder.markChildToken(S->getWhileLoc(),
1487syntax::NodeRole::IntroducerKeyword);
1488Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
1489Builder.foldNode(Builder.getStmtRange(S),
1495Builder.markChildToken(S->getContinueLoc(),
1496syntax::NodeRole::IntroducerKeyword);
1497Builder.foldNode(Builder.getStmtRange(S),
1502 boolWalkUpFromBreakStmt(
BreakStmt*S) {
1503Builder.markChildToken(S->getBreakLoc(),
1504syntax::NodeRole::IntroducerKeyword);
1505Builder.foldNode(Builder.getStmtRange(S),
1511Builder.markChildToken(S->getReturnLoc(),
1512syntax::NodeRole::IntroducerKeyword);
1513Builder.markExprChild(S->getRetValue(), syntax::NodeRole::ReturnValue);
1514Builder.foldNode(Builder.getStmtRange(S),
1520Builder.markChildToken(S->getForLoc(), syntax::NodeRole::IntroducerKeyword);
1521Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
1522Builder.foldNode(Builder.getStmtRange(S),
1527 boolWalkUpFromEmptyDecl(
EmptyDecl*S) {
1528Builder.foldNode(Builder.getDeclarationRange(S),
1534Builder.markExprChild(S->getAssertExpr(), syntax::NodeRole::Condition);
1535Builder.markExprChild(S->getMessage(), syntax::NodeRole::Message);
1536Builder.foldNode(Builder.getDeclarationRange(S),
1542Builder.foldNode(Builder.getDeclarationRange(S),
1549Builder.foldNode(Builder.getDeclarationRange(S),
1555Builder.foldNode(Builder.getDeclarationRange(S),
1560 boolWalkUpFromUsingDecl(
UsingDecl*S) {
1561Builder.foldNode(Builder.getDeclarationRange(S),
1567Builder.foldNode(Builder.getDeclarationRange(S),
1573Builder.foldNode(Builder.getDeclarationRange(S),
1579Builder.foldNode(Builder.getDeclarationRange(S),
1587 template<
classT>
boolprocessDeclaratorAndDeclaration(
T*
D) {
1589Builder.sourceManager(),
D->getTypeSourceInfo()->getTypeLoc(),
1596syntax::NodeRole::Declarators);
1597Builder.foldNode(Builder.getDeclarationRange(
D),
1603Builder.foldNode(Builder.getRange(
Range), N,
nullptr);
1604Builder.markChild(N, syntax::NodeRole::ListElement);
1606 if(!Builder.isResponsibleForCreatingDeclaration(
D)) {
1609 const auto*DelimiterToken = std::next(Builder.findToken(
Range.
getEnd()));
1610 if(DelimiterToken->kind() == clang::tok::TokenKind::comma)
1611Builder.markChildToken(DelimiterToken, syntax::NodeRole::ListDelimiter);
1614 autoDeclarationRange = Builder.getDeclarationRange(
D);
1615Builder.foldList(DeclarationRange, DL,
nullptr);
1617Builder.markChild(DL, syntax::NodeRole::Declarators);
1618Builder.foldNode(DeclarationRange,
1630 autoReturnDeclaratorRange =
SourceRange(GetStartLoc().Visit(ReturnedType),
1631ReturnedType.getEndLoc());
1633 if(ReturnDeclaratorRange.isValid()) {
1635Builder.foldNode(Builder.getRange(ReturnDeclaratorRange),
1636ReturnDeclarator,
nullptr);
1640 autoReturn = Builder.getRange(ReturnedType.getSourceRange());
1641 const auto*Arrow = Return.begin() - 1;
1642assert(Arrow->kind() == tok::arrow);
1644Builder.markChildToken(Arrow, syntax::NodeRole::ArrowToken);
1645 if(ReturnDeclarator)
1646Builder.markChild(ReturnDeclarator, syntax::NodeRole::Declarator);
1648Builder.foldNode(Tokens, R, L);
1652 voidfoldExplicitTemplateInstantiation(
1656assert(!ExternKW || ExternKW->
kind() == tok::kw_extern);
1657assert(TemplateKW && TemplateKW->
kind() == tok::kw_template);
1658Builder.markChildToken(ExternKW, syntax::NodeRole::ExternKeyword);
1659Builder.markChildToken(TemplateKW, syntax::NodeRole::IntroducerKeyword);
1660Builder.markChild(InnerDeclaration, syntax::NodeRole::Declaration);
1668assert(TemplateKW && TemplateKW->
kind() == tok::kw_template);
1669Builder.markChildToken(TemplateKW, syntax::NodeRole::IntroducerKeyword);
1672Builder.foldNode(
Range, N, From);
1673Builder.markChild(N, syntax::NodeRole::Declaration);
1678llvm::BumpPtrAllocator &allocator() {
returnBuilder.allocator(); }
1686DeclsWithoutSemicolons.insert(
D);
1692Pending.assignRole(*findToken(
Loc), Role);
1698Pending.assignRole(*
T, R);
1707 auto*SN = Mapping.find(N);
1708assert(SN !=
nullptr);
1712 auto*SN = Mapping.find(NNSLoc);
1713assert(SN !=
nullptr);
1722 if(
Expr*ChildExpr = dyn_cast<Expr>(Child)) {
1728Pending.foldChildren(TBTM.tokenBuffer(), getStmtRange(Child), ChildNode);
1730ChildNode = Mapping.find(Child);
1732assert(ChildNode !=
nullptr);
1733setRole(ChildNode, Role);
1742assert(ChildNode !=
nullptr);
1743setRole(ChildNode, Role);
1749 autoIt = LocationToToken.find(L);
1750assert(It != LocationToToken.end());
1758BuildTreeVisitor(Context, Builder).TraverseAST(Context);
1759 returnstd::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.
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
CaseStmt - Represent a case statement.
Represents a class template specialization, which refers to a class template with a given set of temp...
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.
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.
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 non-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 parenthesized 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 TraverseStmt(Stmt *S, DataRecursionQueue *Queue=nullptr)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
Recursively visit a C++ nested-name-specifier with location information.
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.
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.
The JSON file list parser is used to communicate input to InstallAPI.
@ 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...
@ Result
The result type of a method or function.
Expr * IgnoreImplicitSingleStep(Expr *E)
const FunctionProtoType * T
void finalize(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4