From dc5874e5b8cdb2a8c8a5dc77a0bb4bd891079e3f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 16 Jul 2012 09:56:04 +0200 Subject: Fix code generation for circularly-dependant classes in separate headers New tests: common/circular/{single,multiple}. --- common/circular/multiple/driver.cxx | 51 ++++++++++++++++ common/circular/multiple/makefile | 116 ++++++++++++++++++++++++++++++++++++ common/circular/multiple/test.std | 0 common/circular/multiple/test1.hxx | 28 +++++++++ common/circular/multiple/test2.hxx | 18 ++++++ common/circular/single/driver.cxx | 39 ++++++++++++ common/circular/single/makefile | 113 +++++++++++++++++++++++++++++++++++ common/circular/single/test.hxx | 29 +++++++++ common/circular/single/test.std | 0 common/makefile | 2 + 10 files changed, 396 insertions(+) create mode 100644 common/circular/multiple/driver.cxx create mode 100644 common/circular/multiple/makefile create mode 100644 common/circular/multiple/test.std create mode 100644 common/circular/multiple/test1.hxx create mode 100644 common/circular/multiple/test2.hxx create mode 100644 common/circular/single/driver.cxx create mode 100644 common/circular/single/makefile create mode 100644 common/circular/single/test.hxx create mode 100644 common/circular/single/test.std (limited to 'common') diff --git a/common/circular/multiple/driver.cxx b/common/circular/multiple/driver.cxx new file mode 100644 index 0000000..2f28911 --- /dev/null +++ b/common/circular/multiple/driver.cxx @@ -0,0 +1,51 @@ +// file : common/circular/multiple/driver.cxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test cases of circular dependencies between persistent classes, multiple +// files version. +// + +#include // std::auto_ptr +#include +#include + +#include +#include +#include + +#include + +#include "test1.hxx" +#include "test2.hxx" + +#include "test2-odb.hxx" +#include "test1-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr db (create_database (argc, argv, false)); + + // Create the database schema. + // + { + transaction t (db->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + } + + query bq (query::d->id != 0); + query dq (query::b->id != 0); + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/common/circular/multiple/makefile b/common/circular/multiple/makefile new file mode 100644 index 0000000..82a0bae --- /dev/null +++ b/common/circular/multiple/makefile @@ -0,0 +1,116 @@ +# file : common/circular/multiple/makefile +# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx +odb_hdr := test1.hxx test2.hxx +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +common.l := $(out_root)/libcommon/common/common.l +common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options + +driver := $(out_base)/driver +dist := $(out_base)/.dist +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Import. +# +$(call import,\ + $(scf_root)/import/odb/stub.make,\ + odb: odb,odb-rules: odb_rules) + +# Build. +# +$(driver): $(cxx_obj) $(common.l) +$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) +$(cxx_obj) $(cxx_od): $(common.l.cpp-options) + +genf := $(foreach f,$(odb_hdr:.hxx=),$(addprefix $f,-odb.hxx -odb.ixx -odb.cxx .sql)) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(odb) +$(gen): odb := $(odb) +$(gen) $(dist): export odb_options += --database $(db_id) --generate-schema \ +--schema-format embedded --generate-query --table-prefix circular_m_ +$(gen): cpp_options := -I$(src_base) +$(gen): $(common.l.cpp-options) + +# Extra dependecy for the ODB-generated code. +# +$(gen): $(src_base)/test1.hxx $(src_base)/test2.hxx + +$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) + +# Alias for default target. +# +$(out_base)/: $(driver) + +# Dist +# +name := $(subst /,-,$(subst $(src_root)/common/,,$(src_base))) + +$(dist): db_id := @database@ +$(dist): sources := $(cxx_tun) +$(dist): headers := $(odb_hdr) +$(dist): data_dist := test.std +$(dist): export name := $(name) +$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ +$(call vc10projs,$(name)) +$(dist): + $(call dist-data,$(sources) $(headers) $(data_dist)) + $(call meta-automake,../template/Makefile.am) + $(call meta-vc9projs,../template/template,$(name)) + $(call meta-vc10projs,../template/template,$(name)) + +# Test. +# +$(test): $(driver) $(src_base)/test.std + $(call message,test $<,$< --options-file $(dcf_root)/db.options \ +>$(out_base)/test.out) + $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) + $(call message,,rm -f $(out_base)/test.out) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) \ + $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(call message,,rm -f $(out_base)/test.out) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + +# How to. +# +$(call include,$(bld_root)/dist.make) +$(call include,$(bld_root)/meta/vc9proj.make) +$(call include,$(bld_root)/meta/vc10proj.make) +$(call include,$(bld_root)/meta/automake.make) + +$(call include,$(bld_root)/cxx/standard.make) # cxx_standard +ifdef cxx_standard +$(gen): odb_options += --std $(cxx_standard) +$(call include,$(odb_rules)) +endif + +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/o-e.make) + +# Dependencies. +# +$(call import,$(src_root)/libcommon/makefile) diff --git a/common/circular/multiple/test.std b/common/circular/multiple/test.std new file mode 100644 index 0000000..e69de29 diff --git a/common/circular/multiple/test1.hxx b/common/circular/multiple/test1.hxx new file mode 100644 index 0000000..5ba4b92 --- /dev/null +++ b/common/circular/multiple/test1.hxx @@ -0,0 +1,28 @@ +// file : common/circular/multiple/test1.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST1_HXX +#define TEST1_HXX + +#include + +#pragma db object +struct derived; + +#pragma db object polymorphic +struct base +{ + virtual ~base () {} + + #pragma db id + unsigned long id_; + + derived* d_; +}; + +#ifdef ODB_COMPILER +# include "test2.hxx" +#endif + +#endif // TEST1_HXX diff --git a/common/circular/multiple/test2.hxx b/common/circular/multiple/test2.hxx new file mode 100644 index 0000000..8f6ae5e --- /dev/null +++ b/common/circular/multiple/test2.hxx @@ -0,0 +1,18 @@ +// file : common/circular/multiple/test2.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST2_HXX +#define TEST2_HXX + +#include + +#include "test1.hxx" + +#pragma db object +struct derived: base +{ + base* b_; +}; + +#endif // TEST2_HXX diff --git a/common/circular/single/driver.cxx b/common/circular/single/driver.cxx new file mode 100644 index 0000000..e4b0be6 --- /dev/null +++ b/common/circular/single/driver.cxx @@ -0,0 +1,39 @@ +// file : common/circular/single/driver.cxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test cases of circular dependencies between persistent classes, single +// file version. +// + +#include // std::auto_ptr +#include +#include + +#include +#include + +#include + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr db (create_database (argc, argv)); + + query bq (query::d->id != 0); + query dq (query::b->id != 0); + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/common/circular/single/makefile b/common/circular/single/makefile new file mode 100644 index 0000000..e1677d4 --- /dev/null +++ b/common/circular/single/makefile @@ -0,0 +1,113 @@ +# file : common/circular/single/makefile +# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx +odb_hdr := test.hxx +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +common.l := $(out_root)/libcommon/common/common.l +common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options + +driver := $(out_base)/driver +dist := $(out_base)/.dist +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Import. +# +$(call import,\ + $(scf_root)/import/odb/stub.make,\ + odb: odb,odb-rules: odb_rules) + +# Build. +# +$(driver): $(cxx_obj) $(common.l) +$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) +$(cxx_obj) $(cxx_od): $(common.l.cpp-options) + +genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(odb) +$(gen): odb := $(odb) +$(gen) $(dist): export odb_options += --database $(db_id) --generate-schema \ +--generate-query --table-prefix circular_s_ +$(gen): cpp_options := -I$(src_base) +$(gen): $(common.l.cpp-options) + +$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) + +# Alias for default target. +# +$(out_base)/: $(driver) + +# Dist +# +name := $(subst /,-,$(subst $(src_root)/common/,,$(src_base))) + +$(dist): db_id := @database@ +$(dist): sources := $(cxx_tun) +$(dist): headers := $(odb_hdr) +$(dist): data_dist := test.std +$(dist): export name := $(name) +$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ +$(call vc10projs,$(name)) +$(dist): + $(call dist-data,$(sources) $(headers) $(data_dist)) + $(call meta-automake,../template/Makefile.am) + $(call meta-vc9projs,../template/template,$(name)) + $(call meta-vc10projs,../template/template,$(name)) + +# Test. +# +$(test): $(driver) $(src_base)/test.std + $(call schema) + $(call message,test $<,$< --options-file $(dcf_root)/db.options \ +>$(out_base)/test.out) + $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) + $(call message,,rm -f $(out_base)/test.out) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) \ + $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(call message,,rm -f $(out_base)/test.out) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + +# How to. +# +$(call include,$(bld_root)/dist.make) +$(call include,$(bld_root)/meta/vc9proj.make) +$(call include,$(bld_root)/meta/vc10proj.make) +$(call include,$(bld_root)/meta/automake.make) + +$(call include,$(bld_root)/cxx/standard.make) # cxx_standard +ifdef cxx_standard +$(gen): odb_options += --std $(cxx_standard) +$(call include,$(odb_rules)) +endif + +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/o-e.make) + +# Dependencies. +# +$(call import,$(src_root)/libcommon/makefile) diff --git a/common/circular/single/test.hxx b/common/circular/single/test.hxx new file mode 100644 index 0000000..8dd39fe --- /dev/null +++ b/common/circular/single/test.hxx @@ -0,0 +1,29 @@ +// file : common/circular/single/test.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include + +struct derived; + +#pragma db object polymorphic +struct base +{ + virtual ~base () {} + + #pragma db id + unsigned long id_; + + derived* d_; +}; + +#pragma db object +struct derived: base +{ + base* b_; +}; + +#endif // TEST_HXX diff --git a/common/circular/single/test.std b/common/circular/single/test.std new file mode 100644 index 0000000..e69de29 diff --git a/common/makefile b/common/makefile index 3ec0aa2..cb033a8 100644 --- a/common/makefile +++ b/common/makefile @@ -8,6 +8,8 @@ tests := \ auto \ blob \ callback \ +circular/single \ +circular/multiple \ composite \ composite-id \ const-object \ -- cgit v1.1