summaryrefslogtreecommitdiff
path: root/src/expand/std_prelude.cpp
blob: 4499dc6d6badb1edc5a2322a588597c80c8f1041 (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
/*
 */
#include <synext.hpp>
#include <ast/crate.hpp>

class Decorator_NoStd:
    public ExpandDecorator
{
public:
    AttrStage stage() const override { return AttrStage::Pre; }
    
    void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate) const override {
        if( crate.m_load_std != AST::Crate::LOAD_STD ) {
            ERROR(sp, E0000, "Invalid use of #![no_std] with itself or #![no_core]");
        }
        crate.m_load_std = AST::Crate::LOAD_CORE;
    }
};
class Decorator_NoCore:
    public ExpandDecorator
{
public:
    AttrStage stage() const override { return AttrStage::Pre; }
    
    void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate) const override {
        if( crate.m_load_std != AST::Crate::LOAD_STD ) {
            ERROR(sp, E0000, "Invalid use of #![no_core] with itself or #![no_std]");
        }
        crate.m_load_std = AST::Crate::LOAD_NONE;
    }
};
//class Decorator_Prelude:
//    public ExpandDecorator
//{
//public:
//    AttrStage stage() const override { return AttrStage::Pre; }
//};

class Decorator_NoPrelude:
    public ExpandDecorator
{
public:
    AttrStage stage() const override { return AttrStage::Pre; }
    
    void handle(const Span& sp, const AST::MetaItem& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override {
        if( i.is_Module() ) {
            i.as_Module().m_insert_prelude = false;
        }
        else {
            ERROR(sp, E0000, "Invalid use of #[no_prelude] on non-module");
        }
    }
};



STATIC_DECORATOR("no_std", Decorator_NoStd)
STATIC_DECORATOR("no_core", Decorator_NoCore)
//STATIC_DECORATOR("prelude", Decorator_Prelude)

STATIC_DECORATOR("no_prelude", Decorator_NoPrelude)