check.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_CHECK_CHECK_H_
  5. #define CARBON_TOOLCHAIN_CHECK_CHECK_H_
  6. #include "clang/Frontend/CompilerInvocation.h"
  7. #include "common/ostream.h"
  8. #include "toolchain/base/shared_value_stores.h"
  9. #include "toolchain/base/timings.h"
  10. #include "toolchain/check/diagnostic_emitter.h"
  11. #include "toolchain/diagnostics/diagnostic_emitter.h"
  12. #include "toolchain/parse/tree_and_subtrees.h"
  13. #include "toolchain/sem_ir/file.h"
  14. #include "toolchain/sem_ir/ids.h"
  15. namespace Carbon::Check {
  16. // Checking information that's tracked per file. All members are caller-owned.
  17. // Other than `timings`, members must be non-null.
  18. struct Unit {
  19. Diagnostics::Consumer* consumer;
  20. SharedValueStores* value_stores;
  21. // The `timings` may be null if nothing is to be recorded.
  22. Timings* timings;
  23. // The unit's SemIR, provided as empty and filled in by CheckParseTrees.
  24. SemIR::File* sem_ir;
  25. // Storage for the unit's Clang AST. The unique_ptr should start empty, and
  26. // can be assigned as part of checking.
  27. std::unique_ptr<clang::ASTUnit>* clang_ast_unit;
  28. };
  29. struct CheckParseTreesOptions {
  30. // Options must be set individually, not through initialization.
  31. explicit CheckParseTreesOptions() = default;
  32. // Whether to import the prelude.
  33. bool prelude_import = false;
  34. // Whether to generate standard `impl`s for types, such as `Core.Destroy`.
  35. // This only controls generation of the `impl`; code which expects the `impl`
  36. // is expected to fail.
  37. bool gen_implicit_type_impls = true;
  38. // If set, enables verbose output.
  39. llvm::raw_ostream* vlog_stream = nullptr;
  40. // Whether fuzzing is being run. Used to disable features we don't want to
  41. // fuzz.
  42. bool fuzzing = false;
  43. // Whether to include each unit in dumps. This is required when dumping
  44. // (either of `dump_stream` or `raw_dump_stream`), and must have entries based
  45. // on CheckIRId.
  46. const FixedSizeValueStore<SemIR::CheckIRId, bool>* include_in_dumps = nullptr;
  47. // If set, SemIR will be dumped to this.
  48. llvm::raw_ostream* dump_stream = nullptr;
  49. // If set, C++ AST will be dumped to this.
  50. llvm::raw_ostream* dump_cpp_ast_stream = nullptr;
  51. // When dumping textual SemIR (or printing it to for verbose output), whether
  52. // to use ranges.
  53. enum class DumpSemIRRanges : int8_t {
  54. IfPresent,
  55. Only,
  56. Ignore,
  57. };
  58. DumpSemIRRanges dump_sem_ir_ranges = DumpSemIRRanges::IfPresent;
  59. // If set, raw SemIR will be dumped to this.
  60. llvm::raw_ostream* raw_dump_stream = nullptr;
  61. // When dumping raw SemIR, whether to include builtins.
  62. bool dump_raw_sem_ir_builtins = false;
  63. };
  64. // Checks a group of parse trees. This will use imports to decide the order of
  65. // checking.
  66. //
  67. // `units` will only contain units which should be checked, and is not indexed
  68. // by `CheckIRId`.
  69. auto CheckParseTrees(
  70. llvm::MutableArrayRef<Unit> units,
  71. const Parse::GetTreeAndSubtreesStore& tree_and_subtrees_getters,
  72. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
  73. const CheckParseTreesOptions& options,
  74. std::shared_ptr<clang::CompilerInvocation> clang_invocation) -> void;
  75. } // namespace Carbon::Check
  76. #endif // CARBON_TOOLCHAIN_CHECK_CHECK_H_