diff options
author | John Hodge <tpg@mutabah.net> | 2016-02-25 13:52:39 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-02-25 13:52:39 +0800 |
commit | beaad85791e078f9128fbab3f5758e001340a6a8 (patch) | |
tree | 9b0cbe4843faad00799f5fda8d6923ba21bb3421 /src/ast | |
parent | a735e91e2f1ff8c688e9f8403860f8ef5bd74606 (diff) | |
download | mrust-beaad85791e078f9128fbab3f5758e001340a6a8.tar.gz |
Heaps more parse fixes against the rustc tests
Diffstat (limited to 'src/ast')
-rw-r--r-- | src/ast/attrs.hpp | 81 | ||||
-rw-r--r-- | src/ast/expr.cpp | 16 | ||||
-rw-r--r-- | src/ast/path.cpp | 2 | ||||
-rw-r--r-- | src/ast/path.hpp | 5 | ||||
-rw-r--r-- | src/ast/pattern.cpp | 34 | ||||
-rw-r--r-- | src/ast/pattern.hpp | 8 |
6 files changed, 136 insertions, 10 deletions
diff --git a/src/ast/attrs.hpp b/src/ast/attrs.hpp new file mode 100644 index 00000000..ebbad066 --- /dev/null +++ b/src/ast/attrs.hpp @@ -0,0 +1,81 @@ +#ifndef _AST_ATTRS_HPP_ +#define _AST_ATTRS_HPP_ + + +namespace AST { + +// +class MetaItem; + +class MetaItems: + public Serialisable +{ +public: + ::std::vector<MetaItem> m_items; + + MetaItems() {} + MetaItems(::std::vector<MetaItem> items): + m_items(items) + { + } + + void push_back(MetaItem i); + + MetaItem* get(const char *name); + bool has(const char *name) { + return get(name) != 0; + } + + friend ::std::ostream& operator<<(::std::ostream& os, const MetaItems& x) { + return os << "[" << x.m_items << "]"; + } + + SERIALISABLE_PROTOTYPES(); +}; + +class MetaItem: + public Serialisable +{ + ::std::string m_name; + MetaItems m_sub_items; + ::std::string m_str_val; +public: + MetaItem() {} + MetaItem(::std::string name): + m_name(name) + { + } + MetaItem(::std::string name, ::std::string str_val): + m_name(name), + m_str_val(str_val) + { + } + MetaItem(::std::string name, ::std::vector<MetaItem> items): + m_name(name), + m_sub_items(items) + { + } + + void mark_used() {} + const ::std::string& name() const { return m_name; } + const ::std::string& string() const { return m_str_val; } + bool has_sub_items() const { return m_sub_items.m_items.size() > 0; } + const MetaItems& items() const { return m_sub_items; } + MetaItems& items() { return m_sub_items; } + + friend ::std::ostream& operator<<(::std::ostream& os, const MetaItem& x) { + os << x.m_name; + if(x.m_sub_items.m_items.size()) + os << "(" << x.m_sub_items.m_items << ")"; + else + os << "=\"" << x.m_str_val << "\""; + return os; + } + + SERIALISABLE_PROTOTYPES(); +}; + +} // namespace AST + +#endif + diff --git a/src/ast/expr.cpp b/src/ast/expr.cpp index 48e080d6..dc0eb59f 100644 --- a/src/ast/expr.cpp +++ b/src/ast/expr.cpp @@ -7,15 +7,19 @@ namespace AST { void Expr::visit_nodes(NodeVisitor& v) { - assert(!!m_node); - m_node->visit(v); + if( m_node ) + { + m_node->visit(v); + } } void Expr::visit_nodes(NodeVisitor& v) const { - assert(!!m_node); - assert(v.is_const()); - //const_cast<const ExprNode*>(m_node.get())->visit(v); - m_node->visit(v); + if( m_node ) + { + assert(v.is_const()); + //const_cast<const ExprNode*>(m_node.get())->visit(v); + m_node->visit(v); + } } ::std::ostream& operator<<(::std::ostream& os, const Expr& pat) { diff --git a/src/ast/path.cpp b/src/ast/path.cpp index 9ad36515..5c0510fe 100644 --- a/src/ast/path.cpp +++ b/src/ast/path.cpp @@ -110,7 +110,7 @@ AST::Path::Path(const Path& x): m_class = Class::make_Self({nodes: ent.nodes}); ), (Super, - m_class = Class::make_Super({nodes: ent.nodes}); + m_class = Class::make_Super({count: ent.count, nodes: ent.nodes}); ), (Absolute, m_class = Class::make_Absolute({nodes: ent.nodes}); diff --git a/src/ast/path.hpp b/src/ast/path.hpp index cbe009f9..1260ece3 100644 --- a/src/ast/path.hpp +++ b/src/ast/path.hpp @@ -114,6 +114,7 @@ public: ::std::vector<PathNode> nodes; ) ), (Super, ( // Parent-relative + unsigned int count; ::std::vector<PathNode> nodes; ) ), (Absolute, ( // Absolute @@ -184,8 +185,8 @@ public: {} // SUPER struct TagSuper {}; - Path(TagSuper, ::std::vector<PathNode> nodes): - m_class( Class::make_Super({nodes: nodes}) ) + Path(TagSuper, unsigned int count, ::std::vector<PathNode> nodes): + m_class( Class::make_Super({count: count, nodes: mv$(nodes)}) ) {} void set_crate(::std::string crate) { diff --git a/src/ast/pattern.cpp b/src/ast/pattern.cpp index 7ebdb35d..35df2a1e 100644 --- a/src/ast/pattern.cpp +++ b/src/ast/pattern.cpp @@ -43,6 +43,30 @@ namespace AST { ), (Struct, os << ent.path << " {" << ent.sub_patterns << "}"; + ), + (Slice, + os << "["; + bool needs_comma = false; + if(ent.leading.size()) { + os << ent.leading; + needs_comma = true; + } + if(ent.extra_bind.size() > 0) { + if( needs_comma ) { + os << ", "; + } + if(ent.extra_bind != "_") + os << ent.extra_bind; + os << ".."; + needs_comma = true; + } + if(ent.trailing.size()) { + if( needs_comma ) { + os << ", "; + } + os << ent.trailing; + } + os << "]"; ) ) os << ")"; @@ -89,6 +113,11 @@ SERIALISE_TYPE(Pattern::, "Pattern", { (Struct, s << e.path; s << e.sub_patterns; + ), + (Slice, + s << e.leading; + s << e.extra_bind; + s << e.trailing; ) ) },{ @@ -125,6 +154,11 @@ SERIALISE_TYPE(Pattern::, "Pattern", { s.item( ent.path ); s.item( ent.sub_patterns ); ) + _D(Slice, + s.item( ent.leading ); + s.item( ent.extra_bind ); + s.item( ent.trailing ); + ) } }); diff --git a/src/ast/pattern.hpp b/src/ast/pattern.hpp index 6cd78e91..ce4844f9 100644 --- a/src/ast/pattern.hpp +++ b/src/ast/pattern.hpp @@ -28,7 +28,8 @@ public: (Value, (unique_ptr<ExprNode> start; unique_ptr<ExprNode> end;) ), (Tuple, (::std::vector<Pattern> sub_patterns;) ), (StructTuple, (Path path; ::std::vector<Pattern> sub_patterns;) ), - (Struct, (Path path; ::std::vector< ::std::pair< ::std::string,Pattern> > sub_patterns;) ) + (Struct, (Path path; ::std::vector< ::std::pair< ::std::string,Pattern> > sub_patterns;) ), + (Slice, (::std::vector<Pattern> leading; ::std::string extra_bind; ::std::vector<Pattern> trailing;) ) ); private: ::std::string m_binding; @@ -93,6 +94,11 @@ public: Pattern(TagStruct, Path path, ::std::vector< ::std::pair< ::std::string,Pattern> > sub_patterns): m_data( Data::make_Struct( { ::std::move(path), ::std::move(sub_patterns) } ) ) {} + + struct TagSlice {}; + Pattern(TagSlice): + m_data( Data::make_Slice( {} ) ) + {} // Mutators void set_bind(::std::string name, bool is_ref, bool is_mut) { |