-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add C source information to Hs
and SHs
ASTs
#316
Comments
One idea is to change data Namespace =
NsOrdinary
| NsStructTag
| NsUnionTag
| NsEnumTag
newtype CName (ns :: Namespace) = CName { getCName :: Text }
... This type does not include member namespaces, which are separate per structure/union. Discussing with @edsko yesterday, he suggested that we may want to model member namespaces as well, perhaps using a GADT. C identifier namespace reference: |
it doesn't work in general. Counter example struct foo {
struct { int x; int y } bar;
int z;
} we will create More generally, what you propose is essentially delaying name mangling. |
Thanks for the example! I think that we should track how parts of our generated ASTs are created, so in this case we could include information for I do not mean to suggest that name mangling should be delayed. A Regarding documentation, we could generate documentation like the following:
|
which is essentially preserving exactly the information (to be) passed to the name mangling machinery. (And source location, but that is purely informative bit). |
Indeed. Perhaps another way to put it is that name mangling is not invertible. When generating tests, name Documentation like the above example could help users understand/confirm which Haskell maps to which C. When a user sees name |
I think that the easiest solution to go forward is to add a field with
That string is not |
Thank you very much for the suggestion. I will give that a try. |
This commit adds a type spelling field to the following ASTs: * `C` phase: `Struct`, `Enu`, `Typedef` * Type: `Text` * `Hs` phase: `Struct`, `Newtype` * Type: `Maybe Text` * `SHs` phase: `Record`, `Newtype` * Type: `Maybe Text` As suggested in #316, the string is not parsed. This commit simply uses `Text`, but we could implement a `newtype` wrapper if desired. The goal is to make it easier to generate tests for structures, enumerations, and `typedef`s of structures/enumerations. Note that this is also required for unions, but those are not implemented yet. This is the minimal change required to do this; the `Maybe` is needed because it does *not* track the type spelling for macros. (Cherry-picked from `source-info` for experimentation)
After discussing this with @TravisCardwell , the idea to annotate the Haskell tree with some kind of
is useful for both test generation and documentation generation; @phadej 's objection that the proposal as originally stated doesn't quite work ("which doesn't correspond to any type we could reference in C.") are especially important cases to consider, both for tests and for documentation generation; we agreed that Travis will submit a draft PR with an initial attempt at this so that we have something concrete to discuss and refine. |
We would like to track how various parts of our generated ASTs are created, referencing the C source.
One motivation for this is test generation (#22), which requires generating both C and Haskell code for testing. Generating the C test code from a C
Header
is not a good option because we would need to reimplement a lot of the logic for translating from C to Haskell. If the Haskell AST includes C source information, we could traverse the Haskell AST and determine exactly what test functions are required, perhaps referencing the CHeader
to get C details.For example, for a given
data
declaration (calledStruct
inHs
andRecord
inSHs
), it is useful to know the name of the corresponding C type, including the C namespace. When generating C code, the namespace determines how an identifier is written.foo
struct
tag namespace:struct foo
union
tag namespace:union foo
enum
namespace:enum foo
C source information can also be used to improve the generated Haddock documentation (#26). For example, we could output corresponding C names to help users understand/confirm which Haskell maps to which C.
We should include source locations, which may optionally be output in
LINE
pragmas (#74). We could even consider including source location information in generated Haddock documentation.Related to #23 (which is for the high-level API)
The text was updated successfully, but these errors were encountered: