Skip to content

Commit 87aeea2

Browse files
committed
Refactor lang item mappings enum into its own header
1 parent 265c223 commit 87aeea2

File tree

2 files changed

+295
-269
lines changed

2 files changed

+295
-269
lines changed

gcc/rust/util/rust-hir-map.h

Lines changed: 1 addition & 269 deletions
Original file line numberDiff line numberDiff line change
@@ -25,279 +25,11 @@
2525
#include "rust-canonical-path.h"
2626
#include "rust-ast-full-decls.h"
2727
#include "rust-hir-full-decls.h"
28-
#include "operator.h"
28+
#include "rust-lang-item.h"
2929

3030
namespace Rust {
3131
namespace Analysis {
3232

33-
// https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
34-
class RustLangItem
35-
{
36-
public:
37-
enum ItemType
38-
{
39-
ADD,
40-
SUBTRACT,
41-
MULTIPLY,
42-
DIVIDE,
43-
REMAINDER,
44-
BITAND,
45-
BITOR,
46-
BITXOR,
47-
SHL,
48-
SHR,
49-
50-
NEGATION,
51-
NOT,
52-
53-
ADD_ASSIGN,
54-
SUB_ASSIGN,
55-
MUL_ASSIGN,
56-
DIV_ASSIGN,
57-
REM_ASSIGN,
58-
BITAND_ASSIGN,
59-
BITOR_ASSIGN,
60-
BITXOR_ASSIGN,
61-
SHL_ASSIGN,
62-
SHR_ASSIGN,
63-
64-
DEREF,
65-
DEREF_MUT,
66-
67-
UNKNOWN,
68-
};
69-
70-
static ItemType Parse (const std::string &item)
71-
{
72-
if (item.compare ("add") == 0)
73-
{
74-
return ItemType::ADD;
75-
}
76-
else if (item.compare ("sub") == 0)
77-
{
78-
return ItemType::SUBTRACT;
79-
}
80-
else if (item.compare ("mul") == 0)
81-
{
82-
return ItemType::MULTIPLY;
83-
}
84-
else if (item.compare ("div") == 0)
85-
{
86-
return ItemType::DIVIDE;
87-
}
88-
else if (item.compare ("rem") == 0)
89-
{
90-
return ItemType::REMAINDER;
91-
}
92-
else if (item.compare ("bitand") == 0)
93-
{
94-
return ItemType::BITAND;
95-
}
96-
else if (item.compare ("bitor") == 0)
97-
{
98-
return ItemType::BITOR;
99-
}
100-
else if (item.compare ("bitxor") == 0)
101-
{
102-
return ItemType::BITXOR;
103-
}
104-
else if (item.compare ("shl") == 0)
105-
{
106-
return ItemType::SHL;
107-
}
108-
else if (item.compare ("shr") == 0)
109-
{
110-
return ItemType::SHR;
111-
}
112-
else if (item.compare ("neg") == 0)
113-
{
114-
return ItemType::NEGATION;
115-
}
116-
else if (item.compare ("not") == 0)
117-
{
118-
return ItemType::NOT;
119-
}
120-
else if (item.compare ("add_assign") == 0)
121-
{
122-
return ItemType::ADD_ASSIGN;
123-
}
124-
else if (item.compare ("sub_assign") == 0)
125-
{
126-
return ItemType::SUB_ASSIGN;
127-
}
128-
else if (item.compare ("mul_assign") == 0)
129-
{
130-
return ItemType::MUL_ASSIGN;
131-
}
132-
else if (item.compare ("div_assign") == 0)
133-
{
134-
return ItemType::DIV_ASSIGN;
135-
}
136-
else if (item.compare ("rem_assign") == 0)
137-
{
138-
return ItemType::REM_ASSIGN;
139-
}
140-
else if (item.compare ("bitand_assign") == 0)
141-
{
142-
return ItemType::BITAND_ASSIGN;
143-
}
144-
else if (item.compare ("bitor_assign") == 0)
145-
{
146-
return ItemType::BITOR_ASSIGN;
147-
}
148-
else if (item.compare ("bitxor_assign") == 0)
149-
{
150-
return ItemType::BITXOR_ASSIGN;
151-
}
152-
else if (item.compare ("shl_assign") == 0)
153-
{
154-
return ItemType::SHL_ASSIGN;
155-
}
156-
else if (item.compare ("shr_assign") == 0)
157-
{
158-
return ItemType::SHR_ASSIGN;
159-
}
160-
else if (item.compare ("deref") == 0)
161-
{
162-
return ItemType::DEREF;
163-
}
164-
else if (item.compare ("deref_mut") == 0)
165-
{
166-
return ItemType::DEREF_MUT;
167-
}
168-
169-
return ItemType::UNKNOWN;
170-
}
171-
172-
static std::string ToString (ItemType type)
173-
{
174-
switch (type)
175-
{
176-
case ADD:
177-
return "add";
178-
case SUBTRACT:
179-
return "sub";
180-
case MULTIPLY:
181-
return "mul";
182-
case DIVIDE:
183-
return "div";
184-
case REMAINDER:
185-
return "rem";
186-
case BITAND:
187-
return "bitand";
188-
case BITOR:
189-
return "bitor";
190-
case BITXOR:
191-
return "bitxor";
192-
case SHL:
193-
return "shl";
194-
case SHR:
195-
return "shr";
196-
case NEGATION:
197-
return "neg";
198-
case NOT:
199-
return "not";
200-
case ADD_ASSIGN:
201-
return "add_assign";
202-
case SUB_ASSIGN:
203-
return "sub_assign";
204-
case MUL_ASSIGN:
205-
return "mul_assign";
206-
case DIV_ASSIGN:
207-
return "div_assign";
208-
case REM_ASSIGN:
209-
return "rem_assign";
210-
case BITAND_ASSIGN:
211-
return "bitand_assign";
212-
case BITOR_ASSIGN:
213-
return "bitor_assign";
214-
case BITXOR_ASSIGN:
215-
return "bitxor_assign";
216-
case SHL_ASSIGN:
217-
return "shl_assign";
218-
case SHR_ASSIGN:
219-
return "shr_assign";
220-
case DEREF:
221-
return "deref";
222-
case DEREF_MUT:
223-
return "deref_mut";
224-
225-
case UNKNOWN:
226-
return "<UNKNOWN>";
227-
}
228-
return "<UNKNOWN>";
229-
}
230-
231-
static ItemType OperatorToLangItem (ArithmeticOrLogicalOperator op)
232-
{
233-
switch (op)
234-
{
235-
case ArithmeticOrLogicalOperator::ADD:
236-
return ItemType::ADD;
237-
case ArithmeticOrLogicalOperator::SUBTRACT:
238-
return ItemType::SUBTRACT;
239-
case ArithmeticOrLogicalOperator::MULTIPLY:
240-
return ItemType::MULTIPLY;
241-
case ArithmeticOrLogicalOperator::DIVIDE:
242-
return ItemType::DIVIDE;
243-
case ArithmeticOrLogicalOperator::MODULUS:
244-
return ItemType::REMAINDER;
245-
case ArithmeticOrLogicalOperator::BITWISE_AND:
246-
return ItemType::BITAND;
247-
case ArithmeticOrLogicalOperator::BITWISE_OR:
248-
return ItemType::BITOR;
249-
case ArithmeticOrLogicalOperator::BITWISE_XOR:
250-
return ItemType::BITXOR;
251-
case ArithmeticOrLogicalOperator::LEFT_SHIFT:
252-
return ItemType::SHL;
253-
case ArithmeticOrLogicalOperator::RIGHT_SHIFT:
254-
return ItemType::SHR;
255-
}
256-
return ItemType::UNKNOWN;
257-
}
258-
259-
static ItemType
260-
CompoundAssignmentOperatorToLangItem (ArithmeticOrLogicalOperator op)
261-
{
262-
switch (op)
263-
{
264-
case ArithmeticOrLogicalOperator::ADD:
265-
return ItemType::ADD_ASSIGN;
266-
case ArithmeticOrLogicalOperator::SUBTRACT:
267-
return ItemType::SUB_ASSIGN;
268-
case ArithmeticOrLogicalOperator::MULTIPLY:
269-
return ItemType::MUL_ASSIGN;
270-
case ArithmeticOrLogicalOperator::DIVIDE:
271-
return ItemType::DIV_ASSIGN;
272-
case ArithmeticOrLogicalOperator::MODULUS:
273-
return ItemType::REM_ASSIGN;
274-
case ArithmeticOrLogicalOperator::BITWISE_AND:
275-
return ItemType::BITAND_ASSIGN;
276-
case ArithmeticOrLogicalOperator::BITWISE_OR:
277-
return ItemType::BITOR_ASSIGN;
278-
case ArithmeticOrLogicalOperator::BITWISE_XOR:
279-
return ItemType::BITXOR_ASSIGN;
280-
case ArithmeticOrLogicalOperator::LEFT_SHIFT:
281-
return ItemType::SHL_ASSIGN;
282-
case ArithmeticOrLogicalOperator::RIGHT_SHIFT:
283-
return ItemType::SHR_ASSIGN;
284-
}
285-
return ItemType::UNKNOWN;
286-
}
287-
288-
static ItemType NegationOperatorToLangItem (NegationOperator op)
289-
{
290-
switch (op)
291-
{
292-
case NegationOperator::NEGATE:
293-
return ItemType::NEGATION;
294-
case NegationOperator::NOT:
295-
return ItemType::NOT;
296-
}
297-
return ItemType::UNKNOWN;
298-
}
299-
};
300-
30133
class NodeMapping
30234
{
30335
public:

0 commit comments

Comments
 (0)