summaryrefslogtreecommitdiff
path: root/src/ast/item.hpp
blob: 22fd44c9148f6a207c9455ba69cd70810568dd2b (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

#pragma once

#include <string>
#include <serialise.hpp>

namespace AST {

template <typename T>
struct NamedNS
{
    ::std::string   name;
    T   data;
    bool    is_pub;
    
    NamedNS():
        is_pub(false)
    {}
    NamedNS(NamedNS&&) = default;
    NamedNS(const NamedNS&) = default;
    NamedNS(::std::string name, T data, bool is_pub):
        name( ::std::move(name) ),
        data( ::std::move(data) ),
        is_pub( is_pub )
    {
    }
    
    //friend ::std::ostream& operator<<(::std::ostream& os, const Named& i) {
    //    return os << (i.is_pub ? "pub " : " ") << i.name << ": " << i.data;
    //}
};

template <typename T>
struct Named:
    public NamedNS<T>,
    public Serialisable
{
    Named():
        NamedNS<T>()
    {}
    Named(Named&&) = default;
    Named(const Named&) = default;
    Named(::std::string name, T data, bool is_pub):
        NamedNS<T>( ::std::move(name), ::std::move(data), is_pub )
    {}
    SERIALISE_TYPE_A(, "Named", {
        s.item(this->name);
        s.item(this->data);
        s.item(this->is_pub);
    })
};

template <typename T>
using NamedList = ::std::vector<Named<T> >;

}   // namespace AST