[vala/staging] codegen: Emit constants without initializer list in defines section
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Emit constants without initializer list in defines section
- Date: Sun, 7 Nov 2021 16:31:45 +0000 (UTC)
commit f38fdde7e837251093a7dadab95dc576712a9fc7
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Nov 7 16:31:47 2021 +0100
codegen: Emit constants without initializer list in defines section
Fixes https://gitlab.gnome.org/GNOME/vala/issues/440
codegen/valaccodebasemodule.vala | 4 +-
tests/Makefile.am | 5 +
.../fixed-length-init0-not-allowed.c-expected | 3 +-
tests/basic-types/arrays.c-expected | 2 +-
tests/basic-types/bug648364.c-expected | 3 +-
tests/basic-types/bug756376.c-expected | 2 +-
tests/basic-types/sizeof.c-expected | 5 +-
tests/constants/strings.c-expected | 1 +
tests/control-flow/switch-string.c-expected | 6 +-
tests/enums/enums.c-expected | 2 +-
tests/genie/constant.c-expected | 3 +-
tests/methods/bug642350.c-expected | 2 +-
tests/ordering/constant-class.c-expected | 326 +++++++++++++++++++++
tests/ordering/constant-class.vala | 19 ++
tests/ordering/constant-constant.c-expected | 31 ++
tests/ordering/constant-constant.vala | 10 +
tests/ordering/constant-enum.c-expected | 65 ++++
tests/ordering/constant-enum.vala | 9 +
tests/ordering/constant-field.c-expected | 43 +++
tests/ordering/constant-field.vala | 9 +
tests/ordering/constant-struct.c-expected | 88 ++++++
tests/ordering/constant-struct.vala | 10 +
tests/posix/arrays.c-expected | 2 +-
.../member-access-static-with-instance.c-expected | 4 +-
24 files changed, 637 insertions(+), 17 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index c31c55a1f..409ebba6c 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1106,8 +1106,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
add_symbol_declaration (decl_space, m, get_ccode_name (m));
}
- var cdefine = new CCodeMacroReplacement.with_expression (get_ccode_name (c),
get_cvalue (c.value));
- decl_space.add_type_member_declaration (cdefine);
+ var cdefine = new CCodeDefine.with_expression (get_ccode_name (c), get_cvalue
(c.value));
+ decl_space.add_define (cdefine);
}
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f412d641b..9b917dea2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -955,6 +955,11 @@ TESTS = \
resolver/peek-inner-types-ambiguous.test \
resolver/peek-inner-types.vala \
resolver/struct-base-cycle.test \
+ ordering/constant-class.vala \
+ ordering/constant-constant.vala \
+ ordering/constant-enum.vala \
+ ordering/constant-field.vala \
+ ordering/constant-struct.vala \
ordering/delegate-class.vala \
ordering/delegate-enum.vala \
ordering/delegate-interface.vala \
diff --git a/tests/arrays/fixed-length-init0-not-allowed.c-expected
b/tests/arrays/fixed-length-init0-not-allowed.c-expected
index d201b5660..4bf72a2f7 100644
--- a/tests/arrays/fixed-length-init0-not-allowed.c-expected
+++ b/tests/arrays/fixed-length-init0-not-allowed.c-expected
@@ -4,12 +4,13 @@
#include <glib.h>
#include <string.h>
+#define BAR 1024
+
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN,
G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
-#define BAR 1024
static void _vala_main (void);
static void _vala_array_destroy (gpointer array,
gssize array_length,
diff --git a/tests/basic-types/arrays.c-expected b/tests/basic-types/arrays.c-expected
index e760db8c1..ec9664488 100644
--- a/tests/basic-types/arrays.c-expected
+++ b/tests/basic-types/arrays.c-expected
@@ -6,6 +6,7 @@
#include <stdlib.h>
#include <glib-object.h>
+#define FOO 2
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
@@ -91,7 +92,6 @@ VALA_EXTERN gint* pass_helper (gint* a,
static gint* _vala_array_dup8 (gint* self,
gssize length);
VALA_EXTERN void test_array_pass (void);
-#define FOO 2
VALA_EXTERN void test_static_array (void);
VALA_EXTERN void test_reference_transfer (void);
VALA_EXTERN void test_length_assignment (void);
diff --git a/tests/basic-types/bug648364.c-expected b/tests/basic-types/bug648364.c-expected
index 9e295633c..69d7e181f 100644
--- a/tests/basic-types/bug648364.c-expected
+++ b/tests/basic-types/bug648364.c-expected
@@ -4,9 +4,10 @@
#include <glib.h>
#include <string.h>
+#define foo 3
+
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
-#define foo 3
static void _vala_main (void);
static gint* _int_dup (gint* self);
diff --git a/tests/basic-types/bug756376.c-expected b/tests/basic-types/bug756376.c-expected
index 8403cbcaf..773d6921c 100644
--- a/tests/basic-types/bug756376.c-expected
+++ b/tests/basic-types/bug756376.c-expected
@@ -3,6 +3,7 @@
#include <glib.h>
+#define FOO_BAR 5
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
@@ -13,7 +14,6 @@
#endif
#endif
-#define FOO_BAR 5
VALA_EXTERN void bar (gint* a,
gint a_length1);
static void _vala_main (void);
diff --git a/tests/basic-types/sizeof.c-expected b/tests/basic-types/sizeof.c-expected
index 5b39d707b..1beba725b 100644
--- a/tests/basic-types/sizeof.c-expected
+++ b/tests/basic-types/sizeof.c-expected
@@ -3,13 +3,14 @@
#include <glib.h>
+#define simple_size ((gsize) sizeof (gint))
+#define composed_size ((gsize) (sizeof (gint) + sizeof (gsize)))
+
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN,
G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
-#define simple_size ((gsize) sizeof (gint))
-#define composed_size ((gsize) (sizeof (gint) + sizeof (gsize)))
static void _vala_main (void);
static void
diff --git a/tests/constants/strings.c-expected b/tests/constants/strings.c-expected
index 812a169ff..f0bb50459 100644
--- a/tests/constants/strings.c-expected
+++ b/tests/constants/strings.c-expected
@@ -8,6 +8,7 @@
#define FOO "string constant"
#define BAR _ ("translated string constant")
+
static void _vala_main (void);
static void
diff --git a/tests/control-flow/switch-string.c-expected b/tests/control-flow/switch-string.c-expected
index 6a1a1b015..dea8a5d73 100644
--- a/tests/control-flow/switch-string.c-expected
+++ b/tests/control-flow/switch-string.c-expected
@@ -5,6 +5,9 @@
#include <string.h>
#include <glib.h>
+#define FOO "foo"
+#define BAR "bar"
+#define MANAM "manam"
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
@@ -21,9 +24,6 @@
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
-#define FOO "foo"
-#define BAR "bar"
-#define MANAM "manam"
VALA_EXTERN gchar* foo (void);
VALA_EXTERN gchar* get_bar (void);
VALA_EXTERN gchar* bar (void);
diff --git a/tests/enums/enums.c-expected b/tests/enums/enums.c-expected
index fc6dd0197..bef176eac 100644
--- a/tests/enums/enums.c-expected
+++ b/tests/enums/enums.c-expected
@@ -5,6 +5,7 @@
#include <glib.h>
#include <stdio.h>
+#define MAMAN_FOOISH_FOO 2
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
@@ -60,7 +61,6 @@ static gpointer maman_bar_parent_class = NULL;
VALA_EXTERN GType maman_foo_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType maman_fooish_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gint maman_fooish_something (MamanFooish self);
-#define MAMAN_FOOISH_FOO 2
VALA_EXTERN GType maman_bar_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MamanBar, g_object_unref)
VALA_EXTERN void maman_bar_run (MamanBar* self);
diff --git a/tests/genie/constant.c-expected b/tests/genie/constant.c-expected
index 66743ce3b..24099c0fc 100644
--- a/tests/genie/constant.c-expected
+++ b/tests/genie/constant.c-expected
@@ -5,6 +5,8 @@
#include <string.h>
#include <glib.h>
+#define TEST 23
+
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN,
G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
@@ -12,7 +14,6 @@
static void _vala_main (gchar** args,
gint args_length1);
-#define TEST 23
static void
_vala_main (gchar** args,
diff --git a/tests/methods/bug642350.c-expected b/tests/methods/bug642350.c-expected
index 98ebea8be..749255e04 100644
--- a/tests/methods/bug642350.c-expected
+++ b/tests/methods/bug642350.c-expected
@@ -7,6 +7,7 @@
#include <glib/gi18n-lib.h>
#include <glib-object.h>
+#define BAZ N_ ("bar")
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
@@ -61,7 +62,6 @@ static gpointer bar_parent_class = NULL;
VALA_EXTERN gchar* bar_foo;
gchar* bar_foo = NULL;
-#define BAZ N_ ("bar")
VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ;
VALA_EXTERN Foo* foo_dup (const Foo* self);
VALA_EXTERN void foo_free (Foo* self);
diff --git a/tests/ordering/constant-class.c-expected b/tests/ordering/constant-class.c-expected
new file mode 100644
index 000000000..312b74812
--- /dev/null
+++ b/tests/ordering/constant-class.c-expected
@@ -0,0 +1,326 @@
+/* ordering_constant_class.c generated by valac, the Vala compiler
+ * generated from ordering_constant_class.vala, do not modify */
+
+#include <glib-object.h>
+#include <glib.h>
+#include <gobject/gvaluecollector.h>
+
+#define FOO 42
+#if !defined(VALA_EXTERN)
+#if defined(_MSC_VER)
+#define VALA_EXTERN __declspec(dllexport) extern
+#elif __GNUC__ >= 4
+#define VALA_EXTERN __attribute__((visibility("default"))) extern
+#else
+#define VALA_EXTERN extern
+#endif
+#endif
+
+#define TYPE_FOOCLASS (fooclass_get_type ())
+#define FOOCLASS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOOCLASS, FooClass))
+#define FOOCLASS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOOCLASS, FooClassClass))
+#define IS_FOOCLASS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FOOCLASS))
+#define IS_FOOCLASS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FOOCLASS))
+#define FOOCLASS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FOOCLASS, FooClassClass))
+
+typedef struct _FooClass FooClass;
+typedef struct _FooClassClass FooClassClass;
+typedef struct _FooClassPrivate FooClassPrivate;
+typedef struct _ParamSpecFooClass ParamSpecFooClass;
+#define _fooclass_unref0(var) ((var == NULL) ? NULL : (var = (fooclass_unref (var), NULL)))
+#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
+#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN,
G_STRFUNC, msg); return; }
+#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
+#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
+
+struct _FooClass {
+ GTypeInstance parent_instance;
+ volatile int ref_count;
+ FooClassPrivate * priv;
+ gint field;
+ gint array[FOO];
+};
+
+struct _FooClassClass {
+ GTypeClass parent_class;
+ void (*finalize) (FooClass *self);
+};
+
+struct _FooClassPrivate {
+ gint pfield;
+ gint parray[FOO];
+};
+
+struct _ParamSpecFooClass {
+ GParamSpec parent_instance;
+};
+
+static gint FooClass_private_offset;
+static gpointer fooclass_parent_class = NULL;
+
+VALA_EXTERN gpointer fooclass_ref (gpointer instance);
+VALA_EXTERN void fooclass_unref (gpointer instance);
+VALA_EXTERN GParamSpec* param_spec_fooclass (const gchar* name,
+ const gchar* nick,
+ const gchar* blurb,
+ GType object_type,
+ GParamFlags flags);
+VALA_EXTERN void value_set_fooclass (GValue* value,
+ gpointer v_object);
+VALA_EXTERN void value_take_fooclass (GValue* value,
+ gpointer v_object);
+VALA_EXTERN gpointer value_get_fooclass (const GValue* value);
+VALA_EXTERN GType fooclass_get_type (void) G_GNUC_CONST ;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (FooClass, fooclass_unref)
+VALA_EXTERN FooClass* fooclass_new (void);
+VALA_EXTERN FooClass* fooclass_construct (GType object_type);
+static void fooclass_finalize (FooClass * obj);
+static GType fooclass_get_type_once (void);
+static void _vala_main (void);
+
+static inline gpointer
+fooclass_get_instance_private (FooClass* self)
+{
+ return G_STRUCT_MEMBER_P (self, FooClass_private_offset);
+}
+
+FooClass*
+fooclass_construct (GType object_type)
+{
+ FooClass* self = NULL;
+ self = (FooClass*) g_type_create_instance (object_type);
+ _vala_assert (self->priv->pfield == 42, "pfield == 42");
+ _vala_assert (FOO == 42, "parray.length == 42");
+ return self;
+}
+
+FooClass*
+fooclass_new (void)
+{
+ return fooclass_construct (TYPE_FOOCLASS);
+}
+
+static void
+value_fooclass_init (GValue* value)
+{
+ value->data[0].v_pointer = NULL;
+}
+
+static void
+value_fooclass_free_value (GValue* value)
+{
+ if (value->data[0].v_pointer) {
+ fooclass_unref (value->data[0].v_pointer);
+ }
+}
+
+static void
+value_fooclass_copy_value (const GValue* src_value,
+ GValue* dest_value)
+{
+ if (src_value->data[0].v_pointer) {
+ dest_value->data[0].v_pointer = fooclass_ref (src_value->data[0].v_pointer);
+ } else {
+ dest_value->data[0].v_pointer = NULL;
+ }
+}
+
+static gpointer
+value_fooclass_peek_pointer (const GValue* value)
+{
+ return value->data[0].v_pointer;
+}
+
+static gchar*
+value_fooclass_collect_value (GValue* value,
+ guint n_collect_values,
+ GTypeCValue* collect_values,
+ guint collect_flags)
+{
+ if (collect_values[0].v_pointer) {
+ FooClass * object;
+ object = collect_values[0].v_pointer;
+ if (object->parent_instance.g_class == NULL) {
+ return g_strconcat ("invalid unclassed object pointer for value type `",
G_VALUE_TYPE_NAME (value), "'", NULL);
+ } else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
+ return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE
(object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
+ }
+ value->data[0].v_pointer = fooclass_ref (object);
+ } else {
+ value->data[0].v_pointer = NULL;
+ }
+ return NULL;
+}
+
+static gchar*
+value_fooclass_lcopy_value (const GValue* value,
+ guint n_collect_values,
+ GTypeCValue* collect_values,
+ guint collect_flags)
+{
+ FooClass ** object_p;
+ object_p = collect_values[0].v_pointer;
+ if (!object_p) {
+ return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
+ }
+ if (!value->data[0].v_pointer) {
+ *object_p = NULL;
+ } else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
+ *object_p = value->data[0].v_pointer;
+ } else {
+ *object_p = fooclass_ref (value->data[0].v_pointer);
+ }
+ return NULL;
+}
+
+GParamSpec*
+param_spec_fooclass (const gchar* name,
+ const gchar* nick,
+ const gchar* blurb,
+ GType object_type,
+ GParamFlags flags)
+{
+ ParamSpecFooClass* spec;
+ g_return_val_if_fail (g_type_is_a (object_type, TYPE_FOOCLASS), NULL);
+ spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
+ G_PARAM_SPEC (spec)->value_type = object_type;
+ return G_PARAM_SPEC (spec);
+}
+
+gpointer
+value_get_fooclass (const GValue* value)
+{
+ g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_FOOCLASS), NULL);
+ return value->data[0].v_pointer;
+}
+
+void
+value_set_fooclass (GValue* value,
+ gpointer v_object)
+{
+ FooClass * old;
+ g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_FOOCLASS));
+ old = value->data[0].v_pointer;
+ if (v_object) {
+ g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_FOOCLASS));
+ g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE
(value)));
+ value->data[0].v_pointer = v_object;
+ fooclass_ref (value->data[0].v_pointer);
+ } else {
+ value->data[0].v_pointer = NULL;
+ }
+ if (old) {
+ fooclass_unref (old);
+ }
+}
+
+void
+value_take_fooclass (GValue* value,
+ gpointer v_object)
+{
+ FooClass * old;
+ g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_FOOCLASS));
+ old = value->data[0].v_pointer;
+ if (v_object) {
+ g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_FOOCLASS));
+ g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE
(value)));
+ value->data[0].v_pointer = v_object;
+ } else {
+ value->data[0].v_pointer = NULL;
+ }
+ if (old) {
+ fooclass_unref (old);
+ }
+}
+
+static void
+fooclass_class_init (FooClassClass * klass,
+ gpointer klass_data)
+{
+ fooclass_parent_class = g_type_class_peek_parent (klass);
+ ((FooClassClass *) klass)->finalize = fooclass_finalize;
+ g_type_class_adjust_private_offset (klass, &FooClass_private_offset);
+}
+
+static void
+fooclass_instance_init (FooClass * self,
+ gpointer klass)
+{
+ self->priv = fooclass_get_instance_private (self);
+ self->field = FOO;
+ self->priv->pfield = FOO;
+ self->ref_count = 1;
+}
+
+static void
+fooclass_finalize (FooClass * obj)
+{
+ FooClass * self;
+ self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FOOCLASS, FooClass);
+ g_signal_handlers_destroy (self);
+}
+
+static GType
+fooclass_get_type_once (void)
+{
+ static const GTypeValueTable g_define_type_value_table = { value_fooclass_init,
value_fooclass_free_value, value_fooclass_copy_value, value_fooclass_peek_pointer, "p",
value_fooclass_collect_value, "p", value_fooclass_lcopy_value };
+ static const GTypeInfo g_define_type_info = { sizeof (FooClassClass), (GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL, (GClassInitFunc) fooclass_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof
(FooClass), 0, (GInstanceInitFunc) fooclass_instance_init, &g_define_type_value_table };
+ static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED |
G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
+ GType fooclass_type_id;
+ fooclass_type_id = g_type_register_fundamental (g_type_fundamental_next (), "FooClass",
&g_define_type_info, &g_define_type_fundamental_info, 0);
+ FooClass_private_offset = g_type_add_instance_private (fooclass_type_id, sizeof (FooClassPrivate));
+ return fooclass_type_id;
+}
+
+GType
+fooclass_get_type (void)
+{
+ static volatile gsize fooclass_type_id__volatile = 0;
+ if (g_once_init_enter (&fooclass_type_id__volatile)) {
+ GType fooclass_type_id;
+ fooclass_type_id = fooclass_get_type_once ();
+ g_once_init_leave (&fooclass_type_id__volatile, fooclass_type_id);
+ }
+ return fooclass_type_id__volatile;
+}
+
+gpointer
+fooclass_ref (gpointer instance)
+{
+ FooClass * self;
+ self = instance;
+ g_atomic_int_inc (&self->ref_count);
+ return instance;
+}
+
+void
+fooclass_unref (gpointer instance)
+{
+ FooClass * self;
+ self = instance;
+ if (g_atomic_int_dec_and_test (&self->ref_count)) {
+ FOOCLASS_GET_CLASS (self)->finalize (self);
+ g_type_free_instance ((GTypeInstance *) self);
+ }
+}
+
+static void
+_vala_main (void)
+{
+ FooClass* foo = NULL;
+ FooClass* _tmp0_;
+ _tmp0_ = fooclass_new ();
+ foo = _tmp0_;
+ _vala_assert (foo->field == 42, "foo.field == 42");
+ _vala_assert (FOO == 42, "foo.array.length == 42");
+ _fooclass_unref0 (foo);
+}
+
+int
+main (int argc,
+ char ** argv)
+{
+ _vala_main ();
+ return 0;
+}
+
diff --git a/tests/ordering/constant-class.vala b/tests/ordering/constant-class.vala
new file mode 100644
index 000000000..3a2f46843
--- /dev/null
+++ b/tests/ordering/constant-class.vala
@@ -0,0 +1,19 @@
+class FooClass {
+ public int field = FOO;
+ public int array[FOO];
+ int pfield = FOO;
+ int parray[FOO];
+
+ public FooClass () {
+ assert (pfield == 42);
+ assert (parray.length == 42);
+ }
+}
+
+const int FOO = 42;
+
+void main () {
+ var foo = new FooClass ();
+ assert (foo.field == 42);
+ assert (foo.array.length == 42);
+}
diff --git a/tests/ordering/constant-constant.c-expected b/tests/ordering/constant-constant.c-expected
new file mode 100644
index 000000000..e42751a15
--- /dev/null
+++ b/tests/ordering/constant-constant.c-expected
@@ -0,0 +1,31 @@
+/* ordering_constant_constant.c generated by valac, the Vala compiler
+ * generated from ordering_constant_constant.vala, do not modify */
+
+#include <glib.h>
+
+#define FOO 42
+#define BAR FOO
+#define FOO_BAR (FOO + BAR)
+
+#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
+#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN,
G_STRFUNC, msg); return; }
+#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
+#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
+
+static void _vala_main (void);
+
+static void
+_vala_main (void)
+{
+ _vala_assert (BAR == 42, "BAR == 42");
+ _vala_assert (FOO_BAR == 84, "FOO_BAR == 84");
+}
+
+int
+main (int argc,
+ char ** argv)
+{
+ _vala_main ();
+ return 0;
+}
+
diff --git a/tests/ordering/constant-constant.vala b/tests/ordering/constant-constant.vala
new file mode 100644
index 000000000..8915dd29f
--- /dev/null
+++ b/tests/ordering/constant-constant.vala
@@ -0,0 +1,10 @@
+const int FOO_BAR = FOO + BAR;
+
+const int BAR = FOO;
+
+const int FOO = 42;
+
+void main () {
+ assert (BAR == 42);
+ assert (FOO_BAR == 84);
+}
diff --git a/tests/ordering/constant-enum.c-expected b/tests/ordering/constant-enum.c-expected
new file mode 100644
index 000000000..308e19768
--- /dev/null
+++ b/tests/ordering/constant-enum.c-expected
@@ -0,0 +1,65 @@
+/* ordering_constant_enum.c generated by valac, the Vala compiler
+ * generated from ordering_constant_enum.vala, do not modify */
+
+#include <glib.h>
+#include <glib-object.h>
+
+#define FOO 42
+#if !defined(VALA_EXTERN)
+#if defined(_MSC_VER)
+#define VALA_EXTERN __declspec(dllexport) extern
+#elif __GNUC__ >= 4
+#define VALA_EXTERN __attribute__((visibility("default"))) extern
+#else
+#define VALA_EXTERN extern
+#endif
+#endif
+
+typedef enum {
+ FOO_ENUM_BAR = FOO
+} FooEnum;
+
+#define TYPE_FOO_ENUM (foo_enum_get_type ())
+#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
+#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN,
G_STRFUNC, msg); return; }
+#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
+#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
+
+VALA_EXTERN GType foo_enum_get_type (void) G_GNUC_CONST ;
+static void _vala_main (void);
+
+static GType
+foo_enum_get_type_once (void)
+{
+ static const GEnumValue values[] = {{FOO_ENUM_BAR, "FOO_ENUM_BAR", "bar"}, {0, NULL, NULL}};
+ GType foo_enum_type_id;
+ foo_enum_type_id = g_enum_register_static ("FooEnum", values);
+ return foo_enum_type_id;
+}
+
+GType
+foo_enum_get_type (void)
+{
+ static volatile gsize foo_enum_type_id__volatile = 0;
+ if (g_once_init_enter (&foo_enum_type_id__volatile)) {
+ GType foo_enum_type_id;
+ foo_enum_type_id = foo_enum_get_type_once ();
+ g_once_init_leave (&foo_enum_type_id__volatile, foo_enum_type_id);
+ }
+ return foo_enum_type_id__volatile;
+}
+
+static void
+_vala_main (void)
+{
+ _vala_assert (FOO_ENUM_BAR == 42, "FooEnum.BAR == 42");
+}
+
+int
+main (int argc,
+ char ** argv)
+{
+ _vala_main ();
+ return 0;
+}
+
diff --git a/tests/ordering/constant-enum.vala b/tests/ordering/constant-enum.vala
new file mode 100644
index 000000000..2fee75e62
--- /dev/null
+++ b/tests/ordering/constant-enum.vala
@@ -0,0 +1,9 @@
+enum FooEnum {
+ BAR = FOO;
+}
+
+const int FOO = 42;
+
+void main () {
+ assert (FooEnum.BAR == 42);
+}
diff --git a/tests/ordering/constant-field.c-expected b/tests/ordering/constant-field.c-expected
new file mode 100644
index 000000000..ffc093b52
--- /dev/null
+++ b/tests/ordering/constant-field.c-expected
@@ -0,0 +1,43 @@
+/* ordering_constant_field.c generated by valac, the Vala compiler
+ * generated from ordering_constant_field.vala, do not modify */
+
+#include <glib.h>
+
+#define FOO 42
+#if !defined(VALA_EXTERN)
+#if defined(_MSC_VER)
+#define VALA_EXTERN __declspec(dllexport) extern
+#elif __GNUC__ >= 4
+#define VALA_EXTERN __attribute__((visibility("default"))) extern
+#else
+#define VALA_EXTERN extern
+#endif
+#endif
+
+#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
+#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN,
G_STRFUNC, msg); return; }
+#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
+#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
+
+VALA_EXTERN gint field;
+gint field = FOO;
+VALA_EXTERN gint array[FOO];
+gint array[FOO] = {0};
+
+static void _vala_main (void);
+
+static void
+_vala_main (void)
+{
+ _vala_assert (field == 42, "field == 42");
+ _vala_assert (FOO == 42, "array.length == 42");
+}
+
+int
+main (int argc,
+ char ** argv)
+{
+ _vala_main ();
+ return 0;
+}
+
diff --git a/tests/ordering/constant-field.vala b/tests/ordering/constant-field.vala
new file mode 100644
index 000000000..389d2e27a
--- /dev/null
+++ b/tests/ordering/constant-field.vala
@@ -0,0 +1,9 @@
+int field = FOO;
+int array[FOO];
+
+const int FOO = 42;
+
+void main () {
+ assert (field == 42);
+ assert (array.length == 42);
+}
diff --git a/tests/ordering/constant-struct.c-expected b/tests/ordering/constant-struct.c-expected
new file mode 100644
index 000000000..d85d9c400
--- /dev/null
+++ b/tests/ordering/constant-struct.c-expected
@@ -0,0 +1,88 @@
+/* ordering_constant_struct.c generated by valac, the Vala compiler
+ * generated from ordering_constant_struct.vala, do not modify */
+
+#include <glib-object.h>
+#include <glib.h>
+#include <string.h>
+
+#define FOO 42
+#if !defined(VALA_EXTERN)
+#if defined(_MSC_VER)
+#define VALA_EXTERN __declspec(dllexport) extern
+#elif __GNUC__ >= 4
+#define VALA_EXTERN __attribute__((visibility("default"))) extern
+#else
+#define VALA_EXTERN extern
+#endif
+#endif
+
+#define TYPE_FOO_STRUCT (foo_struct_get_type ())
+typedef struct _FooStruct FooStruct;
+#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
+#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN,
G_STRFUNC, msg); return; }
+#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
+#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, msg);
+
+struct _FooStruct {
+ gint array[FOO];
+};
+
+VALA_EXTERN GType foo_struct_get_type (void) G_GNUC_CONST ;
+VALA_EXTERN FooStruct* foo_struct_dup (const FooStruct* self);
+VALA_EXTERN void foo_struct_free (FooStruct* self);
+static void _vala_main (void);
+
+FooStruct*
+foo_struct_dup (const FooStruct* self)
+{
+ FooStruct* dup;
+ dup = g_new0 (FooStruct, 1);
+ memcpy (dup, self, sizeof (FooStruct));
+ return dup;
+}
+
+void
+foo_struct_free (FooStruct* self)
+{
+ g_free (self);
+}
+
+static GType
+foo_struct_get_type_once (void)
+{
+ GType foo_struct_type_id;
+ foo_struct_type_id = g_boxed_type_register_static ("FooStruct", (GBoxedCopyFunc) foo_struct_dup,
(GBoxedFreeFunc) foo_struct_free);
+ return foo_struct_type_id;
+}
+
+GType
+foo_struct_get_type (void)
+{
+ static volatile gsize foo_struct_type_id__volatile = 0;
+ if (g_once_init_enter (&foo_struct_type_id__volatile)) {
+ GType foo_struct_type_id;
+ foo_struct_type_id = foo_struct_get_type_once ();
+ g_once_init_leave (&foo_struct_type_id__volatile, foo_struct_type_id);
+ }
+ return foo_struct_type_id__volatile;
+}
+
+static void
+_vala_main (void)
+{
+ FooStruct foo = {0};
+ FooStruct _tmp0_ = {0};
+ FooStruct _tmp1_;
+ foo = _tmp0_;
+ _tmp1_ = foo;
+ _vala_assert (FOO == 42, "foo.array.length == 42");
+}
+
+int
+main (int argc,
+ char ** argv)
+{
+ _vala_main ();
+ return 0;
+}
+
diff --git a/tests/ordering/constant-struct.vala b/tests/ordering/constant-struct.vala
new file mode 100644
index 000000000..135cd4fc1
--- /dev/null
+++ b/tests/ordering/constant-struct.vala
@@ -0,0 +1,10 @@
+struct FooStruct {
+ public int array[FOO];
+}
+
+const int FOO = 42;
+
+void main () {
+ FooStruct foo = {};
+ assert (foo.array.length == 42);
+}
diff --git a/tests/posix/arrays.c-expected b/tests/posix/arrays.c-expected
index c4ed3586d..7b76fb9d8 100644
--- a/tests/posix/arrays.c-expected
+++ b/tests/posix/arrays.c-expected
@@ -8,6 +8,7 @@
#include <string.h>
#include <stdbool.h>
+#define FOO 2
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
@@ -85,7 +86,6 @@ VALA_EXTERN int* pass_helper (int* a,
static int* _vala_array_dup8 (int* self,
ssize_t length);
VALA_EXTERN void test_array_pass (void);
-#define FOO 2
VALA_EXTERN void test_static_array (void);
VALA_EXTERN void test_reference_transfer (void);
VALA_EXTERN void test_length_assignment (void);
diff --git a/tests/semantic/member-access-static-with-instance.c-expected
b/tests/semantic/member-access-static-with-instance.c-expected
index e73423aa5..1e589ffbc 100644
--- a/tests/semantic/member-access-static-with-instance.c-expected
+++ b/tests/semantic/member-access-static-with-instance.c-expected
@@ -5,6 +5,8 @@
#include <glib.h>
#include <string.h>
+#define FOO_FOO 23
+#define BAR FOO_FOO
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
@@ -32,8 +34,6 @@ Foo foo_static_field = {0};
VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ;
VALA_EXTERN Foo* foo_dup (const Foo* self);
VALA_EXTERN void foo_free (Foo* self);
-#define FOO_FOO 23
-#define BAR FOO_FOO
static void _vala_main (void);
Foo*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]