Changeset View
Changeset View
Standalone View
Standalone View
plugins/astyle/3rdparty/libastyle/ASResource.cpp
1 | // ASResource.cpp | 1 | // ASResource.cpp | ||
---|---|---|---|---|---|
2 | // Copyright (c) 2016 by Jim Pattee <jimp03@email.com>. | 2 | // Copyright (c) 2018 by Jim Pattee <jimp03@email.com>. | ||
3 | // This code is licensed under the MIT License. | 3 | // This code is licensed under the MIT License. | ||
4 | // License.txt describes the conditions under which this software may be distributed. | 4 | // License.md describes the conditions under which this software may be distributed. | ||
5 | 5 | | |||
6 | //----------------------------------------------------------------------------- | 6 | //----------------------------------------------------------------------------- | ||
7 | // headers | 7 | // headers | ||
8 | //----------------------------------------------------------------------------- | 8 | //----------------------------------------------------------------------------- | ||
9 | 9 | | |||
10 | #include "astyle.h" | 10 | #include "astyle.h" | ||
11 | #include <algorithm> | 11 | #include <algorithm> | ||
12 | 12 | | |||
13 | //----------------------------------------------------------------------------- | 13 | //----------------------------------------------------------------------------- | ||
14 | // astyle namespace | 14 | // astyle namespace | ||
15 | //----------------------------------------------------------------------------- | 15 | //----------------------------------------------------------------------------- | ||
16 | 16 | | |||
17 | namespace astyle { | 17 | namespace astyle { | ||
18 | // | 18 | // | ||
19 | const string ASResource::AS_IF = string("if"); | 19 | const string ASResource::_AS_EXCEPT = string("__except"); | ||
20 | const string ASResource::AS_ELSE = string("else"); | 20 | const string ASResource::_AS_FINALLY = string("__finally"); | ||
21 | const string ASResource::AS_FOR = string("for"); | 21 | const string ASResource::_AS_TRY = string("__try"); | ||
22 | const string ASResource::AS_DO = string("do"); | 22 | const string ASResource::AS_ADD = string("add"); | ||
23 | const string ASResource::AS_WHILE = string("while"); | 23 | const string ASResource::AS_AUTO = string("auto"); | ||
24 | const string ASResource::AS_SWITCH = string("switch"); | 24 | const string ASResource::AS_AUTORELEASEPOOL = string("autoreleasepool"); | ||
25 | const string ASResource::AS_CASE = string("case"); | 25 | const string ASResource::AS_CASE = string("case"); | ||
26 | const string ASResource::AS_DEFAULT = string("default"); | 26 | const string ASResource::AS_CATCH = string("catch"); | ||
27 | const string ASResource::AS_CLASS = string("class"); | 27 | const string ASResource::AS_CLASS = string("class"); | ||
28 | const string ASResource::AS_VOLATILE = string("volatile"); | 28 | const string ASResource::AS_CONST = string("const"); | ||
29 | const string ASResource::AS_INTERRUPT = string("interrupt"); | 29 | const string ASResource::AS_CONST_CAST = string("const_cast"); | ||
30 | const string ASResource::AS_NOEXCEPT = string("noexcept"); | 30 | const string ASResource::AS_DEFAULT = string("default"); | ||
31 | const string ASResource::AS_AUTORELEASEPOOL = string("autoreleasepool"); | 31 | const string ASResource::AS_DELEGATE = string("delegate"); | ||
32 | const string ASResource::AS_STRUCT = string("struct"); | 32 | const string ASResource::AS_DELETE = string("delete"); | ||
33 | const string ASResource::AS_UNION = string("union"); | 33 | const string ASResource::AS_DO = string("do"); | ||
34 | const string ASResource::AS_INTERFACE = string("interface"); | 34 | const string ASResource::AS_DYNAMIC_CAST = string("dynamic_cast"); | ||
35 | const string ASResource::AS_NAMESPACE = string("namespace"); | 35 | const string ASResource::AS_ELSE = string("else"); | ||
36 | const string ASResource::AS_MODULE = string("module"); // CORBA IDL module definition | | |||
37 | const string ASResource::AS_END = string("end"); | 36 | const string ASResource::AS_END = string("end"); | ||
38 | const string ASResource::AS_SELECTOR = string("selector"); | | |||
39 | const string ASResource::AS_EXTERN = string("extern"); | | |||
40 | const string ASResource::AS_ENUM = string("enum"); | 37 | const string ASResource::AS_ENUM = string("enum"); | ||
41 | const string ASResource::AS_PUBLIC = string("public"); | 38 | const string ASResource::AS_EXTERN = string("extern"); | ||
42 | const string ASResource::AS_PROTECTED = string("protected"); | 39 | const string ASResource::AS_FINAL = string("final"); | ||
40 | const string ASResource::AS_FINALLY = string("finally"); | ||||
41 | const string ASResource::AS_FIXED = string("fixed"); | ||||
42 | const string ASResource::AS_FOR = string("for"); | ||||
43 | const string ASResource::AS_FOREACH = string("foreach"); | ||||
44 | const string ASResource::AS_FOREVER = string("forever"); | ||||
45 | const string ASResource::AS_GET = string("get"); | ||||
46 | const string ASResource::AS_IF = string("if"); | ||||
47 | const string ASResource::AS_INTERFACE = string("interface"); | ||||
48 | const string ASResource::AS_INTERRUPT = string("interrupt"); | ||||
49 | const string ASResource::AS_LET = string("let"); | ||||
50 | const string ASResource::AS_LOCK = string("lock"); | ||||
51 | const string ASResource::AS_MODULE = string("module"); // CORBA IDL module definition | ||||
52 | const string ASResource::AS_NAMESPACE = string("namespace"); | ||||
53 | const string ASResource::AS_NEW = string("new"); | ||||
54 | const string ASResource::AS_NOEXCEPT = string("noexcept"); | ||||
55 | const string ASResource::AS_NS_DURING = string("NS_DURING"); | ||||
56 | const string ASResource::AS_NS_HANDLER = string("NS_HANDLER"); | ||||
57 | const string ASResource::AS_OPERATOR = string("operator"); | ||||
58 | const string ASResource::AS_OVERRIDE = string("override"); | ||||
43 | const string ASResource::AS_PRIVATE = string("private"); | 59 | const string ASResource::AS_PRIVATE = string("private"); | ||
60 | const string ASResource::AS_PROTECTED = string("protected"); | ||||
61 | const string ASResource::AS_PUBLIC = string("public"); | ||||
62 | const string ASResource::AS_QFOREACH = string("Q_FOREACH"); | ||||
63 | const string ASResource::AS_QFOREVER = string("Q_FOREVER"); | ||||
64 | const string ASResource::AS_REINTERPRET_CAST = string("reinterpret_cast"); | ||||
65 | const string ASResource::AS_REMOVE = string("remove"); | ||||
66 | const string ASResource::AS_SEALED = string("sealed"); | ||||
67 | const string ASResource::AS_SELECTOR = string("selector"); | ||||
68 | const string ASResource::AS_SET = string("set"); | ||||
44 | const string ASResource::AS_STATIC = string("static"); | 69 | const string ASResource::AS_STATIC = string("static"); | ||
70 | const string ASResource::AS_STATIC_CAST = string("static_cast"); | ||||
71 | const string ASResource::AS_STRUCT = string("struct"); | ||||
72 | const string ASResource::AS_SWITCH = string("switch"); | ||||
45 | const string ASResource::AS_SYNCHRONIZED = string("synchronized"); | 73 | const string ASResource::AS_SYNCHRONIZED = string("synchronized"); | ||
46 | const string ASResource::AS_OPERATOR = string("operator"); | | |||
47 | const string ASResource::AS_TEMPLATE = string("template"); | 74 | const string ASResource::AS_TEMPLATE = string("template"); | ||
48 | const string ASResource::AS_TRY = string("try"); | | |||
49 | const string ASResource::AS_CATCH = string("catch"); | | |||
50 | const string ASResource::AS_THROW = string("throw"); | 75 | const string ASResource::AS_THROW = string("throw"); | ||
51 | const string ASResource::AS_FINALLY = string("finally"); | | |||
52 | const string ASResource::AS_USING = string("using"); | | |||
53 | const string ASResource::_AS_TRY = string("__try"); | | |||
54 | const string ASResource::_AS_FINALLY = string("__finally"); | | |||
55 | const string ASResource::_AS_EXCEPT = string("__except"); | | |||
56 | const string ASResource::AS_THROWS = string("throws"); | 76 | const string ASResource::AS_THROWS = string("throws"); | ||
57 | const string ASResource::AS_CONST = string("const"); | 77 | const string ASResource::AS_TRY = string("try"); | ||
58 | const string ASResource::AS_SEALED = string("sealed"); | 78 | const string ASResource::AS_UNCHECKED = string("unchecked"); | ||
59 | const string ASResource::AS_OVERRIDE = string("override"); | 79 | const string ASResource::AS_UNION = string("union"); | ||
80 | const string ASResource::AS_UNSAFE = string("unsafe"); | ||||
81 | const string ASResource::AS_USING = string("using"); | ||||
82 | const string ASResource::AS_VOLATILE = string("volatile"); | ||||
60 | const string ASResource::AS_WHERE = string("where"); | 83 | const string ASResource::AS_WHERE = string("where"); | ||
61 | const string ASResource::AS_LET = string("let"); | 84 | const string ASResource::AS_WHILE = string("while"); | ||
62 | const string ASResource::AS_NEW = string("new"); | | |||
63 | const string ASResource::AS_DELETE = string("delete"); | | |||
64 | 85 | | |||
65 | const string ASResource::AS_ASM = string("asm"); | 86 | const string ASResource::AS_ASM = string("asm"); | ||
66 | const string ASResource::AS__ASM__ = string("__asm__"); | 87 | const string ASResource::AS__ASM__ = string("__asm__"); | ||
67 | const string ASResource::AS_MS_ASM = string("_asm"); | 88 | const string ASResource::AS_MS_ASM = string("_asm"); | ||
68 | const string ASResource::AS_MS__ASM = string("__asm"); | 89 | const string ASResource::AS_MS__ASM = string("__asm"); | ||
69 | 90 | | |||
70 | const string ASResource::AS_BAR_DEFINE = string("#define"); | 91 | const string ASResource::AS_BAR_DEFINE = string("#define"); | ||
71 | const string ASResource::AS_BAR_INCLUDE = string("#include"); | 92 | const string ASResource::AS_BAR_INCLUDE = string("#include"); | ||
72 | const string ASResource::AS_BAR_IF = string("#if"); | 93 | const string ASResource::AS_BAR_IF = string("#if"); | ||
73 | const string ASResource::AS_BAR_EL = string("#el"); | 94 | const string ASResource::AS_BAR_EL = string("#el"); | ||
74 | const string ASResource::AS_BAR_ENDIF = string("#endif"); | 95 | const string ASResource::AS_BAR_ENDIF = string("#endif"); | ||
75 | 96 | | |||
76 | const string ASResource::AS_OPEN_BRACKET = string("{"); | 97 | const string ASResource::AS_OPEN_BRACE = string("{"); | ||
77 | const string ASResource::AS_CLOSE_BRACKET = string("}"); | 98 | const string ASResource::AS_CLOSE_BRACE = string("}"); | ||
78 | const string ASResource::AS_OPEN_LINE_COMMENT = string("//"); | 99 | const string ASResource::AS_OPEN_LINE_COMMENT = string("//"); | ||
79 | const string ASResource::AS_OPEN_COMMENT = string("/*"); | 100 | const string ASResource::AS_OPEN_COMMENT = string("/*"); | ||
80 | const string ASResource::AS_CLOSE_COMMENT = string("*/"); | 101 | const string ASResource::AS_CLOSE_COMMENT = string("*/"); | ||
81 | 102 | | |||
82 | const string ASResource::AS_ASSIGN = string("="); | 103 | const string ASResource::AS_ASSIGN = string("="); | ||
83 | const string ASResource::AS_PLUS_ASSIGN = string("+="); | 104 | const string ASResource::AS_PLUS_ASSIGN = string("+="); | ||
84 | const string ASResource::AS_MINUS_ASSIGN = string("-="); | 105 | const string ASResource::AS_MINUS_ASSIGN = string("-="); | ||
85 | const string ASResource::AS_MULT_ASSIGN = string("*="); | 106 | const string ASResource::AS_MULT_ASSIGN = string("*="); | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
129 | const string ASResource::AS_BIT_AND = string("&"); | 150 | const string ASResource::AS_BIT_AND = string("&"); | ||
130 | const string ASResource::AS_BIT_NOT = string("~"); | 151 | const string ASResource::AS_BIT_NOT = string("~"); | ||
131 | const string ASResource::AS_BIT_XOR = string("^"); | 152 | const string ASResource::AS_BIT_XOR = string("^"); | ||
132 | const string ASResource::AS_QUESTION = string("?"); | 153 | const string ASResource::AS_QUESTION = string("?"); | ||
133 | const string ASResource::AS_COLON = string(":"); | 154 | const string ASResource::AS_COLON = string(":"); | ||
134 | const string ASResource::AS_COMMA = string(","); | 155 | const string ASResource::AS_COMMA = string(","); | ||
135 | const string ASResource::AS_SEMICOLON = string(";"); | 156 | const string ASResource::AS_SEMICOLON = string(";"); | ||
136 | 157 | | |||
137 | const string ASResource::AS_QFOREACH = string("Q_FOREACH"); | | |||
138 | const string ASResource::AS_QFOREVER = string("Q_FOREVER"); | | |||
139 | const string ASResource::AS_FOREVER = string("forever"); | | |||
140 | const string ASResource::AS_FOREACH = string("foreach"); | | |||
141 | const string ASResource::AS_LOCK = string("lock"); | | |||
142 | const string ASResource::AS_UNSAFE = string("unsafe"); | | |||
143 | const string ASResource::AS_FIXED = string("fixed"); | | |||
144 | const string ASResource::AS_GET = string("get"); | | |||
145 | const string ASResource::AS_SET = string("set"); | | |||
146 | const string ASResource::AS_ADD = string("add"); | | |||
147 | const string ASResource::AS_REMOVE = string("remove"); | | |||
148 | const string ASResource::AS_DELEGATE = string("delegate"); | | |||
149 | const string ASResource::AS_UNCHECKED = string("unchecked"); | | |||
150 | | ||||
151 | const string ASResource::AS_CONST_CAST = string("const_cast"); | | |||
152 | const string ASResource::AS_DYNAMIC_CAST = string("dynamic_cast"); | | |||
153 | const string ASResource::AS_REINTERPRET_CAST = string("reinterpret_cast"); | | |||
154 | const string ASResource::AS_STATIC_CAST = string("static_cast"); | | |||
155 | | ||||
156 | const string ASResource::AS_NS_DURING = string("NS_DURING"); | | |||
157 | const string ASResource::AS_NS_HANDLER = string("NS_HANDLER"); | | |||
158 | | ||||
159 | /** | 158 | /** | ||
160 | * Sort comparison function. | 159 | * Sort comparison function. | ||
161 | * Compares the length of the value of pointers in the vectors. | 160 | * Compares the length of the value of pointers in the vectors. | ||
162 | * The LONGEST strings will be first in the vector. | 161 | * The LONGEST strings will be first in the vector. | ||
163 | * | 162 | * | ||
164 | * @param a and b, the string pointers to be compared. | 163 | * @param a and b, the string pointers to be compared. | ||
165 | */ | 164 | */ | ||
166 | bool sortOnLength(const string* a, const string* b) | 165 | bool sortOnLength(const string* a, const string* b) | ||
Show All 15 Lines | |||||
182 | /** | 181 | /** | ||
183 | * Build the vector of assignment operators. | 182 | * Build the vector of assignment operators. | ||
184 | * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp | 183 | * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp | ||
185 | * | 184 | * | ||
186 | * @param assignmentOperators a reference to the vector to be built. | 185 | * @param assignmentOperators a reference to the vector to be built. | ||
187 | */ | 186 | */ | ||
188 | void ASResource::buildAssignmentOperators(vector<const string*>* assignmentOperators) | 187 | void ASResource::buildAssignmentOperators(vector<const string*>* assignmentOperators) | ||
189 | { | 188 | { | ||
190 | assignmentOperators->push_back(&AS_ASSIGN); | 189 | const size_t elements = 15; | ||
191 | assignmentOperators->push_back(&AS_PLUS_ASSIGN); | 190 | static bool reserved = false; | ||
192 | assignmentOperators->push_back(&AS_MINUS_ASSIGN); | 191 | if (!reserved) | ||
193 | assignmentOperators->push_back(&AS_MULT_ASSIGN); | 192 | { | ||
194 | assignmentOperators->push_back(&AS_DIV_ASSIGN); | 193 | assignmentOperators->reserve(elements); | ||
195 | assignmentOperators->push_back(&AS_MOD_ASSIGN); | 194 | reserved = true; | ||
196 | assignmentOperators->push_back(&AS_OR_ASSIGN); | 195 | } | ||
197 | assignmentOperators->push_back(&AS_AND_ASSIGN); | 196 | | ||
198 | assignmentOperators->push_back(&AS_XOR_ASSIGN); | 197 | assignmentOperators->emplace_back(&AS_ASSIGN); | ||
198 | assignmentOperators->emplace_back(&AS_PLUS_ASSIGN); | ||||
199 | assignmentOperators->emplace_back(&AS_MINUS_ASSIGN); | ||||
200 | assignmentOperators->emplace_back(&AS_MULT_ASSIGN); | ||||
201 | assignmentOperators->emplace_back(&AS_DIV_ASSIGN); | ||||
202 | assignmentOperators->emplace_back(&AS_MOD_ASSIGN); | ||||
203 | assignmentOperators->emplace_back(&AS_OR_ASSIGN); | ||||
204 | assignmentOperators->emplace_back(&AS_AND_ASSIGN); | ||||
205 | assignmentOperators->emplace_back(&AS_XOR_ASSIGN); | ||||
199 | 206 | | |||
200 | // Java | 207 | // Java | ||
201 | assignmentOperators->push_back(&AS_GR_GR_GR_ASSIGN); | 208 | assignmentOperators->emplace_back(&AS_GR_GR_GR_ASSIGN); | ||
202 | assignmentOperators->push_back(&AS_GR_GR_ASSIGN); | 209 | assignmentOperators->emplace_back(&AS_GR_GR_ASSIGN); | ||
203 | assignmentOperators->push_back(&AS_LS_LS_ASSIGN); | 210 | assignmentOperators->emplace_back(&AS_LS_LS_ASSIGN); | ||
204 | 211 | | |||
205 | // Unknown | 212 | // Unknown | ||
206 | assignmentOperators->push_back(&AS_LS_LS_LS_ASSIGN); | 213 | assignmentOperators->emplace_back(&AS_LS_LS_LS_ASSIGN); | ||
207 | 214 | | |||
215 | assert(assignmentOperators->size() < elements); | ||||
208 | sort(assignmentOperators->begin(), assignmentOperators->end(), sortOnLength); | 216 | sort(assignmentOperators->begin(), assignmentOperators->end(), sortOnLength); | ||
209 | } | 217 | } | ||
210 | 218 | | |||
211 | /** | 219 | /** | ||
212 | * Build the vector of C++ cast operators. | 220 | * Build the vector of C++ cast operators. | ||
213 | * Used by ONLY ASFormatter.cpp | 221 | * Used by ONLY ASFormatter.cpp | ||
214 | * | 222 | * | ||
215 | * @param castOperators a reference to the vector to be built. | 223 | * @param castOperators a reference to the vector to be built. | ||
216 | */ | 224 | */ | ||
217 | void ASResource::buildCastOperators(vector<const string*>* castOperators) | 225 | void ASResource::buildCastOperators(vector<const string*>* castOperators) | ||
218 | { | 226 | { | ||
219 | castOperators->push_back(&AS_CONST_CAST); | 227 | const size_t elements = 5; | ||
220 | castOperators->push_back(&AS_DYNAMIC_CAST); | 228 | static bool reserved = false; | ||
221 | castOperators->push_back(&AS_REINTERPRET_CAST); | 229 | if (!reserved) | ||
222 | castOperators->push_back(&AS_STATIC_CAST); | 230 | { | ||
231 | castOperators->reserve(elements); | ||||
232 | reserved = true; | ||||
233 | } | ||||
234 | | ||||
235 | castOperators->emplace_back(&AS_CONST_CAST); | ||||
236 | castOperators->emplace_back(&AS_DYNAMIC_CAST); | ||||
237 | castOperators->emplace_back(&AS_REINTERPRET_CAST); | ||||
238 | castOperators->emplace_back(&AS_STATIC_CAST); | ||||
239 | | ||||
240 | assert(castOperators->size() < elements); | ||||
241 | sort(castOperators->begin(), castOperators->end(), sortOnName); | ||||
223 | } | 242 | } | ||
224 | 243 | | |||
225 | /** | 244 | /** | ||
226 | * Build the vector of header words. | 245 | * Build the vector of header words. | ||
227 | * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp | 246 | * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp | ||
228 | * | 247 | * | ||
229 | * @param headers a reference to the vector to be built. | 248 | * @param headers a reference to the vector to be built. | ||
230 | */ | 249 | */ | ||
231 | void ASResource::buildHeaders(vector<const string*>* headers, int fileType, bool beautifier) | 250 | void ASResource::buildHeaders(vector<const string*>* headers, int fileType, bool beautifier) | ||
232 | { | 251 | { | ||
233 | headers->push_back(&AS_IF); | 252 | const size_t elements = 25; | ||
234 | headers->push_back(&AS_ELSE); | 253 | static bool reserved = false; | ||
235 | headers->push_back(&AS_FOR); | 254 | if (!reserved) | ||
236 | headers->push_back(&AS_WHILE); | 255 | { | ||
237 | headers->push_back(&AS_DO); | 256 | headers->reserve(elements); | ||
238 | headers->push_back(&AS_SWITCH); | 257 | reserved = true; | ||
239 | headers->push_back(&AS_CASE); | 258 | } | ||
240 | headers->push_back(&AS_DEFAULT); | 259 | | ||
241 | headers->push_back(&AS_TRY); | 260 | headers->emplace_back(&AS_IF); | ||
242 | headers->push_back(&AS_CATCH); | 261 | headers->emplace_back(&AS_ELSE); | ||
243 | headers->push_back(&AS_QFOREACH); // QT | 262 | headers->emplace_back(&AS_FOR); | ||
244 | headers->push_back(&AS_QFOREVER); // QT | 263 | headers->emplace_back(&AS_WHILE); | ||
245 | headers->push_back(&AS_FOREACH); // QT & C# | 264 | headers->emplace_back(&AS_DO); | ||
246 | headers->push_back(&AS_FOREVER); // Qt & Boost | 265 | headers->emplace_back(&AS_SWITCH); | ||
266 | headers->emplace_back(&AS_CASE); | ||||
267 | headers->emplace_back(&AS_DEFAULT); | ||||
268 | headers->emplace_back(&AS_TRY); | ||||
269 | headers->emplace_back(&AS_CATCH); | ||||
270 | headers->emplace_back(&AS_QFOREACH); // QT | ||||
271 | headers->emplace_back(&AS_QFOREVER); // QT | ||||
272 | headers->emplace_back(&AS_FOREACH); // QT & C# | ||||
273 | headers->emplace_back(&AS_FOREVER); // Qt & Boost | ||||
247 | 274 | | |||
248 | if (fileType == C_TYPE) | 275 | if (fileType == C_TYPE) | ||
249 | { | 276 | { | ||
250 | headers->push_back(&_AS_TRY); // __try | 277 | headers->emplace_back(&_AS_TRY); // __try | ||
251 | headers->push_back(&_AS_FINALLY); // __finally | 278 | headers->emplace_back(&_AS_FINALLY); // __finally | ||
252 | headers->push_back(&_AS_EXCEPT); // __except | 279 | headers->emplace_back(&_AS_EXCEPT); // __except | ||
253 | } | 280 | } | ||
254 | if (fileType == JAVA_TYPE) | 281 | if (fileType == JAVA_TYPE) | ||
255 | { | 282 | { | ||
256 | headers->push_back(&AS_FINALLY); | 283 | headers->emplace_back(&AS_FINALLY); | ||
257 | headers->push_back(&AS_SYNCHRONIZED); | 284 | headers->emplace_back(&AS_SYNCHRONIZED); | ||
258 | } | 285 | } | ||
259 | 286 | | |||
260 | if (fileType == SHARP_TYPE) | 287 | if (fileType == SHARP_TYPE) | ||
261 | { | 288 | { | ||
262 | headers->push_back(&AS_FINALLY); | 289 | headers->emplace_back(&AS_FINALLY); | ||
263 | headers->push_back(&AS_LOCK); | 290 | headers->emplace_back(&AS_LOCK); | ||
264 | headers->push_back(&AS_FIXED); | 291 | headers->emplace_back(&AS_FIXED); | ||
265 | headers->push_back(&AS_GET); | 292 | headers->emplace_back(&AS_GET); | ||
266 | headers->push_back(&AS_SET); | 293 | headers->emplace_back(&AS_SET); | ||
267 | headers->push_back(&AS_ADD); | 294 | headers->emplace_back(&AS_ADD); | ||
268 | headers->push_back(&AS_REMOVE); | 295 | headers->emplace_back(&AS_REMOVE); | ||
269 | headers->push_back(&AS_USING); | 296 | headers->emplace_back(&AS_USING); | ||
270 | } | 297 | } | ||
271 | 298 | | |||
272 | if (beautifier) | 299 | if (beautifier) | ||
273 | { | 300 | { | ||
274 | if (fileType == C_TYPE) | 301 | if (fileType == C_TYPE) | ||
275 | { | 302 | { | ||
276 | headers->push_back(&AS_TEMPLATE); | 303 | headers->emplace_back(&AS_TEMPLATE); | ||
277 | } | 304 | } | ||
278 | 305 | | |||
279 | if (fileType == JAVA_TYPE) | 306 | if (fileType == JAVA_TYPE) | ||
280 | { | 307 | { | ||
281 | headers->push_back(&AS_STATIC); // for static constructor | 308 | headers->emplace_back(&AS_STATIC); // for static constructor | ||
282 | } | 309 | } | ||
283 | } | 310 | } | ||
311 | | ||||
312 | assert(headers->size() < elements); | ||||
284 | sort(headers->begin(), headers->end(), sortOnName); | 313 | sort(headers->begin(), headers->end(), sortOnName); | ||
285 | } | 314 | } | ||
286 | 315 | | |||
287 | /** | 316 | /** | ||
288 | * Build the vector of indentable headers. | 317 | * Build the vector of indentable headers. | ||
289 | * Used by ONLY ASBeautifier.cpp | 318 | * Used by ONLY ASBeautifier.cpp | ||
290 | * | 319 | * | ||
291 | * @param indentableHeaders a reference to the vector to be built. | 320 | * @param indentableHeaders a reference to the vector to be built. | ||
292 | */ | 321 | */ | ||
293 | void ASResource::buildIndentableHeaders(vector<const string*>* indentableHeaders) | 322 | void ASResource::buildIndentableHeaders(vector<const string*>* indentableHeaders) | ||
294 | { | 323 | { | ||
295 | indentableHeaders->push_back(&AS_RETURN); | 324 | indentableHeaders->emplace_back(&AS_RETURN); | ||
296 | 325 | | |||
297 | sort(indentableHeaders->begin(), indentableHeaders->end(), sortOnName); | 326 | // sort(indentableHeaders->begin(), indentableHeaders->end(), sortOnName); | ||
298 | } | 327 | } | ||
299 | 328 | | |||
300 | /** | 329 | /** | ||
301 | * Build the vector of indentable macros pairs. | 330 | * Build the vector of indentable macros pairs. | ||
302 | * Initialized by ASFormatter, used by ONLY ASEnhancer.cpp | 331 | * Initialized by ASFormatter, used by ONLY ASEnhancer.cpp | ||
303 | * | 332 | * | ||
304 | * @param indentableMacros a reference to the vector to be built. | 333 | * @param indentableMacros a reference to the vector to be built. | ||
305 | */ | 334 | */ | ||
306 | void ASResource::buildIndentableMacros(vector<const pair<const string, const string>* >* indentableMacros) | 335 | void ASResource::buildIndentableMacros(vector<const pair<const string, const string>* >* indentableMacros) | ||
307 | { | 336 | { | ||
308 | typedef pair<const string, const string> macro_pair; | 337 | const size_t elements = 10; | ||
338 | static bool reserved = false; | ||||
339 | if (!reserved) | ||||
340 | { | ||||
341 | indentableMacros->reserve(elements); | ||||
342 | reserved = true; | ||||
343 | } | ||||
309 | 344 | | |||
310 | // the pairs must be retained in memory because of pair pointers | 345 | // the pairs must be retained in memory because of pair pointers | ||
346 | typedef pair<const string, const string> macro_pair; | ||||
311 | static const macro_pair macros[] = | 347 | static const macro_pair macros[] = | ||
312 | { | 348 | { | ||
313 | // wxWidgets | 349 | // wxWidgets | ||
314 | macro_pair("BEGIN_EVENT_TABLE", "END_EVENT_TABLE"), | 350 | macro_pair("BEGIN_EVENT_TABLE", "END_EVENT_TABLE"), | ||
315 | macro_pair("wxBEGIN_EVENT_TABLE", "wxEND_EVENT_TABLE"), | 351 | macro_pair("wxBEGIN_EVENT_TABLE", "wxEND_EVENT_TABLE"), | ||
316 | // MFC | 352 | // MFC | ||
317 | macro_pair("BEGIN_DISPATCH_MAP", "END_DISPATCH_MAP"), | 353 | macro_pair("BEGIN_DISPATCH_MAP", "END_DISPATCH_MAP"), | ||
318 | macro_pair("BEGIN_EVENT_MAP", "END_EVENT_MAP"), | 354 | macro_pair("BEGIN_EVENT_MAP", "END_EVENT_MAP"), | ||
319 | macro_pair("BEGIN_MESSAGE_MAP", "END_MESSAGE_MAP"), | 355 | macro_pair("BEGIN_MESSAGE_MAP", "END_MESSAGE_MAP"), | ||
320 | macro_pair("BEGIN_PROPPAGEIDS", "END_PROPPAGEIDS"), | 356 | macro_pair("BEGIN_PROPPAGEIDS", "END_PROPPAGEIDS"), | ||
321 | }; | 357 | }; | ||
322 | 358 | | |||
323 | size_t elements = sizeof(macros) / sizeof(macros[0]); | 359 | size_t entries = sizeof(macros) / sizeof(macros[0]); | ||
324 | for (size_t i = 0; i < elements; i++) | 360 | for (size_t i = 0; i < entries; i++) | ||
325 | indentableMacros->push_back(¯os[i]); | 361 | indentableMacros->emplace_back(¯os[i]); | ||
362 | | ||||
363 | assert(indentableMacros->size() < elements); | ||||
326 | } | 364 | } | ||
327 | 365 | | |||
328 | /** | 366 | /** | ||
329 | * Build the vector of non-assignment operators. | 367 | * Build the vector of non-assignment operators. | ||
330 | * Used by ONLY ASBeautifier.cpp | 368 | * Used by ONLY ASBeautifier.cpp | ||
331 | * | 369 | * | ||
332 | * @param nonAssignmentOperators a reference to the vector to be built. | 370 | * @param nonAssignmentOperators a reference to the vector to be built. | ||
333 | */ | 371 | */ | ||
334 | void ASResource::buildNonAssignmentOperators(vector<const string*>* nonAssignmentOperators) | 372 | void ASResource::buildNonAssignmentOperators(vector<const string*>* nonAssignmentOperators) | ||
335 | { | 373 | { | ||
336 | nonAssignmentOperators->push_back(&AS_EQUAL); | 374 | const size_t elements = 15; | ||
337 | nonAssignmentOperators->push_back(&AS_PLUS_PLUS); | 375 | static bool reserved = false; | ||
338 | nonAssignmentOperators->push_back(&AS_MINUS_MINUS); | 376 | if (!reserved) | ||
339 | nonAssignmentOperators->push_back(&AS_NOT_EQUAL); | 377 | { | ||
340 | nonAssignmentOperators->push_back(&AS_GR_EQUAL); | 378 | nonAssignmentOperators->reserve(elements); | ||
341 | nonAssignmentOperators->push_back(&AS_GR_GR_GR); | 379 | reserved = true; | ||
342 | nonAssignmentOperators->push_back(&AS_GR_GR); | 380 | } | ||
343 | nonAssignmentOperators->push_back(&AS_LS_EQUAL); | 381 | | ||
344 | nonAssignmentOperators->push_back(&AS_LS_LS_LS); | 382 | nonAssignmentOperators->emplace_back(&AS_EQUAL); | ||
345 | nonAssignmentOperators->push_back(&AS_LS_LS); | 383 | nonAssignmentOperators->emplace_back(&AS_PLUS_PLUS); | ||
346 | nonAssignmentOperators->push_back(&AS_ARROW); | 384 | nonAssignmentOperators->emplace_back(&AS_MINUS_MINUS); | ||
347 | nonAssignmentOperators->push_back(&AS_AND); | 385 | nonAssignmentOperators->emplace_back(&AS_NOT_EQUAL); | ||
348 | nonAssignmentOperators->push_back(&AS_OR); | 386 | nonAssignmentOperators->emplace_back(&AS_GR_EQUAL); | ||
349 | nonAssignmentOperators->push_back(&AS_LAMBDA); | 387 | nonAssignmentOperators->emplace_back(&AS_GR_GR_GR); | ||
388 | nonAssignmentOperators->emplace_back(&AS_GR_GR); | ||||
389 | nonAssignmentOperators->emplace_back(&AS_LS_EQUAL); | ||||
390 | nonAssignmentOperators->emplace_back(&AS_LS_LS_LS); | ||||
391 | nonAssignmentOperators->emplace_back(&AS_LS_LS); | ||||
392 | nonAssignmentOperators->emplace_back(&AS_ARROW); | ||||
393 | nonAssignmentOperators->emplace_back(&AS_AND); | ||||
394 | nonAssignmentOperators->emplace_back(&AS_OR); | ||||
395 | nonAssignmentOperators->emplace_back(&AS_LAMBDA); | ||||
350 | 396 | | |||
397 | assert(nonAssignmentOperators->size() < elements); | ||||
351 | sort(nonAssignmentOperators->begin(), nonAssignmentOperators->end(), sortOnLength); | 398 | sort(nonAssignmentOperators->begin(), nonAssignmentOperators->end(), sortOnLength); | ||
352 | } | 399 | } | ||
353 | 400 | | |||
354 | /** | 401 | /** | ||
355 | * Build the vector of header non-paren headers. | 402 | * Build the vector of header non-paren headers. | ||
356 | * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp. | 403 | * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp. | ||
357 | * NOTE: Non-paren headers should also be included in the headers vector. | 404 | * NOTE: Non-paren headers should also be included in the headers vector. | ||
358 | * | 405 | * | ||
359 | * @param nonParenHeaders a reference to the vector to be built. | 406 | * @param nonParenHeaders a reference to the vector to be built. | ||
360 | */ | 407 | */ | ||
361 | void ASResource::buildNonParenHeaders(vector<const string*>* nonParenHeaders, int fileType, bool beautifier) | 408 | void ASResource::buildNonParenHeaders(vector<const string*>* nonParenHeaders, int fileType, bool beautifier) | ||
362 | { | 409 | { | ||
363 | nonParenHeaders->push_back(&AS_ELSE); | 410 | const size_t elements = 20; | ||
364 | nonParenHeaders->push_back(&AS_DO); | 411 | static bool reserved = false; | ||
365 | nonParenHeaders->push_back(&AS_TRY); | 412 | if (!reserved) | ||
366 | nonParenHeaders->push_back(&AS_CATCH); // can be paren or non-paren | 413 | { | ||
367 | nonParenHeaders->push_back(&AS_CASE); // can be paren or non-paren | 414 | nonParenHeaders->reserve(elements); | ||
368 | nonParenHeaders->push_back(&AS_DEFAULT); | 415 | reserved = true; | ||
369 | nonParenHeaders->push_back(&AS_QFOREVER); // QT | 416 | } | ||
370 | nonParenHeaders->push_back(&AS_FOREVER); // Boost | 417 | | ||
418 | nonParenHeaders->emplace_back(&AS_ELSE); | ||||
419 | nonParenHeaders->emplace_back(&AS_DO); | ||||
420 | nonParenHeaders->emplace_back(&AS_TRY); | ||||
421 | nonParenHeaders->emplace_back(&AS_CATCH); // can be paren or non-paren | ||||
422 | nonParenHeaders->emplace_back(&AS_CASE); // can be paren or non-paren | ||||
423 | nonParenHeaders->emplace_back(&AS_DEFAULT); | ||||
424 | nonParenHeaders->emplace_back(&AS_QFOREVER); // QT | ||||
425 | nonParenHeaders->emplace_back(&AS_FOREVER); // Boost | ||||
371 | 426 | | |||
372 | if (fileType == C_TYPE) | 427 | if (fileType == C_TYPE) | ||
373 | { | 428 | { | ||
374 | nonParenHeaders->push_back(&_AS_TRY); // __try | 429 | nonParenHeaders->emplace_back(&_AS_TRY); // __try | ||
375 | nonParenHeaders->push_back(&_AS_FINALLY); // __finally | 430 | nonParenHeaders->emplace_back(&_AS_FINALLY); // __finally | ||
376 | } | 431 | } | ||
377 | if (fileType == JAVA_TYPE) | 432 | if (fileType == JAVA_TYPE) | ||
378 | { | 433 | { | ||
379 | nonParenHeaders->push_back(&AS_FINALLY); | 434 | nonParenHeaders->emplace_back(&AS_FINALLY); | ||
380 | } | 435 | } | ||
381 | 436 | | |||
382 | if (fileType == SHARP_TYPE) | 437 | if (fileType == SHARP_TYPE) | ||
383 | { | 438 | { | ||
384 | nonParenHeaders->push_back(&AS_FINALLY); | 439 | nonParenHeaders->emplace_back(&AS_FINALLY); | ||
385 | nonParenHeaders->push_back(&AS_GET); | 440 | nonParenHeaders->emplace_back(&AS_GET); | ||
386 | nonParenHeaders->push_back(&AS_SET); | 441 | nonParenHeaders->emplace_back(&AS_SET); | ||
387 | nonParenHeaders->push_back(&AS_ADD); | 442 | nonParenHeaders->emplace_back(&AS_ADD); | ||
388 | nonParenHeaders->push_back(&AS_REMOVE); | 443 | nonParenHeaders->emplace_back(&AS_REMOVE); | ||
389 | } | 444 | } | ||
390 | 445 | | |||
391 | if (beautifier) | 446 | if (beautifier) | ||
392 | { | 447 | { | ||
393 | if (fileType == C_TYPE) | 448 | if (fileType == C_TYPE) | ||
394 | { | 449 | { | ||
395 | nonParenHeaders->push_back(&AS_TEMPLATE); | 450 | nonParenHeaders->emplace_back(&AS_TEMPLATE); | ||
396 | } | 451 | } | ||
397 | if (fileType == JAVA_TYPE) | 452 | if (fileType == JAVA_TYPE) | ||
398 | { | 453 | { | ||
399 | nonParenHeaders->push_back(&AS_STATIC); | 454 | nonParenHeaders->emplace_back(&AS_STATIC); | ||
400 | } | 455 | } | ||
401 | } | 456 | } | ||
457 | | ||||
458 | assert(nonParenHeaders->size() < elements); | ||||
402 | sort(nonParenHeaders->begin(), nonParenHeaders->end(), sortOnName); | 459 | sort(nonParenHeaders->begin(), nonParenHeaders->end(), sortOnName); | ||
403 | } | 460 | } | ||
404 | 461 | | |||
405 | /** | 462 | /** | ||
406 | * Build the vector of operators. | 463 | * Build the vector of operators. | ||
407 | * Used by ONLY ASFormatter.cpp | 464 | * Used by ONLY ASFormatter.cpp | ||
408 | * | 465 | * | ||
409 | * @param operators a reference to the vector to be built. | 466 | * @param operators a reference to the vector to be built. | ||
410 | */ | 467 | */ | ||
411 | void ASResource::buildOperators(vector<const string*>* operators, int fileType) | 468 | void ASResource::buildOperators(vector<const string*>* operators, int fileType) | ||
412 | { | 469 | { | ||
413 | operators->push_back(&AS_PLUS_ASSIGN); | 470 | const size_t elements = 50; | ||
414 | operators->push_back(&AS_MINUS_ASSIGN); | 471 | static bool reserved = false; | ||
415 | operators->push_back(&AS_MULT_ASSIGN); | 472 | if (!reserved) | ||
416 | operators->push_back(&AS_DIV_ASSIGN); | 473 | { | ||
417 | operators->push_back(&AS_MOD_ASSIGN); | 474 | operators->reserve(elements); | ||
418 | operators->push_back(&AS_OR_ASSIGN); | 475 | reserved = true; | ||
419 | operators->push_back(&AS_AND_ASSIGN); | 476 | } | ||
420 | operators->push_back(&AS_XOR_ASSIGN); | 477 | | ||
421 | operators->push_back(&AS_EQUAL); | 478 | | ||
422 | operators->push_back(&AS_PLUS_PLUS); | 479 | operators->emplace_back(&AS_PLUS_ASSIGN); | ||
423 | operators->push_back(&AS_MINUS_MINUS); | 480 | operators->emplace_back(&AS_MINUS_ASSIGN); | ||
424 | operators->push_back(&AS_NOT_EQUAL); | 481 | operators->emplace_back(&AS_MULT_ASSIGN); | ||
425 | operators->push_back(&AS_GR_EQUAL); | 482 | operators->emplace_back(&AS_DIV_ASSIGN); | ||
426 | operators->push_back(&AS_GR_GR_GR_ASSIGN); | 483 | operators->emplace_back(&AS_MOD_ASSIGN); | ||
427 | operators->push_back(&AS_GR_GR_ASSIGN); | 484 | operators->emplace_back(&AS_OR_ASSIGN); | ||
428 | operators->push_back(&AS_GR_GR_GR); | 485 | operators->emplace_back(&AS_AND_ASSIGN); | ||
429 | operators->push_back(&AS_GR_GR); | 486 | operators->emplace_back(&AS_XOR_ASSIGN); | ||
430 | operators->push_back(&AS_LS_EQUAL); | 487 | operators->emplace_back(&AS_EQUAL); | ||
431 | operators->push_back(&AS_LS_LS_LS_ASSIGN); | 488 | operators->emplace_back(&AS_PLUS_PLUS); | ||
432 | operators->push_back(&AS_LS_LS_ASSIGN); | 489 | operators->emplace_back(&AS_MINUS_MINUS); | ||
433 | operators->push_back(&AS_LS_LS_LS); | 490 | operators->emplace_back(&AS_NOT_EQUAL); | ||
434 | operators->push_back(&AS_LS_LS); | 491 | operators->emplace_back(&AS_GR_EQUAL); | ||
435 | operators->push_back(&AS_QUESTION_QUESTION); | 492 | operators->emplace_back(&AS_GR_GR_GR_ASSIGN); | ||
436 | operators->push_back(&AS_LAMBDA); | 493 | operators->emplace_back(&AS_GR_GR_ASSIGN); | ||
437 | operators->push_back(&AS_ARROW); | 494 | operators->emplace_back(&AS_GR_GR_GR); | ||
438 | operators->push_back(&AS_AND); | 495 | operators->emplace_back(&AS_GR_GR); | ||
439 | operators->push_back(&AS_OR); | 496 | operators->emplace_back(&AS_LS_EQUAL); | ||
440 | operators->push_back(&AS_SCOPE_RESOLUTION); | 497 | operators->emplace_back(&AS_LS_LS_LS_ASSIGN); | ||
441 | operators->push_back(&AS_PLUS); | 498 | operators->emplace_back(&AS_LS_LS_ASSIGN); | ||
442 | operators->push_back(&AS_MINUS); | 499 | operators->emplace_back(&AS_LS_LS_LS); | ||
443 | operators->push_back(&AS_MULT); | 500 | operators->emplace_back(&AS_LS_LS); | ||
444 | operators->push_back(&AS_DIV); | 501 | operators->emplace_back(&AS_QUESTION_QUESTION); | ||
445 | operators->push_back(&AS_MOD); | 502 | operators->emplace_back(&AS_LAMBDA); | ||
446 | operators->push_back(&AS_QUESTION); | 503 | operators->emplace_back(&AS_ARROW); | ||
447 | operators->push_back(&AS_COLON); | 504 | operators->emplace_back(&AS_AND); | ||
448 | operators->push_back(&AS_ASSIGN); | 505 | operators->emplace_back(&AS_OR); | ||
449 | operators->push_back(&AS_LS); | 506 | operators->emplace_back(&AS_SCOPE_RESOLUTION); | ||
450 | operators->push_back(&AS_GR); | 507 | operators->emplace_back(&AS_PLUS); | ||
451 | operators->push_back(&AS_NOT); | 508 | operators->emplace_back(&AS_MINUS); | ||
452 | operators->push_back(&AS_BIT_OR); | 509 | operators->emplace_back(&AS_MULT); | ||
453 | operators->push_back(&AS_BIT_AND); | 510 | operators->emplace_back(&AS_DIV); | ||
454 | operators->push_back(&AS_BIT_NOT); | 511 | operators->emplace_back(&AS_MOD); | ||
455 | operators->push_back(&AS_BIT_XOR); | 512 | operators->emplace_back(&AS_QUESTION); | ||
513 | operators->emplace_back(&AS_COLON); | ||||
514 | operators->emplace_back(&AS_ASSIGN); | ||||
515 | operators->emplace_back(&AS_LS); | ||||
516 | operators->emplace_back(&AS_GR); | ||||
517 | operators->emplace_back(&AS_NOT); | ||||
518 | operators->emplace_back(&AS_BIT_OR); | ||||
519 | operators->emplace_back(&AS_BIT_AND); | ||||
520 | operators->emplace_back(&AS_BIT_NOT); | ||||
521 | operators->emplace_back(&AS_BIT_XOR); | ||||
456 | if (fileType == C_TYPE) | 522 | if (fileType == C_TYPE) | ||
457 | { | 523 | { | ||
458 | operators->push_back(&AS_GCC_MIN_ASSIGN); | 524 | operators->emplace_back(&AS_GCC_MIN_ASSIGN); | ||
459 | operators->push_back(&AS_GCC_MAX_ASSIGN); | 525 | operators->emplace_back(&AS_GCC_MAX_ASSIGN); | ||
460 | } | 526 | } | ||
527 | | ||||
528 | assert(operators->size() < elements); | ||||
461 | sort(operators->begin(), operators->end(), sortOnLength); | 529 | sort(operators->begin(), operators->end(), sortOnLength); | ||
462 | } | 530 | } | ||
463 | 531 | | |||
464 | /** | 532 | /** | ||
465 | * Build the vector of pre-block statements. | 533 | * Build the vector of pre-block statements. | ||
466 | * Used by ONLY ASBeautifier.cpp | 534 | * Used by ONLY ASBeautifier.cpp | ||
467 | * NOTE: Cannot be both a header and a preBlockStatement. | 535 | * NOTE: Cannot be both a header and a preBlockStatement. | ||
468 | * | 536 | * | ||
469 | * @param preBlockStatements a reference to the vector to be built. | 537 | * @param preBlockStatements a reference to the vector to be built. | ||
470 | */ | 538 | */ | ||
471 | void ASResource::buildPreBlockStatements(vector<const string*>* preBlockStatements, int fileType) | 539 | void ASResource::buildPreBlockStatements(vector<const string*>* preBlockStatements, int fileType) | ||
472 | { | 540 | { | ||
473 | preBlockStatements->push_back(&AS_CLASS); | 541 | const size_t elements = 10; | ||
542 | static bool reserved = false; | ||||
543 | if (!reserved) | ||||
544 | { | ||||
545 | preBlockStatements->reserve(elements); | ||||
546 | reserved = true; | ||||
547 | } | ||||
548 | | ||||
549 | preBlockStatements->emplace_back(&AS_CLASS); | ||||
474 | if (fileType == C_TYPE) | 550 | if (fileType == C_TYPE) | ||
475 | { | 551 | { | ||
476 | preBlockStatements->push_back(&AS_STRUCT); | 552 | preBlockStatements->emplace_back(&AS_STRUCT); | ||
477 | preBlockStatements->push_back(&AS_UNION); | 553 | preBlockStatements->emplace_back(&AS_UNION); | ||
478 | preBlockStatements->push_back(&AS_NAMESPACE); | 554 | preBlockStatements->emplace_back(&AS_NAMESPACE); | ||
479 | preBlockStatements->push_back(&AS_MODULE); // for CORBA IDL | 555 | preBlockStatements->emplace_back(&AS_MODULE); // for CORBA IDL | ||
480 | preBlockStatements->push_back(&AS_INTERFACE); // for CORBA IDL | 556 | preBlockStatements->emplace_back(&AS_INTERFACE); // for CORBA IDL | ||
481 | } | 557 | } | ||
482 | if (fileType == JAVA_TYPE) | 558 | if (fileType == JAVA_TYPE) | ||
483 | { | 559 | { | ||
484 | preBlockStatements->push_back(&AS_INTERFACE); | 560 | preBlockStatements->emplace_back(&AS_INTERFACE); | ||
485 | preBlockStatements->push_back(&AS_THROWS); | 561 | preBlockStatements->emplace_back(&AS_THROWS); | ||
486 | } | 562 | } | ||
487 | if (fileType == SHARP_TYPE) | 563 | if (fileType == SHARP_TYPE) | ||
488 | { | 564 | { | ||
489 | preBlockStatements->push_back(&AS_INTERFACE); | 565 | preBlockStatements->emplace_back(&AS_INTERFACE); | ||
490 | preBlockStatements->push_back(&AS_NAMESPACE); | 566 | preBlockStatements->emplace_back(&AS_NAMESPACE); | ||
491 | preBlockStatements->push_back(&AS_WHERE); | 567 | preBlockStatements->emplace_back(&AS_WHERE); | ||
492 | preBlockStatements->push_back(&AS_STRUCT); | 568 | preBlockStatements->emplace_back(&AS_STRUCT); | ||
493 | } | 569 | } | ||
570 | | ||||
571 | assert(preBlockStatements->size() < elements); | ||||
494 | sort(preBlockStatements->begin(), preBlockStatements->end(), sortOnName); | 572 | sort(preBlockStatements->begin(), preBlockStatements->end(), sortOnName); | ||
495 | } | 573 | } | ||
496 | 574 | | |||
497 | /** | 575 | /** | ||
498 | * Build the vector of pre-command headers. | 576 | * Build the vector of pre-command headers. | ||
499 | * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp. | 577 | * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp. | ||
500 | * NOTE: Cannot be both a header and a preCommandHeader. | 578 | * NOTE: Cannot be both a header and a preCommandHeader. | ||
501 | * | 579 | * | ||
502 | * A preCommandHeader is in a function definition between | 580 | * A preCommandHeader is in a function definition between | ||
503 | * the closing paren and the opening bracket. | 581 | * the closing paren and the opening brace. | ||
504 | * e.g. in "void foo() const {}", "const" is a preCommandHeader. | 582 | * e.g. in "void foo() const {}", "const" is a preCommandHeader. | ||
505 | */ | 583 | */ | ||
506 | void ASResource::buildPreCommandHeaders(vector<const string*>* preCommandHeaders, int fileType) | 584 | void ASResource::buildPreCommandHeaders(vector<const string*>* preCommandHeaders, int fileType) | ||
507 | { | 585 | { | ||
586 | const size_t elements = 10; | ||||
587 | static bool reserved = false; | ||||
588 | if (!reserved) | ||||
589 | { | ||||
590 | preCommandHeaders->reserve(elements); | ||||
591 | reserved = true; | ||||
592 | } | ||||
593 | | ||||
508 | if (fileType == C_TYPE) | 594 | if (fileType == C_TYPE) | ||
509 | { | 595 | { | ||
510 | preCommandHeaders->push_back(&AS_CONST); | 596 | preCommandHeaders->emplace_back(&AS_CONST); | ||
511 | preCommandHeaders->push_back(&AS_VOLATILE); | 597 | preCommandHeaders->emplace_back(&AS_FINAL); | ||
512 | preCommandHeaders->push_back(&AS_INTERRUPT); | 598 | preCommandHeaders->emplace_back(&AS_INTERRUPT); | ||
513 | preCommandHeaders->push_back(&AS_NOEXCEPT); | 599 | preCommandHeaders->emplace_back(&AS_NOEXCEPT); | ||
514 | preCommandHeaders->push_back(&AS_OVERRIDE); | 600 | preCommandHeaders->emplace_back(&AS_OVERRIDE); | ||
515 | preCommandHeaders->push_back(&AS_SEALED); // Visual C only | 601 | preCommandHeaders->emplace_back(&AS_VOLATILE); | ||
516 | preCommandHeaders->push_back(&AS_AUTORELEASEPOOL); // Obj-C only | 602 | preCommandHeaders->emplace_back(&AS_SEALED); // Visual C only | ||
603 | preCommandHeaders->emplace_back(&AS_AUTORELEASEPOOL); // Obj-C only | ||||
517 | } | 604 | } | ||
518 | 605 | | |||
519 | if (fileType == JAVA_TYPE) | 606 | if (fileType == JAVA_TYPE) | ||
520 | { | 607 | { | ||
521 | preCommandHeaders->push_back(&AS_THROWS); | 608 | preCommandHeaders->emplace_back(&AS_THROWS); | ||
522 | } | 609 | } | ||
523 | 610 | | |||
524 | if (fileType == SHARP_TYPE) | 611 | if (fileType == SHARP_TYPE) | ||
525 | { | 612 | { | ||
526 | preCommandHeaders->push_back(&AS_WHERE); | 613 | preCommandHeaders->emplace_back(&AS_WHERE); | ||
527 | } | 614 | } | ||
528 | 615 | | |||
616 | assert(preCommandHeaders->size() < elements); | ||||
529 | sort(preCommandHeaders->begin(), preCommandHeaders->end(), sortOnName); | 617 | sort(preCommandHeaders->begin(), preCommandHeaders->end(), sortOnName); | ||
530 | } | 618 | } | ||
531 | 619 | | |||
532 | /** | 620 | /** | ||
533 | * Build the vector of pre-definition headers. | 621 | * Build the vector of pre-definition headers. | ||
534 | * Used by ONLY ASFormatter.cpp | 622 | * Used by ONLY ASFormatter.cpp | ||
535 | * NOTE: Do NOT add 'enum' here. It is an array type bracket. | 623 | * NOTE: Do NOT add 'enum' here. It is an array type brace. | ||
536 | * NOTE: Do NOT add 'extern' here. Do not want an extra indent. | 624 | * NOTE: Do NOT add 'extern' here. Do not want an extra indent. | ||
537 | * | 625 | * | ||
538 | * @param preDefinitionHeaders a reference to the vector to be built. | 626 | * @param preDefinitionHeaders a reference to the vector to be built. | ||
539 | */ | 627 | */ | ||
540 | void ASResource::buildPreDefinitionHeaders(vector<const string*>* preDefinitionHeaders, int fileType) | 628 | void ASResource::buildPreDefinitionHeaders(vector<const string*>* preDefinitionHeaders, int fileType) | ||
541 | { | 629 | { | ||
542 | preDefinitionHeaders->push_back(&AS_CLASS); | 630 | const size_t elements = 10; | ||
631 | static bool reserved = false; | ||||
632 | if (!reserved) | ||||
633 | { | ||||
634 | preDefinitionHeaders->reserve(elements); | ||||
635 | reserved = true; | ||||
636 | } | ||||
637 | | ||||
638 | preDefinitionHeaders->emplace_back(&AS_CLASS); | ||||
543 | if (fileType == C_TYPE) | 639 | if (fileType == C_TYPE) | ||
544 | { | 640 | { | ||
545 | preDefinitionHeaders->push_back(&AS_STRUCT); | 641 | preDefinitionHeaders->emplace_back(&AS_STRUCT); | ||
546 | preDefinitionHeaders->push_back(&AS_UNION); | 642 | preDefinitionHeaders->emplace_back(&AS_UNION); | ||
547 | preDefinitionHeaders->push_back(&AS_NAMESPACE); | 643 | preDefinitionHeaders->emplace_back(&AS_NAMESPACE); | ||
548 | preDefinitionHeaders->push_back(&AS_MODULE); // for CORBA IDL | 644 | preDefinitionHeaders->emplace_back(&AS_MODULE); // for CORBA IDL | ||
549 | preDefinitionHeaders->push_back(&AS_INTERFACE); // for CORBA IDL | 645 | preDefinitionHeaders->emplace_back(&AS_INTERFACE); // for CORBA IDL | ||
550 | } | 646 | } | ||
551 | if (fileType == JAVA_TYPE) | 647 | if (fileType == JAVA_TYPE) | ||
552 | { | 648 | { | ||
553 | preDefinitionHeaders->push_back(&AS_INTERFACE); | 649 | preDefinitionHeaders->emplace_back(&AS_INTERFACE); | ||
554 | } | 650 | } | ||
555 | if (fileType == SHARP_TYPE) | 651 | if (fileType == SHARP_TYPE) | ||
556 | { | 652 | { | ||
557 | preDefinitionHeaders->push_back(&AS_STRUCT); | 653 | preDefinitionHeaders->emplace_back(&AS_STRUCT); | ||
558 | preDefinitionHeaders->push_back(&AS_INTERFACE); | 654 | preDefinitionHeaders->emplace_back(&AS_INTERFACE); | ||
559 | preDefinitionHeaders->push_back(&AS_NAMESPACE); | 655 | preDefinitionHeaders->emplace_back(&AS_NAMESPACE); | ||
560 | } | 656 | } | ||
657 | | ||||
658 | assert(preDefinitionHeaders->size() < elements); | ||||
561 | sort(preDefinitionHeaders->begin(), preDefinitionHeaders->end(), sortOnName); | 659 | sort(preDefinitionHeaders->begin(), preDefinitionHeaders->end(), sortOnName); | ||
562 | } | 660 | } | ||
563 | 661 | | |||
564 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 662 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
565 | * ASBase Functions | 663 | * ASBase Functions | ||
566 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | 664 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
567 | 665 | | |||
666 | // check if a specific line position contains a header. | ||||
667 | const string* ASBase::findHeader(const string& line, int i, | ||||
668 | const vector<const string*>* possibleHeaders) const | ||||
669 | { | ||||
670 | assert(isCharPotentialHeader(line, i)); | ||||
671 | // check the word | ||||
672 | size_t maxHeaders = possibleHeaders->size(); | ||||
673 | for (size_t p = 0; p < maxHeaders; p++) | ||||
674 | { | ||||
675 | const string* header = (*possibleHeaders)[p]; | ||||
676 | const size_t wordEnd = i + header->length(); | ||||
677 | if (wordEnd > line.length()) | ||||
678 | continue; | ||||
679 | int result = (line.compare(i, header->length(), *header)); | ||||
680 | if (result > 0) | ||||
681 | continue; | ||||
682 | if (result < 0) | ||||
683 | break; | ||||
684 | // check that this is not part of a longer word | ||||
685 | if (wordEnd == line.length()) | ||||
686 | return header; | ||||
687 | if (isLegalNameChar(line[wordEnd])) | ||||
688 | continue; | ||||
689 | const char peekChar = peekNextChar(line, wordEnd - 1); | ||||
690 | // is not a header if part of a definition | ||||
691 | if (peekChar == ',' || peekChar == ')') | ||||
692 | break; | ||||
693 | // the following accessor definitions are NOT headers | ||||
694 | // goto default; is NOT a header | ||||
695 | // default(int) keyword in C# is NOT a header | ||||
696 | else if ((header == &AS_GET | ||||
697 | || header == &AS_SET | ||||
698 | || header == &AS_DEFAULT) | ||||
699 | && (peekChar == ';' || peekChar == '(' || peekChar == '=')) | ||||
700 | break; | ||||
701 | return header; | ||||
702 | } | ||||
703 | return nullptr; | ||||
704 | } | ||||
705 | | ||||
568 | // check if a specific line position contains a keyword. | 706 | // check if a specific line position contains a keyword. | ||
569 | bool ASBase::findKeyword(const string& line, int i, const string& keyword) const | 707 | bool ASBase::findKeyword(const string& line, int i, const string& keyword) const | ||
570 | { | 708 | { | ||
571 | assert(isCharPotentialHeader(line, i)); | 709 | assert(isCharPotentialHeader(line, i)); | ||
572 | // check the word | 710 | // check the word | ||
573 | const size_t keywordLength = keyword.length(); | 711 | const size_t keywordLength = keyword.length(); | ||
574 | const size_t wordEnd = i + keywordLength; | 712 | const size_t wordEnd = i + keywordLength; | ||
575 | if (wordEnd > line.length()) | 713 | if (wordEnd > line.length()) | ||
576 | return false; | 714 | return false; | ||
577 | if (line.compare(i, keywordLength, keyword) != 0) | 715 | if (line.compare(i, keywordLength, keyword) != 0) | ||
578 | return false; | 716 | return false; | ||
579 | // check that this is not part of a longer word | 717 | // check that this is not part of a longer word | ||
580 | if (wordEnd == line.length()) | 718 | if (wordEnd == line.length()) | ||
581 | return true; | 719 | return true; | ||
582 | if (isLegalNameChar(line[wordEnd])) | 720 | if (isLegalNameChar(line[wordEnd])) | ||
583 | return false; | 721 | return false; | ||
584 | // is not a keyword if part of a definition | 722 | // is not a keyword if part of a definition | ||
585 | const char peekChar = peekNextChar(line, (int)wordEnd - 1); | 723 | const char peekChar = peekNextChar(line, (int) wordEnd - 1); | ||
586 | if (peekChar == ',' || peekChar == ')') | 724 | if (peekChar == ',' || peekChar == ')') | ||
587 | return false; | 725 | return false; | ||
588 | return true; | 726 | return true; | ||
589 | } | 727 | } | ||
590 | 728 | | |||
729 | // check if a specific line position contains an operator. | ||||
730 | const string* ASBase::findOperator(const string& line, int i, | ||||
731 | const vector<const string*>* possibleOperators) const | ||||
732 | { | ||||
733 | assert(isCharPotentialOperator(line[i])); | ||||
734 | // find the operator in the vector | ||||
735 | // the vector contains the LONGEST operators first | ||||
736 | // must loop thru the entire vector | ||||
737 | size_t maxOperators = possibleOperators->size(); | ||||
738 | for (size_t p = 0; p < maxOperators; p++) | ||||
739 | { | ||||
740 | const size_t wordEnd = i + (*(*possibleOperators)[p]).length(); | ||||
741 | if (wordEnd > line.length()) | ||||
742 | continue; | ||||
743 | if (line.compare(i, (*(*possibleOperators)[p]).length(), *(*possibleOperators)[p]) == 0) | ||||
744 | return (*possibleOperators)[p]; | ||||
745 | } | ||||
746 | return nullptr; | ||||
747 | } | ||||
748 | | ||||
591 | // get the current word on a line | 749 | // get the current word on a line | ||
592 | // index must point to the beginning of the word | 750 | // index must point to the beginning of the word | ||
593 | string ASBase::getCurrentWord(const string& line, size_t index) const | 751 | string ASBase::getCurrentWord(const string& line, size_t index) const | ||
594 | { | 752 | { | ||
595 | assert(isCharPotentialHeader(line, index)); | 753 | assert(isCharPotentialHeader(line, index)); | ||
596 | size_t lineLength = line.length(); | 754 | size_t lineLength = line.length(); | ||
597 | size_t i; | 755 | size_t i; | ||
598 | for (i = index; i < lineLength; i++) | 756 | for (i = index; i < lineLength; i++) | ||
599 | { | 757 | { | ||
600 | if (!isLegalNameChar(line[i])) | 758 | if (!isLegalNameChar(line[i])) | ||
601 | break; | 759 | break; | ||
602 | } | 760 | } | ||
603 | return line.substr(index, i - index); | 761 | return line.substr(index, i - index); | ||
604 | } | 762 | } | ||
605 | 763 | | |||
606 | // check if a specific character can be used in a legal variable/method/class name | 764 | // check if a specific character can be used in a legal variable/method/class name | ||
607 | bool ASBase::isLegalNameChar(char ch) const | 765 | bool ASBase::isLegalNameChar(char ch) const | ||
608 | { | 766 | { | ||
609 | if (isWhiteSpace(ch)) | 767 | if (isWhiteSpace(ch)) | ||
610 | return false; | 768 | return false; | ||
611 | if ((unsigned) ch > 127) | 769 | if ((unsigned char) ch > 127) | ||
612 | return false; | 770 | return false; | ||
613 | return (isalnum((unsigned char) ch) | 771 | return (isalnum((unsigned char) ch) | ||
614 | || ch == '.' || ch == '_' | 772 | || ch == '.' || ch == '_' | ||
615 | || (isJavaStyle() && ch == '$') | 773 | || (isJavaStyle() && ch == '$') | ||
616 | || (isSharpStyle() && ch == '@')); // may be used as a prefix | 774 | || (isSharpStyle() && ch == '@')); // may be used as a prefix | ||
617 | } | 775 | } | ||
618 | 776 | | |||
619 | // check if a specific character can be part of a header | 777 | // check if a specific character can be part of a header | ||
620 | bool ASBase::isCharPotentialHeader(const string& line, size_t i) const | 778 | bool ASBase::isCharPotentialHeader(const string& line, size_t i) const | ||
621 | { | 779 | { | ||
622 | assert(!isWhiteSpace(line[i])); | 780 | assert(!isWhiteSpace(line[i])); | ||
623 | char prevCh = ' '; | 781 | char prevCh = ' '; | ||
624 | if (i > 0) | 782 | if (i > 0) | ||
625 | prevCh = line[i - 1]; | 783 | prevCh = line[i - 1]; | ||
784 | if (i > 1 && line[i - 2] == '\\') | ||||
785 | prevCh = ' '; | ||||
626 | if (!isLegalNameChar(prevCh) && isLegalNameChar(line[i])) | 786 | if (!isLegalNameChar(prevCh) && isLegalNameChar(line[i])) | ||
627 | return true; | 787 | return true; | ||
628 | return false; | 788 | return false; | ||
629 | } | 789 | } | ||
630 | 790 | | |||
631 | // check if a specific character can be part of an operator | 791 | // check if a specific character can be part of an operator | ||
632 | bool ASBase::isCharPotentialOperator(char ch) const | 792 | bool ASBase::isCharPotentialOperator(char ch) const | ||
633 | { | 793 | { | ||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |