prelude.cpp 1010 B

1234567891011121314151617181920212223242526
  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 "explorer/syntax/prelude.h"
  5. #include "explorer/syntax/parse.h"
  6. namespace Carbon {
  7. // Adds the Carbon prelude to `declarations`.
  8. void AddPrelude(std::string_view prelude_file_name, Nonnull<Arena*> arena,
  9. std::vector<Nonnull<Declaration*>>* declarations) {
  10. ErrorOr<AST> parse_result = Parse(arena, prelude_file_name, false);
  11. if (!parse_result.ok()) {
  12. // Try again with tracing, to help diagnose the problem.
  13. ErrorOr<AST> trace_parse_result = Parse(arena, prelude_file_name, true);
  14. CARBON_FATAL() << "Failed to parse prelude:\n"
  15. << trace_parse_result.error();
  16. }
  17. const auto& prelude = *parse_result;
  18. declarations->insert(declarations->begin(), prelude.declarations.begin(),
  19. prelude.declarations.end());
  20. }
  21. } // namespace Carbon