LCOV - code coverage report
Current view: top level - src/torque - ast.h (source / functions) Hit Total Coverage
Test: app.info Lines: 224 225 99.6 %
Date: 2019-03-21 Functions: 241 302 79.8 %

          Line data    Source code
       1             : // Copyright 2018 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_TORQUE_AST_H_
       6             : #define V8_TORQUE_AST_H_
       7             : 
       8             : #include <iostream>
       9             : #include <memory>
      10             : #include <string>
      11             : #include <vector>
      12             : 
      13             : #include "src/base/optional.h"
      14             : #include "src/torque/source-positions.h"
      15             : 
      16             : namespace v8 {
      17             : namespace internal {
      18             : namespace torque {
      19             : 
      20             : #define AST_EXPRESSION_NODE_KIND_LIST(V) \
      21             :   V(CallExpression)                      \
      22             :   V(CallMethodExpression)                \
      23             :   V(LoadObjectFieldExpression)           \
      24             :   V(StoreObjectFieldExpression)          \
      25             :   V(IntrinsicCallExpression)             \
      26             :   V(StructExpression)                    \
      27             :   V(LogicalOrExpression)                 \
      28             :   V(LogicalAndExpression)                \
      29             :   V(ConditionalExpression)               \
      30             :   V(IdentifierExpression)                \
      31             :   V(StringLiteralExpression)             \
      32             :   V(NumberLiteralExpression)             \
      33             :   V(FieldAccessExpression)               \
      34             :   V(ElementAccessExpression)             \
      35             :   V(AssignmentExpression)                \
      36             :   V(IncrementDecrementExpression)        \
      37             :   V(NewExpression)                       \
      38             :   V(AssumeTypeImpossibleExpression)      \
      39             :   V(StatementExpression)                 \
      40             :   V(TryLabelExpression)
      41             : 
      42             : #define AST_TYPE_EXPRESSION_NODE_KIND_LIST(V) \
      43             :   V(BasicTypeExpression)                      \
      44             :   V(FunctionTypeExpression)                   \
      45             :   V(UnionTypeExpression)
      46             : 
      47             : #define AST_STATEMENT_NODE_KIND_LIST(V) \
      48             :   V(BlockStatement)                     \
      49             :   V(ExpressionStatement)                \
      50             :   V(IfStatement)                        \
      51             :   V(WhileStatement)                     \
      52             :   V(ForLoopStatement)                   \
      53             :   V(ForOfLoopStatement)                 \
      54             :   V(BreakStatement)                     \
      55             :   V(ContinueStatement)                  \
      56             :   V(ReturnStatement)                    \
      57             :   V(DebugStatement)                     \
      58             :   V(AssertStatement)                    \
      59             :   V(TailCallStatement)                  \
      60             :   V(VarDeclarationStatement)            \
      61             :   V(GotoStatement)
      62             : 
      63             : #define AST_DECLARATION_NODE_KIND_LIST(V) \
      64             :   V(TypeDeclaration)                      \
      65             :   V(TypeAliasDeclaration)                 \
      66             :   V(StandardDeclaration)                  \
      67             :   V(GenericDeclaration)                   \
      68             :   V(SpecializationDeclaration)            \
      69             :   V(ExternConstDeclaration)               \
      70             :   V(ClassDeclaration)                     \
      71             :   V(StructDeclaration)                    \
      72             :   V(NamespaceDeclaration)                 \
      73             :   V(ConstDeclaration)                     \
      74             :   V(CppIncludeDeclaration)
      75             : 
      76             : #define AST_CALLABLE_NODE_KIND_LIST(V) \
      77             :   V(TorqueMacroDeclaration)            \
      78             :   V(TorqueBuiltinDeclaration)          \
      79             :   V(ExternalMacroDeclaration)          \
      80             :   V(ExternalBuiltinDeclaration)        \
      81             :   V(ExternalRuntimeDeclaration)        \
      82             :   V(IntrinsicDeclaration)
      83             : 
      84             : #define AST_NODE_KIND_LIST(V)           \
      85             :   AST_EXPRESSION_NODE_KIND_LIST(V)      \
      86             :   AST_TYPE_EXPRESSION_NODE_KIND_LIST(V) \
      87             :   AST_STATEMENT_NODE_KIND_LIST(V)       \
      88             :   AST_DECLARATION_NODE_KIND_LIST(V)     \
      89             :   AST_CALLABLE_NODE_KIND_LIST(V)        \
      90             :   V(Identifier)                         \
      91             :   V(LabelBlock)
      92             : 
      93             : struct AstNode {
      94             :  public:
      95             :   enum class Kind {
      96             : #define ENUM_ITEM(name) k##name,
      97             :     AST_NODE_KIND_LIST(ENUM_ITEM)
      98             : #undef ENUM_ITEM
      99             :   };
     100             : 
     101       46310 :   AstNode(Kind kind, SourcePosition pos) : kind(kind), pos(pos) {}
     102       46310 :   virtual ~AstNode() = default;
     103             : 
     104             :   const Kind kind;
     105             :   SourcePosition pos;
     106             : };
     107             : 
     108             : struct AstNodeClassCheck {
     109             :   template <class T>
     110             :   static bool IsInstanceOf(AstNode* node);
     111             : };
     112             : 
     113             : // Boilerplate for most derived classes.
     114             : #define DEFINE_AST_NODE_LEAF_BOILERPLATE(T)                        \
     115             :   static const Kind kKind = Kind::k##T;                            \
     116             :   static T* cast(AstNode* node) {                                  \
     117             :     if (node->kind != kKind) return nullptr;                       \
     118             :     return static_cast<T*>(node);                                  \
     119             :   }                                                                \
     120             :   static T* DynamicCast(AstNode* node) {                           \
     121             :     if (!node) return nullptr;                                     \
     122             :     if (!AstNodeClassCheck::IsInstanceOf<T>(node)) return nullptr; \
     123             :     return static_cast<T*>(node);                                  \
     124             :   }
     125             : 
     126             : // Boilerplate for classes with subclasses.
     127             : #define DEFINE_AST_NODE_INNER_BOILERPLATE(T)                       \
     128             :   static T* cast(AstNode* node) {                                  \
     129             :     DCHECK(AstNodeClassCheck::IsInstanceOf<T>(node));              \
     130             :     return static_cast<T*>(node);                                  \
     131             :   }                                                                \
     132             :   static T* DynamicCast(AstNode* node) {                           \
     133             :     if (!node) return nullptr;                                     \
     134             :     if (!AstNodeClassCheck::IsInstanceOf<T>(node)) return nullptr; \
     135             :     return static_cast<T*>(node);                                  \
     136             :   }
     137             : 
     138       33806 : struct Expression : AstNode {
     139       16903 :   Expression(Kind kind, SourcePosition pos) : AstNode(kind, pos) {}
     140             :   DEFINE_AST_NODE_INNER_BOILERPLATE(Expression)
     141             : };
     142             : 
     143       22018 : struct LocationExpression : Expression {
     144       11009 :   LocationExpression(Kind kind, SourcePosition pos) : Expression(kind, pos) {}
     145             :   DEFINE_AST_NODE_INNER_BOILERPLATE(LocationExpression)
     146             : };
     147             : 
     148       11300 : struct TypeExpression : AstNode {
     149        5650 :   TypeExpression(Kind kind, SourcePosition pos) : AstNode(kind, pos) {}
     150             :   DEFINE_AST_NODE_INNER_BOILERPLATE(TypeExpression)
     151             : };
     152             : 
     153        2864 : struct Declaration : AstNode {
     154        1432 :   Declaration(Kind kind, SourcePosition pos) : AstNode(kind, pos) {}
     155             :   DEFINE_AST_NODE_INNER_BOILERPLATE(Declaration)
     156             : };
     157             : 
     158       12232 : struct Statement : AstNode {
     159        6116 :   Statement(Kind kind, SourcePosition pos) : AstNode(kind, pos) {}
     160             :   DEFINE_AST_NODE_INNER_BOILERPLATE(Statement)
     161             : };
     162             : 
     163             : class Namespace;
     164             : 
     165         135 : struct NamespaceDeclaration : Declaration {
     166          45 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(NamespaceDeclaration)
     167          45 :   NamespaceDeclaration(SourcePosition pos, std::string name,
     168             :                        std::vector<Declaration*> declarations)
     169             :       : Declaration(kKind, pos),
     170             :         declarations(std::move(declarations)),
     171         135 :         name(name) {}
     172             :   std::vector<Declaration*> declarations;
     173             :   std::string name;
     174             : };
     175             : 
     176          18 : class Ast {
     177             :  public:
     178             :   Ast() {}
     179             : 
     180         897 :   std::vector<Declaration*>& declarations() { return declarations_; }
     181             :   const std::vector<Declaration*>& declarations() const {
     182             :     return declarations_;
     183             :   }
     184             :   template <class T>
     185       46310 :   T* AddNode(std::unique_ptr<T> node) {
     186             :     T* result = node.get();
     187       92620 :     nodes_.push_back(std::move(node));
     188       46310 :     return result;
     189             :   }
     190             : 
     191             :  private:
     192             :   std::vector<Declaration*> declarations_;
     193             :   std::vector<std::unique_ptr<AstNode>> nodes_;
     194             : };
     195             : 
     196             : static const char* const kThisParameterName = "this";
     197             : 
     198             : // A Identifier is a string with a SourcePosition attached.
     199       29996 : struct Identifier : AstNode {
     200             :   DEFINE_AST_NODE_LEAF_BOILERPLATE(Identifier)
     201             :   Identifier(SourcePosition pos, std::string identifier)
     202       14998 :       : AstNode(kKind, pos), value(std::move(identifier)) {}
     203             :   std::string value;
     204             : };
     205             : 
     206       40508 : struct IdentifierExpression : LocationExpression {
     207        8239 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(IdentifierExpression)
     208             :   IdentifierExpression(SourcePosition pos,
     209             :                        std::vector<std::string> namespace_qualification,
     210             :                        Identifier* name, std::vector<TypeExpression*> args = {})
     211             :       : LocationExpression(kKind, pos),
     212             :         namespace_qualification(std::move(namespace_qualification)),
     213             :         name(name),
     214       20254 :         generic_arguments(std::move(args)) {}
     215        1674 :   IdentifierExpression(SourcePosition pos, Identifier* name,
     216             :                        std::vector<TypeExpression*> args = {})
     217        1674 :       : IdentifierExpression(pos, {}, name, std::move(args)) {}
     218        1071 :   bool IsThis() const { return name->value == kThisParameterName; }
     219             :   std::vector<std::string> namespace_qualification;
     220             :   Identifier* name;
     221             :   std::vector<TypeExpression*> generic_arguments;
     222             : };
     223             : 
     224         492 : struct LoadObjectFieldExpression : Expression {
     225         246 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(LoadObjectFieldExpression)
     226             :   LoadObjectFieldExpression(SourcePosition pos, Expression* base,
     227             :                             std::string field_name)
     228             :       : Expression(kKind, pos),
     229             :         base(std::move(base)),
     230         246 :         field_name(std::move(field_name)) {}
     231             :   Expression* base;
     232             :   std::string field_name;
     233             : };
     234             : 
     235         492 : struct StoreObjectFieldExpression : Expression {
     236         246 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(StoreObjectFieldExpression)
     237             :   StoreObjectFieldExpression(SourcePosition pos, Expression* base,
     238             :                              std::string field_name, Expression* value)
     239             :       : Expression(kKind, pos),
     240             :         base(std::move(base)),
     241             :         field_name(std::move(field_name)),
     242         492 :         value(std::move(value)) {}
     243             :   Expression* base;
     244             :   std::string field_name;
     245             :   Expression* value;
     246             :   size_t offset;
     247             : };
     248             : 
     249         138 : struct IntrinsicCallExpression : Expression {
     250          81 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(IntrinsicCallExpression)
     251          46 :   IntrinsicCallExpression(SourcePosition pos, std::string name,
     252             :                           std::vector<TypeExpression*> generic_arguments,
     253             :                           std::vector<Expression*> arguments)
     254             :       : Expression(kKind, pos),
     255             :         name(std::move(name)),
     256             :         generic_arguments(std::move(generic_arguments)),
     257          92 :         arguments(std::move(arguments)) {}
     258             :   std::string name;
     259             :   std::vector<TypeExpression*> generic_arguments;
     260             :   std::vector<Expression*> arguments;
     261             : };
     262             : 
     263         351 : struct CallMethodExpression : Expression {
     264         126 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(CallMethodExpression)
     265             :   CallMethodExpression(SourcePosition pos, Expression* target,
     266             :                        IdentifierExpression* method,
     267             :                        std::vector<Expression*> arguments,
     268             :                        std::vector<std::string> labels)
     269             :       : Expression(kKind, pos),
     270             :         target(target),
     271             :         method(method),
     272             :         arguments(std::move(arguments)),
     273         117 :         labels(std::move(labels)) {}
     274             :   Expression* target;
     275             :   IdentifierExpression* method;
     276             :   std::vector<Expression*> arguments;
     277             :   std::vector<std::string> labels;
     278             : };
     279             : 
     280        8823 : struct CallExpression : Expression {
     281        3207 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(CallExpression)
     282             :   CallExpression(SourcePosition pos, IdentifierExpression* callee,
     283             :                  std::vector<Expression*> arguments,
     284             :                  std::vector<std::string> labels)
     285             :       : Expression(kKind, pos),
     286             :         callee(callee),
     287             :         arguments(std::move(arguments)),
     288        2941 :         labels(std::move(labels)) {}
     289             :   IdentifierExpression* callee;
     290             :   std::vector<Expression*> arguments;
     291             :   std::vector<std::string> labels;
     292             : };
     293             : 
     294          68 : struct StructExpression : Expression {
     295          17 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(StructExpression)
     296          17 :   StructExpression(SourcePosition pos,
     297             :                    std::vector<std::string> namespace_qualification,
     298             :                    std::string name, std::vector<Expression*> expressions)
     299             :       : Expression(kKind, pos),
     300             :         namespace_qualification(std::move(namespace_qualification)),
     301             :         name(std::move(name)),
     302          34 :         expressions(std::move(expressions)) {}
     303             :   std::vector<std::string> namespace_qualification;
     304             :   std::string name;
     305             :   std::vector<Expression*> expressions;
     306             : };
     307             : 
     308          56 : struct LogicalOrExpression : Expression {
     309          31 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(LogicalOrExpression)
     310             :   LogicalOrExpression(SourcePosition pos, Expression* left, Expression* right)
     311          28 :       : Expression(kKind, pos), left(left), right(right) {}
     312             :   Expression* left;
     313             :   Expression* right;
     314             : };
     315             : 
     316          92 : struct LogicalAndExpression : Expression {
     317          24 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(LogicalAndExpression)
     318             :   LogicalAndExpression(SourcePosition pos, Expression* left, Expression* right)
     319          46 :       : Expression(kKind, pos), left(left), right(right) {}
     320             :   Expression* left;
     321             :   Expression* right;
     322             : };
     323             : 
     324         196 : struct ConditionalExpression : Expression {
     325         101 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ConditionalExpression)
     326             :   ConditionalExpression(SourcePosition pos, Expression* condition,
     327             :                         Expression* if_true, Expression* if_false)
     328             :       : Expression(kKind, pos),
     329             :         condition(condition),
     330             :         if_true(if_true),
     331          98 :         if_false(if_false) {}
     332             :   Expression* condition;
     333             :   Expression* if_true;
     334             :   Expression* if_false;
     335             : };
     336             : 
     337         200 : struct StringLiteralExpression : Expression {
     338         101 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(StringLiteralExpression)
     339             :   StringLiteralExpression(SourcePosition pos, std::string literal)
     340         100 :       : Expression(kKind, pos), literal(std::move(literal)) {}
     341             :   std::string literal;
     342             : };
     343             : 
     344        1876 : struct NumberLiteralExpression : Expression {
     345         911 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(NumberLiteralExpression)
     346             :   NumberLiteralExpression(SourcePosition pos, std::string name)
     347         938 :       : Expression(kKind, pos), number(std::move(name)) {}
     348             :   std::string number;
     349             : };
     350             : 
     351         522 : struct ElementAccessExpression : LocationExpression {
     352         211 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ElementAccessExpression)
     353             :   ElementAccessExpression(SourcePosition pos, Expression* array,
     354             :                           Expression* index)
     355         261 :       : LocationExpression(kKind, pos), array(array), index(index) {}
     356             :   Expression* array;
     357             :   Expression* index;
     358             : };
     359             : 
     360        1242 : struct FieldAccessExpression : LocationExpression {
     361         633 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(FieldAccessExpression)
     362             :   FieldAccessExpression(SourcePosition pos, Expression* object,
     363             :                         Identifier* field)
     364         621 :       : LocationExpression(kKind, pos), object(object), field(field) {}
     365             :   Expression* object;
     366             :   Identifier* field;
     367             : };
     368             : 
     369         796 : struct AssignmentExpression : Expression {
     370         479 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(AssignmentExpression)
     371             :   AssignmentExpression(SourcePosition pos, LocationExpression* location,
     372             :                        base::Optional<std::string> op, Expression* value)
     373             :       : Expression(kKind, pos),
     374             :         location(location),
     375             :         op(std::move(op)),
     376         796 :         value(value) {}
     377             :   LocationExpression* location;
     378             :   base::Optional<std::string> op;
     379             :   Expression* value;
     380             : };
     381             : 
     382             : enum class IncrementDecrementOperator { kIncrement, kDecrement };
     383             : 
     384         270 : struct IncrementDecrementExpression : Expression {
     385         153 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(IncrementDecrementExpression)
     386             :   IncrementDecrementExpression(SourcePosition pos, LocationExpression* location,
     387             :                                IncrementDecrementOperator op, bool postfix)
     388         135 :       : Expression(kKind, pos), location(location), op(op), postfix(postfix) {}
     389             :   LocationExpression* location;
     390             :   IncrementDecrementOperator op;
     391             :   bool postfix;
     392             : };
     393             : 
     394             : // This expression is only used in the desugaring of typeswitch, and it allows
     395             : // to bake in the static information that certain types are impossible at a
     396             : // certain position in the control flow.
     397             : // The result type is the type of {expression} minus the provided type.
     398          68 : struct AssumeTypeImpossibleExpression : Expression {
     399          40 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(AssumeTypeImpossibleExpression)
     400             :   AssumeTypeImpossibleExpression(SourcePosition pos,
     401             :                                  TypeExpression* excluded_type,
     402             :                                  Expression* expression)
     403             :       : Expression(kKind, pos),
     404             :         excluded_type(excluded_type),
     405          34 :         expression(expression) {}
     406             :   TypeExpression* excluded_type;
     407             :   Expression* expression;
     408             : };
     409             : 
     410          14 : struct NewExpression : Expression {
     411           7 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(NewExpression)
     412             :   NewExpression(SourcePosition pos, TypeExpression* type,
     413             :                 std::vector<Expression*> parameters)
     414           7 :       : Expression(kKind, pos), type(type), parameters(parameters) {}
     415             :   TypeExpression* type;
     416             :   std::vector<Expression*> parameters;
     417             : };
     418             : 
     419       49916 : struct ParameterList {
     420             :   std::vector<Identifier*> names;
     421             :   std::vector<TypeExpression*> types;
     422             :   size_t implicit_count;
     423             :   bool has_varargs;
     424             :   std::string arguments_variable;
     425             : 
     426         195 :   static ParameterList Empty() { return ParameterList{{}, {}, 0, false, ""}; }
     427             :   std::vector<TypeExpression*> GetImplicitTypes() {
     428             :     return std::vector<TypeExpression*>(types.begin(),
     429             :                                         types.begin() + implicit_count);
     430             :   }
     431             :   std::vector<TypeExpression*> GetExplicitTypes() {
     432             :     return std::vector<TypeExpression*>(types.begin() + implicit_count,
     433             :                                         types.end());
     434             :   }
     435             : };
     436             : 
     437       22128 : struct BasicTypeExpression : TypeExpression {
     438       14170 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(BasicTypeExpression)
     439             :   BasicTypeExpression(SourcePosition pos,
     440             :                       std::vector<std::string> namespace_qualification,
     441             :                       bool is_constexpr, std::string name)
     442             :       : TypeExpression(kKind, pos),
     443             :         namespace_qualification(std::move(namespace_qualification)),
     444             :         is_constexpr(is_constexpr),
     445       11064 :         name(std::move(name)) {}
     446             :   std::vector<std::string> namespace_qualification;
     447             :   bool is_constexpr;
     448             :   std::string name;
     449             : };
     450             : 
     451          22 : struct FunctionTypeExpression : TypeExpression {
     452          11 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(FunctionTypeExpression)
     453             :   FunctionTypeExpression(SourcePosition pos,
     454             :                          std::vector<TypeExpression*> parameters,
     455             :                          TypeExpression* return_type)
     456             :       : TypeExpression(kKind, pos),
     457             :         parameters(std::move(parameters)),
     458          22 :         return_type(return_type) {}
     459             :   std::vector<TypeExpression*> parameters;
     460             :   TypeExpression* return_type;
     461             : };
     462             : 
     463         214 : struct UnionTypeExpression : TypeExpression {
     464         108 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(UnionTypeExpression)
     465             :   UnionTypeExpression(SourcePosition pos, TypeExpression* a, TypeExpression* b)
     466         107 :       : TypeExpression(kKind, pos), a(a), b(b) {}
     467             :   TypeExpression* a;
     468             :   TypeExpression* b;
     469             : };
     470             : 
     471        2980 : struct ExpressionStatement : Statement {
     472        1799 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ExpressionStatement)
     473             :   ExpressionStatement(SourcePosition pos, Expression* expression)
     474        1490 :       : Statement(kKind, pos), expression(expression) {}
     475             :   Expression* expression;
     476             : };
     477             : 
     478         974 : struct IfStatement : Statement {
     479         664 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(IfStatement)
     480             :   IfStatement(SourcePosition pos, bool is_constexpr, Expression* condition,
     481             :               Statement* if_true, base::Optional<Statement*> if_false)
     482             :       : Statement(kKind, pos),
     483             :         condition(condition),
     484             :         is_constexpr(is_constexpr),
     485             :         if_true(if_true),
     486         487 :         if_false(if_false) {}
     487             :   Expression* condition;
     488             :   bool is_constexpr;
     489             :   Statement* if_true;
     490             :   base::Optional<Statement*> if_false;
     491             : };
     492             : 
     493          76 : struct WhileStatement : Statement {
     494          42 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(WhileStatement)
     495             :   WhileStatement(SourcePosition pos, Expression* condition, Statement* body)
     496          38 :       : Statement(kKind, pos), condition(condition), body(body) {}
     497             :   Expression* condition;
     498             :   Statement* body;
     499             : };
     500             : 
     501        1688 : struct ReturnStatement : Statement {
     502        1016 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ReturnStatement)
     503             :   ReturnStatement(SourcePosition pos, base::Optional<Expression*> value)
     504         844 :       : Statement(kKind, pos), value(value) {}
     505             :   base::Optional<Expression*> value;
     506             : };
     507             : 
     508         246 : struct DebugStatement : Statement {
     509         125 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(DebugStatement)
     510             :   DebugStatement(SourcePosition pos, const std::string& reason,
     511             :                  bool never_continues)
     512             :       : Statement(kKind, pos),
     513             :         reason(reason),
     514         246 :         never_continues(never_continues) {}
     515             :   std::string reason;
     516             :   bool never_continues;
     517             : };
     518             : 
     519         454 : struct AssertStatement : Statement {
     520         287 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(AssertStatement)
     521             :   AssertStatement(SourcePosition pos, bool debug_only, Expression* expression,
     522             :                   std::string source)
     523             :       : Statement(kKind, pos),
     524             :         debug_only(debug_only),
     525             :         expression(expression),
     526         227 :         source(std::move(source)) {}
     527             :   bool debug_only;
     528             :   Expression* expression;
     529             :   std::string source;
     530             : };
     531             : 
     532           4 : struct TailCallStatement : Statement {
     533           2 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(TailCallStatement)
     534             :   TailCallStatement(SourcePosition pos, CallExpression* call)
     535           2 :       : Statement(kKind, pos), call(call) {}
     536             :   CallExpression* call;
     537             : };
     538             : 
     539        2374 : struct VarDeclarationStatement : Statement {
     540        4151 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(VarDeclarationStatement)
     541             :   VarDeclarationStatement(
     542             :       SourcePosition pos, bool const_qualified, Identifier* name,
     543             :       base::Optional<TypeExpression*> type,
     544             :       base::Optional<Expression*> initializer = base::nullopt)
     545             :       : Statement(kKind, pos),
     546             :         const_qualified(const_qualified),
     547             :         name(name),
     548             :         type(type),
     549        1187 :         initializer(initializer) {}
     550             :   bool const_qualified;
     551             :   Identifier* name;
     552             :   base::Optional<TypeExpression*> type;
     553             :   base::Optional<Expression*> initializer;
     554             : };
     555             : 
     556          50 : struct BreakStatement : Statement {
     557          25 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(BreakStatement)
     558          25 :   explicit BreakStatement(SourcePosition pos) : Statement(kKind, pos) {}
     559             : };
     560             : 
     561          28 : struct ContinueStatement : Statement {
     562          17 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ContinueStatement)
     563          14 :   explicit ContinueStatement(SourcePosition pos) : Statement(kKind, pos) {}
     564             : };
     565             : 
     566         555 : struct GotoStatement : Statement {
     567         222 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(GotoStatement)
     568         185 :   GotoStatement(SourcePosition pos, std::string label,
     569             :                 const std::vector<Expression*>& arguments)
     570             :       : Statement(kKind, pos),
     571             :         label(std::move(label)),
     572         370 :         arguments(std::move(arguments)) {}
     573             :   std::string label;
     574             :   std::vector<Expression*> arguments;
     575             : };
     576             : 
     577         108 : struct ForLoopStatement : Statement {
     578          57 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ForLoopStatement)
     579             :   ForLoopStatement(SourcePosition pos, base::Optional<Statement*> declaration,
     580             :                    base::Optional<Expression*> test,
     581             :                    base::Optional<Statement*> action, Statement* body)
     582             :       : Statement(kKind, pos),
     583             :         var_declaration(),
     584             :         test(std::move(test)),
     585             :         action(std::move(action)),
     586         108 :         body(std::move(body)) {
     587          54 :     if (declaration)
     588             :       var_declaration = VarDeclarationStatement::cast(*declaration);
     589             :   }
     590             :   base::Optional<VarDeclarationStatement*> var_declaration;
     591             :   base::Optional<Expression*> test;
     592             :   base::Optional<Statement*> action;
     593             :   Statement* body;
     594             : };
     595             : 
     596             : struct RangeExpression {
     597             :   base::Optional<Expression*> begin;
     598             :   base::Optional<Expression*> end;
     599             : };
     600             : 
     601           6 : struct ForOfLoopStatement : Statement {
     602           4 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ForOfLoopStatement)
     603             :   ForOfLoopStatement(SourcePosition pos, Statement* decl, Expression* iterable,
     604             :                      base::Optional<RangeExpression> range, Statement* body)
     605             :       : Statement(kKind, pos),
     606             :         var_declaration(VarDeclarationStatement::cast(decl)),
     607             :         iterable(iterable),
     608           9 :         body(body) {
     609           3 :     if (range) {
     610             :       begin = range->begin;
     611             :       end = range->end;
     612             :     }
     613             :   }
     614             :   VarDeclarationStatement* var_declaration;
     615             :   Expression* iterable;
     616             :   base::Optional<Expression*> begin;
     617             :   base::Optional<Expression*> end;
     618             :   Statement* body;
     619             : };
     620             : 
     621         987 : struct LabelBlock : AstNode {
     622             :   DEFINE_AST_NODE_LEAF_BOILERPLATE(LabelBlock)
     623         329 :   LabelBlock(SourcePosition pos, std::string label,
     624             :              const ParameterList& parameters, Statement* body)
     625             :       : AstNode(kKind, pos),
     626             :         label(std::move(label)),
     627             :         parameters(parameters),
     628         658 :         body(std::move(body)) {}
     629             :   std::string label;
     630             :   ParameterList parameters;
     631             :   Statement* body;
     632             : };
     633             : 
     634         336 : struct StatementExpression : Expression {
     635         179 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(StatementExpression)
     636             :   StatementExpression(SourcePosition pos, Statement* statement)
     637         168 :       : Expression(kKind, pos), statement(statement) {}
     638             :   Statement* statement;
     639             : };
     640             : 
     641         658 : struct TryLabelExpression : Expression {
     642         342 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(TryLabelExpression)
     643             :   TryLabelExpression(SourcePosition pos, bool catch_exceptions,
     644             :                      Expression* try_expression, LabelBlock* label_block)
     645             :       : Expression(kKind, pos),
     646             :         catch_exceptions(catch_exceptions),
     647             :         try_expression(try_expression),
     648         329 :         label_block(label_block) {}
     649             :   bool catch_exceptions;
     650             :   Expression* try_expression;
     651             :   LabelBlock* label_block;
     652             : };
     653             : 
     654        2874 : struct BlockStatement : Statement {
     655        6870 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(BlockStatement)
     656             :   explicit BlockStatement(SourcePosition pos, bool deferred = false,
     657             :                           std::vector<Statement*> statements = {})
     658             :       : Statement(kKind, pos),
     659             :         deferred(deferred),
     660        1437 :         statements(std::move(statements)) {}
     661             :   bool deferred;
     662             :   std::vector<Statement*> statements;
     663             : };
     664             : 
     665         288 : struct TypeDeclaration : Declaration {
     666          96 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(TypeDeclaration)
     667          96 :   TypeDeclaration(SourcePosition pos, Identifier* name, bool transient,
     668             :                   base::Optional<Identifier*> extends,
     669             :                   base::Optional<std::string> generates,
     670             :                   base::Optional<std::string> constexpr_generates)
     671             :       : Declaration(kKind, pos),
     672             :         name(name),
     673             :         transient(transient),
     674             :         extends(extends),
     675             :         generates(std::move(generates)),
     676         192 :         constexpr_generates(std::move(constexpr_generates)) {}
     677             :   Identifier* name;
     678             :   bool transient;
     679             :   base::Optional<Identifier*> extends;
     680             :   base::Optional<std::string> generates;
     681             :   base::Optional<std::string> constexpr_generates;
     682             : };
     683             : 
     684          36 : struct TypeAliasDeclaration : Declaration {
     685          18 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(TypeAliasDeclaration)
     686             :   TypeAliasDeclaration(SourcePosition pos, Identifier* name,
     687             :                        TypeExpression* type)
     688          18 :       : Declaration(kKind, pos), name(name), type(type) {}
     689             :   Identifier* name;
     690             :   TypeExpression* type;
     691             : };
     692             : 
     693             : struct NameAndTypeExpression {
     694             :   Identifier* name;
     695             :   TypeExpression* type;
     696             : };
     697             : 
     698             : struct StructFieldExpression {
     699             :   NameAndTypeExpression name_and_type;
     700             : };
     701             : 
     702        4643 : struct ClassFieldExpression {
     703             :   NameAndTypeExpression name_and_type;
     704             :   base::Optional<std::string> index;
     705             :   bool weak;
     706             : };
     707             : 
     708        2650 : struct LabelAndTypes {
     709             :   std::string name;
     710             :   std::vector<TypeExpression*> types;
     711             : };
     712             : 
     713             : typedef std::vector<LabelAndTypes> LabelAndTypesVector;
     714             : 
     715        1021 : struct CallableNodeSignature {
     716             :   ParameterList parameters;
     717             :   TypeExpression* return_type;
     718             :   LabelAndTypesVector labels;
     719             : };
     720             : 
     721        1764 : struct CallableNode : AstNode {
     722         882 :   CallableNode(AstNode::Kind kind, SourcePosition pos, bool transitioning,
     723             :                std::string name, ParameterList parameters,
     724             :                TypeExpression* return_type, const LabelAndTypesVector& labels)
     725             :       : AstNode(kind, pos),
     726             :         transitioning(transitioning),
     727             :         name(std::move(name)),
     728        2646 :         signature(new CallableNodeSignature{parameters, return_type, labels}) {}
     729             :   DEFINE_AST_NODE_INNER_BOILERPLATE(CallableNode)
     730             :   bool transitioning;
     731             :   std::string name;
     732             :   std::unique_ptr<CallableNodeSignature> signature;
     733             : };
     734             : 
     735        1420 : struct MacroDeclaration : CallableNode {
     736         319 :   DEFINE_AST_NODE_INNER_BOILERPLATE(MacroDeclaration)
     737         710 :   MacroDeclaration(AstNode::Kind kind, SourcePosition pos, bool transitioning,
     738             :                    std::string name, base::Optional<std::string> op,
     739             :                    ParameterList parameters, TypeExpression* return_type,
     740             :                    const LabelAndTypesVector& labels)
     741             :       : CallableNode(kind, pos, transitioning, std::move(name),
     742             :                      std::move(parameters), return_type, labels),
     743        2840 :         op(std::move(op)) {}
     744             :   base::Optional<std::string> op;
     745             : };
     746             : 
     747        1236 : struct ExternalMacroDeclaration : MacroDeclaration {
     748         412 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalMacroDeclaration)
     749         412 :   ExternalMacroDeclaration(SourcePosition pos, bool transitioning,
     750             :                            std::string external_assembler_name,
     751             :                            std::string name, base::Optional<std::string> op,
     752             :                            ParameterList parameters,
     753             :                            TypeExpression* return_type,
     754             :                            const LabelAndTypesVector& labels)
     755             :       : MacroDeclaration(kKind, pos, transitioning, std::move(name),
     756             :                          std::move(op), std::move(parameters), return_type,
     757             :                          labels),
     758        2060 :         external_assembler_name(std::move(external_assembler_name)) {}
     759             :   std::string external_assembler_name;
     760             : };
     761             : 
     762           6 : struct IntrinsicDeclaration : CallableNode {
     763         186 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(IntrinsicDeclaration)
     764           6 :   IntrinsicDeclaration(SourcePosition pos, std::string name,
     765             :                        ParameterList parameters, TypeExpression* return_type)
     766             :       : CallableNode(kKind, pos, false, std::move(name), std::move(parameters),
     767          18 :                      return_type, {}) {}
     768             : };
     769             : 
     770         298 : struct TorqueMacroDeclaration : MacroDeclaration {
     771         267 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(TorqueMacroDeclaration)
     772         298 :   TorqueMacroDeclaration(SourcePosition pos, bool transitioning,
     773             :                          std::string name, base::Optional<std::string> op,
     774             :                          ParameterList parameters, TypeExpression* return_type,
     775             :                          const LabelAndTypesVector& labels)
     776             :       : MacroDeclaration(kKind, pos, transitioning, std::move(name),
     777             :                          std::move(op), std::move(parameters), return_type,
     778        1192 :                          labels) {}
     779             : };
     780             : 
     781         150 : struct BuiltinDeclaration : CallableNode {
     782             :   DEFINE_AST_NODE_INNER_BOILERPLATE(BuiltinDeclaration)
     783         150 :   BuiltinDeclaration(AstNode::Kind kind, SourcePosition pos,
     784             :                      bool javascript_linkage, bool transitioning,
     785             :                      std::string name, ParameterList parameters,
     786             :                      TypeExpression* return_type)
     787             :       : CallableNode(kind, pos, transitioning, std::move(name),
     788             :                      std::move(parameters), return_type, {}),
     789         450 :         javascript_linkage(javascript_linkage) {}
     790             :   bool javascript_linkage;
     791             : };
     792             : 
     793          34 : struct ExternalBuiltinDeclaration : BuiltinDeclaration {
     794          17 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalBuiltinDeclaration)
     795          17 :   ExternalBuiltinDeclaration(SourcePosition pos, bool transitioning,
     796             :                              bool javascript_linkage, std::string name,
     797             :                              ParameterList parameters,
     798             :                              TypeExpression* return_type)
     799             :       : BuiltinDeclaration(kKind, pos, javascript_linkage, transitioning,
     800             :                            std::move(name), std::move(parameters),
     801          51 :                            return_type) {}
     802             : };
     803             : 
     804         266 : struct TorqueBuiltinDeclaration : BuiltinDeclaration {
     805         125 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(TorqueBuiltinDeclaration)
     806         133 :   TorqueBuiltinDeclaration(SourcePosition pos, bool transitioning,
     807             :                            bool javascript_linkage, std::string name,
     808             :                            ParameterList parameters,
     809             :                            TypeExpression* return_type)
     810             :       : BuiltinDeclaration(kKind, pos, javascript_linkage, transitioning,
     811             :                            std::move(name), std::move(parameters),
     812         399 :                            return_type) {}
     813             : };
     814             : 
     815          16 : struct ExternalRuntimeDeclaration : CallableNode {
     816          16 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalRuntimeDeclaration)
     817          16 :   ExternalRuntimeDeclaration(SourcePosition pos, bool transitioning,
     818             :                              std::string name, ParameterList parameters,
     819             :                              TypeExpression* return_type)
     820             :       : CallableNode(kKind, pos, transitioning, name, parameters, return_type,
     821          48 :                      {}) {}
     822             : };
     823             : 
     824          62 : struct ConstDeclaration : Declaration {
     825          31 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ConstDeclaration)
     826             :   ConstDeclaration(SourcePosition pos, Identifier* name, TypeExpression* type,
     827             :                    Expression* expression)
     828             :       : Declaration(kKind, pos),
     829             :         name(name),
     830             :         type(type),
     831          31 :         expression(expression) {}
     832             :   Identifier* name;
     833             :   TypeExpression* type;
     834             :   Expression* expression;
     835             : };
     836             : 
     837        1674 : struct StandardDeclaration : Declaration {
     838         837 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(StandardDeclaration)
     839             :   StandardDeclaration(SourcePosition pos, CallableNode* callable,
     840             :                       base::Optional<Statement*> body)
     841         837 :       : Declaration(kKind, pos), callable(callable), body(body) {}
     842             :   CallableNode* callable;
     843             :   base::Optional<Statement*> body;
     844             : };
     845             : 
     846          90 : struct GenericDeclaration : Declaration {
     847          45 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(GenericDeclaration)
     848             :   GenericDeclaration(SourcePosition pos, CallableNode* callable,
     849             :                      std::vector<Identifier*> generic_parameters,
     850             :                      base::Optional<Statement*> body = base::nullopt)
     851             :       : Declaration(kKind, pos),
     852             :         callable(callable),
     853             :         generic_parameters(std::move(generic_parameters)),
     854          90 :         body(body) {}
     855             :   CallableNode* callable;
     856             :   std::vector<Identifier*> generic_parameters;
     857             :   base::Optional<Statement*> body;
     858             : };
     859             : 
     860         417 : struct SpecializationDeclaration : Declaration {
     861         139 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(SpecializationDeclaration)
     862         139 :   SpecializationDeclaration(SourcePosition pos, std::string name,
     863             :                             std::vector<TypeExpression*> generic_parameters,
     864             :                             ParameterList parameters,
     865             :                             TypeExpression* return_type,
     866             :                             LabelAndTypesVector labels, Statement* b)
     867             :       : Declaration(kKind, pos),
     868             :         name(std::move(name)),
     869             :         external(false),
     870             :         generic_parameters(std::move(generic_parameters)),
     871             :         signature(new CallableNodeSignature{std::move(parameters), return_type,
     872             :                                             std::move(labels)}),
     873         556 :         body(b) {}
     874             :   std::string name;
     875             :   bool external;
     876             :   std::vector<TypeExpression*> generic_parameters;
     877             :   std::unique_ptr<CallableNodeSignature> signature;
     878             :   Statement* body;
     879             : };
     880             : 
     881         178 : struct ExternConstDeclaration : Declaration {
     882          89 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternConstDeclaration)
     883             :   ExternConstDeclaration(SourcePosition pos, Identifier* name,
     884             :                          TypeExpression* type, std::string literal)
     885             :       : Declaration(kKind, pos),
     886             :         name(name),
     887             :         type(type),
     888          89 :         literal(std::move(literal)) {}
     889             :   Identifier* name;
     890             :   TypeExpression* type;
     891             :   std::string literal;
     892             : };
     893             : 
     894          42 : struct StructDeclaration : Declaration {
     895          14 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(StructDeclaration)
     896             :   StructDeclaration(SourcePosition pos, Identifier* name,
     897             :                     std::vector<Declaration*> methods,
     898             :                     std::vector<StructFieldExpression> fields)
     899             :       : Declaration(kKind, pos),
     900             :         name(name),
     901             :         methods(std::move(methods)),
     902          14 :         fields(std::move(fields)) {}
     903             :   Identifier* name;
     904             :   std::vector<Declaration*> methods;
     905             :   std::vector<StructFieldExpression> fields;
     906             : };
     907             : 
     908         267 : struct ClassDeclaration : Declaration {
     909          89 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(ClassDeclaration)
     910          89 :   ClassDeclaration(SourcePosition pos, Identifier* name, bool is_extern,
     911             :                    bool transient, base::Optional<std::string> super,
     912             :                    base::Optional<std::string> generates,
     913             :                    std::vector<Declaration*> methods,
     914             :                    std::vector<ClassFieldExpression> fields)
     915             :       : Declaration(kKind, pos),
     916             :         name(name),
     917             :         is_extern(is_extern),
     918             :         transient(transient),
     919             :         super(std::move(super)),
     920             :         generates(std::move(generates)),
     921             :         methods(std::move(methods)),
     922         178 :         fields(std::move(fields)) {}
     923             :   Identifier* name;
     924             :   bool is_extern;
     925             :   bool transient;
     926             :   base::Optional<std::string> super;
     927             :   base::Optional<std::string> generates;
     928             :   std::vector<Declaration*> methods;
     929             :   std::vector<ClassFieldExpression> fields;
     930             : };
     931             : 
     932          58 : struct CppIncludeDeclaration : Declaration {
     933          29 :   DEFINE_AST_NODE_LEAF_BOILERPLATE(CppIncludeDeclaration)
     934             :   CppIncludeDeclaration(SourcePosition pos, std::string include_path)
     935          29 :       : Declaration(kKind, pos), include_path(std::move(include_path)) {}
     936             :   std::string include_path;
     937             : };
     938             : 
     939             : #define ENUM_ITEM(name)                     \
     940             :   case AstNode::Kind::k##name:              \
     941             :     return std::is_base_of<T, name>::value; \
     942             :     break;
     943             : 
     944             : template <class T>
     945       24683 : bool AstNodeClassCheck::IsInstanceOf(AstNode* node) {
     946       24683 :   switch (node->kind) {
     947       17506 :     AST_NODE_KIND_LIST(ENUM_ITEM)
     948             :     default:
     949           0 :       UNIMPLEMENTED();
     950             :   }
     951             :   return true;
     952             : }
     953             : 
     954             : #undef ENUM_ITEM
     955             : 
     956             : inline bool IsDeferred(Statement* stmt) {
     957        1014 :   if (auto* block = BlockStatement::DynamicCast(stmt)) {
     958         599 :     return block->deferred;
     959             :   }
     960             :   return false;
     961             : }
     962             : 
     963             : DECLARE_CONTEXTUAL_VARIABLE(CurrentAst, Ast);
     964             : 
     965             : template <class T, class... Args>
     966       46310 : T* MakeNode(Args... args) {
     967             :   return CurrentAst::Get().AddNode(std::unique_ptr<T>(
     968      205398 :       new T(CurrentSourcePosition::Get(), std::move(args)...)));
     969             : }
     970             : 
     971             : }  // namespace torque
     972             : }  // namespace internal
     973             : }  // namespace v8
     974             : 
     975             : #endif  // V8_TORQUE_AST_H_

Generated by: LCOV version 1.10