diff options
Diffstat (limited to 'src/convert')
| -rw-r--r-- | src/convert/ast_iterate.cpp | 80 | ||||
| -rw-r--r-- | src/convert/ast_iterate.hpp | 2 | ||||
| -rw-r--r-- | src/convert/decorators.cpp | 1 | ||||
| -rw-r--r-- | src/convert/resolve.cpp | 49 | ||||
| -rw-r--r-- | src/convert/typecheck_bounds.cpp | 1 | ||||
| -rw-r--r-- | src/convert/typecheck_expr.cpp | 2 | ||||
| -rw-r--r-- | src/convert/typecheck_params.cpp | 1 |
7 files changed, 81 insertions, 55 deletions
diff --git a/src/convert/ast_iterate.cpp b/src/convert/ast_iterate.cpp index 2e1dfe23..2a910692 100644 --- a/src/convert/ast_iterate.cpp +++ b/src/convert/ast_iterate.cpp @@ -303,41 +303,49 @@ void CASTIterator::handle_module(AST::Path path, AST::Module& mod) INDENT(); start_scope(); - for( auto& item : mod.structs() ) + for( auto& item : mod.items() ) { - DEBUG("Handling struct " << item.name); - handle_struct(path + item.name, item.data); - } - for( auto& item : mod.enums() ) - { - DEBUG("Handling enum " << item.name); - handle_enum(path + item.name, item.data); - } - for( auto& item : mod.traits() ) - { - DEBUG("Handling trait " << item.name); - handle_trait(path + item.name, item.data); - } - for( auto& item : mod.type_aliases() ) - { - DEBUG("Handling alias " << item.name); - handle_alias(path + item.name, item.data); - } - for( auto& stat : mod.statics() ) - { - DEBUG("handling static " << stat.name); - handle_type(stat.data.type()); - if( stat.data.value().is_valid() ) - { - handle_expr(stat.data.value().node()); - } + TU_MATCH(::AST::Item, (item.data), (e), + (None, + // Explicitly ignored (represents a deleted item) + ), + (Crate, + // Nothing to be done + ), + (Struct, + DEBUG("Handling struct " << item.name); + handle_struct(path + item.name, e.e); + ), + (Enum, + DEBUG("Handling enum " << item.name); + handle_enum(path + item.name, e.e); + ), + (Trait, + DEBUG("Handling trait " << item.name); + handle_trait(path + item.name, e.e); + ), + (Type, + DEBUG("Handling alias " << item.name); + handle_alias(path + item.name, e.e); + ), + (Static, + DEBUG("handling static " << item.name); + handle_type(e.e.type()); + if( e.e.value().is_valid() ) + { + handle_expr(e.e.value().node()); + } + ), + (Function, + DEBUG("Handling function '" << item.name << "'"); + handle_function(path + item.name, e.e); + ), + (Module, + // Skip, done after all items + ) + ) } - for( auto& fcn : mod.functions() ) - { - DEBUG("Handling function '" << fcn.name << "'"); - handle_function(path + fcn.name, fcn.data); - } for( auto& impl : mod.impls() ) { DEBUG("Handling 'impl' " << impl); @@ -347,10 +355,12 @@ void CASTIterator::handle_module(AST::Path path, AST::Module& mod) // End scope before handling sub-modules end_scope(); - for( auto& submod : mod.submods() ) + for( auto& item : mod.items() ) { - DEBUG("Handling submod '" << submod.first.name() << "'"); - handle_module(path + submod.first.name(), submod.first); + if(!item.data.is_Module()) continue; + auto& submod = item.data.as_Module().e; + DEBUG("Handling submod '" << item.name << "'"); + handle_module(path + item.name, submod); } unsigned int anon_mod_idx = 0; for( auto& anonmod : mod.anon_mods() ) diff --git a/src/convert/ast_iterate.hpp b/src/convert/ast_iterate.hpp index 3872db58..fc57cf57 100644 --- a/src/convert/ast_iterate.hpp +++ b/src/convert/ast_iterate.hpp @@ -13,7 +13,7 @@ class GenericParams; class Impl; class ImplDef; class EnumVariant; -template<typename T> struct Item; +template<typename T> struct Named; }; diff --git a/src/convert/decorators.cpp b/src/convert/decorators.cpp index 267f9dc7..06716e5f 100644 --- a/src/convert/decorators.cpp +++ b/src/convert/decorators.cpp @@ -7,6 +7,7 @@ */ #include "ast_iterate.hpp" #include "../ast/ast.hpp" +#include "../ast/crate.hpp" #include <main_bindings.hpp> #include <unordered_map> // C++11, hashmap #include <synext.hpp> diff --git a/src/convert/resolve.cpp b/src/convert/resolve.cpp index 20785af5..cd72d27b 100644 --- a/src/convert/resolve.cpp +++ b/src/convert/resolve.cpp @@ -9,6 +9,7 @@ */
#include "../common.hpp"
#include "../ast/ast.hpp"
+#include "../ast/crate.hpp"
#include "../parse/parseerror.hpp"
#include "ast_iterate.hpp"
@@ -161,20 +162,22 @@ private: ret.push_back(t);
}
if( it->module ) {
- for( const auto& t : it->module->traits() ) {
- auto trait_path = it->module_path + t.name;
+ for( const auto& i : it->module->items() ) {
+ if( !i.data.is_Trait() ) continue ;
+ const auto& t = i.data.as_Trait().e;
+ auto trait_path = it->module_path + i.name;
DEBUG("t = " << trait_path);
- ::std::pair<AST::Path, const AST::Trait&> tr(trait_path, t.data);
- ret.push_back( tr );
+ ret.push_back( ::std::pair<AST::Path, const AST::Trait&>(trait_path, t) );
}
}
}
- for( const auto& t : m_module->traits() ) {
- auto trait_path = m_module_path + t.name;
+ for( const auto& i : m_module->items() ) {
+ if( !i.data.is_Trait() ) continue ;
+ const auto& t = i.data.as_Trait().e;
+ auto trait_path = m_module_path + i.name;
DEBUG("(mod) t = " << trait_path);
- ::std::pair<AST::Path, const AST::Trait&> tr(trait_path, t.data);
- ret.push_back( tr );
+ ret.push_back( ::std::pair<AST::Path, const AST::Trait&>(trait_path, t) );
}
for( const auto& i : m_module->imports() ) {
if( i.data.binding().is_Trait() )
@@ -1369,7 +1372,7 @@ bool CPathResolver::find_trait_item(const Span& span, const AST::Path& path, AST {
const auto& fcns = trait.functions();
//DEBUG("fcns = " << fcns);
- auto it = ::std::find_if( fcns.begin(), fcns.end(), [&](const AST::Item<AST::Function>& a) { DEBUG("fcn " << a.name); return a.name == item_name; } );
+ auto it = ::std::find_if( fcns.begin(), fcns.end(), [&](const AST::Named<AST::Function>& a) { DEBUG("fcn " << a.name); return a.name == item_name; } );
if( it != fcns.end() ) {
// Found it.
out_is_method = true;
@@ -1381,7 +1384,7 @@ bool CPathResolver::find_trait_item(const Span& span, const AST::Path& path, AST }
{
const auto& types = trait.types();
- auto it = ::std::find_if( types.begin(), types.end(), [&](const AST::Item<AST::TypeAlias>& a) { DEBUG("type " << a.name); return a.name == item_name; } );
+ auto it = ::std::find_if( types.begin(), types.end(), [&](const AST::Named<AST::TypeAlias>& a) { DEBUG("type " << a.name); return a.name == item_name; } );
if( it != types.end() ) {
// Found it.
out_is_method = false;
@@ -1756,12 +1759,14 @@ void ResolvePaths_HandleModule_Use(const AST::Crate& crate, const AST::Path& mod //if( new_imp.binding().is_Unbound() ) {
// new_imp.resolve(crate, false);
//}
- mod.add_alias(false, new_imp, new_imp[new_imp.size()-1].name());
+ // TODO: Get attributes from the source import
+ mod.add_alias(false, new_imp, new_imp[new_imp.size()-1].name(), ::AST::MetaItems());
}
- for( auto& submod : mod.submods() )
- {
- ResolvePaths_HandleModule_Use(crate, modpath + submod.first.name(), submod.first);
+ for(auto& item : mod.items()) {
+ if( item.data.is_Module() ) {
+ ResolvePaths_HandleModule_Use(crate, modpath + item.name, item.data.as_Module().e);
+ }
}
}
@@ -1776,8 +1781,11 @@ void SetCrateName_Type(const AST::Crate& crate, ::std::string name, TypeRef& typ void SetCrateName_Mod(const AST::Crate& crate, ::std::string name, AST::Module& mod)
{
- for(auto& submod : mod.submods())
- SetCrateName_Mod(crate, name, submod.first);
+ for(auto& item : mod.items()) {
+ if( item.data.is_Module() ) {
+ SetCrateName_Mod(crate, name, item.data.as_Module().e);
+ }
+ }
// Imports 'use' statements
for(auto& imp : mod.imports())
{
@@ -1787,9 +1795,10 @@ void SetCrateName_Mod(const AST::Crate& crate, ::std::string name, AST::Module& }
// TODO: All other types
- for(auto& fcn : mod.functions())
- {
- SetCrateName_Type(crate, name, fcn.data.rettype());
+ for(auto& item : mod.items()) {
+ if( item.data.is_Function() ) {
+ SetCrateName_Type(crate, name, item.data.as_Function().e.rettype());
+ }
}
}
@@ -1801,6 +1810,7 @@ void ResolvePaths(AST::Crate& crate) {
DEBUG(" >>>");
// Pre-process external crates to tag all paths
+ #if 0
DEBUG(" --- Extern crates");
INDENT();
for(auto& ec : crate.extern_crates())
@@ -1808,6 +1818,7 @@ void ResolvePaths(AST::Crate& crate) SetCrateName_Mod(crate, ec.first, ec.second.root_module());
}
UNINDENT();
+ #endif
// Handle 'use' statements in an initial parss
DEBUG(" --- Use Statements");
diff --git a/src/convert/typecheck_bounds.cpp b/src/convert/typecheck_bounds.cpp index 6af5e778..f2cda828 100644 --- a/src/convert/typecheck_bounds.cpp +++ b/src/convert/typecheck_bounds.cpp @@ -2,6 +2,7 @@ */ #include <main_bindings.hpp> #include "ast_iterate.hpp" +#include "../ast/crate.hpp" #include "../common.hpp" #include <stdexcept> diff --git a/src/convert/typecheck_expr.cpp b/src/convert/typecheck_expr.cpp index 69651d7f..1c7099e4 100644 --- a/src/convert/typecheck_expr.cpp +++ b/src/convert/typecheck_expr.cpp @@ -7,6 +7,8 @@ */ #include <main_bindings.hpp> #include "ast_iterate.hpp" +#include "../ast/expr.hpp" +#include "../ast/crate.hpp" #include "../common.hpp" #include <stdexcept> diff --git a/src/convert/typecheck_params.cpp b/src/convert/typecheck_params.cpp index ea6f74c7..2abcc099 100644 --- a/src/convert/typecheck_params.cpp +++ b/src/convert/typecheck_params.cpp @@ -3,6 +3,7 @@ */ #include <main_bindings.hpp> #include "ast_iterate.hpp" +#include "../ast/crate.hpp" #include "../common.hpp" #include <stdexcept> |
