vala r1738 - in trunk: . gobject tests
- From: jaredm svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1738 - in trunk: . gobject tests
- Date: Sun, 10 Aug 2008 02:20:26 +0000 (UTC)
Author: jaredm
Date: Sun Aug 10 02:20:26 2008
New Revision: 1738
URL: http://svn.gnome.org/viewvc/vala?rev=1738&view=rev
Log:
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.
Modified:
trunk/ChangeLog
trunk/gobject/valaccodecompiler.vala
trunk/gobject/valaccodeinvocationexpressionbinding.vala
trunk/tests/classes-methods.exp
trunk/tests/classes-methods.vala
Modified: trunk/gobject/valaccodecompiler.vala
==============================================================================
--- trunk/gobject/valaccodecompiler.vala (original)
+++ trunk/gobject/valaccodecompiler.vala Sun Aug 10 02:20:26 2008
@@ -113,7 +113,7 @@
// 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);
}
Modified: trunk/gobject/valaccodeinvocationexpressionbinding.vala
==============================================================================
--- trunk/gobject/valaccodeinvocationexpressionbinding.vala (original)
+++ trunk/gobject/valaccodeinvocationexpressionbinding.vala Sun Aug 10 02:20:26 2008
@@ -98,8 +98,27 @@
} 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);
}
Modified: trunk/tests/classes-methods.exp
==============================================================================
--- trunk/tests/classes-methods.exp (original)
+++ trunk/tests/classes-methods.exp Sun Aug 10 02:20:26 2008
@@ -2,3 +2,7 @@
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
Modified: trunk/tests/classes-methods.vala
==============================================================================
--- trunk/tests/classes-methods.vala (original)
+++ trunk/tests/classes-methods.vala Sun Aug 10 02:20:26 2008
@@ -81,6 +81,8 @@
test_ref_weak (ref str2);
assert (str == "world");
+ ClassTest.run_test ();
+
return 0;
}
}
@@ -183,3 +185,33 @@
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 ();
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]