diff --git a/ast/ast.cpp b/ast/ast.cpp index 575d3c605..a39bc0d47 100644 --- a/ast/ast.cpp +++ b/ast/ast.cpp @@ -51,11 +51,14 @@ void Impl::add_function(bool is_public, Function fcn) { } +void Crate::iterate_functions(Crate::fcn_visitor_t* visitor) +{ +} + void Module::add_constant(bool is_public, ::std::string name, TypeRef type, Expr val) { ::std::cout << "add_constant()" << ::std::endl; } - void Module::add_global(bool is_public, bool is_mut, ::std::string name, TypeRef type, Expr val) { ::std::cout << "add_global()" << ::std::endl; diff --git a/ast/ast.hpp b/ast/ast.hpp index 194c79b87..fdb1114d7 100644 --- a/ast/ast.hpp +++ b/ast/ast.hpp @@ -7,7 +7,7 @@ #include "../coretypes.hpp" #include -class TypeRef; +#include "../types.hpp" namespace AST { @@ -30,40 +30,6 @@ class MetaItem class ExprNode; -class TypeParam -{ -public: - TypeParam(bool is_lifetime, ::std::string name); - void addLifetimeBound(::std::string name); - void addTypeBound(TypeRef type); -}; - -typedef ::std::vector TypeParams; -typedef ::std::pair< ::std::string, TypeRef> StructItem; - -class PathNode -{ - ::std::string m_name; - ::std::vector m_params; -public: - PathNode(::std::string name, ::std::vector args); - const ::std::string& name() const; - const ::std::vector& args() const; -}; - -class Path -{ -public: - Path(); - struct TagAbsolute {}; - Path(TagAbsolute); - - void append(PathNode node) {} - size_t length() const {return 0;} - - PathNode& operator[](size_t idx) { throw ::std::out_of_range("Path []"); } -}; - class Pattern { public: @@ -156,10 +122,7 @@ class Expr class Function { - Expr m_code; - ::std::auto_ptr m_rettype; public: - enum Class { CLASS_UNBOUND, @@ -167,13 +130,22 @@ class Function CLASS_MUTMETHOD, CLASS_VALMETHOD, }; + typedef ::std::vector Arglist; - Function(::std::string name, TypeParams params, Class fcn_class, TypeRef ret_type, ::std::vector args, Expr code); +private: + Expr m_code; + TypeRef m_rettype; + Arglist m_args; +public: + + Function(::std::string name, TypeParams params, Class fcn_class, TypeRef ret_type, Arglist args, Expr code); Expr& code() { return m_code; } const Expr code() const { return m_code; } - TypeRef& rettype() { return *m_rettype; } + TypeRef& rettype() { return m_rettype; } + + Arglist& args() { return m_args; } }; class Impl diff --git a/ast/path.hpp b/ast/path.hpp new file mode 100644 index 000000000..09e5d9ed6 --- /dev/null +++ b/ast/path.hpp @@ -0,0 +1,49 @@ +/* + */ +#ifndef AST_PATH_HPP_INCLUDED +#define AST_PATH_HPP_INCLUDED + +#include +#include + +class TypeRef; + +namespace AST { + +class TypeParam +{ +public: + TypeParam(bool is_lifetime, ::std::string name); + void addLifetimeBound(::std::string name); + void addTypeBound(TypeRef type); +}; + +typedef ::std::vector TypeParams; +typedef ::std::pair< ::std::string, TypeRef> StructItem; + +class PathNode +{ + ::std::string m_name; + ::std::vector m_params; +public: + PathNode(::std::string name, ::std::vector args); + const ::std::string& name() const; + const ::std::vector& args() const; +}; + +class Path +{ +public: + Path(); + struct TagAbsolute {}; + Path(TagAbsolute); + + void append(PathNode node) {} + size_t length() const {return 0;} + + PathNode& operator[](size_t idx) { throw ::std::out_of_range("Path []"); } +}; + +} // namespace AST + +#endif diff --git a/common.hpp b/common.hpp new file mode 100644 index 000000000..deaf4ed13 --- /dev/null +++ b/common.hpp @@ -0,0 +1,9 @@ +/* + */ +#ifndef COMMON_HPP_INCLUDED +#define COMMON_HPP_INCLUDED + +#define FOREACH(basetype, it, src) for(basetype::const_iterator it = src.begin(); it != src.end(); ++ it) +#define FOREACH_M(basetype, it, src) for(basetype::iterator it = src.begin(); it != src.end(); ++ it) + +#endif diff --git a/convert/resolve.cpp b/convert/resolve.cpp index 23d497268..29ad8dacd 100644 --- a/convert/resolve.cpp +++ b/convert/resolve.cpp @@ -1,5 +1,7 @@ +#include "../common.hpp" #include "../ast/ast.hpp" +#include "../parse/parseerror.hpp" // Path resolution checking void ResolvePaths(AST::Crate& crate); @@ -17,18 +19,25 @@ class CResolvePaths_NodeVisitor: void visit(AST::ExprNode::TagNamedValue, AST::ExprNode& node) { // TODO: Convert into a real absolute path + throw ParseError::Todo("CResolvePaths_NodeVisitor::visit(TagNamedValue)"); } }; +void ResolvePaths_Type(TypeRef& type) +{ + // TODO: Convert type into absolute + throw ParseError::Todo("ResolvePaths_Type"); +} + void ResolvePaths_HandleFunction(const AST::Crate& crate, AST::Function& fcn) { fcn.code().visit_nodes( CResolvePaths_NodeVisitor(crate) ); ResolvePaths_Type(fcn.rettype()); - FOREACH(arg, fcn.args()) + FOREACH_M(AST::Function::Arglist, arg, fcn.args()) { - ResolvePaths_Type(arg.type()); + ResolvePaths_Type(arg->second); } } diff --git a/macros.cpp b/macros.cpp index f81bf566f..4356a3992 100644 --- a/macros.cpp +++ b/macros.cpp @@ -1,12 +1,11 @@ /* */ +#include "common.hpp" #include "macros.hpp" #include "parse/parseerror.hpp" #include "parse/tokentree.hpp" #include "parse/common.hpp" -#define FOREACH(basetype, it, src) for(basetype::const_iterator it = src.begin(); it != src.end(); ++ it) - typedef ::std::map< ::std::string, MacroRules> t_macro_regs; t_macro_regs g_macro_registrations; diff --git a/main.cpp b/main.cpp index f33492571..50b77f5b0 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,8 @@ #include +#include #include "parse/lex.hpp" #include "parse/parseerror.hpp" +#include "ast/ast.hpp" using namespace std; diff --git a/mrustc.cbp b/mrustc.cbp index 90fa7330f..f7d200eb0 100644 --- a/mrustc.cbp +++ b/mrustc.cbp @@ -36,6 +36,9 @@ + + + @@ -49,6 +52,7 @@ + diff --git a/parse/preproc.cpp b/parse/preproc.cpp index 2287c41eb..3e2865b2a 100644 --- a/parse/preproc.cpp +++ b/parse/preproc.cpp @@ -17,7 +17,7 @@ Token Preproc::getTokenInt() while(true) { Token tok = m_lex.getToken(); - ::std::cout << "getTokenInt: tok = " << tok << ::std::endl; + //::std::cout << "getTokenInt: tok = " << tok << ::std::endl; switch(tok.type()) { case TOK_WHITESPACE: diff --git a/types.cpp b/types.cpp new file mode 100644 index 000000000..4bfb448fb --- /dev/null +++ b/types.cpp @@ -0,0 +1,8 @@ +/* + */ +#include "types.hpp" +#include "ast/ast.hpp" + +TypeRef::TypeRef(TypeRef::TagSizedArray, TypeRef inner, AST::Expr size_expr) +{ +} diff --git a/types.hpp b/types.hpp index 02355d665..189721430 100644 --- a/types.hpp +++ b/types.hpp @@ -3,6 +3,7 @@ #include #include "coretypes.hpp" +#include "ast/path.hpp" namespace AST { class Expr;