diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-05-30 19:55:18 -0400 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-05-30 19:55:18 -0400 |
commit | 93dfe8d00dc4ea19b31ebcf4dab35a32cd1d6791 (patch) | |
tree | db4d7ccab16a4ba7c84c5cd0673e9b638b354017 /xsd-frontend | |
parent | 3c55d0d6934cb037a5fb2b5729b6603d8b7ca7e5 (diff) |
Get rid of dependency on Boost filesystem
Diffstat (limited to 'xsd-frontend')
-rw-r--r-- | xsd-frontend/makefile | 12 | ||||
-rw-r--r-- | xsd-frontend/parser.cxx | 120 | ||||
-rw-r--r-- | xsd-frontend/semantic-graph/elements.cxx | 2 | ||||
-rw-r--r-- | xsd-frontend/semantic-graph/elements.hxx | 13 | ||||
-rw-r--r-- | xsd-frontend/transformations/anonymous.cxx | 20 | ||||
-rw-r--r-- | xsd-frontend/transformations/schema-per-type.cxx | 8 |
6 files changed, 65 insertions, 110 deletions
diff --git a/xsd-frontend/makefile b/xsd-frontend/makefile index 51ce8f2..3f62bf0 100644 --- a/xsd-frontend/makefile +++ b/xsd-frontend/makefile @@ -59,12 +59,6 @@ xsd_frontend.l.cpp-options := $(out_base)/xsd-frontend.l.cpp-options clean := $(out_base)/.clean -# Import. -# -$(call import,\ - $(scf_root)/import/libboost/filesystem/stub.make,\ - l: fs.l,cpp-options: fs.l.cpp-options) - $(call import,\ $(scf_root)/import/libxerces-c/stub.make,\ l: xerces_c.l,cpp-options: xerces_c.l.cpp-options) @@ -75,13 +69,11 @@ $(call import,\ # What to build. # -$(xsd_frontend.l): $(cxx_obj) $(cutl.l) $(xerces_c.l) $(fs.l) +$(xsd_frontend.l): $(cxx_obj) $(cutl.l) $(xerces_c.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) \ - $(cutl.l.cpp-options) +$(xsd_frontend.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 a9701a4..dbe070c 100644 --- a/xsd-frontend/parser.cxx +++ b/xsd-frontend/parser.cxx @@ -1303,18 +1303,6 @@ namespace XSDFrontend }; } - // - // - struct FilePathComparator - { - bool - operator () (SemanticGraph::Path const& x, - SemanticGraph::Path const& y) const - { - return x.native_file_string () < y.native_file_string (); - } - }; - // Parser::Impl // @@ -1669,9 +1657,7 @@ namespace XSDFrontend friend bool operator< (SchemaId const& x, SchemaId const& y) { - return x.path_.native_file_string () < y.path_.native_file_string () - || (x.path_.native_file_string () == y.path_.native_file_string () - && x.ns_ < y.ns_); + return x.path_ < y.path_ || (x.path_ == y.path_ && x.ns_ < y.ns_); } private: @@ -1923,10 +1909,12 @@ namespace XSDFrontend // Parse. // { - // Enter the file into schema_map_. + // Enter the file into schema_map_. Do normalize() before + // complete() to avoid hitting system path limits with '..' + // directories. // - Path abs_path (system_complete (tu)); - abs_path.normalize (); + Path abs_path (tu); + abs_path.normalize ().complete (); schema_map_[SchemaId (abs_path, ns)] = rs.get (); rs->context ().set ("absolute-path", abs_path); @@ -2126,7 +2114,7 @@ namespace XSDFrontend NamespaceMap cache; cache_ = &cache; - auto_ptr<Schema> rs (new Schema ("", 0, 0)); + auto_ptr<Schema> rs (new Schema (Path (), 0, 0)); // Implied schema with fundamental types. // @@ -2153,10 +2141,12 @@ namespace XSDFrontend if (trace_) wcout << "target namespace: " << ns << endl; - // Check if we already have this schema. + // Check if we already have this schema. Do normalize() before + // complete() to avoid hitting system path limits with '..' + // directories. // - Path abs_path (system_complete (tu)); - abs_path.normalize (); + Path abs_path (tu); + abs_path.normalize ().complete (); SchemaId schema_id (abs_path, ns); if (schema_map_.find (schema_id) != schema_map_.end ()) @@ -2434,31 +2424,21 @@ namespace XSDFrontend Path path, rel_path, abs_path; try { - try - { - path = Path (loc); - } - catch (InvalidPath const&) - { - // Retry as a native path. - // - path = Path (loc, boost::filesystem::native); - } + path = Path (loc); - if (path.is_complete ()) + if (path.absolute ()) { abs_path = rel_path = path; + abs_path.normalize (); } else { - // Use abs_file to construct the absolute path to avoid - // hitting system path limits with '..' directories. + // Do normalize() before complete() to avoid hitting system path + // limits with '..' directories. // - rel_path = file ().branch_path () / path; - abs_path = system_complete (abs_file ().branch_path () / path); + abs_path = rel_path = file ().directory () / path; + abs_path.normalize ().complete (); } - - abs_path.normalize (); } catch (InvalidPath const&) { @@ -2541,31 +2521,21 @@ namespace XSDFrontend Path path, rel_path, abs_path; try { - try - { - path = Path (loc); - } - catch (InvalidPath const&) - { - // Retry as a native path. - // - path = Path (loc, boost::filesystem::native); - } + path = Path (loc); - if (path.is_complete ()) + if (path.absolute ()) { abs_path = rel_path = path; + abs_path.normalize (); } else { - // Use abs_file to construct the absolute path to avoid - // hitting system path limits with '..' directories. + // Do normalize() before complete() to avoid hitting system path + // limits with '..' directories. // - rel_path = file ().branch_path () / path; - abs_path = system_complete (abs_file ().branch_path () / path); + abs_path = rel_path = file ().directory () / path; + abs_path.normalize ().complete (); } - - abs_path.normalize (); } catch (InvalidPath const&) { @@ -4791,7 +4761,7 @@ namespace XSDFrontend Context& operator= (Context const&); private: - typedef std::map<Path, Path, FilePathComparator> FileMap; + typedef std::map<Path, Path> FileMap; FileMap file_map_; }; @@ -4819,8 +4789,7 @@ namespace XSDFrontend XSDFrontend::SemanticGraph::Path abs_path ( - XML::transcode_to_narrow (e.getLocation ()->getURI ()), - boost::filesystem::native); + XML::transcode_to_narrow (e.getLocation ()->getURI ())); XSDFrontend::SemanticGraph::Path rel_path (ctx_.file (abs_path)); @@ -4873,8 +4842,7 @@ namespace XSDFrontend base_ (base), ctx_ (ctx) { - setSystemId (XML::XMLChString ( - String (abs_.native_file_string ())).c_str ()); + setSystemId (XML::XMLChString (String (abs_.string ())).c_str ()); } virtual Xerces::BinInputStream* @@ -4947,8 +4915,7 @@ namespace XSDFrontend // base_uri should be a valid path by now. // - Path base (XML::transcode_to_narrow (base_uri), - boost::filesystem::native); + Path base (XML::transcode_to_narrow (base_uri)); if (prv_id == 0) { @@ -4972,31 +4939,19 @@ namespace XSDFrontend try { - Path path; - - try - { - path = Path (path_str); - } - catch (InvalidPath const&) - { - // Retry as a native path. - // - path = Path (path_str, boost::filesystem::native); - } - - Path base_dir (base.branch_path ()); + Path path (path_str); + Path base_dir (base.directory ()); Path abs_path, rel_path; - if (path.is_complete ()) + if (path.absolute ()) { abs_path = rel_path = path; } else { abs_path = base_dir / path; - rel_path = ctx_.file (base).branch_path () / path; + rel_path = ctx_.file (base).directory () / path; } abs_path.normalize (); @@ -5042,8 +4997,11 @@ namespace XSDFrontend { XSDFrontend::Context ctx; - Path abs_path (system_complete (tu)); - abs_path.normalize (); + // Do normalize() before complete() to avoid hitting system path + // limits with '..' directories. + // + Path abs_path (tu); + abs_path.normalize ().complete (); ctx.map_file (abs_path, tu); InputSource input_source (abs_path, tu, abs_path, ctx); diff --git a/xsd-frontend/semantic-graph/elements.cxx b/xsd-frontend/semantic-graph/elements.cxx index 28cfe4d..d99bb37 100644 --- a/xsd-frontend/semantic-graph/elements.cxx +++ b/xsd-frontend/semantic-graph/elements.cxx @@ -296,5 +296,5 @@ namespace XSDFrontend std::wostream& operator<< (std::wostream& os, XSDFrontend::SemanticGraph::Path const& path) { - return os << path.native_file_string ().c_str (); + return os << path.string ().c_str (); } diff --git a/xsd-frontend/semantic-graph/elements.hxx b/xsd-frontend/semantic-graph/elements.hxx index 1847572..b4904d6 100644 --- a/xsd-frontend/semantic-graph/elements.hxx +++ b/xsd-frontend/semantic-graph/elements.hxx @@ -10,16 +10,15 @@ #include <map> #include <list> #include <vector> -#include <utility> // std::pair #include <iosfwd> - -#include <boost/filesystem/path.hpp> -#include <boost/filesystem/operations.hpp> -#include <boost/filesystem/exception.hpp> +#include <utility> // std::pair +#include <cstdlib> // abort +#include <cassert> #include <cutl/container/graph.hxx> #include <cutl/container/pointer-iterator.hxx> #include <cutl/compiler/context.hxx> +#include <cutl/fs/path.hxx> #include <xsd-frontend/types.hxx> @@ -33,9 +32,9 @@ namespace XSDFrontend // // - typedef boost::filesystem::path Path; + typedef fs::path Path; + typedef fs::invalid_path InvalidPath; typedef std::vector<Path> Paths; - typedef boost::filesystem::filesystem_error InvalidPath; typedef compiler::context Context; diff --git a/xsd-frontend/transformations/anonymous.cxx b/xsd-frontend/transformations/anonymous.cxx index 3fa4f00..2c5b009 100644 --- a/xsd-frontend/transformations/anonymous.cxx +++ b/xsd-frontend/transformations/anonymous.cxx @@ -531,6 +531,7 @@ namespace XSDFrontend // Run the name through the translation service. // SemanticGraph::Path file (path (l)); + file.normalize (); String file_str; // Try to use the portable representation of the path. If that @@ -538,11 +539,11 @@ namespace XSDFrontend // try { - file_str = file.string (); + file_str = file.posix_string (); } catch (SemanticGraph::InvalidPath const&) { - file_str = file.native_file_string (); + file_str = file.string (); } String name ( @@ -615,17 +616,18 @@ namespace XSDFrontend if (!file_str) { SemanticGraph::Path file (path (u)); + file.normalize (); // Try to use the portable representation of the path. If // that fails, fall back to the native representation. // try { - file_str = file.string (); + file_str = file.posix_string (); } catch (SemanticGraph::InvalidPath const&) { - file_str = file.native_file_string (); + file_str = file.string (); } } @@ -697,6 +699,7 @@ namespace XSDFrontend // Run the name through the translation service. // SemanticGraph::Path file (path (c)); + file.normalize (); String file_str; // Try to use the portable representation of the path. If that @@ -704,11 +707,11 @@ namespace XSDFrontend // try { - file_str = file.string (); + file_str = file.posix_string (); } catch (SemanticGraph::InvalidPath const&) { - file_str = file.native_file_string (); + file_str = file.string (); } String name ( @@ -895,6 +898,7 @@ namespace XSDFrontend // Run the name through the translation service. // SemanticGraph::Path file (path (m)); + file.normalize (); String file_str; // Try to use the portable representation of the path. If that @@ -902,11 +906,11 @@ namespace XSDFrontend // try { - file_str = file.string (); + file_str = file.posix_string (); } catch (SemanticGraph::InvalidPath const&) { - file_str = file.native_file_string (); + file_str = file.string (); } String name ( diff --git a/xsd-frontend/transformations/schema-per-type.cxx b/xsd-frontend/transformations/schema-per-type.cxx index caae52d..b957a58 100644 --- a/xsd-frontend/transformations/schema-per-type.cxx +++ b/xsd-frontend/transformations/schema-per-type.cxx @@ -374,6 +374,8 @@ namespace XSDFrontend for (Schemas::iterator i (schemas.begin ()); i != schemas.end (); ++i) { + // This path was already normalized by the parser. + // SemanticGraph::Path const& path ( (*i)->context ().get<SemanticGraph::Path> ("absolute-path")); @@ -386,15 +388,15 @@ namespace XSDFrontend // try { - abs_path = path.string (); + abs_path = path.posix_string (); } catch (SemanticGraph::InvalidPath const&) { - abs_path = path.native_file_string (); + abs_path = path.string (); } NarrowString tf (trans_.translate_schema (abs_path)); - NarrowString file (tf ? tf : path.leaf ()); + NarrowString file (tf ? tf : path.leaf ().string ()); size_t p (file.rfind ('.')); NarrowString ext ( |