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
>From 3b4ac1cec5b459287e45fc3d681a65f4a539c593 Mon Sep 17 00:00:00 2001
From: Yu Feng <[email protected]>
Date: Thu, 25 Jun 2009 16:00:55 +0800
Subject: [PATCH] GType is a IntegerType + SimpleType
Refer to Sam's email on Jun 24th Switch statement on GType.
I can't access mail-archive in china; weird.
---
vapi/gobject-2.0.vapi | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/vapi/gobject-2.0.vapi b/vapi/gobject-2.0.vapi
index 54b53e0..d902452 100644
--- a/vapi/gobject-2.0.vapi
+++ b/vapi/gobject-2.0.vapi
@@ -26,8 +26,10 @@
[CCode (cprefix = "G", lower_case_cprefix = "g_", cheader_filename = "glib.h")]
namespace GLib {
+ [SimpleType]
[CCode (type_id = "G_TYPE_GTYPE", marshaller_type_name = "GTYPE", get_value_function = "g_value_get_gtype", set_value_function = "g_value_set_gtype")]
- public struct Type : ulong {
+ [IntegerType (rank = 9)]
+ public struct Type {
[CCode (cname = "G_TYPE_IS_OBJECT")]
public bool is_object ();
[CCode (cname = "G_TYPE_IS_ABSTRACT")]
--
1.6.0.6
>From 71dc1e9fc3d11dcc26618b2f83feba2748c55b1a Mon Sep 17 00:00:00 2001
From: Yu Feng <[email protected]>
Date: Fri, 26 Jun 2009 10:00:47 +0800
Subject: [PATCH] EnumValue is a constant
---
vala/valamemberaccess.vala | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 2ef15a4..7c01a84 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -187,6 +187,8 @@ public class Vala.MemberAccess : Expression {
public override bool is_constant () {
if (symbol_reference is Constant) {
return true;
+ } else if (symbol_reference is EnumValue) {
+ return true;
} else {
return false;
}
--
1.6.0.6
>From 7b58ecb6c242e6a4b0ba6867117968b2986d6230 Mon Sep 17 00:00:00 2001
From: Yu Feng <[email protected]>
Date: Fri, 26 Jun 2009 10:01:29 +0800
Subject: [PATCH] Deduces is_all_constant in switch statements
Currently non-constant case labels are not supported.
---
vala/valaswitchlabel.vala | 10 +++++++++-
vala/valaswitchsection.vala | 12 ++++++++++++
vala/valaswitchstatement.vala | 20 ++++++++++++++++++++
3 files changed, 41 insertions(+), 1 deletions(-)
diff --git a/vala/valaswitchlabel.vala b/vala/valaswitchlabel.vala
index a778ce2..67cb16c 100644
--- a/vala/valaswitchlabel.vala
+++ b/vala/valaswitchlabel.vala
@@ -65,11 +65,19 @@ public class Vala.SwitchLabel : CodeNode {
}
}
+ /* for default label this flag is also true */
+ private bool _is_constant = true;
+
public override bool check (SemanticAnalyzer analyzer) {
if (expression != null) {
expression.check (analyzer);
+ _is_constant = expression.is_constant();
}
-
+
return true;
}
+
+ public bool is_constant () {
+ return _is_constant;
+ }
}
diff --git a/vala/valaswitchsection.vala b/vala/valaswitchsection.vala
index 27c02c2..bacad15 100644
--- a/vala/valaswitchsection.vala
+++ b/vala/valaswitchsection.vala
@@ -67,6 +67,15 @@ public class Vala.SwitchSection : Block {
return false;
}
+ private bool _is_all_constant = true;
+ /**
+ * Return if all labels are constant
+ *
+ * @return if all labels are constant
+ */
+ public bool is_all_constant () {
+ return _is_all_constant;
+ }
public override void accept (CodeVisitor visitor) {
visitor.visit_switch_section (this);
}
@@ -90,6 +99,9 @@ public class Vala.SwitchSection : Block {
foreach (SwitchLabel label in get_labels ()) {
label.check (analyzer);
+ if(label.is_constant() == false) {
+ _is_all_constant = false;
+ }
}
owner = analyzer.current_symbol.scope;
diff --git a/vala/valaswitchstatement.vala b/vala/valaswitchstatement.vala
index a66a284..5be6fac 100644
--- a/vala/valaswitchstatement.vala
+++ b/vala/valaswitchstatement.vala
@@ -43,6 +43,7 @@ public class Vala.SwitchStatement : CodeNode, Statement {
private Expression _expression;
private Gee.List<SwitchSection> sections = new ArrayList<SwitchSection> ();
+ private bool _is_all_constant = true;
/**
* Creates a new switch statement.
*
@@ -74,6 +75,15 @@ public class Vala.SwitchStatement : CodeNode, Statement {
return new ReadOnlyList<SwitchSection> (sections);
}
+ /**
+ * Returns if all labels can be deduced into a constant
+ *
+ * @return if all labels can be deduced into a constant
+ */
+ public bool is_all_constant() {
+ return _is_all_constant;
+ }
+
public override void accept (CodeVisitor visitor) {
visitor.visit_switch_statement (this);
}
@@ -116,8 +126,18 @@ public class Vala.SwitchStatement : CodeNode, Statement {
foreach (SwitchSection section in sections) {
section.check (analyzer);
+ if(section.is_all_constant() == false) {
+ _is_all_constant = false;
+ }
}
+ if(!_is_all_constant
+ && !expression.value_type.compatible (analyzer.string_type)) {
+ Report.error (expression.source_reference,
+ "Non-constant case labels are not yet supported");
+ error = true;
+ return false;
+ }
return !error;
}
}
--
1.6.0.6
>From 9f33660b0794813e08757b3554561c92fd1b7c73 Mon Sep 17 00:00:00 2001
From: Yu Feng <[email protected]>
Date: Fri, 26 Jun 2009 10:36:49 +0800
Subject: [PATCH] Add type_id_const CCode attribute
added to class enum struct, specifying whether the type_id is const or not
---
vala/valaclass.vala | 5 +++++
vala/valaenum.vala | 5 +++++
vala/valastruct.vala | 5 +++++
3 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index 51efba3..284b631 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -103,6 +103,8 @@ public class Vala.Class : ObjectTypeSymbol {
*/
public bool has_class_private_fields { get; private set; }
+ public bool type_id_const { get; private set; default = false; }
+
private string cname;
private string const_cname;
private string lower_case_cprefix;
@@ -630,6 +632,9 @@ public class Vala.Class : ObjectTypeSymbol {
if (a.has_argument ("type_id")) {
type_id = a.get_string ("type_id");
}
+ if (a.has_argument ("type_id_const")) {
+ type_id_const = a.get_bool ("type_id_const");
+ }
if (a.has_argument ("marshaller_type_name")) {
marshaller_type_name = a.get_string ("marshaller_type_name");
}
diff --git a/vala/valaenum.vala b/vala/valaenum.vala
index 1d1e8c1..25c5cfe 100644
--- a/vala/valaenum.vala
+++ b/vala/valaenum.vala
@@ -37,6 +37,8 @@ public class Vala.Enum : TypeSymbol {
*/
public bool has_type_id { get; set; default = true; }
+ public bool type_id_const { get; private set; default = false; }
+
private Gee.List<EnumValue> values = new ArrayList<EnumValue> ();
private Gee.List<Method> methods = new ArrayList<Method> ();
private string cname;
@@ -198,6 +200,9 @@ public class Vala.Enum : TypeSymbol {
if (a.has_argument ("has_type_id")) {
has_type_id = a.get_bool ("has_type_id");
}
+ if (a.has_argument ("type_id_const")) {
+ type_id_const = a.get_bool ("type_id_const");
+ }
if (a.has_argument ("type_id")) {
type_id = a.get_string ("type_id");
}
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index 166edba..0efb222 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -91,6 +91,8 @@ public class Vala.Struct : TypeSymbol {
*/
public bool has_type_id { get; set; default = true; }
+ public bool type_id_const { get; private set; default = false; }
+
public int width { get; set; default = 32; }
public bool signed { get; set; default = true; }
@@ -380,6 +382,9 @@ public class Vala.Struct : TypeSymbol {
if (a.has_argument ("type_id")) {
set_type_id (a.get_string ("type_id"));
}
+ if (a.has_argument ("type_id_const")) {
+ type_id_const = a.get_bool ("type_id_const");
+ }
if (a.has_argument ("marshaller_type_name")) {
set_marshaller_type_name (a.get_string ("marshaller_type_name"));
}
--
1.6.0.6
>From 1bedb9c1c2c4a9240f1d0fa37d046f1298bd4a19 Mon Sep 17 00:00:00 2001
From: Yu Feng <[email protected]>
Date: Fri, 26 Jun 2009 10:37:04 +0800
Subject: [PATCH] type_id_const for glib internal types
---
vapi/glib-2.0.vapi | 40 ++++++++++++++++++++--------------------
vapi/gobject-2.0.vapi | 10 +++++-----
2 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 56e8839..b08ec31 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -29,7 +29,7 @@
*/
[SimpleType]
-[CCode (cname = "gboolean", cheader_filename = "glib.h", type_id = "G_TYPE_BOOLEAN", marshaller_type_name = "BOOLEAN", get_value_function = "g_value_get_boolean", set_value_function = "g_value_set_boolean", default_value = "FALSE", type_signature = "b")]
+[CCode (cname = "gboolean", cheader_filename = "glib.h", type_id = "G_TYPE_BOOLEAN", type_id_const = true, marshaller_type_name = "BOOLEAN", get_value_function = "g_value_get_boolean", set_value_function = "g_value_set_boolean", default_value = "FALSE", type_signature = "b")]
[BooleanType]
public struct bool {
public string to_string () {
@@ -42,7 +42,7 @@ public struct bool {
}
[SimpleType]
-[CCode (cname = "gchar", cprefix = "g_ascii_", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char", default_value = "\'\\0\'", type_signature = "y")]
+[CCode (cname = "gchar", cprefix = "g_ascii_", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", type_id_const = true, marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char", default_value = "\'\\0\'", type_signature = "y")]
[IntegerType (rank = 2, min = 0, max = 127)]
public struct char {
[CCode (cname = "g_strdup_printf", instance_pos = -1)]
@@ -72,7 +72,7 @@ public struct char {
}
[SimpleType]
-[CCode (cname = "guchar", cheader_filename = "glib.h", type_id = "G_TYPE_UCHAR", marshaller_type_name = "UCHAR", get_value_function = "g_value_get_uchar", set_value_function = "g_value_set_uchar", default_value = "\'\\0\'")]
+[CCode (cname = "guchar", cheader_filename = "glib.h", type_id = "G_TYPE_UCHAR", type_id_const = true, marshaller_type_name = "UCHAR", get_value_function = "g_value_get_uchar", set_value_function = "g_value_set_uchar", default_value = "\'\\0\'")]
[IntegerType (rank = 3, min = 0, max = 255)]
public struct uchar {
[CCode (cname = "g_strdup_printf", instance_pos = -1)]
@@ -123,7 +123,7 @@ public struct int {
}
[SimpleType]
-[CCode (cname = "guint", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")]
+[CCode (cname = "guint", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", type_id_const = true, marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")]
[IntegerType (rank = 7)]
public struct uint {
[CCode (cname = "0")]
@@ -196,7 +196,7 @@ public struct ushort {
}
[SimpleType]
-[CCode (cname = "glong", cheader_filename = "glib.h", type_id = "G_TYPE_LONG", marshaller_type_name = "LONG", get_value_function = "g_value_get_long", set_value_function = "g_value_set_long", default_value = "0L")]
+[CCode (cname = "glong", cheader_filename = "glib.h", type_id = "G_TYPE_LONG", type_id_const = true, marshaller_type_name = "LONG", get_value_function = "g_value_get_long", set_value_function = "g_value_set_long", default_value = "0L")]
[IntegerType (rank = 8)]
public struct long {
[CCode (cname = "G_MINLONG")]
@@ -228,7 +228,7 @@ public struct long {
}
[SimpleType]
-[CCode (cname = "gulong", cheader_filename = "glib.h", type_id = "G_TYPE_ULONG", marshaller_type_name = "ULONG", get_value_function = "g_value_get_ulong", set_value_function = "g_value_set_ulong", default_value = "0UL")]
+[CCode (cname = "gulong", cheader_filename = "glib.h", type_id = "G_TYPE_ULONG", type_id_const = true, marshaller_type_name = "ULONG", get_value_function = "g_value_get_ulong", set_value_function = "g_value_set_ulong", default_value = "0UL")]
[IntegerType (rank = 9)]
public struct ulong {
[CCode (cname = "0UL")]
@@ -258,7 +258,7 @@ public struct ulong {
}
[SimpleType]
-[CCode (cname = "gsize", cheader_filename = "glib.h", type_id = "G_TYPE_ULONG", marshaller_type_name = "ULONG", get_value_function = "g_value_get_ulong", set_value_function = "g_value_set_ulong", default_value = "0UL")]
+[CCode (cname = "gsize", cheader_filename = "glib.h", type_id = "G_TYPE_ULONG", type_id_const = true, marshaller_type_name = "ULONG", get_value_function = "g_value_get_ulong", set_value_function = "g_value_set_ulong", default_value = "0UL")]
[IntegerType (rank = 9)]
public struct size_t {
[CCode (cname = "0UL")]
@@ -286,7 +286,7 @@ public struct size_t {
}
[SimpleType]
-[CCode (cname = "gssize", cheader_filename = "glib.h", type_id = "G_TYPE_LONG", marshaller_type_name = "LONG", get_value_function = "g_value_get_long", set_value_function = "g_value_set_long", default_value = "0L")]
+[CCode (cname = "gssize", cheader_filename = "glib.h", type_id = "G_TYPE_LONG", type_id_const = true, marshaller_type_name = "LONG", get_value_function = "g_value_get_long", set_value_function = "g_value_set_long", default_value = "0L")]
[IntegerType (rank = 8)]
public struct ssize_t {
[CCode (cname = "G_MINSSIZE")]
@@ -311,7 +311,7 @@ public struct ssize_t {
}
[SimpleType]
-[CCode (cname = "gint8", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char", default_value = "0", type_signature = "y")]
+[CCode (cname = "gint8", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", type_id_const = true, marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char", default_value = "0", type_signature = "y")]
[IntegerType (rank = 1, min = -128, max = 127)]
public struct int8 {
[CCode (cname = "G_MININT8")]
@@ -331,7 +331,7 @@ public struct int8 {
}
[SimpleType]
-[CCode (cname = "guint8", cheader_filename = "glib.h", type_id = "G_TYPE_UCHAR", marshaller_type_name = "UCHAR", get_value_function = "g_value_get_uchar", set_value_function = "g_value_set_uchar", default_value = "0U", type_signature = "y")]
+[CCode (cname = "guint8", cheader_filename = "glib.h", type_id = "G_TYPE_UCHAR", type_id_const = true, marshaller_type_name = "UCHAR", get_value_function = "g_value_get_uchar", set_value_function = "g_value_set_uchar", default_value = "0U", type_signature = "y")]
[IntegerType (rank = 3, min = 0, max = 255)]
public struct uint8 {
[CCode (cname = "0U")]
@@ -421,7 +421,7 @@ public struct uint16 {
}
[SimpleType]
-[CCode (cname = "gint32", cheader_filename = "glib.h", type_id = "G_TYPE_INT", marshaller_type_name = "INT", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int", default_value = "0", type_signature = "i")]
+[CCode (cname = "gint32", cheader_filename = "glib.h", type_id = "G_TYPE_INT", type_id_const = true, marshaller_type_name = "INT", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int", default_value = "0", type_signature = "i")]
[IntegerType (rank = 6)]
public struct int32 {
[CCode (cname = "G_MININT32")]
@@ -456,7 +456,7 @@ public struct int32 {
}
[SimpleType]
-[CCode (cname = "guint32", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")]
+[CCode (cname = "guint32", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", type_id_const = true, marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")]
[IntegerType (rank = 7)]
public struct uint32 {
[CCode (cname = "0U")]
@@ -491,7 +491,7 @@ public struct uint32 {
}
[SimpleType]
-[CCode (cname = "gint64", cheader_filename = "glib.h", type_id = "G_TYPE_INT64", marshaller_type_name = "INT64", get_value_function = "g_value_get_int64", set_value_function = "g_value_set_int64", default_value = "0LL", type_signature = "x")]
+[CCode (cname = "gint64", cheader_filename = "glib.h", type_id = "G_TYPE_INT64", type_id_const = true, marshaller_type_name = "INT64", get_value_function = "g_value_get_int64", set_value_function = "g_value_set_int64", default_value = "0LL", type_signature = "x")]
[IntegerType (rank = 10)]
public struct int64 {
[CCode (cname = "G_MININT64")]
@@ -528,7 +528,7 @@ public struct int64 {
}
[SimpleType]
-[CCode (cname = "guint64", cheader_filename = "glib.h", type_id = "G_TYPE_UINT64", marshaller_type_name = "UINT64", get_value_function = "g_value_get_uint64", set_value_function = "g_value_set_uint64", default_value = "0ULL", type_signature = "t")]
+[CCode (cname = "guint64", cheader_filename = "glib.h", type_id = "G_TYPE_UINT64", type_id_const = true, marshaller_type_name = "UINT64", get_value_function = "g_value_get_uint64", set_value_function = "g_value_set_uint64", default_value = "0ULL", type_signature = "t")]
[IntegerType (rank = 11)]
public struct uint64 {
[CCode (cname = "0ULL")]
@@ -563,7 +563,7 @@ public struct uint64 {
}
[SimpleType]
-[CCode (cname = "float", cheader_filename = "glib.h,float.h,math.h", type_id = "G_TYPE_FLOAT", marshaller_type_name = "FLOAT", get_value_function = "g_value_get_float", set_value_function = "g_value_set_float", default_value = "0.0F")]
+[CCode (cname = "float", cheader_filename = "glib.h,float.h,math.h", type_id = "G_TYPE_FLOAT", type_id_const = true, marshaller_type_name = "FLOAT", get_value_function = "g_value_get_float", set_value_function = "g_value_set_float", default_value = "0.0F")]
[FloatingType (rank = 1)]
public struct float {
[CCode (cname = "FLT_MANT_DIG")]
@@ -614,7 +614,7 @@ public struct float {
}
[SimpleType]
-[CCode (cname = "double", cheader_filename = "glib.h,float.h,math.h", type_id = "G_TYPE_DOUBLE", marshaller_type_name = "DOUBLE", get_value_function = "g_value_get_double", set_value_function = "g_value_set_double", default_value = "0.0", type_signature = "d")]
+[CCode (cname = "double", cheader_filename = "glib.h,float.h,math.h", type_id = "G_TYPE_DOUBLE", type_id_const = true, marshaller_type_name = "DOUBLE", get_value_function = "g_value_get_double", set_value_function = "g_value_set_double", default_value = "0.0", type_signature = "d")]
[FloatingType (rank = 2)]
public struct double {
[CCode (cname = "DBL_MANT_DIG")]
@@ -673,7 +673,7 @@ public struct time_t {
}
[SimpleType]
-[CCode (cname = "gunichar", cprefix = "g_unichar_", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")]
+[CCode (cname = "gunichar", cprefix = "g_unichar_", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", type_id_const = true, marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U", type_signature = "u")]
[IntegerType (rank = 7)]
public struct unichar {
public bool validate ();
@@ -800,7 +800,7 @@ public enum NormalizeMode {
[Compact]
[Immutable]
-[CCode (cname = "char", const_cname = "const char", copy_function = "g_strdup", free_function = "g_free", cheader_filename = "stdlib.h,string.h,glib.h", type_id = "G_TYPE_STRING", marshaller_type_name = "STRING", get_value_function = "g_value_get_string", set_value_function = "g_value_set_string", type_signature = "s")]
+[CCode (cname = "char", const_cname = "const char", copy_function = "g_strdup", free_function = "g_free", cheader_filename = "stdlib.h,string.h,glib.h", type_id = "G_TYPE_STRING", type_id_const = true, marshaller_type_name = "STRING", get_value_function = "g_value_get_string", set_value_function = "g_value_set_string", type_signature = "s")]
public class string {
[CCode (cname = "strstr")]
public weak string? str (string needle);
@@ -3119,7 +3119,7 @@ namespace GLib {
/* Hash Tables */
[Compact]
- [CCode (ref_function = "g_hash_table_ref", unref_function = "g_hash_table_unref", type_id = "G_TYPE_HASH_TABLE", type_signature = "a{%s}")]
+ [CCode (ref_function = "g_hash_table_ref", unref_function = "g_hash_table_unref", type_id = "G_TYPE_HASH_TABLE", type_id_const = true, type_signature = "a{%s}")]
public class HashTable<K,V> : Boxed {
public HashTable (HashFunc? hash_func, EqualFunc? key_equal_func);
public HashTable.full (HashFunc? hash_func, EqualFunc? key_equal_func, DestroyNotify? key_destroy_func, DestroyNotify? value_destroy_func);
@@ -3168,7 +3168,7 @@ namespace GLib {
/* Strings */
[Compact]
- [CCode (cname = "GString", cprefix = "g_string_", free_function = "g_string_free", type_id = "G_TYPE_GSTRING")]
+ [CCode (cname = "GString", cprefix = "g_string_", free_function = "g_string_free", type_id = "G_TYPE_GSTRING", type_id_const = true)]
public class StringBuilder : Boxed {
public StringBuilder (string init = "");
[CCode (cname = "g_string_sized_new")]
diff --git a/vapi/gobject-2.0.vapi b/vapi/gobject-2.0.vapi
index d902452..7815908 100644
--- a/vapi/gobject-2.0.vapi
+++ b/vapi/gobject-2.0.vapi
@@ -27,7 +27,7 @@
[CCode (cprefix = "G", lower_case_cprefix = "g_", cheader_filename = "glib.h")]
namespace GLib {
[SimpleType]
- [CCode (type_id = "G_TYPE_GTYPE", marshaller_type_name = "GTYPE", get_value_function = "g_value_get_gtype", set_value_function = "g_value_set_gtype")]
+ [CCode (type_id = "G_TYPE_GTYPE", type_id_const = true, marshaller_type_name = "GTYPE", get_value_function = "g_value_get_gtype", set_value_function = "g_value_set_gtype")]
[IntegerType (rank = 9)]
public struct Type {
[CCode (cname = "G_TYPE_IS_OBJECT")]
@@ -172,7 +172,7 @@ namespace GLib {
public static delegate void ObjectSetPropertyFunc (Object object, uint property_id, Value value, ParamSpec pspec);
public static delegate void WeakNotify (void *data, Object object);
- [CCode (ref_function = "g_object_ref", unref_function = "g_object_unref", marshaller_type_name = "OBJECT", get_value_function = "g_value_get_object", set_value_function = "g_value_set_object", param_spec_function = "g_param_spec_object", cheader_filename = "glib-object.h")]
+ [CCode (ref_function = "g_object_ref", unref_function = "g_object_unref", marshaller_type_name = "OBJECT", get_value_function = "g_value_get_object", set_value_function = "g_value_set_object", param_spec_function = "g_param_spec_object", cheader_filename = "glib-object.h", type_id_const = true)]
public class Object {
public uint ref_count;
@@ -254,13 +254,13 @@ namespace GLib {
}
[Compact]
- [CCode (cname = "gpointer", has_type_id = true, type_id = "G_TYPE_BOXED", marshaller_type_name = "BOXED", get_value_function = "g_value_get_boxed", set_value_function = "g_value_set_boxed")]
+ [CCode (cname = "gpointer", has_type_id = true, type_id = "G_TYPE_BOXED", type_id_const = true, marshaller_type_name = "BOXED", get_value_function = "g_value_get_boxed", set_value_function = "g_value_set_boxed")]
public abstract class Boxed {
}
public static delegate void ValueTransform (Value src_value, out Value dest_value);
- [CCode (copy_function = "g_value_copy", destroy_function = "g_value_unset", type_id = "G_TYPE_VALUE", marshaller_type_name = "BOXED", get_value_function = "g_value_get_boxed", set_value_function = "g_value_set_boxed", type_signature = "v")]
+ [CCode (copy_function = "g_value_copy", destroy_function = "g_value_unset", type_id = "G_TYPE_VALUE", type_id_const = true, marshaller_type_name = "BOXED", get_value_function = "g_value_get_boxed", set_value_function = "g_value_set_boxed", type_signature = "v")]
public struct Value {
[CCode (cname = "G_VALUE_HOLDS")]
public bool holds (Type type);
@@ -360,7 +360,7 @@ namespace GLib {
public static delegate void ClosureNotify (void* data, Closure closure);
[Compact]
- [CCode (type_id = "G_TYPE_VALUE_ARRAY")]
+ [CCode (type_id = "G_TYPE_VALUE_ARRAY", type_id_const = true)]
public class ValueArray : Boxed {
public uint n_values;
public Value[] values;
--
1.6.0.6
>From 4351b1448d5036c5087e954ca84246a9bb4012a0 Mon Sep 17 00:00:00 2001
From: Yu Feng <[email protected]>
Date: Fri, 26 Jun 2009 10:37:32 +0800
Subject: [PATCH] Deduce whether the typeof expression is const
---
vala/valatypeofexpression.vala | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/vala/valatypeofexpression.vala b/vala/valatypeofexpression.vala
index 99d9145..76b49a7 100644
--- a/vala/valatypeofexpression.vala
+++ b/vala/valatypeofexpression.vala
@@ -39,6 +39,7 @@ public class Vala.TypeofExpression : Expression {
private DataType _data_type;
+ private bool _is_constant = false;
/**
* Creates a new typeof expression.
*
@@ -78,8 +79,25 @@ public class Vala.TypeofExpression : Expression {
type_reference.check (analyzer);
+ _is_constant = false;
+ if(type_reference.data_type is Class) {
+ var cl = type_reference.data_type as Class;
+ _is_constant = cl.type_id_const;
+ }
+ if(type_reference.data_type is Struct) {
+ var st = type_reference.data_type as Struct;
+ _is_constant = st.type_id_const;
+ }
+ if(type_reference.data_type is Enum) {
+ var en = type_reference.data_type as Enum;
+ _is_constant = en.type_id_const;
+ }
value_type = analyzer.type_type;
return !error;
}
+
+ public override bool is_constant() {
+ return _is_constant;
+ }
}
--
1.6.0.6
const int ONE = 1;
const int TWO = 2;
void func() {
int t = 0;
switch(t) {
case ONE:
case TWO:
break;
default:
break;
}
}
enum ENU {
ONE,
TWO
}
void func() {
ENU s = ENU.ONE;
switch(s) {
case ENU.ONE:
case ENU.TWO:
break;
default:
break;
}
}
void func() {
int s = 1;
switch(s) {
case 1:
case 2:
break;
default:
break;
}
}
void func() {
string s = "shit";
switch(s) {
case "1":
case "2":
break;
default:
break;
}
}
class TestType : Object {}
void func() {
Type t = Type.INVALID;
switch(t) {
case typeof(string):
case typeof(Object):
case typeof(TestType):
break;
default:
break;
}
}
void func() {
Type t = Type.INVALID;
switch(t) {
case typeof(string):
case typeof(Object):
break;
default:
break;
}
}
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list