56
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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 |
* Trace parameter rule for adding casting and pointer operations to source code
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
package com.nokia.tracecompiler.engine.rules;
|
|
20 |
|
|
21 |
import com.nokia.tracecompiler.model.TraceModelPersistentExtension;
|
|
22 |
import com.nokia.tracecompiler.model.TraceParameter;
|
|
23 |
import com.nokia.tracecompiler.source.SourceConstants;
|
|
24 |
import com.nokia.tracecompiler.source.SourceUtils;
|
|
25 |
import com.nokia.tracecompiler.source.TypeMapping;
|
|
26 |
|
|
27 |
/**
|
|
28 |
* Trace parameter rule for adding casting and pointer operations to source code
|
|
29 |
*
|
|
30 |
*/
|
|
31 |
final class ParameterTypeMappingRule extends TraceParameterFormattingRuleBase
|
|
32 |
implements TraceModelPersistentExtension {
|
|
33 |
|
|
34 |
/**
|
|
35 |
* TTime.Int64() function
|
|
36 |
*/
|
|
37 |
private static final String INT64_FUNCTION = ".Int64()"; //$NON-NLS-1$
|
|
38 |
|
|
39 |
/**
|
|
40 |
* The type mapping
|
|
41 |
*/
|
|
42 |
private TypeMapping typeMapping;
|
|
43 |
|
|
44 |
/**
|
|
45 |
* Storage name for this parameter
|
|
46 |
*/
|
|
47 |
static String STORAGE_NAME = "TypeMapping"; //$NON-NLS-1$
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Constructor for reflection
|
|
51 |
*/
|
|
52 |
ParameterTypeMappingRule() {
|
|
53 |
typeMapping = new TypeMapping(null);
|
|
54 |
}
|
|
55 |
|
|
56 |
/**
|
|
57 |
* Creates a new type mapping rule
|
|
58 |
*
|
|
59 |
* @param mapping
|
|
60 |
* the type mapping to be used
|
|
61 |
*/
|
|
62 |
ParameterTypeMappingRule(TypeMapping mapping) {
|
|
63 |
this.typeMapping = mapping;
|
|
64 |
}
|
|
65 |
|
|
66 |
/*
|
|
67 |
* (non-Javadoc)
|
|
68 |
*
|
|
69 |
* @see com.nokia.tracecompiler.engine.rules.TraceParameterFormattingRuleBase#
|
|
70 |
* mapNameToSource(java.lang.String)
|
|
71 |
*/
|
|
72 |
@Override
|
|
73 |
public String mapNameToSource(String originalName) {
|
|
74 |
StringBuffer source = new StringBuffer();
|
|
75 |
if (typeMapping.type.equals(TraceParameter.TIME)) {
|
|
76 |
source.append(originalName);
|
|
77 |
source.append(INT64_FUNCTION);
|
|
78 |
} else {
|
|
79 |
if (typeMapping.needsCasting) {
|
|
80 |
source.append(SourceConstants.START_PARAMETERS);
|
|
81 |
TraceParameter param = (TraceParameter) getOwner();
|
|
82 |
source.append(SourceUtils.mapParameterTypeToSymbianType(param));
|
|
83 |
source.append(SourceConstants.END_PARAMETERS);
|
|
84 |
}
|
|
85 |
if (typeMapping.valueToPointer) {
|
|
86 |
source.append('&');
|
|
87 |
}
|
|
88 |
source.append(SourceConstants.START_PARAMETERS);
|
|
89 |
source.append(originalName);
|
|
90 |
source.append(SourceConstants.END_PARAMETERS);
|
|
91 |
}
|
|
92 |
return source.toString();
|
|
93 |
}
|
|
94 |
|
|
95 |
/*
|
|
96 |
* (non-Javadoc)
|
|
97 |
*
|
|
98 |
* @see com.nokia.tracecompiler.model.TraceModelPersistentExtension#getData()
|
|
99 |
*/
|
|
100 |
public String getData() {
|
|
101 |
StringBuffer sb = new StringBuffer();
|
|
102 |
if (typeMapping.needsCasting) {
|
|
103 |
sb.append('C');
|
|
104 |
}
|
|
105 |
if (typeMapping.valueToPointer) {
|
|
106 |
sb.append('V');
|
|
107 |
}
|
|
108 |
return sb.toString();
|
|
109 |
}
|
|
110 |
|
|
111 |
/*
|
|
112 |
* (non-Javadoc)
|
|
113 |
*
|
|
114 |
* @see com.nokia.tracecompiler.model.TraceModelPersistentExtension#getStorageName()
|
|
115 |
*/
|
|
116 |
public String getStorageName() {
|
|
117 |
return STORAGE_NAME;
|
|
118 |
}
|
|
119 |
|
|
120 |
/*
|
|
121 |
* (non-Javadoc)
|
|
122 |
*
|
|
123 |
* @see com.nokia.tracecompiler.model.TraceModelPersistentExtension#setData(java.lang.String)
|
|
124 |
*/
|
|
125 |
public boolean setData(String data) {
|
|
126 |
boolean retval = false;
|
|
127 |
if (data != null) {
|
|
128 |
for (int i = 0; i < data.length(); i++) {
|
|
129 |
char c = data.charAt(i);
|
|
130 |
switch (c) {
|
|
131 |
case 'C':
|
|
132 |
typeMapping.needsCasting = true;
|
|
133 |
retval = true;
|
|
134 |
break;
|
|
135 |
case 'V':
|
|
136 |
typeMapping.valueToPointer = true;
|
|
137 |
retval = true;
|
|
138 |
break;
|
|
139 |
}
|
|
140 |
}
|
|
141 |
}
|
|
142 |
return retval;
|
|
143 |
}
|
|
144 |
|
|
145 |
} |