-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrimitiveTypes.cpp
155 lines (145 loc) · 4.02 KB
/
PrimitiveTypes.cpp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// SPDX-License-Identifier: GPL-3.0-only
/**
* @file PrimitiveTypes.cpp
*
* @copyright Copyright (C) 2021-2024 srcML, LLC. (www.srcML.org)
*
* This file is part of the Stereocode application.
*/
#include "PrimitiveTypes.hpp"
extern std::vector<std::string> LANGUAGE;
// Checks if 'type' is a primitive
// User-defined primitives are checked for all languages
//
bool primitiveTypes::isPrimitive(const std::string& type, const std::string& unitLanguage) {
return (ptypes.at(unitLanguage).find(type) != ptypes.at(unitLanguage).end() ||
userTypes.find(type) != userTypes.end());
}
// Reads a set of user-defined primitive types
// File should list one type per line
//
std::istream& operator>>(std::istream& in, primitiveTypes& primitives) {
std::string utype;
while(std::getline(in, utype))
primitives.addPrimitive(utype);
return in;
}
// Adds "userType" to user-defined primitives if not already present
// Apply to all languages
//
void primitiveTypes::addPrimitive(const std::string& userType) {
userTypes.insert(userType);
}
void primitiveTypes::outputPrimitives() {
std::cerr<<"---Primitives---";
for (const auto& pair : ptypes) {
std::cerr<<"\n[" << pair.first << "]:" ;
for (const std::string& primit : pair.second)
std::cerr << ' ' << primit;
}
if (userTypes.size() > 0) {
std::cerr<<"\n[User-Defined]:";
for (const std::string& primit : userTypes)
std::cerr << ' ' << primit;
}
std::cerr << "\n\n";
}
// Specific primitives are used based on unit language
// Generic types (e.g., T), auto (C++), and var (C# and Java)
// are considered as non-primitive unless added by user
//
void primitiveTypes::createPrimitiveList() {
for (const auto& l : LANGUAGE) {
if (l == "C++") {
ptypes.insert({l, {
"short",
"shortint",
"int",
"int8_t",
"int16_t",
"int32_t",
"int64_t",
"uint8_t",
"uint16_t",
"uint32_t",
"uint64_t",
"long",
"longint",
"longlong",
"longlongint",
"float",
"double",
"longdouble",
"char",
"byte",
"string",
"size_type",
"size_t",
"wchar_t",
"char16_t",
"char32_t",
"bool",
"ptrdiff_t",
"void"
}});
}
else if (l == "C#") {
ptypes.insert({l, {
"bool",
"byte",
"sbyte",
"char",
"double",
"float",
"int",
"uint",
"long",
"ulong",
"short",
"ushort",
"decimal",
"string",
"void",
"Boolean",
"Byte",
"SByte",
"Char",
"Double",
"Single",
"Int32",
"UInt32",
"Int64",
"UInt64",
"Int16",
"IntPtr",
"UIntPtr",
"UInt16",
"Decimal",
"String",
"Void"
}});
}
else if (l == "Java") {
ptypes.insert({l, {
"boolean",
"byte",
"char",
"short",
"int",
"long",
"float",
"double",
"void",
"Byte",
"Character",
"Short",
"Integer",
"Long",
"Float",
"Double",
"String",
"Void"
}});
}
}
}