David Tolnay
3a45173325
Reject unsafe on an extern Rust block
...
error: extern "Rust" block does not need to be unsafe
--> lib.rs:116:5
|
116 | unsafe extern "Rust" {
| ^^^^^^^^^^^^^^^^^^^^
2020-08-29 18:58:06 -07:00
David Tolnay
73075fe85f
Fix stray question operator
2020-08-29 18:58:06 -07:00
David Tolnay
c880ae2c34
Parse extern C++ structs
2020-08-29 18:46:50 -07:00
David Tolnay
8984995600
Box, Vec of an extern enum is supposed to work
2020-08-29 18:35:31 -07:00
David Tolnay
554837220f
Add enum classifier for error messages
2020-08-29 18:27:46 -07:00
David Tolnay
0b3eef7435
Clean up some unneeded clones of the type names
2020-08-29 16:15:09 -07:00
David Tolnay
0c0cfee264
Parse unsafety on extern blocks
2020-08-29 15:30:53 -07:00
David Tolnay
c598a27902
Represent the unsafety on foreign module
2020-08-29 15:12:46 -07:00
David Tolnay
00a83852cd
Data structure for parsed contents of bridge module
2020-08-29 15:11:37 -07:00
David Tolnay
633f5669fa
Parse unsafety on module
2020-08-29 14:47:45 -07:00
David Tolnay
3c64a4e144
Parse full file using the new Module parser
2020-08-29 14:36:42 -07:00
David Tolnay
05ef6ffa28
Data structure to represent possibly unsafe module
2020-08-29 11:55:04 -07:00
David Tolnay
47e239df11
Implement CxxVector<CxxString>
2020-08-28 00:43:10 -07:00
David Tolnay
33f56ad8d5
Implement Vec<String>
2020-08-28 00:25:41 -07:00
David Tolnay
c8361027d9
Remove dependency of ui test on whether rust-src is installed
2020-08-25 22:03:00 -07:00
David Tolnay
91e87fa51e
Parse include!(<path/to/bracketed>)
...
For example:
#[cxx::bridge]
mod ffi {
extern "C" {
include!("path/to/quoted");
include!(<path/to/bracketed>);
...
}
}
Emitted as:
#include "path/to/quoted"
#include <path/to/bracketed>
2020-05-11 20:07:34 -07:00
David Tolnay
65bc8e6af8
Detect earlier untyped discriminants out of bounds of later suffix
2020-05-11 00:30:24 -07:00
David Tolnay
9f7c55acde
Rename discriminant Bounds to Limits
...
This is aligned with "limits" as used in std::numeric_limits in C++.
2020-05-11 00:19:02 -07:00
David Tolnay
8155e58ba1
Treat unexpected tokens in repr attribute as unexpected repr
2020-05-11 00:15:12 -07:00
David Tolnay
17451dea34
Restore rust 1.42 compatibility
2020-05-10 23:49:12 -07:00
David Tolnay
c605e6fa61
Respect inferred enum repr in Rust code generator
2020-05-10 23:37:12 -07:00
David Tolnay
f2d584101d
Expand maximum recognized discriminant to 64 bits
2020-05-10 23:23:37 -07:00
David Tolnay
94cce00fdd
Detect mismatched suffix on discriminant values
2020-05-10 23:19:39 -07:00
David Tolnay
5966f7b3f6
Detect out of bounds when inserting discriminant
2020-05-10 22:59:56 -07:00
David Tolnay
ddf69e291b
Parse repr attribute on enums
2020-05-10 22:57:33 -07:00
David Tolnay
0435a81842
Recover from some enum parsing errors
2020-05-10 22:57:33 -07:00
David Tolnay
e2e303f7f2
Infer enum repr based on discriminant range
2020-05-10 22:57:32 -07:00
David Tolnay
f1715fa994
Add const bound data for various discriminant reprs
2020-05-10 22:57:32 -07:00
David Tolnay
9bcb4c6d0b
Extract integer suffix of discriminants as the repr
2020-05-10 22:57:32 -07:00
David Tolnay
2b8bf6d262
Preserve the original discriminant Expr
2020-05-10 22:57:32 -07:00
David Tolnay
69c7960cb2
Parse negative discriminants
2020-05-10 22:57:32 -07:00
David Tolnay
17e137fbb3
Factor out a discriminant processing library
2020-05-10 22:57:32 -07:00
David Tolnay
699351bc78
Display for Atom
2020-05-10 22:57:08 -07:00
David Tolnay
a4596c4455
Expose Atom str for use in error messages
2020-05-10 22:55:45 -07:00
David Tolnay
64703b4207
Give Derive enum and impls their own module
2020-05-10 22:12:33 -07:00
David Tolnay
3e62888960
Keep items that have attr parse errors
2020-05-10 15:36:01 -07:00
David Tolnay
b129ea7163
Organize how the caller determines which attrs to parse
...
In preparation for parsing even more attributes, such as `repr`.
2020-05-10 14:48:30 -07:00
David Tolnay
e86b9cf225
Update derive parsing to produce structured representation
2020-05-10 14:26:04 -07:00
David Tolnay
2b821e60e0
Don't do trait impls for non-local types
2020-05-07 23:18:09 -07:00
David Tolnay
e5a015a2b4
Allow type alias as a method receiver
2020-05-07 21:54:31 -07:00
David Tolnay
379d342779
Type alias type info
2020-05-07 19:46:02 -07:00
David Tolnay
3118fa6606
Type alias ident checking
2020-05-07 19:46:02 -07:00
David Tolnay
e2f9ec4c89
Type alias parsing
2020-05-07 19:46:02 -07:00
David Tolnay
9938381aa7
Introduce type aliases in syntax tree
2020-05-07 19:46:02 -07:00
David Tolnay
295ef6b38a
Adjust foreign item parsing to prepare for type aliases
...
This will be required for parse_extern_type to return a different kind
of Api for the case of type aliases.
2020-05-07 16:10:30 -07:00
David Tolnay
4301f3ca51
Simplify discriminant overflow check
2020-05-05 10:29:52 -07:00
David Tolnay
a3f6407efa
Expand discriminant overflow error message
...
Renders as:
error[cxxbridge]: discriminant overflow on value after 4294967295
┌─ src/main.rs:11:9
│
11 │ B,
│ ^ discriminant overflow
│
= note: explicitly set `= 0` if that is desired outcome
This more closely matches rustc's error message, which is:
error[E0370]: enum discriminant overflowed
--> src/lib.rs:4:5
|
4 | B,
| ^ overflowed on value after 255
|
= note: explicitly set `B = 0` if that is desired outcome
2020-05-05 10:28:00 -07:00
David Tolnay
7ae018fb5a
Resolve redundant_field_names lint
2020-05-05 10:11:30 -07:00
Joel Galenson
8ef1bc809c
Fix rustc 1.42.0.
2020-05-05 08:45:49 -07:00
Joel Galenson
8854773c56
Compute enum discriminant during parsing
...
This allows us to reuse the computation in multiple places later.
2020-05-05 08:32:32 -07:00
Joel Galenson
0f654ffeb0
Fix previous commit.
2020-05-04 20:04:21 -07:00
Joel Galenson
905eb2e1f5
Support enums defined in C++ code.
...
This allows listing an enum in an extern "C" block as well as in the
shared block. In this case, we do not emit the C++ declaration of the
enum but instead emit static assertions that it has the values that we
expect.
2020-05-04 15:02:17 -07:00
David Tolnay
5275978d13
Batch errors from the parser
2020-05-04 01:29:17 -07:00
David Tolnay
0dd85ff5f7
Move error collection one level out of type checker
2020-05-04 01:29:17 -07:00
David Tolnay
df344a82d9
Extract error collection to be not specific to check.rs
2020-05-04 01:29:16 -07:00
David Tolnay
7bc2edd734
Include conflicting name in duplicate name error message
2020-05-04 00:41:53 -07:00
David Tolnay
83496ebf33
Move error reporting span computation to tokens.rs
2020-05-04 00:36:53 -07:00
David Tolnay
d932041745
Catch function name collisions
2020-05-04 00:31:56 -07:00
David Tolnay
ab91445c1d
Check type name duplication more compactly
2020-05-04 00:31:28 -07:00
David Tolnay
96a826b8f0
Check function signature restrictions in a more appropriate place
2020-05-04 00:17:12 -07:00
David Tolnay
8adb223f3e
Restore support for rustc 1.42
2020-05-01 10:14:27 -07:00
David Tolnay
57d81a12fb
Merge pull request #180 from jgalenson/enums
...
Properly handle enum discriminant overflows.
2020-05-01 10:13:24 -07:00
Joel Galenson
04fa0967e2
Properly handle enum discriminant overflows.
...
This both checks for enum values that are illegal due to overflow and
ensures we do not overflow on valid enums.
2020-05-01 10:00:31 -07:00
David Tolnay
c4ddb4d172
Add tests for by-value-not-supported errors
2020-05-01 10:00:17 -07:00
David Tolnay
6b6423edfb
Really check everything in check_all
2020-04-30 22:55:23 -07:00
David Tolnay
a83301ce5b
Update ident checker's error reporting to match type checker's
2020-04-30 22:55:23 -07:00
David Tolnay
9dcb8339f0
Do not abort parser on namespace ident checks
2020-04-30 22:55:23 -07:00
David Tolnay
63f92e8283
Preserve Span of namespace segments
2020-04-30 22:55:23 -07:00
David Tolnay
d7984c2b7f
Touch up PR 170
2020-04-30 22:50:10 -07:00
Joel Galenson
c03402aee5
Support C-style enums
...
This adds support for passing C-style enums between Rust and C++.
We use the Rust representation for enums suggested by dtolnay in #132 .
Note that as this does not use real enums, Rust code cannot treat them
as normal enums, e.g., by converting them to integers. But common
uses such as pattern matching remain unchanged.
2020-04-30 14:12:37 -07:00
David Tolnay
6960162922
Bump namespace to cxxbridge03
2020-04-29 18:49:50 -07:00
David Tolnay
776fd8953d
Generalize reference-to-reference check to cover all positions
...
Checking this in check_type_ref allows it to apply anywhere that a
reference is written, such as return position which was not covered by
the previous logic.
2020-04-28 13:38:28 -07:00
Joel Galenson
2bd1312f2f
Disallow passing a reference to a reference.
2020-04-28 10:14:41 -07:00
Joel Galenson
ba67607fa2
Allow wildcard argument names.
...
This adds support for wildcard variable names by internally giving
them unique names.
2020-04-27 16:00:50 -07:00
David Tolnay
03dca70161
Fix Vec returns by value
2020-04-25 18:02:18 -07:00
David Tolnay
fa85fce853
Clarify mentions of C++ vector in error messages
2020-04-25 18:02:18 -07:00
David Tolnay
e70303c68e
Disallow passing CxxVector by move
2020-04-25 18:02:18 -07:00
David Tolnay
51cc8ee061
Fix module path of Vec in generated Rust code
2020-04-25 18:02:18 -07:00
David Tolnay
99c93d864c
Add vector types to reserved names list
2020-04-25 18:02:18 -07:00
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
David Tolnay
d95b119931
Preserve original tokens of Signature
2020-03-18 20:07:46 -07:00
David Tolnay
417305a41a
Add function pointer types to syntax tree
2020-03-18 17:03:26 -07:00
David Tolnay
35c82eb673
Prevent forgetting fields in PartialEq and Hash impls
2020-03-18 16:48:36 -07:00
David Tolnay
b40b9dba07
Divide up big parse_type function
2020-03-18 13:50:36 -07:00
David Tolnay
0b76aea8e8
Allow extern abi to be specified as "C++"
2020-03-18 12:54:24 -07:00
David Tolnay
16448731f2
Move extern fn signature fields to struct
...
This will allow reusing the Signature struct for the type of function
pointers.
2020-03-18 12:40:26 -07:00
David Tolnay
ebef4a23a2
Implement fallible C++ functions
2020-03-17 17:34:52 -07:00
David Tolnay
1e548174c3
Implement fallible Rust functions
2020-03-17 00:15:48 -07:00
David Tolnay
bb16d53057
Split the fallible function error message
2020-03-16 23:04:17 -07:00
David Tolnay
6cde49f694
Store language identifier inside ExternFn for diagnostics
2020-03-16 23:04:17 -07:00
David Tolnay
c0a166d790
Add error message to say Result is not implemented yet
2020-03-16 00:40:15 -07:00
David Tolnay
59b7edea27
Parse Result return type
2020-03-16 00:36:15 -07:00
David Tolnay
64181b127e
Ignore Void in return position
2020-03-15 23:42:54 -07:00
David Tolnay
1fa1ae4cec
Implement restrictions on placement of ()
2020-03-15 23:39:58 -07:00
David Tolnay
d0bb3646cf
Remove Span wrapper type
2020-03-15 23:27:49 -07:00
David Tolnay
c21b20ac0f
Handwrite boilerplate impls for Type
...
This allows dropping the Span wrapper that was only needed for the Eq
and Hash support.
2020-03-15 23:25:34 -07:00
David Tolnay
fb134ed1be
Implement parsing () type
2020-03-15 23:17:48 -07:00
David Tolnay
2fb14e934b
Add Type::Void variant
...
Not currently usable as a function argument or explicit return value,
but will be required when we introduce Result for the case of fallible
void functions, whose return type will be Result<()>.
2020-03-15 23:11:40 -07:00
David Tolnay
9542f227db
Clean up Atom::from match arm order
2020-03-13 13:55:28 -07:00
David Tolnay
3383ae719f
Add f32 and f64 types
2020-03-13 01:14:11 -07:00
David Tolnay
a52602b8af
Use PartialEq<Atom> for some ident comparisons
2020-03-06 10:24:34 -08:00
David Tolnay
438e26034c
Make PartialEq work with reference lhs
2020-03-06 10:21:35 -08:00
David Tolnay
ba5eb2de8c
Add PartialEq impls for comparison against specific atoms
2020-03-06 10:15:52 -08:00
David Tolnay
7db7369797
Safe FFI between Rust and C++
2020-01-08 08:57:24 -08:00