meta_node_block.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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_META_NODE_BLOCK_H_
  5. #define CARBON_TOOLCHAIN_SEMANTICS_META_NODE_BLOCK_H_
  6. #include "llvm/ADT/ArrayRef.h"
  7. #include "llvm/ADT/SmallVector.h"
  8. #include "llvm/ADT/StringMap.h"
  9. #include "toolchain/semantics/meta_node.h"
  10. namespace Carbon::Semantics {
  11. // The standard structure for declaration and statement blocks.
  12. template <typename MetaNodeT>
  13. struct MetaNodeBlock {
  14. public:
  15. MetaNodeBlock(llvm::SmallVector<MetaNodeT, 0> nodes,
  16. llvm::StringMap<MetaNodeT> name_lookup)
  17. : nodes_(std::move(nodes)), name_lookup_(std::move(name_lookup)) {}
  18. auto nodes() const -> llvm::ArrayRef<MetaNodeT> { return nodes_; }
  19. auto name_lookup() const -> const llvm::StringMap<MetaNodeT>& {
  20. return name_lookup_;
  21. }
  22. protected:
  23. llvm::SmallVector<MetaNodeT, 0> nodes_;
  24. llvm::StringMap<MetaNodeT> name_lookup_;
  25. };
  26. using DeclarationBlock = MetaNodeBlock<Declaration>;
  27. using StatementBlock = MetaNodeBlock<Statement>;
  28. } // namespace Carbon::Semantics
  29. #endif // CARBON_TOOLCHAIN_SEMANTICS_META_NODE_BLOCK_H_