diff options
author | Michaël Zasso <targos@protonmail.com> | 2018-09-21 09:14:51 +0200 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2018-09-22 18:29:25 +0200 |
commit | 0e7ddbd3d7e9439c67573b854c49cf82c398ae82 (patch) | |
tree | 2afe372acde921cb57ddb3444ff00c5adef8848c /deps/v8/src/torque/ast.h | |
parent | 13245dc50da4cb7443c39ef6c68d419d5e6336d4 (diff) | |
download | android-node-v8-0e7ddbd3d7e9439c67573b854c49cf82c398ae82.tar.gz android-node-v8-0e7ddbd3d7e9439c67573b854c49cf82c398ae82.tar.bz2 android-node-v8-0e7ddbd3d7e9439c67573b854c49cf82c398ae82.zip |
deps: update V8 to 7.0.276.20
PR-URL: https://github.com/nodejs/node/pull/22754
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'deps/v8/src/torque/ast.h')
-rw-r--r-- | deps/v8/src/torque/ast.h | 499 |
1 files changed, 279 insertions, 220 deletions
diff --git a/deps/v8/src/torque/ast.h b/deps/v8/src/torque/ast.h index 6af444a56b..d9bb71a663 100644 --- a/deps/v8/src/torque/ast.h +++ b/deps/v8/src/torque/ast.h @@ -11,22 +11,12 @@ #include <vector> #include "src/base/optional.h" -#include "src/torque/contextual.h" +#include "src/torque/source-positions.h" namespace v8 { namespace internal { namespace torque { -enum class SourceId : int {}; - -struct SourcePosition { - SourceId source; - int line; - int column; -}; - -DECLARE_CONTEXTUAL_VARIABLE(CurrentSourcePosition, SourcePosition) - #define AST_EXPRESSION_NODE_KIND_LIST(V) \ V(CallExpression) \ V(StructExpression) \ @@ -39,7 +29,8 @@ DECLARE_CONTEXTUAL_VARIABLE(CurrentSourcePosition, SourcePosition) V(FieldAccessExpression) \ V(ElementAccessExpression) \ V(AssignmentExpression) \ - V(IncrementDecrementExpression) + V(IncrementDecrementExpression) \ + V(AssumeTypeImpossibleExpression) #define AST_TYPE_EXPRESSION_NODE_KIND_LIST(V) \ V(BasicTypeExpression) \ @@ -98,7 +89,7 @@ struct AstNode { #undef ENUM_ITEM }; - AstNode(Kind k, SourcePosition p) : kind(k), pos(p) {} + AstNode(Kind kind, SourcePosition pos) : kind(kind), pos(pos) {} virtual ~AstNode() {} const Kind kind; @@ -136,36 +127,38 @@ struct AstNodeClassCheck { } struct Expression : AstNode { - Expression(Kind k, SourcePosition p) : AstNode(k, p) {} + Expression(Kind kind, SourcePosition pos) : AstNode(kind, pos) {} DEFINE_AST_NODE_INNER_BOILERPLATE(Expression) }; struct LocationExpression : Expression { - LocationExpression(Kind k, SourcePosition p) : Expression(k, p) {} + LocationExpression(Kind kind, SourcePosition pos) : Expression(kind, pos) {} DEFINE_AST_NODE_INNER_BOILERPLATE(LocationExpression) }; struct TypeExpression : AstNode { - TypeExpression(Kind k, SourcePosition p) : AstNode(k, p) {} + TypeExpression(Kind kind, SourcePosition pos) : AstNode(kind, pos) {} DEFINE_AST_NODE_INNER_BOILERPLATE(TypeExpression) }; struct Declaration : AstNode { - Declaration(Kind k, SourcePosition p) : AstNode(k, p) {} + Declaration(Kind kind, SourcePosition pos) : AstNode(kind, pos) {} DEFINE_AST_NODE_INNER_BOILERPLATE(Declaration) }; struct Statement : AstNode { - Statement(Kind k, SourcePosition p) : AstNode(k, p) {} + Statement(Kind kind, SourcePosition pos) : AstNode(kind, pos) {} DEFINE_AST_NODE_INNER_BOILERPLATE(Statement) }; class Module; struct ModuleDeclaration : Declaration { - ModuleDeclaration(AstNode::Kind kind, SourcePosition p, - std::vector<Declaration*> d) - : Declaration(kind, p), module(nullptr), declarations(std::move(d)) {} + ModuleDeclaration(AstNode::Kind kind, SourcePosition pos, + std::vector<Declaration*> declarations) + : Declaration(kind, pos), + module(nullptr), + declarations(std::move(declarations)) {} virtual bool IsDefault() const = 0; // virtual std::string GetName() const = 0; void SetModule(Module* m) { module = m; } @@ -176,48 +169,24 @@ struct ModuleDeclaration : Declaration { struct DefaultModuleDeclaration : ModuleDeclaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(DefaultModuleDeclaration) - DefaultModuleDeclaration(SourcePosition p, std::vector<Declaration*> d) - : ModuleDeclaration(kKind, p, d) {} + DefaultModuleDeclaration(SourcePosition pos, + std::vector<Declaration*> declarations) + : ModuleDeclaration(kKind, pos, declarations) {} bool IsDefault() const override { return true; } }; struct ExplicitModuleDeclaration : ModuleDeclaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(ExplicitModuleDeclaration) - ExplicitModuleDeclaration(SourcePosition p, std::string n, - std::vector<Declaration*> d) - : ModuleDeclaration(kKind, p, d), name(std::move(n)) {} + ExplicitModuleDeclaration(SourcePosition pos, std::string name, + std::vector<Declaration*> declarations) + : ModuleDeclaration(kKind, pos, declarations), name(std::move(name)) {} bool IsDefault() const override { return false; } std::string name; }; -class SourceFileMap : public ContextualClass<SourceFileMap> { - public: - SourceFileMap() {} - const std::string& GetSource(SourceId id) const { - return sources_[static_cast<int>(id)]; - } - - std::string PositionAsString(SourcePosition pos) { - return GetSource(pos.source) + ":" + std::to_string(pos.line) + ":" + - std::to_string(pos.column); - } - - SourceId AddSource(std::string path) { - sources_.push_back(std::move(path)); - return static_cast<SourceId>(sources_.size() - 1); - } - - private: - std::vector<std::string> sources_; -}; - -inline std::string PositionAsString(SourcePosition pos) { - return SourceFileMap::Get().PositionAsString(pos); -} - class Ast { public: - Ast() : default_module_{SourcePosition(), {}} {} + Ast() : default_module_{SourcePosition{CurrentSourceFile::Get(), 0, 0}, {}} {} std::vector<Declaration*>& declarations() { return default_module_.declarations; @@ -225,8 +194,11 @@ class Ast { const std::vector<Declaration*>& declarations() const { return default_module_.declarations; } - void AddNode(std::unique_ptr<AstNode> node) { - nodes_.emplace_back(std::move(node)); + template <class T> + T* AddNode(std::unique_ptr<T> node) { + T* result = node.get(); + nodes_.push_back(std::move(node)); + return result; } DefaultModuleDeclaration* default_module() { return &default_module_; } @@ -237,10 +209,10 @@ class Ast { struct IdentifierExpression : LocationExpression { DEFINE_AST_NODE_LEAF_BOILERPLATE(IdentifierExpression) - IdentifierExpression(SourcePosition p, std::string n, - std::vector<TypeExpression*> args) - : LocationExpression(kKind, p), - name(std::move(n)), + IdentifierExpression(SourcePosition pos, std::string name, + std::vector<TypeExpression*> args = {}) + : LocationExpression(kKind, pos), + name(std::move(name)), generic_arguments(std::move(args)) {} std::string name; std::vector<TypeExpression*> generic_arguments; @@ -248,14 +220,15 @@ struct IdentifierExpression : LocationExpression { struct CallExpression : Expression { DEFINE_AST_NODE_LEAF_BOILERPLATE(CallExpression) - CallExpression(SourcePosition p, std::string c, bool o, - std::vector<TypeExpression*> ga, std::vector<Expression*> a, - std::vector<std::string> l) - : Expression(kKind, p), - callee(p, std::move(c), std::move(ga)), - is_operator(o), - arguments(std::move(a)), - labels(l) {} + CallExpression(SourcePosition pos, std::string callee, bool is_operator, + std::vector<TypeExpression*> generic_arguments, + std::vector<Expression*> arguments, + std::vector<std::string> labels) + : Expression(kKind, pos), + callee(pos, std::move(callee), std::move(generic_arguments)), + is_operator(is_operator), + arguments(std::move(arguments)), + labels(labels) {} IdentifierExpression callee; bool is_operator; std::vector<Expression*> arguments; @@ -264,33 +237,39 @@ struct CallExpression : Expression { struct StructExpression : Expression { DEFINE_AST_NODE_LEAF_BOILERPLATE(StructExpression) - StructExpression(SourcePosition p, std::string n, std::vector<Expression*> e) - : Expression(kKind, p), name(n), expressions(std::move(e)) {} + StructExpression(SourcePosition pos, std::string name, + std::vector<Expression*> expressions) + : Expression(kKind, pos), + name(name), + expressions(std::move(expressions)) {} std::string name; std::vector<Expression*> expressions; }; struct LogicalOrExpression : Expression { DEFINE_AST_NODE_LEAF_BOILERPLATE(LogicalOrExpression) - LogicalOrExpression(SourcePosition p, Expression* l, Expression* r) - : Expression(kKind, p), left(l), right(r) {} + LogicalOrExpression(SourcePosition pos, Expression* left, Expression* right) + : Expression(kKind, pos), left(left), right(right) {} Expression* left; Expression* right; }; struct LogicalAndExpression : Expression { DEFINE_AST_NODE_LEAF_BOILERPLATE(LogicalAndExpression) - LogicalAndExpression(SourcePosition p, Expression* l, Expression* r) - : Expression(kKind, p), left(l), right(r) {} + LogicalAndExpression(SourcePosition pos, Expression* left, Expression* right) + : Expression(kKind, pos), left(left), right(right) {} Expression* left; Expression* right; }; struct ConditionalExpression : Expression { DEFINE_AST_NODE_LEAF_BOILERPLATE(ConditionalExpression) - ConditionalExpression(SourcePosition p, Expression* c, Expression* t, - Expression* f) - : Expression(kKind, p), condition(c), if_true(t), if_false(f) {} + ConditionalExpression(SourcePosition pos, Expression* condition, + Expression* if_true, Expression* if_false) + : Expression(kKind, pos), + condition(condition), + if_true(if_true), + if_false(if_false) {} Expression* condition; Expression* if_true; Expression* if_false; @@ -298,39 +277,46 @@ struct ConditionalExpression : Expression { struct StringLiteralExpression : Expression { DEFINE_AST_NODE_LEAF_BOILERPLATE(StringLiteralExpression) - StringLiteralExpression(SourcePosition p, std::string l) - : Expression(kKind, p), literal(std::move(l)) {} + StringLiteralExpression(SourcePosition pos, std::string literal) + : Expression(kKind, pos), literal(std::move(literal)) {} std::string literal; }; struct NumberLiteralExpression : Expression { DEFINE_AST_NODE_LEAF_BOILERPLATE(NumberLiteralExpression) - NumberLiteralExpression(SourcePosition p, std::string n) - : Expression(kKind, p), number(std::move(n)) {} + NumberLiteralExpression(SourcePosition pos, std::string name) + : Expression(kKind, pos), number(std::move(name)) {} std::string number; }; struct ElementAccessExpression : LocationExpression { DEFINE_AST_NODE_LEAF_BOILERPLATE(ElementAccessExpression) - ElementAccessExpression(SourcePosition p, Expression* a, Expression* i) - : LocationExpression(kKind, p), array(a), index(i) {} + ElementAccessExpression(SourcePosition pos, Expression* array, + Expression* index) + : LocationExpression(kKind, pos), array(array), index(index) {} Expression* array; Expression* index; }; struct FieldAccessExpression : LocationExpression { DEFINE_AST_NODE_LEAF_BOILERPLATE(FieldAccessExpression) - FieldAccessExpression(SourcePosition p, Expression* o, std::string f) - : LocationExpression(kKind, p), object(o), field(std::move(f)) {} + FieldAccessExpression(SourcePosition pos, Expression* object, + std::string field) + : LocationExpression(kKind, pos), + object(object), + field(std::move(field)) {} Expression* object; std::string field; }; struct AssignmentExpression : Expression { DEFINE_AST_NODE_LEAF_BOILERPLATE(AssignmentExpression) - AssignmentExpression(SourcePosition p, LocationExpression* l, - base::Optional<std::string> o, Expression* v) - : Expression(kKind, p), location(l), op(std::move(o)), value(v) {} + AssignmentExpression(SourcePosition pos, LocationExpression* location, + base::Optional<std::string> op, Expression* value) + : Expression(kKind, pos), + location(location), + op(std::move(op)), + value(value) {} LocationExpression* location; base::Optional<std::string> op; Expression* value; @@ -340,34 +326,56 @@ enum class IncrementDecrementOperator { kIncrement, kDecrement }; struct IncrementDecrementExpression : Expression { DEFINE_AST_NODE_LEAF_BOILERPLATE(IncrementDecrementExpression) - IncrementDecrementExpression(SourcePosition p, LocationExpression* l, - IncrementDecrementOperator o, bool pf) - : Expression(kKind, p), location(l), op(o), postfix(pf) {} + IncrementDecrementExpression(SourcePosition pos, LocationExpression* location, + IncrementDecrementOperator op, bool postfix) + : Expression(kKind, pos), location(location), op(op), postfix(postfix) {} LocationExpression* location; IncrementDecrementOperator op; bool postfix; }; +// This expression is only used in the desugaring of typeswitch, and it allows +// to bake in the static information that certain types are impossible at a +// certain position in the control flow. +// The result type is the type of {expression} minus the provided type. +struct AssumeTypeImpossibleExpression : Expression { + DEFINE_AST_NODE_LEAF_BOILERPLATE(AssumeTypeImpossibleExpression) + AssumeTypeImpossibleExpression(SourcePosition pos, + TypeExpression* excluded_type, + Expression* expression) + : Expression(kKind, pos), + excluded_type(excluded_type), + expression(expression) {} + TypeExpression* excluded_type; + Expression* expression; +}; + struct ParameterList { std::vector<std::string> names; std::vector<TypeExpression*> types; bool has_varargs; std::string arguments_variable; + + static ParameterList Empty() { return ParameterList{{}, {}, false, ""}; } }; struct BasicTypeExpression : TypeExpression { DEFINE_AST_NODE_LEAF_BOILERPLATE(BasicTypeExpression) - BasicTypeExpression(SourcePosition p, bool c, std::string n) - : TypeExpression(kKind, p), is_constexpr(c), name(n) {} + BasicTypeExpression(SourcePosition pos, bool is_constexpr, std::string name) + : TypeExpression(kKind, pos), is_constexpr(is_constexpr), name(name) {} bool is_constexpr; std::string name; }; struct FunctionTypeExpression : TypeExpression { DEFINE_AST_NODE_LEAF_BOILERPLATE(FunctionTypeExpression) - FunctionTypeExpression(SourcePosition p, ParameterList pl, TypeExpression* r) - : TypeExpression(kKind, p), parameters(pl), return_type(r) {} - ParameterList parameters; + FunctionTypeExpression(SourcePosition pos, + std::vector<TypeExpression*> parameters, + TypeExpression* return_type) + : TypeExpression(kKind, pos), + parameters(parameters), + return_type(return_type) {} + std::vector<TypeExpression*> parameters; TypeExpression* return_type; }; @@ -381,20 +389,20 @@ struct UnionTypeExpression : TypeExpression { struct ExpressionStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(ExpressionStatement) - ExpressionStatement(SourcePosition p, Expression* e) - : Statement(kKind, p), expression(e) {} + ExpressionStatement(SourcePosition pos, Expression* expression) + : Statement(kKind, pos), expression(expression) {} Expression* expression; }; struct IfStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(IfStatement) - IfStatement(SourcePosition p, Expression* c, bool cexpr, Statement* t, - base::Optional<Statement*> f) - : Statement(kKind, p), - condition(c), - is_constexpr(cexpr), - if_true(t), - if_false(f) {} + IfStatement(SourcePosition pos, bool is_constexpr, Expression* condition, + Statement* if_true, base::Optional<Statement*> if_false) + : Statement(kKind, pos), + condition(condition), + is_constexpr(is_constexpr), + if_true(if_true), + if_false(if_false) {} Expression* condition; bool is_constexpr; Statement* if_true; @@ -403,23 +411,26 @@ struct IfStatement : Statement { struct WhileStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(WhileStatement) - WhileStatement(SourcePosition p, Expression* c, Statement* b) - : Statement(kKind, p), condition(c), body(b) {} + WhileStatement(SourcePosition pos, Expression* condition, Statement* body) + : Statement(kKind, pos), condition(condition), body(body) {} Expression* condition; Statement* body; }; struct ReturnStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(ReturnStatement) - ReturnStatement(SourcePosition p, base::Optional<Expression*> v) - : Statement(kKind, p), value(v) {} + ReturnStatement(SourcePosition pos, base::Optional<Expression*> value) + : Statement(kKind, pos), value(value) {} base::Optional<Expression*> value; }; struct DebugStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(DebugStatement) - DebugStatement(SourcePosition p, const std::string& r, bool n) - : Statement(kKind, p), reason(r), never_continues(n) {} + DebugStatement(SourcePosition pos, const std::string& reason, + bool never_continues) + : Statement(kKind, pos), + reason(reason), + never_continues(never_continues) {} std::string reason; bool never_continues; }; @@ -439,71 +450,86 @@ struct AssertStatement : Statement { struct TailCallStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(TailCallStatement) - TailCallStatement(SourcePosition p, CallExpression* c) - : Statement(kKind, p), call(c) {} + TailCallStatement(SourcePosition pos, CallExpression* call) + : Statement(kKind, pos), call(call) {} CallExpression* call; }; struct VarDeclarationStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(VarDeclarationStatement) - VarDeclarationStatement(SourcePosition p, bool c, std::string n, - TypeExpression* t, base::Optional<Expression*> i) - : Statement(kKind, p), - const_qualified(c), - name(std::move(n)), - type(t), - initializer(i) {} + VarDeclarationStatement( + SourcePosition pos, bool const_qualified, std::string name, + base::Optional<TypeExpression*> type, + base::Optional<Expression*> initializer = base::nullopt) + : Statement(kKind, pos), + const_qualified(const_qualified), + name(std::move(name)), + type(type), + initializer(initializer) {} bool const_qualified; std::string name; - TypeExpression* type; + base::Optional<TypeExpression*> type; base::Optional<Expression*> initializer; }; struct BreakStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(BreakStatement) - explicit BreakStatement(SourcePosition p) : Statement(kKind, p) {} + explicit BreakStatement(SourcePosition pos) : Statement(kKind, pos) {} }; struct ContinueStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(ContinueStatement) - explicit ContinueStatement(SourcePosition p) : Statement(kKind, p) {} + explicit ContinueStatement(SourcePosition pos) : Statement(kKind, pos) {} }; struct GotoStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(GotoStatement) - GotoStatement(SourcePosition p, std::string l, - const std::vector<Expression*>& a) - : Statement(kKind, p), label(std::move(l)), arguments(std::move(a)) {} + GotoStatement(SourcePosition pos, std::string label, + const std::vector<Expression*>& arguments) + : Statement(kKind, pos), + label(std::move(label)), + arguments(std::move(arguments)) {} std::string label; std::vector<Expression*> arguments; }; struct ForLoopStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(ForLoopStatement) - ForLoopStatement(SourcePosition p, base::Optional<VarDeclarationStatement*> d, - Expression* t, Expression* a, Statement* b) - : Statement(kKind, p), - var_declaration(d), - test(std::move(t)), - action(std::move(a)), - body(std::move(b)) {} + ForLoopStatement(SourcePosition pos, base::Optional<Statement*> declaration, + base::Optional<Expression*> test, + base::Optional<Expression*> action, Statement* body) + : Statement(kKind, pos), + var_declaration(), + test(std::move(test)), + action(std::move(action)), + body(std::move(body)) { + if (declaration) + var_declaration = VarDeclarationStatement::cast(*declaration); + } base::Optional<VarDeclarationStatement*> var_declaration; - Expression* test; - Expression* action; + base::Optional<Expression*> test; + base::Optional<Expression*> action; Statement* body; }; +struct RangeExpression { + base::Optional<Expression*> begin; + base::Optional<Expression*> end; +}; + struct ForOfLoopStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(ForOfLoopStatement) - ForOfLoopStatement(SourcePosition p, VarDeclarationStatement* d, - Expression* i, base::Optional<Expression*> bg, - base::Optional<Expression*> e, Statement* bd) - : Statement(kKind, p), - var_declaration(d), - iterable(std::move(i)), - begin(std::move(bg)), - end(std::move(e)), - body(std::move(bd)) {} + ForOfLoopStatement(SourcePosition pos, Statement* decl, Expression* iterable, + base::Optional<RangeExpression> range, Statement* body) + : Statement(kKind, pos), + var_declaration(VarDeclarationStatement::cast(decl)), + iterable(iterable), + body(body) { + if (range) { + begin = range->begin; + end = range->end; + } + } VarDeclarationStatement* var_declaration; Expression* iterable; base::Optional<Expression*> begin; @@ -513,12 +539,12 @@ struct ForOfLoopStatement : Statement { struct LabelBlock : AstNode { DEFINE_AST_NODE_LEAF_BOILERPLATE(LabelBlock) - LabelBlock(SourcePosition p, const std::string& l, - const ParameterList& p_list, Statement* b) - : AstNode(kKind, p), - label(std::move(l)), - parameters(p_list), - body(std::move(b)) {} + LabelBlock(SourcePosition pos, const std::string& label, + const ParameterList& parameters, Statement* body) + : AstNode(kKind, pos), + label(std::move(label)), + parameters(parameters), + body(std::move(body)) {} std::string label; ParameterList parameters; Statement* body; @@ -526,28 +552,37 @@ struct LabelBlock : AstNode { struct TryLabelStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(TryLabelStatement) - TryLabelStatement(SourcePosition p, Statement* t) - : Statement(kKind, p), try_block(std::move(t)) {} + TryLabelStatement(SourcePosition pos, Statement* try_block, + std::vector<LabelBlock*> label_blocks) + : Statement(kKind, pos), + try_block(try_block), + label_blocks(std::move(label_blocks)) {} Statement* try_block; std::vector<LabelBlock*> label_blocks; }; struct BlockStatement : Statement { DEFINE_AST_NODE_LEAF_BOILERPLATE(BlockStatement) - BlockStatement(SourcePosition p, bool d, std::vector<Statement*> s) - : Statement(kKind, p), deferred(d), statements(std::move(s)) {} + explicit BlockStatement(SourcePosition pos, bool deferred = false, + std::vector<Statement*> statements = {}) + : Statement(kKind, pos), + deferred(deferred), + statements(std::move(statements)) {} bool deferred; std::vector<Statement*> statements; }; struct TypeDeclaration : Declaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(TypeDeclaration) - TypeDeclaration(SourcePosition p, std::string n, - base::Optional<std::string> e, base::Optional<std::string> g) - : Declaration(kKind, p), - name(std::move(n)), - extends(std::move(e)), - generates(std::move(g)) {} + TypeDeclaration(SourcePosition pos, std::string name, + base::Optional<std::string> extends, + base::Optional<std::string> generates, + base::Optional<std::string> constexpr_generates) + : Declaration(kKind, pos), + name(std::move(name)), + extends(std::move(extends)), + generates(std::move(generates)), + constexpr_generates(std::move(constexpr_generates)) {} std::string name; base::Optional<std::string> extends; base::Optional<std::string> generates; @@ -556,13 +591,14 @@ struct TypeDeclaration : Declaration { struct TypeAliasDeclaration : Declaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(TypeAliasDeclaration) - TypeAliasDeclaration(SourcePosition p, std::string n, TypeExpression* t) - : Declaration(kKind, p), name(std::move(n)), type(t) {} + TypeAliasDeclaration(SourcePosition pos, std::string name, + TypeExpression* type) + : Declaration(kKind, pos), name(std::move(name)), type(type) {} std::string name; TypeExpression* type; }; -struct FieldNameAndType { +struct NameAndTypeExpression { std::string name; TypeExpression* type; }; @@ -581,12 +617,12 @@ struct CallableNodeSignature { }; struct CallableNode : AstNode { - CallableNode(AstNode::Kind kind, SourcePosition p, std::string n, - ParameterList pl, TypeExpression* r, - const LabelAndTypesVector& l) - : AstNode(kind, p), - name(std::move(n)), - signature(new CallableNodeSignature{pl, r, l}) {} + CallableNode(AstNode::Kind kind, SourcePosition pos, std::string name, + ParameterList parameters, TypeExpression* return_type, + const LabelAndTypesVector& labels) + : AstNode(kind, pos), + name(std::move(name)), + signature(new CallableNodeSignature{parameters, return_type, labels}) {} DEFINE_AST_NODE_INNER_BOILERPLATE(CallableNode) std::string name; std::unique_ptr<CallableNodeSignature> signature; @@ -594,61 +630,79 @@ struct CallableNode : AstNode { struct MacroDeclaration : CallableNode { DEFINE_AST_NODE_INNER_BOILERPLATE(MacroDeclaration) - MacroDeclaration(AstNode::Kind kind, SourcePosition p, std::string n, - base::Optional<std::string> o, ParameterList pl, - TypeExpression* r, const LabelAndTypesVector& l) - : CallableNode(kind, p, n, pl, r, l), op(std::move(o)) {} + MacroDeclaration(AstNode::Kind kind, SourcePosition pos, std::string name, + base::Optional<std::string> op, ParameterList parameters, + TypeExpression* return_type, + const LabelAndTypesVector& labels) + : CallableNode(kind, pos, name, parameters, return_type, labels), + op(std::move(op)) {} base::Optional<std::string> op; }; struct ExternalMacroDeclaration : MacroDeclaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalMacroDeclaration) - ExternalMacroDeclaration(SourcePosition p, std::string n, - base::Optional<std::string> o, ParameterList pl, - TypeExpression* r, const LabelAndTypesVector& l) - : MacroDeclaration(kKind, p, n, o, pl, r, l) {} + ExternalMacroDeclaration(SourcePosition pos, std::string name, + base::Optional<std::string> op, + ParameterList parameters, + TypeExpression* return_type, + const LabelAndTypesVector& labels) + : MacroDeclaration(kKind, pos, name, op, parameters, return_type, + labels) {} }; struct TorqueMacroDeclaration : MacroDeclaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(TorqueMacroDeclaration) - TorqueMacroDeclaration(SourcePosition p, std::string n, ParameterList pl, - TypeExpression* r, const LabelAndTypesVector& l) - : MacroDeclaration(kKind, p, n, {}, pl, r, l) {} + TorqueMacroDeclaration(SourcePosition pos, std::string name, + base::Optional<std::string> op, + ParameterList parameters, TypeExpression* return_type, + const LabelAndTypesVector& labels) + : MacroDeclaration(kKind, pos, name, op, parameters, return_type, + labels) {} }; struct BuiltinDeclaration : CallableNode { - BuiltinDeclaration(AstNode::Kind kind, SourcePosition p, bool j, - std::string n, ParameterList pl, TypeExpression* r) - : CallableNode(kind, p, n, pl, r, {}), javascript_linkage(j) {} + BuiltinDeclaration(AstNode::Kind kind, SourcePosition pos, + bool javascript_linkage, std::string name, + ParameterList parameters, TypeExpression* return_type) + : CallableNode(kind, pos, name, parameters, return_type, {}), + javascript_linkage(javascript_linkage) {} bool javascript_linkage; }; struct ExternalBuiltinDeclaration : BuiltinDeclaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalBuiltinDeclaration) - ExternalBuiltinDeclaration(SourcePosition p, bool j, std::string n, - ParameterList pl, TypeExpression* r) - : BuiltinDeclaration(kKind, p, j, n, pl, r) {} + ExternalBuiltinDeclaration(SourcePosition pos, bool javascript_linkage, + std::string name, ParameterList parameters, + TypeExpression* return_type) + : BuiltinDeclaration(kKind, pos, javascript_linkage, name, parameters, + return_type) {} }; struct TorqueBuiltinDeclaration : BuiltinDeclaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(TorqueBuiltinDeclaration) - TorqueBuiltinDeclaration(SourcePosition p, bool j, std::string n, - ParameterList pl, TypeExpression* r) - : BuiltinDeclaration(kKind, p, j, n, pl, r) {} + TorqueBuiltinDeclaration(SourcePosition pos, bool javascript_linkage, + std::string name, ParameterList parameters, + TypeExpression* return_type) + : BuiltinDeclaration(kKind, pos, javascript_linkage, name, parameters, + return_type) {} }; struct ExternalRuntimeDeclaration : CallableNode { DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternalRuntimeDeclaration) - ExternalRuntimeDeclaration(SourcePosition p, std::string n, ParameterList pl, - TypeExpression* r) - : CallableNode(kKind, p, n, pl, r, {}) {} + ExternalRuntimeDeclaration(SourcePosition pos, std::string name, + ParameterList parameters, + TypeExpression* return_type) + : CallableNode(kKind, pos, name, parameters, return_type, {}) {} }; struct ConstDeclaration : Declaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(ConstDeclaration) - ConstDeclaration(SourcePosition p, std::string n, TypeExpression* r, - Expression* e) - : Declaration(kKind, p), name(std::move(n)), type(r), expression(e) {} + ConstDeclaration(SourcePosition pos, std::string name, TypeExpression* type, + Expression* expression) + : Declaration(kKind, pos), + name(std::move(name)), + type(type), + expression(expression) {} std::string name; TypeExpression* type; Expression* expression; @@ -656,21 +710,22 @@ struct ConstDeclaration : Declaration { struct StandardDeclaration : Declaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(StandardDeclaration) - StandardDeclaration(SourcePosition p, CallableNode* c, Statement* b) - : Declaration(kKind, p), callable(c), body(b) {} + StandardDeclaration(SourcePosition pos, CallableNode* callable, + Statement* body) + : Declaration(kKind, pos), callable(callable), body(body) {} CallableNode* callable; Statement* body; }; struct GenericDeclaration : Declaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(GenericDeclaration) - GenericDeclaration(SourcePosition p, CallableNode* c, - std::vector<std::string> gp, - base::Optional<Statement*> b = base::nullopt) - : Declaration(kKind, p), - callable(c), - generic_parameters(std::move(gp)), - body(b) {} + GenericDeclaration(SourcePosition pos, CallableNode* callable, + std::vector<std::string> generic_parameters, + base::Optional<Statement*> body = base::nullopt) + : Declaration(kKind, pos), + callable(callable), + generic_parameters(std::move(generic_parameters)), + body(body) {} CallableNode* callable; std::vector<std::string> generic_parameters; base::Optional<Statement*> body; @@ -678,15 +733,16 @@ struct GenericDeclaration : Declaration { struct SpecializationDeclaration : Declaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(SpecializationDeclaration) - SpecializationDeclaration(SourcePosition p, std::string n, bool e, - std::vector<TypeExpression*> gp, ParameterList pl, - TypeExpression* r, LabelAndTypesVector l, - Statement* b) - : Declaration(kKind, p), - name(std::move(n)), - external(e), - generic_parameters(gp), - signature(new CallableNodeSignature{pl, r, l}), + SpecializationDeclaration(SourcePosition pos, std::string name, + std::vector<TypeExpression*> generic_parameters, + ParameterList parameters, + TypeExpression* return_type, + LabelAndTypesVector labels, Statement* b) + : Declaration(kKind, pos), + name(std::move(name)), + external(false), + generic_parameters(generic_parameters), + signature(new CallableNodeSignature{parameters, return_type, labels}), body(b) {} std::string name; bool external; @@ -697,12 +753,12 @@ struct SpecializationDeclaration : Declaration { struct ExternConstDeclaration : Declaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(ExternConstDeclaration) - ExternConstDeclaration(SourcePosition p, std::string n, TypeExpression* t, - std::string l) - : Declaration(kKind, p), - name(std::move(n)), - type(t), - literal(std::move(l)) {} + ExternConstDeclaration(SourcePosition pos, std::string name, + TypeExpression* type, std::string literal) + : Declaration(kKind, pos), + name(std::move(name)), + type(type), + literal(std::move(literal)) {} std::string name; TypeExpression* type; std::string literal; @@ -710,10 +766,13 @@ struct ExternConstDeclaration : Declaration { struct StructDeclaration : Declaration { DEFINE_AST_NODE_LEAF_BOILERPLATE(StructDeclaration) - StructDeclaration(SourcePosition p, std::string n) - : Declaration(kKind, p), name(std::move(n)) {} + StructDeclaration(SourcePosition pos, std::string name, + std::vector<NameAndTypeExpression> fields) + : Declaration(kKind, pos), + name(std::move(name)), + fields(std::move(fields)) {} std::string name; - std::vector<FieldNameAndType> fields; + std::vector<NameAndTypeExpression> fields; }; #define ENUM_ITEM(name) \ |