Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 1 | // Part of the Crubit 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 | |
| 5 | #include "rs_bindings_from_cc/ast_consumer.h" |
| 6 | |
Marcel Hlopko | 20f4ce4 | 2021-11-02 08:20:00 +0000 | [diff] [blame] | 7 | #include "base/logging.h" |
Michael Forster | 500b476 | 2022-01-27 12:30:17 +0000 | [diff] [blame^] | 8 | #include "rs_bindings_from_cc/importer.h" |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 9 | #include "rs_bindings_from_cc/ir.h" |
| 10 | #include "third_party/absl/container/flat_hash_map.h" |
| 11 | #include "third_party/absl/types/span.h" |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 12 | #include "third_party/llvm/llvm-project/clang/include/clang/AST/ASTContext.h" |
| 13 | #include "third_party/llvm/llvm-project/clang/include/clang/AST/Decl.h" |
Marcel Hlopko | 20f4ce4 | 2021-11-02 08:20:00 +0000 | [diff] [blame] | 14 | #include "third_party/llvm/llvm-project/clang/include/clang/Frontend/CompilerInstance.h" |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 15 | |
| 16 | namespace rs_bindings_from_cc { |
| 17 | |
Marcel Hlopko | e936aac | 2021-08-24 20:52:27 +0000 | [diff] [blame] | 18 | void AstConsumer::HandleTranslationUnit(clang::ASTContext& ast_context) { |
Marcel Hlopko | 19f2ebf | 2021-08-18 09:35:05 +0000 | [diff] [blame] | 19 | if (ast_context.getDiagnostics().hasErrorOccurred()) { |
| 20 | // We do not need to process partially incorrect headers, we assume all |
| 21 | // input is valid C++. If there is an error Clang already printed it to |
| 22 | // stderr; the user will be informed about the cause of the failure. |
| 23 | // There is nothing more for us to do here. |
| 24 | return; |
| 25 | } |
Devin Jeanpierre | 31e104b | 2021-10-20 07:27:25 +0000 | [diff] [blame] | 26 | CHECK(instance_.hasSema()); |
Marcel Hlopko | 7aa38a7 | 2021-11-11 07:39:51 +0000 | [diff] [blame] | 27 | CHECK(!public_header_names_.empty()); |
| 28 | CHECK(!headers_to_targets_.empty()); |
Michael Forster | 500b476 | 2022-01-27 12:30:17 +0000 | [diff] [blame^] | 29 | Importer importer(instance_.getSema(), current_target_, public_header_names_, |
| 30 | &headers_to_targets_, &ir_, *lifetime_context_); |
| 31 | importer.Import(ast_context.getTranslationUnitDecl()); |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | } // namespace rs_bindings_from_cc |