blob: ccc1e614f940cf0906840d3d3a228339476e56e4 (
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
// Copyright (C) 2025 Free Software Foundation, Inc.
// This file is part of GCC.
// GCC is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3, or (at your option) any later
// version.
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
// You should have received a copy of the GNU General Public License
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include "rust-system.h"
#include "optional.h"
#include "rust-lang-item.h"
#include "rust-mapping-common.h"
#include <ast/rust-ast-full-decls.h>
namespace Rust {
/*
* Used to convert different path segment object references
* into SimplePathSegment/PathIdentSegment references
*
* unwrap_type_segment:
* expands to a call to unwrap_type_segment_inner::unwrap,
* used for type inference
*/
#define unwrap_type_segment(x) \
(unwrap_type_segment_inner<typename std::remove_const< \
typename std::remove_reference<decltype (x)>::type>::type>::unwrap (x))
template <class T> class unwrap_type_segment_inner;
/* base case */
template <> class unwrap_type_segment_inner<AST::SimplePathSegment>
{
public:
/* The return type of unwrap */
using ret = AST::SimplePathSegment;
/* non-const qualified unwrap */
static AST::SimplePathSegment &unwrap (AST::SimplePathSegment &x)
{
return x;
}
/* const qualified unwrap */
static const AST::SimplePathSegment &unwrap (const AST::SimplePathSegment &x)
{
return x;
}
};
/* case which dereferences unique_ptr */
template <class T> class unwrap_type_segment_inner<std::unique_ptr<T>>
{
public:
using ret = typename unwrap_type_segment_inner<T>::ret;
static ret &unwrap (std::unique_ptr<T> &x)
{
return unwrap_type_segment (*x);
}
static const ret &unwrap (const std::unique_ptr<T> &x)
{
return unwrap_type_segment (*x);
}
};
/* case which handles objects with a get_ident_segment member function */
template <class T> class unwrap_type_segment_inner
{
public:
using ret = AST::PathIdentSegment;
static ret &unwrap (T &x) { return x.get_ident_segment (); }
static const ret &unwrap (const T &x) { return x.get_ident_segment (); }
};
/*
* Used to get the node id of a path segment object
*/
NodeId unwrap_segment_node_id (const AST::TypePathSegment &seg);
NodeId unwrap_segment_node_id (const AST::SimplePathSegment &seg);
NodeId unwrap_segment_node_id (const AST::PathExprSegment &seg);
template <class T>
NodeId
unwrap_segment_node_id (const std::unique_ptr<T> &ptr)
{
return unwrap_segment_node_id (*ptr);
}
/**
* Used to check if a path segment is associated with a lang item
*/
tl::optional<LangItem::Kind>
unwrap_segment_get_lang_item (const AST::TypePathSegment &seg);
tl::optional<LangItem::Kind>
unwrap_segment_get_lang_item (const AST::SimplePathSegment &seg);
tl::optional<LangItem::Kind>
unwrap_segment_get_lang_item (const AST::PathExprSegment &seg);
template <class T>
tl::optional<LangItem::Kind>
unwrap_segment_get_lang_item (const std::unique_ptr<T> &ptr)
{
return unwrap_segment_get_lang_item (*ptr);
}
/**
* Used to output a path in error messages
*/
inline static std::string
unwrap_segment_error_string (const AST::TypePath &path)
{
return path.make_debug_string ();
}
inline static std::string
unwrap_segment_error_string (const AST::PathInExpression &path)
{
return path.as_simple_path ().as_string ();
}
} // namespace Rust
|