From d4a78b31a1a045471c2fe12d2618d9d5edf78fb2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 11 Feb 2011 17:01:02 +0200 Subject: Fix recursive polymorphic parsing in C++/Parser New test: cxx/parser/polymorphism/recursive. --- tests/cxx/parser/polymorphism/recursive/driver.cxx | 70 ++++++++++ tests/cxx/parser/polymorphism/recursive/makefile | 80 +++++++++++ tests/cxx/parser/polymorphism/recursive/output | 22 +++ .../parser/polymorphism/recursive/test-pimpl.cxx | 149 +++++++++++++++++++++ .../parser/polymorphism/recursive/test-pimpl.hxx | 96 +++++++++++++ tests/cxx/parser/polymorphism/recursive/test.xml | 15 +++ tests/cxx/parser/polymorphism/recursive/test.xsd | 53 ++++++++ 7 files changed, 485 insertions(+) create mode 100644 tests/cxx/parser/polymorphism/recursive/driver.cxx create mode 100644 tests/cxx/parser/polymorphism/recursive/makefile create mode 100644 tests/cxx/parser/polymorphism/recursive/output create mode 100644 tests/cxx/parser/polymorphism/recursive/test-pimpl.cxx create mode 100644 tests/cxx/parser/polymorphism/recursive/test-pimpl.hxx create mode 100644 tests/cxx/parser/polymorphism/recursive/test.xml create mode 100644 tests/cxx/parser/polymorphism/recursive/test.xsd (limited to 'tests/cxx/parser/polymorphism/recursive') diff --git a/tests/cxx/parser/polymorphism/recursive/driver.cxx b/tests/cxx/parser/polymorphism/recursive/driver.cxx new file mode 100644 index 0000000..c91a1c0 --- /dev/null +++ b/tests/cxx/parser/polymorphism/recursive/driver.cxx @@ -0,0 +1,70 @@ +// file : tests/cxx/parser/polymorphism/recursive/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2006-2011 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test polymorphic recursive parsing. +// + +#include +#include + +#include "test-pskel.hxx" +#include "test-pimpl.hxx" + +using namespace std; +using namespace test; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + try + { + xml_schema::int_pimpl int_p; + + root_pimpl root_p; + expression_pimpl expression_p; + recursive_pimpl recursive_p; + value_a_pimpl value_a_p; + value_b_pimpl value_b_p; + + xml_schema::parser_map_impl expression_map; + + // Connect the parsers together. + // + root_p.parsers (expression_p); + expression_map.insert(value_a_p); + expression_map.insert(value_b_p); + expression_map.insert(recursive_p); + + root_p.expression_parser(expression_map); + + recursive_p.parsers(expression_p); + recursive_p.expression_parser(expression_map); + + value_a_p.parsers(int_p); + value_b_p.parsers(int_p); + + xml_schema::document doc_p (root_p, "test", "root", true); + + root_p.pre (); + doc_p.parse (argv[1]); + root_p.post_root (); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } + catch (std::ios_base::failure const&) + { + cerr << "io failure" << endl; + return 1; + } +} diff --git a/tests/cxx/parser/polymorphism/recursive/makefile b/tests/cxx/parser/polymorphism/recursive/makefile new file mode 100644 index 0000000..4ae706e --- /dev/null +++ b/tests/cxx/parser/polymorphism/recursive/makefile @@ -0,0 +1,80 @@ +# file : tests/cxx/parser/polymorphism/recursive/makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2006-2011 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make + +xsd := test.xsd +cxx := driver.cxx test-pimpl.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o)) +dep := $(obj:.o=.o.d) + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Import. +# +$(call import,\ + $(scf_root)/import/libxerces-c/stub.make,\ + l: xerces_c.l,cpp-options: xerces_c.l.cpp-options) + +# Build. +# +$(driver): $(obj) $(xerces_c.l) + +$(obj) $(dep): cpp_options := -I$(src_root)/libxsd +$(obj) $(dep): $(xerces_c.l.cpp-options) + +genf := $(xsd:.xsd=-pskel.hxx) $(xsd:.xsd=-pskel.ixx) $(xsd:.xsd=-pskel.cxx) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): xsd := $(out_root)/xsd/xsd +$(gen): xsd_options := --generate-polymorphic +$(gen): $(out_root)/xsd/xsd + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/output + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(gen): | $(out_base)/.gitignore +$(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)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsd/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsd/makefile) diff --git a/tests/cxx/parser/polymorphism/recursive/output b/tests/cxx/parser/polymorphism/recursive/output new file mode 100644 index 0000000..28a835f --- /dev/null +++ b/tests/cxx/parser/polymorphism/recursive/output @@ -0,0 +1,22 @@ +root start +recursive start +value_a begin +value->constant +value: post_expression override +value_a: post_value override +value_a end +recursive->expression event +recursive start +value_b begin +value->constant +value: post_expression override +value_b: post_value override +value_b end +recursive->expression event +recursive: post_expression override +recursive end +recursive->expression event +recursive: post_expression override +recursive end +root->expression +root end diff --git a/tests/cxx/parser/polymorphism/recursive/test-pimpl.cxx b/tests/cxx/parser/polymorphism/recursive/test-pimpl.cxx new file mode 100644 index 0000000..3be2921 --- /dev/null +++ b/tests/cxx/parser/polymorphism/recursive/test-pimpl.cxx @@ -0,0 +1,149 @@ +// file : tests/cxx/parser/polymorphism/recursive/test-pimpl.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2006-2011 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +#include "test-pimpl.hxx" + +using namespace std; + +namespace test +{ + // root_pimpl + // + + void root_pimpl:: + pre () + { + cout << "root start" << endl; + } + + void root_pimpl:: + expression () + { + cout << "root->expression" << endl; + } + + void root_pimpl:: + post_root () + { + cout << "root end" << endl; + } + + // expression_pimpl + // + + void expression_pimpl:: + pre () + { + cout << "expression begin" << endl; + } + + void expression_pimpl:: + post_expression () + { + cout << "expression end" << endl; + } + + // recursive_pimpl + // + + void recursive_pimpl:: + pre () + { + cout << "recursive start" << endl; + } + + void recursive_pimpl:: + expression () + { + cout << "recursive->expression event" << endl; + } + + void recursive_pimpl:: + post_expression () + { + cout << "recursive: post_expression override" << endl; + post_recursive (); + } + + void recursive_pimpl:: + post_recursive () + { + cout << "recursive end" << endl; + } + + // value_pimpl + // + + void value_pimpl:: + pre () + { + cout << "value begin" << endl; + } + + void value_pimpl:: + constant (int) + { + cout << "value->constant" << endl; + } + + void value_pimpl:: + post_expression () + { + cout << "value: post_expression override" << endl; + post_value (); + } + + void value_pimpl:: + post_value () + { + cout << "value end" << endl; + } + + // value_a_pimpl + // + + void value_a_pimpl:: + pre () + { + cout << "value_a begin" << endl; + } + + void value_a_pimpl:: + post_value () + { + cout << "value_a: post_value override" << endl; + post_value_a (); + } + + void value_a_pimpl:: + post_value_a () + { + cout << "value_a end" << endl; + } + + // value_b_pimpl + // + + void value_b_pimpl:: + pre () + { + cout << "value_b begin" << endl; + } + + void value_b_pimpl:: + post_value () + { + cout << "value_b: post_value override" << endl; + post_value_b (); + } + + void value_b_pimpl:: + post_value_b () + { + cout << "value_b end" << endl; + } +} diff --git a/tests/cxx/parser/polymorphism/recursive/test-pimpl.hxx b/tests/cxx/parser/polymorphism/recursive/test-pimpl.hxx new file mode 100644 index 0000000..2dc2d35 --- /dev/null +++ b/tests/cxx/parser/polymorphism/recursive/test-pimpl.hxx @@ -0,0 +1,96 @@ +// file : tests/cxx/parser/polymorphism/recursive/test-pimpl.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2006-2011 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef TEST_PIMPL_HXX +#define TEST_PIMPL_HXX + +#include "test-pskel.hxx" + +namespace test +{ + class root_pimpl: public virtual root_pskel + { + public: + virtual void + pre (); + + virtual void + expression (); + + virtual void + post_root (); + }; + + class expression_pimpl: public virtual expression_pskel + { + public: + virtual void + pre (); + + virtual void + post_expression (); + }; + + class recursive_pimpl: public virtual recursive_pskel, + public expression_pimpl + { + public: + virtual void + pre (); + + virtual void + expression (); + + virtual void + post_expression (); + + virtual void + post_recursive (); + }; + + class value_pimpl: public virtual value_pskel, public expression_pimpl + { + public: + virtual void + pre (); + + virtual void + constant (int); + + virtual void + post_expression (); + + virtual void + post_value (); + }; + + class value_a_pimpl: public virtual value_a_pskel, public value_pimpl + { + public: + virtual void + pre (); + + virtual void + post_value (); + + virtual void + post_value_a (); + }; + + class value_b_pimpl: public virtual value_b_pskel, public value_pimpl + { + public: + virtual void + pre (); + + virtual void + post_value (); + + virtual void + post_value_b (); + }; +} + +#endif // TEST_PIMPL_HXX diff --git a/tests/cxx/parser/polymorphism/recursive/test.xml b/tests/cxx/parser/polymorphism/recursive/test.xml new file mode 100644 index 0000000..42035ba --- /dev/null +++ b/tests/cxx/parser/polymorphism/recursive/test.xml @@ -0,0 +1,15 @@ + + + + + 1 + + + + 2 + + + + diff --git a/tests/cxx/parser/polymorphism/recursive/test.xsd b/tests/cxx/parser/polymorphism/recursive/test.xsd new file mode 100644 index 0000000..affcc8a --- /dev/null +++ b/tests/cxx/parser/polymorphism/recursive/test.xsd @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.1