~ubuntu-branches/ubuntu/karmic/kdevelop/karmic

« back to all changes in this revision

Viewing changes to formatters/lib/ASResource.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2009-05-25 19:34:26 UTC
  • mfrom: (1.1.11 upstream) (2.3.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090525193426-hdntv90rvflyew8g
Tags: 4:3.9.93-1ubuntu1
* Merge from Debian experimental, remaining changes:
  - Conflict/replace -kde4 packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
2
 *
 
3
 *   ASResource.cpp
 
4
 *
 
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
 
8
 *
 
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
 
14
 *   version.
 
15
 *
 
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.
 
20
 *
 
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.
 
25
 *
 
26
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
27
 */
 
28
 
 
29
#include "astyle.h"
 
30
 
 
31
 
 
32
namespace astyle
 
33
{
 
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");
 
60
 
 
61
const string ASResource::AS_ASM = string("asm");
 
62
 
 
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");
 
68
 
 
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("*/");
 
74
 
 
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");
 
92
 
 
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("[]");
 
109
 
 
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(";");
 
126
 
 
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");
 
135
 
 
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");
 
140
 
 
141
 
 
142
/**
 
143
 * Build the vector of assignment operators.
 
144
 * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
 
145
 *
 
146
 * @param assignmentOperators   a reference to the vector to be built.
 
147
 */
 
148
void ASResource::buildAssignmentOperators(vector<const string*> &assignmentOperators)
 
149
{
 
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);
 
159
 
 
160
        // Java
 
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);
 
164
 
 
165
        // Unknown
 
166
        assignmentOperators.push_back(&AS_LS_LS_LS_ASSIGN);
 
167
 
 
168
        assignmentOperators.push_back(&AS_RETURN);
 
169
        assignmentOperators.push_back(&AS_CIN);
 
170
        assignmentOperators.push_back(&AS_COUT);
 
171
        assignmentOperators.push_back(&AS_CERR);
 
172
}
 
173
 
 
174
/**
 
175
 * Build the vector of C++ cast operators.
 
176
 * Used by ONLY ASFormatter.cpp
 
177
 *
 
178
 * @param castOperators     a reference to the vector to be built.
 
179
 */
 
180
void ASResource::buildCastOperators(vector<const string*> &castOperators)
 
181
{
 
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);
 
186
}
 
187
 
 
188
/**
 
189
 * Build the vector of header words.
 
190
 * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
 
191
 *
 
192
 * @param headers       a reference to the vector to be built.
 
193
 */
 
194
void ASResource::buildHeaders(vector<const string*> &headers, int fileType, bool beautifier)
 
195
{
 
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);
 
204
 
 
205
        if (beautifier)
 
206
        {
 
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);
 
213
        }
 
214
 
 
215
        if (fileType == JAVA_TYPE)
 
216
        {
 
217
                headers.push_back(&AS_FINALLY);
 
218
                headers.push_back(&AS_SYNCHRONIZED);
 
219
        }
 
220
 
 
221
        if (fileType == SHARP_TYPE)
 
222
        {
 
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);
 
232
        }
 
233
}
 
234
 
 
235
/**
 
236
 * Build the vector of non-assignment operators.
 
237
 * Used by ONLY ASBeautifier.cpp
 
238
 *
 
239
 * @param nonAssignmentOperators       a reference to the vector to be built.
 
240
 */
 
241
void ASResource::buildNonAssignmentOperators(vector<const string*> &nonAssignmentOperators)
 
242
{
 
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);
 
256
}
 
257
 
 
258
/**
 
259
 * Build the vector of header non-paren headers.
 
260
 * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
 
261
 *
 
262
 * @param nonParenHeaders       a reference to the vector to be built.
 
263
 */
 
264
void ASResource::buildNonParenHeaders(vector<const string*> &nonParenHeaders, int fileType, bool beautifier)
 
265
{
 
266
        nonParenHeaders.push_back(&AS_ELSE);
 
267
        nonParenHeaders.push_back(&AS_DO);
 
268
        nonParenHeaders.push_back(&AS_TRY);
 
269
 
 
270
        if (beautifier)
 
271
        {
 
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);
 
278
        }
 
279
 
 
280
        if (fileType == JAVA_TYPE)
 
281
        {
 
282
                nonParenHeaders.push_back(&AS_FINALLY);
 
283
        }
 
284
 
 
285
        if (fileType == SHARP_TYPE)
 
286
        {
 
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);
 
294
        }
 
295
}
 
296
 
 
297
/**
 
298
 * Build the vector of operators.
 
299
 * Used by ONLY ASFormatter.cpp
 
300
 *
 
301
 * @param operators             a reference to the vector to be built.
 
302
 */
 
303
void ASResource::buildOperators(vector<const string*> &operators)
 
304
{
 
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);
 
349
}
 
350
 
 
351
/**
 
352
 * Build the vector of pre-block statements.
 
353
 * Used by ONLY ASBeautifier.cpp
 
354
 *
 
355
 * @param preBlockStatements        a reference to the vector to be built.
 
356
 */
 
357
void ASResource::buildPreBlockStatements(vector<const string*> &preBlockStatements)
 
358
{
 
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);
 
366
}
 
367
 
 
368
/**
 
369
 * Build the vector of pre-command headers.
 
370
 * Used by ONLY ASFormatter.cpp
 
371
 *
 
372
 * @param preCommandHeaders     a reference to the vector to be built.
 
373
 */
 
374
void ASResource::buildPreCommandHeaders(vector<const string*> &preCommandHeaders)
 
375
{
 
376
        preCommandHeaders.push_back(&AS_EXTERN);
 
377
        preCommandHeaders.push_back(&AS_THROWS);
 
378
        preCommandHeaders.push_back(&AS_CONST);
 
379
}
 
380
 
 
381
/**
 
382
 * Build the vector of pre-definition headers.
 
383
 * Used by ONLY ASFormatter.cpp
 
384
 *
 
385
 * @param preDefinitionHeaders      a reference to the vector to be built.
 
386
 */
 
387
void ASResource::buildPreDefinitionHeaders(vector<const string*> &preDefinitionHeaders)
 
388
{
 
389
        preDefinitionHeaders.push_back(&AS_CLASS);
 
390
        preDefinitionHeaders.push_back(&AS_INTERFACE);
 
391
        preDefinitionHeaders.push_back(&AS_NAMESPACE);
 
392
        preDefinitionHeaders.push_back(&AS_STRUCT);
 
393
}
 
394
 
 
395
 
 
396
}   // end namespace astyle