Dear Jurg,
These patches provide a foundation for non-constant switches. They solve
the GType issue mentioned by you.
The .vala files are tests.
switch-type-ok.vala contains all constant GType labels. It compiles fine
into valid C code.
switch-type-fail.vala contains mixed constant and non-constant labels.
It yields an error 'non-constant case label is not yet supported'.
(0003) We can later support it, or remove the word 'yet'.
In 0003, member function is_constant is added to SwitchLabel; it is true
for the default label(the one without expression). member function
is_all_constant is added to SwitchSection and SwitchStatement.
New CCode attribute type_id_const is introduced(0004, 0005) to indicate
whether the type id is a C constant(Class.type_id_const,
Enum.type_id_const, Struct.type_id_const). The TypeOfExpression is also
a vala constant if the type id is a C constant(0006).
It is perhaps more appropriate to use const type definitions (eg, const
class {} or const struct {}) for this purpose. Because in that way we
don't specifically depend on the GObject/CCode backend. That will be a
grammar change; I dare not do it.
MemberAccess to EnumValue weren't correctly deduced as Vala constant.
Patch 0002 fixes this issue.
0001 is the old patch to gobject-2.0 binding about IntegerType. I
remember some time ago we preferred not to inherit from GBoxed but
directly declare the structs. Why don't we do the same for GType: ulong
this time?
I am not sure if the work worth the effort: literally it only added
support for GType in switch statements. Nevertheless some of subtle
might be useful to improve the internal of the compiler.
Regards,
Yu
Attachment:
0001-GType-is-a-IntegerType-SimpleType.patch
Description: Text Data
Attachment:
0002-EnumValue-is-a-constant.patch
Description: Text Data
Attachment:
0003-Deduces-is_all_constant-in-switch-statements.patch
Description: Text Data
Attachment:
0004-Add-type_id_const-CCode-attribute.patch
Description: Text Data
Attachment:
0005-type_id_const-for-glib-internal-types.patch
Description: Text Data
Attachment:
0006-Deduce-whether-the-typeof-expression-is-const.patch
Description: Text Data
Attachment:
switch-const.vala
Description: Text Data
Attachment:
switch-enum.vala
Description: Text Data
Attachment:
switch-int.vala
Description: Text Data
Attachment:
switch-string.vala
Description: Text Data
Attachment:
switch-type-fail.vala
Description: Text Data
Attachment:
switch-type-ok.vala
Description: Text Data