187
187
var data_type_get = data_type.copy ();
188
188
data_type_get.value_owned = true;
190
var switch_section = new Vala.SwitchSection (null);
190
var switch_section = new Vala.SwitchSection (source_reference);
191
191
signals.add_section (switch_section);
192
switch_section.add_label (new Vala.SwitchLabel (new Vala.StringLiteral (@"\"$(name)\"")));
192
switch_section.add_label (new Vala.SwitchLabel (new Vala.StringLiteral (@"\"$(name)\"", source_reference), source_reference));
193
193
Vala.MethodCall emit_changed_notify;
195
195
if ( !write_properties ) {
196
var changed_signal = new Vala.Signal (@"$(name)_changed", new Vala.VoidType ());
196
var changed_signal = new Vala.Signal (@"$(name)_changed", new Vala.VoidType (source_reference), source_reference);
197
197
changed_signal.access = Vala.SymbolAccessibility.PUBLIC;
198
198
cl.add_signal (changed_signal);
199
emit_changed_notify = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this"), @"$(name)_changed"));
199
emit_changed_notify = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this"), @"$(name)_changed", source_reference), source_reference);
202
var get_method = new Vala.Method (@"get_$(name)", data_type_get);
202
var get_method = new Vala.Method (@"get_$(name)", data_type_get, source_reference);
203
203
cl.add_method (get_method);
204
204
get_method.access = Vala.SymbolAccessibility.PUBLIC;
205
205
get_method.add_error_type (type_from_string ("SQLHeavy.Error"));
207
var block = new Vala.Block (null);
208
var call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this"), @"get_$(data_type_get.to_string ())"));
209
call.add_argument (new Vala.StringLiteral (@"\"$(table.field_name (field))\""));
210
block.add_statement (new Vala.ReturnStatement (call));
207
var block = new Vala.Block (source_reference);
208
var call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this"), @"get_$(data_type_get.to_string ())", source_reference), source_reference);
209
call.add_argument (new Vala.StringLiteral (@"\"$(table.field_name (field))\"", source_reference));
210
block.add_statement (new Vala.ReturnStatement (call, source_reference));
212
212
get_method.body = block;
216
var set_method = new Vala.Method (@"set_$(name)", new Vala.VoidType ());
217
set_method.add_parameter (new Vala.Parameter ("value", data_type));
216
var set_method = new Vala.Method (@"set_$(name)", new Vala.VoidType (source_reference), source_reference);
217
set_method.add_parameter (new Vala.Parameter ("value", data_type, source_reference));
218
218
cl.add_method (set_method);
219
219
set_method.access = Vala.SymbolAccessibility.PUBLIC;
220
220
set_method.add_error_type (type_from_string ("SQLHeavy.Error"));
222
var block = new Vala.Block (null);
223
var call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this"), @"set_$(data_type.to_string ())"));
224
call.add_argument (new Vala.StringLiteral (@"\"$(table.field_name (field))\""));
225
block.add_statement (new Vala.ExpressionStatement (call));
222
var block = new Vala.Block (source_reference);
223
var call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this"), @"set_$(data_type.to_string ())", source_reference), source_reference);
224
call.add_argument (new Vala.StringLiteral (@"\"$(table.field_name (field))\"", source_reference));
225
block.add_statement (new Vala.ExpressionStatement (call, source_reference));
227
227
set_method.body = block;
230
230
Vala.PropertyAccessor get_accessor, set_accessor;
231
emit_changed_notify = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this"), "notify_property"));
232
emit_changed_notify.add_argument (new Vala.StringLiteral ("\"" + name.replace ("_", "-") + "\""));
234
var block = new Vala.Block (null);
235
var try_block = new Vala.Block (null);
236
var catch_block = new Vala.Block (null);
237
var try_stmt = new Vala.TryStatement (try_block, null, null);
239
var call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this"), @"get_$(data_type_get.to_string ())"));
240
call.add_argument (new Vala.StringLiteral (@"\"$(table.field_name (field))\""));
241
try_block.add_statement (new Vala.ReturnStatement (call));
243
var error_call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("GLib"), "error"));
244
error_call.add_argument (new Vala.StringLiteral (@"\"Unable to retrieve `$(name)': %s\""));
245
error_call.add_argument (new Vala.MemberAccess (new Vala.MemberAccess (null, "e"), "message"));
246
catch_block.add_statement (new Vala.ExpressionStatement (error_call));
248
var anr = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("GLib"), "assert_not_reached"));
249
catch_block.add_statement (new Vala.ExpressionStatement (anr));
251
try_stmt.add_catch_clause (new Vala.CatchClause (type_from_string ("SQLHeavy.Error"), "e", catch_block, null));
252
block.add_statement (try_stmt);
254
get_accessor = new Vala.PropertyAccessor (true, false, false, data_type_get, block, null);
258
var block = new Vala.Block (null);
259
var try_block = new Vala.Block (null);
260
var catch_block = new Vala.Block (null);
261
var try_stmt = new Vala.TryStatement (try_block, null, null);
263
var call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this"), @"set_$(data_type_get.to_string ())"));
264
call.add_argument (new Vala.StringLiteral (@"\"$(table.field_name (field))\""));
265
call.add_argument (new Vala.MemberAccess (null, "value"));
266
try_block.add_statement (new Vala.ExpressionStatement (call));
268
var error_call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("GLib"), "error"));
269
error_call.add_argument (new Vala.StringLiteral (@"\"Unable to set `$(name)': %s\""));
270
error_call.add_argument (new Vala.MemberAccess (new Vala.MemberAccess (null, "e"), "message"));
271
catch_block.add_statement (new Vala.ExpressionStatement (error_call));
273
try_stmt.add_catch_clause (new Vala.CatchClause (type_from_string ("SQLHeavy.Error"), "e", catch_block, null));
274
block.add_statement (try_stmt);
276
set_accessor = new Vala.PropertyAccessor (false, true, false, data_type, block, null);
279
var prop = new Vala.Property (name, data_type, get_accessor, set_accessor);
231
emit_changed_notify = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this", source_reference), "notify_property", source_reference), source_reference);
232
emit_changed_notify.add_argument (new Vala.StringLiteral ("\"" + name.replace ("_", "-") + "\"", source_reference));
234
var block = new Vala.Block (source_reference);
235
var try_block = new Vala.Block (source_reference);
236
var catch_block = new Vala.Block (source_reference);
237
var try_stmt = new Vala.TryStatement (try_block, null, source_reference);
239
var call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this"), @"get_$(data_type_get.to_string ())", source_reference), source_reference);
240
call.add_argument (new Vala.StringLiteral (@"\"$(table.field_name (field))\"", source_reference));
241
try_block.add_statement (new Vala.ReturnStatement (call, source_reference));
243
var error_call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("GLib"), "error", source_reference), source_reference);
244
error_call.add_argument (new Vala.StringLiteral (@"\"Unable to retrieve `$(name)': %s\"", source_reference));
245
error_call.add_argument (new Vala.MemberAccess (new Vala.MemberAccess (null, "e"), "message", source_reference));
246
catch_block.add_statement (new Vala.ExpressionStatement (error_call, source_reference));
248
var anr = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("GLib", source_reference), "assert_not_reached", source_reference));
249
catch_block.add_statement (new Vala.ExpressionStatement (anr, source_reference));
251
try_stmt.add_catch_clause (new Vala.CatchClause (type_from_string ("SQLHeavy.Error"), "e", catch_block, source_reference));
252
block.add_statement (try_stmt);
254
get_accessor = new Vala.PropertyAccessor (true, false, false, data_type_get, block, source_reference);
258
var block = new Vala.Block (source_reference);
259
var try_block = new Vala.Block (source_reference);
260
var catch_block = new Vala.Block (source_reference);
261
var try_stmt = new Vala.TryStatement (try_block, null, source_reference);
263
var call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this", source_reference), @"set_$(data_type_get.to_string ())", source_reference), source_reference);
264
call.add_argument (new Vala.StringLiteral (@"\"$(table.field_name (field))\"", source_reference));
265
call.add_argument (new Vala.MemberAccess (null, "value", source_reference));
266
try_block.add_statement (new Vala.ExpressionStatement (call, source_reference));
268
var error_call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("GLib"), "error", source_reference), source_reference);
269
error_call.add_argument (new Vala.StringLiteral (@"\"Unable to set `$(name)': %s\"", source_reference));
270
error_call.add_argument (new Vala.MemberAccess (new Vala.MemberAccess (null, "e"), "message", source_reference));
271
catch_block.add_statement (new Vala.ExpressionStatement (error_call, source_reference));
273
try_stmt.add_catch_clause (new Vala.CatchClause (type_from_string ("SQLHeavy.Error"), "e", catch_block, source_reference));
274
block.add_statement (try_stmt);
276
set_accessor = new Vala.PropertyAccessor (false, true, false, data_type, block, source_reference);
279
var prop = new Vala.Property (name, data_type, get_accessor, set_accessor, source_reference);
280
280
prop.access = Vala.SymbolAccessibility.PUBLIC;
281
281
cl.add_property (prop);
284
switch_section.add_statement (new Vala.ExpressionStatement (emit_changed_notify));
285
switch_section.add_statement (new Vala.BreakStatement (null));
284
switch_section.add_statement (new Vala.ExpressionStatement (emit_changed_notify, source_reference));
285
switch_section.add_statement (new Vala.BreakStatement (source_reference));
288
private void parse_table (SQLHeavy.Table table, Vala.Namespace ns) throws GeneratorError, SQLHeavy.Error {
288
private void parse_table (SQLHeavy.Table table, Vala.Namespace ns, Vala.SourceReference source_reference) throws GeneratorError, SQLHeavy.Error {
289
289
var db = table.queryable.database;
290
290
var db_symbol = GLib.Path.get_basename (db.filename).split (".", 2)[0];
291
291
var symbol = @"@$(GLib.Path.get_basename (db_symbol))/$(table.name)";
310
310
register_notify.access = Vala.SymbolAccessibility.PRIVATE;
311
311
register_notify.add_parameter (new Vala.Parameter ("field", type_from_string ("int")));
313
var block = new Vala.Block (null);
314
var try_block = new Vala.Block (null);
315
var catch_block = new Vala.Block (null);
316
var try_stmt = new Vala.TryStatement (try_block, null, null);
313
var block = new Vala.Block (source_reference);
314
var try_block = new Vala.Block (source_reference);
315
var catch_block = new Vala.Block (source_reference);
316
var try_stmt = new Vala.TryStatement (try_block, null, source_reference);
318
var field_name = new Vala.LocalVariable (type_from_string ("string"), "field_name", new Vala.StringLiteral ("null"));
319
block.add_statement (new Vala.DeclarationStatement (field_name, null));
318
var field_name = new Vala.LocalVariable (type_from_string ("string"), "field_name", new Vala.StringLiteral ("null"), source_reference);
319
block.add_statement (new Vala.DeclarationStatement (field_name, source_reference));
321
321
block.add_statement (try_stmt);
322
322
var get_field_name = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("this"), "field_name"));
323
323
get_field_name.add_argument (new Vala.MemberAccess (null, "field"));
324
324
try_block.add_statement (new Vala.ExpressionStatement (new Vala.Assignment (new Vala.StringLiteral ("field_name"), get_field_name)));
326
var warn_call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("GLib"), "warning"));
327
warn_call.add_argument (new Vala.StringLiteral ("\"" + "Unknown field: %d" + "\""));
328
warn_call.add_argument (new Vala.MemberAccess (null, "field"));
329
catch_block.add_statement (new Vala.ExpressionStatement (warn_call));
330
catch_block.add_statement (new Vala.ReturnStatement ());
331
try_stmt.add_catch_clause (new Vala.CatchClause (type_from_string ("SQLHeavy.Error"), "e", catch_block, null));
326
var warn_call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.StringLiteral ("GLib"), "warning"), source_reference);
327
warn_call.add_argument (new Vala.StringLiteral ("\"" + "Unknown field: %d" + "\"", source_reference));
328
warn_call.add_argument (new Vala.MemberAccess (null, "field", source_reference));
329
catch_block.add_statement (new Vala.ExpressionStatement (warn_call, source_reference));
330
catch_block.add_statement (new Vala.ReturnStatement (null, source_reference));
331
try_stmt.add_catch_clause (new Vala.CatchClause (type_from_string ("SQLHeavy.Error"), "e", catch_block, source_reference));
333
signals_switch = new Vala.SwitchStatement (new Vala.StringLiteral ("field_name"), null);
333
signals_switch = new Vala.SwitchStatement (new Vala.StringLiteral ("field_name"), source_reference);
334
334
block.add_statement (signals_switch);
335
335
register_notify.body = block;
337
337
cl.add_method (register_notify);
340
var con = new Vala.Constructor (null);
341
con.body = new Vala.Block (null);
343
var conn_call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.MemberAccess (new Vala.StringLiteral ("this"), "field_changed"), "connect"));
344
conn_call.add_argument (new Vala.MemberAccess (new Vala.StringLiteral ("this"), "emit_change_notification"));
346
con.body.add_statement (new Vala.ExpressionStatement (conn_call));
340
var con = new Vala.Constructor (source_reference);
341
con.body = new Vala.Block (source_reference);
343
var conn_call = new Vala.MethodCall (new Vala.MemberAccess (new Vala.MemberAccess (new Vala.StringLiteral ("this"), "field_changed", source_reference), "connect", source_reference), source_reference);
344
conn_call.add_argument (new Vala.MemberAccess (new Vala.StringLiteral ("this"), "emit_change_notification", source_reference));
346
con.body.add_statement (new Vala.ExpressionStatement (conn_call, source_reference));
347
347
cl.constructor = con;
349
349
for ( var field = 0 ; field < table.field_count ; field++ ) {
350
this.parse_field (table, field, cl, signals_switch);
350
this.parse_field (table, field, cl, signals_switch, source_reference);