semantics_ir.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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_SEMANTICS_IR_H_
  5. #define CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_IR_H_
  6. #include "llvm/ADT/ArrayRef.h"
  7. #include "llvm/ADT/SmallVector.h"
  8. #include "toolchain/parser/parse_tree.h"
  9. #include "toolchain/semantics/node_store.h"
  10. namespace Carbon::Testing {
  11. class SemanticsIRForTest;
  12. } // namespace Carbon::Testing
  13. namespace Carbon {
  14. // Provides semantic analysis on a ParseTree.
  15. class SemanticsIR {
  16. public:
  17. // File-level declarations.
  18. auto root_block() const -> llvm::ArrayRef<Semantics::NodeRef> {
  19. return root_block_;
  20. }
  21. // Prints the node information.
  22. auto Print(llvm::raw_ostream& out, Semantics::NodeRef node_ref) const -> void;
  23. private:
  24. friend class SemanticsIRFactory;
  25. friend class Testing::SemanticsIRForTest;
  26. explicit SemanticsIR(const ParseTree& parse_tree)
  27. : parse_tree_(&parse_tree) {}
  28. Semantics::NodeStore nodes_;
  29. llvm::SmallVector<Semantics::NodeRef, 0> root_block_;
  30. const ParseTree* parse_tree_;
  31. };
  32. } // namespace Carbon
  33. #endif // CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_IR_H_