summaryrefslogtreecommitdiff
path: root/src/hir/path.hpp
blob: 584d598bbbe9ca10b6e0c7723c3b3783d5c005d8 (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
81
82
83
84
85
86
87

#ifndef _HIR_PATH_HPP_
#define _HIR_PATH_HPP_
#pragma once

#include <common.hpp>
#include <tagged_union.hpp>
#include <hir/type_ptr.hpp>

namespace HIR {

/// Simple path - Absolute with no generic parameters
struct SimplePath
{
    SimplePath():
        m_crate_name("")
    {
    }
    SimplePath(::std::string crate):
        m_crate_name( mv$(crate) )
    {
    }

    ::std::string   m_crate_name;
    ::std::vector< ::std::string>   m_components;

    
    SimplePath operator+(const ::std::string& s) const;
    friend ::std::ostream& operator<<(::std::ostream& os, const SimplePath& x);
};


struct PathParams
{
    ::std::vector<TypeRef>  m_types;
    
    PathParams();
};

/// Generic path - Simple path with one lot of generic params
class GenericPath
{
public:
    SimplePath  m_path;
    PathParams  m_params;

    GenericPath();
    GenericPath(::HIR::SimplePath sp);
    GenericPath(::HIR::SimplePath sp, ::HIR::PathParams params);
};

class TraitPath
{
public:
    GenericPath m_path;
    ::std::vector< ::std::string>   m_hrls;
};

class Path
{
public:
    // Two possibilities
    // - UFCS
    // - Generic path
    TAGGED_UNION(Data, Generic,
    (Generic, GenericPath),
    (UFCS, struct {
        TypeRefPtr  type;
        GenericPath trait;
        ::std::string   item;
        PathParams  params;
        })
    );

private:
    Data m_data;

public:
    Path(GenericPath _);
    Path(TypeRefPtr type, GenericPath trait, ::std::string item, PathParams params);
    Path(SimplePath _);
};

}   // namespace HIR

#endif