From ed60746355044dd39acd82b8f42c4d9886914567 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 2 Jun 2010 17:22:12 +0200 Subject: Implement generation of specifier functions (--generate-specifier) These functions determine whether the option was specified on the command line. New test: specifier. --- tests/makefile | 2 +- tests/specifier/driver.cxx | 30 +++++++++++++++++++ tests/specifier/makefile | 73 ++++++++++++++++++++++++++++++++++++++++++++++ tests/specifier/test.cli | 13 +++++++++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 tests/specifier/driver.cxx create mode 100644 tests/specifier/makefile create mode 100644 tests/specifier/test.cli (limited to 'tests') diff --git a/tests/makefile b/tests/makefile index 109c48d..0d96d76 100644 --- a/tests/makefile +++ b/tests/makefile @@ -5,7 +5,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make -tests := ctor erase file lexer parser +tests := ctor erase file lexer parser specifier default := $(out_base)/ test := $(out_base)/.test diff --git a/tests/specifier/driver.cxx b/tests/specifier/driver.cxx new file mode 100644 index 0000000..9f9005a --- /dev/null +++ b/tests/specifier/driver.cxx @@ -0,0 +1,30 @@ +// file : tests/specifier/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +// Test specifier functions. +// + +#include +#include + +#include "test.hxx" + +using namespace std; + +int +main (int argc, char* argv[]) +{ + options o (argc, argv); + + assert (o.a ()); + assert (o.b () == 1 && !o.b_specified ()); + assert (o.c () == "foo" && o.c_specified ()); + + o.b_specified (true); + o.c_specified (false); + + assert (o.b_specified ()); + assert (!o.c_specified ()); +} diff --git a/tests/specifier/makefile b/tests/specifier/makefile new file mode 100644 index 0000000..d2f67a3 --- /dev/null +++ b/tests/specifier/makefile @@ -0,0 +1,73 @@ +# file : tests/specifier/makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +cxx_tun := driver.cxx +cli_tun := test.cli + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(cli_tun:.cli=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) +$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) + +genf := $(cli_tun:.cli=.hxx) $(cli_tun:.cli=.ixx) $(cli_tun:.cli=.cxx) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(out_root)/cli/cli +$(gen): cli := $(out_root)/cli/cli +$(gen): cli_options := --generate-specifier --generate-modifier + +$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) + +# Alias for default target. +# +$(out_base)/: $(driver) + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) + $(call message,test $$1,$$1 -a -c foo,$(driver)) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) \ + $(addprefix $(out_base)/,$(cli_tun:.cli=.cxx.cli.clean)) + +# 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)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/cli/cli-cxx.make) + +# Dependencies. +# +$(call import,$(src_root)/cli/makefile) + diff --git a/tests/specifier/test.cli b/tests/specifier/test.cli new file mode 100644 index 0000000..e9c9ad0 --- /dev/null +++ b/tests/specifier/test.cli @@ -0,0 +1,13 @@ +// file : tests/specifier/test.cli +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +include ; + +class options +{ + bool -a; + int -b = 1; + std::string -c; +}; -- cgit v1.1