 |
Spicy
|
8 #include <hilti/ast/expression.h> 9 #include <hilti/ast/expressions/member.h> 10 #include <hilti/ast/expressions/resolved-operator.h> 11 #include <hilti/ast/expressions/unresolved-operator.h> 12 #include <hilti/ast/operator.h> 13 #include <hilti/ast/statements/expression.h> 14 #include <hilti/ast/types/doc-only.h> 15 #include <hilti/ast/types/operand-list.h> 18 #define __BEGIN_OPERATOR_CUSTOM(ns, op, cls) \ 21 class cls : public hilti::expression::ResolvedOperatorBase { \ 23 using hilti::expression::ResolvedOperatorBase::ResolvedOperatorBase; \ 26 struct Operator : public hilti::trait::isOperator { \ 27 static ::hilti::operator_::Kind kind() { return ::hilti::operator_::Kind::op; } \ 29 hilti::Expression instantiate(const std::vector<hilti::Expression>& operands, const Meta& meta) const; \ 30 std::string docNamespace() const { return #ns; } 33 #define __END_OPERATOR_CUSTOM \ 49 #define BEGIN_OPERATOR(ns, op) __BEGIN_OPERATOR_CUSTOM(ns, op, op) 52 #define END_OPERATOR \ 53 std::vector<hilti::operator_::Operand> operands() const { return signature().args; } \ 55 std::string doc() const { return signature().doc; } \ 57 hilti::Type result(const hilti::node::Range<hilti::Expression>& ops) const { \ 58 return *hilti::operator_::type(signature().result, ops, ops); \ 61 bool isLhs() const { return signature().lhs; } \ 62 hilti::operator_::Priority priority() const { return signature().priority; } \ 64 void validate(const hilti::expression::ResolvedOperator& , hilti::operator_::position_t ) const {} \ 75 #define BEGIN_OPERATOR_CUSTOM(ns, op) __BEGIN_OPERATOR_CUSTOM(ns, op, op) 81 #define END_OPERATOR_CUSTOM __END_OPERATOR_CUSTOM 92 #define BEGIN_OPERATOR_CUSTOM_x(ns, cls, op) __BEGIN_OPERATOR_CUSTOM(ns, op, cls) 98 #define END_OPERATOR_CUSTOM_x __END_OPERATOR_CUSTOM 104 #define STANDARD_OPERATOR_1(ns, op, result_, ty_op1, doc_) \ 105 BEGIN_OPERATOR(ns, op) \ 106 auto signature() const { \ 107 return hilti::operator_::Signature{.result = result_, \ 110 {.id = "op", .type = ty_op1}, \ 119 #define STANDARD_OPERATOR_1x(ns, cls, op, result_, ty_op1, doc_) \ 120 __BEGIN_OPERATOR_CUSTOM(ns, op, cls) \ 121 auto signature() const { \ 122 return hilti::operator_::Signature{.result = result_, \ 125 {.id = "op", .type = ty_op1}, \ 134 #define STANDARD_OPERATOR_2(ns, op, result_, ty_op1, ty_op2, doc_) \ 135 BEGIN_OPERATOR(ns, op) \ 136 auto signature() const { \ 137 return hilti::operator_::Signature{.result = result_, \ 138 .args = {{.id = "op0", .type = ty_op1}, {.id = "op1", .type = ty_op2}}, \ 146 #define STANDARD_OPERATOR_2x(ns, cls, op, result_, ty_op1, ty_op2, doc_) \ 147 __BEGIN_OPERATOR_CUSTOM(ns, op, cls) \ 148 auto signature() const { \ 149 return hilti::operator_::Signature{.result = result_, \ 150 .args = {{.id = "op0", .type = ty_op1}, {.id = "op1", .type = ty_op2}}, \ 158 #define STANDARD_OPERATOR_2x_low_prio(ns, cls, op, result_, ty_op1, ty_op2, doc_) \ 159 __BEGIN_OPERATOR_CUSTOM(ns, op, cls) \ 160 auto signature() const { \ 161 return hilti::operator_::Signature{.priority = operator_::Priority::Low, \ 163 .args = {{.id = "op0", .type = ty_op1}, {.id = "op1", .type = ty_op2}}, \ 171 #define STANDARD_OPERATOR_2x_lhs(ns, cls, op, result_, ty_op1, ty_op2, doc_) \ 172 __BEGIN_OPERATOR_CUSTOM(ns, op, cls) \ 173 auto signature() const { \ 174 return hilti::operator_::Signature{.lhs = true, \ 176 .args = {{.id = "op0", .type = ty_op1}, {.id = "op1", .type = ty_op2}}, \ 184 #define STANDARD_OPERATOR_3(ns, op, result_, ty_op1, ty_op2, ty_op3, doc_) \ 185 BEGIN_OPERATOR(ns, op) \ 186 auto signature() const { \ 187 return hilti::operator_::Signature{.result = result_, \ 188 .args = {{.id = "op0", .type = ty_op1}, \ 189 {.id = "op1", .type = ty_op2}, \ 190 {.id = "op2", .type = ty_op3}}, \ 202 #define BEGIN_METHOD(ns, method) __BEGIN_OPERATOR_CUSTOM(ns, MemberCall, method) 211 #define BEGIN_METHOD_CUSTOM_RESULT(ns, method) __BEGIN_OPERATOR_CUSTOM(ns, MemberCall, method) 214 #define __END_METHOD \ 215 std::vector<hilti::operator_::Operand> operands() const { \ 216 return {{.type = signature().self}, \ 217 {.type = hilti::type::Member(signature().id)}, \ 218 {.type = hilti::type::OperandList(signature().args)}}; \ 221 std::string doc() const { return signature().doc; } 227 hilti::Type result(const hilti::node::Range<hilti::Expression>& ops) const { \ 228 return *hilti::operator_::type(signature().result, hilti::node::Range(ops), ops); \ 231 bool isLhs() const { return false; } \ 232 hilti::operator_::Priority priority() const { return signature().priority; } \ 234 void validate(const hilti::expression::ResolvedOperator& , hilti::operator_::position_t ) const {} \ 236 __END_OPERATOR_CUSTOM 242 #define END_METHOD_CUSTOM_RESULT \ 244 __END_OPERATOR_CUSTOM 252 #define BEGIN_CTOR(ns, cls) __BEGIN_OPERATOR_CUSTOM(ns, Call, cls) 255 std::vector<hilti::operator_::Operand> operands() const { \ 256 return {{.type = hilti::type::Type_(ctorType())}, {.type = hilti::type::OperandList(signature().args)}}; \ 259 std::string doc() const { return signature().doc; } \ 261 hilti::Type result(const hilti::node::Range<hilti::Expression>& ops) const { \ 263 return ops[0].type().as<hilti::type::Type_>().typeValue(); \ 268 bool isLhs() const { return false; } \ 269 hilti::operator_::Priority priority() const { return signature().priority; } \ 271 void validate(const hilti::expression::ResolvedOperator& , hilti::operator_::position_t ) const {} \ 273 __END_OPERATOR_CUSTOM 279 #define OPERATOR_DECLARE_ONLY(ns, cls)