summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-03-15 21:32:48 +0800
committerJohn Hodge <tpg@mutabah.net>2016-03-15 21:32:48 +0800
commit124cf9fc5fb6c0b7f70ef94382efd5190019edac (patch)
tree3e2b3e42e49b51d8ddcb0c52616e201b18b2a23e /src
parent9a3987bb1575c4ab1eae9c065e907773fa3dcf17 (diff)
downloadmrust-124cf9fc5fb6c0b7f70ef94382efd5190019edac.tar.gz
Expand - More attribute handling
Diffstat (limited to 'src')
-rw-r--r--src/ast/ast.hpp2
-rw-r--r--src/ast/expr.cpp2
-rw-r--r--src/ast/expr.hpp28
-rw-r--r--src/expand/mod.cpp11
-rw-r--r--src/include/synext.hpp23
-rw-r--r--src/parse/expr.cpp4
6 files changed, 40 insertions, 30 deletions
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp
index ed6ad07b..c05e7aa4 100644
--- a/src/ast/ast.hpp
+++ b/src/ast/ast.hpp
@@ -44,6 +44,7 @@ enum eItemType
};
typedef Named<TypeRef> StructItem;
+
class Crate;
class TypeAlias:
@@ -321,6 +322,7 @@ class Impl:
{
ImplDef m_def;
+ //NamedList<Item> m_items;
NamedList<TypeRef> m_types;
NamedList<Function> m_functions;
NamedList<Static> m_statics;
diff --git a/src/ast/expr.cpp b/src/ast/expr.cpp
index 104c6094..0c40c741 100644
--- a/src/ast/expr.cpp
+++ b/src/ast/expr.cpp
@@ -237,7 +237,7 @@ NODE(ExprNode_Loop, {
//os << "LOOP [" << m_label << "] " << m_pattern << " in/= " << m_cond << " " << m_code;
})
-SERIALISE_TYPE_A(ExprNode_Match::Arm::, "ExprNode_Match_Arm", {
+SERIALISE_TYPE_A(ExprNode_Match_Arm::, "ExprNode_Match_Arm", {
s.item(m_patterns);
s.item(m_cond);
s.item(m_code);
diff --git a/src/ast/expr.hpp b/src/ast/expr.hpp
index 214be267..19b7cddc 100644
--- a/src/ast/expr.hpp
+++ b/src/ast/expr.hpp
@@ -236,26 +236,26 @@ struct ExprNode_Loop:
NODE_METHODS();
};
-struct ExprNode_Match:
- public ExprNode
+struct ExprNode_Match_Arm:
+ public Serialisable
{
- struct Arm:
- public Serialisable
- {
- MetaItems m_attrs;
- ::std::vector<Pattern> m_patterns;
- unique_ptr<ExprNode> m_cond;
-
- unique_ptr<ExprNode> m_code;
+ MetaItems m_attrs;
+ ::std::vector<Pattern> m_patterns;
+ unique_ptr<ExprNode> m_cond;
- SERIALISABLE_PROTOTYPES();
- };
+ unique_ptr<ExprNode> m_code;
+
+ SERIALISABLE_PROTOTYPES();
+};
+struct ExprNode_Match:
+ public ExprNode
+{
unique_ptr<ExprNode> m_val;
- ::std::vector<Arm> m_arms;
+ ::std::vector<ExprNode_Match_Arm> m_arms;
ExprNode_Match() {}
- ExprNode_Match(unique_ptr<ExprNode> val, ::std::vector<Arm> arms):
+ ExprNode_Match(unique_ptr<ExprNode> val, ::std::vector<ExprNode_Match_Arm> arms):
m_val( ::std::move(val) ),
m_arms( ::std::move(arms) )
{
diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp
index 2f936f1f..0c9fb487 100644
--- a/src/expand/mod.cpp
+++ b/src/expand/mod.cpp
@@ -179,7 +179,10 @@ void Expand_Type(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> m
(Primitive,
),
(Function,
- TODO(ty.span(), "Expand function type " << ty);
+ Type_Function& tf = e.info;
+ Expand_Type(is_early, crate, modstack, mod, *tf.m_rettype);
+ for(auto& st : tf.m_arg_types)
+ Expand_Type(is_early, crate, modstack, mod, st);
),
(Tuple,
for(auto& st : e.inner_types)
@@ -470,7 +473,10 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> mo
),
(Struct,
- // TODO: Struct items
+ for(auto& fld : e.e.fields()) {
+ // TODO: Attributes on struct items
+ Expand_Type(is_early, crate, modstack, mod, fld.data);
+ }
),
(Enum,
// TODO: Enum variants
@@ -504,6 +510,7 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> mo
for( auto& i : mod.impls() )
{
DEBUG("- " << i);
+ // TODO: Expand impls
}
for( const auto& mi: mod.macro_imports_res() )
diff --git a/src/include/synext.hpp b/src/include/synext.hpp
index aa72e985..58b4f608 100644
--- a/src/include/synext.hpp
+++ b/src/include/synext.hpp
@@ -7,16 +7,21 @@
#include "../ast/item.hpp"
#include <span.hpp>
+class TypeRef;
namespace AST {
class Crate;
class MetaItem;
class Path;
+
+// class StructItem;
+ typedef Named<::TypeRef> StructItem;
class Module;
class Item;
- class ExprNode;
class Expr;
+ class ExprNode;
+ class ExprNode_Match_Arm;
class MacroInvocation;
}
@@ -44,16 +49,12 @@ public:
virtual void handle(const AST::MetaItem& mi, AST::Crate& crate) const {}
virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, AST::MacroInvocation& mac) const {}
virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const {}
- virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::std::unique_ptr<AST::ExprNode>& expr) const {};
-};
-
-enum class MacroPosition
-{
- Item,
- Stmt,
- Expr,
- Type,
- Pattern,
+ // NOTE: To delete, set the type to Invalid
+ virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::AST::StructItem& si) const {}
+
+ virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::std::unique_ptr<AST::ExprNode>& expr) const {}
+ // NOTE: To delete, clear the patterns vector
+ virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::AST::ExprNode_Match_Arm& expr) const {}
};
class ExpandProcMacro
diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp
index ee5698e8..58c82a0b 100644
--- a/src/parse/expr.cpp
+++ b/src/parse/expr.cpp
@@ -340,12 +340,12 @@ ExprNodeP Parse_Expr_Match(TokenStream& lex)
//ASSERT(lex, !CHECK_PARSE_FLAG(lex, disallow_struct_literal) );
GET_CHECK_TOK(tok, lex, TOK_BRACE_OPEN);
- ::std::vector< AST::ExprNode_Match::Arm > arms;
+ ::std::vector< AST::ExprNode_Match_Arm > arms;
do {
if( GET_TOK(tok, lex) == TOK_BRACE_CLOSE )
break;
lex.putback(tok);
- AST::ExprNode_Match::Arm arm;
+ AST::ExprNode_Match_Arm arm;
::AST::MetaItems arm_attrs;
while( LOOK_AHEAD(lex) == TOK_ATTR_OPEN ) {