+2008-10-10 Jürg Billeter <j@bitron.ch>
+
+ * gobject/valaccodecreationmethodbinding.vala:
+ * gobject/valaccodemethodbinding.vala:
+
+ Lift restriction on statements in creation methods of GObjects
+ in preparation to support more flexible construction scheme
+
2008-10-09 Jürg Billeter <j@bitron.ch>
* vala/valainterfacewriter.vala:
if (m.body != null && codegen.current_type_symbol is Class && codegen.current_class.is_subtype_of (codegen.gobject_type)) {
int n_params = 0;
foreach (Statement stmt in m.body.get_statements ()) {
- if (!(stmt is ExpressionStatement) || ((ExpressionStatement) stmt).assigned_property () == null) {
- m.error = true;
- Report.error (stmt.source_reference, "class creation methods only allow property assignment statements");
- return;
- }
-
- Property prop = ((ExpressionStatement) stmt).assigned_property ();
- if (prop.access == SymbolAccessibility.PRIVATE) {
- m.error = true;
- Report.error (stmt.source_reference, "class creation methods only allow assignments to public and protected properties");
- return;
- }
- if (prop.set_accessor.construction) {
- n_params++;
+ var expr_stmt = stmt as ExpressionStatement;
+ if (expr_stmt != null) {
+ Property prop = expr_stmt.assigned_property ();
+ if (prop != null && prop.set_accessor.construction) {
+ n_params++;
+ }
}
}
m.n_construction_params = n_params;
if (m is CreationMethod) {
if (in_gobject_creation_method && m.body != null) {
var cblock = new CCodeBlock ();
-
+
+ // set construct properties
foreach (CodeNode stmt in m.body.get_statements ()) {
- if (((ExpressionStatement) stmt).assigned_property ().set_accessor.construction) {
- if (stmt.ccodenode is CCodeFragment) {
- foreach (CCodeNode cstmt in ((CCodeFragment) stmt.ccodenode).get_children ()) {
- cblock.add_statement (cstmt);
+ var expr_stmt = stmt as ExpressionStatement;
+ if (expr_stmt != null) {
+ var prop = expr_stmt.assigned_property ();
+ if (prop != null && prop.set_accessor.construction) {
+ if (stmt.ccodenode is CCodeFragment) {
+ foreach (CCodeNode cstmt in ((CCodeFragment) stmt.ccodenode).get_children ()) {
+ cblock.add_statement (cstmt);
+ }
+ } else {
+ cblock.add_statement (stmt.ccodenode);
}
- } else {
- cblock.add_statement (stmt.ccodenode);
}
}
}
add_object_creation (cblock, ((CreationMethod) m).n_construction_params > 0 || codegen.current_class.get_type_parameters ().size > 0);
-
+
+ // other initialization code
foreach (CodeNode stmt in m.body.get_statements ()) {
- if (!((ExpressionStatement) stmt).assigned_property ().set_accessor.construction) {
- if (stmt.ccodenode is CCodeFragment) {
- foreach (CCodeNode cstmt in ((CCodeFragment) stmt.ccodenode).get_children ()) {
- cblock.add_statement (cstmt);
- }
- } else {
- cblock.add_statement (stmt.ccodenode);
+ var expr_stmt = stmt as ExpressionStatement;
+ if (expr_stmt != null) {
+ var prop = expr_stmt.assigned_property ();
+ if (prop != null && prop.set_accessor.construction) {
+ continue;
}
}
+ if (stmt.ccodenode is CCodeFragment) {
+ foreach (CCodeNode cstmt in ((CCodeFragment) stmt.ccodenode).get_children ()) {
+ cblock.add_statement (cstmt);
+ }
+ } else {
+ cblock.add_statement (stmt.ccodenode);
+ }
}
m.body.ccodenode = cblock;