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 | |
Marco Poletti | c61bcc4 | 2022-04-08 12:54:30 -0700 | [diff] [blame] | 7 | #include "common/check.h" |
Michael Forster | 500b476 | 2022-01-27 12:30:17 +0000 | [diff] [blame] | 8 | #include "rs_bindings_from_cc/importer.h" |
Lukasz Anforowicz | cec7a8a | 2022-04-27 10:24:51 -0700 | [diff] [blame] | 9 | #include "clang/AST/ASTContext.h" |
| 10 | #include "clang/Frontend/CompilerInstance.h" |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 11 | |
Marcel Hlopko | f15e8ce | 2022-04-08 08:46:09 -0700 | [diff] [blame] | 12 | namespace crubit { |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 13 | |
Marcel Hlopko | e936aac | 2021-08-24 20:52:27 +0000 | [diff] [blame] | 14 | void AstConsumer::HandleTranslationUnit(clang::ASTContext& ast_context) { |
Marcel Hlopko | 19f2ebf | 2021-08-18 09:35:05 +0000 | [diff] [blame] | 15 | if (ast_context.getDiagnostics().hasErrorOccurred()) { |
| 16 | // We do not need to process partially incorrect headers, we assume all |
| 17 | // input is valid C++. If there is an error Clang already printed it to |
| 18 | // stderr; the user will be informed about the cause of the failure. |
| 19 | // There is nothing more for us to do here. |
| 20 | return; |
| 21 | } |
Lukasz Anforowicz | 34ad7f7 | 2022-03-17 16:05:28 +0000 | [diff] [blame] | 22 | CRUBIT_CHECK(instance_.hasSema()); |
Michael Forster | a49d2e6 | 2022-01-28 07:26:40 +0000 | [diff] [blame] | 23 | Importer importer(invocation_, ast_context, instance_.getSema()); |
Michael Forster | 500b476 | 2022-01-27 12:30:17 +0000 | [diff] [blame] | 24 | importer.Import(ast_context.getTranslationUnitDecl()); |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Marcel Hlopko | f15e8ce | 2022-04-08 08:46:09 -0700 | [diff] [blame] | 27 | } // namespace crubit |