From 26899a31d9a85e6ec6cfb782b0977af05e3330c1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 22 Jun 2012 11:51:14 +0200 Subject: Get rid of dependency on libcult --- build/import/libcult/LICENSE | 340 ----------------------- build/import/libcult/configuration-rules.make | 15 - build/import/libcult/configure | 55 ---- build/import/libcult/stub.make | 30 -- tests/dump/driver.cxx | 23 +- xsd-frontend/makefile | 11 +- xsd-frontend/parser.cxx | 22 +- xsd-frontend/parser.hxx | 11 +- xsd-frontend/semantic-graph/annotation.hxx | 6 +- xsd-frontend/semantic-graph/any-attribute.cxx | 8 +- xsd-frontend/semantic-graph/any-attribute.hxx | 4 +- xsd-frontend/semantic-graph/any.cxx | 8 +- xsd-frontend/semantic-graph/any.hxx | 4 +- xsd-frontend/semantic-graph/elements.hxx | 18 +- xsd-frontend/transformations/anonymous.cxx | 4 - xsd-frontend/transformations/anonymous.hxx | 14 +- xsd-frontend/transformations/enum-synthesis.cxx | 3 - xsd-frontend/transformations/enum-synthesis.hxx | 4 +- xsd-frontend/transformations/restriction.cxx | 6 +- xsd-frontend/transformations/restriction.hxx | 4 +- xsd-frontend/transformations/schema-per-type.cxx | 18 +- xsd-frontend/transformations/schema-per-type.hxx | 12 +- xsd-frontend/transformations/simplifier.cxx | 2 - xsd-frontend/transformations/simplifier.hxx | 4 +- xsd-frontend/traversal/elements.hxx | 4 +- xsd-frontend/types.cxx | 62 +++++ xsd-frontend/types.hxx | 237 +++++++++++++++- xsd-frontend/xml.hxx | 2 +- 28 files changed, 374 insertions(+), 557 deletions(-) delete mode 100644 build/import/libcult/LICENSE delete mode 100644 build/import/libcult/configuration-rules.make delete mode 100755 build/import/libcult/configure delete mode 100644 build/import/libcult/stub.make create mode 100644 xsd-frontend/types.cxx diff --git a/build/import/libcult/LICENSE b/build/import/libcult/LICENSE deleted file mode 100644 index 3912109..0000000 --- a/build/import/libcult/LICENSE +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/build/import/libcult/configuration-rules.make b/build/import/libcult/configuration-rules.make deleted file mode 100644 index dc19df4..0000000 --- a/build/import/libcult/configuration-rules.make +++ /dev/null @@ -1,15 +0,0 @@ -# file : build/import/libcult/configuration-rules.make -# author : Boris Kolpackov -# copyright : Copyright (c) 2005-2009 Boris Kolpackov -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libcult/configuration-dynamic.make: | $(dcf_root)/import/libcult/. - $(call message,,$(scf_root)/import/libcult/configure $@) - -ifndef %foreign% - -disfigure:: - $(call message,rm $(dcf_root)/import/libcult/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/libcult/configuration-dynamic.make) - -endif diff --git a/build/import/libcult/configure b/build/import/libcult/configure deleted file mode 100755 index afa4c9c..0000000 --- a/build/import/libcult/configure +++ /dev/null @@ -1,55 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/libcult/configure -# author : Boris Kolpackov -# copyright : Copyright (c) 2005-2009 Boris Kolpackov -# license : GNU GPL v2; see accompanying LICENSE file - - -# $1 - out file -# -# bld_root - build root -# project_name - project name -# - -source $bld_root/dialog.bash - - -$echo -$echo "Configuring external dependency on 'libcult' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed " -$echo "version of 'libcult' as opposed to the development build?" -$echo - -installed=`read_y_n y` - -path= - -if [ "$installed" = "n" ]; then - -$echo -$echo "Please enter the src_root for 'libcult'." -$echo - -src_root=`read_path --directory --exist` - -$echo -$echo "Please enter the out_root for 'libcult'." -$echo - -out_root=`read_path --directory $src_root` - -fi - -echo libcult_installed := $installed >$1 - -if [ "$installed" = "n" ]; then - -echo src_root := $src_root >>$1 -echo scf_root := \$\(src_root\)/build >>$1 -echo out_root := $out_root >>$1 - -fi diff --git a/build/import/libcult/stub.make b/build/import/libcult/stub.make deleted file mode 100644 index f5f7691..0000000 --- a/build/import/libcult/stub.make +++ /dev/null @@ -1,30 +0,0 @@ -# file : build/import/libcult/stub.make -# author : Boris Kolpackov -# copyright : Copyright (c) 2005-2009 Boris Kolpackov -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libcult/configuration-rules.make,$(dcf_root)) - -libcult_installed := - -$(call -include,$(dcf_root)/import/libcult/configuration-dynamic.make) - -ifdef libcult_installed - -ifeq ($(libcult_installed),y) - -$(call export,l: -lcult,cpp-options: ) - -else - -# Include export stub. -# -$(call include,$(scf_root)/export/libcult/stub.make) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/tests/dump/driver.cxx b/tests/dump/driver.cxx index 0d98e10..f17579f 100644 --- a/tests/dump/driver.cxx +++ b/tests/dump/driver.cxx @@ -3,8 +3,7 @@ // copyright : Copyright (c) 2006-2011 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file -#include - +#include #include #include #include @@ -14,10 +13,8 @@ #include -using namespace Cult::Types; -using namespace XSDFrontend; - using namespace std; +using namespace XSDFrontend; static unsigned long indent; @@ -32,8 +29,6 @@ ind (std::wostream& os) namespace { - typedef Cult::Types::WideString String; - // Nameable which is named in the namespace scope. // String @@ -543,11 +538,11 @@ namespace struct AnonymousNameTranslator: Transformations::AnonymousNameTranslator { - virtual WideString - translate (WideString const& /*file*/, - WideString const& ns, - WideString const& name, - WideString const& xpath) + virtual String + translate (String const& /*file*/, + String const& ns, + String const& name, + String const& xpath) { wcout << "anonymous: " << ns << " " << name << " " << xpath << endl; return name; @@ -555,7 +550,7 @@ struct AnonymousNameTranslator: Transformations::AnonymousNameTranslator }; int -main (int argc, Char* argv[]) +main (int argc, char* argv[]) { try { @@ -567,7 +562,7 @@ main (int argc, Char* argv[]) // Parse options. // - Int i (1); + int i (1); bool anon (false); bool enum_synth (false); diff --git a/xsd-frontend/makefile b/xsd-frontend/makefile index 010ec7d..68b427a 100644 --- a/xsd-frontend/makefile +++ b/xsd-frontend/makefile @@ -44,7 +44,7 @@ cxx_tun += transformations/anonymous.cxx \ transformations/schema-per-type.cxx \ transformations/simplifier.cxx -cxx_tun += parser.cxx schema-dom-parser.cxx +cxx_tun += types.cxx parser.cxx schema-dom-parser.cxx cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) @@ -71,19 +71,14 @@ $(call import,\ $(scf_root)/import/libcutl/stub.make,\ l: cutl.l,cpp-options: cutl.l.cpp-options) -$(call import,\ - $(scf_root)/import/libcult/stub.make,\ - l: cult.l,cpp-options: cult.l.cpp-options) - -# what to build +# What to build. # -$(xsd_frontend.l): $(cxx_obj) $(cult.l) $(cutl.l) $(xerces_c.l) $(fs.l) +$(xsd_frontend.l): $(cxx_obj) $(cutl.l) $(xerces_c.l) $(fs.l) $(xsd_frontend.l.cpp-options): prefix := xsd-frontend/ $(out_root)/ $(xsd_frontend.l.cpp-options): value := -I$(src_root) -I$(out_root) $(xsd_frontend.l.cpp-options): \ $(fs.l.cpp-options) \ - $(cult.l.cpp-options) \ $(cutl.l.cpp-options) #@@ This can be further optimized since only parser depends on xerces. diff --git a/xsd-frontend/parser.cxx b/xsd-frontend/parser.cxx index 782b01f..3a0b180 100644 --- a/xsd-frontend/parser.cxx +++ b/xsd-frontend/parser.cxx @@ -11,7 +11,6 @@ #include -#include #include #include #include @@ -107,10 +106,10 @@ namespace XSDFrontend // Trim leading and trailing whitespaces. // template - Cult::StringTemplate - trim (Cult::StringTemplate const& s) + StringTemplate + trim (StringTemplate const& s) { - typedef Cult::StringTemplate String; + typedef StringTemplate String; size_t size (s.size ()); @@ -1312,8 +1311,11 @@ namespace XSDFrontend // Parser::Impl // - class Parser::Impl: public NonCopyable + class Parser::Impl { + Impl (Impl const&); + Impl& operator= (Impl const&); + public: ~Impl (); @@ -1417,7 +1419,7 @@ namespace XSDFrontend private: bool - is_disabled (Char const* warning) + is_disabled (char const* warning) { return disabled_warnings_all_ || (disabled_warnings_ && @@ -4750,8 +4752,10 @@ namespace XSDFrontend // that can later be used in diagnostics. Unfortunately, it doesn't // work. So we will have to keep our own track. // - struct Context: public NonCopyable + struct Context { + Context () {} + // File map for diagnostic. // Path const& @@ -4776,6 +4780,10 @@ namespace XSDFrontend } private: + Context (Context const&); + Context& operator= (Context const&); + + private: typedef std::map FileMap; FileMap file_map_; }; diff --git a/xsd-frontend/parser.hxx b/xsd-frontend/parser.hxx index 2efb75f..cf8122f 100644 --- a/xsd-frontend/parser.hxx +++ b/xsd-frontend/parser.hxx @@ -9,14 +9,11 @@ #include #include // std::auto_ptr -#include - +#include #include namespace XSDFrontend { - using namespace Cult::Types; - struct InvalidSchema {}; class LocationTranslator @@ -34,7 +31,7 @@ namespace XSDFrontend // typedef std::set WarningSet; - class Parser: public NonCopyable + class Parser { public: ~Parser (); @@ -49,6 +46,10 @@ namespace XSDFrontend LocationTranslator&, const WarningSet& disabled); + private: + Parser (Parser const&); + Parser& operator= (Parser const&); + public: // Parse a schema file. Throws InvalidSchema in case of a failure. // diff --git a/xsd-frontend/semantic-graph/annotation.hxx b/xsd-frontend/semantic-graph/annotation.hxx index 3d6f098..6752a86 100644 --- a/xsd-frontend/semantic-graph/annotation.hxx +++ b/xsd-frontend/semantic-graph/annotation.hxx @@ -49,7 +49,7 @@ namespace XSDFrontend class Annotation: public virtual Node { public: - WideString const& + String const& documentation () const { return documentation_; @@ -59,7 +59,7 @@ namespace XSDFrontend Annotation (Path const& file, unsigned long line, unsigned long column, - WideString const& documentation) + String const& documentation) : Node (file, line, column), documentation_ (documentation) { } @@ -68,7 +68,7 @@ namespace XSDFrontend add_edge_left (Annotates&) {} private: - WideString documentation_; + String documentation_; }; } } diff --git a/xsd-frontend/semantic-graph/any-attribute.cxx b/xsd-frontend/semantic-graph/any-attribute.cxx index 8a8660c..a5dcd36 100644 --- a/xsd-frontend/semantic-graph/any-attribute.cxx +++ b/xsd-frontend/semantic-graph/any-attribute.cxx @@ -16,7 +16,7 @@ namespace XSDFrontend AnyAttribute (Path const& file, unsigned long line, unsigned long column, - WideString const& namespaces) + String const& namespaces) : Node (file, line, column), prototype_ (0) { @@ -26,9 +26,9 @@ namespace XSDFrontend for (size_t i (0), j (namespaces.find (L' '));;) { - if (j != WideString::npos) + if (j != String::npos) { - namespaces_.push_back (WideString (namespaces, i, j - i)); + namespaces_.push_back (String (namespaces, i, j - i)); i = j + 1; j = namespaces.find (L' ', i); @@ -37,7 +37,7 @@ namespace XSDFrontend { // Last element. // - namespaces_.push_back (WideString (namespaces, i)); + namespaces_.push_back (String (namespaces, i)); break; } } diff --git a/xsd-frontend/semantic-graph/any-attribute.hxx b/xsd-frontend/semantic-graph/any-attribute.hxx index 8827987..a5ce78a 100644 --- a/xsd-frontend/semantic-graph/any-attribute.hxx +++ b/xsd-frontend/semantic-graph/any-attribute.hxx @@ -17,7 +17,7 @@ namespace XSDFrontend { class AnyAttribute: public virtual Nameable { - typedef std::vector Namespaces; + typedef std::vector Namespaces; public: typedef Namespaces::const_iterator NamespaceIterator; @@ -63,7 +63,7 @@ namespace XSDFrontend AnyAttribute (Path const& file, unsigned long line, unsigned long column, - WideString const& namespaces); + String const& namespaces); AnyAttribute (Path const& file, unsigned long line, diff --git a/xsd-frontend/semantic-graph/any.cxx b/xsd-frontend/semantic-graph/any.cxx index 75eb5dd..8aff295 100644 --- a/xsd-frontend/semantic-graph/any.cxx +++ b/xsd-frontend/semantic-graph/any.cxx @@ -16,7 +16,7 @@ namespace XSDFrontend Any (Path const& file, unsigned long line, unsigned long column, - WideString const& namespaces) + String const& namespaces) : Node (file, line, column), prototype_ (0) { @@ -26,9 +26,9 @@ namespace XSDFrontend for (size_t i (0), j (namespaces.find (L' '));;) { - if (j != WideString::npos) + if (j != String::npos) { - namespaces_.push_back (WideString (namespaces, i, j - i)); + namespaces_.push_back (String (namespaces, i, j - i)); i = j + 1; j = namespaces.find (L' ', i); @@ -37,7 +37,7 @@ namespace XSDFrontend { // Last element. // - namespaces_.push_back (WideString (namespaces, i)); + namespaces_.push_back (String (namespaces, i)); break; } } diff --git a/xsd-frontend/semantic-graph/any.hxx b/xsd-frontend/semantic-graph/any.hxx index b0506d0..47513b9 100644 --- a/xsd-frontend/semantic-graph/any.hxx +++ b/xsd-frontend/semantic-graph/any.hxx @@ -19,7 +19,7 @@ namespace XSDFrontend class Any: public virtual Nameable, public virtual Particle { - typedef std::vector Namespaces; + typedef std::vector Namespaces; public: typedef Namespaces::const_iterator NamespaceIterator; @@ -65,7 +65,7 @@ namespace XSDFrontend Any (Path const& file, unsigned long line, unsigned long column, - WideString const& namespaces); + String const& namespaces); Any (Path const& file, unsigned long line, diff --git a/xsd-frontend/semantic-graph/elements.hxx b/xsd-frontend/semantic-graph/elements.hxx index ad70221..1847572 100644 --- a/xsd-frontend/semantic-graph/elements.hxx +++ b/xsd-frontend/semantic-graph/elements.hxx @@ -21,7 +21,7 @@ #include #include -#include +#include namespace XSDFrontend { @@ -31,8 +31,6 @@ namespace XSDFrontend using container::pointer_iterator; - using namespace Cult::Types; - // // typedef boost::filesystem::path Path; @@ -181,7 +179,7 @@ namespace XSDFrontend // // - typedef WideString Name; + typedef String Name; // @@ -648,7 +646,7 @@ namespace XSDFrontend class Restricts: public virtual Inherits { public: - typedef std::map Facets; + typedef std::map Facets; typedef Facets::iterator FacetIterator; bool @@ -670,7 +668,7 @@ namespace XSDFrontend } FacetIterator - facet_find (WideString const& name) + facet_find (String const& name) { return facets_.find (name); } @@ -782,7 +780,7 @@ namespace XSDFrontend struct NoValue {}; - WideString + String value () const { if (value_type_ != ValueType::none) @@ -794,14 +792,14 @@ namespace XSDFrontend // // void - default_ (WideString const& v) + default_ (String const& v) { value_ = v; value_type_ = ValueType::default_; } void - fixed (WideString const& v) + fixed (String const& v) { value_ = v; value_type_ = ValueType::fixed; @@ -841,7 +839,7 @@ namespace XSDFrontend }; }; - WideString value_; + String value_; ValueType::Value value_type_; }; diff --git a/xsd-frontend/transformations/anonymous.cxx b/xsd-frontend/transformations/anonymous.cxx index afaf66a..3fa4f00 100644 --- a/xsd-frontend/transformations/anonymous.cxx +++ b/xsd-frontend/transformations/anonymous.cxx @@ -17,10 +17,6 @@ using std::endl; namespace XSDFrontend { - using namespace Cult; - - typedef WideString String; - namespace { using Transformations::AnonymousNameTranslator; diff --git a/xsd-frontend/transformations/anonymous.hxx b/xsd-frontend/transformations/anonymous.hxx index 992b7ff..4f1dcdd 100644 --- a/xsd-frontend/transformations/anonymous.hxx +++ b/xsd-frontend/transformations/anonymous.hxx @@ -6,7 +6,7 @@ #ifndef XSD_FRONTEND_TRANSFORMATIONS_ANONYMOUS_HXX #define XSD_FRONTEND_TRANSFORMATIONS_ANONYMOUS_HXX -#include +#include #include // Path #include @@ -15,8 +15,6 @@ namespace XSDFrontend { namespace Transformations { - using namespace Cult::Types; - class AnonymousNameTranslator { public: @@ -26,11 +24,11 @@ namespace XSDFrontend // The file argument is empty for the currect translation // unit. // - virtual WideString - translate (WideString const& file, - WideString const& ns, - WideString const& name, - WideString const& xpath) = 0; + virtual String + translate (String const& file, + String const& ns, + String const& name, + String const& xpath) = 0; }; // This transformation morphs anonymous types into named ones diff --git a/xsd-frontend/transformations/enum-synthesis.cxx b/xsd-frontend/transformations/enum-synthesis.cxx index c1ef5a7..169d27e 100644 --- a/xsd-frontend/transformations/enum-synthesis.cxx +++ b/xsd-frontend/transformations/enum-synthesis.cxx @@ -12,9 +12,6 @@ namespace XSDFrontend { - using namespace Cult; - typedef WideString String; - namespace { typedef std::set Enumerators; diff --git a/xsd-frontend/transformations/enum-synthesis.hxx b/xsd-frontend/transformations/enum-synthesis.hxx index 97658a3..edbee07 100644 --- a/xsd-frontend/transformations/enum-synthesis.hxx +++ b/xsd-frontend/transformations/enum-synthesis.hxx @@ -6,7 +6,7 @@ #ifndef XSD_FRONTEND_TRANSFORMATIONS_ENUM_SYNTHESIS_HXX #define XSD_FRONTEND_TRANSFORMATIONS_ENUM_SYNTHESIS_HXX -#include +#include #include // Path #include @@ -15,8 +15,6 @@ namespace XSDFrontend { namespace Transformations { - using namespace Cult::Types; - // This transformation replaces unions of one or more enumerations // with the same base with an equivalent synthesized enumeration. // This transformation assumes that there are no anonymous types. diff --git a/xsd-frontend/transformations/restriction.cxx b/xsd-frontend/transformations/restriction.cxx index dae1f03..0d63a9f 100644 --- a/xsd-frontend/transformations/restriction.cxx +++ b/xsd-frontend/transformations/restriction.cxx @@ -11,14 +11,10 @@ #include -using std::wcerr; -using std::endl; +using namespace std; namespace XSDFrontend { - using namespace Cult; - - typedef WideString String; typedef Transformations::Restriction::Failed Failed; typedef std::vector BaseList; diff --git a/xsd-frontend/transformations/restriction.hxx b/xsd-frontend/transformations/restriction.hxx index 8cf4cd8..2adeb03 100644 --- a/xsd-frontend/transformations/restriction.hxx +++ b/xsd-frontend/transformations/restriction.hxx @@ -6,7 +6,7 @@ #ifndef XSD_FRONTEND_TRANSFORMATIONS_RESTRICTION_HXX #define XSD_FRONTEND_TRANSFORMATIONS_RESTRICTION_HXX -#include +#include #include // Path #include @@ -15,8 +15,6 @@ namespace XSDFrontend { namespace Transformations { - using namespace Cult::Types; - // This transformation performs two major tasks. It transfers omitted // attribute declarations from the base to derived-by-restriction type // and establishes correspondence between particles and compositors by diff --git a/xsd-frontend/transformations/schema-per-type.cxx b/xsd-frontend/transformations/schema-per-type.cxx index 69b43ca..caae52d 100644 --- a/xsd-frontend/transformations/schema-per-type.cxx +++ b/xsd-frontend/transformations/schema-per-type.cxx @@ -22,15 +22,9 @@ using std::endl; namespace XSDFrontend { - using namespace Cult; - - typedef WideString String; typedef Transformations::SchemaPerType::Failed Failed; - typedef std::vector Schemas; - typedef - std::map - TypeSchemaMap; + typedef std::map TypeSchemaMap; // Compare file paths case-insensitively. // @@ -143,7 +137,7 @@ namespace XSDFrontend // if (!tn) { - for (NarrowString::Iterator i (base.begin ()), e (base.end ()); + for (NarrowString::iterator i (base.begin ()), e (base.end ()); i != e; ++i) { if (*i == '/' || *i == '\\') @@ -182,7 +176,7 @@ namespace XSDFrontend throw Failed (); } } - catch (String::NonRepresentable const&) + catch (NonRepresentable const&) { wcerr << "error: '" << wbase << "' cannot be represented as a " << "narrow string" << endl; @@ -251,7 +245,7 @@ namespace XSDFrontend { Type (SemanticGraph::Schema& schema, SemanticGraph::Schema& root, - Char const* by_value_key, + char const* by_value_key, TypeSchemaMap& tsm) : schema_ (schema), root_ (root), @@ -333,7 +327,7 @@ namespace XSDFrontend private: SemanticGraph::Schema& schema_; SemanticGraph::Schema& root_; - Char const* by_value_key_; + char const* by_value_key_; TypeSchemaMap& tsm_; std::set type_set_; @@ -346,7 +340,7 @@ namespace XSDFrontend SchemaPerType:: SchemaPerType (SchemaPerTypeTranslator& trans, bool fat, - Char const* key) + char const* key) : fat_type_file_ (fat), by_value_key_ (key), trans_ (trans) { } diff --git a/xsd-frontend/transformations/schema-per-type.hxx b/xsd-frontend/transformations/schema-per-type.hxx index 6e034d6..9498d42 100644 --- a/xsd-frontend/transformations/schema-per-type.hxx +++ b/xsd-frontend/transformations/schema-per-type.hxx @@ -8,7 +8,7 @@ #include -#include +#include #include // Path #include @@ -17,8 +17,6 @@ namespace XSDFrontend { namespace Transformations { - using namespace Cult::Types; - class SchemaPerTypeTranslator { public: @@ -28,8 +26,8 @@ namespace XSDFrontend // The following two functions should return empty string if // there is no match. // - virtual WideString - translate_type (WideString const& ns, WideString const& name) = 0; + virtual String + translate_type (String const& ns, String const& name) = 0; virtual NarrowString translate_schema (NarrowString const& abs_path) = 0; @@ -49,14 +47,14 @@ namespace XSDFrontend // SchemaPerType (SchemaPerTypeTranslator&, bool fat_type_file, - Char const* by_value_key = 0); + char const* by_value_key = 0); std::vector transform (SemanticGraph::Schema&); private: bool fat_type_file_; - Char const* by_value_key_; + char const* by_value_key_; SchemaPerTypeTranslator& trans_; }; } diff --git a/xsd-frontend/transformations/simplifier.cxx b/xsd-frontend/transformations/simplifier.cxx index ba6b04f..16f07a1 100644 --- a/xsd-frontend/transformations/simplifier.cxx +++ b/xsd-frontend/transformations/simplifier.cxx @@ -10,8 +10,6 @@ namespace XSDFrontend { - using namespace Cult; - namespace { struct Compositor: Traversal::All, diff --git a/xsd-frontend/transformations/simplifier.hxx b/xsd-frontend/transformations/simplifier.hxx index 44a3429..d516943 100644 --- a/xsd-frontend/transformations/simplifier.hxx +++ b/xsd-frontend/transformations/simplifier.hxx @@ -6,7 +6,7 @@ #ifndef XSD_FRONTEND_TRANSFORMATIONS_SIMPLIFIER_HXX #define XSD_FRONTEND_TRANSFORMATIONS_SIMPLIFIER_HXX -#include +#include #include // Path #include @@ -15,8 +15,6 @@ namespace XSDFrontend { namespace Transformations { - using namespace Cult::Types; - // This transformation performs various schema simplifications // (e.g., removing empty compositors, etc). This transformation // assumes that there are no anonymous types. diff --git a/xsd-frontend/traversal/elements.hxx b/xsd-frontend/traversal/elements.hxx index bf4b0f1..9e2b106 100644 --- a/xsd-frontend/traversal/elements.hxx +++ b/xsd-frontend/traversal/elements.hxx @@ -6,10 +6,9 @@ #ifndef XSD_FRONTEND_TRAVERSAL_ELEMENTS_HXX #define XSD_FRONTEND_TRAVERSAL_ELEMENTS_HXX -#include - #include +#include #include namespace XSDFrontend @@ -17,7 +16,6 @@ namespace XSDFrontend namespace Traversal { using namespace cutl; - using namespace Cult::Types; typedef compiler::dispatcher NodeDispatcher; typedef compiler::dispatcher EdgeDispatcher; diff --git a/xsd-frontend/types.cxx b/xsd-frontend/types.cxx new file mode 100644 index 0000000..126a2e1 --- /dev/null +++ b/xsd-frontend/types.cxx @@ -0,0 +1,62 @@ +// file : xsd-frontend/types.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include // std::mbstowcs + +#include + +namespace XSDFrontend +{ + // NonRepresentable + // + char const* NonRepresentable:: + what () const throw () + { + return "character is not representable in the narrower encoding"; + } + + // StringTemplate + // + + // Specialization for char to wchar_t conversion. + // + template <> + void StringTemplate:: + from_narrow (char const* s) + { + size_type size (std::mbstowcs (0, s, 0) + 1); + + // I dare to change the guts! + // + resize (size - 1); + + wchar_t* p (const_cast (data ())); + + std::mbstowcs (p, s, size); + } + + // Specialization for wchar_t to char conversion. + // + template <> + StringTemplate StringTemplate:: + to_narrow () const + { + size_type size (std::wcstombs (0, c_str (), 0)); + + if (size == size_type (-1)) + throw NonRepresentable (); + + // I dare to change the guts! + // + StringTemplate r; + r.resize (size); + + char* p (const_cast (r.data ())); + + std::wcstombs (p, c_str (), size + 1); + + return r; + } +} diff --git a/xsd-frontend/types.hxx b/xsd-frontend/types.hxx index f3512e1..5e7793e 100644 --- a/xsd-frontend/types.hxx +++ b/xsd-frontend/types.hxx @@ -6,17 +6,246 @@ #ifndef XSD_FRONTEND_TYPES_HXX #define XSD_FRONTEND_TYPES_HXX +#include #include // std::size_t -#include - namespace XSDFrontend { using std::size_t; - using namespace Cult::Types; + namespace Bits + { + struct None {}; + + template + struct NarrowerChar + { + typedef None Type; + }; + + template <> + struct NarrowerChar + { + typedef char Type; + }; + } + + struct NonRepresentable: std::exception + { + virtual char const* + what () const throw (); + }; + + template ::Type> + class StringTemplate; + + template <> + class StringTemplate + { + }; + + template + class StringTemplate : public std::basic_string + { + typedef std::basic_string Base; + typedef std::basic_string NarrowerBase; + + Base& + base () + { + return *this; + } + + Base const& + base () const + { + return *this; + } + + public: + typedef typename Base::size_type size_type; + + using Base::npos; + + public: + StringTemplate () + { + } + + StringTemplate (StringTemplate const& str, + size_type pos, + size_type n = npos) + : Base (str, pos, n) + { + } + + StringTemplate (C const* s, size_type n) + : Base (s, n) + { + } + + StringTemplate (C const* s) + : Base (s) + { + } + + StringTemplate (size_type n, C c) + : Base (n, c) + { + } + + template + StringTemplate(I begin, I end) + : Base (begin, end) + { + } + + StringTemplate (StringTemplate const& other) + : Base (other) + { + } + + // Conversion from Base. + // + StringTemplate (Base const& str) + : Base (str) + { + } + + // Conversion from the Narrower type. Experimental. + // + StringTemplate (NC const* s) + { + from_narrow (s); + } + + StringTemplate (StringTemplate const& other) + { + from_narrow (other.c_str ()); + } + + StringTemplate (NarrowerBase const& other) + { + from_narrow (other.c_str ()); + } + + // Assignment. + // + StringTemplate& + operator= (StringTemplate const& str) + { + base () = str; + return *this; + } + + StringTemplate& + operator= (C const* s) + { + base () = s; + return *this; + } + + StringTemplate& + operator= (C c) + { + base () = c; + return *this; + } + + // Assignment from Base. + // + StringTemplate& + operator= (Base const& str) + { + base () = str; + return *this; + } + + public: + StringTemplate& + operator+= (StringTemplate const& str) + { + base () += str; + return *this; + } + + StringTemplate& + operator+= (C const* s) + { + base () += s; + return *this; + } + + StringTemplate& + operator+= (C c) + { + base () += c; + return *this; + } + + // Conversion to the Narrower type. + // + public: + StringTemplate + to_narrow () const; + + // Conversion to bool. + // + private: + typedef void (StringTemplate::*BooleanConvertible)(); + void true_ () {} + + public: + operator BooleanConvertible () const + { + return this->empty () ? 0 : &StringTemplate::true_; + } + + private: + void + from_narrow (NC const* s); + }; + + + template + StringTemplate + operator+ (StringTemplate const& lhs, StringTemplate const& rhs) + { + return StringTemplate (lhs) += rhs; + } + + template + StringTemplate + operator+ (C const* lhs, StringTemplate const& rhs) + { + return StringTemplate (lhs) += rhs; + } + + template + StringTemplate + operator+ (StringTemplate const& lhs, C const* rhs) + { + return StringTemplate (lhs) += rhs; + } + + template + StringTemplate + operator+ (C lhs, StringTemplate const& rhs) + { + return StringTemplate (1, lhs) += rhs; + } + + template + StringTemplate + operator+ (StringTemplate const& lhs, C rhs) + { + return StringTemplate (lhs) += rhs; + } + + typedef StringTemplate NarrowString; + typedef StringTemplate WideString; - typedef Cult::WideString String; + typedef WideString String; } #endif // XSD_FRONTEND_TYPES_HXX diff --git a/xsd-frontend/xml.hxx b/xsd-frontend/xml.hxx index 4b8effa..a785eee 100644 --- a/xsd-frontend/xml.hxx +++ b/xsd-frontend/xml.hxx @@ -96,7 +96,7 @@ namespace XSDFrontend NarrowString transcode_to_narrow (XMLCh const* xs) { - Char* s (Xerces::XMLString::transcode (xs)); + char* s (Xerces::XMLString::transcode (xs)); NarrowString r (s); Xerces::XMLString::release (&s); return r; -- cgit v1.1