jerryd/gtk-fortran — Issue #39: Setting Enum integer constants
Author: Dohle
Created: 2012-01-27 11:47:48+00:00
State: open

Hi,

In order to be able to use another f03 compiler two changes to the cfwrapper script were necessary. The boz constants were not accepted as scalar-int-constant-expr in the enumerator definition and assignment.

Instead of converting to a bit pattern the same C like bit shifting can be used:

def set_bit_field(match):
""" Returns the Fortran bitfield from a C enum flag"""
b = int(match.group(1))
field = "1"
s = "ISHFTC(1,"+str(b)+")"
return s

And for the hex constants simply insert the INT intrinsic function:

# Is it in hexadecimal ?
parameters[0] = re.sub("0x([0-9A-Fa-f]+)", "INT(z'\\1')", parameters[0])

Now a major f03 compiler accepts the statements in gtk.f90/gtkenums-auto.f90. For example:

enum, bind(c) !GModuleFlags
enumerator :: G_MODULE_BIND_LAZY = ISHFTC(1,0)
enumerator :: G_MODULE_BIND_LOCAL = ISHFTC(1,1)
enumerator :: G_MODULE_BIND_MASK = INT(z'03')
end enum

Regards!
Henk