summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-09-13 18:46:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-09-13 18:46:11 +0200
commitcb65012eb524eb57b00249f1dee0f245e947cda4 (patch)
tree9706e59d98f2208ec110d84a5aaef14e45b49542
parenta1686fdeabe24823225cfb4cf79646e12cf98b2c (diff)
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.
-rw-r--r--cli/cli.cxx21
-rw-r--r--cli/context.cxx20
-rw-r--r--cli/context.hxx39
-rw-r--r--cli/generator.cxx15
-rw-r--r--cli/generator.hxx26
-rw-r--r--cli/makefile4
-rw-r--r--cli/parser.cxx48
-rw-r--r--cli/parser.hxx4
-rw-r--r--cli/semantics/elements.hxx7
-rw-r--r--cli/semantics/unit.hxx10
10 files changed, 158 insertions, 36 deletions
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 <memory> // std::auto_ptr
#include <fstream>
#include <iostream>
#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<semantics::cli_unit> 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 <boris@codesynthesis.com>
+// 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 <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_CONTEXT_HXX
+#define CLI_CONTEXT_HXX
+
+#include <ostream>
+
+#include <cutl/shared-ptr.hxx>
+
+#include "semantics.hxx"
+#include "traversal.hxx"
+
+using std::endl;
+
+class context
+{
+private:
+ struct data
+ {
+ };
+
+ cutl::shared_ptr<data> 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 <boris@codesynthesis.com>
+// 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 <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CLI_GENERATOR_HXX
+#define CLI_GENERATOR_HXX
+
+#include <semantics/unit.hxx>
+
+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<cli_unit> parser::
-parse (std::istream& is, std::string const& id)
+parse (std::istream& is, path const& p)
{
- auto_ptr<cli_unit> unit (new cli_unit (id));
+ auto_ptr<cli_unit> 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<cxx_unit> (*id_, t.line (), t.column ()));
+ cxx_unit& n (unit_->new_node<cxx_unit> (*path_, t.line (), t.column ()));
unit_->new_edge<cxx_includes> (*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<namespace_> (*id_, t.line (), t.column ()));
+ unit_->new_node<namespace_> (*path_, t.line (), t.column ()));
unit_->new_edge<names> (*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<class_> (*id_, t.line (), t.column ()));
+ class_& n (unit_->new_node<class_> (*path_, t.line (), t.column ()));
unit_->new_edge<names> (*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<option> (*id_, l, c);
- type& t (unit_->new_type (*id_, l, c, type_name));
+ o = &unit_->new_node<option> (*path_, l, c);
+ type& t (unit_->new_type (*path_, l, c, type_name));
unit_->new_edge<belongs> (*o, t);
}
@@ -411,7 +411,7 @@ option_def (token& t)
}
default:
{
- cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: "
+ cerr << *path_ << ':' << t.line () << ':' << t.column () << ": error: "
<< "option name expected instead of " << t << endl;
throw error ();
}
@@ -494,7 +494,7 @@ option_def (token& t)
}
default:
{
- cerr << *id_ << ':' << t.line () << ':' << t.column ()
+ cerr << *path_ << ':' << t.line () << ':' << t.column ()
<< ": error: expected intializer instead of " << t << endl;
throw error ();
}
@@ -515,13 +515,13 @@ option_def (token& t)
if (valid_ && !ev.empty ())
{
- expression& e (unit_->new_node<expression> (*id_, l, c, et, ev));
+ expression& e (unit_->new_node<expression> (*path_, l, c, et, ev));
unit_->new_edge<initialized> (*o, e);
}
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 ();
}
@@ -547,7 +547,7 @@ qualified_name (token& t, string& r)
{
if (t.type () != token::t_identifier)
{
- cerr << *id_ << ':' << t.line () << ':' << t.column () << ": error: "
+ cerr << *path_ << ':' << t.line () << ':' << t.column () << ": error: "
<< "expected identifier after '::'" << endl;
throw error ();
}
diff --git a/cli/parser.hxx b/cli/parser.hxx
index 458efbc..3597fac 100644
--- a/cli/parser.hxx
+++ b/cli/parser.hxx
@@ -22,7 +22,7 @@ public:
struct invalid_input {};
std::auto_ptr<semantics::cli_unit>
- parse (std::istream& is, std::string const& id);
+ parse (std::istream& is, semantics::path const& path);
private:
struct error {};
@@ -57,7 +57,7 @@ private:
private:
bool valid_;
- std::string const* id_;
+ semantics::path const* path_;
lexer* lexer_;
diff --git a/cli/semantics/elements.hxx b/cli/semantics/elements.hxx
index f9b08fc..da9e031 100644
--- a/cli/semantics/elements.hxx
+++ b/cli/semantics/elements.hxx
@@ -15,6 +15,8 @@
#include <utility> // std::pair
#include <cassert>
+#include <cutl/fs/path.hxx>
+
#include <cutl/container/graph.hxx>
#include <cutl/container/pointer-iterator.hxx>
@@ -35,9 +37,11 @@ namespace semantics
//
//
- typedef string path;
typedef string name;
+ using fs::path;
+ using fs::invalid_path;
+
//
//
@@ -141,6 +145,7 @@ namespace semantics
// For virtual inheritance. Should never be actually called.
//
node ()
+ : file_ ("")
{
std::abort ();
}
diff --git a/cli/semantics/unit.hxx b/cli/semantics/unit.hxx
index c15d172..a67e1ff 100644
--- a/cli/semantics/unit.hxx
+++ b/cli/semantics/unit.hxx
@@ -30,7 +30,7 @@ namespace semantics
return *includer_;
}
- path
+ string const&
file () const
{
return file_;
@@ -39,7 +39,7 @@ namespace semantics
protected:
friend class graph<node, edge>;
- includes (path const& file)
+ includes (string const& file)
: file_ (file)
{
}
@@ -51,7 +51,7 @@ namespace semantics
}
protected:
- path file_;
+ string file_;
cli_unit* includer_;
};
@@ -69,7 +69,7 @@ namespace semantics
protected:
friend class graph<node, edge>;
- cli_includes (path const& file)
+ cli_includes (string const& file)
: includes (file)
{
}
@@ -98,7 +98,7 @@ namespace semantics
protected:
friend class graph<node, edge>;
- cxx_includes (path const& file)
+ cxx_includes (string const& file)
: includes (file)
{
}