summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge (sonata) <tpg@mutabah.net>2015-01-12 20:56:44 +0800
committerJohn Hodge (sonata) <tpg@mutabah.net>2015-01-12 20:56:44 +0800
commited264377ef0e4ed3a5b96b39f3282b3c10d65455 (patch)
treec1ec1312c0a00a0521d93aac291b5210eff794b7 /src
parent4af0826c332c52af0796a2fe30074bbd6aba664b (diff)
downloadmrust-ed264377ef0e4ed3a5b96b39f3282b3c10d65455.tar.gz
TypeRef fleshed out
Diffstat (limited to 'src')
-rw-r--r--src/ast/ast.hpp6
-rw-r--r--src/ast/expr.hpp1
-rw-r--r--src/parse/root.cpp2
-rw-r--r--src/types.cpp9
-rw-r--r--src/types.hpp84
5 files changed, 78 insertions, 24 deletions
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp
index e7a0ba2d..7a417e4f 100644
--- a/src/ast/ast.hpp
+++ b/src/ast/ast.hpp
@@ -106,9 +106,9 @@ public:
Function(TypeParams params, Class fcn_class, TypeRef ret_type, Arglist args, Expr code):
m_fcn_class(fcn_class),
m_generic_params(params),
- m_code(code),
- m_rettype(ret_type),
- m_args(args)
+ m_code( ::std::move(code) ),
+ m_rettype( move(ret_type) ),
+ m_args( move(args) )
{
}
diff --git a/src/ast/expr.hpp b/src/ast/expr.hpp
index 1ebd3090..340d0bb2 100644
--- a/src/ast/expr.hpp
+++ b/src/ast/expr.hpp
@@ -358,6 +358,7 @@ public:
{
}
+ ::std::shared_ptr<ExprNode> take_node() { return ::std::move(m_node); }
void visit_nodes(NodeVisitor& v);
friend ::std::ostream& operator<<(::std::ostream& os, const Expr& pat);
diff --git a/src/parse/root.cpp b/src/parse/root.cpp
index d3ca5b9b..a0b8329f 100644
--- a/src/parse/root.cpp
+++ b/src/parse/root.cpp
@@ -156,7 +156,7 @@ TypeRef Parse_Type(TokenStream& lex)
GET_CHECK_TOK(tok, lex, TOK_DOUBLE_DOT);
AST::Expr array_size = Parse_Expr(lex, true);
GET_CHECK_TOK(tok, lex, TOK_SQUARE_CLOSE);
- return TypeRef(TypeRef::TagSizedArray(), inner, ::std::move(array_size));
+ return TypeRef(TypeRef::TagSizedArray(), inner, array_size.take_node());
}
else {
GET_CHECK_TOK(tok, lex, TOK_SQUARE_CLOSE);
diff --git a/src/types.cpp b/src/types.cpp
index a5edb5b8..c0a69f8d 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -3,6 +3,11 @@
#include "types.hpp"
#include "ast/ast.hpp"
-TypeRef::TypeRef(TypeRef::TagSizedArray, TypeRef inner, AST::Expr&& size_expr)
-{
+::std::ostream& operator<<(::std::ostream& os, const TypeRef& tr) {
+ os << "TypeRef(TODO)";
+ return os;
}
+
+SERIALISE_TYPE(TypeRef::, "TypeRef", {
+ // TODO: TypeRef serialise
+})
diff --git a/src/types.hpp b/src/types.hpp
index 2e6a1fa1..7ce170f2 100644
--- a/src/types.hpp
+++ b/src/types.hpp
@@ -1,51 +1,99 @@
#ifndef TYPES_HPP_INCLUDED
#define TYPES_HPP_INCLUDED
+#include <memory>
+
#include "common.hpp"
#include "coretypes.hpp"
#include "ast/path.hpp"
#include <serialise.hpp>
namespace AST {
+class ExprNode;
class Expr;
}
class TypeRef:
public Serialisable
{
+ enum Class {
+ ANY,
+ UNIT,
+ PRIMITIVE,
+ TUPLE,
+ REFERENCE,
+ POINTER,
+ ARRAY,
+ GENERIC,
+ PATH,
+ };
+
+ Class m_class;
+ enum eCoreType m_core_type;
+ bool m_is_inner_mutable;
+
+ AST::Path m_path; // local = argument
+ ::std::vector<TypeRef> m_inner_types;
+ ::std::shared_ptr<AST::ExprNode> m_size_expr; //< Can be null (unsized array)
public:
- TypeRef() {}
+ TypeRef():
+ m_class(ANY)
+ {}
struct TagUnit {}; // unit maps to a zero-length tuple, just easier to type
- TypeRef(TagUnit) {}
+ TypeRef(TagUnit):
+ m_class(UNIT)
+ {}
struct TagPrimitive {};
- TypeRef(TagPrimitive, enum eCoreType type) {}
+ TypeRef(TagPrimitive, enum eCoreType type):
+ m_class(PRIMITIVE),
+ m_core_type(type)
+ {}
struct TagTuple {};
- TypeRef(TagTuple _, ::std::vector<TypeRef> inner_types) {}
+ TypeRef(TagTuple _, ::std::vector<TypeRef> inner_types):
+ m_class(TUPLE),
+ m_inner_types( ::std::move(inner_types) )
+ {}
struct TagReference {};
- TypeRef(TagReference _, bool is_mut, TypeRef inner_type) {}
+ TypeRef(TagReference _, bool is_mut, TypeRef inner_type):
+ m_class(REFERENCE),
+ m_is_inner_mutable(is_mut),
+ m_inner_types({::std::move(inner_type)})
+ {}
struct TagPointer {};
- TypeRef(TagPointer _, bool is_mut, TypeRef inner_type) {}
+ TypeRef(TagPointer _, bool is_mut, TypeRef inner_type):
+ m_class(POINTER),
+ m_is_inner_mutable(is_mut),
+ m_inner_types({::std::move(inner_type)})
+ {}
struct TagSizedArray {};
- TypeRef(TagSizedArray _, TypeRef inner_type, AST::Expr&& size);
+ TypeRef(TagSizedArray _, TypeRef inner_type, ::std::shared_ptr<AST::ExprNode> size):
+ m_class(ARRAY),
+ m_inner_types({::std::move(inner_type)}),
+ m_size_expr( ::std::move(size) )
+ {}
struct TagUnsizedArray {};
- TypeRef(TagUnsizedArray _, TypeRef inner_type) {}
+ TypeRef(TagUnsizedArray _, TypeRef inner_type):
+ m_class(ARRAY),
+ m_inner_types({::std::move(inner_type)})
+ {}
struct TagArg {};
- TypeRef(TagArg, ::std::string name) {}
+ TypeRef(TagArg, ::std::string name):
+ m_class(GENERIC),
+ m_path({AST::PathNode(name, {})})
+ {}
struct TagPath {};
- TypeRef(TagPath, AST::Path path) {}
-
- friend ::std::ostream& operator<<(::std::ostream& os, const TypeRef& tr) {
- os << "TypeRef(TODO)";
- return os;
- }
+ TypeRef(TagPath, AST::Path path):
+ m_class(PATH),
+ m_path( ::std::move(path) )
+ {}
- SERIALISE_TYPE(, "TypeRef", {
- // TODO: Typeref serialise
- })
+ friend ::std::ostream& operator<<(::std::ostream& os, const TypeRef& tr);
+
+ SERIALISABLE_PROTOTYPES();
};
#endif // TYPES_HPP_INCLUDED