blob: 34eefaf2466df6437b2fd32dd4e9806218b28448 [file] [log] [blame]
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +00001// 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 Hlopko20f4ce42021-11-02 08:20:00 +00007#include "base/logging.h"
Michael Forster500b4762022-01-27 12:30:17 +00008#include "rs_bindings_from_cc/importer.h"
Marcel Hlopko7aa38a72021-11-11 07:39:51 +00009#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 Hlopkoe8f1c4e2021-07-28 18:12:49 +000012#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 Hlopko20f4ce42021-11-02 08:20:00 +000014#include "third_party/llvm/llvm-project/clang/include/clang/Frontend/CompilerInstance.h"
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000015
16namespace rs_bindings_from_cc {
17
Marcel Hlopkoe936aac2021-08-24 20:52:27 +000018void AstConsumer::HandleTranslationUnit(clang::ASTContext& ast_context) {
Marcel Hlopko19f2ebf2021-08-18 09:35:05 +000019 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 Jeanpierre31e104b2021-10-20 07:27:25 +000026 CHECK(instance_.hasSema());
Marcel Hlopko7aa38a72021-11-11 07:39:51 +000027 CHECK(!public_header_names_.empty());
28 CHECK(!headers_to_targets_.empty());
Michael Forster500b4762022-01-27 12:30:17 +000029 Importer importer(instance_.getSema(), current_target_, public_header_names_,
30 &headers_to_targets_, &ir_, *lifetime_context_);
31 importer.Import(ast_context.getTranslationUnitDecl());
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000032}
33
34} // namespace rs_bindings_from_cc