]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/C/VfrCompile/VfrError.cpp
BaseTools/VfrCompile: Explicitly state format string for DebugMsg()
[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 - 2016, 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_STRING_TO_UINT_OVERFLOW, ": String to UINT* Overflow"},\r
55 { VFR_WARNING_ACTION_WITH_TEXT_TWO, ": Action opcode should not have TextTwo part"},\r
56 { VFR_WARNING_OBSOLETED_FRAMEWORK_OPCODE, ": Not recommend to use obsoleted framework opcode"},\r
57 { VFR_WARNING_CODEUNDEFINED, ": undefined Warning Code" }\r
58};\r
59\r
60CVfrErrorHandle::CVfrErrorHandle (\r
61 VOID\r
62 )\r
63{\r
64 mInputFileName = NULL;\r
65 mScopeRecordListHead = NULL;\r
66 mScopeRecordListTail = NULL;\r
67 mVfrErrorHandleTable = VFR_ERROR_HANDLE_TABLE;\r
68 mVfrWarningHandleTable = VFR_WARNING_HANDLE_TABLE;\r
69}\r
70\r
71CVfrErrorHandle::~CVfrErrorHandle (\r
72 VOID\r
73 )\r
74{\r
75 SVfrFileScopeRecord *pNode = NULL;\r
76\r
77 if (mInputFileName != NULL) {\r
78 delete mInputFileName;\r
79 }\r
80\r
81 while (mScopeRecordListHead != NULL) {\r
82 pNode = mScopeRecordListHead;\r
83 mScopeRecordListHead = mScopeRecordListHead->mNext;\r
84 delete pNode;\r
85 }\r
86\r
87 mScopeRecordListHead = NULL;\r
88 mScopeRecordListTail = NULL;\r
89 mVfrErrorHandleTable = NULL;\r
90 mVfrWarningHandleTable = NULL;\r
91}\r
92\r
93VOID\r
94CVfrErrorHandle::SetWarningAsError (\r
95 IN BOOLEAN WarningAsError\r
96 )\r
97{\r
98 mWarningAsError = WarningAsError;\r
99}\r
100\r
101VOID\r
102CVfrErrorHandle::SetInputFile (\r
103 IN CHAR8 *InputFile\r
104 )\r
105{\r
106 if (InputFile != NULL) {\r
107 mInputFileName = new CHAR8[strlen(InputFile) + 1];\r
108 strcpy (mInputFileName, InputFile);\r
109 }\r
110}\r
111\r
112SVfrFileScopeRecord::SVfrFileScopeRecord (\r
113 IN CHAR8 *Record, \r
114 IN UINT32 LineNum\r
115 )\r
116{\r
117 UINT32 Index;\r
118 CHAR8 *FileName = NULL;\r
119 CHAR8 *Str = NULL;\r
120\r
121 mWholeScopeLine = LineNum;\r
122 mNext = NULL;\r
123\r
124 Str = strchr (Record, ' ');\r
125 mScopeLineStart = atoi (++Str);\r
126\r
127 Str = strchr (Str, '\"');\r
128 FileName = ++Str;\r
129\r
130 while((Str = strstr (FileName, "\\\\")) != NULL) {\r
131 FileName = Str + 2;\r
132 }\r
133 if ((mFileName = new CHAR8[strlen(FileName)]) != NULL) {\r
134 for (Index = 0; FileName[Index] != '\"'; Index++) {\r
135 mFileName[Index] = FileName[Index];\r
136 }\r
137 mFileName[Index] = '\0';\r
138 }\r
139\r
140 return;\r
141}\r
142\r
143SVfrFileScopeRecord::~SVfrFileScopeRecord (\r
144 VOID\r
145 )\r
146{\r
147 if (mFileName != NULL) {\r
148 delete[] mFileName;\r
149 }\r
150}\r
151\r
152VOID\r
153CVfrErrorHandle::ParseFileScopeRecord (\r
154 IN CHAR8 *Record, \r
155 IN UINT32 WholeScopeLine\r
156 )\r
157{\r
158 SVfrFileScopeRecord *pNode = NULL;\r
159\r
160 if (Record == NULL) {\r
161 return;\r
162 }\r
163\r
164 if ((pNode = new SVfrFileScopeRecord(Record, WholeScopeLine)) == NULL) {\r
165 return;\r
166 }\r
167\r
168 if (mScopeRecordListHead == NULL) {\r
169 mScopeRecordListTail = mScopeRecordListHead = pNode;\r
170 } else {\r
171 mScopeRecordListTail->mNext = pNode;\r
172 mScopeRecordListTail = pNode;\r
173 }\r
174}\r
175\r
176VOID\r
177CVfrErrorHandle::GetFileNameLineNum (\r
178 IN UINT32 LineNum,\r
179 OUT CHAR8 **FileName,\r
180 OUT UINT32 *FileLine\r
181 )\r
182{\r
183 SVfrFileScopeRecord *pNode = NULL;\r
184\r
185 if ((FileName == NULL) || (FileLine == NULL)) {\r
186 return;\r
187 }\r
188\r
189 *FileName = NULL;\r
190 *FileLine = 0xFFFFFFFF;\r
191\r
192 //\r
193 // Some errors occur before scope record list been built.\r
194 //\r
195 if (mScopeRecordListHead == NULL) {\r
196 *FileLine = LineNum;\r
197 *FileName = mInputFileName;\r
198 return ;\r
199 }\r
200\r
201 for (pNode = mScopeRecordListHead; pNode->mNext != NULL; pNode = pNode->mNext) {\r
202 if ((LineNum > pNode->mWholeScopeLine) && (pNode->mNext->mWholeScopeLine > LineNum)) {\r
203 *FileName = pNode->mFileName;\r
204 *FileLine = LineNum - pNode->mWholeScopeLine + pNode->mScopeLineStart - 1;\r
205 return ;\r
206 }\r
207 }\r
208\r
209 *FileName = pNode->mFileName;\r
210 *FileLine = LineNum - pNode->mWholeScopeLine + pNode->mScopeLineStart - 1;\r
211}\r
212\r
213VOID\r
214CVfrErrorHandle::PrintMsg (\r
215 IN UINT32 LineNum,\r
216 IN CHAR8 *TokName,\r
217 IN CONST CHAR8 *MsgType,\r
218 IN CONST CHAR8 *ErrorMsg\r
219 )\r
220{\r
221 CHAR8 *FileName = NULL;\r
222 UINT32 FileLine;\r
223 \r
224 if (strncmp ("Warning", MsgType, strlen ("Warning")) == 0) {\r
225 VerboseMsg ((CHAR8 *) ErrorMsg);\r
226 return;\r
227 }\r
228 GetFileNameLineNum (LineNum, &FileName, &FileLine);\r
229 Error (FileName, FileLine, 0x3000, TokName, (CHAR8 *) "\t%s\n", (CHAR8 *) ErrorMsg);\r
230}\r
231\r
232UINT8\r
233CVfrErrorHandle::HandleError (\r
234 IN EFI_VFR_RETURN_CODE ErrorCode,\r
235 IN UINT32 LineNum,\r
236 IN CHAR8 *TokName\r
237 )\r
238{\r
239 UINT32 Index;\r
240 CHAR8 *FileName = NULL;\r
241 UINT32 FileLine;\r
242 CONST CHAR8 *ErrorMsg = NULL;\r
243\r
244 if (mVfrErrorHandleTable == NULL) {\r
245 return 1;\r
246 }\r
247\r
248 for (Index = 0; mVfrErrorHandleTable[Index].mErrorCode != VFR_RETURN_CODEUNDEFINED; Index++) {\r
249 if (ErrorCode == mVfrErrorHandleTable[Index].mErrorCode) {\r
250 ErrorMsg = mVfrErrorHandleTable[Index].mErrorMsg;\r
251 break;\r
252 }\r
253 }\r
254\r
255 if (ErrorMsg != NULL) {\r
256 GetFileNameLineNum (LineNum, &FileName, &FileLine);\r
257 Error (FileName, FileLine, 0x3000, TokName, (CHAR8 *) "\t%s\n", (CHAR8 *) ErrorMsg);\r
258 return 1;\r
259 } else {\r
260 return 0;\r
261 }\r
262}\r
263\r
264UINT8\r
265CVfrErrorHandle::HandleWarning (\r
266 IN EFI_VFR_WARNING_CODE WarningCode,\r
267 IN UINT32 LineNum,\r
268 IN CHAR8 *TokName\r
269 )\r
270{\r
271 UINT32 Index;\r
272 CHAR8 *FileName = NULL;\r
273 UINT32 FileLine;\r
274 CONST CHAR8 *WarningMsg = NULL;\r
275\r
276 if (mVfrWarningHandleTable == NULL) {\r
277 return 1;\r
278 }\r
279\r
280 GetFileNameLineNum (LineNum, &FileName, &FileLine);\r
281\r
282 if (mWarningAsError) {\r
283 Error (FileName, FileLine, 0x2220, (CHAR8 *) "warning treated as error", NULL);\r
284 }\r
285\r
286 for (Index = 0; mVfrWarningHandleTable[Index].mWarningCode != VFR_WARNING_CODEUNDEFINED; Index++) {\r
287 if (WarningCode == mVfrWarningHandleTable[Index].mWarningCode) {\r
288 WarningMsg = mVfrWarningHandleTable[Index].mWarningMsg;\r
289 break;\r
290 }\r
291 }\r
292\r
293 if (WarningMsg != NULL) {\r
294 Warning (FileName, FileLine, 0, TokName, (CHAR8 *) "\t%s\n", (CHAR8 *) WarningMsg);\r
295 return 1;\r
296 } else {\r
297 return 0;\r
298 }\r
299}\r
300\r
301CVfrErrorHandle gCVfrErrorHandle;\r