summaryrefslogtreecommitdiff
path: root/src/resolve
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-04-30 22:46:29 +0800
committerJohn Hodge <tpg@mutabah.net>2016-04-30 22:46:29 +0800
commitd296771ea7229a62ee26e818aea483456bc64187 (patch)
tree268bd4d3aff80d21fdf93c30ceba9c3f7ba4b73c /src/resolve
parent756abd3f2fd768e73a014e190c7a446a3f5aa44c (diff)
downloadmrust-d296771ea7229a62ee26e818aea483456bc64187.tar.gz
Resolve - Fleshing out absolute
Diffstat (limited to 'src/resolve')
-rw-r--r--src/resolve/absolute.cpp134
-rw-r--r--src/resolve/index.cpp3
2 files changed, 135 insertions, 2 deletions
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp
index dd0c5f0d..c965d2ee 100644
--- a/src/resolve/absolute.cpp
+++ b/src/resolve/absolute.cpp
@@ -1,16 +1,148 @@
/*
* Convert all paths in AST into absolute form (or to the relevant local item)
+ * - NOTE: This is the core of the 'resolve' pass.
*
* After complete there should be no:
* - Relative/super/self paths
* - MaybeBind patterns
*/
#include <ast/crate.hpp>
+#include <ast/ast.hpp>
#include <main_bindings.hpp>
+struct GenericSlot
+{
+ enum class Level
+ {
+ Impl,
+ Function,
+ } level;
+ unsigned short index;
+};
+template<typename Val>
+struct Named
+{
+ ::std::string name;
+ Val value;
+};
+
+struct Context
+{
+ TAGGED_UNION(Ent, Module,
+ (Module, struct {
+ const ::AST::Module* mod;
+ }),
+ (VarBlock, struct {
+ // "Map" of names to function-level variable slots
+ ::std::vector< Named< unsigned int > > variables;
+ }),
+ (Generic, struct {
+ // Map of names to slots
+ ::std::vector< Named< GenericSlot > > types;
+ ::std::vector< Named< GenericSlot > > constants;
+ ::std::vector< Named< GenericSlot > > lifetimes;
+ })
+ );
+
+ const ::AST::Module& m_mod;
+ ::std::vector<Ent> m_name_context;
+
+ Context(const::AST::Module& mod):
+ m_mod(mod)
+ {}
+};
+
+void Resolve_Absolute_Type(const ::AST::Crate& crate, const Context& context, TypeRef& type)
+{
+ TU_MATCH(TypeData, (type.m_data), (e),
+ (None,
+ // ! type
+ ),
+ (Any,
+ // _ type
+ ),
+ (Unit,
+ ),
+ (Macro,
+ BUG(Span(), "Resolve_Absolute_Type - Encountered an unexpanded macro");
+ ),
+ (Primitive,
+ ),
+ (Function,
+ TODO(Span(), "Resolve_Absolute_Type - Function - " << type);
+ ),
+ (Tuple,
+ for(auto& t : e.inner_types)
+ Resolve_Absolute_Type(crate, context, t);
+ ),
+ (Borrow,
+ Resolve_Absolute_Type(crate, context, *e.inner);
+ ),
+ (Pointer,
+ Resolve_Absolute_Type(crate, context, *e.inner);
+ ),
+ (Array,
+ Resolve_Absolute_Type(crate, context, *e.inner);
+ ),
+ (Generic,
+ TODO(Span(), "Resolve_Absolute_Type - Encountered generic");
+ ),
+ (Path,
+ TODO(Span(), "Resolve_Absolute_Type - Path");
+ ),
+ (TraitObject,
+ TODO(Span(), "Resolve_Absolute_Type - TraitObject");
+ )
+ )
+}
+
+void Resolve_Absolute_Expr(const ::AST::Crate& crate, const Context& context, ::AST::Expr& expr)
+{
+ if( expr.is_valid() )
+ {
+ TODO(Span(), "Resolve_Absolute_Expr");
+ }
+}
+
+void Resolve_Absolute_Mod(const ::AST::Crate& crate, ::AST::Module& mod)
+{
+ for( auto& i : mod.items() )
+ {
+ TU_MATCH(AST::Item, (i.data), (e),
+ (None,
+ ),
+ (Module,
+ Resolve_Absolute_Mod(crate, e);
+ ),
+ (Crate,
+ // - Nothing
+ ),
+ (Enum,
+ TODO(Span(), "Resolve_Absolute_Mod - Enum");
+ ),
+ (Trait,
+ TODO(Span(), "Resolve_Absolute_Mod - Trait");
+ ),
+ (Type,
+ TODO(Span(), "Resolve_Absolute_Mod - Type");
+ ),
+ (Struct,
+ TODO(Span(), "Resolve_Absolute_Mod - Struct");
+ ),
+ (Function,
+ TODO(Span(), "Resolve_Absolute_Mod - Function");
+ ),
+ (Static,
+ Resolve_Absolute_Type( crate, Context(mod), e.type() );
+ Resolve_Absolute_Expr( crate, Context(mod), e.value() );
+ )
+ )
+ }
+}
+
void Resolve_Absolutise(AST::Crate& crate)
{
- TODO(Span(), "Run 'absolutise' resolve pass");
+ Resolve_Absolute_Mod(crate, crate.root_module());
}
diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp
index cb4ffc6b..b5fdbf33 100644
--- a/src/resolve/index.cpp
+++ b/src/resolve/index.cpp
@@ -59,7 +59,8 @@ void Resolve_Index_Module_Base(AST::Module& mod)
// - Mixed
(Struct,
_add_item_type(mod, i.name, i.is_pub, ::AST::PathBinding::make_Struct({&e}));
- if( e.m_data.is_Struct() ) {
+ // - If the struct is a tuple-like struct, it presents in the value namespace
+ if( e.m_data.is_Tuple() ) {
_add_item_value(mod, i.name, i.is_pub, ::AST::PathBinding::make_Struct({&e}));
}
),