[C2hs] Intented meaning of CDeclr

Benedikt Huber benjovi at gmx.net
Tue Aug 5 20:57:26 EDT 2008


I've been trying to fix some bugs in c2hs, which all seem related to  
the definition of CDeclr.
I'm not quite sure what the actual problem is, so maybe someone can  
help me out here.
I'm referring to the lasted revision from darcs (0.15.2):

The problem is that the Parser assumes that the leftmost indirection  
is represented outermost in the chain of CDeclrs.
To illustrate, consider

 > char * x[];

"x is an array of pointers to char".

The parser returns (simplified):

 > CPtrDeclr (CArrDeclr (CVarDeclr "x"))

I'm not sure if this is an accidental mistake, but in the analysis  
code, it is assumed that the above declarator is represented as

 > CArrDeclr (CPtrDeclr (CVarDeclr "x"))

which seems more plausible in my opinion.  Should this be fixed in the  
parser ?

Another confusing part:

In src/C2HS/C/AST.hs, we find
424: -- * The qualifiers list in a `CPtrDeclr' may not be empty
437: CPtrDeclr [CTypeQual]             -- indirections
This sounds as if the type qualifiers (const,restrict,volatile) model  
indirections of pointers, which isn't true of course.
This assumption apparently is used in src/C2HS/Gen/Bind.hs:
 >      case declr of
 >        (Just (CPtrDeclr [_]       declr at), oinit, oexpr) ->
 >          return $ CDecl specs [(Just declr, oinit, oexpr)] at
 >        (Just (CPtrDeclr (_:quals) declr at), oinit, oexpr) ->
 >          return $
 >            CDecl specs [(Just (CPtrDeclr quals declr at), oinit,  
oexpr)] at
This is just an accidental mistake, I suppose ?

best regards, benedikt

More information about the C2hs mailing list