summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ast/ast.cpp5
-rw-r--r--ast/ast.hpp52
-rw-r--r--ast/path.hpp49
-rw-r--r--common.hpp9
-rw-r--r--convert/resolve.cpp13
-rw-r--r--macros.cpp3
-rw-r--r--main.cpp2
-rw-r--r--mrustc.cbp4
-rw-r--r--parse/preproc.cpp2
-rw-r--r--types.cpp8
-rw-r--r--types.hpp1
11 files changed, 102 insertions, 46 deletions
diff --git a/ast/ast.cpp b/ast/ast.cpp
index 575d3c60..a39bc0d4 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 194c79b8..fdb1114d 100644
--- a/ast/ast.hpp
+++ b/ast/ast.hpp
@@ -7,7 +7,7 @@
#include "../coretypes.hpp"
#include <memory>
-class TypeRef;
+#include "../types.hpp"
namespace AST {
@@ -30,40 +30,6 @@ public:
class ExprNode;
-class TypeParam
-{
-public:
- TypeParam(bool is_lifetime, ::std::string name);
- void addLifetimeBound(::std::string name);
- void addTypeBound(TypeRef type);
-};
-
-typedef ::std::vector<TypeParam> TypeParams;
-typedef ::std::pair< ::std::string, TypeRef> StructItem;
-
-class PathNode
-{
- ::std::string m_name;
- ::std::vector<TypeRef> m_params;
-public:
- PathNode(::std::string name, ::std::vector<TypeRef> args);
- const ::std::string& name() const;
- const ::std::vector<TypeRef>& 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 @@ public:
class Function
{
- Expr m_code;
- ::std::auto_ptr<TypeRef> m_rettype;
public:
-
enum Class
{
CLASS_UNBOUND,
@@ -167,13 +130,22 @@ public:
CLASS_MUTMETHOD,
CLASS_VALMETHOD,
};
+ typedef ::std::vector<StructItem> Arglist;
- Function(::std::string name, TypeParams params, Class fcn_class, TypeRef ret_type, ::std::vector<StructItem> 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 00000000..09e5d9ed
--- /dev/null
+++ b/ast/path.hpp
@@ -0,0 +1,49 @@
+/*
+ */
+#ifndef AST_PATH_HPP_INCLUDED
+#define AST_PATH_HPP_INCLUDED
+
+#include <string>
+#include <stdexcept>
+
+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<TypeParam> TypeParams;
+typedef ::std::pair< ::std::string, TypeRef> StructItem;
+
+class PathNode
+{
+ ::std::string m_name;
+ ::std::vector<TypeRef> m_params;
+public:
+ PathNode(::std::string name, ::std::vector<TypeRef> args);
+ const ::std::string& name() const;
+ const ::std::vector<TypeRef>& 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 00000000..deaf4ed1
--- /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 23d49726..29ad8dac 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 @@ public:
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 f81bf566..4356a399 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 f3349257..50b77f5b 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,6 +1,8 @@
#include <iostream>
+#include <string>
#include "parse/lex.hpp"
#include "parse/parseerror.hpp"
+#include "ast/ast.hpp"
using namespace std;
diff --git a/mrustc.cbp b/mrustc.cbp
index 90fa7330..f7d200eb 100644
--- a/mrustc.cbp
+++ b/mrustc.cbp
@@ -36,6 +36,9 @@
</Compiler>
<Unit filename="ast/ast.cpp" />
<Unit filename="ast/ast.hpp" />
+ <Unit filename="ast/path.hpp" />
+ <Unit filename="common.hpp" />
+ <Unit filename="convert/resolve.cpp" />
<Unit filename="coretypes.hpp" />
<Unit filename="macros.cpp" />
<Unit filename="main.cpp" />
@@ -49,6 +52,7 @@
<Unit filename="parse/preproc.hpp" />
<Unit filename="parse/root.cpp" />
<Unit filename="samples/1.rs" />
+ <Unit filename="types.cpp" />
<Unit filename="types.hpp" />
<Extensions>
<code_completion />
diff --git a/parse/preproc.cpp b/parse/preproc.cpp
index 2287c41e..3e2865b2 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 00000000..4bfb448f
--- /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 02355d66..18972143 100644
--- a/types.hpp
+++ b/types.hpp
@@ -3,6 +3,7 @@
#include <vector>
#include "coretypes.hpp"
+#include "ast/path.hpp"
namespace AST {
class Expr;