diff options
Diffstat (limited to 'src/ast')
-rw-r--r-- | src/ast/ast.cpp | 12 | ||||
-rw-r--r-- | src/ast/ast.hpp | 23 | ||||
-rw-r--r-- | src/ast/expr.hpp | 27 | ||||
-rw-r--r-- | src/ast/generics.hpp | 36 | ||||
-rw-r--r-- | src/ast/types.hpp | 24 |
5 files changed, 40 insertions, 82 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 08aad21b..144842db 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -77,7 +77,7 @@ TupleItem TupleItem::clone() const TypeAlias TypeAlias::clone() const
{
- return TypeAlias( m_params, m_type );
+ return TypeAlias( m_params.clone(), m_type );
}
Static Static::clone() const
{
@@ -101,7 +101,7 @@ Function Function::clone() const for(const auto& arg : m_args)
new_args.push_back( ::std::make_pair( arg.first.clone(), arg.second ) );
- auto rv = Function( m_span, m_params, m_abi, m_is_unsafe, m_is_const, m_is_variadic, m_rettype, mv$(new_args) );
+ auto rv = Function( m_span, m_params.clone(), m_abi, m_is_unsafe, m_is_const, m_is_variadic, m_rettype, mv$(new_args) );
if( m_code.is_valid() )
{
rv.m_code = AST::Expr( m_code.node().clone() );
@@ -139,7 +139,7 @@ bool Trait::has_named_item(const ::std::string& name, bool& out_is_fcn) const Trait Trait::clone() const
{
- auto rv = Trait(m_params, m_supertraits);
+ auto rv = Trait(m_params.clone(), m_supertraits);
for(const auto& item : m_items)
{
rv.m_items.push_back( Named<Item> { item.name, item.data.clone(), item.is_pub } );
@@ -167,7 +167,7 @@ Enum Enum::clone() const )
)
}
- return Enum(m_params, mv$(new_variants));
+ return Enum(m_params.clone(), mv$(new_variants));
}
Struct Struct::clone() const
{
@@ -176,13 +176,13 @@ Struct Struct::clone() const decltype(e.ents) new_fields;
for(const auto& f : e.ents)
new_fields.push_back( f.clone() );
- return Struct(m_params, mv$(new_fields));
+ return Struct(m_params.clone(), mv$(new_fields));
),
(Struct,
decltype(e.ents) new_fields;
for(const auto& f : e.ents)
new_fields.push_back( f.clone() );
- return Struct(m_params, mv$(new_fields));
+ return Struct(m_params.clone(), mv$(new_fields));
)
)
throw "";
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index 700a7e40..e6b1ea1c 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -55,9 +55,7 @@ struct StructItem ::std::string m_name;
TypeRef m_type;
- StructItem()
- {
- }
+ //StructItem() {}
StructItem(::AST::MetaItems attrs, bool is_pub, ::std::string name, TypeRef ty):
m_attrs( mv$(attrs) ),
@@ -80,9 +78,7 @@ struct TupleItem bool m_is_public;
TypeRef m_type;
- TupleItem()
- {
- }
+ //TupleItem() {}
TupleItem(::AST::MetaItems attrs, bool is_pub, TypeRef ty):
m_attrs( mv$(attrs) ),
@@ -103,7 +99,7 @@ class TypeAlias GenericParams m_params;
TypeRef m_type;
public:
- TypeAlias() {}
+ //TypeAlias() {}
TypeAlias(GenericParams params, TypeRef type):
m_params( move(params) ),
m_type( move(type) )
@@ -132,9 +128,9 @@ private: TypeRef m_type;
Expr m_value;
public:
- Static():
- m_class(CONST)
- {}
+ //Static():
+ // m_class(CONST)
+ //{}
Static(Class s_class, TypeRef type, Expr value):
m_class(s_class),
m_type( move(type) ),
@@ -170,13 +166,12 @@ private: bool m_is_unsafe;
bool m_is_variadic; // extern only
public:
- Function()
- {}
Function(const Function&) = delete;
Function& operator=(const Function&) = delete;
Function(Function&&) = default;
Function& operator=(Function&&) = default;
+ //Function() {}
Function(Span sp, GenericParams params, ::std::string abi, bool is_unsafe, bool is_const, bool is_variadic, TypeRef ret_type, Arglist args);
void set_code(Expr code) { m_code = ::std::move(code); }
@@ -369,7 +364,7 @@ class ImplDef Spanned<Path> m_trait;
TypeRef m_type;
public:
- ImplDef() {}
+ //ImplDef() {}
ImplDef(ImplDef&&) /*noexcept*/ = default;
ImplDef(Span sp, MetaItems attrs, GenericParams params, Spanned<Path> trait_type, TypeRef impl_type):
m_span( mv$(sp) ),
@@ -416,7 +411,7 @@ private: //NamedList<Static> m_statics;
public:
- Impl() {}
+ //Impl() {}
Impl(Impl&&) /*noexcept*/ = default;
Impl(ImplDef def):
m_def( mv$(def) )
diff --git a/src/ast/expr.hpp b/src/ast/expr.hpp index 3f2151dd..1d1ccdae 100644 --- a/src/ast/expr.hpp +++ b/src/ast/expr.hpp @@ -20,7 +20,7 @@ class NodeVisitor; class ExprNode { - TypeRef m_res_type; + TypeRef m_res_type = TypeRef(Span()); MetaItems m_attrs; Position m_pos; public: @@ -81,7 +81,6 @@ struct ExprNode_Macro: ::std::string m_ident; ::TokenTree m_tokens; - ExprNode_Macro() {} ExprNode_Macro(::std::string name, ::std::string ident, ::TokenTree&& tokens): m_name(name), m_ident(ident), @@ -103,7 +102,6 @@ struct ExprNode_Flow: ::std::string m_target; unique_ptr<ExprNode> m_value; - ExprNode_Flow() {} ExprNode_Flow(Type type, ::std::string target, unique_ptr<ExprNode>&& value): m_type(type), m_target( move(target) ), @@ -120,7 +118,6 @@ struct ExprNode_LetBinding: TypeRef m_type; unique_ptr<ExprNode> m_value; - ExprNode_LetBinding() {} ExprNode_LetBinding(Pattern pat, TypeRef type, unique_ptr<ExprNode>&& value): m_pat( move(pat) ), m_type( move(type) ), @@ -159,7 +156,6 @@ struct ExprNode_CallPath: Path m_path; ::std::vector<unique_ptr<ExprNode>> m_args; - ExprNode_CallPath() {} ExprNode_CallPath(Path&& path, ::std::vector<unique_ptr<ExprNode>>&& args): m_path( move(path) ), m_args( move(args) ) @@ -175,7 +171,6 @@ struct ExprNode_CallMethod: PathNode m_method; ::std::vector<unique_ptr<ExprNode>> m_args; - ExprNode_CallMethod() {} ExprNode_CallMethod(unique_ptr<ExprNode> obj, PathNode method, ::std::vector<unique_ptr<ExprNode>> args): m_val( move(obj) ), m_method( move(method) ), @@ -192,7 +187,6 @@ struct ExprNode_CallObject: unique_ptr<ExprNode> m_val; ::std::vector<unique_ptr<ExprNode>> m_args; - ExprNode_CallObject() {} ExprNode_CallObject(unique_ptr<ExprNode>&& val, ::std::vector< unique_ptr<ExprNode> >&& args): m_val( move(val) ), m_args( move(args) ) @@ -261,7 +255,6 @@ struct ExprNode_Match: unique_ptr<ExprNode> m_val; ::std::vector<ExprNode_Match_Arm> m_arms; - ExprNode_Match() {} ExprNode_Match(unique_ptr<ExprNode> val, ::std::vector<ExprNode_Match_Arm> arms): m_val( ::std::move(val) ), m_arms( ::std::move(arms) ) @@ -277,7 +270,6 @@ struct ExprNode_If: unique_ptr<ExprNode> m_true; unique_ptr<ExprNode> m_false; - ExprNode_If() {} ExprNode_If(unique_ptr<ExprNode>&& cond, unique_ptr<ExprNode>&& true_code, unique_ptr<ExprNode>&& false_code): m_cond( ::std::move(cond) ), m_true( ::std::move(true_code) ), @@ -294,7 +286,6 @@ struct ExprNode_IfLet: unique_ptr<ExprNode> m_true; unique_ptr<ExprNode> m_false; - ExprNode_IfLet() {} ExprNode_IfLet(AST::Pattern pattern, unique_ptr<ExprNode>&& cond, unique_ptr<ExprNode>&& true_code, unique_ptr<ExprNode>&& false_code): m_pattern( ::std::move(pattern) ), m_value( ::std::move(cond) ), @@ -311,7 +302,6 @@ struct ExprNode_Integer: enum eCoreType m_datatype; uint64_t m_value; - ExprNode_Integer() {} ExprNode_Integer(uint64_t value, enum eCoreType datatype): m_datatype(datatype), m_value(value) @@ -327,7 +317,6 @@ struct ExprNode_Float: enum eCoreType m_datatype; double m_value; - ExprNode_Float() {} ExprNode_Float(double value, enum eCoreType datatype): m_datatype(datatype), m_value(value) @@ -342,7 +331,6 @@ struct ExprNode_Bool: { bool m_value; - ExprNode_Bool() {} ExprNode_Bool(bool value): m_value(value) { @@ -356,7 +344,6 @@ struct ExprNode_String: { ::std::string m_value; - ExprNode_String() {} ExprNode_String(::std::string value): m_value( ::std::move(value) ) {} @@ -369,7 +356,6 @@ struct ExprNode_ByteString: { ::std::string m_value; - ExprNode_ByteString() {} ExprNode_ByteString(::std::string value): m_value( ::std::move(value) ) {} @@ -387,7 +373,6 @@ struct ExprNode_Closure: TypeRef m_return; unique_ptr<ExprNode> m_code; - ExprNode_Closure() {} ExprNode_Closure(args_t args, TypeRef rv, unique_ptr<ExprNode> code): m_args( ::std::move(args) ), m_return( ::std::move(rv) ), @@ -405,7 +390,6 @@ struct ExprNode_StructLiteral: unique_ptr<ExprNode> m_base_value; t_values m_values; - ExprNode_StructLiteral() {} ExprNode_StructLiteral(Path path, unique_ptr<ExprNode>&& base_value, t_values&& values ): m_path( move(path) ), m_base_value( move(base_value) ), @@ -421,7 +405,6 @@ struct ExprNode_Array: unique_ptr<ExprNode> m_size; // if non-NULL, it's a sized array ::std::vector< unique_ptr<ExprNode> > m_values; - ExprNode_Array() {} ExprNode_Array(::std::vector< unique_ptr<ExprNode> > vals): m_values( ::std::move(vals) ) {} @@ -439,7 +422,6 @@ struct ExprNode_Tuple: { ::std::vector< unique_ptr<ExprNode> > m_values; - ExprNode_Tuple() {} ExprNode_Tuple(::std::vector< unique_ptr<ExprNode> > vals): m_values( ::std::move(vals) ) {} @@ -452,7 +434,6 @@ struct ExprNode_NamedValue: { Path m_path; - ExprNode_NamedValue() {} ExprNode_NamedValue(Path&& path): m_path( ::std::move(path) ) { @@ -466,7 +447,6 @@ struct ExprNode_Field: ::std::unique_ptr<ExprNode> m_obj; ::std::string m_name; - ExprNode_Field() {} ExprNode_Field(::std::unique_ptr<ExprNode>&& obj, ::std::string name): m_obj( ::std::move(obj) ), m_name( ::std::move(name) ) @@ -480,7 +460,6 @@ struct ExprNode_Index: ::std::unique_ptr<ExprNode> m_obj; ::std::unique_ptr<ExprNode> m_idx; - ExprNode_Index() {} ExprNode_Index(::std::unique_ptr<ExprNode> obj, ::std::unique_ptr<ExprNode> idx): m_obj( ::std::move(obj) ), m_idx( ::std::move(idx) ) @@ -495,7 +474,6 @@ struct ExprNode_Deref: { ::std::unique_ptr<ExprNode> m_value; - ExprNode_Deref() {} ExprNode_Deref(::std::unique_ptr<ExprNode> value): m_value( ::std::move(value) ) { @@ -511,7 +489,6 @@ struct ExprNode_Cast: unique_ptr<ExprNode> m_value; TypeRef m_type; - ExprNode_Cast() {} ExprNode_Cast(unique_ptr<ExprNode>&& value, TypeRef&& dst_type): m_value( move(value) ), m_type( move(dst_type) ) @@ -557,7 +534,6 @@ struct ExprNode_BinOp: ::std::unique_ptr<ExprNode> m_left; ::std::unique_ptr<ExprNode> m_right; - ExprNode_BinOp() {} ExprNode_BinOp(Type type, ::std::unique_ptr<ExprNode> left, ::std::unique_ptr<ExprNode> right): m_type(type), m_left( ::std::move(left) ), @@ -583,7 +559,6 @@ struct ExprNode_UniOp: enum Type m_type; ::std::unique_ptr<ExprNode> m_value; - ExprNode_UniOp() {} ExprNode_UniOp(Type type, ::std::unique_ptr<ExprNode> value): m_type(type), m_value( ::std::move(value) ) diff --git a/src/ast/generics.hpp b/src/ast/generics.hpp index 0209ccbb..f02de958 100644 --- a/src/ast/generics.hpp +++ b/src/ast/generics.hpp @@ -11,9 +11,10 @@ class TypeParam ::std::string m_name; TypeRef m_default; public: - TypeParam(): m_name("") {} + //TypeParam(): m_name("") {} TypeParam(::std::string name): - m_name( ::std::move(name) ) + m_name( ::std::move(name) ), + m_default( Span() ) {} void setDefault(TypeRef type) { assert(m_default.is_wildcard()); @@ -92,25 +93,18 @@ class GenericParams ::std::vector<GenericBound> m_bounds; public: GenericParams() {} - GenericParams(GenericParams&& x) noexcept: - m_type_params( mv$(x.m_type_params) ), - m_lifetime_params( mv$(x.m_lifetime_params) ), - m_bounds( mv$(x.m_bounds) ) - {} - GenericParams& operator=(GenericParams&& x) { - m_type_params = mv$(x.m_type_params); - m_lifetime_params = mv$(x.m_lifetime_params); - m_bounds = mv$(x.m_bounds); - return *this; - } - GenericParams(const GenericParams& x): - m_type_params(x.m_type_params), - m_lifetime_params(x.m_lifetime_params), - m_bounds() - { - m_bounds.reserve( x.m_bounds.size() ); - for(auto& e: x.m_bounds) - m_bounds.push_back( e.clone() ); + GenericParams(GenericParams&& x) noexcept = default; + GenericParams& operator=(GenericParams&& x) = default; + GenericParams(const GenericParams& x) = delete; + + GenericParams clone() const { + GenericParams rv; + rv.m_type_params = m_type_params; // Copy-constructable + rv.m_lifetime_params = m_lifetime_params; + rv.m_bounds.reserve( m_bounds.size() ); + for(auto& e: m_bounds) + rv.m_bounds.push_back( e.clone() ); + return rv; } const ::std::vector<TypeParam>& ty_params() const { return m_type_params; } diff --git a/src/ast/types.hpp b/src/ast/types.hpp index e0cede23..79934e16 100644 --- a/src/ast/types.hpp +++ b/src/ast/types.hpp @@ -96,6 +96,10 @@ TAGGED_UNION(TypeData, None, (TraitObject, struct {
::std::vector<::std::string> hrls;
::std::vector<AST::Path> traits;
+ // }),
+ //(ImplTrait, struct {
+ // ::std::vector<::std::string> hrls;
+ // ::std::vector<AST::Path> traits;
})
);
@@ -125,7 +129,7 @@ public: return *this;
}
- TypeRef(Span sp = Span()):
+ TypeRef(Span sp):
m_span( mv$(sp) ),
m_data( TypeData::make_Any({}) )
{}
@@ -195,11 +199,12 @@ public: {}
struct TagArg {};
- TypeRef(TagArg, ::std::string name, unsigned int binding = ~0u):
+ TypeRef(TagArg, Span sp, ::std::string name, unsigned int binding = ~0u):
+ m_span( mv$(sp) ),
m_data(TypeData::make_Generic({ name, binding }))
{}
- TypeRef(::std::string name, unsigned int binding = ~0u):
- TypeRef(TagArg(), ::std::move(name), binding)
+ TypeRef(Span sp, ::std::string name, unsigned int binding = ~0u):
+ TypeRef(TagArg(), mv$(sp), mv$(name), binding)
{}
struct TagPath {};
@@ -242,12 +247,6 @@ public: return TypeRef(*this);
}
- //::option<const TypeData::Tuple&> as_tuple() const {
- // switch(m_data.tag())
- // {
- // }
- //}
-
const TypeRef& inner_type() const {
TU_MATCH_DEF(TypeData, (m_data), (e),
( throw ::std::runtime_error("Called inner_type on non-wrapper"); ),
@@ -264,11 +263,6 @@ public: (Array, return *e.inner; )
)
}
- //::std::vector<TypeRef>& sub_types() { return m_inner_types; }
- //const ::std::vector<TypeRef>& sub_types() const { return m_inner_types; }
-
- //void add_trait(TypeRef trait) { assert(is_wildcard()); m_inner_types.push_back( ::std::move(trait) ); }
- //const ::std::vector<TypeRef>& traits() const { assert(is_wildcard()); return m_inner_types; }
Ordering ord(const TypeRef& x) const;
bool operator==(const TypeRef& x) const { return ord(x) == OrdEqual; }
|