Commit e5bccaaa authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

generate warning about invalid property ids, fixes bug 463668

2007-08-28  Juerg Billeter  <j@bitron.ch>

	* ccode/valaccodeswitchstatement.vala,
	  gobject/valacodegeneratorclass.vala: generate warning about invalid
	  property ids, fixes bug 463668

svn path=/trunk/; revision=522
parent 77edd178
2007-08-28 Jürg Billeter <j@bitron.ch>
* ccode/valaccodeswitchstatement.vala,
gobject/valacodegeneratorclass.vala: generate warning about invalid
property ids, fixes bug 463668
2007-08-28 Mathias Hasselmann <mathias.hasselmann@gmx.de>
* gobject/valacodegenerator.vala: avoid crash on missing copy
......
......@@ -33,6 +33,7 @@ public class Vala.CCodeSwitchStatement : CCodeStatement {
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 (construct CCodeExpression! expression) {
}
......@@ -45,7 +46,16 @@ public class Vala.CCodeSwitchStatement : CCodeStatement {
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 ();
writer.write_string ("switch (");
......@@ -56,7 +66,17 @@ public class Vala.CCodeSwitchStatement : CCodeStatement {
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 ();
}
}
......@@ -483,6 +483,9 @@ public class Vala.CodeGenerator {
ccase.add_statement (new CCodeBreakStatement ());
cswitch.add_case (ccase);
}
cswitch.add_default_statement (get_invalid_property_id_warn_statement ());
cswitch.add_default_statement (new CCodeBreakStatement ());
block.add_statement (cswitch);
get_prop.block = block;
......@@ -535,6 +538,9 @@ public class Vala.CodeGenerator {
ccase.add_statement (new CCodeBreakStatement ());
cswitch.add_case (ccase);
}
cswitch.add_default_statement (get_invalid_property_id_warn_statement ());
cswitch.add_default_statement (new CCodeBreakStatement ());
block.add_statement (cswitch);
/* destroy func properties for generic types */
......@@ -555,4 +561,13 @@ public class Vala.CodeGenerator {
source_type_member_definition.append (set_prop);
}
private CCodeStatement get_invalid_property_id_warn_statement () {
// warn on invalid property id
var cwarn = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_WARN_INVALID_PROPERTY_ID"));
cwarn.add_argument (new CCodeIdentifier ("object"));
cwarn.add_argument (new CCodeIdentifier ("property_id"));
cwarn.add_argument (new CCodeIdentifier ("pspec"));
return new CCodeExpressionStatement (cwarn);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment