Rename `type_params` to `type_args` in RsType and CcType.
PiperOrigin-RevId: 413616629
diff --git a/rs_bindings_from_cc/ast_visitor_test.cc b/rs_bindings_from_cc/ast_visitor_test.cc
index a64424e..bbf31fc 100644
--- a/rs_bindings_from_cc/ast_visitor_test.cc
+++ b/rs_bindings_from_cc/ast_visitor_test.cc
@@ -137,17 +137,17 @@
return testing::Field("rs_type", &MappedType::rs_type, AllOf(matchers...));
}
-// Matches an RsType that has type parameters matching `matchers`.
+// Matches an RsType that has type arguments matching `matchers`.
template <typename... Args>
auto RsTypeParamsAre(const Args&... matchers) {
- return testing::Field("type_params", &RsType::type_params,
+ return testing::Field("type_args", &RsType::type_args,
ElementsAre(matchers...));
}
-// Matches a CcType that has type parameters matching `matchers`.
+// Matches a CcType that has type arguments matching `matchers`.
template <typename... Args>
auto CcTypeParamsAre(const Args&... matchers) {
- return testing::Field("type_params", &CcType::type_params,
+ return testing::Field("type_args", &CcType::type_args,
ElementsAre(matchers...));
}
@@ -196,7 +196,7 @@
RsTypeIs(RsPointsTo(IsRsInt())));
}
-// Matches a MappedType for cc and rs types with no type parameters.
+// Matches a MappedType for cc and rs types with no type arguments.
auto IsSimpleType(absl::string_view rs_name, absl::string_view cc_name) {
return AllOf(CcTypeIs(NameIs(cc_name), CcTypeParamsAre()),
RsTypeIs(NameIs(rs_name), RsTypeParamsAre()));
diff --git a/rs_bindings_from_cc/ir.cc b/rs_bindings_from_cc/ir.cc
index 9f02339..f1a57dc 100644
--- a/rs_bindings_from_cc/ir.cc
+++ b/rs_bindings_from_cc/ir.cc
@@ -46,7 +46,7 @@
} else {
result["name"] = name;
}
- result["type_params"] = VectorToJson(type_params);
+ result["type_args"] = VectorToJson(type_args);
return result;
}
@@ -60,7 +60,7 @@
result["name"] = name;
}
result["is_const"] = is_const;
- result["type_params"] = VectorToJson(type_params);
+ result["type_args"] = VectorToJson(type_args);
return result;
}
diff --git a/rs_bindings_from_cc/ir.h b/rs_bindings_from_cc/ir.h
index 30645e0..a21367d 100644
--- a/rs_bindings_from_cc/ir.h
+++ b/rs_bindings_from_cc/ir.h
@@ -89,11 +89,11 @@
// all the same type in C++.
bool is_const = false;
- // Type parameters for a generic type. Examples:
- // int has no type parameters.
- // int* has a single type parameter, int.
- // tuple<int, float> has two type parameters, int and float.
- std::vector<CcType> type_params = {};
+ // Type arguments for a generic type. Examples:
+ // int has no type arguments.
+ // int* has a single type argument, int.
+ // tuple<int, float> has two type arguments, int and float.
+ std::vector<CcType> type_args = {};
};
// A Rust type involved in the bindings. It has the knowledge of how the type
@@ -107,11 +107,11 @@
// Id of a decl that this type corresponds to. `nullopt` for primitive types.
std::optional<DeclId> decl_id = std::nullopt;
- // Type parameters for a generic type. Examples:
- // i32 has no type parameters.
- // *mut i32 has a single type parameter, i32.
- // (i32, f32) has two type parameters, i32 and f32.
- std::vector<RsType> type_params = {};
+ // Type arguments for a generic type. Examples:
+ // i32 has no type arguments.
+ // *mut i32 has a single type argument, i32.
+ // (i32, f32) has two type arguments, i32 and f32.
+ std::vector<RsType> type_args = {};
};
inline std::ostream& operator<<(std::ostream& o, const RsType& type) {
@@ -145,8 +145,8 @@
: internal::kRustPtrMut;
auto pointer_type =
Simple(std::string(rs_name), std::string(internal::kCcPtr));
- pointer_type.rs_type.type_params.push_back(std::move(pointee_type.rs_type));
- pointer_type.cc_type.type_params.push_back(std::move(pointee_type.cc_type));
+ pointer_type.rs_type.type_args.push_back(std::move(pointee_type.rs_type));
+ pointer_type.cc_type.type_args.push_back(std::move(pointee_type.cc_type));
return pointer_type;
}
@@ -156,8 +156,8 @@
: internal::kRustPtrMut;
auto pointer_type =
Simple(std::string(rs_name), std::string(internal::kCcLValueRef));
- pointer_type.rs_type.type_params.push_back(std::move(pointee_type.rs_type));
- pointer_type.cc_type.type_params.push_back(std::move(pointee_type.cc_type));
+ pointer_type.rs_type.type_args.push_back(std::move(pointee_type.rs_type));
+ pointer_type.cc_type.type_args.push_back(std::move(pointee_type.cc_type));
return pointer_type;
}
diff --git a/rs_bindings_from_cc/ir.rs b/rs_bindings_from_cc/ir.rs
index e816d93..3aa69e9 100644
--- a/rs_bindings_from_cc/ir.rs
+++ b/rs_bindings_from_cc/ir.rs
@@ -62,7 +62,7 @@
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize)]
pub struct RsType {
pub name: Option<String>,
- pub type_params: Vec<RsType>,
+ pub type_args: Vec<RsType>,
pub decl_id: Option<DeclId>,
}
@@ -70,7 +70,7 @@
pub struct CcType {
pub name: Option<String>,
pub is_const: bool,
- pub type_params: Vec<CcType>,
+ pub type_args: Vec<CcType>,
pub decl_id: Option<DeclId>,
}
@@ -380,8 +380,8 @@
{
"identifier": {"identifier": "public_int" },
"type": {
- "rs_type": {"name": "i32", "type_params": []},
- "cc_type": {"name": "int", "is_const": false, "type_params": []}
+ "rs_type": {"name": "i32", "type_args": []},
+ "cc_type": {"name": "int", "is_const": false, "type_args": []}
},
"access": "Public",
"offset": 0
@@ -389,8 +389,8 @@
{
"identifier": {"identifier": "protected_int" },
"type": {
- "rs_type": {"name": "i32", "type_params": []},
- "cc_type": {"name": "int", "is_const": false, "type_params": []}
+ "rs_type": {"name": "i32", "type_args": []},
+ "cc_type": {"name": "int", "is_const": false, "type_args": []}
},
"access": "Protected",
"offset": 32
@@ -398,8 +398,8 @@
{
"identifier": {"identifier": "private_int" },
"type": {
- "rs_type": {"name": "i32", "type_params": []},
- "cc_type": {"name": "int", "is_const": false, "type_params": []}
+ "rs_type": {"name": "i32", "type_args": []},
+ "cc_type": {"name": "int", "is_const": false, "type_args": []}
},
"access": "Private",
"offset": 64
@@ -440,13 +440,13 @@
type_: MappedType {
rs_type: RsType {
name: "i32".to_string().into(),
- type_params: vec![],
+ type_args: vec![],
decl_id: None,
},
cc_type: CcType {
name: "int".to_string().into(),
is_const: false,
- type_params: vec![],
+ type_args: vec![],
decl_id: None,
},
},
@@ -459,13 +459,13 @@
type_: MappedType {
rs_type: RsType {
name: "i32".to_string().into(),
- type_params: vec![],
+ type_args: vec![],
decl_id: None,
},
cc_type: CcType {
name: "int".to_string().into(),
is_const: false,
- type_params: vec![],
+ type_args: vec![],
decl_id: None,
},
},
@@ -478,13 +478,13 @@
type_: MappedType {
rs_type: RsType {
name: "i32".to_string().into(),
- type_params: vec![],
+ type_args: vec![],
decl_id: None,
},
cc_type: CcType {
name: "int".to_string().into(),
is_const: false,
- type_params: vec![],
+ type_args: vec![],
decl_id: None,
},
},
@@ -526,14 +526,14 @@
{
"identifier": {"identifier": "ptr" },
"type": {
- "rs_type": {"name": "*mut", "type_params": [
- {"name": "SomeStruct", "type_params": [], "decl_id": 42}
+ "rs_type": {"name": "*mut", "type_args": [
+ {"name": "SomeStruct", "type_args": [], "decl_id": 42}
]},
- "cc_type": { "name": "*", "is_const": false, "type_params": [
+ "cc_type": { "name": "*", "is_const": false, "type_args": [
{
"name": "SomeStruct",
"is_const": false,
- "type_params": [],
+ "type_args": [],
"decl_id": 42
}
]}
@@ -577,9 +577,9 @@
rs_type: RsType {
name: "*mut".to_string().into(),
decl_id: None,
- type_params: vec![RsType {
+ type_args: vec![RsType {
name: "SomeStruct".to_string().into(),
- type_params: vec![],
+ type_args: vec![],
decl_id: Some(DeclId(42)),
}],
},
@@ -587,10 +587,10 @@
name: "*".to_string().into(),
is_const: false,
decl_id: None,
- type_params: vec![CcType {
+ type_args: vec![CcType {
name: "SomeStruct".to_string().into(),
is_const: false,
- type_params: vec![],
+ type_args: vec![],
decl_id: Some(DeclId(42)),
}],
},
diff --git a/rs_bindings_from_cc/ir_test.cc b/rs_bindings_from_cc/ir_test.cc
index 64efd5a..43174c7 100644
--- a/rs_bindings_from_cc/ir_test.cc
+++ b/rs_bindings_from_cc/ir_test.cc
@@ -19,30 +19,30 @@
nlohmann::json expected = nlohmann::json::parse(R"j({
"rs_type": {
"name": "CompoundRs",
- "type_params": [{"name": "i32", "type_params": []}]
+ "type_args": [{"name": "i32", "type_args": []}]
},
"cc_type": {
"name": "CompoundCc",
"is_const": false,
- "type_params": [
- {"is_const": false, "name": "int", "type_params": []}
+ "type_args": [
+ {"is_const": false, "name": "int", "type_args": []}
]
}
})j");
auto type = MappedType{
- .rs_type = RsType{.name = "CompoundRs", .type_params = {RsType{"i32"}}},
+ .rs_type = RsType{.name = "CompoundRs", .type_args = {RsType{"i32"}}},
.cc_type = CcType{.name = "CompoundCc",
.is_const = false,
- .type_params = {CcType{"int"}}}};
+ .type_args = {CcType{"int"}}}};
EXPECT_EQ(type.ToJson(), expected);
}
TEST(IrTest, TypeWithDeclIdToJson) {
nlohmann::json expected = nlohmann::json::parse(R"j({
- "rs_type": {"type_params": [], "decl_id": 42},
+ "rs_type": {"type_args": [], "decl_id": 42},
"cc_type": {
"is_const": false,
- "type_params": [],
+ "type_args": [],
"decl_id": 43
}
})j");
@@ -65,11 +65,11 @@
{
"identifier": { "identifier": "public_int" },
"type": {
- "rs_type": { "name": "i32", "type_params": [] },
+ "rs_type": { "name": "i32", "type_args": [] },
"cc_type": {
"is_const": false,
"name": "int",
- "type_params": []
+ "type_args": []
}
},
"access": "Public",
@@ -78,11 +78,11 @@
{
"identifier": { "identifier": "protected_int" },
"type": {
- "rs_type": { "name": "i32", "type_params": [] },
+ "rs_type": { "name": "i32", "type_args": [] },
"cc_type": {
"is_const": false,
"name": "int",
- "type_params": []
+ "type_args": []
}
},
"access": "Protected",
@@ -91,11 +91,11 @@
{
"identifier": { "identifier": "private_int" },
"type": {
- "rs_type": { "name": "i32", "type_params": [] },
+ "rs_type": { "name": "i32", "type_args": [] },
"cc_type": {
"is_const": false,
"name": "int",
- "type_params": []
+ "type_args": []
}
},
"access": "Private",
diff --git a/rs_bindings_from_cc/ir_testing.rs b/rs_bindings_from_cc/ir_testing.rs
index f0f5e42..71ba4ee 100644
--- a/rs_bindings_from_cc/ir_testing.rs
+++ b/rs_bindings_from_cc/ir_testing.rs
@@ -28,10 +28,10 @@
/// Creates a simple type instance for `int`/`i32`
pub fn ir_int() -> MappedType {
MappedType {
- rs_type: RsType { name: "i32".to_string().into(), type_params: vec![], decl_id: None },
+ rs_type: RsType { name: "i32".to_string().into(), type_args: vec![], decl_id: None },
cc_type: CcType {
name: "int".to_string().into(),
- type_params: vec![],
+ type_args: vec![],
is_const: false,
decl_id: None,
},
diff --git a/rs_bindings_from_cc/src_code_gen.rs b/rs_bindings_from_cc/src_code_gen.rs
index 58d10ec..0cae54e 100644
--- a/rs_bindings_from_cc/src_code_gen.rs
+++ b/rs_bindings_from_cc/src_code_gen.rs
@@ -469,26 +469,26 @@
};
match kind {
TypeKind::Pointer(mutability) => {
- if ty.type_params.len() != 1 {
- bail!("Invalid pointer type (need exactly 1 type parameter): {:?}", ty);
+ if ty.type_args.len() != 1 {
+ bail!("Invalid pointer type (need exactly 1 type argument): {:?}", ty);
}
- let nested_type = format_rs_type(&ty.type_params[0], ir)?;
+ let nested_type = format_rs_type(&ty.type_args[0], ir)?;
Ok(quote! {* #mutability #nested_type})
}
TypeKind::Record(ident) => {
- if !ty.type_params.is_empty() {
- bail!("Type parameters on records are not yet supported: {:?}", ty);
+ if !ty.type_args.is_empty() {
+ bail!("Type arguments on records are not yet supported: {:?}", ty);
}
Ok(quote! {#ident})
}
TypeKind::Unit => {
- if !ty.type_params.is_empty() {
- bail!("Unit type must not have type parameters: {:?}", ty);
+ if !ty.type_args.is_empty() {
+ bail!("Unit type must not have type arguments: {:?}", ty);
}
Ok(quote! {()})
}
TypeKind::Other(name) => {
- if !ty.type_params.is_empty() {
+ if !ty.type_args.is_empty() {
bail!("Type not yet supported: {:?}", ty);
}
let ident = make_ident(name);
@@ -506,15 +506,15 @@
if let Some(ref name) = ty.name {
match name.as_str() {
"*" => {
- if ty.type_params.len() != 1 {
- bail!("Invalid pointer type (need exactly 1 type parameter): {:?}", ty);
+ if ty.type_args.len() != 1 {
+ bail!("Invalid pointer type (need exactly 1 type argument): {:?}", ty);
}
- assert_eq!(ty.type_params.len(), 1);
- let nested_type = format_cc_type(&ty.type_params[0], ir)?;
+ assert_eq!(ty.type_args.len(), 1);
+ let nested_type = format_cc_type(&ty.type_args[0], ir)?;
Ok(quote! {#nested_type * #const_fragment})
}
ident => {
- if !ty.type_params.is_empty() {
+ if !ty.type_args.is_empty() {
bail!("Type not yet supported: {:?}", ty);
}
let ident = make_ident(ident);
@@ -889,9 +889,9 @@
rs_type: RsType {
name: "*mut".to_string().into(),
decl_id: None,
- type_params: vec![RsType {
+ type_args: vec![RsType {
name: "i32".to_string().into(),
- type_params: vec![],
+ type_args: vec![],
decl_id: None,
}],
},
@@ -899,10 +899,10 @@
name: "*".to_string().into(),
is_const: false,
decl_id: None,
- type_params: vec![CcType {
+ type_args: vec![CcType {
name: "int".to_string().into(),
is_const: false,
- type_params: vec![],
+ type_args: vec![],
decl_id: None,
}],
},
@@ -913,12 +913,12 @@
rs_type: RsType {
name: "*const".to_string().into(),
decl_id: None,
- type_params: vec![RsType {
+ type_args: vec![RsType {
name: "*mut".to_string().into(),
decl_id: None,
- type_params: vec![RsType {
+ type_args: vec![RsType {
name: "i32".to_string().into(),
- type_params: vec![],
+ type_args: vec![],
decl_id: None,
}],
}],
@@ -927,14 +927,14 @@
name: "*".to_string().into(),
is_const: false,
decl_id: None,
- type_params: vec![CcType {
+ type_args: vec![CcType {
name: "*".to_string().into(),
is_const: true,
decl_id: None,
- type_params: vec![CcType {
+ type_args: vec![CcType {
name: "int".to_string().into(),
is_const: false,
- type_params: vec![],
+ type_args: vec![],
decl_id: None,
}],
}],