|
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 <cassert> |
|
17 #include "messagedefparser\enumprocessor.h" |
|
18 #include "messagedefparser\initialstate.h" |
|
19 #include "messagedefparser\definitiontokenizer.h" |
|
20 #include "util.h" |
|
21 |
|
22 namespace Parser |
|
23 { |
|
24 |
|
25 void CEnumProcessor::ProcessState() |
|
26 { |
|
27 Tokens::TTokenType tokenType = CurrentTokenType(); |
|
28 Parser::TResult result = Parser::EUnexpectedToken; |
|
29 const CIntegerTypeIdentifier* intType; |
|
30 |
|
31 switch (iInternalState) |
|
32 { |
|
33 case EStateExpectEnumIdentifierOrFormat: |
|
34 switch (tokenType) |
|
35 { |
|
36 case Tokens::EIdentifier: |
|
37 if (!ParserSM().FindIdentifier(CurrentToken())) |
|
38 { |
|
39 iIdentifier = new CEnumTypeIdentifier(CurrentToken()); |
|
40 iInternalState = EStateExpectColon; |
|
41 result = Parser::ENoError; |
|
42 } |
|
43 else |
|
44 { |
|
45 result = Parser::EDuplicateIdentifier; |
|
46 } |
|
47 break; |
|
48 |
|
49 case Tokens::EDisplayDec: |
|
50 case Tokens::EDisplayHex: |
|
51 iFormatOptions.iFormatAsHex = (tokenType == Tokens::EDisplayHex); |
|
52 iInternalState = EStateExpectEnumIdentifier; |
|
53 result = Parser::ENoError; |
|
54 break; |
|
55 } |
|
56 |
|
57 case EStateExpectEnumIdentifier: |
|
58 if (tokenType == Tokens::EIdentifier) |
|
59 { |
|
60 if (!ParserSM().FindIdentifier(CurrentToken())) |
|
61 { |
|
62 iIdentifier = new CEnumTypeIdentifier(CurrentToken()); |
|
63 iInternalState = EStateExpectColon; |
|
64 result = Parser::ENoError; |
|
65 } |
|
66 else |
|
67 { |
|
68 result = Parser::EDuplicateIdentifier; |
|
69 } |
|
70 } |
|
71 break; |
|
72 |
|
73 case EStateExpectColon: |
|
74 if (tokenType == Tokens::EColon) |
|
75 { |
|
76 iInternalState = EStateExpectBaseIntType; |
|
77 result = Parser::ENoError; |
|
78 } |
|
79 break; |
|
80 |
|
81 case EStateExpectBaseIntType: |
|
82 result = Parser::ENoError; |
|
83 iInternalState = EStateExpectEnumValueIdentifierOrEnd; |
|
84 if (tokenType == Tokens::EIntType) |
|
85 { |
|
86 intType = static_cast<const CIntegerTypeIdentifier*>(ParserSM().FindIdentifier(CurrentToken())); |
|
87 assert(intType && intType->Type() == Parser::EIntegerTypeIdentifier); |
|
88 iIdentifier->SetSize(intType->Size()); |
|
89 iIdentifier->SetSigned(intType->Signed()); |
|
90 } |
|
91 else |
|
92 { |
|
93 result = Parser::EInvalidType; |
|
94 } |
|
95 break; |
|
96 |
|
97 case EStateExpectEnumValueIdentifierOrEnd: |
|
98 if (tokenType == Tokens::EIdentifier) |
|
99 { |
|
100 if (!ParserSM().FindIdentifier(CurrentToken())) |
|
101 { |
|
102 iTempEnumValue = new CEnumValueIdentifier(CurrentToken()); |
|
103 result = Parser::ENoError; |
|
104 iInternalState = EStateExpectEquals; |
|
105 } |
|
106 else |
|
107 { |
|
108 result = Parser::EDuplicateIdentifier; |
|
109 } |
|
110 } |
|
111 else if (tokenType == Tokens::EEnd && iIdentifier->iEnumValues.size() > 0) |
|
112 { |
|
113 iInternalState = EStateExpectEndEnum; |
|
114 result = Parser::ENoError; |
|
115 } |
|
116 break; |
|
117 |
|
118 case EStateExpectEquals: |
|
119 if (tokenType == Tokens::EEquals) |
|
120 { |
|
121 result = Parser::ENoError; |
|
122 iInternalState = EStateExpectEnumValue; |
|
123 } |
|
124 break; |
|
125 |
|
126 case EStateExpectEnumValue: |
|
127 iInternalState = EStateExpectEnumValueIdentifierOrEnd; |
|
128 if (tokenType == Tokens::ENumberDec || tokenType == Tokens::ENumberHex) |
|
129 { |
|
130 if (tokenType == Tokens::ENumberDec) |
|
131 { |
|
132 iTempEnumValue->iValue = atol(CurrentToken()); |
|
133 } |
|
134 else |
|
135 { |
|
136 iTempEnumValue->iValue = HexToVal(CurrentToken()); |
|
137 } |
|
138 |
|
139 if (iIdentifier->ValueInRange(iTempEnumValue->iValue)) |
|
140 { |
|
141 ParserSM().AddIdentifier(iTempEnumValue); |
|
142 iIdentifier->AddValue(iTempEnumValue); |
|
143 iTempEnumValue = NULL; |
|
144 result = Parser::ENoError; |
|
145 } |
|
146 else |
|
147 { |
|
148 result = Parser::EValueOutOfRange; |
|
149 } |
|
150 } |
|
151 break; |
|
152 |
|
153 case EStateExpectEndEnum: |
|
154 if (tokenType == Tokens::EEnum) |
|
155 { |
|
156 result = Parser::ENoError; |
|
157 iIdentifier->iFormatOptions = iFormatOptions; |
|
158 ParserSM().AddIdentifier(iIdentifier); |
|
159 iIdentifier = NULL; |
|
160 ParserSM().SetState(new CInitialState(ParserSM())); |
|
161 } |
|
162 else |
|
163 { |
|
164 ParserSM().SetState(new CInitialState(ParserSM())); |
|
165 } |
|
166 break; |
|
167 } |
|
168 |
|
169 if (result != Parser::ENoError) |
|
170 { |
|
171 ParserSM().SetError(result); |
|
172 } |
|
173 } |
|
174 |
|
175 } // namespace Parser |
|
176 |