summaryrefslogtreecommitdiff
path: root/src/ast/crate.hpp
blob: 24106bfa79425875719a8acb5e799f630a3ee5f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

#pragma once

#include "ast.hpp"
#include "types.hpp"

namespace AST {


class ExternCrate;

class Crate:
    public Serialisable
{
public:
    ::std::map< TypeRef, ::std::vector<Impl*> >  m_impl_map;
    ::std::vector<Impl*>    m_impl_index;
    ::std::vector<const ImplDef*> m_neg_impl_index;

    ::AST::MetaItems    m_attrs;
    
    ::std::map< ::std::string, ::AST::Path> m_lang_items;
public:
    Module  m_root_module;
    ::std::map< ::std::string, ExternCrate> m_extern_crates;
    // Mapping filled by searching for (?visible) macros with is_pub=true
    ::std::map< ::std::string, const MacroRules*> m_exported_macros;
    
    enum LoadStd {
        LOAD_STD,
        LOAD_CORE,
        LOAD_NONE,
    } m_load_std;
    AST::Path   m_prelude_path;

    Crate();

    Module& root_module() { return m_root_module; }
    Module& get_root_module(const ::std::string& name);
    ::std::map< ::std::string, ExternCrate>& extern_crates() { return m_extern_crates; }   
    
    const Module& root_module() const { return m_root_module; }
    const Module& get_root_module(const ::std::string& name) const;
    const ::std::map< ::std::string, ExternCrate>& extern_crates() const { return m_extern_crates; }   
 
    /// Load referenced crates
    void load_externs();
    
    void load_extern_crate(::std::string name);
    
    SERIALISABLE_PROTOTYPES();
};

/// Representation of an imported crate
/// - Functions are stored as resolved+typechecked ASTs
class ExternCrate:
    public Serialisable
{
    ::std::map< ::std::string, MacroRulesPtr > m_mr_macros;
    
    //::MIR::Module   m_root_module;
    
    //Crate   m_crate;
public:
    ExternCrate();
    ExternCrate(const char *path);
    ExternCrate(const ExternCrate&) = delete;
    ExternCrate(ExternCrate&&) = default;
    
    const MacroRules* find_macro_rules(const ::std::string& name);
    
    //Crate& crate() { return m_crate; }
    //const Crate& crate() const { return m_crate; }
    //Module& root_module() { return m_crate.root_module(); }
    //const Module& root_module() const { return m_crate.root_module(); }
    
    SERIALISABLE_PROTOTYPES();
};

}   // namespace AST