Closed phlummox closed 3 years ago
By the way, I'd be interested to know - is there a quick and easy way of running the parsers in
src/Language/C/Types/Parse.hs
on a code fragment to see whether and how the code is parsed? I had a very quick look at the file, but it wasn't obvious to me where to start, and unfortunately I couldn't spend too much more time looking. I realize that code will be parsed differently depending on what sort of context it appears in -- but if this is something that could be easily provided, it might save developers some of the time they'd otherwise spend in boiling code down to a minimal example and experimenting with it. (I initially thought problems I was having were due to a templated struct
I was using, and it took me a while to establish that that wasn't the issue at all; it was the use of long
.)
@junjihashimoto could you take a look at this?
@phlummox regarding testing the parser, you can use https://hackage.haskell.org/package/inline-c-0.9.1.4/docs/Language-C-Types.html#v:quickCParser to run one of those parsers easily.
Ah, I missed quickCParser! Many thanks for that.
The parser for template is here. https://github.com/fpco/inline-c/blob/b37b60f1712b12b43c86493cafb9ac324443d22e/inline-c/src/Language/C/Types/Parse.hs#L383
type_specifier
parses each argument like long
.
It seems that one term is supported, but it does not seem to support multiple terms like long long
.
https://github.com/fpco/inline-c/blob/b37b60f1712b12b43c86493cafb9ac324443d22e/inline-c/src/Language/C/Types/Parse.hs#L306-L322
untangleDeclarationSpecifiers's error is around here. https://github.com/fpco/inline-c/blob/b37b60f1712b12b43c86493cafb9ac324443d22e/inline-c/src/Language/C/Types.hs#L212-L262
It may not be just a parser issue.
I will check the cause of untangleDeclarationSpecifiers's error later.
I am fixing it like this draft. https://github.com/fpco/inline-c/pull/126
Released as 0.9.1.5.
When using inline-c-cpp and returning a template type from a block, it seems the code responsible for parsing types chokes on any numeric type other than an "int"; it apparently can't handle a "long int", "unsigned int", "short int", "long long", etc.
For instance, the following code
gives a compilation error message along the lines of:
but the same code works if we change the
long
toint
(and correspondingly change theCLong
to aCInt
).Minimal-ish working example:
1. Create a Cabal file
bogus.cabal
.`bogus.cabal` contents
``` cabal-version: 1.12 name: bogus version: 0.1.0.0 build-type: Simple library exposed-modules: Lib hs-source-dirs: src build-depends: base >=4.7 && <5 , inline-c , inline-c-cpp default-language: Haskell2010 ```and add a minimal
src/Lib.hs
file:If using
stack
(which I am), then you can add astack.yaml
file with the latest versions of inline-c and inline-c-cpp:`stack.yaml` contents
``` resolver: lts-13.30 # or whatever you like packages: - . extra-deps: - inline-c-cpp-0.4.0.3 - inline-c-0.9.1.4 ```Build it (e.g. with
stack build
orcabal new-build
).2. Create a file
test.hs
:3. Try to compile it, e.g. with
stack ghc -- --make test.hs
Expected result
The file should compile with no errors.
Actual result
Compilation fails, with the error message
I also tried using the current HEAD of the GitHub repository, and got the same results.