vala r1948 - in trunk: . ccode gobject
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1948 - in trunk: . ccode gobject
- Date: Sat, 1 Nov 2008 20:12:06 +0000 (UTC)
Author: juergbi
Date: Sat Nov 1 20:12:06 2008
New Revision: 1948
URL: http://svn.gnome.org/viewvc/vala?rev=1948&view=rev
Log:
2008-11-01 JÃrg Billeter <j bitron ch>
* ccode/valaccodecasestatement.vala:
* ccode/valaccodeswitchstatement.vala:
* gobject/valaccodegenerator.vala:
* gobject/valagobjectclassmodule.vala:
Support more flexible C switch statements
Modified:
trunk/ChangeLog
trunk/ccode/valaccodecasestatement.vala
trunk/ccode/valaccodeswitchstatement.vala
trunk/gobject/valaccodegenerator.vala
trunk/gobject/valagobjectclassmodule.vala
Modified: trunk/ccode/valaccodecasestatement.vala
==============================================================================
--- trunk/ccode/valaccodecasestatement.vala (original)
+++ trunk/ccode/valaccodecasestatement.vala Sat Nov 1 20:12:06 2008
@@ -32,30 +32,15 @@
*/
public CCodeExpression expression { get; set; }
- private Gee.List<CCodeStatement> statements = new ArrayList<CCodeStatement> ();
-
public CCodeCaseStatement (CCodeExpression expression) {
this.expression = expression;
}
- /**
- * Append the specified statement to this switch section.
- *
- * @param stmt a statement
- */
- public void add_statement (CCodeStatement stmt) {
- statements.add (stmt);
- }
-
public override void write (CCodeWriter writer) {
writer.write_indent (line);
writer.write_string ("case ");
expression.write (writer);
writer.write_string (":");
writer.write_newline ();
-
- foreach (CCodeStatement stmt in statements) {
- stmt.write (writer);
- }
}
}
Modified: trunk/ccode/valaccodeswitchstatement.vala
==============================================================================
--- trunk/ccode/valaccodeswitchstatement.vala (original)
+++ trunk/ccode/valaccodeswitchstatement.vala Sat Nov 1 20:12:06 2008
@@ -26,58 +26,22 @@
/**
* Represents a switch selection statement in the C code.
*/
-public class Vala.CCodeSwitchStatement : CCodeStatement {
+public class Vala.CCodeSwitchStatement : CCodeBlock {
/**
* The switch expression.
*/
public CCodeExpression expression { get; set; }
- private Gee.List<CCodeCaseStatement> case_statements = new ArrayList<CCodeCaseStatement> ();
- private Gee.List<CCodeStatement> default_statements = new ArrayList<CCodeStatement> ();
-
public CCodeSwitchStatement (CCodeExpression expression) {
this.expression = expression;
}
- /**
- * Adds the specified case statement to the list of switch sections.
- *
- * @param case_stmt a case statement
- */
- public void add_case (CCodeCaseStatement case_stmt) {
- case_statements.add (case_stmt);
- }
-
- /**
- * Append the specified statement to the default clause.
- *
- * @param stmt a statement
- */
- public void add_default_statement (CCodeStatement stmt) {
- default_statements.add (stmt);
- }
-
public override void write (CCodeWriter writer) {
writer.write_indent (line);
writer.write_string ("switch (");
expression.write (writer);
writer.write_string (")");
- writer.write_begin_block ();
-
- foreach (CCodeCaseStatement case_stmt in case_statements) {
- case_stmt.write (writer);
- }
-
- if (default_statements.size > 0) {
- writer.write_indent ();
- writer.write_string ("default:");
- writer.write_newline ();
-
- foreach (CCodeStatement stmt in default_statements) {
- stmt.write (writer);
- }
- }
- writer.write_end_block ();
+ base.write (writer);
}
}
Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala (original)
+++ trunk/gobject/valaccodegenerator.vala Sat Nov 1 20:12:06 2008
@@ -2109,23 +2109,21 @@
foreach (SwitchSection section in stmt.get_sections ()) {
if (section.has_default_label ()) {
+ cswitch.add_statement (new CCodeLabel ("default"));
var cdefaultblock = new CCodeBlock ();
- cswitch.add_default_statement (cdefaultblock);
+ cswitch.add_statement (cdefaultblock);
foreach (CodeNode default_stmt in section.get_statements ()) {
cdefaultblock.add_statement (default_stmt.ccodenode);
}
continue;
}
- CCodeCaseStatement ccase = null;
-
foreach (SwitchLabel label in section.get_labels ()) {
- ccase = new CCodeCaseStatement ((CCodeExpression) label.expression.ccodenode);
- cswitch.add_case (ccase);
+ cswitch.add_statement (new CCodeCaseStatement ((CCodeExpression) label.expression.ccodenode));
}
var cblock = new CCodeBlock ();
- ccase.add_statement (cblock);
+ cswitch.add_statement (cblock);
foreach (CodeNode body_stmt in section.get_statements ()) {
cblock.add_statement (body_stmt.ccodenode);
}
Modified: trunk/gobject/valagobjectclassmodule.vala
==============================================================================
--- trunk/gobject/valagobjectclassmodule.vala (original)
+++ trunk/gobject/valagobjectclassmodule.vala Sat Nov 1 20:12:06 2008
@@ -1155,19 +1155,19 @@
cself = codegen.transform_expression (cself, new ObjectType (cl), new ObjectType (base_type));
}
- var ccase = new CCodeCaseStatement (new CCodeIdentifier (prop.get_upper_case_cname ()));
+ cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (prop.get_upper_case_cname ())));
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_get_%s".printf (prefix, prop.name)));
ccall.add_argument (cself);
var csetcall = new CCodeFunctionCall ();
csetcall.call = head.get_value_setter_function (prop.property_type);
csetcall.add_argument (new CCodeIdentifier ("value"));
csetcall.add_argument (ccall);
- ccase.add_statement (new CCodeExpressionStatement (csetcall));
- ccase.add_statement (new CCodeBreakStatement ());
- cswitch.add_case (ccase);
+ cswitch.add_statement (new CCodeExpressionStatement (csetcall));
+ cswitch.add_statement (new CCodeBreakStatement ());
}
- cswitch.add_default_statement (get_invalid_property_id_warn_statement ());
- cswitch.add_default_statement (new CCodeBreakStatement ());
+ cswitch.add_statement (new CCodeLabel ("default"));
+ cswitch.add_statement (get_invalid_property_id_warn_statement ());
+ cswitch.add_statement (new CCodeBreakStatement ());
block.add_statement (cswitch);
@@ -1215,7 +1215,7 @@
cself = codegen.transform_expression (cself, new ObjectType (cl), new ObjectType (base_type));
}
- var ccase = new CCodeCaseStatement (new CCodeIdentifier (prop.get_upper_case_cname ()));
+ cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (prop.get_upper_case_cname ())));
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_set_%s".printf (prefix, prop.name)));
ccall.add_argument (cself);
var cgetcall = new CCodeFunctionCall ();
@@ -1226,51 +1226,47 @@
}
cgetcall.add_argument (new CCodeIdentifier ("value"));
ccall.add_argument (cgetcall);
- ccase.add_statement (new CCodeExpressionStatement (ccall));
- ccase.add_statement (new CCodeBreakStatement ());
- cswitch.add_case (ccase);
+ cswitch.add_statement (new CCodeExpressionStatement (ccall));
+ cswitch.add_statement (new CCodeBreakStatement ());
}
- cswitch.add_default_statement (get_invalid_property_id_warn_statement ());
- cswitch.add_default_statement (new CCodeBreakStatement ());
+ cswitch.add_statement (new CCodeLabel ("default"));
+ cswitch.add_statement (get_invalid_property_id_warn_statement ());
+ cswitch.add_statement (new CCodeBreakStatement ());
block.add_statement (cswitch);
/* type, dup func, and destroy func properties for generic types */
foreach (TypeParameter type_param in cl.get_type_parameters ()) {
string func_name, enum_value;
- CCodeCaseStatement ccase;
CCodeMemberAccess cfield;
CCodeFunctionCall cgetcall;
func_name = "%s_type".printf (type_param.name.down ());
enum_value = "%s_%s".printf (cl.get_lower_case_cname (null), func_name).up ();
- ccase = new CCodeCaseStatement (new CCodeIdentifier (enum_value));
+ cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (enum_value)));
cfield = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
cgetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_gtype"));
cgetcall.add_argument (new CCodeIdentifier ("value"));
- ccase.add_statement (new CCodeExpressionStatement (new CCodeAssignment (cfield, cgetcall)));
- ccase.add_statement (new CCodeBreakStatement ());
- cswitch.add_case (ccase);
+ cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (cfield, cgetcall)));
+ cswitch.add_statement (new CCodeBreakStatement ());
func_name = "%s_dup_func".printf (type_param.name.down ());
enum_value = "%s_%s".printf (cl.get_lower_case_cname (null), func_name).up ();
- ccase = new CCodeCaseStatement (new CCodeIdentifier (enum_value));
+ cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (enum_value)));
cfield = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
cgetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_pointer"));
cgetcall.add_argument (new CCodeIdentifier ("value"));
- ccase.add_statement (new CCodeExpressionStatement (new CCodeAssignment (cfield, cgetcall)));
- ccase.add_statement (new CCodeBreakStatement ());
- cswitch.add_case (ccase);
+ cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (cfield, cgetcall)));
+ cswitch.add_statement (new CCodeBreakStatement ());
func_name = "%s_destroy_func".printf (type_param.name.down ());
enum_value = "%s_%s".printf (cl.get_lower_case_cname (null), func_name).up ();
- ccase = new CCodeCaseStatement (new CCodeIdentifier (enum_value));
+ cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (enum_value)));
cfield = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
cgetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_pointer"));
cgetcall.add_argument (new CCodeIdentifier ("value"));
- ccase.add_statement (new CCodeExpressionStatement (new CCodeAssignment (cfield, cgetcall)));
- ccase.add_statement (new CCodeBreakStatement ());
- cswitch.add_case (ccase);
+ cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (cfield, cgetcall)));
+ cswitch.add_statement (new CCodeBreakStatement ());
}
set_prop.block = block;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]