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