From cb65012eb524eb57b00249f1dee0f245e947cda4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 13 Sep 2009 18:46:11 +0200 Subject: Use new path class, add context and generator classes Use cutl::fs::path instead of std::string in the semantic graph. Add context and generator stubs, to be filled next. Connect everything in the compiler driver. --- cli/cli.cxx | 21 ++++++++++++++++---- cli/context.cxx | 20 +++++++++++++++++++ cli/context.hxx | 39 +++++++++++++++++++++++++++++++++++++ cli/generator.cxx | 15 +++++++++++++++ cli/generator.hxx | 26 +++++++++++++++++++++++++ cli/makefile | 4 ++++ cli/parser.cxx | 48 +++++++++++++++++++++++----------------------- cli/parser.hxx | 4 ++-- cli/semantics/elements.hxx | 7 ++++++- cli/semantics/unit.hxx | 10 +++++----- 10 files changed, 158 insertions(+), 36 deletions(-) create mode 100644 cli/context.cxx create mode 100644 cli/context.hxx create mode 100644 cli/generator.cxx create mode 100644 cli/generator.hxx diff --git a/cli/cli.cxx b/cli/cli.cxx index 39fff16..3d54452 100644 --- a/cli/cli.cxx +++ b/cli/cli.cxx @@ -3,10 +3,12 @@ // copyright : Copyright (c) 2009 Code Synthesis Tools CC // license : MIT; see accompanying LICENSE file +#include // std::auto_ptr #include #include #include "parser.hxx" +#include "generator.hxx" using namespace std; @@ -20,21 +22,32 @@ int main (int argc, char* argv[]) try { - ifstream ifs (argv[1]); + semantics::path path (argv[1]); + + ifstream ifs (path.string ().c_str ()); if (!ifs.is_open ()) { - wcerr << argv[1] << ": error: unable to open in read mode" << endl; + cerr << path << ": error: unable to open in read mode" << endl; return 1; } ifs.exceptions (ifstream::failbit | ifstream::badbit); parser p; - p.parse (ifs, argv[1]); + auto_ptr unit (p.parse (ifs, path)); + + generator g; + g.generate (*unit, path); + } + catch (semantics::invalid_path const&) + { + cerr << "error: '" << argv[1] << "' is not a valid filesystem path" + << endl; + return 1; } catch (std::ios_base::failure const&) { - wcerr << argv[1] << ": error: read failure" << endl; + cerr << argv[1] << ": error: read failure" << endl; return 1; } catch (parser::invalid_input const&) diff --git a/cli/context.cxx b/cli/context.cxx new file mode 100644 index 0000000..3c62e38 --- /dev/null +++ b/cli/context.cxx @@ -0,0 +1,20 @@ +// file : cli/context.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include "context.hxx" + +context:: +context (std::ostream& os_) + : data_ (new (shared) data), + os (os_) +{ +} + +context:: +context (context& c) + : data_ (c.data_), + os (c.os) +{ +} diff --git a/cli/context.hxx b/cli/context.hxx new file mode 100644 index 0000000..28b74eb --- /dev/null +++ b/cli/context.hxx @@ -0,0 +1,39 @@ +// file : cli/context.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef CLI_CONTEXT_HXX +#define CLI_CONTEXT_HXX + +#include + +#include + +#include "semantics.hxx" +#include "traversal.hxx" + +using std::endl; + +class context +{ +private: + struct data + { + }; + + cutl::shared_ptr data_; + +public: + std::ostream& os; + +public: + context (std::ostream& os_); + context (context& c); + +private: + context& + operator= (context const&); +}; + +#endif // CLI_CONTEXT_HXX diff --git a/cli/generator.cxx b/cli/generator.cxx new file mode 100644 index 0000000..a5c588c --- /dev/null +++ b/cli/generator.cxx @@ -0,0 +1,15 @@ +// file : cli/generator.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include "generator.hxx" + +generator:: +generator () +{ +} +void generator:: +generate (semantics::cli_unit& unit, semantics::path const& path) +{ +} diff --git a/cli/generator.hxx b/cli/generator.hxx new file mode 100644 index 0000000..5db2aa5 --- /dev/null +++ b/cli/generator.hxx @@ -0,0 +1,26 @@ +// file : cli/generator.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef CLI_GENERATOR_HXX +#define CLI_GENERATOR_HXX + +#include + +class generator +{ +public: + generator (); + + void + generate (semantics::cli_unit&, semantics::path const&); + +private: + generator (generator const&); + + generator& + operator= (generator const&); +}; + +#endif // CLI_GENERATOR_HXX diff --git a/cli/makefile b/cli/makefile index 76d23d8..10899be 100644 --- a/cli/makefile +++ b/cli/makefile @@ -8,6 +8,10 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make cxx_tun := cli.cxx lexer.cxx parser.cxx cxx_tun += \ +context.cxx \ +generator.cxx + +cxx_tun += \ semantics/class.cxx \ semantics/elements.cxx \ semantics/expression.cxx \ diff --git a/cli/parser.cxx b/cli/parser.cxx index 9b9c116..54ab78a 100644 --- a/cli/parser.cxx +++ b/cli/parser.cxx @@ -124,15 +124,15 @@ recover (token& t) } auto_ptr parser:: -parse (std::istream& is, std::string const& id) +parse (std::istream& is, path const& p) { - auto_ptr unit (new cli_unit (id)); + auto_ptr unit (new cli_unit (p)); unit_ = unit.get (); - lexer l (is, id); + lexer l (is, p.string ()); lexer_ = &l; - id_ = &id; + path_ = &p; valid_ = true; def_unit (); @@ -179,7 +179,7 @@ def_unit () continue; } - cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " + cerr << *path_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected namespace or class declaration instead of " << t << endl; throw error (); @@ -201,14 +201,14 @@ include_decl () if (t.type () != token::t_path_lit) { - cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " + cerr << *path_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected path literal instead of " << t << endl; throw error (); } if (valid_) { - cxx_unit& n (unit_->new_node (*id_, t.line (), t.column ())); + cxx_unit& n (unit_->new_node (*path_, t.line (), t.column ())); unit_->new_edge (*unit_, n, t.literal ()); } @@ -216,7 +216,7 @@ include_decl () if (t.punctuation () != token::p_semi) { - cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " + cerr << *path_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected ';' instead of " << t << endl; throw error (); } @@ -253,7 +253,7 @@ namespace_def () if (t.type () != token::t_identifier) { - cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " + cerr << *path_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected identifier instead of " << t << endl; throw error (); } @@ -263,7 +263,7 @@ namespace_def () if (valid_) { namespace_& n ( - unit_->new_node (*id_, t.line (), t.column ())); + unit_->new_node (*path_, t.line (), t.column ())); unit_->new_edge (*scope_, n, t.identifier ()); scope_ = &n; } @@ -272,7 +272,7 @@ namespace_def () if (t.punctuation () != token::p_lcbrace) { - cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " + cerr << *path_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected '{' instead of " << t << endl; throw error (); } @@ -288,7 +288,7 @@ namespace_def () if (t.punctuation () != token::p_rcbrace) { - cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " + cerr << *path_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected namespace declaration, class declaration, or '}' " << "instead of " << t << endl; throw error (); @@ -302,7 +302,7 @@ class_def () if (t.type () != token::t_identifier) { - cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " + cerr << *path_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected identifier instead of " << t << endl; throw error (); } @@ -311,7 +311,7 @@ class_def () if (valid_) { - class_& n (unit_->new_node (*id_, t.line (), t.column ())); + class_& n (unit_->new_node (*path_, t.line (), t.column ())); unit_->new_edge (*scope_, n, t.identifier ()); scope_ = &n; } @@ -320,7 +320,7 @@ class_def () if (t.punctuation () != token::p_lcbrace) { - cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " + cerr << *path_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected '{' instead of " << t << endl; throw error (); } @@ -349,7 +349,7 @@ class_def () if (t.punctuation () != token::p_rcbrace) { - cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " + cerr << *path_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected option declaration or '}' instead of " << t << endl; throw error (); } @@ -358,7 +358,7 @@ class_def () if (t.punctuation () != token::p_semi) { - cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: " + cerr << *path_ << ':' << t.line () << ':' << t.column () << ": error: " << "expected ';' instead of " << t << endl; throw error (); } @@ -383,8 +383,8 @@ option_def (token& t) if (valid_) { - o = &unit_->new_node