diff options
author | John Hodge (bugs) <tpg@mutabah.net> | 2014-12-14 10:03:30 +0800 |
---|---|---|
committer | John Hodge (bugs) <tpg@mutabah.net> | 2014-12-14 10:03:30 +0800 |
commit | 5d29fdaa42c638e9420bd3111fb15f3594342354 (patch) | |
tree | d1c3ce2d13751c6ee23b92b44fc7053c681d4a3d /ast/ast.hpp | |
parent | 605c764a79ed00630967780ee7d434fbaa8aa284 (diff) | |
download | mrust-5d29fdaa42c638e9420bd3111fb15f3594342354.tar.gz |
Parse working, starting on conversion
Diffstat (limited to 'ast/ast.hpp')
-rw-r--r-- | ast/ast.hpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/ast/ast.hpp b/ast/ast.hpp index f05747ac..194c79b8 100644 --- a/ast/ast.hpp +++ b/ast/ast.hpp @@ -5,11 +5,29 @@ #include <vector>
#include <stdexcept>
#include "../coretypes.hpp"
+#include <memory>
class TypeRef;
namespace AST {
+class MetaItem
+{
+ ::std::string m_name;
+ ::std::vector<MetaItem> m_items;
+ ::std::string m_str_val;
+public:
+ MetaItem(::std::string name):
+ m_name(name)
+ {
+ }
+ MetaItem(::std::string name, ::std::vector<MetaItem> items):
+ m_name(name),
+ m_items(items)
+ {
+ }
+};
+
class ExprNode;
class TypeParam
@@ -120,15 +138,26 @@ public: ExprNode(TagBinOp, BinOpType type, ExprNode left, ExprNode right);
};
+class NodeVisitor
+{
+public:
+ virtual void visit(ExprNode::TagBlock, ExprNode& node) {}
+ virtual void visit(ExprNode::TagNamedValue, ExprNode& node) {}
+};
+
class Expr
{
public:
Expr() {}
Expr(ExprNode node) {}
+
+ void visit_nodes(const NodeVisitor& v);
};
class Function
{
+ Expr m_code;
+ ::std::auto_ptr<TypeRef> m_rettype;
public:
enum Class
@@ -140,6 +169,11 @@ public: };
Function(::std::string name, TypeParams params, Class fcn_class, TypeRef ret_type, ::std::vector<StructItem> args, Expr code);
+
+ Expr& code() { return m_code; }
+ const Expr code() const { return m_code; }
+
+ TypeRef& rettype() { return *m_rettype; }
};
class Impl
@@ -152,6 +186,7 @@ public: class Module
{
+ ::std::vector<Function> m_functions;
public:
void add_alias(bool is_public, Path path) {}
void add_constant(bool is_public, ::std::string name, TypeRef type, Expr val);
@@ -161,6 +196,20 @@ public: void add_impl(Impl impl);
};
+class Crate
+{
+ Module m_root_module;
+public:
+ Crate(Module root_module):
+ m_root_module(root_module)
+ {
+ }
+
+ typedef void fcn_visitor_t(const AST::Crate& crate, Function& fcn);
+
+ void iterate_functions( fcn_visitor_t* visitor );
+};
+
}
#endif // AST_HPP_INCLUDED
|