Lines Matching refs:syntax

164 static syntax::NodeKind getOperatorNodeKind(const CXXOperatorCallExpr &E) {
197 return syntax::NodeKind::BinaryOperatorExpression;
200 return syntax::NodeKind::PrefixUnaryOperatorExpression;
206 return syntax::NodeKind::PrefixUnaryOperatorExpression;
208 return syntax::NodeKind::PostfixUnaryOperatorExpression;
219 return syntax::NodeKind::PrefixUnaryOperatorExpression;
221 return syntax::NodeKind::BinaryOperatorExpression;
225 return syntax::NodeKind::BinaryOperatorExpression;
234 return syntax::NodeKind::UnknownExpression;
236 return syntax::NodeKind::CallExpression;
317 /// Maintains a mapping from AST to syntax tree nodes. This class will get more
322 void add(ASTPtr From, syntax::Tree *To) {
331 void add(NestedNameSpecifierLoc From, syntax::Tree *To) {
340 syntax::Tree *find(ASTPtr P) const { return Nodes.lookup(P); }
342 syntax::Tree *find(NestedNameSpecifierLoc P) const {
347 llvm::DenseMap<ASTPtr, syntax::Tree *> Nodes;
348 llvm::DenseMap<NestedNameSpecifierLoc, syntax::Tree *> NNSNodes;
352 /// A helper class for constructing the syntax tree while traversing a clang
358 /// - create a corresponding syntax node,
361 /// - replace the child nodes with the new syntax node in the pending list
367 class syntax::TreeBuilder {
369 TreeBuilder(syntax::Arena &Arena, TokenBufferTokenManager& TBTM)
384 void foldNode(ArrayRef<syntax::Token> Range, syntax::Tree *New, ASTPtr From) {
391 void foldNode(ArrayRef<syntax::Token> Range, syntax::Tree *New, TypeLoc L) {
396 void foldNode(llvm::ArrayRef<syntax::Token> Range, syntax::Tree *New,
406 void foldList(ArrayRef<syntax::Token> SuperRange, syntax::List *New,
430 void markChildToken(const syntax::Token *T, NodeRole R);
433 void markChild(syntax::Node *N, NodeRole R);
434 /// Set role for the syntax node matching \p N.
436 /// Set role for the syntax node matching \p N.
440 syntax::TranslationUnit *finalize() && {
447 new (Arena.getAllocator()) syntax::TranslationUnit);
449 auto *TU = cast<syntax::TranslationUnit>(std::move(Pending).finalize());
455 const syntax::Token *findToken(SourceLocation L) const;
457 /// Finds the syntax tokens corresponding to the \p SourceRange.
458 ArrayRef<syntax::Token> getRange(SourceRange Range) const {
463 /// Finds the syntax tokens corresponding to the passed source locations.
466 ArrayRef<syntax::Token> getRange(SourceLocation First,
475 ArrayRef<syntax::Token>
509 ArrayRef<syntax::Token> getDeclarationRange(Decl *D) {
510 ArrayRef<syntax::Token> Tokens;
519 ArrayRef<syntax::Token> getExprRange(const Expr *E) const {
525 ArrayRef<syntax::Token> getStmtRange(const Stmt *S) const {
538 ArrayRef<syntax::Token> maybeAppendSemicolon(ArrayRef<syntax::Token> Tokens,
545 // Most declarations own a semicolon in syntax trees, but not in clang AST.
549 ArrayRef<syntax::Token>
550 withTrailingSemicolon(ArrayRef<syntax::Token> Tokens) const {
559 void setRole(syntax::Node *N, NodeRole R) {
571 Forest(syntax::Arena &A, const syntax::TokenBuffer &TB) {
578 syntax::Leaf(reinterpret_cast<TokenManager::Key>(&T));
585 void assignRole(ArrayRef<syntax::Token> Range, syntax::NodeRole Role) {
600 ArrayRef<syntax::Token> shrinkToFitList(ArrayRef<syntax::Token> Range) {
613 return Role == syntax::NodeRole::ListElement ||
614 Role == syntax::NodeRole::ListDelimiter;
623 return ArrayRef<syntax::Token>(BeginListChildren->first,
628 void foldChildren(const syntax::TokenBuffer &TB,
629 ArrayRef<syntax::Token> Tokens, syntax::Tree *Node) {
661 syntax::Node *finalize() && {
668 std::string str(const syntax::TokenBufferTokenManager &STM) const {
688 std::map<const syntax::Token *, syntax::Node *> Trees;
694 syntax::Arena &Arena;
697 llvm::DenseMap<SourceLocation, const syntax::Token *> LocationToToken;
706 explicit BuildTreeVisitor(ASTContext &Context, syntax::TreeBuilder &Builder)
722 new (allocator()) syntax::UnknownDeclaration(), D);
736 cast<syntax::SimpleDeclaration>(handleFreeStandingTagDecl(C));
761 syntax::Declaration *handleFreeStandingTagDecl(TagDecl *C) {
765 syntax::Declaration *Result = new (allocator()) syntax::SimpleDeclaration;
790 using NodeRole = syntax::NodeRole;
798 new (allocator()) syntax::CompoundStatement, S);
802 // Some statements are not yet handled by syntax trees.
805 new (allocator()) syntax::UnknownStatement, S);
816 // implicit condition expression in the syntax tree.
865 // OpaqueValue doesn't correspond to concrete syntax, ignore it.
869 // Some expressions are not yet handled by syntax trees.
873 new (allocator()) syntax::UnknownExpression, E);
881 // can't represent the UDL suffix as a separate syntax tree node.
886 syntax::UserDefinedLiteralExpression *
890 return new (allocator()) syntax::IntegerUserDefinedLiteralExpression;
892 return new (allocator()) syntax::FloatUserDefinedLiteralExpression;
894 return new (allocator()) syntax::CharUserDefinedLiteralExpression;
896 return new (allocator()) syntax::StringUserDefinedLiteralExpression;
911 return new (allocator()) syntax::IntegerUserDefinedLiteralExpression;
914 return new (allocator()) syntax::FloatUserDefinedLiteralExpression;
921 Builder.markChildToken(S->getBeginLoc(), syntax::NodeRole::LiteralToken);
953 syntax::NodeKind getNameSpecifierKind(const NestedNameSpecifier &NNS) {
956 return syntax::NodeKind::GlobalNameSpecifier;
960 return syntax::NodeKind::IdentifierNameSpecifier;
962 return syntax::NodeKind::SimpleTemplateNameSpecifier;
967 return syntax::NodeKind::DecltypeNameSpecifier;
970 return syntax::NodeKind::SimpleTemplateNameSpecifier;
971 return syntax::NodeKind::IdentifierNameSpecifier;
980 syntax::NameSpecifier *
986 case syntax::NodeKind::GlobalNameSpecifier:
987 return new (allocator()) syntax::GlobalNameSpecifier;
988 case syntax::NodeKind::IdentifierNameSpecifier: {
991 syntax::NodeRole::Unknown);
992 auto *NS = new (allocator()) syntax::IdentifierNameSpecifier;
996 case syntax::NodeKind::SimpleTemplateNameSpecifier: {
1002 auto *NS = new (allocator()) syntax::SimpleTemplateNameSpecifier;
1006 case syntax::NodeKind::DecltypeNameSpecifier: {
1010 auto *NS = new (allocator()) syntax::DecltypeNameSpecifier;
1013 // For that add mapping from `TypeLoc` to `syntax::Node*` then:
1014 // Builder.markChild(TypeLoc, syntax::NodeRole);
1023 // To build syntax tree nodes for NestedNameSpecifierLoc we override
1034 Builder.markChild(NS, syntax::NodeRole::ListElement);
1035 Builder.markChildToken(It.getEndLoc(), syntax::NodeRole::ListDelimiter);
1038 new (allocator()) syntax::NestedNameSpecifier,
1043 syntax::IdExpression *buildIdExpression(NestedNameSpecifierLoc QualifierLoc,
1048 Builder.markChild(QualifierLoc, syntax::NodeRole::Qualifier);
1051 syntax::NodeRole::TemplateKeyword);
1054 auto *TheUnqualifiedId = new (allocator()) syntax::UnqualifiedId;
1057 Builder.markChild(TheUnqualifiedId, syntax::NodeRole::UnqualifiedId);
1062 auto *TheIdExpression = new (allocator()) syntax::IdExpression;
1072 // `id-expression` syntax node, beacuse an implicit `member-expression` is
1084 Builder.markChild(TheIdExpression, syntax::NodeRole::Member);
1086 Builder.markExprChild(S->getBase(), syntax::NodeRole::Object);
1087 Builder.markChildToken(S->getOperatorLoc(), syntax::NodeRole::AccessToken);
1090 new (allocator()) syntax::MemberExpression, S);
1112 syntax::NodeRole::IntroducerKeyword);
1114 new (allocator()) syntax::ThisExpression, 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);
1124 new (allocator()) syntax::ParenExpression, S);
1129 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1131 new (allocator()) syntax::IntegerLiteralExpression, S);
1136 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1138 new (allocator()) syntax::CharacterLiteralExpression, S);
1143 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1145 new (allocator()) syntax::FloatingLiteralExpression, S);
1150 Builder.markChildToken(S->getBeginLoc(), syntax::NodeRole::LiteralToken);
1152 new (allocator()) syntax::StringLiteralExpression, S);
1157 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1159 new (allocator()) syntax::BoolLiteralExpression, S);
1164 Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
1166 new (allocator()) syntax::CxxNullPtrExpression, S);
1172 syntax::NodeRole::OperatorToken);
1173 Builder.markExprChild(S->getSubExpr(), syntax::NodeRole::Operand);
1177 new (allocator()) syntax::PostfixUnaryOperatorExpression,
1181 new (allocator()) syntax::PrefixUnaryOperatorExpression,
1188 Builder.markExprChild(S->getLHS(), syntax::NodeRole::LeftHandSide);
1190 syntax::NodeRole::OperatorToken);
1191 Builder.markExprChild(S->getRHS(), syntax::NodeRole::RightHandSide);
1193 new (allocator()) syntax::BinaryOperatorExpression, S);
1197 /// Builds `CallArguments` syntax node from arguments that appear in source
1199 syntax::CallArguments *
1203 Builder.markExprChild(Arg, syntax::NodeRole::ListElement);
1207 Builder.markChildToken(DelimiterToken, syntax::NodeRole::ListDelimiter);
1210 auto *Arguments = new (allocator()) syntax::CallArguments;
1220 Builder.markExprChild(S->getCallee(), syntax::NodeRole::Callee);
1227 Builder.markChildToken(LParenToken, syntax::NodeRole::OpenParen);
1230 syntax::NodeRole::Arguments);
1232 Builder.markChildToken(S->getRParenLoc(), syntax::NodeRole::CloseParen);
1235 new (allocator()) syntax::CallExpression, S);
1248 // To construct a syntax tree of the same shape for calls to built-in and
1261 syntax::NodeKind::PostfixUnaryOperatorExpression);
1272 case syntax::NodeKind::BinaryOperatorExpression:
1273 Builder.markExprChild(S->getArg(0), syntax::NodeRole::LeftHandSide);
1275 syntax::NodeRole::OperatorToken);
1276 Builder.markExprChild(S->getArg(1), syntax::NodeRole::RightHandSide);
1278 new (allocator()) syntax::BinaryOperatorExpression, S);
1280 case syntax::NodeKind::PrefixUnaryOperatorExpression:
1282 syntax::NodeRole::OperatorToken);
1283 Builder.markExprChild(S->getArg(0), syntax::NodeRole::Operand);
1285 new (allocator()) syntax::PrefixUnaryOperatorExpression,
1288 case syntax::NodeKind::PostfixUnaryOperatorExpression:
1290 syntax::NodeRole::OperatorToken);
1291 Builder.markExprChild(S->getArg(0), syntax::NodeRole::Operand);
1293 new (allocator()) syntax::PostfixUnaryOperatorExpression,
1296 case syntax::NodeKind::CallExpression: {
1297 Builder.markExprChild(S->getArg(0), syntax::NodeRole::Callee);
1304 Builder.markChildToken(LParenToken, syntax::NodeRole::OpenParen);
1308 syntax::NodeRole::Arguments);
1310 Builder.markChildToken(S->getRParenLoc(), syntax::NodeRole::CloseParen);
1313 new (allocator()) syntax::CallExpression, S);
1316 case syntax::NodeKind::UnknownExpression:
1333 Builder.foldNode(Tokens, new (allocator()) syntax::NamespaceDefinition, S);
1340 // We reverse order of traversal to get the proper syntax structure.
1347 Builder.markChildToken(L.getLParenLoc(), syntax::NodeRole::OpenParen);
1348 Builder.markChildToken(L.getRParenLoc(), syntax::NodeRole::CloseParen);
1350 new (allocator()) syntax::ParenDeclarator, L);
1356 Builder.markChildToken(L.getLBracketLoc(), syntax::NodeRole::OpenParen);
1357 Builder.markExprChild(L.getSizeExpr(), syntax::NodeRole::Size);
1358 Builder.markChildToken(L.getRBracketLoc(), syntax::NodeRole::CloseParen);
1360 new (allocator()) syntax::ArraySubscript, L);
1364 syntax::ParameterDeclarationList *
1367 Builder.markChild(P, syntax::NodeRole::ListElement);
1370 Builder.markChildToken(DelimiterToken, syntax::NodeRole::ListDelimiter);
1372 auto *Parameters = new (allocator()) syntax::ParameterDeclarationList;
1381 Builder.markChildToken(L.getLParenLoc(), syntax::NodeRole::OpenParen);
1384 syntax::NodeRole::Parameters);
1386 Builder.markChildToken(L.getRParenLoc(), syntax::NodeRole::CloseParen);
1388 new (allocator()) syntax::ParametersAndQualifiers, L);
1398 Builder.markChild(TrailingReturnTokens, syntax::NodeRole::TrailingReturn);
1406 // syntax structure.
1415 new (allocator()) syntax::MemberPointer, L);
1424 new (allocator()) syntax::DeclarationStatement, S);
1430 new (allocator()) syntax::EmptyStatement, S);
1436 syntax::NodeRole::IntroducerKeyword);
1437 Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
1439 new (allocator()) syntax::SwitchStatement, S);
1445 syntax::NodeRole::IntroducerKeyword);
1446 Builder.markExprChild(S->getLHS(), syntax::NodeRole::CaseValue);
1447 Builder.markStmtChild(S->getSubStmt(), syntax::NodeRole::BodyStatement);
1449 new (allocator()) syntax::CaseStatement, S);
1455 syntax::NodeRole::IntroducerKeyword);
1456 Builder.markStmtChild(S->getSubStmt(), syntax::NodeRole::BodyStatement);
1458 new (allocator()) syntax::DefaultStatement, S);
1463 Builder.markChildToken(S->getIfLoc(), syntax::NodeRole::IntroducerKeyword);
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);
1472 new (allocator()) syntax::IfStatement, S);
1477 Builder.markChildToken(S->getForLoc(), syntax::NodeRole::IntroducerKeyword);
1478 Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
1480 new (allocator()) syntax::ForStatement, S);
1486 syntax::NodeRole::IntroducerKeyword);
1487 Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
1489 new (allocator()) syntax::WhileStatement, S);
1495 syntax::NodeRole::IntroducerKeyword);
1497 new (allocator()) syntax::ContinueStatement, S);
1503 syntax::NodeRole::IntroducerKeyword);
1505 new (allocator()) syntax::BreakStatement, S);
1511 syntax::NodeRole::IntroducerKeyword);
1512 Builder.markExprChild(S->getRetValue(), syntax::NodeRole::ReturnValue);
1514 new (allocator()) syntax::ReturnStatement, S);
1519 Builder.markChildToken(S->getForLoc(), syntax::NodeRole::IntroducerKeyword);
1520 Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
1522 new (allocator()) syntax::RangeBasedForStatement, S);
1528 new (allocator()) syntax::EmptyDeclaration, S);
1533 Builder.markExprChild(S->getAssertExpr(), syntax::NodeRole::Condition);
1534 Builder.markExprChild(S->getMessage(), syntax::NodeRole::Message);
1536 new (allocator()) syntax::StaticAssertDeclaration, S);
1542 new (allocator()) syntax::LinkageSpecificationDeclaration,
1549 new (allocator()) syntax::NamespaceAliasDefinition, S);
1555 new (allocator()) syntax::UsingNamespaceDirective, S);
1561 new (allocator()) syntax::UsingDeclaration, S);
1567 new (allocator()) syntax::UsingDeclaration, S);
1573 new (allocator()) syntax::UsingDeclaration, S);
1579 new (allocator()) syntax::TypeAliasDeclaration, S);
1594 Builder.markChild(new (allocator()) syntax::DeclaratorList,
1595 syntax::NodeRole::Declarators);
1597 new (allocator()) syntax::SimpleDeclaration, D);
1601 auto *N = new (allocator()) syntax::SimpleDeclarator;
1603 Builder.markChild(N, syntax::NodeRole::ListElement);
1610 Builder.markChildToken(DelimiterToken, syntax::NodeRole::ListDelimiter);
1612 auto *DL = new (allocator()) syntax::DeclaratorList;
1616 Builder.markChild(DL, syntax::NodeRole::Declarators);
1618 new (allocator()) syntax::SimpleDeclaration, D);
1624 syntax::TrailingReturnType *buildTrailingReturn(FunctionProtoTypeLoc L) {
1631 syntax::SimpleDeclarator *ReturnDeclarator = nullptr;
1633 ReturnDeclarator = new (allocator()) syntax::SimpleDeclarator;
1643 Builder.markChildToken(Arrow, syntax::NodeRole::ArrowToken);
1645 Builder.markChild(ReturnDeclarator, syntax::NodeRole::Declarator);
1646 auto *R = new (allocator()) syntax::TrailingReturnType;
1652 ArrayRef<syntax::Token> Range, const syntax::Token *ExternKW,
1653 const syntax::Token *TemplateKW,
1654 syntax::SimpleDeclaration *InnerDeclaration, Decl *From) {
1657 Builder.markChildToken(ExternKW, syntax::NodeRole::ExternKeyword);
1658 Builder.markChildToken(TemplateKW, syntax::NodeRole::IntroducerKeyword);
1659 Builder.markChild(InnerDeclaration, syntax::NodeRole::Declaration);
1661 Range, new (allocator()) syntax::ExplicitTemplateInstantiation, From);
1664 syntax::TemplateDeclaration *foldTemplateDeclaration(
1665 ArrayRef<syntax::Token> Range, const syntax::Token *TemplateKW,
1666 ArrayRef<syntax::Token> TemplatedDeclaration, Decl *From) {
1668 Builder.markChildToken(TemplateKW, syntax::NodeRole::IntroducerKeyword);
1670 auto *N = new (allocator()) syntax::TemplateDeclaration;
1672 Builder.markChild(N, syntax::NodeRole::Declaration);
1679 syntax::TreeBuilder &Builder;
1684 void syntax::TreeBuilder::noticeDeclWithoutSemicolon(Decl *D) {
1688 void syntax::TreeBuilder::markChildToken(SourceLocation Loc, NodeRole Role) {
1694 void syntax::TreeBuilder::markChildToken(const syntax::Token *T, NodeRole R) {
1700 void syntax::TreeBuilder::markChild(syntax::Node *N, NodeRole R) {
1705 void syntax::TreeBuilder::markChild(ASTPtr N, NodeRole R) {
1710 void syntax::TreeBuilder::markChild(NestedNameSpecifierLoc NNSLoc, NodeRole R) {
1716 void syntax::TreeBuilder::markStmtChild(Stmt *Child, NodeRole Role) {
1720 syntax::Tree *ChildNode;
1725 ChildNode = new (allocator()) syntax::ExpressionStatement;
1735 void syntax::TreeBuilder::markExprChild(Expr *Child, NodeRole Role) {
1740 syntax::Tree *ChildNode = Mapping.find(Child);
1745 const syntax::Token *syntax::TreeBuilder::findToken(SourceLocation L) const {
1753 syntax::TranslationUnit *syntax::buildSyntaxTree(Arena &A,