|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "messagedefparser\signatureprocessor.h" |
|
17 #include "messagedefparser\initialstate.h" |
|
18 #include "messagedefparser\definitiontokenizer.h" |
|
19 #include "messagedefparser\integeridentifier.h" |
|
20 #include "util.h" |
|
21 |
|
22 namespace Parser |
|
23 { |
|
24 |
|
25 void CSignatureProcessor::ProcessState() |
|
26 { |
|
27 Tokens::TTokenType tokenType = CurrentTokenType(); |
|
28 Parser::TResult result = Parser::EUnexpectedToken; |
|
29 const CIdentifierBase* ident = NULL; |
|
30 |
|
31 switch (iInternalState) |
|
32 { |
|
33 case EStateExpectSignatureIdentifier: |
|
34 if (tokenType == Tokens::EIdentifier) |
|
35 { |
|
36 if (!ParserSM().FindIdentifier(CurrentToken())) |
|
37 { |
|
38 iIdentifier = new CSignatureIdentifier(CurrentToken()); |
|
39 iInternalState = EStateExpectTypeIdOrBaseColon; |
|
40 result = Parser::ENoError; |
|
41 } |
|
42 else |
|
43 { |
|
44 result = Parser::EDuplicateIdentifier; |
|
45 } |
|
46 } |
|
47 break; |
|
48 |
|
49 case EStateExpectTypeIdOrBaseColon: |
|
50 if (tokenType == Tokens::ETypeId) |
|
51 { |
|
52 result = Parser::ENoError; |
|
53 iInternalState = EStateExpectTypeIdEquals; |
|
54 } |
|
55 else if (tokenType == Tokens::EColon) |
|
56 { |
|
57 result = Parser::ENoError; |
|
58 iInternalState = EStateExpectSignatureBase; |
|
59 } |
|
60 break; |
|
61 |
|
62 case EStateExpectTypeIdEquals: |
|
63 if (tokenType == Tokens::EEquals) |
|
64 { |
|
65 result = Parser::ENoError; |
|
66 iInternalState = EStateExpectSignatureUidValue; |
|
67 } |
|
68 break; |
|
69 |
|
70 case EStateExpectSignatureUidValue: |
|
71 result = ResolveNumericToken(tokenType, CurrentToken(), 32, iIdentifier->TypeId().iUid); |
|
72 if (result == Parser::ENoError) |
|
73 { |
|
74 iInternalState = EStateExpectSignatureIdColon; |
|
75 } |
|
76 break; |
|
77 |
|
78 case EStateExpectSignatureIdColon: |
|
79 if (tokenType == Tokens::EColon) |
|
80 { |
|
81 result = Parser::ENoError; |
|
82 iInternalState = EStateExpectSignatureIdValue; |
|
83 } |
|
84 break; |
|
85 |
|
86 case EStateExpectSignatureIdValue: |
|
87 result = ResolveNumericToken(tokenType, CurrentToken(), 32, iIdentifier->TypeId().iType); |
|
88 if (result == Parser::ENoError) |
|
89 { |
|
90 iInternalState = EStateExpectMoreMembersOrEnd; |
|
91 } |
|
92 break; |
|
93 |
|
94 case EStateExpectMoreMembersOrEnd: |
|
95 result = Parser::ENoError; |
|
96 switch (tokenType) |
|
97 { |
|
98 case Tokens::EEnd: |
|
99 iInternalState = EStateExpectEndSignature; |
|
100 break; |
|
101 |
|
102 case Tokens::EIdentifier: |
|
103 case Tokens::EIntType: |
|
104 case Tokens::EPadType: |
|
105 case Tokens::EMessageIdType: |
|
106 ident = ParserSM().FindIdentifier(CurrentToken()); |
|
107 if (!ident) |
|
108 { |
|
109 result = EUnknownIdentifier; |
|
110 } |
|
111 else if (ident->Type() == EEnumTypeIdentifier || ident->Type() == EStructIdentifier |
|
112 || ident->Type() == EIntegerTypeIdentifier || ident->Type() == EContextIdentifier |
|
113 || ident->Type() == Parser::EMessageIdTypeIdentifier) |
|
114 { |
|
115 iTempMember = new TMember(); |
|
116 iTempMember->iMemberType = ident; |
|
117 |
|
118 if (ident->Type() == EIntegerTypeIdentifier) |
|
119 { |
|
120 iInternalState = EStateExpectMemberNameOrFormat; |
|
121 } |
|
122 else |
|
123 { |
|
124 iInternalState = EStateExpectMemberName; |
|
125 } |
|
126 } |
|
127 else if (ident->Type() == EPadTypeIdentifier) |
|
128 { |
|
129 iTempMember = new TMember(); |
|
130 iTempMember->iMemberType = ident; |
|
131 iInternalState = EStateExpectPadSize; |
|
132 } |
|
133 else |
|
134 { |
|
135 result = Parser::EInvalidType; |
|
136 } |
|
137 break; |
|
138 |
|
139 default: |
|
140 result = Parser::EUnexpectedToken; |
|
141 } |
|
142 break; |
|
143 |
|
144 case EStateExpectMemberNameOrFormat: |
|
145 switch (tokenType) |
|
146 { |
|
147 case Tokens::EIdentifier: |
|
148 if (iIdentifier->FindMember(CurrentToken())) |
|
149 { |
|
150 result = Parser::EDuplicateIdentifier; |
|
151 delete iTempMember; |
|
152 } |
|
153 else |
|
154 { |
|
155 iTempMember->iMemberName = _strdup(CurrentToken()); |
|
156 iIdentifier->AddMember(iTempMember); |
|
157 result = Parser::ENoError; |
|
158 } |
|
159 iTempMember = NULL; |
|
160 iInternalState = EStateExpectMoreMembersOrEnd; |
|
161 break; |
|
162 |
|
163 case Tokens::EDisplayDec: |
|
164 case Tokens::EDisplayHex: |
|
165 iTempMember->iIdentifierOptions = new TIntegerIdentifierOptions(tokenType == Tokens::EDisplayHex); |
|
166 iInternalState = EStateExpectMemberName; |
|
167 result = Parser::ENoError; |
|
168 break; |
|
169 } |
|
170 break; |
|
171 |
|
172 case EStateExpectMemberName: |
|
173 if (tokenType == Tokens::EIdentifier) |
|
174 { |
|
175 if (iIdentifier->FindMember(CurrentToken())) |
|
176 { |
|
177 result = Parser::EDuplicateIdentifier; |
|
178 delete iTempMember; |
|
179 } |
|
180 else |
|
181 { |
|
182 iTempMember->iMemberName = _strdup(CurrentToken()); |
|
183 iIdentifier->AddMember(iTempMember); |
|
184 result = Parser::ENoError; |
|
185 } |
|
186 iTempMember = NULL; |
|
187 iInternalState = EStateExpectMoreMembersOrEnd; |
|
188 } |
|
189 break; |
|
190 |
|
191 case EStateExpectEndSignature: |
|
192 if (tokenType == Tokens::ESignature) |
|
193 { |
|
194 result = Parser::ENoError; |
|
195 ParserSM().AddIdentifier(iIdentifier); |
|
196 iIdentifier = NULL; |
|
197 } |
|
198 ParserSM().SetState(new CInitialState(ParserSM())); |
|
199 break; |
|
200 |
|
201 case EStateExpectSignatureBase: |
|
202 iInternalState = EStateExpectTypeId; |
|
203 if (tokenType == Tokens::EIdentifier) |
|
204 { |
|
205 ident = ParserSM().FindIdentifier(CurrentToken()); |
|
206 if (!ident) |
|
207 { |
|
208 result = Parser::EUnknownIdentifier; |
|
209 } |
|
210 else if (ident->Type() == Parser::ESignatureIdentifier) |
|
211 { |
|
212 iIdentifier->SetBaseSignature(static_cast<const CSignatureIdentifier*>(ident)); |
|
213 result = Parser::ENoError; |
|
214 } |
|
215 else |
|
216 { |
|
217 result = Parser::EInvalidType; |
|
218 } |
|
219 } |
|
220 break; |
|
221 |
|
222 case EStateExpectTypeId: |
|
223 if (tokenType == Tokens::ETypeId) |
|
224 { |
|
225 result = Parser::ENoError; |
|
226 iInternalState = EStateExpectTypeIdEquals; |
|
227 } |
|
228 break; |
|
229 |
|
230 case EStateExpectPadSize: |
|
231 { |
|
232 result = Parser::ENoError; |
|
233 iInternalState = 6; |
|
234 unsigned int v = 0; |
|
235 if (tokenType == Tokens::ENumberHex) |
|
236 { |
|
237 v = HexToVal(CurrentToken()); |
|
238 } |
|
239 else if (tokenType == Tokens::ENumberDec) |
|
240 { |
|
241 v = atol(CurrentToken()); |
|
242 } |
|
243 else |
|
244 { |
|
245 result = Parser::EUnexpectedToken; |
|
246 delete iTempMember; |
|
247 } |
|
248 if (result == Parser::ENoError) |
|
249 { |
|
250 if (v >= 1) |
|
251 { |
|
252 iTempMember->iArraySize = v; |
|
253 iIdentifier->AddMember(iTempMember); |
|
254 } |
|
255 else |
|
256 { |
|
257 result = Parser::EValueOutOfRange; |
|
258 delete iTempMember; |
|
259 } |
|
260 } |
|
261 iTempMember = NULL; |
|
262 } |
|
263 break; |
|
264 } |
|
265 |
|
266 if (result != Parser::ENoError) |
|
267 { |
|
268 ParserSM().SetError(result); |
|
269 } |
|
270 } |
|
271 |
|
272 } // namespace Parser |
|
273 |