Previously we just supported int and string, add double to this.
Technically we should probably differentiate between float and
double, but it's not likely to be very useful in practice to do so.
symbol_get_const_int (PyGISourceSymbol *self,
void *context)
{
+ if (!self->symbol->const_int_set)
+ {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
return PyInt_FromLong (self->symbol->const_int);
}
+static PyObject *
+symbol_get_const_double (PyGISourceSymbol *self,
+ void *context)
+{
+ if (!self->symbol->const_double_set)
+ {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return PyFloat_FromDouble (self->symbol->const_double);
+}
+
static PyObject *
symbol_get_const_string (PyGISourceSymbol *self,
void *context)
{ "ident", (getter)symbol_get_ident, NULL, NULL},
{ "base_type", (getter)symbol_get_base_type, NULL, NULL},
/* gboolean const_int_set; */
- { "const_int", (getter)symbol_get_const_int, NULL, NULL},
+ { "const_int", (getter)symbol_get_const_int, NULL, NULL},
+ /* gboolean const_double_set; */
+ { "const_double", (getter)symbol_get_const_double, NULL, NULL},
{ "const_string", (getter)symbol_get_const_string, NULL, NULL},
{ "source_filename", (getter)symbol_get_source_filename, NULL, NULL},
{ 0 }
}
| FLOATING
{
- $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
+ $$->const_double_set = TRUE;
+ $$->const_double = 0.0;
+ sscanf (yytext, "%lf", &($$->const_double));
}
| strings
| '(' expression ')'
object_macro_define
: object_macro constant_expression
{
- if ($2->const_int_set || $2->const_string != NULL) {
+ if ($2->const_int_set || $2->const_double_set || $2->const_string != NULL) {
$2->ident = $1;
gi_source_scanner_add_symbol (scanner, $2);
gi_source_symbol_unref ($2);
gboolean const_int_set;
int const_int;
char *const_string;
+ gboolean const_double_set;
+ double const_double;
char *source_filename;
};
class SourceSymbol(object):
- __members__ = ['const_int', 'const_string', 'ident', 'type', 'base_type']
+ __members__ = ['const_int', 'const_double', 'const_string', 'ident',
+ 'type', 'base_type']
def __init__(self, scanner, symbol):
self._scanner = scanner
def const_int(self):
return self._symbol.const_int
+ @property
+ def const_double(self):
+ return self._symbol.const_double
+
@property
def const_string(self):
return self._symbol.const_string
if not symbol.source_filename.endswith('.h'):
return None
name = self.remove_prefix(symbol.ident)
- if symbol.const_string is None:
+ if symbol.const_string is not None:
+ type_name = 'utf8'
+ value = symbol.const_string
+ elif symbol.const_int is not None:
type_name = 'int'
value = symbol.const_int
+ elif symbol.const_double is not None:
+ type_name = 'double'
+ value = symbol.const_double
else:
- type_name = 'utf8'
- value = symbol.const_string
+ raise AssertionError()
+
const = Constant(name, type_name, value)
return const
</parameters>
</callback>
</record>
+ <constant name="PIE_IS_TASTY" value="3.14159">
+ <type name="double"/>
+ </constant>
<record name="Rectangle" c:type="FooRectangle">
<field name="x" writable="1">
<type name="int" c:type="gint"/>
<type name="GObject.ObjectClass"/>
</field>
</record>
+ <constant name="PIE_IS_TASTY" value="3.141590">
+ <type name="double"/>
+ </constant>
<record name="Rectangle">
<field name="x" writable="1">
<type name="int"/>
#define FOO_DEFINE_SHOULD_BE_EXPOSED "should be exposed"
+#define FOO_PIE_IS_TASTY 3.14159
+
#define FOO_TYPE_INTERFACE (foo_interface_get_type ())
#define FOO_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), FOO_TYPE_INTERFACE, FooInterface))
#define FOO_IS_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), FOO_TYPE_INTERFACE))