blob: d55eb802deed56dff35645540c210425e74ce35f [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
Marco Polettic61bcc42022-04-08 12:54:30 -07007#include "common/check.h"
Michael Forster500b4762022-01-27 12:30:17 +00008#include "rs_bindings_from_cc/importer.h"
Lukasz Anforowiczcec7a8a2022-04-27 10:24:51 -07009#include "clang/AST/ASTContext.h"
10#include "clang/Frontend/CompilerInstance.h"
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000011
Marcel Hlopkof15e8ce2022-04-08 08:46:09 -070012namespace crubit {
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000013
Marcel Hlopkoe936aac2021-08-24 20:52:27 +000014void AstConsumer::HandleTranslationUnit(clang::ASTContext& ast_context) {
Marcel Hlopko19f2ebf2021-08-18 09:35:05 +000015 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 Anforowicz34ad7f72022-03-17 16:05:28 +000022 CRUBIT_CHECK(instance_.hasSema());
Michael Forstera49d2e62022-01-28 07:26:40 +000023 Importer importer(invocation_, ast_context, instance_.getSema());
Michael Forster500b4762022-01-27 12:30:17 +000024 importer.Import(ast_context.getTranslationUnitDecl());
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000025}
26
Marcel Hlopkof15e8ce2022-04-08 08:46:09 -070027} // namespace crubit