1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
5
* This file is a part of "Artistic Style" - an indentation and
6
* reformatting tool for C, C++, C# and Java source files.
7
* http://astyle.sourceforge.net
9
* The "Artistic Style" project, including all files needed to
10
* compile it, is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public
12
* License as published by the Free Software Foundation; either
13
* version 2.1 of the License, or (at your option) any later
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Lesser General Public License for more details.
21
* You should have received a copy of the GNU Lesser General Public
22
* License along with this project; if not, write to the
23
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24
* Boston, MA 02110-1301, USA.
26
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
34
const string ASResource::AS_IF = string("if");
35
const string ASResource::AS_ELSE = string("else");
36
const string ASResource::AS_FOR = string("for");
37
const string ASResource::AS_DO = string("do");
38
const string ASResource::AS_WHILE = string("while");
39
const string ASResource::AS_SWITCH = string("switch");
40
const string ASResource::AS_CASE = string("case");
41
const string ASResource::AS_DEFAULT = string("default");
42
const string ASResource::AS_CLASS = string("class");
43
const string ASResource::AS_STRUCT = string("struct");
44
const string ASResource::AS_UNION = string("union");
45
const string ASResource::AS_INTERFACE = string("interface");
46
const string ASResource::AS_NAMESPACE = string("namespace");
47
const string ASResource::AS_EXTERN = string("extern");
48
const string ASResource::AS_PUBLIC = string("public");
49
const string ASResource::AS_PROTECTED = string("protected");
50
const string ASResource::AS_PRIVATE = string("private");
51
const string ASResource::AS_STATIC = string("static");
52
const string ASResource::AS_SYNCHRONIZED = string("synchronized");
53
const string ASResource::AS_OPERATOR = string("operator");
54
const string ASResource::AS_TEMPLATE = string("template");
55
const string ASResource::AS_TRY = string("try");
56
const string ASResource::AS_CATCH = string("catch");
57
const string ASResource::AS_FINALLY = string("finally");
58
const string ASResource::AS_THROWS = string("throws");
59
const string ASResource::AS_CONST = string("const");
61
const string ASResource::AS_ASM = string("asm");
63
const string ASResource::AS_BAR_DEFINE = string("#define");
64
const string ASResource::AS_BAR_INCLUDE = string("#include");
65
const string ASResource::AS_BAR_IF = string("#if");
66
const string ASResource::AS_BAR_EL = string("#el");
67
const string ASResource::AS_BAR_ENDIF = string("#endif");
69
const string ASResource::AS_OPEN_BRACKET = string("{");
70
const string ASResource::AS_CLOSE_BRACKET = string("}");
71
const string ASResource::AS_OPEN_LINE_COMMENT = string("//");
72
const string ASResource::AS_OPEN_COMMENT = string("/*");
73
const string ASResource::AS_CLOSE_COMMENT = string("*/");
75
const string ASResource::AS_ASSIGN = string("=");
76
const string ASResource::AS_PLUS_ASSIGN = string("+=");
77
const string ASResource::AS_MINUS_ASSIGN = string("-=");
78
const string ASResource::AS_MULT_ASSIGN = string("*=");
79
const string ASResource::AS_DIV_ASSIGN = string("/=");
80
const string ASResource::AS_MOD_ASSIGN = string("%=");
81
const string ASResource::AS_OR_ASSIGN = string("|=");
82
const string ASResource::AS_AND_ASSIGN = string("&=");
83
const string ASResource::AS_XOR_ASSIGN = string("^=");
84
const string ASResource::AS_GR_GR_ASSIGN = string(">>=");
85
const string ASResource::AS_LS_LS_ASSIGN = string("<<=");
86
const string ASResource::AS_GR_GR_GR_ASSIGN = string(">>>=");
87
const string ASResource::AS_LS_LS_LS_ASSIGN = string("<<<=");
88
const string ASResource::AS_RETURN = string("return");
89
const string ASResource::AS_CIN = string("cin");
90
const string ASResource::AS_COUT = string("cout");
91
const string ASResource::AS_CERR = string("cerr");
93
const string ASResource::AS_EQUAL = string("==");
94
const string ASResource::AS_PLUS_PLUS = string("++");
95
const string ASResource::AS_MINUS_MINUS = string("--");
96
const string ASResource::AS_NOT_EQUAL = string("!=");
97
const string ASResource::AS_GR_EQUAL = string(">=");
98
const string ASResource::AS_GR_GR = string(">>");
99
const string ASResource::AS_GR_GR_GR = string(">>>");
100
const string ASResource::AS_LS_EQUAL = string("<=");
101
const string ASResource::AS_LS_LS = string("<<");
102
const string ASResource::AS_LS_LS_LS = string("<<<");
103
const string ASResource::AS_ARROW = string("->");
104
const string ASResource::AS_AND = string("&&");
105
const string ASResource::AS_OR = string("||");
106
const string ASResource::AS_COLON_COLON = string("::");
107
const string ASResource::AS_PAREN_PAREN = string("()");
108
const string ASResource::AS_BLPAREN_BLPAREN = string("[]");
110
const string ASResource::AS_PLUS = string("+");
111
const string ASResource::AS_MINUS = string("-");
112
const string ASResource::AS_MULT = string("*");
113
const string ASResource::AS_DIV = string("/");
114
const string ASResource::AS_MOD = string("%");
115
const string ASResource::AS_GR = string(">");
116
const string ASResource::AS_LS = string("<");
117
const string ASResource::AS_NOT = string("!");
118
const string ASResource::AS_BIT_OR = string("|");
119
const string ASResource::AS_BIT_AND = string("&");
120
const string ASResource::AS_BIT_NOT = string("~");
121
const string ASResource::AS_BIT_XOR = string("^");
122
const string ASResource::AS_QUESTION = string("?");
123
const string ASResource::AS_COLON = string(":");
124
const string ASResource::AS_COMMA = string(",");
125
const string ASResource::AS_SEMICOLON = string(";");
127
const string ASResource::AS_FOREACH = string("foreach");
128
const string ASResource::AS_LOCK = string("lock");
129
const string ASResource::AS_UNSAFE = string("unsafe");
130
const string ASResource::AS_FIXED = string("fixed");
131
const string ASResource::AS_GET = string("get");
132
const string ASResource::AS_SET = string("set");
133
const string ASResource::AS_ADD = string("add");
134
const string ASResource::AS_REMOVE = string("remove");
136
const string ASResource::AS_CONST_CAST = string("const_cast");
137
const string ASResource::AS_DYNAMIC_CAST = string("dynamic_cast");
138
const string ASResource::AS_REINTERPRET_CAST = string("reinterpret_cast");
139
const string ASResource::AS_STATIC_CAST = string("static_cast");
143
* Build the vector of assignment operators.
144
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
146
* @param assignmentOperators a reference to the vector to be built.
148
void ASResource::buildAssignmentOperators(vector<const string*> &assignmentOperators)
150
assignmentOperators.push_back(&AS_ASSIGN);
151
assignmentOperators.push_back(&AS_PLUS_ASSIGN);
152
assignmentOperators.push_back(&AS_MINUS_ASSIGN);
153
assignmentOperators.push_back(&AS_MULT_ASSIGN);
154
assignmentOperators.push_back(&AS_DIV_ASSIGN);
155
assignmentOperators.push_back(&AS_MOD_ASSIGN);
156
assignmentOperators.push_back(&AS_OR_ASSIGN);
157
assignmentOperators.push_back(&AS_AND_ASSIGN);
158
assignmentOperators.push_back(&AS_XOR_ASSIGN);
161
assignmentOperators.push_back(&AS_GR_GR_GR_ASSIGN);
162
assignmentOperators.push_back(&AS_GR_GR_ASSIGN);
163
assignmentOperators.push_back(&AS_LS_LS_ASSIGN);
166
assignmentOperators.push_back(&AS_LS_LS_LS_ASSIGN);
168
assignmentOperators.push_back(&AS_RETURN);
169
assignmentOperators.push_back(&AS_CIN);
170
assignmentOperators.push_back(&AS_COUT);
171
assignmentOperators.push_back(&AS_CERR);
175
* Build the vector of C++ cast operators.
176
* Used by ONLY ASFormatter.cpp
178
* @param castOperators a reference to the vector to be built.
180
void ASResource::buildCastOperators(vector<const string*> &castOperators)
182
castOperators.push_back(&AS_CONST_CAST);
183
castOperators.push_back(&AS_DYNAMIC_CAST);
184
castOperators.push_back(&AS_REINTERPRET_CAST);
185
castOperators.push_back(&AS_STATIC_CAST);
189
* Build the vector of header words.
190
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
192
* @param headers a reference to the vector to be built.
194
void ASResource::buildHeaders(vector<const string*> &headers, int fileType, bool beautifier)
196
headers.push_back(&AS_IF);
197
headers.push_back(&AS_ELSE);
198
headers.push_back(&AS_FOR);
199
headers.push_back(&AS_WHILE);
200
headers.push_back(&AS_DO);
201
headers.push_back(&AS_SWITCH);
202
headers.push_back(&AS_TRY);
203
headers.push_back(&AS_CATCH);
207
headers.push_back(&AS_CASE);
208
headers.push_back(&AS_DEFAULT);
209
headers.push_back(&AS_CONST);
210
headers.push_back(&AS_STATIC);
211
headers.push_back(&AS_EXTERN);
212
headers.push_back(&AS_TEMPLATE);
215
if (fileType == JAVA_TYPE)
217
headers.push_back(&AS_FINALLY);
218
headers.push_back(&AS_SYNCHRONIZED);
221
if (fileType == SHARP_TYPE)
223
headers.push_back(&AS_FINALLY);
224
headers.push_back(&AS_FOREACH);
225
headers.push_back(&AS_LOCK);
226
headers.push_back(&AS_UNSAFE);
227
headers.push_back(&AS_FIXED);
228
headers.push_back(&AS_GET);
229
headers.push_back(&AS_SET);
230
headers.push_back(&AS_ADD);
231
headers.push_back(&AS_REMOVE);
236
* Build the vector of non-assignment operators.
237
* Used by ONLY ASBeautifier.cpp
239
* @param nonAssignmentOperators a reference to the vector to be built.
241
void ASResource::buildNonAssignmentOperators(vector<const string*> &nonAssignmentOperators)
243
nonAssignmentOperators.push_back(&AS_EQUAL);
244
nonAssignmentOperators.push_back(&AS_PLUS_PLUS);
245
nonAssignmentOperators.push_back(&AS_MINUS_MINUS);
246
nonAssignmentOperators.push_back(&AS_NOT_EQUAL);
247
nonAssignmentOperators.push_back(&AS_GR_EQUAL);
248
nonAssignmentOperators.push_back(&AS_GR_GR_GR);
249
nonAssignmentOperators.push_back(&AS_GR_GR);
250
nonAssignmentOperators.push_back(&AS_LS_EQUAL);
251
nonAssignmentOperators.push_back(&AS_LS_LS_LS);
252
nonAssignmentOperators.push_back(&AS_LS_LS);
253
nonAssignmentOperators.push_back(&AS_ARROW);
254
nonAssignmentOperators.push_back(&AS_AND);
255
nonAssignmentOperators.push_back(&AS_OR);
259
* Build the vector of header non-paren headers.
260
* Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
262
* @param nonParenHeaders a reference to the vector to be built.
264
void ASResource::buildNonParenHeaders(vector<const string*> &nonParenHeaders, int fileType, bool beautifier)
266
nonParenHeaders.push_back(&AS_ELSE);
267
nonParenHeaders.push_back(&AS_DO);
268
nonParenHeaders.push_back(&AS_TRY);
272
nonParenHeaders.push_back(&AS_CASE);
273
nonParenHeaders.push_back(&AS_DEFAULT);
274
nonParenHeaders.push_back(&AS_CONST);
275
nonParenHeaders.push_back(&AS_STATIC);
276
nonParenHeaders.push_back(&AS_EXTERN);
277
nonParenHeaders.push_back(&AS_TEMPLATE);
280
if (fileType == JAVA_TYPE)
282
nonParenHeaders.push_back(&AS_FINALLY);
285
if (fileType == SHARP_TYPE)
287
nonParenHeaders.push_back(&AS_CATCH); // can be a paren or non-paren header
288
nonParenHeaders.push_back(&AS_FINALLY);
289
nonParenHeaders.push_back(&AS_UNSAFE);
290
nonParenHeaders.push_back(&AS_GET);
291
nonParenHeaders.push_back(&AS_SET);
292
nonParenHeaders.push_back(&AS_ADD);
293
nonParenHeaders.push_back(&AS_REMOVE);
298
* Build the vector of operators.
299
* Used by ONLY ASFormatter.cpp
301
* @param operators a reference to the vector to be built.
303
void ASResource::buildOperators(vector<const string*> &operators)
305
operators.push_back(&AS_PLUS_ASSIGN);
306
operators.push_back(&AS_MINUS_ASSIGN);
307
operators.push_back(&AS_MULT_ASSIGN);
308
operators.push_back(&AS_DIV_ASSIGN);
309
operators.push_back(&AS_MOD_ASSIGN);
310
operators.push_back(&AS_OR_ASSIGN);
311
operators.push_back(&AS_AND_ASSIGN);
312
operators.push_back(&AS_XOR_ASSIGN);
313
operators.push_back(&AS_EQUAL);
314
operators.push_back(&AS_PLUS_PLUS);
315
operators.push_back(&AS_MINUS_MINUS);
316
operators.push_back(&AS_NOT_EQUAL);
317
operators.push_back(&AS_GR_EQUAL);
318
operators.push_back(&AS_GR_GR_GR_ASSIGN);
319
operators.push_back(&AS_GR_GR_ASSIGN);
320
operators.push_back(&AS_GR_GR_GR);
321
operators.push_back(&AS_GR_GR);
322
operators.push_back(&AS_LS_EQUAL);
323
operators.push_back(&AS_LS_LS_LS_ASSIGN);
324
operators.push_back(&AS_LS_LS_ASSIGN);
325
operators.push_back(&AS_LS_LS_LS);
326
operators.push_back(&AS_LS_LS);
327
operators.push_back(&AS_ARROW);
328
operators.push_back(&AS_AND);
329
operators.push_back(&AS_OR);
330
operators.push_back(&AS_COLON_COLON);
331
operators.push_back(&AS_PLUS);
332
operators.push_back(&AS_MINUS);
333
operators.push_back(&AS_MULT);
334
operators.push_back(&AS_DIV);
335
operators.push_back(&AS_MOD);
336
operators.push_back(&AS_QUESTION);
337
operators.push_back(&AS_COLON);
338
operators.push_back(&AS_ASSIGN);
339
operators.push_back(&AS_LS);
340
operators.push_back(&AS_GR);
341
operators.push_back(&AS_NOT);
342
operators.push_back(&AS_BIT_OR);
343
operators.push_back(&AS_BIT_AND);
344
operators.push_back(&AS_BIT_NOT);
345
operators.push_back(&AS_BIT_XOR);
346
operators.push_back(&AS_OPERATOR);
347
operators.push_back(&AS_COMMA);
348
operators.push_back(&AS_RETURN);
352
* Build the vector of pre-block statements.
353
* Used by ONLY ASBeautifier.cpp
355
* @param preBlockStatements a reference to the vector to be built.
357
void ASResource::buildPreBlockStatements(vector<const string*> &preBlockStatements)
359
preBlockStatements.push_back(&AS_CLASS);
360
preBlockStatements.push_back(&AS_STRUCT);
361
preBlockStatements.push_back(&AS_UNION);
362
preBlockStatements.push_back(&AS_INTERFACE);
363
preBlockStatements.push_back(&AS_NAMESPACE);
364
preBlockStatements.push_back(&AS_THROWS);
365
preBlockStatements.push_back(&AS_EXTERN);
369
* Build the vector of pre-command headers.
370
* Used by ONLY ASFormatter.cpp
372
* @param preCommandHeaders a reference to the vector to be built.
374
void ASResource::buildPreCommandHeaders(vector<const string*> &preCommandHeaders)
376
preCommandHeaders.push_back(&AS_EXTERN);
377
preCommandHeaders.push_back(&AS_THROWS);
378
preCommandHeaders.push_back(&AS_CONST);
382
* Build the vector of pre-definition headers.
383
* Used by ONLY ASFormatter.cpp
385
* @param preDefinitionHeaders a reference to the vector to be built.
387
void ASResource::buildPreDefinitionHeaders(vector<const string*> &preDefinitionHeaders)
389
preDefinitionHeaders.push_back(&AS_CLASS);
390
preDefinitionHeaders.push_back(&AS_INTERFACE);
391
preDefinitionHeaders.push_back(&AS_NAMESPACE);
392
preDefinitionHeaders.push_back(&AS_STRUCT);
396
} // end namespace astyle