set_name.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_SET_NAME_H_
  5. #define CARBON_TOOLCHAIN_SEMANTICS_NODES_SET_NAME_H_
  6. #include "common/ostream.h"
  7. #include "llvm/ADT/SmallVector.h"
  8. #include "toolchain/parser/parse_tree.h"
  9. #include "toolchain/semantics/node_kind.h"
  10. namespace Carbon::Semantics {
  11. // Represents `fn name(params...) [-> return_expr] body`.
  12. class SetName {
  13. public:
  14. static constexpr NodeKind Kind = NodeKind::SetName;
  15. SetName(ParseTree::Node node, llvm::StringRef name, int32_t target_id)
  16. : node_(node), name_(name), target_id_(target_id) {}
  17. void Print(llvm::raw_ostream& out) const {
  18. out << "SetName(`" << name_ << "`, %" << target_id_ << ")";
  19. }
  20. auto node() const -> ParseTree::Node { return node_; }
  21. auto name() const -> llvm::StringRef { return name_; }
  22. auto target_id() const -> int32_t { return target_id_; }
  23. private:
  24. // The name node.
  25. ParseTree::Node node_;
  26. // The name to assign.
  27. llvm::StringRef name_;
  28. // The ID being named.
  29. int32_t target_id_;
  30. };
  31. } // namespace Carbon::Semantics
  32. #endif // CARBON_TOOLCHAIN_SEMANTICS_NODES_SET_NAME_H_