~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to lib/astyle/ASResource.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

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
 
 
90
 
const string ASResource::AS_EQUAL = string("==");
91
 
const string ASResource::AS_PLUS_PLUS = string("++");
92
 
const string ASResource::AS_MINUS_MINUS = string("--");
93
 
const string ASResource::AS_NOT_EQUAL = string("!=");
94
 
const string ASResource::AS_GR_EQUAL = string(">=");
95
 
const string ASResource::AS_GR_GR = string(">>");
96
 
const string ASResource::AS_GR_GR_GR = string(">>>");
97
 
const string ASResource::AS_LS_EQUAL = string("<=");
98
 
const string ASResource::AS_LS_LS = string("<<");
99
 
const string ASResource::AS_LS_LS_LS = string("<<<");
100
 
const string ASResource::AS_ARROW = string("->");
101
 
const string ASResource::AS_AND = string("&&");
102
 
const string ASResource::AS_OR = string("||");
103
 
const string ASResource::AS_COLON_COLON = string("::");
104
 
const string ASResource::AS_PAREN_PAREN = string("()");
105
 
const string ASResource::AS_BLPAREN_BLPAREN = string("[]");
106
 
 
107
 
const string ASResource::AS_PLUS = string("+");
108
 
const string ASResource::AS_MINUS = string("-");
109
 
const string ASResource::AS_MULT = string("*");
110
 
const string ASResource::AS_DIV = string("/");
111
 
const string ASResource::AS_MOD = string("%");
112
 
const string ASResource::AS_GR = string(">");
113
 
const string ASResource::AS_LS = string("<");
114
 
const string ASResource::AS_NOT = string("!");
115
 
const string ASResource::AS_BIT_OR = string("|");
116
 
const string ASResource::AS_BIT_AND = string("&");
117
 
const string ASResource::AS_BIT_NOT = string("~");
118
 
const string ASResource::AS_BIT_XOR = string("^");
119
 
const string ASResource::AS_QUESTION = string("?");
120
 
const string ASResource::AS_COLON = string(":");
121
 
const string ASResource::AS_COMMA = string(",");
122
 
const string ASResource::AS_SEMICOLON = string(";");
123
 
 
124
 
const string ASResource::AS_FOREACH = string("foreach");
125
 
const string ASResource::AS_LOCK = string("lock");
126
 
const string ASResource::AS_UNSAFE = string("unsafe");
127
 
const string ASResource::AS_FIXED = string("fixed");
128
 
const string ASResource::AS_GET = string("get");
129
 
const string ASResource::AS_SET = string("set");
130
 
const string ASResource::AS_ADD = string("add");
131
 
const string ASResource::AS_REMOVE = string("remove");
132
 
 
133
 
const string ASResource::AS_CONST_CAST = string("const_cast");
134
 
const string ASResource::AS_DYNAMIC_CAST = string("dynamic_cast");
135
 
const string ASResource::AS_REINTERPRET_CAST = string("reinterpret_cast");
136
 
const string ASResource::AS_STATIC_CAST = string("static_cast");
137
 
 
138
 
 
139
 
/**
140
 
 * Build the vector of assignment operators.
141
 
 * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
142
 
 *
143
 
 * @param assignmentOperators   a reference to the vector to be built.
144
 
 */
145
 
void ASResource::buildAssignmentOperators(vector<const string*> &assignmentOperators)
146
 
{
147
 
        assignmentOperators.push_back(&AS_ASSIGN);
148
 
        assignmentOperators.push_back(&AS_PLUS_ASSIGN);
149
 
        assignmentOperators.push_back(&AS_MINUS_ASSIGN);
150
 
        assignmentOperators.push_back(&AS_MULT_ASSIGN);
151
 
        assignmentOperators.push_back(&AS_DIV_ASSIGN);
152
 
        assignmentOperators.push_back(&AS_MOD_ASSIGN);
153
 
        assignmentOperators.push_back(&AS_OR_ASSIGN);
154
 
        assignmentOperators.push_back(&AS_AND_ASSIGN);
155
 
        assignmentOperators.push_back(&AS_XOR_ASSIGN);
156
 
 
157
 
        // Java
158
 
        assignmentOperators.push_back(&AS_GR_GR_GR_ASSIGN);
159
 
        assignmentOperators.push_back(&AS_GR_GR_ASSIGN);
160
 
        assignmentOperators.push_back(&AS_LS_LS_ASSIGN);
161
 
 
162
 
        // Unknown
163
 
        assignmentOperators.push_back(&AS_LS_LS_LS_ASSIGN);
164
 
 
165
 
        assignmentOperators.push_back(&AS_RETURN);
166
 
}
167
 
 
168
 
/**
169
 
 * Build the vector of C++ cast operators.
170
 
 * Used by ONLY ASFormatter.cpp
171
 
 *
172
 
 * @param castOperators     a reference to the vector to be built.
173
 
 */
174
 
void ASResource::buildCastOperators(vector<const string*> &castOperators)
175
 
{
176
 
        castOperators.push_back(&AS_CONST_CAST);
177
 
        castOperators.push_back(&AS_DYNAMIC_CAST);
178
 
        castOperators.push_back(&AS_REINTERPRET_CAST);
179
 
        castOperators.push_back(&AS_STATIC_CAST);
180
 
}
181
 
 
182
 
/**
183
 
 * Build the vector of header words.
184
 
 * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
185
 
 *
186
 
 * @param headers       a reference to the vector to be built.
187
 
 */
188
 
void ASResource::buildHeaders(vector<const string*> &headers, int fileType, bool beautifier)
189
 
{
190
 
        headers.push_back(&AS_IF);
191
 
        headers.push_back(&AS_ELSE);
192
 
        headers.push_back(&AS_FOR);
193
 
        headers.push_back(&AS_WHILE);
194
 
        headers.push_back(&AS_DO);
195
 
        headers.push_back(&AS_SWITCH);
196
 
        headers.push_back(&AS_TRY);
197
 
        headers.push_back(&AS_CATCH);
198
 
 
199
 
        if (beautifier)
200
 
        {
201
 
                headers.push_back(&AS_CASE);
202
 
                headers.push_back(&AS_DEFAULT);
203
 
                headers.push_back(&AS_CONST);
204
 
                headers.push_back(&AS_STATIC);
205
 
                headers.push_back(&AS_EXTERN);
206
 
                headers.push_back(&AS_TEMPLATE);
207
 
        }
208
 
 
209
 
        if (fileType == JAVA_TYPE)
210
 
        {
211
 
                headers.push_back(&AS_FINALLY);
212
 
                headers.push_back(&AS_SYNCHRONIZED);
213
 
        }
214
 
 
215
 
        if (fileType == SHARP_TYPE)
216
 
        {
217
 
                headers.push_back(&AS_FINALLY);
218
 
                headers.push_back(&AS_FOREACH);
219
 
                headers.push_back(&AS_LOCK);
220
 
                headers.push_back(&AS_UNSAFE);
221
 
                headers.push_back(&AS_FIXED);
222
 
                headers.push_back(&AS_GET);
223
 
                headers.push_back(&AS_SET);
224
 
                headers.push_back(&AS_ADD);
225
 
                headers.push_back(&AS_REMOVE);
226
 
        }
227
 
}
228
 
 
229
 
/**
230
 
 * Build the vector of non-assignment operators.
231
 
 * Used by ONLY ASBeautifier.cpp
232
 
 *
233
 
 * @param nonParenHeaders       a reference to the vector to be built.
234
 
 */
235
 
void ASResource::buildNonAssignmentOperators(vector<const string*> &nonAssignmentOperators)
236
 
{
237
 
        nonAssignmentOperators.push_back(&AS_EQUAL);
238
 
        nonAssignmentOperators.push_back(&AS_PLUS_PLUS);
239
 
        nonAssignmentOperators.push_back(&AS_MINUS_MINUS);
240
 
        nonAssignmentOperators.push_back(&AS_NOT_EQUAL);
241
 
        nonAssignmentOperators.push_back(&AS_GR_EQUAL);
242
 
        nonAssignmentOperators.push_back(&AS_GR_GR_GR);
243
 
        nonAssignmentOperators.push_back(&AS_GR_GR);
244
 
        nonAssignmentOperators.push_back(&AS_LS_EQUAL);
245
 
        nonAssignmentOperators.push_back(&AS_LS_LS_LS);
246
 
        nonAssignmentOperators.push_back(&AS_LS_LS);
247
 
        nonAssignmentOperators.push_back(&AS_ARROW);
248
 
        nonAssignmentOperators.push_back(&AS_AND);
249
 
        nonAssignmentOperators.push_back(&AS_OR);
250
 
}
251
 
 
252
 
/**
253
 
 * Build the vector of header non-paren headers.
254
 
 * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp
255
 
 *
256
 
 * @param nonParenHeaders       a reference to the vector to be built.
257
 
 */
258
 
void ASResource::buildNonParenHeaders(vector<const string*> &nonParenHeaders, int fileType, bool beautifier)
259
 
{
260
 
        nonParenHeaders.push_back(&AS_ELSE);
261
 
        nonParenHeaders.push_back(&AS_DO);
262
 
        nonParenHeaders.push_back(&AS_TRY);
263
 
 
264
 
        if (beautifier)
265
 
        {
266
 
                nonParenHeaders.push_back(&AS_CASE);
267
 
                nonParenHeaders.push_back(&AS_DEFAULT);
268
 
                nonParenHeaders.push_back(&AS_CONST);
269
 
                nonParenHeaders.push_back(&AS_STATIC);
270
 
                nonParenHeaders.push_back(&AS_EXTERN);
271
 
                nonParenHeaders.push_back(&AS_TEMPLATE);
272
 
        }
273
 
 
274
 
        if (fileType == JAVA_TYPE)
275
 
        {
276
 
                nonParenHeaders.push_back(&AS_FINALLY);
277
 
        }
278
 
 
279
 
        if (fileType == SHARP_TYPE)
280
 
        {
281
 
                nonParenHeaders.push_back(&AS_FINALLY);
282
 
                nonParenHeaders.push_back(&AS_UNSAFE);
283
 
                nonParenHeaders.push_back(&AS_GET);
284
 
                nonParenHeaders.push_back(&AS_SET);
285
 
                nonParenHeaders.push_back(&AS_ADD);
286
 
                nonParenHeaders.push_back(&AS_REMOVE);
287
 
        }
288
 
}
289
 
 
290
 
/**
291
 
 * Build the vector of operators.
292
 
 * Used by ONLY ASFormatter.cpp
293
 
 *
294
 
 * @param operators             a reference to the vector to be built.
295
 
 */
296
 
void ASResource::buildOperators(vector<const string*> &operators)
297
 
{
298
 
        operators.push_back(&AS_PLUS_ASSIGN);
299
 
        operators.push_back(&AS_MINUS_ASSIGN);
300
 
        operators.push_back(&AS_MULT_ASSIGN);
301
 
        operators.push_back(&AS_DIV_ASSIGN);
302
 
        operators.push_back(&AS_MOD_ASSIGN);
303
 
        operators.push_back(&AS_OR_ASSIGN);
304
 
        operators.push_back(&AS_AND_ASSIGN);
305
 
        operators.push_back(&AS_XOR_ASSIGN);
306
 
        operators.push_back(&AS_EQUAL);
307
 
        operators.push_back(&AS_PLUS_PLUS);
308
 
        operators.push_back(&AS_MINUS_MINUS);
309
 
        operators.push_back(&AS_NOT_EQUAL);
310
 
        operators.push_back(&AS_GR_EQUAL);
311
 
        operators.push_back(&AS_GR_GR_GR_ASSIGN);
312
 
        operators.push_back(&AS_GR_GR_ASSIGN);
313
 
        operators.push_back(&AS_GR_GR_GR);
314
 
        operators.push_back(&AS_GR_GR);
315
 
        operators.push_back(&AS_LS_EQUAL);
316
 
        operators.push_back(&AS_LS_LS_LS_ASSIGN);
317
 
        operators.push_back(&AS_LS_LS_ASSIGN);
318
 
        operators.push_back(&AS_LS_LS_LS);
319
 
        operators.push_back(&AS_LS_LS);
320
 
        operators.push_back(&AS_ARROW);
321
 
        operators.push_back(&AS_AND);
322
 
        operators.push_back(&AS_OR);
323
 
        operators.push_back(&AS_COLON_COLON);
324
 
        operators.push_back(&AS_PLUS);
325
 
        operators.push_back(&AS_MINUS);
326
 
        operators.push_back(&AS_MULT);
327
 
        operators.push_back(&AS_DIV);
328
 
        operators.push_back(&AS_MOD);
329
 
        operators.push_back(&AS_QUESTION);
330
 
        operators.push_back(&AS_COLON);
331
 
        operators.push_back(&AS_ASSIGN);
332
 
        operators.push_back(&AS_LS);
333
 
        operators.push_back(&AS_GR);
334
 
        operators.push_back(&AS_NOT);
335
 
        operators.push_back(&AS_BIT_OR);
336
 
        operators.push_back(&AS_BIT_AND);
337
 
        operators.push_back(&AS_BIT_NOT);
338
 
        operators.push_back(&AS_BIT_XOR);
339
 
        operators.push_back(&AS_OPERATOR);
340
 
        operators.push_back(&AS_COMMA);
341
 
        operators.push_back(&AS_RETURN);
342
 
}
343
 
 
344
 
/**
345
 
 * Build the vector of pre-block statements.
346
 
 * Used by ONLY ASBeautifier.cpp
347
 
 *
348
 
 * @param preBlockStatements        a reference to the vector to be built.
349
 
 */
350
 
void ASResource::buildPreBlockStatements(vector<const string*> &preBlockStatements)
351
 
{
352
 
        preBlockStatements.push_back(&AS_CLASS);
353
 
        preBlockStatements.push_back(&AS_STRUCT);
354
 
        preBlockStatements.push_back(&AS_UNION);
355
 
        preBlockStatements.push_back(&AS_INTERFACE);
356
 
        preBlockStatements.push_back(&AS_NAMESPACE);
357
 
        preBlockStatements.push_back(&AS_THROWS);
358
 
        preBlockStatements.push_back(&AS_EXTERN);
359
 
}
360
 
 
361
 
/**
362
 
 * Build the vector of pre-command headers.
363
 
 * Used by ONLY ASFormatter.cpp
364
 
 *
365
 
 * @param preCommandHeaders     a reference to the vector to be built.
366
 
 */
367
 
void ASResource::buildPreCommandHeaders(vector<const string*> &preCommandHeaders)
368
 
{
369
 
        preCommandHeaders.push_back(&AS_EXTERN);
370
 
        preCommandHeaders.push_back(&AS_THROWS);
371
 
        preCommandHeaders.push_back(&AS_CONST);
372
 
}
373
 
 
374
 
/**
375
 
 * Build the vector of pre-definition headers.
376
 
 * Used by ONLY ASFormatter.cpp
377
 
 *
378
 
 * @param preDefinitionHeaders      a reference to the vector to be built.
379
 
 */
380
 
void ASResource::buildPreDefinitionHeaders(vector<const string*> &preDefinitionHeaders)
381
 
{
382
 
        preDefinitionHeaders.push_back(&AS_CLASS);
383
 
        preDefinitionHeaders.push_back(&AS_INTERFACE);
384
 
        preDefinitionHeaders.push_back(&AS_NAMESPACE);
385
 
        preDefinitionHeaders.push_back(&AS_STRUCT);
386
 
}
387
 
 
388
 
 
389
 
}   // end namespace astyle