]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | /** @file\r |
2 | \r | |
3 | VfrCompiler error handler.\r | |
4 | \r | |
4afd3d04 | 5 | Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r |
40d841f6 | 6 | This program and the accompanying materials \r |
30fdf114 LG |
7 | are licensed and made available under the terms and conditions of the BSD License \r |
8 | which accompanies this distribution. The full text of the license may be found at \r | |
9 | http://opensource.org/licenses/bsd-license.php \r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "stdio.h"\r | |
17 | #include "string.h"\r | |
18 | #include "stdlib.h"\r | |
19 | #include "VfrError.h"\r | |
20 | #include "EfiUtilityMsgs.h"\r | |
21 | \r | |
22 | static SVFR_ERROR_HANDLE VFR_ERROR_HANDLE_TABLE [] = {\r | |
23 | { VFR_RETURN_SUCCESS, NULL },\r | |
24 | { VFR_RETURN_ERROR_SKIPED, NULL },\r | |
25 | { VFR_RETURN_FATAL_ERROR, ": fatal error!!" },\r | |
26 | \r | |
27 | { VFR_RETURN_MISMATCHED, ": unexpected token" },\r | |
28 | { VFR_RETURN_INVALID_PARAMETER, ": invalid parameter" },\r | |
29 | { VFR_RETURN_OUT_FOR_RESOURCES, ": system out of memory" },\r | |
30 | { VFR_RETURN_UNSUPPORTED, ": unsupported" },\r | |
31 | { VFR_RETURN_REDEFINED, ": already defined" },\r | |
32 | { VFR_RETURN_FORMID_REDEFINED, ": form id already defined" },\r | |
33 | { VFR_RETURN_QUESTIONID_REDEFINED, ": question id already defined" },\r | |
34 | { VFR_RETURN_VARSTOREID_REDEFINED, ": varstore id already defined" },\r | |
35 | { VFR_RETURN_UNDEFINED, ": undefined" },\r | |
36 | { VFR_RETURN_VAR_NOTDEFINED_BY_QUESTION, ": some variable has not defined by a question"},\r | |
da92f276 | 37 | { VFR_RETURN_VARSTORE_DATATYPE_REDEFINED_ERROR, ": Data Structure is defined by more than one varstores, it can't be referred as varstore, only varstore name could be used."},\r |
30fdf114 LG |
38 | { VFR_RETURN_GET_EFIVARSTORE_ERROR, ": get efi varstore error"},\r |
39 | { VFR_RETURN_EFIVARSTORE_USE_ERROR, ": can not use the efi varstore like this" },\r | |
40 | { VFR_RETURN_EFIVARSTORE_SIZE_ERROR, ": unsupport efi varstore size should be <= 8 bytes" },\r | |
41 | { VFR_RETURN_GET_NVVARSTORE_ERROR, ": get name value varstore error" },\r | |
42 | { VFR_RETURN_QVAR_REUSE, ": variable reused by more than one question" },\r | |
43 | { VFR_RETURN_FLAGS_UNSUPPORTED, ": flags unsupported" },\r | |
44 | { VFR_RETURN_ERROR_ARRARY_NUM, ": array number error, the valid value is in (0 ~ MAX_INDEX-1) for UEFI vfr and in (1 ~ MAX_INDEX) for Framework Vfr" },\r | |
45 | { VFR_RETURN_DATA_STRING_ERROR, ": data field string error or not support"},\r | |
46 | { VFR_RETURN_DEFAULT_VALUE_REDEFINED, ": default value re-defined with different value"},\r | |
47 | { VFR_RETURN_CONSTANT_ONLY, ": only constant is allowed in the expression"},\r | |
4afd3d04 | 48 | { VFR_RETURN_VARSTORE_NAME_REDEFINED_ERROR, ": Varstore name is defined by more than one varstores, it can't be referred as varstore, only varstore strucure name could be used."},\r |
30fdf114 LG |
49 | { VFR_RETURN_CODEUNDEFINED, ": undefined Error Code" }\r |
50 | };\r | |
51 | \r | |
4afd3d04 LG |
52 | static SVFR_WARNING_HANDLE VFR_WARNING_HANDLE_TABLE [] = {\r |
53 | { VFR_WARNING_DEFAULT_VALUE_REDEFINED, ": default value re-defined with different value"},\r | |
e4ac870f | 54 | { VFR_WARNING_STRING_TO_UINT_OVERFLOW, ": String to UINT* Overflow"},\r |
1d218f83 | 55 | { VFR_WARNING_ACTION_WITH_TEXT_TWO, ": Action opcode should not have TextTwo part"},\r |
4afd3d04 LG |
56 | { VFR_WARNING_CODEUNDEFINED, ": undefined Warning Code" }\r |
57 | };\r | |
58 | \r | |
30fdf114 LG |
59 | CVfrErrorHandle::CVfrErrorHandle (\r |
60 | VOID\r | |
61 | )\r | |
62 | {\r | |
4afd3d04 LG |
63 | mInputFileName = NULL;\r |
64 | mScopeRecordListHead = NULL;\r | |
65 | mScopeRecordListTail = NULL;\r | |
66 | mVfrErrorHandleTable = VFR_ERROR_HANDLE_TABLE;\r | |
67 | mVfrWarningHandleTable = VFR_WARNING_HANDLE_TABLE;\r | |
30fdf114 LG |
68 | }\r |
69 | \r | |
70 | CVfrErrorHandle::~CVfrErrorHandle (\r | |
71 | VOID\r | |
72 | )\r | |
73 | {\r | |
74 | SVfrFileScopeRecord *pNode = NULL;\r | |
75 | \r | |
76 | if (mInputFileName != NULL) {\r | |
77 | delete mInputFileName;\r | |
78 | }\r | |
79 | \r | |
80 | while (mScopeRecordListHead != NULL) {\r | |
81 | pNode = mScopeRecordListHead;\r | |
82 | mScopeRecordListHead = mScopeRecordListHead->mNext;\r | |
83 | delete pNode;\r | |
84 | }\r | |
85 | \r | |
4afd3d04 LG |
86 | mScopeRecordListHead = NULL;\r |
87 | mScopeRecordListTail = NULL;\r | |
88 | mVfrErrorHandleTable = NULL;\r | |
89 | mVfrWarningHandleTable = NULL;\r | |
90 | }\r | |
91 | \r | |
92 | VOID\r | |
93 | CVfrErrorHandle::SetWarningAsError (\r | |
94 | IN BOOLEAN WarningAsError\r | |
95 | )\r | |
96 | {\r | |
97 | mWarningAsError = WarningAsError;\r | |
30fdf114 LG |
98 | }\r |
99 | \r | |
100 | VOID\r | |
101 | CVfrErrorHandle::SetInputFile (\r | |
102 | IN CHAR8 *InputFile\r | |
103 | )\r | |
104 | {\r | |
105 | if (InputFile != NULL) {\r | |
106 | mInputFileName = new CHAR8[strlen(InputFile) + 1];\r | |
107 | strcpy (mInputFileName, InputFile);\r | |
108 | }\r | |
109 | }\r | |
110 | \r | |
111 | SVfrFileScopeRecord::SVfrFileScopeRecord (\r | |
112 | IN CHAR8 *Record, \r | |
113 | IN UINT32 LineNum\r | |
114 | )\r | |
115 | {\r | |
116 | UINT32 Index;\r | |
117 | CHAR8 *FileName = NULL;\r | |
118 | CHAR8 *Str = NULL;\r | |
119 | \r | |
120 | mWholeScopeLine = LineNum;\r | |
121 | mNext = NULL;\r | |
122 | \r | |
123 | Str = strchr (Record, ' ');\r | |
124 | mScopeLineStart = atoi (++Str);\r | |
125 | \r | |
126 | Str = strchr (Str, '\"');\r | |
127 | FileName = ++Str;\r | |
128 | \r | |
129 | while((Str = strstr (FileName, "\\\\")) != NULL) {\r | |
130 | FileName = Str + 2;\r | |
131 | }\r | |
132 | if ((mFileName = new CHAR8[strlen(FileName)]) != NULL) {\r | |
133 | for (Index = 0; FileName[Index] != '\"'; Index++) {\r | |
134 | mFileName[Index] = FileName[Index];\r | |
135 | }\r | |
136 | mFileName[Index] = '\0';\r | |
137 | }\r | |
138 | \r | |
139 | return;\r | |
140 | }\r | |
141 | \r | |
142 | SVfrFileScopeRecord::~SVfrFileScopeRecord (\r | |
143 | VOID\r | |
144 | )\r | |
145 | {\r | |
146 | if (mFileName != NULL) {\r | |
147 | delete mFileName;\r | |
148 | }\r | |
149 | }\r | |
150 | \r | |
151 | VOID\r | |
152 | CVfrErrorHandle::ParseFileScopeRecord (\r | |
153 | IN CHAR8 *Record, \r | |
154 | IN UINT32 WholeScopeLine\r | |
155 | )\r | |
156 | {\r | |
30fdf114 LG |
157 | SVfrFileScopeRecord *pNode = NULL;\r |
158 | \r | |
159 | if (Record == NULL) {\r | |
160 | return;\r | |
161 | }\r | |
162 | \r | |
163 | if ((pNode = new SVfrFileScopeRecord(Record, WholeScopeLine)) == NULL) {\r | |
164 | return;\r | |
165 | }\r | |
166 | \r | |
167 | if (mScopeRecordListHead == NULL) {\r | |
168 | mScopeRecordListTail = mScopeRecordListHead = pNode;\r | |
169 | } else {\r | |
170 | mScopeRecordListTail->mNext = pNode;\r | |
171 | mScopeRecordListTail = pNode;\r | |
172 | }\r | |
173 | }\r | |
174 | \r | |
175 | VOID\r | |
176 | CVfrErrorHandle::GetFileNameLineNum (\r | |
177 | IN UINT32 LineNum,\r | |
178 | OUT CHAR8 **FileName,\r | |
179 | OUT UINT32 *FileLine\r | |
180 | )\r | |
181 | {\r | |
182 | SVfrFileScopeRecord *pNode = NULL;\r | |
183 | \r | |
184 | if ((FileName == NULL) || (FileLine == NULL)) {\r | |
185 | return;\r | |
186 | }\r | |
187 | \r | |
188 | *FileName = NULL;\r | |
189 | *FileLine = 0xFFFFFFFF;\r | |
190 | \r | |
191 | //\r | |
192 | // Some errors occur before scope record list been built.\r | |
193 | //\r | |
194 | if (mScopeRecordListHead == NULL) {\r | |
195 | *FileLine = LineNum;\r | |
196 | *FileName = mInputFileName;\r | |
197 | return ;\r | |
198 | }\r | |
199 | \r | |
200 | for (pNode = mScopeRecordListHead; pNode->mNext != NULL; pNode = pNode->mNext) {\r | |
201 | if ((LineNum > pNode->mWholeScopeLine) && (pNode->mNext->mWholeScopeLine > LineNum)) {\r | |
202 | *FileName = pNode->mFileName;\r | |
203 | *FileLine = LineNum - pNode->mWholeScopeLine + pNode->mScopeLineStart - 1;\r | |
204 | return ;\r | |
205 | }\r | |
206 | }\r | |
207 | \r | |
208 | *FileName = pNode->mFileName;\r | |
209 | *FileLine = LineNum - pNode->mWholeScopeLine + pNode->mScopeLineStart - 1;\r | |
210 | }\r | |
211 | \r | |
212 | VOID\r | |
213 | CVfrErrorHandle::PrintMsg (\r | |
214 | IN UINT32 LineNum,\r | |
215 | IN CHAR8 *TokName,\r | |
52302d4d LG |
216 | IN CONST CHAR8 *MsgType,\r |
217 | IN CONST CHAR8 *ErrorMsg\r | |
30fdf114 LG |
218 | )\r |
219 | {\r | |
220 | CHAR8 *FileName = NULL;\r | |
221 | UINT32 FileLine;\r | |
fd171542 | 222 | \r |
223 | if (strncmp ("Warning", MsgType, strlen ("Warning")) == 0) {\r | |
52302d4d | 224 | VerboseMsg ((CHAR8 *) ErrorMsg);\r |
fd171542 | 225 | return;\r |
226 | }\r | |
30fdf114 | 227 | GetFileNameLineNum (LineNum, &FileName, &FileLine);\r |
52302d4d | 228 | Error (FileName, FileLine, 0x3000, TokName, (CHAR8 *) "\t%s\n", (CHAR8 *) ErrorMsg);\r |
30fdf114 LG |
229 | }\r |
230 | \r | |
231 | UINT8\r | |
232 | CVfrErrorHandle::HandleError (\r | |
233 | IN EFI_VFR_RETURN_CODE ErrorCode,\r | |
234 | IN UINT32 LineNum,\r | |
235 | IN CHAR8 *TokName\r | |
236 | )\r | |
237 | {\r | |
238 | UINT32 Index;\r | |
239 | CHAR8 *FileName = NULL;\r | |
240 | UINT32 FileLine;\r | |
52302d4d | 241 | CONST CHAR8 *ErrorMsg = NULL;\r |
30fdf114 LG |
242 | \r |
243 | if (mVfrErrorHandleTable == NULL) {\r | |
244 | return 1;\r | |
245 | }\r | |
246 | \r | |
247 | for (Index = 0; mVfrErrorHandleTable[Index].mErrorCode != VFR_RETURN_CODEUNDEFINED; Index++) {\r | |
248 | if (ErrorCode == mVfrErrorHandleTable[Index].mErrorCode) {\r | |
249 | ErrorMsg = mVfrErrorHandleTable[Index].mErrorMsg;\r | |
250 | break;\r | |
251 | }\r | |
252 | }\r | |
253 | \r | |
254 | if (ErrorMsg != NULL) {\r | |
255 | GetFileNameLineNum (LineNum, &FileName, &FileLine);\r | |
52302d4d | 256 | Error (FileName, FileLine, 0x3000, TokName, (CHAR8 *) "\t%s\n", (CHAR8 *) ErrorMsg);\r |
30fdf114 LG |
257 | return 1;\r |
258 | } else {\r | |
259 | return 0;\r | |
260 | }\r | |
261 | }\r | |
262 | \r | |
4afd3d04 LG |
263 | UINT8\r |
264 | CVfrErrorHandle::HandleWarning (\r | |
265 | IN EFI_VFR_WARNING_CODE WarningCode,\r | |
266 | IN UINT32 LineNum,\r | |
267 | IN CHAR8 *TokName\r | |
268 | )\r | |
269 | {\r | |
270 | UINT32 Index;\r | |
271 | CHAR8 *FileName = NULL;\r | |
272 | UINT32 FileLine;\r | |
273 | CONST CHAR8 *WarningMsg = NULL;\r | |
274 | \r | |
275 | if (mVfrWarningHandleTable == NULL) {\r | |
276 | return 1;\r | |
277 | }\r | |
278 | \r | |
279 | GetFileNameLineNum (LineNum, &FileName, &FileLine);\r | |
280 | \r | |
281 | if (mWarningAsError) {\r | |
282 | Error (FileName, FileLine, 0x2220, "warning treated as error", NULL);\r | |
283 | }\r | |
284 | \r | |
285 | for (Index = 0; mVfrWarningHandleTable[Index].mWarningCode != VFR_WARNING_CODEUNDEFINED; Index++) {\r | |
286 | if (WarningCode == mVfrWarningHandleTable[Index].mWarningCode) {\r | |
287 | WarningMsg = mVfrWarningHandleTable[Index].mWarningMsg;\r | |
288 | break;\r | |
289 | }\r | |
290 | }\r | |
291 | \r | |
292 | if (WarningMsg != NULL) {\r | |
293 | Warning (FileName, FileLine, 0, TokName, (CHAR8 *) "\t%s\n", (CHAR8 *) WarningMsg);\r | |
294 | return 1;\r | |
295 | } else {\r | |
296 | return 0;\r | |
297 | }\r | |
298 | }\r | |
299 | \r | |
30fdf114 | 300 | CVfrErrorHandle gCVfrErrorHandle;\r |