-
Notifications
You must be signed in to change notification settings - Fork 4
Binding specifications: separate C and Haskell specs #960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
In typedef struct { ... } vector; Currently, the following binding specification is generated: types:
- headers: vector.h
cname: '@vector'
module: Vector
identifier: Vector
instances:
- Eq
- Show
- Storable When using this binding specification as an external binding specification to create bindings for
A pending task is to add alias information to binding specifications. We already have a When generating a binding specification, we need to output any aliases for each type. The above would become the following. types:
- headers: vector.h
cname: '@vector'
aliases:
- vector
module: Vector
identifier: Vector
instances:
- Eq
- Show
- Storable When loading an external binding specification, we must make sure that there is not duplicate configuration for the same type. Configuration for When resolving external bindings, any use of an alias is also replaced with an external binding. In this case, Thoughts? |
This does not work, because aliases must be known during the We need to decide about the binding specification syntax. How should we specify if a I am thinking through one option below, but I am of course open to alternate ideas! One option is to just use typedef struct foo { ... } foo_t; (1) User wants distinct types types:
- headers: acme.h
cname: struct foo
aliases: []
module: Acme
identifier: Foo
- headers: acme.h
cname: foo_t
aliases: []
module: Acme
identifier: Foo_t This is the default if (2) User wants types:
- headers: acme.h
cname: struct foo
aliases: foo_t
module: Acme
identifier: Foo (3) User wants types:
- headers: acme.h
cname: struct foo
aliases:
- cname: foo_t
identifier: FooT
module: Acme
identifier: Foo (4) User wants no declaration for the alias types:
- headers: acme.h
cname: struct foo
aliases:
- cname: foo_t
identifier: Foo
module: Acme
identifier: Foo (5) User wants a single declaration using the alias name types:
- headers: acme.h
cname: struct foo
aliases: foo_t
module: Acme
identifier: Foo_t This is the default if typedef struct foo { ... } foo;
typedef struct boo { ... } Boo; In cases where the default Haskell names conflict, and the (6) User wants distinct types types:
- headers: acme.h
cname: struct foo
aliases: []
module: Acme
identifier: Foo
- headers: acme.h
cname: foo
aliases: []
module: Acme
identifier: FooT typedef struct { ... } foo; Anonymous types always have a single use. (7) User wants just types:
- headers: acme.h
cname: '@foo'
aliases: foo
module: Acme
identifier: Foo This is the default. (8) User wants distinct types (for some reason) types:
- headers: acme.h
cname: @foo
aliases: []
module: Acme
identifier: FooStruct
- headers: acme.h
cname: foo
aliases: []
module: Acme
identifier: Foo (9) User wants types:
- headers: acme.h
cname: '@foo'
aliases: foo
module: Acme
identifier: Foo
opaque: True Configuration of opaque types is a separate issue (#809), but we should consider the relationship between various options. In this example, the syntax configures a single |
For typedef struct foo { ... } foo_t; types:
- headers: acme.h
cname: foo_t
module: Acme
identifier: Foo_t
representation: {newtype/synonym/transparent}
We'd also have an entry for types:
- headers: acme.h
cname: '@foo'
module: Acme
identifier: Foo # can be omitted (then we use the default naming) The user can now pick which identifier we use; without a prescriptive binding specification, we would use (Perhaps |
If the user wants a type to be opaque: types:
- headers: acme.h
cname: '@foo'
module: Acme
identifier: Foo
representation: opaque or types:
- headers: acme.h
cname: foo_t
module: Acme
identifier: Foo
representation: opaque-and-omit-anything-this-depends-on-if-not-used-anywhere-else
struct FILE__ { ... };
typedef struct FILE__ FILE; If we can implement this (perhaps it's not that difficult?), then Side note: generated binding specifications do not in general need to record omitted types: this is the purpose of selection and program slicing. Recording everything we don't generate bindings for (say, everything in the sys headers) could be an enormous list. However, explicit omits in prescriptive binding specifications should be included in the generated binding specifications, so that the output binding spec is a valid extension of the input binding spec. |
1f5b053
to
be7e7bb
Compare
(Rebased) |
0a45d7d
to
bff654b
Compare
bff654b
to
4a72843
Compare
This PR is blocked because "aliases" are not represented in binding specifications. We have decided to refactor binding specifications to instead specify C and Haskell types separately (#799). I need the work already done in this PR, so I am hijacking it. I just renamed it. I rebased the branch and changed |
4a72843
to
e33e58e
Compare
New type constructor `QualNameAnon` is added to the `QualName` type to distinguish anonymous declarations in binding specifications and select predicates. The string representation uses an `@` prefix. Example: `@SC_c` This character should not cause issues with regular expressions. This character is reserved for future use by YAML and must therefore be quoted. Example: ```yaml cname: '@S1_c' ```
With this change, we now write `struct @foo` instead of just `@foo`.
e33e58e
to
1c90af2
Compare
New type constructor
QualNameAnon
is added to theQualName
type to distinguish anonymous declarations in binding specifications and select predicates. The string representation uses an@
prefix.Example:
@SC_c
This character should not cause issues with regular expressions.
This character is reserved for future use by YAML and must therefore be quoted.
Example: