Marco Poletti | b5239c9 | 2022-05-11 09:46:05 -0700 | [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 | #ifndef CRUBIT_MIGRATOR_RS_FROM_CC_CONVERTER_H_ |
| 6 | #define CRUBIT_MIGRATOR_RS_FROM_CC_CONVERTER_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <optional> |
| 10 | #include <set> |
| 11 | #include <string> |
| 12 | #include <utility> |
| 13 | #include <variant> |
| 14 | #include <vector> |
| 15 | |
| 16 | #include "absl/container/flat_hash_map.h" |
| 17 | #include "absl/container/flat_hash_set.h" |
| 18 | #include "absl/status/statusor.h" |
| 19 | #include "absl/types/span.h" |
| 20 | #include "lifetime_annotations/lifetime_annotations.h" |
| 21 | #include "clang/AST/ASTContext.h" |
| 22 | #include "clang/AST/Decl.h" |
| 23 | #include "clang/AST/Mangle.h" |
| 24 | #include "clang/AST/RawCommentList.h" |
| 25 | #include "clang/AST/Type.h" |
| 26 | #include "clang/Basic/SourceLocation.h" |
| 27 | #include "clang/Basic/Specifiers.h" |
| 28 | #include "clang/Sema/Sema.h" |
| 29 | |
| 30 | namespace crubit_rs_from_cc { |
| 31 | |
| 32 | // Visits the C++ AST and generates the corresponding Rust code in the |
| 33 | // Invocation object. |
| 34 | class Converter { |
| 35 | public: |
| 36 | // Top-level parameters as well as return value of a migrator invocation. |
| 37 | class Invocation { |
| 38 | public: |
| 39 | std::string rs_code_; |
| 40 | }; |
| 41 | |
| 42 | explicit Converter(Invocation& invocation, clang::ASTContext& ctx) |
| 43 | : result_(invocation.rs_code_), ctx_(ctx) {} |
| 44 | |
Marco Poletti | 8e21c12 | 2022-05-24 09:40:58 -0700 | [diff] [blame] | 45 | void Convert(const clang::TranslationUnitDecl* translation_unit); |
Marco Poletti | b5239c9 | 2022-05-11 09:46:05 -0700 | [diff] [blame] | 46 | |
| 47 | private: |
Marco Poletti | 8e21c12 | 2022-05-24 09:40:58 -0700 | [diff] [blame] | 48 | void Convert(const clang::Decl* decl); |
| 49 | |
| 50 | void ConvertUnhandled(const clang::Decl* decl); |
| 51 | |
Marco Poletti | b5239c9 | 2022-05-11 09:46:05 -0700 | [diff] [blame] | 52 | // The main output of the conversion process (Rust code). |
| 53 | std::string& result_; |
| 54 | |
| 55 | clang::ASTContext& ctx_; |
| 56 | }; // class Converter |
| 57 | |
| 58 | } // namespace crubit_rs_from_cc |
| 59 | |
| 60 | #endif // CRUBIT_MIGRATOR_RS_FROM_CC_CONVERTER_H_ |