Commit Graph

74 Commits

Author SHA1 Message Date
David Tolnay
bae50eff4e
Move C++-only to_mangled function to C++ generator 2020-04-25 18:02:17 -07:00
David Tolnay
6bd63de58e
Inline vector element check
These will need to diverge shortly; in particular we'd like to support
Rust vectors containing Rust strings and C++ vectors containing C++
strings.
2020-04-25 18:02:17 -07:00
David Tolnay
c0faaf6cda
Update cxx vector check to match rust vec check 2020-04-25 18:02:17 -07:00
David Tolnay
c6d891ece2
Fix Vec type checking
The previous logic incorrectly accepted Atoms outside the intended set,
and also emitted duplicate errors for opaque C++ types.
2020-04-25 18:02:16 -07:00
David Tolnay
76a8424864
Express is_valid_vector_element more compactly 2020-04-25 18:02:16 -07:00
David Tolnay
2410aff870
Rename vector element checking function
Vectors have elements, not targets. Pointers have targets.
2020-04-25 18:02:16 -07:00
David Tolnay
fff4c8a5d6
Clarify vector checking function names 2020-04-25 18:02:16 -07:00
David Tolnay
7ff1b8c1b5
Move is_valid_vector_target into type checker 2020-04-25 18:02:16 -07:00
David Tolnay
029f1d6a2e
Move C++-specific type printing back into C++ generator 2020-04-25 18:02:15 -07:00
David Tolnay
2eca4a0ce9
Move C++-specific to_typename to C++ code generator 2020-04-25 18:02:14 -07:00
David Tolnay
f12e983d8c
Eliminate unnecessary ToMangled trait 2020-04-25 18:02:14 -07:00
David Tolnay
4c4b550aed
Eliminate unnecessary ToTypename trait 2020-04-25 18:02:14 -07:00
David Tolnay
42a7742bcb
Revert visibility of Namespace segments from PR 67 2020-04-25 18:02:14 -07:00
David Tolnay
4ef2743b29
Keep type of namespace-iterator in helpers 2020-04-25 18:02:13 -07:00
David Tolnay
3a4299d0db
Emit prefixed path when using CxxVector type 2020-04-25 18:02:13 -07:00
David Tolnay
e1dcdf7317
Parse vector's type as CxxVector 2020-04-25 18:02:13 -07:00
David Tolnay
4377a9e837
Rename Type::Vector to CxxVector 2020-04-25 18:02:12 -07:00
David Tolnay
91d1bb9b7d
Use absolute paths consistently in generated code 2020-04-25 18:02:07 -07:00
Myron Ahn
eba35cfce7
C++ std::vector<T> and Rust std::vec::Vec<T> support
Add basic std::vector and std::vec::Vec support across FFI boundary.
2020-04-25 12:47:04 -07:00
David Tolnay
a1f29c4e43
Defer computing the Self type of methods 2020-04-22 18:20:58 -07:00
David Tolnay
9bfbea37c7
Allow mutating signature through ExternFn 2020-04-22 18:12:49 -07:00
David Tolnay
0b368ae341
Defer error on restricted type names 2020-04-22 17:55:09 -07:00
David Tolnay
8b60bf170b
Reject unrecognized idents in receiver's type 2020-04-22 16:54:15 -07:00
David Tolnay
d763f4cd64
Reject explicit lifetimes in a reference type 2020-04-22 16:39:44 -07:00
David Tolnay
bfad5f759f
Preserve span on Receiver shorthand self token 2020-04-22 16:36:55 -07:00
David Tolnay
62d360ccaf
Preserve whether Receiver was shorthand for error reporting 2020-04-22 16:26:21 -07:00
David Tolnay
0bd50fa931
Preserve lifetimes on parsed references 2020-04-22 16:23:39 -07:00
David Tolnay
18ba92ce82
Split Receiver's ToTokens into a wrapper type 2020-04-22 16:22:47 -07:00
David Tolnay
1dd11a16b4
Touch up &self shorthand PR 2020-04-22 15:33:54 -07:00
Joel Galenson
e1e969d06f Allow &self without a type when the block only has one type 2020-04-22 08:44:49 -07:00
David Tolnay
05e11cca1f
Preserve span of self var in Receiver 2020-04-20 02:13:56 -07:00
David Tolnay
fb6e386cf4
Clean up printing of Receiver to tokens 2020-04-20 01:35:08 -07:00
David Tolnay
891061bc7f
Use Symbol for mangled names throughout code generators 2020-04-19 23:35:54 -07:00
David Tolnay
5ea922a211
Centralize mangled symbol joining 2020-04-19 23:35:54 -07:00
David Tolnay
9d8d80bd81
Remove '_' segment from symbol of non-associated functions 2020-04-19 23:35:02 -07:00
David Tolnay
3caa50ac99
Share function link name mangling logic 2020-04-19 21:38:44 -07:00
David Tolnay
b6cf314a45
Unify Namespace parsing code 2020-04-19 20:59:20 -07:00
David Tolnay
0841930d34
Share one Namespace type between gen and macro 2020-04-19 20:38:28 -07:00
Joel Galenson
3d4f612b34 Support calling C++ methods from Rust
These methods can be declared in the bridge by naming the first
argument self and making it a reference to the containing class, e.g.,
  fn get(self: &C) -> usize;
  fn set(self: &mut C, n: usize);
This syntax requires Rust 1.43.

Note that the implementation also changes the internal naming of shim
functions so that they also contain the name of the owning class, if
any.  This allows defining multiple methods with the same name on
different objects.
2020-04-16 16:24:48 -07:00
David Tolnay
eebe9b7289
Improve type checking and error messages for slice type 2020-04-14 16:42:06 -07:00
David Tolnay
eb952bac14
Format with rustfmt and clang-format 2020-04-14 16:42:06 -07:00
Adrian Taylor
f5dd552036 Adding &[u8] support.
This change adds specifically, support for &[u8] with a corresponding
rust::Slice<uint8_t> type. No other types of slice are permitted. The
rationale is that it may be common to pass binary data back and forth
across the FFI boundary, so it's more urgent to get this in place sooner.
Broader support for other slices can wait for the future.

But, both C++ and Rust-side bindings should allow the existing support
to be broadened to other Slice types in future without code changes.

A few specific notes:

* The name "rust::Slice" might be better as "rust::SliceRef" but I'm
  following the precedent of "rust::Str".
* It would be good to add constructors from std::span but as that's
  a C++20 feature, that may have to wait until C++ feature detection
  is resolved.
* Internally, this follows the pattern of &str, where the parser will
  initially recognize this as Type::Ref (of Type::Slice) but then
  will replace that with Type::SliceRefU8. Type::Slice should not
  persist through later stages. As we later come to support other
  types of slice, we would probably want to remove Type::SliceRefU8.
2020-04-14 14:13:48 -07:00
David Tolnay
e3a481508a
Store finer grained tokens of Signature
This is required in order for function pointers like `fn(&CxxString)` to
work, which requires the cxx bridge to emit `fn(&::cxx::CxxString)`
rather than a straight copy of the input tokens.
2020-04-08 20:01:16 -07:00
David Tolnay
75dca2e846
Passing function pointer from Rust to C++ 2020-03-29 21:50:25 -07:00
David Tolnay
d7e1f1e519
Split function pointer error message into specific cases 2020-03-25 20:18:39 -07:00
David Tolnay
a420f0141a
Move error message construction into checking functions
These were pulled out originally because error message construction was
so verbose that it detracted from being able to follow the logic of the
checks, but now that checks are broken up into finer granularity the
messages can be inlined.
2020-03-25 18:01:12 -07:00
David Tolnay
26a2a1deda
Collect typecheck context into a struct 2020-03-25 17:35:17 -07:00
David Tolnay
d4e6830d40
Split up typecheck logic to functions 2020-03-25 16:59:02 -07:00
David Tolnay
09462acd4b
Disallow shared structs having 0 fields 2020-03-20 14:58:56 -07:00
David Tolnay
c071b89c2c
Parse function pointer types 2020-03-18 20:14:00 -07:00