cel_cxx_ffi/common/
ast.rs1use crate::common::Type;
2use crate::protobuf::{Arena, DescriptorPool};
3
4#[cxx::bridge]
5mod ffi {
6 #[namespace = "google::protobuf"]
7 unsafe extern "C++" {
8 include!(<google/protobuf/descriptor.h>);
9
10 type Arena = super::Arena;
11 type DescriptorPool = super::DescriptorPool;
12 }
13
14 #[namespace = "cel"]
15 unsafe extern "C++" {
16 include!(<common/type.h>);
17 type Type<'a> = super::Type<'a>;
18
19 include!(<common/ast.h>);
20
21 type Ast;
22 #[rust_name = "is_checked"]
23 fn IsChecked(self: &Ast) -> bool;
24 }
25
26 #[namespace = "cel::ast_internal"]
27 unsafe extern "C++" {
28 include!(<common/ast/ast_impl.h>);
29
30 type AstImpl;
31 #[rust_name = "return_type"]
32 fn GetReturnType(self: &AstImpl) -> &AstType;
33
34 #[rust_name = "AstType"]
35 type Type;
36 }
37
38 #[namespace = "rust::cel_cxx"]
39 unsafe extern "C++" {
40 include!(<cel-cxx-ffi/include/ast.h>);
41
42 fn AstImpl_cast_from_public_ast(ast: &Ast) -> &AstImpl;
43 fn AstType_to_type<'a>(
44 ast_type: &AstType,
45 descriptor_pool: &DescriptorPool,
46 arena: &'a Arena,
47 ) -> Type<'a>;
48 }
49
50 impl UniquePtr<Ast> {}
51}
52
53pub use ffi::Ast;
54unsafe impl Send for Ast {}
55unsafe impl Sync for Ast {}
56
57impl Ast {
58 pub fn return_type<'a>(&self, descriptor_pool: &DescriptorPool, arena: &'a Arena) -> Type<'a> {
59 let ast_impl = ffi::AstImpl_cast_from_public_ast(self);
60 let ast_type = ast_impl.return_type();
61 ffi::AstType_to_type(ast_type, descriptor_pool, arena)
62 }
63}