From f36518ed2fb6444884f991bcd6c8e0c3acd47beb Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 4 Jun 2016 15:08:50 +0800 Subject: Compilation fixes (clang and different gcc version) --- src/ast/expr.cpp | 2 +- src/ast/path.cpp | 10 +++++----- src/ast/path.hpp | 24 ------------------------ src/ast/types.hpp | 4 ++++ src/hir/expr_ptr.hpp | 2 ++ src/hir/from_ast.cpp | 4 +--- src/hir/hir.hpp | 18 ++++++++++++++---- src/hir/type.hpp | 5 +++-- src/hir_conv/bind.cpp | 2 +- src/hir_conv/constant_evaluation.cpp | 2 +- src/hir_conv/expand_type.cpp | 2 +- src/hir_conv/resolve_ufcs.cpp | 2 +- src/hir_typeck/expr.cpp | 6 +++--- src/hir_typeck/outer.cpp | 6 +++--- src/include/synext.hpp | 8 ++++---- src/parse/lex.cpp | 3 +-- src/parse/parseerror.cpp | 3 +-- src/parse/parseerror.hpp | 2 +- src/parse/root.cpp | 14 ++++++++++---- src/parse/tokentree.hpp | 1 - 20 files changed, 57 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/ast/expr.cpp b/src/ast/expr.cpp index 24e6ab3b..ddb72beb 100644 --- a/src/ast/expr.cpp +++ b/src/ast/expr.cpp @@ -41,7 +41,7 @@ SERIALISE_TYPE(Expr::, "Expr", { ::std::ostream& operator<<(::std::ostream& os, const ExprNode& node) { - if( &node != nullptr ) { + if( static_cast(&node) != nullptr ) { node.print(os); } else { diff --git a/src/ast/path.cpp b/src/ast/path.cpp index bd5ffe1a..01eed8c7 100644 --- a/src/ast/path.cpp +++ b/src/ast/path.cpp @@ -151,19 +151,19 @@ AST::Path::Path(const Path& x): TU_MATCH(Class, (x.m_class), (ent), (Invalid, m_class = Class::make_Invalid({});), (Local, - m_class = Class::make_Local({name: ent.name}); + m_class = Class::make_Local({ent.name}); ), (Relative, - m_class = Class::make_Relative({nodes: ent.nodes}); + m_class = Class::make_Relative({ent.nodes}); ), (Self, - m_class = Class::make_Self({nodes: ent.nodes}); + m_class = Class::make_Self({ent.nodes}); ), (Super, - m_class = Class::make_Super({count: ent.count, nodes: ent.nodes}); + m_class = Class::make_Super({ent.count, ent.nodes}); ), (Absolute, - m_class = Class::make_Absolute({crate: ent.crate, nodes: ent.nodes}); + m_class = Class::make_Absolute({ent.crate, ent.nodes}); ), (UFCS, if( ent.trait ) diff --git a/src/ast/path.hpp b/src/ast/path.hpp index 4b9cffa4..c31f4bc0 100644 --- a/src/ast/path.hpp +++ b/src/ast/path.hpp @@ -217,30 +217,6 @@ public: return m_class.tag(); } - /// Add the all nodes except the first from 'b' to 'a' and return - static Path add_tailing(const Path& a, const Path& b) { - Path ret(a); - ret.add_tailing(b); - return ret; - } - /// Grab the args from the first node of b, and add the rest to the end of the path - // TODO: Args should probably be moved to the path, not the nodes - void add_tailing(const Path& b) { - assert( !this->m_class.is_Invalid() ); - assert( b.m_class.is_Relative() ); - const auto& b_r = b.m_class.as_Relative(); - if( b_r.nodes.size() == 0 ) - ; - else if( nodes().size() > 0 ) - nodes().back().args() = b[0].args(); - else if( ! b[0].args().is_empty() ) - throw ::std::runtime_error("add_tail to empty path, but generics in source"); - else { - } - for(unsigned int i = 1; i < b_r.nodes.size(); i ++) - nodes().push_back(b_r.nodes[i]); - m_binding = PathBinding(); - } Path operator+(PathNode&& pn) const { Path tmp = Path(*this); tmp.nodes().push_back( pn ); diff --git a/src/ast/types.hpp b/src/ast/types.hpp index b3208f8c..2e9608a5 100644 --- a/src/ast/types.hpp +++ b/src/ast/types.hpp @@ -243,6 +243,10 @@ public: bool is_pointer() const { return m_data.is_Pointer(); } bool is_tuple() const { return m_data.is_Tuple(); } + TypeRef clone() const { + return TypeRef(*this); + } + //::option as_tuple() const { // switch(m_data.tag()) // { diff --git a/src/hir/expr_ptr.hpp b/src/hir/expr_ptr.hpp index 6378b052..80400d55 100644 --- a/src/hir/expr_ptr.hpp +++ b/src/hir/expr_ptr.hpp @@ -29,6 +29,8 @@ public: ~ExprPtr(); ::std::unique_ptr< ::HIR::ExprNode> into_unique(); + operator bool () const { return node != nullptr; } + ::HIR::ExprNode* get() const { return node; } ::HIR::ExprNode& operator*() { return *node; } const ::HIR::ExprNode& operator*() const { return *node; } diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index 626b3348..d2aba4a9 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -670,9 +670,7 @@ ::HIR::Trait rv { LowerHIR_GenericParams(f.params()), mv$(lifetime), - mv$(supertraits), - {}, - {} + mv$(supertraits) }; for(const auto& item : f.items()) diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp index ef565c4e..9b76c166 100644 --- a/src/hir/hir.hpp +++ b/src/hir/hir.hpp @@ -54,8 +54,9 @@ extern ::std::ostream& operator<<(::std::ostream& os, const Literal& v); // -------------------------------------------------------------------- // Type structures // -------------------------------------------------------------------- -struct Static +class Static { +public: bool m_is_mut; TypeRef m_type; @@ -71,8 +72,9 @@ struct Constant ExprPtr m_value; Literal m_value_res; }; -struct Function +class Function { +public: ::std::string m_abi; bool m_unsafe; bool m_const; @@ -93,8 +95,9 @@ struct TypeAlias GenericParams m_params; ::HIR::TypeRef m_type; }; -struct Enum +class Enum { +public: TAGGED_UNION(Variant, Unit, (Unit, struct{}), (Value, ::HIR::ExprPtr), @@ -112,8 +115,9 @@ struct Enum Repr m_repr; ::std::vector< ::std::pair< ::std::string, Variant > > m_variants; }; -struct Struct +class Struct { +public: enum class Repr { Rust, @@ -153,6 +157,12 @@ struct Trait ::std::unordered_map< ::std::string, AssociatedType > m_types; ::std::unordered_map< ::std::string, TraitValueItem > m_values; + + Trait( GenericParams gps, ::std::string lifetime, ::std::vector< ::HIR::GenericPath> parents): + m_params( mv$(gps) ), + m_lifetime( mv$(lifetime) ), + m_parent_traits( mv$(parents) ) + {} }; class Module diff --git a/src/hir/type.hpp b/src/hir/type.hpp index 9fe13872..49c0107f 100644 --- a/src/hir/type.hpp +++ b/src/hir/type.hpp @@ -12,7 +12,7 @@ namespace HIR { class Struct; class Enum; -struct TypeRef; +class TypeRef; enum class CoreType { @@ -49,8 +49,9 @@ struct FunctionType ::std::vector m_arg_types; }; -struct TypeRef +class TypeRef { +public: // Options: // - Primitive // - Parameter diff --git a/src/hir_conv/bind.cpp b/src/hir_conv/bind.cpp index e06708fc..c96fc348 100644 --- a/src/hir_conv/bind.cpp +++ b/src/hir_conv/bind.cpp @@ -280,7 +280,7 @@ namespace { } }; - if( &*expr != nullptr ) + if( expr.get() != nullptr ) { ExprVisitor v { *this }; (*expr).visit(v); diff --git a/src/hir_conv/constant_evaluation.cpp b/src/hir_conv/constant_evaluation.cpp index 9ccd2033..c9f25f60 100644 --- a/src/hir_conv/constant_evaluation.cpp +++ b/src/hir_conv/constant_evaluation.cpp @@ -572,7 +572,7 @@ namespace { } }; - if( &*expr != nullptr ) + if( expr.get() != nullptr ) { Visitor v { this->m_crate }; (*expr).visit(v); diff --git a/src/hir_conv/expand_type.cpp b/src/hir_conv/expand_type.cpp index 2b2ba4c6..c29b7d71 100644 --- a/src/hir_conv/expand_type.cpp +++ b/src/hir_conv/expand_type.cpp @@ -125,7 +125,7 @@ public: } }; - if( &*expr != nullptr ) + if( expr.get() != nullptr ) { Visitor v { *this }; (*expr).visit(v); diff --git a/src/hir_conv/resolve_ufcs.cpp b/src/hir_conv/resolve_ufcs.cpp index fbc4bc6f..be23be21 100644 --- a/src/hir_conv/resolve_ufcs.cpp +++ b/src/hir_conv/resolve_ufcs.cpp @@ -84,7 +84,7 @@ namespace { } }; - if( &*expr != nullptr ) + if( expr.get() != nullptr ) { ExprVisitor v { *this }; (*expr).visit(v); diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp index 9b35c1c7..d9dd3198 100644 --- a/src/hir_typeck/expr.cpp +++ b/src/hir_typeck/expr.cpp @@ -1210,7 +1210,7 @@ namespace { // ------ void visit_function(::HIR::Function& item) override { auto _ = this->set_item_generics(item.m_params); - if( &*item.m_code ) + if( item.m_code ) { TypecheckContext typeck_context { }; for( auto& arg : item.m_args ) { @@ -1222,7 +1222,7 @@ namespace { } void visit_static(::HIR::Static& item) override { //auto _ = this->set_item_generics(item.m_params); - if( &*item.m_value ) + if( item.m_value ) { TypecheckContext typeck_context { }; DEBUG("Static value"); @@ -1231,7 +1231,7 @@ namespace { } void visit_constant(::HIR::Constant& item) override { auto _ = this->set_item_generics(item.m_params); - if( &*item.m_value ) + if( item.m_value ) { TypecheckContext typeck_context { }; DEBUG("Const value"); diff --git a/src/hir_typeck/outer.cpp b/src/hir_typeck/outer.cpp index 156dd6e8..ff2b0477 100644 --- a/src/hir_typeck/outer.cpp +++ b/src/hir_typeck/outer.cpp @@ -99,13 +99,13 @@ namespace { ::HIR::Crate& crate; ::HIR::GenericParams* m_impl_generics; - ::HIR::GenericParams* m_item_generics; + //::HIR::GenericParams* m_item_generics; ::std::vector< ::HIR::TypeRef* > m_self_types; public: Visitor(::HIR::Crate& crate): crate(crate), - m_impl_generics(nullptr), - m_item_generics(nullptr) + m_impl_generics(nullptr)/*, + m_item_generics(nullptr)*/ { } diff --git a/src/include/synext.hpp b/src/include/synext.hpp index 3ac3fb37..ae1c14f6 100644 --- a/src/include/synext.hpp +++ b/src/include/synext.hpp @@ -13,16 +13,16 @@ namespace AST { class MetaItem; class Path; - class StructItem; - class TupleItem; - class EnumVariant; + struct StructItem; + struct TupleItem; + struct EnumVariant; class Module; class Item; class Expr; class ExprNode; - class ExprNode_Match_Arm; + struct ExprNode_Match_Arm; class MacroInvocation; diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp index 5530f0b5..2b84d0e4 100644 --- a/src/parse/lex.cpp +++ b/src/parse/lex.cpp @@ -930,8 +930,7 @@ void Lexer::ungetc() m_last_char_valid = true; } -TTStream::TTStream(const TokenTree& input_tt): - m_input_tt(input_tt) +TTStream::TTStream(const TokenTree& input_tt) { DEBUG("input_tt = [" << input_tt << "]"); m_stack.push_back( ::std::make_pair(0, &input_tt) ); diff --git a/src/parse/parseerror.cpp b/src/parse/parseerror.cpp index 7c6f6a21..116776a5 100644 --- a/src/parse/parseerror.cpp +++ b/src/parse/parseerror.cpp @@ -47,8 +47,7 @@ CompileError::Todo::~Todo() throw() { } -ParseError::BadChar::BadChar(const TokenStream& lex, char character): - m_char(character) +ParseError::BadChar::BadChar(const TokenStream& lex, char character) { ::std::cout << lex.getPosition() << ": BadChar(" << character << ")" << ::std::endl; } diff --git a/src/parse/parseerror.hpp b/src/parse/parseerror.hpp index 42a89785..b847ccc4 100644 --- a/src/parse/parseerror.hpp +++ b/src/parse/parseerror.hpp @@ -14,7 +14,7 @@ using CompileError::Todo; class BadChar: public CompileError::Base { - char m_char; + //char m_char; public: BadChar(const TokenStream& lex, char character); virtual ~BadChar() throw (); diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 58708ec7..15b792d0 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -65,10 +65,14 @@ void Parse_TypeBound(TokenStream& lex, AST::GenericParams& ret, TypeRef checked_ do { if(GET_TOK(tok, lex) == TOK_LIFETIME) { - ret.add_bound(AST::GenericBound::make_TypeLifetime( {type: checked_type, bound: tok.str()} )); + ret.add_bound(AST::GenericBound::make_TypeLifetime( { + checked_type.clone(), tok.str() + } )); } else if( tok.type() == TOK_QMARK ) { - ret.add_bound(AST::GenericBound::make_MaybeTrait( {type: checked_type, trait: Parse_Path(lex, PATH_GENERIC_TYPE)} )); + ret.add_bound(AST::GenericBound::make_MaybeTrait( { + checked_type.clone(), Parse_Path(lex, PATH_GENERIC_TYPE) + } )); } else { if( tok.type() == TOK_RWORD_FOR ) @@ -90,7 +94,9 @@ void Parse_TypeBound(TokenStream& lex, AST::GenericParams& ret, TypeRef checked_ PUTBACK(tok, lex); } - ret.add_bound( AST::GenericBound::make_IsTrait( {type: checked_type, hrls: lifetimes, trait: Parse_Path(lex, PATH_GENERIC_TYPE) }) ); + ret.add_bound( AST::GenericBound::make_IsTrait({ + checked_type.clone(), mv$(lifetimes), Parse_Path(lex, PATH_GENERIC_TYPE) + }) ); } } while( GET_TOK(tok, lex) == TOK_PLUS ); PUTBACK(tok, lex); @@ -131,7 +137,7 @@ AST::GenericParams Parse_GenericParams(TokenStream& lex) { do { GET_CHECK_TOK(tok, lex, TOK_LIFETIME); - ret.add_bound(AST::GenericBound::make_Lifetime( {test: param_name, bound: tok.str()} )); + ret.add_bound(AST::GenericBound::make_Lifetime( {param_name, tok.str()} )); } while( GET_TOK(tok, lex) == TOK_PLUS ); } else diff --git a/src/parse/tokentree.hpp b/src/parse/tokentree.hpp index 68080689..7f8810a7 100644 --- a/src/parse/tokentree.hpp +++ b/src/parse/tokentree.hpp @@ -61,7 +61,6 @@ public: class TTStream: public TokenStream { - const TokenTree& m_input_tt; ::std::vector< ::std::pair > m_stack; public: TTStream(const TokenTree& input_tt); -- cgit v1.2.3