semantics_ir.cpp 944 B

12345678910111213141516171819202122232425262728
  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. #include "toolchain/semantics/semantics_ir.h"
  5. #include "common/check.h"
  6. #include "llvm/Support/FormatVariadic.h"
  7. #include "toolchain/lexer/tokenized_buffer.h"
  8. namespace Carbon {
  9. void SemanticsIR::Block::Add(llvm::StringRef name, Node named_entity) {
  10. ordering_.push_back(named_entity);
  11. name_lookup_.insert({name, named_entity});
  12. }
  13. auto SemanticsIR::AddFunction(Block& block, ParseTree::Node decl_node,
  14. ParseTree::Node name_node)
  15. -> Semantics::Function& {
  16. int32_t index = functions_.size();
  17. functions_.push_back(Semantics::Function(decl_node, name_node));
  18. block.Add(parse_tree_->GetNodeText(name_node),
  19. Node(Node::Kind::Function, index));
  20. return functions_[index];
  21. }
  22. } // namespace Carbon