~ubuntu-branches/debian/jessie/sqlheavy/jessie

« back to all changes in this revision

Viewing changes to utils/sqlheavy-gen-orm.vala

  • Committer: Package Import Robot
  • Author(s): Devid Antonio Filoni
  • Date: 2012-05-17 09:47:17 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120517094717-ue17pqaud5tywjj5
Tags: 0.1.1-1
* New upstream release (Closes: #663320).
* Fix debug-package-should-be-priority-extra lintian warning.
* debian/control: switch to vala-0.16 in Build-Depends field.
* debian/libsqlheavy-dev.install, debian/libsqlheavygtk-dev.install:
  install files in vala-0.16 dir.
* Update libsqlheavy0.1-0.symbols.amd64 file.
* debian/rules: update override_dh_makeshlibs target.
* Bump Standards-Version to 3.9.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
      { "metadata", 'm', 0, OptionArg.FILENAME, ref metadata_location, "Load metadata from FILE", "FILE..." },
26
26
      { "vapidir", 0, 0, OptionArg.FILENAME_ARRAY, ref vapi_directories, "Look for package bindings in DIRECTORY", "DIRECTORY..." },
27
27
      { "pkg", 0, 0, OptionArg.STRING_ARRAY, ref packages, "Include binding for PACKAGE", "PACKAGE..." },
28
 
      { "output", 'o', 0, OptionArg.FILENAME, ref output_location, "Output to FILE (default is stdout)", "FILE..." },
 
28
      { "output", 'o', 0, OptionArg.FILENAME, ref output_location, "Output to FILE", "FILE..." },
29
29
      { "properties", 'p', 0, GLib.OptionArg.NONE, ref write_properties, "Write properties instead of methods", null },
30
30
      { "", 0, 0, OptionArg.FILENAME_ARRAY, ref sources, "SQLite databases", "DATABASE..." },
31
31
      { null }
156
156
      return name == null ? null : type_from_string (name);
157
157
    }
158
158
 
159
 
    private void parse_field (SQLHeavy.Table table, int field, Vala.Class cl, Vala.SwitchStatement signals) throws GeneratorError, SQLHeavy.Error {
 
159
    private void parse_field (SQLHeavy.Table table, int field, Vala.Class cl, Vala.SwitchStatement signals, Vala.SourceReference source_reference) throws GeneratorError, SQLHeavy.Error {
160
160
      var db = table.queryable.database;
161
161
      var db_symbol = GLib.Path.get_basename (db.filename).split (".", 2)[0];
162
162
      var symbol = @"@$(GLib.Path.get_basename (db_symbol))/$(table.name)/$(table.field_name (field))";
187
187
      var data_type_get = data_type.copy ();
188
188
      data_type_get.value_owned = true;
189
189
 
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;
194
194
 
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);
200
200
 
201
201
        {
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"));
206
206
 
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));
211
211
 
212
212
          get_method.body = block;
213
213
        }
214
214
 
215
215
        {
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"));
221
221
 
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));
226
226
 
227
227
          set_method.body = block;
228
228
        }
229
229
      } else {
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 ("_", "-") + "\""));
233
 
        {
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);
238
 
 
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));
242
 
 
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));
247
 
 
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));
250
 
 
251
 
          try_stmt.add_catch_clause (new Vala.CatchClause (type_from_string ("SQLHeavy.Error"), "e", catch_block, null));
252
 
          block.add_statement (try_stmt);
253
 
 
254
 
          get_accessor = new Vala.PropertyAccessor (true, false, false, data_type_get, block, null);
255
 
        }
256
 
 
257
 
        {
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);
262
 
 
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));
267
 
 
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));
272
 
 
273
 
          try_stmt.add_catch_clause (new Vala.CatchClause (type_from_string ("SQLHeavy.Error"), "e", catch_block, null));
274
 
          block.add_statement (try_stmt);
275
 
 
276
 
          set_accessor = new Vala.PropertyAccessor (false, true, false, data_type, block, null);
277
 
        }
278
 
 
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));
 
233
        {
 
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);
 
238
 
 
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));
 
242
 
 
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));
 
247
 
 
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));
 
250
 
 
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);
 
253
 
 
254
          get_accessor = new Vala.PropertyAccessor (true, false, false, data_type_get, block, source_reference);
 
255
        }
 
256
 
 
257
        {
 
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);
 
262
 
 
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));
 
267
 
 
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));
 
272
 
 
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);
 
275
 
 
276
          set_accessor = new Vala.PropertyAccessor (false, true, false, data_type, block, source_reference);
 
277
        }
 
278
 
 
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);
282
282
      }
283
283
 
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));
286
286
    }
287
287
 
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)";
297
297
      var cl = ns.scope.lookup (symbol_name) as Vala.Class;
298
298
 
299
299
      if ( cl == null ) {
300
 
        cl = new Vala.Class (symbol_name);
 
300
        cl = new Vala.Class (symbol_name, source_reference);
301
301
        cl.access = Vala.SymbolAccessibility.PUBLIC;
302
302
        ns.add_class (cl);
303
303
      }
310
310
        register_notify.access = Vala.SymbolAccessibility.PRIVATE;
311
311
        register_notify.add_parameter (new Vala.Parameter ("field", type_from_string ("int")));
312
312
 
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);
317
317
 
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));
320
320
 
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)));
325
325
 
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));
332
332
 
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;
336
336
 
337
337
        cl.add_method (register_notify);
338
338
      }
339
339
 
340
 
      var con = new Vala.Constructor (null);
341
 
      con.body = new Vala.Block (null);
342
 
 
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"));
345
 
 
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);
 
342
 
 
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));
 
345
 
 
346
      con.body.add_statement (new Vala.ExpressionStatement (conn_call, source_reference));
347
347
      cl.constructor = con;
348
348
 
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);
351
351
      }
352
352
    }
353
353
 
356
356
      var symbol_name = this.get_symbol_name (symbol);
357
357
      Vala.Namespace? ns = this.context.root.scope.lookup (symbol_name) as Vala.Namespace;
358
358
 
 
359
      Vala.SourceFile source_file = new Vala.SourceFile (this.context, Vala.SourceFileType.NONE, db.filename);
 
360
      Vala.SourceReference source_reference = new Vala.SourceReference (source_file);
 
361
 
359
362
      if ( ns == null ) {
360
 
        ns = new Vala.Namespace (symbol_name, null);
 
363
        ns = new Vala.Namespace (symbol_name, source_reference);
361
364
        this.context.root.add_namespace (ns);
362
365
      }
363
366
 
367
370
      try {
368
371
        var tables = db.get_tables ();
369
372
        foreach ( unowned SQLHeavy.Table table in tables.get_values () ) {
370
 
          this.parse_table (table, ns);
 
373
          this.parse_table (table, ns, source_reference);
371
374
        }
372
375
      } catch ( SQLHeavy.Error e ) {
373
376
        throw new GeneratorError.DATABASE ("Database error: %s", e.message);
375
378
    }
376
379
 
377
380
    public void run () throws GeneratorError {
 
381
      if ( output_location == null ) {
 
382
        GLib.stderr.printf ("You must supply an output location\n");
 
383
        return;
 
384
      }
 
385
 
378
386
      var parser = new Vala.Parser ();
379
387
      parser.parse (this.context);
380
388
 
394
402
      if (context.report.get_errors () > 0)
395
403
        throw new GeneratorError.SYMBOL_RESOLVER ("Error resolving symbols.");
396
404
 
397
 
      var analyzer = new Vala.SemanticAnalyzer ();
398
 
      analyzer.analyze (context);
 
405
      context.analyzer.analyze (context);
399
406
 
400
 
      var code_writer = new Vala.CodeWriter ();
401
 
      code_writer.write_file (this.context, output_location ?? "/dev/stdout");
 
407
      var code_writer = new Vala.CodeWriter (Vala.CodeWriterType.DUMP);
 
408
      code_writer.write_file (this.context, output_location);
402
409
    }
403
410
 
404
411
    private static string parse_selector (string selector, out bool wildcard) throws GeneratorError {
405
412
      wildcard = false;
406
 
      string?[] real_selector = new string[3];
 
413
      string[] real_selector = new string[3];
407
414
      var segments = selector.split ("/", 3);
408
415
 
409
416
      int pos = 0;
480
487
      // Default packages
481
488
      this.context.add_external_package ("glib-2.0");
482
489
      this.context.add_external_package ("gobject-2.0");
483
 
      this.context.add_external_package ("sqlheavy-1.0");
 
490
      this.context.add_external_package ("sqlheavy-%s".printf (SQLHeavy.Version.api ()));
484
491
 
485
492
      foreach ( unowned string pkg in packages ) {
486
493
        this.context.add_external_package (pkg);