Commit bd8e3a8
Use
> AI Disclaimer: the code and description are AI generated, but I have reviewed them so readers need not worry about AI slop.
This change uses the new Crubit feature flag, `leading_colons_for_cpp_type`. When enabled, it ensures that generated `cpp_type` annotations in Rust bindings have a leading `::` (e.g., `CRUBIT_ANNOTATE: cpp_type=::Foo`).
This change required some refactoring that spans both `rs_bindings_from_cc` and `cc_bindings_from_rs`. Here is a summary and justification for those changes:
1. **Refactor of `NamespaceQualifier`**:
* **What**: Added a `use_leading_colons` field to `NamespaceQualifier` and updated `NamespaceQualifier::new` to accept this boolean explicitly. Centralized the logic for prepending `::` in `format_for_cc`.
* **Why**: Instead of manually handling string manipulation at every annotation generation site, centralizing it in `NamespaceQualifier` is less error-prone. Forcing the argument in `new` ensures that we explicitly consider the feature flag at every call site rather than defaulting to `false`.
2. **Refactor of `crate_features` in `cc_bindings_from_rs`**:
* **What**: Moved the `crate_features` free function from `generate_bindings/lib.rs` to be a method on `BindingsGenerator` in `database/db.rs`.
* **Why**: To support the feature flag in `cc_bindings_from_rs` (specifically in `fully_qualified_name.rs` where `ExportedPath` is converted to `NamespaceQualifier`), we needed access to crate features. `fully_qualified_name.rs` belongs to the `database` crate and could not access the free function in `lib.rs`. Moving it to `BindingsGenerator` resolved this dependency issue and is architecturally cleaner, making feature lookup part of the database query.
3. **Cleanup and Inlining**:
* **What**: Inlined the remaining free function `crate_features` in `lib.rs` and updated all call sites in `lib.rs` and `generate_struct_and_union.rs` to use `db.crate_features` directly.
4. **Test consolidation**:
* **What**: Updated existing tests for `NamespaceQualifier` to use `true` for the feature flag instead of adding duplicate tests for both boolean states.
PiperOrigin-RevId: 900832916leading_colons_for_cpp_type feature flag and refactor NamespaceQualifier
1 parent 5be7af4 commit bd8e3a8
File tree
48 files changed
+450
-364
lines changed- cc_bindings_from_rs/generate_bindings
- database
- common
- rs_bindings_from_cc
- generate_bindings
- database
- test
- annotations
- assume_lifetimes
- display
- golden
- namespace/nested_items
- struct
- constructors
- inheritance
- methods_qualifiers
- methods
- templates
- type_alias_access_rule
- type_alias
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
48 files changed
+450
-364
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
179 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
180 | 183 | | |
181 | | - | |
| 184 | + | |
182 | 185 | | |
183 | 186 | | |
184 | 187 | | |
185 | 188 | | |
| 189 | + | |
186 | 190 | | |
187 | 191 | | |
188 | 192 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2204 | 2204 | | |
2205 | 2205 | | |
2206 | 2206 | | |
2207 | | - | |
2208 | | - | |
2209 | | - | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
2210 | 2210 | | |
2211 | 2211 | | |
2212 | 2212 | | |
| |||
Lines changed: 7 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| |||
339 | 338 | | |
340 | 339 | | |
341 | 340 | | |
342 | | - | |
| 341 | + | |
343 | 342 | | |
344 | 343 | | |
345 | 344 | | |
| |||
1461 | 1460 | | |
1462 | 1461 | | |
1463 | 1462 | | |
1464 | | - | |
1465 | | - | |
1466 | | - | |
1467 | | - | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
1468 | 1466 | | |
1469 | 1467 | | |
1470 | 1468 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | | - | |
| 247 | + | |
| 248 | + | |
248 | 249 | | |
249 | 250 | | |
250 | 251 | | |
| |||
336 | 337 | | |
337 | 338 | | |
338 | 339 | | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | 340 | | |
353 | 341 | | |
354 | 342 | | |
| |||
705 | 693 | | |
706 | 694 | | |
707 | 695 | | |
708 | | - | |
709 | | - | |
710 | | - | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
711 | 705 | | |
712 | 706 | | |
713 | 707 | | |
| |||
1661 | 1655 | | |
1662 | 1656 | | |
1663 | 1657 | | |
1664 | | - | |
| 1658 | + | |
1665 | 1659 | | |
1666 | 1660 | | |
1667 | 1661 | | |
| |||
1937 | 1931 | | |
1938 | 1932 | | |
1939 | 1933 | | |
1940 | | - | |
| 1934 | + | |
1941 | 1935 | | |
1942 | 1936 | | |
1943 | 1937 | | |
| |||
2096 | 2090 | | |
2097 | 2091 | | |
2098 | 2092 | | |
2099 | | - | |
2100 | | - | |
2101 | | - | |
2102 | | - | |
2103 | | - | |
2104 | | - | |
2105 | | - | |
2106 | | - | |
2107 | | - | |
2108 | | - | |
2109 | | - | |
2110 | | - | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
2111 | 2115 | | |
2112 | | - | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
2113 | 2122 | | |
2114 | 2123 | | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
2115 | 2127 | | |
2116 | 2128 | | |
2117 | 2129 | | |
2118 | 2130 | | |
| 2131 | + | |
2119 | 2132 | | |
2120 | 2133 | | |
2121 | 2134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
351 | 354 | | |
352 | 355 | | |
353 | 356 | | |
354 | 357 | | |
355 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
356 | 362 | | |
357 | 363 | | |
358 | 364 | | |
359 | 365 | | |
360 | 366 | | |
361 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
362 | 372 | | |
363 | 373 | | |
364 | 374 | | |
| |||
387 | 397 | | |
388 | 398 | | |
389 | 399 | | |
390 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
391 | 405 | | |
392 | 406 | | |
393 | 407 | | |
| |||
745 | 759 | | |
746 | 760 | | |
747 | 761 | | |
748 | | - | |
| 762 | + | |
749 | 763 | | |
750 | 764 | | |
751 | 765 | | |
752 | | - | |
| 766 | + | |
753 | 767 | | |
754 | 768 | | |
755 | 769 | | |
756 | 770 | | |
757 | | - | |
| 771 | + | |
758 | 772 | | |
759 | 773 | | |
760 | 774 | | |
761 | | - | |
| 775 | + | |
762 | 776 | | |
763 | 777 | | |
764 | 778 | | |
765 | 779 | | |
766 | | - | |
| 780 | + | |
767 | 781 | | |
768 | 782 | | |
769 | 783 | | |
770 | | - | |
| 784 | + | |
771 | 785 | | |
772 | 786 | | |
773 | 787 | | |
774 | 788 | | |
775 | | - | |
| 789 | + | |
776 | 790 | | |
777 | 791 | | |
778 | 792 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
480 | 480 | | |
481 | 481 | | |
482 | 482 | | |
483 | | - | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
484 | 494 | | |
485 | 495 | | |
486 | 496 | | |
| |||
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
173 | 176 | | |
174 | 177 | | |
175 | 178 | | |
| |||
2173 | 2176 | | |
2174 | 2177 | | |
2175 | 2178 | | |
2176 | | - | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
2177 | 2184 | | |
2178 | 2185 | | |
2179 | 2186 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
724 | 724 | | |
725 | 725 | | |
726 | 726 | | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
727 | 745 | | |
728 | 746 | | |
729 | 747 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | | - | |
274 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
275 | 278 | | |
276 | 279 | | |
277 | 280 | | |
| |||
0 commit comments