]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/C/VfrCompile/VfrError.cpp
ShellPkg: Fix Ctrl+C support for dmpstore command.
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / VfrError.cpp
... / ...
CommitLineData
1/** @file\r
2 \r
3 VfrCompiler error handler.\r
4\r
5Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials \r
7are licensed and made available under the terms and conditions of the BSD License \r
8which accompanies this distribution. The full text of the license may be found at \r
9http://opensource.org/licenses/bsd-license.php \r
10 \r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
12WITHOUT 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
22static 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
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
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
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
49 { VFR_RETURN_CODEUNDEFINED, ": undefined Error Code" }\r
50};\r
51\r
52static SVFR_WARNING_HANDLE VFR_WARNING_HANDLE_TABLE [] = {\r
53 { VFR_WARNING_DEFAULT_VALUE_REDEFINED, ": default value re-defined with different value"},\r
54 { VFR_WARNING_CODEUNDEFINED, ": undefined Warning Code" }\r
55};\r
56\r
57CVfrErrorHandle::CVfrErrorHandle (\r
58 VOID\r
59 )\r
60{\r
61 mInputFileName = NULL;\r
62 mScopeRecordListHead = NULL;\r
63 mScopeRecordListTail = NULL;\r
64 mVfrErrorHandleTable = VFR_ERROR_HANDLE_TABLE;\r
65 mVfrWarningHandleTable = VFR_WARNING_HANDLE_TABLE;\r
66}\r
67\r
68CVfrErrorHandle::~CVfrErrorHandle (\r
69 VOID\r
70 )\r
71{\r
72 SVfrFileScopeRecord *pNode = NULL;\r
73\r
74 if (mInputFileName != NULL) {\r
75 delete mInputFileName;\r
76 }\r
77\r
78 while (mScopeRecordListHead != NULL) {\r
79 pNode = mScopeRecordListHead;\r
80 mScopeRecordListHead = mScopeRecordListHead->mNext;\r
81 delete pNode;\r
82 }\r
83\r
84 mScopeRecordListHead = NULL;\r
85 mScopeRecordListTail = NULL;\r
86 mVfrErrorHandleTable = NULL;\r
87 mVfrWarningHandleTable = NULL;\r
88}\r
89\r
90VOID\r
91CVfrErrorHandle::SetWarningAsError (\r
92 IN BOOLEAN WarningAsError\r
93 )\r
94{\r
95 mWarningAsError = WarningAsError;\r
96}\r
97\r
98VOID\r
99CVfrErrorHandle::SetInputFile (\r
100 IN CHAR8 *InputFile\r
101 )\r
102{\r
103 if (InputFile != NULL) {\r
104 mInputFileName = new CHAR8[strlen(InputFile) + 1];\r
105 strcpy (mInputFileName, InputFile);\r
106 }\r
107}\r
108\r
109SVfrFileScopeRecord::SVfrFileScopeRecord (\r
110 IN CHAR8 *Record, \r
111 IN UINT32 LineNum\r
112 )\r
113{\r
114 UINT32 Index;\r
115 CHAR8 *FileName = NULL;\r
116 CHAR8 *Str = NULL;\r
117\r
118 mWholeScopeLine = LineNum;\r
119 mNext = NULL;\r
120\r
121 Str = strchr (Record, ' ');\r
122 mScopeLineStart = atoi (++Str);\r
123\r
124 Str = strchr (Str, '\"');\r
125 FileName = ++Str;\r
126\r
127 while((Str = strstr (FileName, "\\\\")) != NULL) {\r
128 FileName = Str + 2;\r
129 }\r
130 if ((mFileName = new CHAR8[strlen(FileName)]) != NULL) {\r
131 for (Index = 0; FileName[Index] != '\"'; Index++) {\r
132 mFileName[Index] = FileName[Index];\r
133 }\r
134 mFileName[Index] = '\0';\r
135 }\r
136\r
137 return;\r
138}\r
139\r
140SVfrFileScopeRecord::~SVfrFileScopeRecord (\r
141 VOID\r
142 )\r
143{\r
144 if (mFileName != NULL) {\r
145 delete mFileName;\r
146 }\r
147}\r
148\r
149VOID\r
150CVfrErrorHandle::ParseFileScopeRecord (\r
151 IN CHAR8 *Record, \r
152 IN UINT32 WholeScopeLine\r
153 )\r
154{\r
155 SVfrFileScopeRecord *pNode = NULL;\r
156\r
157 if (Record == NULL) {\r
158 return;\r
159 }\r
160\r
161 if ((pNode = new SVfrFileScopeRecord(Record, WholeScopeLine)) == NULL) {\r
162 return;\r
163 }\r
164\r
165 if (mScopeRecordListHead == NULL) {\r
166 mScopeRecordListTail = mScopeRecordListHead = pNode;\r
167 } else {\r
168 mScopeRecordListTail->mNext = pNode;\r
169 mScopeRecordListTail = pNode;\r
170 }\r
171}\r
172\r
173VOID\r
174CVfrErrorHandle::GetFileNameLineNum (\r
175 IN UINT32 LineNum,\r
176 OUT CHAR8 **FileName,\r
177 OUT UINT32 *FileLine\r
178 )\r
179{\r
180 SVfrFileScopeRecord *pNode = NULL;\r
181\r
182 if ((FileName == NULL) || (FileLine == NULL)) {\r
183 return;\r
184 }\r
185\r
186 *FileName = NULL;\r
187 *FileLine = 0xFFFFFFFF;\r
188\r
189 //\r
190 // Some errors occur before scope record list been built.\r
191 //\r
192 if (mScopeRecordListHead == NULL) {\r
193 *FileLine = LineNum;\r
194 *FileName = mInputFileName;\r
195 return ;\r
196 }\r
197\r
198 for (pNode = mScopeRecordListHead; pNode->mNext != NULL; pNode = pNode->mNext) {\r
199 if ((LineNum > pNode->mWholeScopeLine) && (pNode->mNext->mWholeScopeLine > LineNum)) {\r
200 *FileName = pNode->mFileName;\r
201 *FileLine = LineNum - pNode->mWholeScopeLine + pNode->mScopeLineStart - 1;\r
202 return ;\r
203 }\r
204 }\r
205\r
206 *FileName = pNode->mFileName;\r
207 *FileLine = LineNum - pNode->mWholeScopeLine + pNode->mScopeLineStart - 1;\r
208}\r
209\r
210VOID\r
211CVfrErrorHandle::PrintMsg (\r
212 IN UINT32 LineNum,\r
213 IN CHAR8 *TokName,\r
214 IN CONST CHAR8 *MsgType,\r
215 IN CONST CHAR8 *ErrorMsg\r
216 )\r
217{\r
218 CHAR8 *FileName = NULL;\r
219 UINT32 FileLine;\r
220 \r
221 if (strncmp ("Warning", MsgType, strlen ("Warning")) == 0) {\r
222 VerboseMsg ((CHAR8 *) ErrorMsg);\r
223 return;\r
224 }\r
225 GetFileNameLineNum (LineNum, &FileName, &FileLine);\r
226 Error (FileName, FileLine, 0x3000, TokName, (CHAR8 *) "\t%s\n", (CHAR8 *) ErrorMsg);\r
227}\r
228\r
229UINT8\r
230CVfrErrorHandle::HandleError (\r
231 IN EFI_VFR_RETURN_CODE ErrorCode,\r
232 IN UINT32 LineNum,\r
233 IN CHAR8 *TokName\r
234 )\r
235{\r
236 UINT32 Index;\r
237 CHAR8 *FileName = NULL;\r
238 UINT32 FileLine;\r
239 CONST CHAR8 *ErrorMsg = NULL;\r
240\r
241 if (mVfrErrorHandleTable == NULL) {\r
242 return 1;\r
243 }\r
244\r
245 for (Index = 0; mVfrErrorHandleTable[Index].mErrorCode != VFR_RETURN_CODEUNDEFINED; Index++) {\r
246 if (ErrorCode == mVfrErrorHandleTable[Index].mErrorCode) {\r
247 ErrorMsg = mVfrErrorHandleTable[Index].mErrorMsg;\r
248 break;\r
249 }\r
250 }\r
251\r
252 if (ErrorMsg != NULL) {\r
253 GetFileNameLineNum (LineNum, &FileName, &FileLine);\r
254 Error (FileName, FileLine, 0x3000, TokName, (CHAR8 *) "\t%s\n", (CHAR8 *) ErrorMsg);\r
255 return 1;\r
256 } else {\r
257 return 0;\r
258 }\r
259}\r
260\r
261UINT8\r
262CVfrErrorHandle::HandleWarning (\r
263 IN EFI_VFR_WARNING_CODE WarningCode,\r
264 IN UINT32 LineNum,\r
265 IN CHAR8 *TokName\r
266 )\r
267{\r
268 UINT32 Index;\r
269 CHAR8 *FileName = NULL;\r
270 UINT32 FileLine;\r
271 CONST CHAR8 *WarningMsg = NULL;\r
272\r
273 if (mVfrWarningHandleTable == NULL) {\r
274 return 1;\r
275 }\r
276\r
277 GetFileNameLineNum (LineNum, &FileName, &FileLine);\r
278\r
279 if (mWarningAsError) {\r
280 Error (FileName, FileLine, 0x2220, "warning treated as error", NULL);\r
281 }\r
282\r
283 for (Index = 0; mVfrWarningHandleTable[Index].mWarningCode != VFR_WARNING_CODEUNDEFINED; Index++) {\r
284 if (WarningCode == mVfrWarningHandleTable[Index].mWarningCode) {\r
285 WarningMsg = mVfrWarningHandleTable[Index].mWarningMsg;\r
286 break;\r
287 }\r
288 }\r
289\r
290 if (WarningMsg != NULL) {\r
291 Warning (FileName, FileLine, 0, TokName, (CHAR8 *) "\t%s\n", (CHAR8 *) WarningMsg);\r
292 return 1;\r
293 } else {\r
294 return 0;\r
295 }\r
296}\r
297\r
298CVfrErrorHandle gCVfrErrorHandle;\r