Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rs_bindings_from_cc/generate_bindings/generate_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ fn rs_type_kinds_for_func(
if i == 0 && func.is_instance_method() {
// `param_type` is a `this` pointer, but its semantics are really that of
// references. That is, `this` in these operators is non-null.
let CcTypeVariant::Pointer(PointerType { kind, lifetime, pointee_type: _ }) =
let CcTypeVariant::Pointer(PointerType { kind, lifetime, pointee_type: _, is_cref: _}) =
&mut param_type.variant
else {
panic!(
Expand Down
47 changes: 25 additions & 22 deletions rs_bindings_from_cc/ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,32 @@ llvm::json::Value CcType::ToJson() const {
return llvm::json::Object{{"Primitive", primitive.spelling}};
},
[&](CcType::PointerType pointer) {
auto pointer_json = llvm::json::Object{
{
"kind",
[&]() -> llvm::json::Value {
switch (pointer.kind) {
case PointerTypeKind::kLValueRef:
return "LValueRef";
case PointerTypeKind::kRValueRef:
return "RValueRef";
case PointerTypeKind::kNullable:
return "Nullable";
case PointerTypeKind::kNonNull:
return "NonNull";
case PointerTypeKind::kOwned:
return "Owned";
}
}(),
},
{"lifetime", pointer.lifetime},
{"pointee_type", *pointer.pointee_type},
};
if (pointer.is_cref) {
pointer_json.insert({"is_cref", pointer.is_cref});
}
return llvm::json::Object{
{"Pointer",
llvm::json::Object{
{
"kind",
[&]() -> llvm::json::Value {
switch (pointer.kind) {
case PointerTypeKind::kLValueRef:
return "LValueRef";
case PointerTypeKind::kRValueRef:
return "RValueRef";
case PointerTypeKind::kNullable:
return "Nullable";
case PointerTypeKind::kNonNull:
return "NonNull";
case PointerTypeKind::kOwned:
return "Owned";
}
}(),
},
{"lifetime", pointer.lifetime},
{"pointee_type", *pointer.pointee_type},
}},
{"Pointer", std::move(pointer_json)},
};
},
[&](const CcType::FuncPointer& func_value) {
Expand Down
2 changes: 2 additions & 0 deletions rs_bindings_from_cc/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ struct CcType {
std::optional<LifetimeId> lifetime;

std::shared_ptr<CcType> pointee_type;

bool is_cref = false;
};

struct Primitive {
Expand Down
5 changes: 5 additions & 0 deletions rs_bindings_from_cc/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ pub struct PointerType {
pub kind: PointerTypeKind,
pub lifetime: Option<LifetimeId>,
pub pointee_type: Rc<CcType>,
/// Lower as CRef or CMut depending on constness. Depending on the strategy we use, various
/// PointerTypeKinds may be `is_cref`. Note that we don't expect this to be produced from
/// the Clang side.
#[serde(default)]
pub is_cref: bool,
}

/// Generates an enum type that implements `Deserialize`, which parses the stringified contents of
Expand Down
7 changes: 7 additions & 0 deletions rs_bindings_from_cc/ir_from_cc_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4317,6 +4317,7 @@ fn test_assumed_lifetimes_function() {
unknown_attr: "",
explicit_lifetimes: [],
},
is_cref: false,
}),
is_const: false,
unknown_attr: "",
Expand Down Expand Up @@ -4357,6 +4358,7 @@ fn test_assumed_lifetimes_function_with_explicit_binding() {
unknown_attr: "",
explicit_lifetimes: [],
},
is_cref: false,
}),
is_const: false,
unknown_attr: "",
Expand Down Expand Up @@ -4402,6 +4404,7 @@ fn test_assumed_lifetimes_function_with_explicit_bindings() {
unknown_attr: "",
explicit_lifetimes: [],
},
is_cref: false,
}),
is_const: false,
unknown_attr: "",
Expand Down Expand Up @@ -4445,6 +4448,7 @@ fn test_assumed_lifetimes_lifetimebound_free_function() {
unknown_attr: "",
explicit_lifetimes: [],
},
is_cref: false,
}),
is_const: false,
unknown_attr: "",
Expand All @@ -4466,6 +4470,7 @@ fn test_assumed_lifetimes_lifetimebound_free_function() {
unknown_attr: "",
explicit_lifetimes: [],
},
is_cref: false,
}),
is_const: false,
unknown_attr: "",
Expand Down Expand Up @@ -4508,6 +4513,7 @@ fn test_assumed_lifetimes_lifetime_capture_by_free_function() {
unknown_attr: "",
explicit_lifetimes: [],
},
is_cref: false,
}),
is_const: false,
unknown_attr: "",
Expand All @@ -4529,6 +4535,7 @@ fn test_assumed_lifetimes_lifetime_capture_by_free_function() {
unknown_attr: "",
explicit_lifetimes: [],
},
is_cref: false,
}),
is_const: false,
unknown_attr: "",
Expand Down
Loading