infix_operator.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_SEMANTICS_NODES_INFIX_OPERATOR_H_
  5. #define CARBON_TOOLCHAIN_SEMANTICS_NODES_INFIX_OPERATOR_H_
  6. #include "common/ostream.h"
  7. #include "toolchain/parser/parse_tree.h"
  8. #include "toolchain/semantics/meta_node.h"
  9. namespace Carbon::Semantics {
  10. // Represents an infix operator, such as `+` in `1 + 2`.
  11. class InfixOperator {
  12. public:
  13. static constexpr ExpressionKind MetaNodeKind = ExpressionKind::InfixOperator;
  14. explicit InfixOperator(ParseTree::Node node, Expression lhs, Expression rhs)
  15. : node_(node), lhs_(lhs), rhs_(rhs) {}
  16. auto node() const -> ParseTree::Node { return node_; }
  17. auto lhs() const -> Expression { return lhs_; }
  18. auto rhs() const -> Expression { return rhs_; }
  19. private:
  20. ParseTree::Node node_;
  21. Expression lhs_;
  22. Expression rhs_;
  23. };
  24. } // namespace Carbon::Semantics
  25. #endif // CARBON_TOOLCHAIN_SEMANTICS_NODES_INFIX_OPERATOR_H_