blob: 4e9808a4268b41edf7c0867fb5ea76090fb8eb22 [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
Dmitri Gribenkoe4e77d02022-03-17 14:09:39 +00005#ifndef CRUBIT_RS_BINDINGS_FROM_CC_AST_CONSUMER_H_
6#define CRUBIT_RS_BINDINGS_FROM_CC_AST_CONSUMER_H_
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +00007
Michael Forster974bf152022-05-12 00:40:59 -07008#include "rs_bindings_from_cc/decl_importer.h"
Lukasz Anforowiczcec7a8a2022-04-27 10:24:51 -07009#include "clang/AST/ASTConsumer.h"
10#include "clang/AST/ASTContext.h"
11#include "clang/Frontend/CompilerInstance.h"
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000012
Marcel Hlopkof15e8ce2022-04-08 08:46:09 -070013namespace crubit {
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000014
Michael Forstera49d2e62022-01-28 07:26:40 +000015// Consumes the Clang AST created from the invocation's entry header and
16// generates the intermediate representation (`IR`) in the invocation object.
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000017class AstConsumer : public clang::ASTConsumer {
18 public:
Michael Forstera49d2e62022-01-28 07:26:40 +000019 explicit AstConsumer(clang::CompilerInstance& instance,
Michael Forster64217b42022-04-22 05:48:54 -070020 Invocation& invocation)
Michael Forstera49d2e62022-01-28 07:26:40 +000021 : instance_(instance), invocation_(invocation) {}
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000022
Marcel Hlopkoe936aac2021-08-24 20:52:27 +000023 void HandleTranslationUnit(clang::ASTContext& context) override;
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000024
25 private:
Devin Jeanpierre31e104b2021-10-20 07:27:25 +000026 clang::CompilerInstance& instance_;
Michael Forster64217b42022-04-22 05:48:54 -070027 Invocation& invocation_;
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000028}; // class AstConsumer
29
Marcel Hlopkof15e8ce2022-04-08 08:46:09 -070030} // namespace crubit
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000031
Dmitri Gribenkoe4e77d02022-03-17 14:09:39 +000032#endif // CRUBIT_RS_BINDINGS_FROM_CC_AST_CONSUMER_H_