diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-09-13 14:02:04 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-09-13 14:02:04 +0200 |
commit | 29c8ce737f513766673fd3e57e30233d9fcce159 (patch) | |
tree | 5438af51e0befd3dbc831f8258d4b2a964f1a957 /tests/compiler | |
parent | 9767fa0eb684560d3ed9a5abc026e658b5ba735a (diff) |
Add C++ source code indenter
Diffstat (limited to 'tests/compiler')
-rw-r--r-- | tests/compiler/cxx-indenter/driver.cxx | 104 | ||||
-rw-r--r-- | tests/compiler/cxx-indenter/makefile | 71 | ||||
-rw-r--r-- | tests/compiler/cxx-indenter/output.std | 75 | ||||
-rw-r--r-- | tests/compiler/makefile | 2 |
4 files changed, 251 insertions, 1 deletions
diff --git a/tests/compiler/cxx-indenter/driver.cxx b/tests/compiler/cxx-indenter/driver.cxx new file mode 100644 index 0000000..0f9a3c5 --- /dev/null +++ b/tests/compiler/cxx-indenter/driver.cxx @@ -0,0 +1,104 @@ +// file : tests/compiler/cxx-indenter/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include <fstream> +#include <iostream> + +#include <cutl/compiler/code-stream.hxx> +#include <cutl/compiler/cxx-indenter.hxx> + +using namespace std; +using namespace cutl::compiler; + +int +main () +{ + //std::wostream& os (wcout); + //ostream_filter<cxx_indenter, wchar_t> filt (os); + + std::ostream& os (cout); + ostream_filter<cxx_indenter, char> filt (os); + + os << "if (true)" + << "{" + << "// Hello there" << endl + << "//" << endl + << "a ();" + << "}" + << "else" + << "{" + << "b ();" + << "}"; + + os << "if (false)" + << "{" + << "if (true)" + << "{" + << "// test" << endl + << "}" + << "else" + << "{" + << "// test" << endl + << "b ();" + << "}" + << "}"; + + os << "namespace a" + << "{" + << "void f ();" + << "}" + << "#if defined(__HP_aCC) && __HP_aCC <= 39999" << endl + << "#include <foo.h>" << endl + << "#endif" << endl + << endl + << "namespace b" + << "{" + << "void f ();" + << "}"; + + // Test do-while handling. + // + os << "do" << endl + << "f ();" + << "while (false);" + << endl; + + os << "do" + << "{" + << "f ();" + << "}" + << "while (false);" + << endl; + + os << "do" + << "{" + << "if (f ())" + << "{" + << "g ();" + << "}" + << "}" + << "while (false);" + << endl; + + os << "do" + << "{" + << "do" << endl + << "f ();" + << "while (false);" + << "}" + << "while (false);" + << endl; + + os << "do" + << "{" + << "do" + << "{" + << "f ();" + << "}" + << "while (false);" + << "}" + << "while (false);" + << endl; +} diff --git a/tests/compiler/cxx-indenter/makefile b/tests/compiler/cxx-indenter/makefile new file mode 100644 index 0000000..c0e7cff --- /dev/null +++ b/tests/compiler/cxx-indenter/makefile @@ -0,0 +1,71 @@ +# file : tests/compiler/cxx-indenter/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2009 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +cutl.l := $(out_root)/cutl/cutl.l +cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) $(cutl.l) +$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options) + + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/output.std + $(call message,test $$1,$$1 | diff -u $(src_base)/output.std -,$(driver)) + + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) + +# Dependencies. +# +$(call import,$(src_root)/cutl/makefile) diff --git a/tests/compiler/cxx-indenter/output.std b/tests/compiler/cxx-indenter/output.std new file mode 100644 index 0000000..1a22bc7 --- /dev/null +++ b/tests/compiler/cxx-indenter/output.std @@ -0,0 +1,75 @@ +if (true) +{ + // Hello there + // + a (); +} +else +{ + b (); +} + +if (false) +{ + if (true) + { + // test + } + else + { + // test + b (); + } +} + +namespace a +{ + void f (); +} + +#if defined(__HP_aCC) && __HP_aCC <= 39999 +#include <foo.h> +#endif + +namespace b +{ + void f (); +} + +do + f (); +while (false); + +do +{ + f (); +} +while (false); + +do +{ + if (f ()) + { + g (); + } +} +while (false); + +do +{ + do + f (); + while (false); +} +while (false); + +do +{ + do + { + f (); + } + while (false); +} +while (false); + diff --git a/tests/compiler/makefile b/tests/compiler/makefile index 42fd2bf..dfbd7cb 100644 --- a/tests/compiler/makefile +++ b/tests/compiler/makefile @@ -5,7 +5,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make -tests := sloc-counter traversal +tests := cxx-indenter sloc-counter traversal default := $(out_base)/ test := $(out_base)/.test |