haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
197 stars 50 forks source link

pseudo block c and enum, creates wrong line counting #262

Open jpwidera opened 3 years ago

jpwidera commented 3 years ago

WIth version 28.1 on Master branch following code will create wrong line counting:

#c
enum myEnum {
  _A = 0,
  _B = 1,
  _C = 2
};
#endc
{#enum myEnum {underscoreToCase} deriving( Show, Eq) #}

Will create following code snippet

...
  toEnum 2 = C
  toEnum unmatched = error ("myEnum.toEnum: Cannot match " ++ show unmatched)

{-# LINE 8 "test.chs" #-}
...

This LINE 8 should be LINE 9. This can be simply verified by repeating this the first code block. Each time, c2hs looses one line, eg.:

#c
enum myEnum {
  _A = 0,
  _B = 1,
  _C = 2
};
#endc
{#enum myEnum {underscoreToCase} deriving( Show, Eq) #}

#c
enum myEnum2 {
  _A2 = 0,
  _B2 = 1,
  _C2 = 2
};
#endc
{#enum myEnum2 {underscoreToCase} deriving( Show, Eq) #}

This leads to wrong line numbering in error/warnings.

Dumping the c2hs process gives following code for the pseudo-block of c:

#ce
#endc
#cn
#endc
#cu
#endc
#cm
#endc
#c 
#endc
#cm
#endc
#cy
#endc
#cE
#endc
#cn
#endc
#cu
#endc
#cm
#endc
#c 
#endc
#c{
#endc
#c

#endc
#c 
#endc
#c 
#endc
#c_
#endc
#cA
#endc
#c 
#endc
#c=
#endc
#c 
#endc
#c0
#endc
#c,
#endc
#c

...

#endc
#c}
#endc
#c;
#endc
#c

#endc
#c

#endc{#enum myEnum {underscoreToCase} deriving (Show, Eq) #}

I'm not sure, if this is how it should look like. Any suggestions?