diff options
author | John Hodge <tpg@mutabah.net> | 2015-09-19 18:55:13 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2015-09-19 18:55:13 +0800 |
commit | 8b22df5f2a6e1f37cf1964f82d369c8363e8016b (patch) | |
tree | c4ed3c14fe3890cc4e04a6a1a975f575b2c0b714 | |
parent | e6738ed57d644572e7cbefa6d68a4118935a5f80 (diff) | |
download | mrust-8b22df5f2a6e1f37cf1964f82d369c8363e8016b.tar.gz |
Remove function class in favor of full UFCS
-rw-r--r-- | src/ast/ast.cpp | 26 | ||||
-rw-r--r-- | src/ast/ast.hpp | 17 | ||||
-rw-r--r-- | src/convert/ast_iterate.cpp | 34 | ||||
-rw-r--r-- | src/convert/typecheck_expr.cpp | 34 | ||||
-rw-r--r-- | src/parse/root.cpp | 13 | ||||
-rw-r--r-- | src/synexts/derive.cpp | 7 |
6 files changed, 47 insertions, 84 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index d2006e52..2fe36225 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -798,38 +798,12 @@ SERIALISE_TYPE(Static::, "AST_Static", { s.item(m_value);
})
-::Serialiser& operator<<(::Serialiser& s, Function::Class fc)
-{
- switch(fc)
- {
- case Function::CLASS_UNBOUND: s << "UNBOUND"; break;
- case Function::CLASS_REFMETHOD: s << "REFMETHOD"; break;
- case Function::CLASS_MUTMETHOD: s << "MUTMETHOD"; break;
- case Function::CLASS_VALMETHOD: s << "VALMETHOD"; break;
- case Function::CLASS_MUTVALMETHOD: s << "MUTVALMETHOD"; break;
- }
- return s;
-}
-void operator>>(::Deserialiser& s, Function::Class& fc)
-{
- ::std::string n;
- s.item(n);
- if(n == "UNBOUND") fc = Function::CLASS_UNBOUND;
- else if(n == "REFMETHOD") fc = Function::CLASS_REFMETHOD;
- else if(n == "MUTMETHOD") fc = Function::CLASS_MUTMETHOD;
- else if(n == "VALMETHOD") fc = Function::CLASS_VALMETHOD;
- else if(n == "MUTVALMETHOD") fc = Function::CLASS_MUTVALMETHOD;
- else
- throw ::std::runtime_error("Deserialise Function::Class");
-}
SERIALISE_TYPE(Function::, "AST_Function", {
- s << m_fcn_class;
s << m_params;
s << m_rettype;
s << m_args;
s << m_code;
},{
- s >> m_fcn_class;
s.item(m_params);
s.item(m_rettype);
s.item(m_args);
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index bec17bda..94b217d1 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -351,33 +351,22 @@ class Function: public Serialisable
{
public:
- enum Class
- {
- CLASS_UNBOUND,
- CLASS_REFMETHOD,
- CLASS_MUTMETHOD,
- CLASS_VALMETHOD,
- CLASS_MUTVALMETHOD,
- };
typedef ::std::vector< ::std::pair<AST::Pattern,TypeRef> > Arglist;
private:
MetaItems m_attrs;
- Class m_fcn_class;
::std::string m_lifetime;
TypeParams m_params;
Expr m_code;
TypeRef m_rettype;
Arglist m_args;
public:
- Function():
- m_fcn_class(CLASS_UNBOUND)
+ Function()
{}
Function(const Function&) = delete;
Function(Function&&) noexcept = default;
- Function(MetaItems attrs, TypeParams params, Class fcn_class, TypeRef ret_type, Arglist args):
+ Function(MetaItems attrs, TypeParams params, TypeRef ret_type, Arglist args):
m_attrs( move(attrs) ),
- m_fcn_class(fcn_class),
m_params( move(params) ),
m_rettype( move(ret_type) ),
m_args( move(args) )
@@ -387,8 +376,6 @@ public: void set_code(Expr code) { m_code = ::std::move(code); }
void set_self_lifetime(::std::string s) { m_lifetime = s; }
- const Class fcn_class() const { return m_fcn_class; }
-
const MetaItems& attrs() const { return m_attrs; }
const TypeParams& params() const { return m_params; }
const Expr& code() const { return m_code; }
diff --git a/src/convert/ast_iterate.cpp b/src/convert/ast_iterate.cpp index 2946fd63..1536fa61 100644 --- a/src/convert/ast_iterate.cpp +++ b/src/convert/ast_iterate.cpp @@ -314,23 +314,23 @@ void CASTIterator::handle_function(AST::Path path, AST::Function& fcn) DEBUG("ret type"); handle_type(fcn.rettype()); - switch( fcn.fcn_class() ) - { - case AST::Function::CLASS_UNBOUND: - break; - case AST::Function::CLASS_REFMETHOD: - local_variable(false, "self", TypeRef(TypeRef::TagReference(), false, TypeRef(TypeRef::TagArg(), "Self"))); - break; - case AST::Function::CLASS_MUTMETHOD: - local_variable(false, "self", TypeRef(TypeRef::TagReference(), true, TypeRef(TypeRef::TagArg(), "Self"))); - break; - case AST::Function::CLASS_VALMETHOD: - local_variable(false, "self", TypeRef(TypeRef::TagArg(), "Self")); - break; - case AST::Function::CLASS_MUTVALMETHOD: - local_variable(true, "self", TypeRef(TypeRef::TagArg(), "Self")); - break; - } + //switch( fcn.fcn_class() ) + //{ + //case AST::Function::CLASS_UNBOUND: + // break; + //case AST::Function::CLASS_REFMETHOD: + // local_variable(false, "self", TypeRef(TypeRef::TagReference(), false, TypeRef(TypeRef::TagArg(), "Self"))); + // break; + //case AST::Function::CLASS_MUTMETHOD: + // local_variable(false, "self", TypeRef(TypeRef::TagReference(), true, TypeRef(TypeRef::TagArg(), "Self"))); + // break; + //case AST::Function::CLASS_VALMETHOD: + // local_variable(false, "self", TypeRef(TypeRef::TagArg(), "Self")); + // break; + //case AST::Function::CLASS_MUTVALMETHOD: + // local_variable(true, "self", TypeRef(TypeRef::TagArg(), "Self")); + // break; + //} DEBUG("args"); for( auto& arg : fcn.args() ) diff --git a/src/convert/typecheck_expr.cpp b/src/convert/typecheck_expr.cpp index 16aaf62d..ac25982c 100644 --- a/src/convert/typecheck_expr.cpp +++ b/src/convert/typecheck_expr.cpp @@ -206,23 +206,23 @@ void CTypeChecker::handle_function(AST::Path path, AST::Function& fcn) handle_type(fcn.rettype()); - switch(fcn.fcn_class()) - { - case AST::Function::CLASS_UNBOUND: - break; - case AST::Function::CLASS_REFMETHOD: - local_variable(false, "self", TypeRef(TypeRef::TagReference(), false, get_local_type("Self"))); - break; - case AST::Function::CLASS_MUTMETHOD: - local_variable(false, "self", TypeRef(TypeRef::TagReference(), true, get_local_type("Self"))); - break; - case AST::Function::CLASS_VALMETHOD: - local_variable(false, "self", TypeRef(get_local_type("Self"))); - break; - case AST::Function::CLASS_MUTVALMETHOD: - local_variable(true, "self", TypeRef(get_local_type("Self"))); - break; - } + //switch(fcn.fcn_class()) + //{ + //case AST::Function::CLASS_UNBOUND: + // break; + //case AST::Function::CLASS_REFMETHOD: + // local_variable(false, "self", TypeRef(TypeRef::TagReference(), false, get_local_type("Self"))); + // break; + //case AST::Function::CLASS_MUTMETHOD: + // local_variable(false, "self", TypeRef(TypeRef::TagReference(), true, get_local_type("Self"))); + // break; + //case AST::Function::CLASS_VALMETHOD: + // local_variable(false, "self", TypeRef(get_local_type("Self"))); + // break; + //case AST::Function::CLASS_MUTVALMETHOD: + // local_variable(true, "self", TypeRef(get_local_type("Self"))); + // break; + //} for( auto& arg : fcn.args() ) { diff --git a/src/parse/root.cpp b/src/parse/root.cpp index d0bf795c..2931f492 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -217,7 +217,6 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, AST::MetaIt lex.putback(tok);
}
- AST::Function::Class fcn_class = AST::Function::CLASS_UNBOUND;
AST::Function::Arglist args;
GET_CHECK_TOK(tok, lex, TOK_PAREN_OPEN);
@@ -243,11 +242,11 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, AST::MetaIt if( tok.type() == TOK_RWORD_MUT )
{
GET_CHECK_TOK(tok, lex, TOK_RWORD_SELF);
- fcn_class = AST::Function::CLASS_MUTMETHOD;
+ args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef(TypeRef::TagReference(), true, TypeRef("Self"))) );
}
else
{
- fcn_class = AST::Function::CLASS_REFMETHOD;
+ args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef(TypeRef::TagReference(), false, TypeRef("Self"))) );
}
DEBUG("TODO: UFCS / self lifetimes");
if( allow_self == false )
@@ -273,7 +272,7 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, AST::MetaIt GET_TOK(tok, lex);
if( allow_self == false )
throw ParseError::Generic(lex, "Self binding not expected");
- fcn_class = AST::Function::CLASS_MUTVALMETHOD;
+ args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef("Self")) );
GET_TOK(tok, lex);
}
}
@@ -282,7 +281,7 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, AST::MetaIt // By-value method
if( allow_self == false )
throw ParseError::Generic(lex, "Self binding not expected");
- fcn_class = AST::Function::CLASS_VALMETHOD;
+ args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef("Self")) );
GET_TOK(tok, lex);
}
else
@@ -293,7 +292,7 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, AST::MetaIt if( tok.type() != TOK_PAREN_CLOSE )
{
// Comma after self
- if( fcn_class != AST::Function::CLASS_UNBOUND )
+ if( args.size() )
{
CHECK_TOK(tok, TOK_COMMA);
}
@@ -336,7 +335,7 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, AST::MetaIt lex.putback(tok);
}
- return AST::Function(::std::move(attrs), ::std::move(params), fcn_class, ::std::move(ret_type), ::std::move(args));
+ return AST::Function(::std::move(attrs), ::std::move(params), ::std::move(ret_type), ::std::move(args));
}
AST::Function Parse_FunctionDefWithCode(TokenStream& lex, ::std::string abi, AST::MetaItems attrs, bool allow_self)
diff --git a/src/synexts/derive.cpp b/src/synexts/derive.cpp index d52823aa..92566d06 100644 --- a/src/synexts/derive.cpp +++ b/src/synexts/derive.cpp @@ -83,9 +83,12 @@ public: DEBUG("node = " << *node); AST::Function fcn( - AST::MetaItems(), AST::TypeParams(), AST::Function::CLASS_REFMETHOD, + AST::MetaItems(), AST::TypeParams(), ret_type, - vec$( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "f"), f_type ) ) + vec$( + ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef(TypeRef::TagReference(), false, TypeRef("Self")) ), + ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "f"), f_type ) + ) ); fcn.set_code( NEWNODE(AST::ExprNode_Block, vec$(mv$(node)), ::std::unique_ptr<AST::Module>()) ); |