41
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
* Static utility functions related to source files
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
package com.nokia.tracecompiler.source;
|
|
20 |
|
|
21 |
import java.util.regex.Matcher;
|
|
22 |
import java.util.regex.Pattern;
|
|
23 |
|
|
24 |
import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
|
|
25 |
import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.StringErrorParameters;
|
|
26 |
import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
|
|
27 |
import com.nokia.tracecompiler.model.TraceCompilerException;
|
|
28 |
import com.nokia.tracecompiler.model.TraceConstantTable;
|
|
29 |
import com.nokia.tracecompiler.model.TraceParameter;
|
|
30 |
import com.nokia.tracecompiler.rules.ArrayParameterRule;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Static utility functions related to source files
|
|
34 |
*
|
|
35 |
*/
|
|
36 |
public class SourceUtils {
|
|
37 |
|
|
38 |
/**
|
|
39 |
* Tag for array types
|
|
40 |
*/
|
|
41 |
private static final String ARRAY_TAG = "[]"; //$NON-NLS-1$
|
|
42 |
|
|
43 |
/**
|
|
44 |
* Start tag for printf format specifier
|
|
45 |
*/
|
|
46 |
private static final String START_TAG = "%"; //$NON-NLS-1$
|
|
47 |
|
|
48 |
/**
|
|
49 |
* Regular expression optional element tag
|
|
50 |
*/
|
|
51 |
private static final String OPTIONAL_TAG = "?"; //$NON-NLS-1$
|
|
52 |
|
|
53 |
/**
|
|
54 |
* Optional parameter pattern. Quoted from Wikipedia:
|
|
55 |
*
|
|
56 |
* <strong> Parameter can be omitted or can be: 'n$' Where n is the number
|
|
57 |
* of the parameter to display using this format specifier, allowing the
|
|
58 |
* parameters provided to be output multiple times, using varying format
|
|
59 |
* specifiers or in different orders. This is a POSIX extension and not in
|
|
60 |
* C99.</strong>
|
|
61 |
*
|
|
62 |
* This has not been implemented -> Currently format specifier count must
|
|
63 |
* match parameter count
|
|
64 |
*/
|
|
65 |
private final static String PARAMETER_PATTERN = "(\\d+\\$)"; //$NON-NLS-1$
|
|
66 |
|
|
67 |
/**
|
|
68 |
* Optional flags pattern. Quoted from Wikipedia:
|
|
69 |
*
|
|
70 |
* <strong> Flags can be zero or more (in any order) of:
|
|
71 |
* <ul>
|
|
72 |
* <li>'+' : Causes printf to always denote the sign '+' or '-' of a number
|
|
73 |
* (the default is to omit the sign for positive numbers). Only applicable
|
|
74 |
* to numeric types.
|
|
75 |
* <li>'-' : Causes printf to left-align the output of this placeholder (the
|
|
76 |
* default is to right-align the output).
|
|
77 |
* <li>'#' : Alternate form. For 'g' and 'G', trailing zeros are not
|
|
78 |
* removed. For 'f', 'F', 'e', 'E', 'g', 'G', the output always contains a
|
|
79 |
* decimal point. For 'o', 'x', and 'X', a 0, 0x, and 0X, respectively, is
|
|
80 |
* prepended to non-zero numbers.
|
|
81 |
* <li>' ' : Causes printf to left-pad the output with spaces until the
|
|
82 |
* required length of output is attained. If combined with '0' (see below),
|
|
83 |
* it will cause the sign to become a space when positive, but the remaining
|
|
84 |
* characters will be zero-padded
|
|
85 |
* <li>'0' : Causes printf to use '0' (instead of spaces) to left fill a
|
|
86 |
* fixed length field. For example (assume i = 3) printf("%2d", i) results
|
|
87 |
* in " 3", while printf("%02d", i) results in "03"
|
|
88 |
* </ul>
|
|
89 |
* </strong>
|
|
90 |
*/
|
|
91 |
private final static String FLAGS_PATTERN = "([-+# 0])"; //$NON-NLS-1$
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Optional width pattern. Quoted from Wikipedia:
|
|
95 |
*
|
|
96 |
* <strong>Width can be omitted or be any of:
|
|
97 |
* <ul>
|
|
98 |
* <li>a number : Causes printf to pad the output of this placeholder with
|
|
99 |
* spaces until it is at least number characters wide. If number has a
|
|
100 |
* leading '0', then padding is done with '0' characters.
|
|
101 |
* <li>'*' : Causes printf to pad the output until it is n characters wide,
|
|
102 |
* where n is an integer value stored in the a function argument just
|
|
103 |
* preceding that represented by the modified type. For example
|
|
104 |
* printf("%*d", 5, 10) will result in "10" being printed with a width of
|
|
105 |
* 5.</strong>
|
|
106 |
* </ul>
|
|
107 |
* </strong>
|
|
108 |
*
|
|
109 |
* '*' has not been implemented -> Currently format specifier count must
|
|
110 |
* match parameter count
|
|
111 |
*/
|
|
112 |
private final static String WIDTH_PATTERN = "(\\d+|\\*)"; //$NON-NLS-1$
|
|
113 |
|
|
114 |
/**
|
|
115 |
* Optional precision pattern. Quoted from Wikipedia:
|
|
116 |
*
|
|
117 |
* Precision can be omitted or be any of: <strong>
|
|
118 |
* <ul>
|
|
119 |
* <li>a number : For non-integral numeric types, causes the decimal portion
|
|
120 |
* of the output to be expressed in at least number digits. For the string
|
|
121 |
* type, causes the output to be truncated at number characters.
|
|
122 |
* <li>'*' : Same as the above, but uses an integer value in the intaken
|
|
123 |
* argument to determine the number of decimal places or maximum string
|
|
124 |
* length. For example, printf("%.*s", 3, "abcdef") will result in "abc"
|
|
125 |
* being printed.
|
|
126 |
* </ul>
|
|
127 |
* </strong> If the precision is zero, nothing is printed for the
|
|
128 |
* corresponding argument.
|
|
129 |
*
|
|
130 |
* '*' has not been implemented -> Currently format specifier count must
|
|
131 |
* match parameter count
|
|
132 |
*/
|
|
133 |
private final static String PRECISION_PATTERN = "(\\.(\\d+|\\*))"; //$NON-NLS-1$
|
|
134 |
|
|
135 |
/**
|
|
136 |
* Optional length pattern. Quoted from Wikipedia:
|
|
137 |
*
|
|
138 |
* Length can be omitted or be any of: <strong>
|
|
139 |
* <ul>
|
|
140 |
* <li>'hh' : For integer types, causes printf to expect an int sized
|
|
141 |
* integer argument which was promoted from a char.
|
|
142 |
* <li>'h' : For integer types, causes printf to expect a int sized integer
|
|
143 |
* argument which was promoted from a short.
|
|
144 |
* <li>'l' : (ell) For integer types, causes printf to expect a long sized
|
|
145 |
* integer argument.
|
|
146 |
* <li>'ll' : (ell ell) For integer types, causes printf to expect a long
|
|
147 |
* long sized integer argument.
|
|
148 |
* <li>'L' : For floating point types, causes printf to expect a long double
|
|
149 |
* argument.
|
|
150 |
* <li>'z' : For integer types, causes printf to expect a size_t sized
|
|
151 |
* integer argument.
|
|
152 |
* <li>'j' : For integer types, causes printf to expect a intmax_t sized
|
|
153 |
* integer argument.
|
|
154 |
* <li>'t' : For integer types, causes printf to expect a ptrdiff_t sized
|
|
155 |
* integer argument.
|
|
156 |
* </ul>
|
|
157 |
* </strong>
|
|
158 |
*/
|
|
159 |
private final static String LENGTH_PATTERN = "([lh]?[hHlLZjt])"; //$NON-NLS-1$
|
|
160 |
|
|
161 |
/**
|
|
162 |
* Type pattern. Quoted from Wikipedia:
|
|
163 |
*
|
|
164 |
* <strong> type can be any of:
|
|
165 |
* <ul>
|
|
166 |
* <li>'d', 'i' : Print an int as a signed decimal number. '%d' and '%i' are
|
|
167 |
* synonymous for output, but are different when used with scanf() for
|
|
168 |
* input.
|
|
169 |
* <li>'u' : Print decimal unsigned int.
|
|
170 |
* <li>'f', 'F' : Print a double in normal (fixed-point) notation.
|
|
171 |
* <li>'e', 'E' : Print a double value in standard form ([-]d.ddd
|
|
172 |
* e[+/-]ddd).
|
|
173 |
* <li>'g', 'G' : Print a double in either normal or exponential notation,
|
|
174 |
* whichever is more appropriate for its magnitude. 'g' uses lower-case
|
|
175 |
* letters, 'G' uses upper-case letters. This type differs slightly from
|
|
176 |
* fixed-point notation in that insignificant zeroes to the right of the
|
|
177 |
* decimal point are not included. Also, the decimal point is not included
|
|
178 |
* on whole numbers.
|
|
179 |
* <li>'x', 'X' : Print an unsigned int as a hexadecimal number. 'x' uses
|
|
180 |
* lower-case letters and 'X' uses upper-case.
|
|
181 |
* <li>'o' : Print an unsigned int in octal.
|
|
182 |
* <li>'s' : Print a character string.
|
|
183 |
* <li>'c' : Print a char (character).
|
|
184 |
* <li>'p' : Print a void * (pointer to void) in an implementation-defined
|
|
185 |
* format.
|
|
186 |
* <li>'n' : Write number of characters successfully written so far into an
|
|
187 |
* integer pointer parameter.
|
|
188 |
* <li>'%' : Print a literal '%' character (this type doesn't accept any
|
|
189 |
* flags, width, precision or length).
|
|
190 |
* </ul>
|
|
191 |
* </strong>
|
|
192 |
*
|
|
193 |
* The pattern itself accepts all characters and the validity check is done
|
|
194 |
* in {@link #mapFormatToParameterType mapFormatToType}
|
|
195 |
*/
|
|
196 |
private final static String TYPE_PATTERN = "([a-zA-Z%])"; //$NON-NLS-1$
|
|
197 |
|
|
198 |
/**
|
|
199 |
* Regular expression pattern for printf
|
|
200 |
*
|
|
201 |
* %[parameter][flags][width][.precision][length]type
|
|
202 |
*/
|
|
203 |
private static final String STANDARD_PRINTF_PATTERN = PARAMETER_PATTERN
|
|
204 |
+ OPTIONAL_TAG + FLAGS_PATTERN + OPTIONAL_TAG + WIDTH_PATTERN
|
|
205 |
+ OPTIONAL_TAG + PRECISION_PATTERN + OPTIONAL_TAG + LENGTH_PATTERN
|
|
206 |
+ OPTIONAL_TAG + TYPE_PATTERN;
|
|
207 |
|
|
208 |
/**
|
|
209 |
* Regular expression pattern for Open System Trace printf extensions
|
|
210 |
* %{Type}, %{Array[]}
|
|
211 |
*/
|
|
212 |
private static final String EXTENSION_PRINTF_PATTERN = "\\{[\\w_]+(\\[\\])?\\}"; //$NON-NLS-1$
|
|
213 |
|
|
214 |
/**
|
|
215 |
* Regular expression pattern for printf
|
|
216 |
*/
|
|
217 |
public static final String PRINTF_PATTERN = START_TAG + "((" //$NON-NLS-1$
|
|
218 |
+ STANDARD_PRINTF_PATTERN + ")|(" //$NON-NLS-1$
|
|
219 |
+ EXTENSION_PRINTF_PATTERN + "))"; //$NON-NLS-1$
|
|
220 |
|
|
221 |
/**
|
|
222 |
* The pattern for printf-formatted trace text
|
|
223 |
*/
|
|
224 |
public final static Pattern traceTextPattern = Pattern
|
|
225 |
.compile(PRINTF_PATTERN);
|
|
226 |
|
|
227 |
/**
|
|
228 |
* The pattern for parameter length in printf specifier
|
|
229 |
*/
|
|
230 |
public final static Pattern lengthPattern = Pattern.compile(LENGTH_PATTERN);
|
|
231 |
|
|
232 |
/**
|
|
233 |
* Hidden constructor
|
|
234 |
*/
|
|
235 |
private SourceUtils() {
|
|
236 |
}
|
|
237 |
|
|
238 |
/**
|
|
239 |
* Creates a header guard
|
|
240 |
*
|
|
241 |
* @param fileName
|
|
242 |
* the name of the file
|
|
243 |
* @return the header guard
|
|
244 |
*/
|
|
245 |
public static String createHeaderGuard(String fileName) {
|
|
246 |
StringBuffer sb = new StringBuffer();
|
|
247 |
String uname = fileName.replace(SourceConstants.PERIOD_CHAR,
|
|
248 |
SourceConstants.UNDERSCORE_CHAR).toUpperCase();
|
|
249 |
sb.append(SourceConstants.IFNDEF);
|
|
250 |
sb.append(SourceConstants.SPACE);
|
|
251 |
sb.append(SourceConstants.DOUBLE_UNDERSCORE);
|
|
252 |
sb.append(uname);
|
|
253 |
sb.append(SourceConstants.DOUBLE_UNDERSCORE);
|
|
254 |
sb.append(SourceConstants.LINE_FEED);
|
|
255 |
sb.append(SourceConstants.DEFINE);
|
|
256 |
sb.append(SourceConstants.SPACE);
|
|
257 |
sb.append(SourceConstants.DOUBLE_UNDERSCORE);
|
|
258 |
sb.append(uname);
|
|
259 |
sb.append(SourceConstants.DOUBLE_UNDERSCORE);
|
|
260 |
return sb.toString();
|
|
261 |
}
|
|
262 |
|
|
263 |
/**
|
|
264 |
* Checks the validity of name
|
|
265 |
*
|
|
266 |
* @param name
|
|
267 |
* the name
|
|
268 |
* @return true if valid
|
|
269 |
*/
|
|
270 |
public static boolean isValidName(String name) {
|
|
271 |
boolean retval;
|
|
272 |
if (name != null && name.length() > 0) {
|
|
273 |
retval = true;
|
|
274 |
if (!isValidNameStartChar(name.charAt(0))) {
|
|
275 |
retval = false;
|
|
276 |
} else {
|
|
277 |
for (int i = 1; i < name.length() && retval; i++) {
|
|
278 |
retval = isValidNameChar(name.charAt(i));
|
|
279 |
}
|
|
280 |
}
|
|
281 |
} else {
|
|
282 |
retval = false;
|
|
283 |
}
|
|
284 |
return retval;
|
|
285 |
}
|
|
286 |
|
|
287 |
/**
|
|
288 |
* Checks the validity of parameter name
|
|
289 |
*
|
|
290 |
* @param name
|
|
291 |
* the name
|
|
292 |
* @return true if valid
|
|
293 |
*/
|
|
294 |
public static boolean isValidParameterName(String name) {
|
|
295 |
boolean retval;
|
|
296 |
if (name != null && name.length() > 0) {
|
|
297 |
retval = true;
|
|
298 |
if (!isValidNameStartChar(name.charAt(0))) {
|
|
299 |
retval = false;
|
|
300 |
} else {
|
|
301 |
for (int i = 1; i < name.length() && retval; i++) {
|
|
302 |
|
|
303 |
// Check validity of the character
|
|
304 |
char c = name.charAt(i);
|
|
305 |
retval = (isValidNameChar(c) || isValidSpecialChar(c));
|
|
306 |
}
|
|
307 |
}
|
|
308 |
} else {
|
|
309 |
retval = false;
|
|
310 |
}
|
|
311 |
return retval;
|
|
312 |
}
|
|
313 |
|
|
314 |
/**
|
|
315 |
* Checks special character validity
|
|
316 |
*
|
|
317 |
* @param c
|
|
318 |
* character
|
|
319 |
* @return true if valid
|
|
320 |
*/
|
|
321 |
private static boolean isValidSpecialChar(char c) {
|
|
322 |
boolean retval = false;
|
|
323 |
// Check if the character is allowed
|
|
324 |
if (c == '.' || c == '-' || c == '>' || c == '(' || c == ')'
|
|
325 |
|| c == '[' || c == ']' || c == ' ' || c == '&' || c == '*') {
|
|
326 |
retval = true;
|
|
327 |
}
|
|
328 |
return retval;
|
|
329 |
}
|
|
330 |
|
|
331 |
/**
|
|
332 |
* Checks start-of-name character validity
|
|
333 |
*
|
|
334 |
* @param c
|
|
335 |
* character
|
|
336 |
* @return true if valid
|
|
337 |
*/
|
|
338 |
private static boolean isValidNameStartChar(char c) {
|
|
339 |
// Ascii characters and underscore are allowed
|
|
340 |
return (c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A) // CodForChk_Dis_Magic
|
|
341 |
|| c == 0x5F; // CodForChk_Dis_Magic
|
|
342 |
}
|
|
343 |
|
|
344 |
/**
|
|
345 |
* Checks name character validity
|
|
346 |
*
|
|
347 |
* @param c
|
|
348 |
* character
|
|
349 |
* @return true if valid
|
|
350 |
*/
|
|
351 |
private static boolean isValidNameChar(char c) {
|
|
352 |
// Numbers are allowed in addition to start characters
|
|
353 |
return isValidNameStartChar(c) || (c >= 0x30 && c <= 0x39); // CodForChk_Dis_Magic
|
|
354 |
}
|
|
355 |
|
|
356 |
/**
|
|
357 |
* Maps a Symbian type to one of the TraceParameter types
|
|
358 |
*
|
|
359 |
* @param parsedType
|
|
360 |
* the type parsed from source
|
|
361 |
* @return the parameter type
|
|
362 |
*/
|
|
363 |
public static TypeMapping mapSymbianTypeToParameterType(
|
|
364 |
ParsedType parsedType) {
|
|
365 |
String type = null;
|
|
366 |
// The type map contains Symbian types
|
|
367 |
for (int i = 0; i < SymbianConstants.PARAMETER_TYPE_MAP.length
|
|
368 |
&& type == null; i++) {
|
|
369 |
if (parsedType
|
|
370 |
.typeEquals(SymbianConstants.PARAMETER_TYPE_MAP[i][0])) {
|
|
371 |
type = SymbianConstants.PARAMETER_TYPE_MAP[i][1];
|
|
372 |
}
|
|
373 |
}
|
|
374 |
if (type != null) {
|
|
375 |
if (parsedType.hasQualifier(SourceConstants.UNSIGNED)) {
|
|
376 |
type = convertToUnsigned(type);
|
|
377 |
}
|
|
378 |
}
|
|
379 |
TypeMapping retval = new TypeMapping(type);
|
|
380 |
if (type != null) {
|
|
381 |
// Value or a reference can be added to source as is
|
|
382 |
// Points needs to be cast to HEX32
|
|
383 |
if (parsedType.isPointer()) {
|
|
384 |
retval.type = TraceParameter.HEX32;
|
|
385 |
retval.needsCasting = true;
|
|
386 |
} else {
|
|
387 |
// TUint32 needs to be cast to TUint and TInt32 to TInt.
|
|
388 |
// Otherwise there will be some problems with extension
|
|
389 |
// headers
|
|
390 |
if (parsedType.typeEquals(SymbianConstants.TUINT32)
|
|
391 |
|| parsedType.typeEquals(SymbianConstants.TINT32)) {
|
|
392 |
retval.needsCasting = true;
|
|
393 |
}
|
|
394 |
}
|
|
395 |
} else if (parsedType.isPointer()) {
|
|
396 |
// Unrecognized pointer types are cast to Hex32
|
|
397 |
retval.type = TraceParameter.HEX32;
|
|
398 |
retval.needsCasting = true;
|
|
399 |
} else {
|
|
400 |
// Unrecognized value types are passed as pointer and cast to Hex32
|
|
401 |
retval.type = TraceParameter.HEX32;
|
|
402 |
retval.valueToPointer = true;
|
|
403 |
retval.needsCasting = true;
|
|
404 |
}
|
|
405 |
return retval;
|
|
406 |
}
|
|
407 |
|
|
408 |
/**
|
|
409 |
* Maps the type of a parameter to a Symbian type
|
|
410 |
*
|
|
411 |
* @param parameter
|
|
412 |
* the parameter
|
|
413 |
* @return the parameter type as string
|
|
414 |
*/
|
|
415 |
public static String mapParameterTypeToSymbianType(TraceParameter parameter) {
|
|
416 |
String retval;
|
|
417 |
ArrayParameterRule rule = parameter
|
|
418 |
.getExtension(ArrayParameterRule.class);
|
|
419 |
String type = parameter.getType();
|
|
420 |
TraceConstantTable table = parameter.getModel()
|
|
421 |
.findConstantTableByName(type);
|
|
422 |
if (table != null) {
|
|
423 |
type = table.getType();
|
|
424 |
}
|
|
425 |
if (rule != null) {
|
|
426 |
retval = mapArrayTypeToSymbianType(type);
|
|
427 |
} else {
|
|
428 |
retval = mapBasicTypeToSymbianType(type);
|
|
429 |
}
|
|
430 |
return retval;
|
|
431 |
}
|
|
432 |
|
|
433 |
/**
|
|
434 |
* Maps a basic parameter type to Symbian type
|
|
435 |
*
|
|
436 |
* @param type
|
|
437 |
* the parameter type
|
|
438 |
* @return the Symbian type
|
|
439 |
*/
|
|
440 |
public static String mapBasicTypeToSymbianType(String type) {
|
|
441 |
String retval;
|
|
442 |
// Unsigned and hex both use TUint types
|
|
443 |
// Signed uses TInt types
|
|
444 |
if (type.equals(TraceParameter.POINTER)) {
|
|
445 |
retval = SymbianConstants.CONST_TANY_PTR;
|
|
446 |
} else if (type.equals(TraceParameter.SDEC32)) {
|
|
447 |
retval = SymbianConstants.TINT;
|
|
448 |
} else if (type.equals(TraceParameter.UDEC32)
|
|
449 |
|| type.equals(TraceParameter.OCT32)
|
|
450 |
|| type.equals(TraceParameter.HEX32)) {
|
|
451 |
retval = SymbianConstants.TUINT;
|
|
452 |
} else if (type.equals(TraceParameter.SDEC16)) {
|
|
453 |
retval = SymbianConstants.TINT16;
|
|
454 |
} else if (type.equals(TraceParameter.UDEC16)
|
|
455 |
|| type.equals(TraceParameter.OCT16)
|
|
456 |
|| type.equals(TraceParameter.HEX16)) {
|
|
457 |
retval = SymbianConstants.TUINT16;
|
|
458 |
} else if (type.equals(TraceParameter.SDEC8)) {
|
|
459 |
retval = SymbianConstants.TINT8;
|
|
460 |
} else if (type.equals(TraceParameter.UDEC8)
|
|
461 |
|| type.equals(TraceParameter.OCT8)
|
|
462 |
|| type.equals(TraceParameter.HEX8)) {
|
|
463 |
retval = SymbianConstants.TUINT8;
|
|
464 |
} else if (type.equals(TraceParameter.SDEC64)
|
|
465 |
|| type.equals(TraceParameter.TIME)) {
|
|
466 |
retval = SymbianConstants.TINT64;
|
|
467 |
} else if (type.equals(TraceParameter.UDEC64)
|
|
468 |
|| type.equals(TraceParameter.OCT64)
|
|
469 |
|| type.equals(TraceParameter.HEX64)) {
|
|
470 |
retval = SymbianConstants.TUINT64;
|
|
471 |
} else if (type.equals(TraceParameter.ASCII)) {
|
|
472 |
retval = SymbianConstants.CONST_TDESC8_REF;
|
|
473 |
} else if (type.equals(TraceParameter.UNICODE)) {
|
|
474 |
retval = SymbianConstants.CONST_TDESC16_REF;
|
|
475 |
} else if (type.equals(TraceParameter.FLOAT_EXP)
|
|
476 |
|| type.equals(TraceParameter.FLOAT_FIX)
|
|
477 |
|| type.equals(TraceParameter.FLOAT_OPT)) {
|
|
478 |
retval = SymbianConstants.TREAL;
|
|
479 |
} else {
|
|
480 |
retval = SymbianConstants.TANY_PTR;
|
|
481 |
}
|
|
482 |
return retval;
|
|
483 |
}
|
|
484 |
|
|
485 |
/**
|
|
486 |
* Maps an array parameter type to Symbian type
|
|
487 |
*
|
|
488 |
* @param type
|
|
489 |
* the parameter type
|
|
490 |
* @return the Symbian type
|
|
491 |
*/
|
|
492 |
public static String mapArrayTypeToSymbianType(String type) {
|
|
493 |
String basic = mapBasicTypeToSymbianType(type);
|
|
494 |
String retval = SourceConstants.OST_ARRAY_TYPE_PREFIX + basic
|
|
495 |
+ SourceConstants.OST_ARRAY_TYPE_POSTFIX;
|
|
496 |
return retval;
|
|
497 |
}
|
|
498 |
|
|
499 |
/**
|
|
500 |
* Maps a format specifier into parameter type
|
|
501 |
*
|
|
502 |
* @param formatSpecifier
|
|
503 |
* the format specifier
|
|
504 |
* @return the parameter type or null if not recognized. If the type is one
|
|
505 |
* of the supported TraceParameter types, the string contains the
|
|
506 |
* integer value of the type
|
|
507 |
* @throws TraceCompilerException
|
|
508 |
* if format specifier is not valid
|
|
509 |
*/
|
|
510 |
public static FormatMapping mapFormatToParameterType(String formatSpecifier)
|
|
511 |
throws TraceCompilerException {
|
|
512 |
String type;
|
|
513 |
boolean array = false;
|
|
514 |
boolean basic = false;
|
|
515 |
boolean extended = false;
|
|
516 |
int len = formatSpecifier.length();
|
|
517 |
// Extension format is checked first: %{x}
|
|
518 |
if (len > 3 && formatSpecifier.charAt(1) == '{' // CodForChk_Dis_Magic
|
|
519 |
&& formatSpecifier.charAt(len - 1) == '}') {
|
|
520 |
// Extension format can be an array: %{x[]}
|
|
521 |
// In that case it could also be a basic type
|
|
522 |
if (len > 3 + ARRAY_TAG.length() // CodForChk_Dis_Magic
|
|
523 |
&& formatSpecifier.charAt(len - 3) == '[' // CodForChk_Dis_Magic
|
|
524 |
&& formatSpecifier.charAt(len - 2) == ']') { // CodForChk_Dis_Magic
|
|
525 |
type = formatSpecifier.substring(2, len - 1 // CodForChk_Dis_Magic
|
|
526 |
- ARRAY_TAG.length());
|
|
527 |
array = true;
|
|
528 |
if (isStringType(type)) {
|
|
529 |
StringErrorParameters param = new StringErrorParameters();
|
|
530 |
param.string = type;
|
|
531 |
throw new TraceCompilerException(
|
|
532 |
TraceCompilerErrorCode.PARAMETER_FORMAT_NOT_SUPPORTED_IN_ARRAY,
|
|
533 |
param, null);
|
|
534 |
}
|
|
535 |
} else {
|
|
536 |
type = formatSpecifier.substring(2, len - 1); // CodForChk_Dis_Magic
|
|
537 |
}
|
|
538 |
extended = !isBasicType(type);
|
|
539 |
} else {
|
|
540 |
basic = true;
|
|
541 |
type = formatSpecifier;
|
|
542 |
}
|
|
543 |
|
|
544 |
if (basic) {
|
|
545 |
type = mapBasicFormatToType(formatSpecifier);
|
|
546 |
}
|
|
547 |
if (type == null) {
|
|
548 |
StringErrorParameters params = new StringErrorParameters();
|
|
549 |
params.string = formatSpecifier;
|
|
550 |
throw new TraceCompilerException(
|
|
551 |
TraceCompilerErrorCode.PARAMETER_FORMAT_NOT_SUPPORTED,
|
|
552 |
params, null);
|
|
553 |
}
|
|
554 |
FormatMapping retval = new FormatMapping(type);
|
|
555 |
retval.isArray = array;
|
|
556 |
if (extended) {
|
|
557 |
// In case of extended types, a constant table can still be
|
|
558 |
// represented with normal trace macros.
|
|
559 |
TraceConstantTable table = TraceCompilerEngineGlobals.getTraceModel()
|
|
560 |
.findConstantTableByName(retval.type);
|
|
561 |
if (table != null) {
|
|
562 |
if (!array && isSimpleType(table.getType())) {
|
|
563 |
retval.isSimple = true;
|
|
564 |
}
|
|
565 |
} else {
|
|
566 |
// Extended type must be found from the property file
|
|
567 |
StringErrorParameters params = new StringErrorParameters();
|
|
568 |
params.string = formatSpecifier;
|
|
569 |
throw new TraceCompilerException(
|
|
570 |
TraceCompilerErrorCode.PARAMETER_FORMAT_NOT_SUPPORTED,
|
|
571 |
params, null);
|
|
572 |
}
|
|
573 |
} else if (!retval.isArray) {
|
|
574 |
retval.isSimple = isSimpleType(type);
|
|
575 |
}
|
|
576 |
|
|
577 |
return retval;
|
|
578 |
}
|
|
579 |
|
|
580 |
/**
|
|
581 |
* Maps basic format specifies to parameter type
|
|
582 |
*
|
|
583 |
* @param formatSpecifier
|
|
584 |
* the format specifies
|
|
585 |
* @return the type
|
|
586 |
* @throws TraceCompilerException
|
|
587 |
* if mapping cannot be done
|
|
588 |
*/
|
|
589 |
private static String mapBasicFormatToType(String formatSpecifier)
|
|
590 |
throws TraceCompilerException { // CodForChk_Dis_ComplexFunc
|
|
591 |
String type;
|
|
592 |
int paramLength = SourceUtils
|
|
593 |
.mapFormatToParameterLength(formatSpecifier);
|
|
594 |
char formatChar = formatSpecifier.charAt(formatSpecifier.length() - 1);
|
|
595 |
switch (formatChar) {
|
|
596 |
case 'd':
|
|
597 |
type = SourceUtils.mapSignedToParameterType(paramLength);
|
|
598 |
break;
|
|
599 |
case 'x':
|
|
600 |
case 'X':
|
|
601 |
type = SourceUtils.mapHexToParameterType(paramLength);
|
|
602 |
break;
|
|
603 |
case 'u':
|
|
604 |
type = SourceUtils.mapUnsignedToParameterType(paramLength);
|
|
605 |
break;
|
|
606 |
case 'o':
|
|
607 |
type = SourceUtils.mapOctalToParameterType(paramLength);
|
|
608 |
break;
|
|
609 |
case 's':
|
|
610 |
type = TraceParameter.ASCII;
|
|
611 |
break;
|
|
612 |
case 'S': // Symbian extension
|
|
613 |
type = TraceParameter.UNICODE;
|
|
614 |
break;
|
|
615 |
case 'c':
|
|
616 |
type = TraceParameter.SDEC8;
|
|
617 |
break;
|
|
618 |
case 'p':
|
|
619 |
type = TraceParameter.POINTER;
|
|
620 |
break;
|
|
621 |
case 'f':
|
|
622 |
case 'F':
|
|
623 |
type = TraceParameter.FLOAT_FIX;
|
|
624 |
break;
|
|
625 |
case 'e':
|
|
626 |
case 'E':
|
|
627 |
type = TraceParameter.FLOAT_EXP;
|
|
628 |
break;
|
|
629 |
case 'g':
|
|
630 |
case 'G':
|
|
631 |
type = TraceParameter.FLOAT_OPT;
|
|
632 |
break;
|
|
633 |
default:
|
|
634 |
type = null;
|
|
635 |
}
|
|
636 |
|
|
637 |
return type;
|
|
638 |
}
|
|
639 |
|
|
640 |
/**
|
|
641 |
* Maps a parameter type to format string
|
|
642 |
*
|
|
643 |
* @param parameter
|
|
644 |
* the parameter
|
|
645 |
* @return the format string
|
|
646 |
*/
|
|
647 |
public static String mapParameterTypeToFormat(TraceParameter parameter) {
|
|
648 |
String tag;
|
|
649 |
if (parameter.getExtension(ArrayParameterRule.class) != null) {
|
|
650 |
tag = mapArrayTypeToFormat(parameter.getType());
|
|
651 |
} else {
|
|
652 |
tag = mapNormalTypeToFormat(parameter.getType());
|
|
653 |
}
|
|
654 |
return tag;
|
|
655 |
}
|
|
656 |
|
|
657 |
/**
|
|
658 |
* Maps an array type to basic type
|
|
659 |
*
|
|
660 |
* @param arrayType
|
|
661 |
* the array type
|
|
662 |
* @return the basic type or null if original type is not array type
|
|
663 |
*/
|
|
664 |
public static String mapArrayTypeToBasicType(String arrayType) {
|
|
665 |
String retval;
|
|
666 |
if (arrayType.endsWith(ARRAY_TAG)) {
|
|
667 |
retval = arrayType.substring(0, arrayType.length()
|
|
668 |
- ARRAY_TAG.length());
|
|
669 |
} else {
|
|
670 |
retval = null;
|
|
671 |
}
|
|
672 |
return retval;
|
|
673 |
}
|
|
674 |
|
|
675 |
/**
|
|
676 |
* Parses a numeric value from source
|
|
677 |
*
|
|
678 |
* @param number
|
|
679 |
* the number as string
|
|
680 |
* @return the value
|
|
681 |
*/
|
|
682 |
public static int parseNumberFromSource(String number) {
|
|
683 |
int ret;
|
|
684 |
String low = number.toLowerCase();
|
|
685 |
int radix;
|
|
686 |
if (low.startsWith(SourceConstants.HEX_PREFIX)) {
|
|
687 |
radix = 16; // CodForChk_Dis_Magic
|
|
688 |
low = low.substring(SourceConstants.HEX_PREFIX.length());
|
|
689 |
} else if (low.startsWith(SourceConstants.OCTAL_PREFIX)
|
|
690 |
&& low.length() > SourceConstants.OCTAL_PREFIX.length()
|
|
691 |
&& Character.isDigit(low.charAt(SourceConstants.OCTAL_PREFIX
|
|
692 |
.length()))) {
|
|
693 |
radix = 8; // CodForChk_Dis_Magic
|
|
694 |
low = low.substring(SourceConstants.OCTAL_PREFIX.length());
|
|
695 |
} else {
|
|
696 |
radix = 10; // CodForChk_Dis_Magic
|
|
697 |
}
|
|
698 |
if (low.endsWith(SourceConstants.I64_POSTFIX)) {
|
|
699 |
low = low.substring(0, low.length()
|
|
700 |
- SourceConstants.I64_POSTFIX.length());
|
|
701 |
}
|
|
702 |
if (low.length() > 0) {
|
|
703 |
// Removes U / L characters from the end of value
|
|
704 |
int index = low.length() - 1;
|
|
705 |
boolean complete = false;
|
|
706 |
do {
|
|
707 |
char c = low.charAt(index);
|
|
708 |
if (c == 'u' || c == 'l') {
|
|
709 |
index--;
|
|
710 |
} else {
|
|
711 |
complete = true;
|
|
712 |
}
|
|
713 |
} while (!complete && index >= 0);
|
|
714 |
if (index < low.length() - 1 && index > 0) {
|
|
715 |
low = low.substring(0, index + 1);
|
|
716 |
}
|
|
717 |
ret = Integer.parseInt(low, radix);
|
|
718 |
} else {
|
|
719 |
ret = 0;
|
|
720 |
}
|
|
721 |
return ret;
|
|
722 |
}
|
|
723 |
|
|
724 |
/**
|
|
725 |
* Calculates the size of parameter
|
|
726 |
*
|
|
727 |
* @param parameter
|
|
728 |
* the parameter
|
|
729 |
* @return the parameter size or 0 if the size is not known at compile time
|
|
730 |
*/
|
|
731 |
public static int mapParameterTypeToSize(TraceParameter parameter) {
|
|
732 |
int retval;
|
|
733 |
ArrayParameterRule rule = parameter
|
|
734 |
.getExtension(ArrayParameterRule.class);
|
|
735 |
if (rule != null) {
|
|
736 |
// Array parameters are dynamic
|
|
737 |
retval = 0;
|
|
738 |
} else {
|
|
739 |
String type = parameter.getType();
|
|
740 |
TraceConstantTable table = parameter.getModel()
|
|
741 |
.findConstantTableByName(type);
|
|
742 |
if (table != null) {
|
|
743 |
type = table.getType();
|
|
744 |
}
|
|
745 |
retval = mapParameterTypeToSize(type);
|
|
746 |
}
|
|
747 |
return retval;
|
|
748 |
}
|
|
749 |
|
|
750 |
/**
|
|
751 |
* Calculates the size of parameter type
|
|
752 |
*
|
|
753 |
* @param type
|
|
754 |
* the parameter type
|
|
755 |
* @return the parameter size or 0 if size is not known at compile time
|
|
756 |
*/
|
|
757 |
public static int mapParameterTypeToSize(String type) {
|
|
758 |
int retval;
|
|
759 |
if (type.equals(TraceParameter.HEX32)
|
|
760 |
|| type.equals(TraceParameter.UDEC32)
|
|
761 |
|| type.equals(TraceParameter.SDEC32)
|
|
762 |
|| type.equals(TraceParameter.OCT32)
|
|
763 |
|| type.equals(TraceParameter.POINTER)) {
|
|
764 |
retval = 4; // CodForChk_Dis_Magic
|
|
765 |
} else if (type.equals(TraceParameter.HEX16)
|
|
766 |
|| type.equals(TraceParameter.UDEC16)
|
|
767 |
|| type.equals(TraceParameter.SDEC16)
|
|
768 |
|| type.equals(TraceParameter.OCT16)) {
|
|
769 |
retval = 2; // CodForChk_Dis_Magic
|
|
770 |
} else if (type.equals(TraceParameter.HEX8)
|
|
771 |
|| type.equals(TraceParameter.UDEC8)
|
|
772 |
|| type.equals(TraceParameter.SDEC8)
|
|
773 |
|| type.equals(TraceParameter.OCT8)) {
|
|
774 |
retval = 1;
|
|
775 |
} else if (type.equals(TraceParameter.HEX64)
|
|
776 |
|| type.equals(TraceParameter.UDEC64)
|
|
777 |
|| type.equals(TraceParameter.SDEC64)
|
|
778 |
|| type.equals(TraceParameter.OCT64)
|
|
779 |
|| type.equals(TraceParameter.FLOAT_EXP)
|
|
780 |
|| type.equals(TraceParameter.FLOAT_FIX)
|
|
781 |
|| type.equals(TraceParameter.FLOAT_OPT)) {
|
|
782 |
retval = 8; // CodForChk_Dis_Magic
|
|
783 |
} else {
|
|
784 |
retval = 0;
|
|
785 |
}
|
|
786 |
return retval;
|
|
787 |
}
|
|
788 |
|
|
789 |
/**
|
|
790 |
* Removes printf formatting from trace text
|
|
791 |
*
|
|
792 |
* @param text
|
|
793 |
* the text to be converted
|
|
794 |
* @return the new text
|
|
795 |
*/
|
|
796 |
public static String removePrintfFormatting(String text) {
|
|
797 |
Matcher matcher = traceTextPattern.matcher(text);
|
|
798 |
return matcher.replaceAll(""); //$NON-NLS-1$
|
|
799 |
}
|
|
800 |
|
|
801 |
/**
|
|
802 |
* Converts the given type to unsigned type
|
|
803 |
*
|
|
804 |
* @param type
|
|
805 |
* the type
|
|
806 |
* @return unsigned type
|
|
807 |
*/
|
|
808 |
private static String convertToUnsigned(String type) {
|
|
809 |
if (type.equals(TraceParameter.SDEC32)) {
|
|
810 |
type = TraceParameter.UDEC32;
|
|
811 |
} else if (type.equals(TraceParameter.SDEC16)) {
|
|
812 |
type = TraceParameter.UDEC16;
|
|
813 |
} else if (type.equals(TraceParameter.SDEC8)) {
|
|
814 |
type = TraceParameter.UDEC8;
|
|
815 |
} else if (type.equals(TraceParameter.SDEC64)) {
|
|
816 |
type = TraceParameter.UDEC64;
|
|
817 |
}
|
|
818 |
return type;
|
|
819 |
}
|
|
820 |
|
|
821 |
/**
|
|
822 |
* Maps a normal parameter type for format character
|
|
823 |
*
|
|
824 |
* @param type
|
|
825 |
* the parameter type
|
|
826 |
* @return the format character
|
|
827 |
*/
|
|
828 |
public static String mapNormalTypeToFormat(String type) { // CodForChk_Dis_ComplexFunc
|
|
829 |
String tag;
|
|
830 |
if (type.equals(TraceParameter.SDEC32)) {
|
|
831 |
tag = "%d"; //$NON-NLS-1$
|
|
832 |
} else if (type.equals(TraceParameter.POINTER)) {
|
|
833 |
tag = "%p"; //$NON-NLS-1$
|
|
834 |
} else if (type.equals(TraceParameter.HEX32)) {
|
|
835 |
tag = "%x"; //$NON-NLS-1$
|
|
836 |
} else if (type.equals(TraceParameter.UDEC32)) {
|
|
837 |
tag = "%u"; //$NON-NLS-1$
|
|
838 |
} else if (type.equals(TraceParameter.OCT32)) {
|
|
839 |
tag = "%o"; //$NON-NLS-1$
|
|
840 |
} else if (type.equals(TraceParameter.SDEC16)) {
|
|
841 |
tag = "%hd"; //$NON-NLS-1$
|
|
842 |
} else if (type.equals(TraceParameter.HEX16)) {
|
|
843 |
tag = "%hx"; //$NON-NLS-1$
|
|
844 |
} else if (type.equals(TraceParameter.UDEC16)) {
|
|
845 |
tag = "%hu"; //$NON-NLS-1$
|
|
846 |
} else if (type.equals(TraceParameter.OCT16)) {
|
|
847 |
tag = "%ho"; //$NON-NLS-1$
|
|
848 |
} else if (type.equals(TraceParameter.SDEC8)) {
|
|
849 |
tag = "%hhd"; //$NON-NLS-1$
|
|
850 |
} else if (type.equals(TraceParameter.HEX8)) {
|
|
851 |
tag = "%hhx"; //$NON-NLS-1$
|
|
852 |
} else if (type.equals(TraceParameter.UDEC8)) {
|
|
853 |
tag = "%hhu"; //$NON-NLS-1$
|
|
854 |
} else if (type.equals(TraceParameter.OCT8)) {
|
|
855 |
tag = "%hho"; //$NON-NLS-1$
|
|
856 |
} else if (type.equals(TraceParameter.SDEC64)) {
|
|
857 |
tag = "%Ld"; //$NON-NLS-1$
|
|
858 |
} else if (type.equals(TraceParameter.HEX64)) {
|
|
859 |
tag = "%Lx"; //$NON-NLS-1$
|
|
860 |
} else if (type.equals(TraceParameter.UDEC64)) {
|
|
861 |
tag = "%Lu"; //$NON-NLS-1$
|
|
862 |
} else if (type.equals(TraceParameter.OCT64)) {
|
|
863 |
tag = "%Lo"; //$NON-NLS-1$
|
|
864 |
} else if (type.equals(TraceParameter.ASCII)) {
|
|
865 |
tag = "%s"; //$NON-NLS-1$
|
|
866 |
} else if (type.equals(TraceParameter.UNICODE)) {
|
|
867 |
tag = "%S"; //$NON-NLS-1$
|
|
868 |
} else if (type.equals(TraceParameter.FLOAT_FIX)) {
|
|
869 |
tag = "%f"; //$NON-NLS-1$
|
|
870 |
} else if (type.equals(TraceParameter.FLOAT_EXP)) {
|
|
871 |
tag = "%e"; //$NON-NLS-1$
|
|
872 |
} else if (type.equals(TraceParameter.FLOAT_OPT)) {
|
|
873 |
tag = "%g"; //$NON-NLS-1$
|
|
874 |
} else {
|
|
875 |
tag = "%{" //$NON-NLS-1$
|
|
876 |
+ type + "}"; //$NON-NLS-1$
|
|
877 |
}
|
|
878 |
return tag;
|
|
879 |
}
|
|
880 |
|
|
881 |
/**
|
|
882 |
* Maps an array parameter type to format string
|
|
883 |
*
|
|
884 |
* @param type
|
|
885 |
* the parameter type
|
|
886 |
* @return the format string
|
|
887 |
*/
|
|
888 |
public static String mapArrayTypeToFormat(String type) {
|
|
889 |
String tag = "%{" //$NON-NLS-1$
|
|
890 |
+ type + "[]}"; //$NON-NLS-1$
|
|
891 |
return tag;
|
|
892 |
}
|
|
893 |
|
|
894 |
/**
|
|
895 |
* Maps format specifier to parameter length
|
|
896 |
*
|
|
897 |
* @param formatSpecifier
|
|
898 |
* the specifier
|
|
899 |
* @return the length
|
|
900 |
* @throws TraceCompilerException
|
|
901 |
* if length is not valid
|
|
902 |
*/
|
|
903 |
public static int mapFormatToParameterLength(String formatSpecifier)
|
|
904 |
throws TraceCompilerException {
|
|
905 |
Matcher matcher = SourceUtils.lengthPattern.matcher(formatSpecifier);
|
|
906 |
int paramLength = 0;
|
|
907 |
if (matcher.find()) {
|
|
908 |
String length = matcher.group();
|
|
909 |
|
|
910 |
if (length.length() == 2) { // CodForChk_Dis_Magic
|
|
911 |
if (length.charAt(0) == 'h' && length.charAt(1) == 'h') {
|
|
912 |
paramLength = SourceConstants.BYTE_SIZE;
|
|
913 |
} else if (length.charAt(0) == 'l' && length.charAt(1) == 'l') {
|
|
914 |
paramLength = SourceConstants.LONG_SIZE;
|
|
915 |
} else {
|
|
916 |
StringErrorParameters params = new StringErrorParameters();
|
|
917 |
params.string = formatSpecifier;
|
|
918 |
throw new TraceCompilerException(
|
|
919 |
TraceCompilerErrorCode.PARAMETER_FORMAT_NOT_SUPPORTED,
|
|
920 |
params, null);
|
|
921 |
}
|
|
922 |
} else if (length.length() == 1) {
|
|
923 |
switch (length.charAt(0)) {
|
|
924 |
case 'h':
|
|
925 |
paramLength = SourceConstants.SHORT_SIZE;
|
|
926 |
break;
|
|
927 |
case 'l':
|
|
928 |
paramLength = SourceConstants.INT_SIZE;
|
|
929 |
break;
|
|
930 |
case 'L':
|
|
931 |
paramLength = SourceConstants.LONG_SIZE;
|
|
932 |
break;
|
|
933 |
default:
|
|
934 |
StringErrorParameters params = new StringErrorParameters();
|
|
935 |
params.string = formatSpecifier;
|
|
936 |
throw new TraceCompilerException(
|
|
937 |
TraceCompilerErrorCode.PARAMETER_FORMAT_NOT_SUPPORTED,
|
|
938 |
params, null);
|
|
939 |
}
|
|
940 |
} else {
|
|
941 |
throw new TraceCompilerException(
|
|
942 |
TraceCompilerErrorCode.INVALID_TRACE_TEXT_FORMAT, null,
|
|
943 |
formatSpecifier);
|
|
944 |
}
|
|
945 |
}
|
|
946 |
|
|
947 |
return paramLength;
|
|
948 |
}
|
|
949 |
|
|
950 |
/**
|
|
951 |
* Maps signed parameter length to type
|
|
952 |
*
|
|
953 |
* @param paramLength
|
|
954 |
* the length
|
|
955 |
* @return the type
|
|
956 |
*/
|
|
957 |
private static String mapSignedToParameterType(int paramLength) {
|
|
958 |
String retval;
|
|
959 |
if (paramLength == SourceConstants.BYTE_SIZE) {
|
|
960 |
retval = TraceParameter.SDEC8;
|
|
961 |
} else if (paramLength == SourceConstants.SHORT_SIZE) {
|
|
962 |
retval = TraceParameter.SDEC16;
|
|
963 |
} else if (paramLength == SourceConstants.LONG_SIZE) {
|
|
964 |
retval = TraceParameter.SDEC64;
|
|
965 |
} else {
|
|
966 |
retval = TraceParameter.SDEC32;
|
|
967 |
}
|
|
968 |
return retval;
|
|
969 |
}
|
|
970 |
|
|
971 |
/**
|
|
972 |
* Maps unsigned parameter length to type
|
|
973 |
*
|
|
974 |
* @param paramLength
|
|
975 |
* the length
|
|
976 |
* @return the type
|
|
977 |
*/
|
|
978 |
public static String mapUnsignedToParameterType(int paramLength) {
|
|
979 |
String retval;
|
|
980 |
if (paramLength == SourceConstants.BYTE_SIZE) {
|
|
981 |
retval = TraceParameter.UDEC8;
|
|
982 |
} else if (paramLength == SourceConstants.SHORT_SIZE) {
|
|
983 |
retval = TraceParameter.UDEC16;
|
|
984 |
} else if (paramLength == SourceConstants.LONG_SIZE) {
|
|
985 |
retval = TraceParameter.UDEC64;
|
|
986 |
} else {
|
|
987 |
retval = TraceParameter.UDEC32;
|
|
988 |
}
|
|
989 |
return retval;
|
|
990 |
}
|
|
991 |
|
|
992 |
/**
|
|
993 |
* Maps hex parameter length to type
|
|
994 |
*
|
|
995 |
* @param paramLength
|
|
996 |
* the length
|
|
997 |
* @return the type
|
|
998 |
*/
|
|
999 |
public static String mapHexToParameterType(int paramLength) {
|
|
1000 |
String retval;
|
|
1001 |
if (paramLength == SourceConstants.BYTE_SIZE) {
|
|
1002 |
retval = TraceParameter.HEX8;
|
|
1003 |
} else if (paramLength == SourceConstants.SHORT_SIZE) {
|
|
1004 |
retval = TraceParameter.HEX16;
|
|
1005 |
} else if (paramLength == SourceConstants.LONG_SIZE) {
|
|
1006 |
retval = TraceParameter.HEX64;
|
|
1007 |
} else {
|
|
1008 |
retval = TraceParameter.HEX32;
|
|
1009 |
}
|
|
1010 |
return retval;
|
|
1011 |
}
|
|
1012 |
|
|
1013 |
/**
|
|
1014 |
* Maps octal parameter length to type
|
|
1015 |
*
|
|
1016 |
* @param paramLength
|
|
1017 |
* the length
|
|
1018 |
* @return the type
|
|
1019 |
*/
|
|
1020 |
public static String mapOctalToParameterType(int paramLength) {
|
|
1021 |
String retval;
|
|
1022 |
if (paramLength == SourceConstants.BYTE_SIZE) {
|
|
1023 |
retval = TraceParameter.OCT8;
|
|
1024 |
} else if (paramLength == SourceConstants.SHORT_SIZE) {
|
|
1025 |
retval = TraceParameter.OCT16;
|
|
1026 |
} else if (paramLength == SourceConstants.LONG_SIZE) {
|
|
1027 |
retval = TraceParameter.OCT64;
|
|
1028 |
} else {
|
|
1029 |
retval = TraceParameter.OCT32;
|
|
1030 |
}
|
|
1031 |
|
|
1032 |
return retval;
|
|
1033 |
}
|
|
1034 |
|
|
1035 |
/**
|
|
1036 |
* Checks if the parameter can be represented with default trace macros
|
|
1037 |
*
|
|
1038 |
* @param parameter
|
|
1039 |
* the parameter
|
|
1040 |
* @return true if parameter can be represented with default trace macros
|
|
1041 |
*/
|
|
1042 |
public static boolean isSimpleType(TraceParameter parameter) {
|
|
1043 |
boolean retval;
|
|
1044 |
if (parameter.getExtension(ArrayParameterRule.class) != null) {
|
|
1045 |
// Arrays are always complex types
|
|
1046 |
retval = false;
|
|
1047 |
} else {
|
|
1048 |
String type = parameter.getType();
|
|
1049 |
TraceConstantTable table = parameter.getModel()
|
|
1050 |
.findConstantTableByName(type);
|
|
1051 |
if (table != null) {
|
|
1052 |
type = table.getType();
|
|
1053 |
}
|
|
1054 |
retval = isSimpleType(type);
|
|
1055 |
}
|
|
1056 |
return retval;
|
|
1057 |
}
|
|
1058 |
|
|
1059 |
/**
|
|
1060 |
* Simple type is 32-bit integer
|
|
1061 |
*
|
|
1062 |
* @param type
|
|
1063 |
* the type
|
|
1064 |
* @return true if simple, false if not
|
|
1065 |
*/
|
|
1066 |
private static boolean isSimpleType(String type) {
|
|
1067 |
return type.equals(TraceParameter.SDEC32)
|
|
1068 |
|| type.equals(TraceParameter.UDEC32)
|
|
1069 |
|| type.equals(TraceParameter.OCT32)
|
|
1070 |
|| type.equals(TraceParameter.HEX32);
|
|
1071 |
}
|
|
1072 |
|
|
1073 |
/**
|
|
1074 |
* String type is either ascii or unicode
|
|
1075 |
*
|
|
1076 |
* @param type
|
|
1077 |
* the type
|
|
1078 |
* @return true if string, false if not
|
|
1079 |
*/
|
|
1080 |
private static boolean isStringType(String type) {
|
|
1081 |
return type.equals(TraceParameter.ASCII)
|
|
1082 |
|| type.equals(TraceParameter.UNICODE);
|
|
1083 |
}
|
|
1084 |
|
|
1085 |
/**
|
|
1086 |
* Basic type is any of the built-in TraceParameter types
|
|
1087 |
*
|
|
1088 |
* @param type
|
|
1089 |
* the type
|
|
1090 |
* @return true if basic, false if not
|
|
1091 |
*/
|
|
1092 |
private static boolean isBasicType(String type) {
|
|
1093 |
return isSimpleType(type) || type.equals(TraceParameter.SDEC8)
|
|
1094 |
|| type.equals(TraceParameter.SDEC16)
|
|
1095 |
|| type.equals(TraceParameter.UDEC8)
|
|
1096 |
|| type.equals(TraceParameter.UDEC16)
|
|
1097 |
|| type.equals(TraceParameter.OCT16)
|
|
1098 |
|| type.equals(TraceParameter.HEX8)
|
|
1099 |
|| type.equals(TraceParameter.HEX16)
|
|
1100 |
|| type.equals(TraceParameter.SDEC64)
|
|
1101 |
|| type.equals(TraceParameter.UDEC64)
|
|
1102 |
|| type.equals(TraceParameter.OCT64)
|
|
1103 |
|| type.equals(TraceParameter.HEX64)
|
|
1104 |
|| type.equals(TraceParameter.ASCII)
|
|
1105 |
|| type.equals(TraceParameter.UNICODE)
|
|
1106 |
|| type.equals(TraceParameter.FLOAT_EXP)
|
|
1107 |
|| type.equals(TraceParameter.FLOAT_FIX)
|
|
1108 |
|| type.equals(TraceParameter.FLOAT_OPT)
|
|
1109 |
|| type.equals(TraceParameter.POINTER);
|
|
1110 |
}
|
|
1111 |
|
|
1112 |
/**
|
|
1113 |
* Checks if parameter size is dynamic
|
|
1114 |
*
|
|
1115 |
* @param parameter
|
|
1116 |
* the parameter to be checked
|
|
1117 |
* @return true if dynamic size
|
|
1118 |
*/
|
|
1119 |
public static boolean isParameterSizeDynamic(TraceParameter parameter) {
|
|
1120 |
String type = parameter.getType();
|
|
1121 |
ArrayParameterRule rule = parameter
|
|
1122 |
.getExtension(ArrayParameterRule.class);
|
|
1123 |
return rule != null || type.equals(TraceParameter.ASCII)
|
|
1124 |
|| type.equals(TraceParameter.UNICODE);
|
|
1125 |
}
|
|
1126 |
|
|
1127 |
/**
|
|
1128 |
* Checks if alignment is needed
|
|
1129 |
*
|
|
1130 |
* @param type
|
|
1131 |
* the parameter type
|
|
1132 |
* @return true if alignment is needed
|
|
1133 |
*/
|
|
1134 |
public static boolean isParameterAlignementNeeded(String type) {
|
|
1135 |
int size = SourceUtils.mapParameterTypeToSize(type);
|
|
1136 |
boolean retval = false;
|
|
1137 |
if (size == 1 || size == 2) { // CodForChk_Dis_Magic
|
|
1138 |
// 8 and 16-bit parameters need alignment
|
|
1139 |
retval = true;
|
|
1140 |
} else if (isStringType(type)) {
|
|
1141 |
retval = true;
|
|
1142 |
}
|
|
1143 |
return retval;
|
|
1144 |
}
|
|
1145 |
|
|
1146 |
}
|