summaryrefslogtreecommitdiff
path: root/src/ast/macro.hpp
blob: 5cd53e1f9f75ca3420cd4a71878ecd84ad5b2c14 (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

#ifndef _AST_MACRO_HPP_
#define _AST_MACRO_HPP_

#include "../parse/tokentree.hpp"
#include <span.hpp>
#include "attrs.hpp"

namespace AST {

class MacroInvocation:
    public Serialisable
{
    Span    m_span;
    
    ::AST::MetaItems   m_attrs;
    ::std::string   m_macro_name;
    ::std::string   m_ident;
    TokenTree   m_input;
public:
    MacroInvocation(MacroInvocation&&) = default;
    MacroInvocation& operator=(MacroInvocation&&) = default;
    MacroInvocation(const MacroInvocation&) = delete;
    MacroInvocation& operator=(const MacroInvocation&) = delete;
    
    MacroInvocation()
    {
    }
    
    MacroInvocation(Span span, MetaItems attrs, ::std::string macro, ::std::string ident, TokenTree input):
        m_span( mv$(span) ),
        m_attrs( mv$(attrs) ),
        m_macro_name( mv$(macro) ),
        m_ident( mv$(ident) ),
        m_input( mv$(input) )
    {
    }
    
    MacroInvocation clone() const;

    static ::std::unique_ptr<MacroInvocation> from_deserialiser(Deserialiser& s) {
        auto i = new MacroInvocation;
        s.item( *i );
        return ::std::unique_ptr<MacroInvocation>(i);
    }

    void clear() {
        m_macro_name = "";
        m_ident = "";
        m_input = TokenTree();
    }
    
          ::AST::MetaItems& attrs()       { return m_attrs; }
    const ::AST::MetaItems& attrs() const { return m_attrs; }

    const Span& span() const { return m_span; }
    const ::std::string& name() const { return m_macro_name; }

    const ::std::string& input_ident() const { return m_ident; }
    const TokenTree& input_tt() const { return m_input; }


    SERIALISABLE_PROTOTYPES();
    
    friend ::std::ostream& operator<<(::std::ostream& os, const MacroInvocation& x) {
        os << x.m_attrs;
        if(x.m_attrs.m_items.size() > 0)
            os << " ";
        os << x.m_macro_name << "! " << x.m_ident << x.m_input;
        return os;
    }
};


}

#endif