summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Moore <jaredm@svn.gnome.org>2008-08-10 02:20:26 +0000
committerJared William Moore <jaredm@src.gnome.org>2008-08-10 02:20:26 +0000
commit7a599d51ce7e2b4356ab7ccb7ae5a790440684f9 (patch)
treeefcdde9bc5a550181fc4162d318190bc9ee336eb
parente3b78a7c5f2967657c573d61eccda849ecd04581 (diff)
downloadvala-7a599d51ce7e2b4356ab7ccb7ae5a790440684f9.tar.gz
Generate correct code for calling class methods outside of static or class
2008-08-10 Jared Moore <jaredm@svn.gnome.org> * gobject/valaccodeinvocationexpressionbinding.vala: Generate correct code for calling class methods outside of static or class constructors, fixes bug 539592. * tests/classes-methods.vala: * tests/classes-methods.exp: Added test cases for calling class methods. svn path=/trunk/; revision=1738
-rw-r--r--ChangeLog12
-rw-r--r--gobject/valaccodecompiler.vala2
-rw-r--r--gobject/valaccodeinvocationexpressionbinding.vala21
-rw-r--r--tests/classes-methods.exp4
-rw-r--r--tests/classes-methods.vala32
5 files changed, 69 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 151edc287..019512926 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-08-10 Jared Moore <jaredm@svn.gnome.org>
+
+ * gobject/valaccodeinvocationexpressionbinding.vala:
+
+ Generate correct code for calling class methods outside of static or
+ class constructors, fixes bug 539592.
+
+ * tests/classes-methods.vala:
+ * tests/classes-methods.exp:
+
+ Added test cases for calling class methods.
+
2008-08-06 Thijs Vermeir <thijsvermeir@gmail.com>
* vapi/packages/gstreamer-0.10/gstreamer-0.10.metadata:
diff --git a/gobject/valaccodecompiler.vala b/gobject/valaccodecompiler.vala
index 9be754c4c..70f9664a8 100644
--- a/gobject/valaccodecompiler.vala
+++ b/gobject/valaccodecompiler.vala
@@ -113,7 +113,7 @@ public class Vala.CCodeCompiler : Object {
// add libraries after source files to fix linking
// with --as-needed and on Windows
- cmdline += " " + pkgflags;
+ cmdline += " " + pkgflags.strip ();
foreach (string cc_option in cc_options) {
cmdline += " " + Shell.quote (cc_option);
}
diff --git a/gobject/valaccodeinvocationexpressionbinding.vala b/gobject/valaccodeinvocationexpressionbinding.vala
index 57646e8e8..a13383462 100644
--- a/gobject/valaccodeinvocationexpressionbinding.vala
+++ b/gobject/valaccodeinvocationexpressionbinding.vala
@@ -98,8 +98,27 @@ public class Vala.CCodeInvocationExpressionBinding : CCodeExpressionBinding {
} else if (m != null && m.binding == MemberBinding.CLASS) {
var cl = (Class) m.parent_symbol;
var cast = new CCodeFunctionCall (new CCodeIdentifier (cl.get_upper_case_cname (null) + "_CLASS"));
- cast.add_argument (new CCodeIdentifier ("klass"));
+
+ CCodeExpression klass;
+ var ma = expr.call as MemberAccess;
+ if (ma.inner == null) {
+ if (codegen.in_static_or_class_ctor) {
+ // Accessing the method from a static or class constructor
+ klass = new CCodeIdentifier ("klass");
+ } else {
+ // Accessing the method from within an instance method
+ var k = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_GET_CLASS"));
+ k.add_argument (new CCodeIdentifier ("self"));
+ klass = k;
+ }
+ } else {
+ // Accessing the method of an instance
+ var k = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_GET_CLASS"));
+ k.add_argument ((CCodeExpression) ma.inner.ccodenode);
+ klass = k;
+ }
+ cast.add_argument (klass);
carg_map.set (codegen.get_param_pos (m.cinstance_parameter_position), cast);
}
diff --git a/tests/classes-methods.exp b/tests/classes-methods.exp
index 6e621cbad..b32fe50f8 100644
--- a/tests/classes-methods.exp
+++ b/tests/classes-methods.exp
@@ -2,3 +2,7 @@ Inheritance Test: 1 2 3
Static Inheritance Test: 1 2 3
Virtual Method Test: 1 2 3
Interface Inheritance Test: 1 2 3
+Access class method in class constructor: OK
+Access class method in static constructor: OK
+Access class method by member access: OK
+Access class method in instance method: OK
diff --git a/tests/classes-methods.vala b/tests/classes-methods.vala
index e3854d082..33696ca52 100644
--- a/tests/classes-methods.vala
+++ b/tests/classes-methods.vala
@@ -81,6 +81,8 @@ class Maman.SubBar : Bar {
test_ref_weak (ref str2);
assert (str == "world");
+ ClassTest.run_test ();
+
return 0;
}
}
@@ -183,3 +185,33 @@ void test_ref_weak (ref weak string bar) {
bar = "world";
}
+class Maman.ClassTest {
+ public class void class_method () {
+ stdout.printf(" OK\n");
+ }
+
+ public void instance_method () {
+ stdout.printf ("Access class method in instance method:");
+ class_method ();
+ }
+
+ class construct {
+ stdout.printf ("Access class method in class constructor:");
+ class_method ();
+ }
+
+ static construct {
+ stdout.printf ("Access class method in static constructor:");
+ class_method ();
+ }
+
+ public static void run_test () {
+ var c = new ClassTest ();
+
+ stdout.printf ("Access class method by member access:");
+ c.class_method ();
+
+ c.instance_method ();
+ }
+}
+