BaseTools: Replace StandardError with Expression
[mirror_edk2.git] / BaseTools / Source / Python / CommonDataClass / DataClass.py
1 ## @file
2 # This file is used to define class for data structure used in ECC
3 #
4 # Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 ##
14 # Import Modules
15 #
16 import Common.EdkLogger as EdkLogger
17
18 ##
19 # Static values for data models
20 #
21 MODEL_UNKNOWN = 0
22
23 MODEL_FILE_C = 1001
24 MODEL_FILE_H = 1002
25 MODEL_FILE_ASM = 1003
26 MODEL_FILE_INF = 1011
27 MODEL_FILE_DEC = 1012
28 MODEL_FILE_DSC = 1013
29 MODEL_FILE_FDF = 1014
30 MODEL_FILE_INC = 1015
31 MODEL_FILE_CIF = 1016
32 MODEL_FILE_UNI = 1017
33 MODEL_FILE_OTHERS = 1099
34
35 MODEL_IDENTIFIER_FILE_HEADER = 2001
36 MODEL_IDENTIFIER_FUNCTION_HEADER = 2002
37 MODEL_IDENTIFIER_COMMENT = 2003
38 MODEL_IDENTIFIER_PARAMETER = 2004
39 MODEL_IDENTIFIER_STRUCTURE = 2005
40 MODEL_IDENTIFIER_VARIABLE = 2006
41 MODEL_IDENTIFIER_INCLUDE = 2007
42 MODEL_IDENTIFIER_PREDICATE_EXPRESSION = 2008
43 MODEL_IDENTIFIER_ENUMERATE = 2009
44 MODEL_IDENTIFIER_PCD = 2010
45 MODEL_IDENTIFIER_UNION = 2011
46 MODEL_IDENTIFIER_MACRO_IFDEF = 2012
47 MODEL_IDENTIFIER_MACRO_IFNDEF = 2013
48 MODEL_IDENTIFIER_MACRO_DEFINE = 2014
49 MODEL_IDENTIFIER_MACRO_ENDIF = 2015
50 MODEL_IDENTIFIER_MACRO_PROGMA = 2016
51 MODEL_IDENTIFIER_FUNCTION_CALLING = 2018
52 MODEL_IDENTIFIER_TYPEDEF = 2017
53 MODEL_IDENTIFIER_FUNCTION_DECLARATION = 2019
54 MODEL_IDENTIFIER_ASSIGNMENT_EXPRESSION = 2020
55
56 MODEL_EFI_PROTOCOL = 3001
57 MODEL_EFI_PPI = 3002
58 MODEL_EFI_GUID = 3003
59 MODEL_EFI_LIBRARY_CLASS = 3004
60 MODEL_EFI_LIBRARY_INSTANCE = 3005
61 MODEL_EFI_PCD = 3006
62 MODEL_EFI_SOURCE_FILE = 3007
63 MODEL_EFI_BINARY_FILE = 3008
64 MODEL_EFI_SKU_ID = 3009
65 MODEL_EFI_INCLUDE = 3010
66 MODEL_EFI_DEPEX = 3011
67 MODEL_EFI_DEFAULT_STORES = 3012
68
69 MODEL_PCD = 4000
70 MODEL_PCD_FIXED_AT_BUILD = 4001
71 MODEL_PCD_PATCHABLE_IN_MODULE = 4002
72 MODEL_PCD_FEATURE_FLAG = 4003
73 MODEL_PCD_DYNAMIC_EX = 4004
74 MODEL_PCD_DYNAMIC_EX_DEFAULT = 4005
75 MODEL_PCD_DYNAMIC_EX_VPD = 4006
76 MODEL_PCD_DYNAMIC_EX_HII = 4007
77 MODEL_PCD_DYNAMIC = 4008
78 MODEL_PCD_DYNAMIC_DEFAULT = 4009
79 MODEL_PCD_DYNAMIC_VPD = 4010
80 MODEL_PCD_DYNAMIC_HII = 4011
81 MODEL_PCD_TYPE_LIST = [MODEL_PCD_FIXED_AT_BUILD,
82 MODEL_PCD_PATCHABLE_IN_MODULE,
83 MODEL_PCD_FEATURE_FLAG,
84 MODEL_PCD_DYNAMIC_DEFAULT,
85 MODEL_PCD_DYNAMIC_HII,
86 MODEL_PCD_DYNAMIC_VPD,
87 MODEL_PCD_DYNAMIC_EX_DEFAULT,
88 MODEL_PCD_DYNAMIC_EX_HII,
89 MODEL_PCD_DYNAMIC_EX_VPD
90 ]
91
92 MODEL_META_DATA_HEADER_COMMENT = 5000
93 MODEL_META_DATA_HEADER = 5001
94 MODEL_META_DATA_INCLUDE = 5002
95 MODEL_META_DATA_DEFINE = 5003
96 MODEL_META_DATA_CONDITIONAL_STATEMENT_IF = 5004
97 MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE = 5005
98 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF = 5006
99 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF = 5007
100 MODEL_META_DATA_CONDITIONAL_STATEMENT_ERROR = 5400
101 MODEL_META_DATA_BUILD_OPTION = 5008
102 MODEL_META_DATA_COMPONENT = 5009
103 MODEL_META_DATA_USER_EXTENSION = 5010
104 MODEL_META_DATA_PACKAGE = 5011
105 MODEL_META_DATA_NMAKE = 5012
106 MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF = 5013
107 MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF = 5014
108 MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH = 5015
109 MODEL_META_DATA_COMMENT = 5016
110 MODEL_META_DATA_GLOBAL_DEFINE = 5017
111 MODEL_META_DATA_SECTION_HEADER = 5100
112 MODEL_META_DATA_SUBSECTION_HEADER = 5200
113 MODEL_META_DATA_TAIL_COMMENT = 5300
114
115 MODEL_EXTERNAL_DEPENDENCY = 10000
116
117 MODEL_LIST = [('MODEL_UNKNOWN', MODEL_UNKNOWN),
118 ('MODEL_FILE_C', MODEL_FILE_C),
119 ('MODEL_FILE_H', MODEL_FILE_H),
120 ('MODEL_FILE_ASM', MODEL_FILE_ASM),
121 ('MODEL_FILE_INF', MODEL_FILE_INF),
122 ('MODEL_FILE_DEC', MODEL_FILE_DEC),
123 ('MODEL_FILE_DSC', MODEL_FILE_DSC),
124 ('MODEL_FILE_FDF', MODEL_FILE_FDF),
125 ('MODEL_FILE_INC', MODEL_FILE_INC),
126 ('MODEL_FILE_CIF', MODEL_FILE_CIF),
127 ('MODEL_FILE_OTHERS', MODEL_FILE_OTHERS),
128 ('MODEL_IDENTIFIER_FILE_HEADER', MODEL_IDENTIFIER_FILE_HEADER),
129 ('MODEL_IDENTIFIER_FUNCTION_HEADER', MODEL_IDENTIFIER_FUNCTION_HEADER),
130 ('MODEL_IDENTIFIER_COMMENT', MODEL_IDENTIFIER_COMMENT),
131 ('MODEL_IDENTIFIER_PARAMETER', MODEL_IDENTIFIER_PARAMETER),
132 ('MODEL_IDENTIFIER_STRUCTURE', MODEL_IDENTIFIER_STRUCTURE),
133 ('MODEL_IDENTIFIER_VARIABLE', MODEL_IDENTIFIER_VARIABLE),
134 ('MODEL_IDENTIFIER_INCLUDE', MODEL_IDENTIFIER_INCLUDE),
135 ('MODEL_IDENTIFIER_PREDICATE_EXPRESSION', MODEL_IDENTIFIER_PREDICATE_EXPRESSION),
136 ('MODEL_IDENTIFIER_ENUMERATE', MODEL_IDENTIFIER_ENUMERATE),
137 ('MODEL_IDENTIFIER_PCD', MODEL_IDENTIFIER_PCD),
138 ('MODEL_IDENTIFIER_UNION', MODEL_IDENTIFIER_UNION),
139 ('MODEL_IDENTIFIER_MACRO_IFDEF', MODEL_IDENTIFIER_MACRO_IFDEF),
140 ('MODEL_IDENTIFIER_MACRO_IFNDEF', MODEL_IDENTIFIER_MACRO_IFNDEF),
141 ('MODEL_IDENTIFIER_MACRO_DEFINE', MODEL_IDENTIFIER_MACRO_DEFINE),
142 ('MODEL_IDENTIFIER_MACRO_ENDIF', MODEL_IDENTIFIER_MACRO_ENDIF),
143 ('MODEL_IDENTIFIER_MACRO_PROGMA', MODEL_IDENTIFIER_MACRO_PROGMA),
144 ('MODEL_IDENTIFIER_FUNCTION_CALLING', MODEL_IDENTIFIER_FUNCTION_CALLING),
145 ('MODEL_IDENTIFIER_TYPEDEF', MODEL_IDENTIFIER_TYPEDEF),
146 ('MODEL_IDENTIFIER_FUNCTION_DECLARATION', MODEL_IDENTIFIER_FUNCTION_DECLARATION),
147 ('MODEL_IDENTIFIER_ASSIGNMENT_EXPRESSION', MODEL_IDENTIFIER_ASSIGNMENT_EXPRESSION),
148 ('MODEL_EFI_PROTOCOL', MODEL_EFI_PROTOCOL),
149 ('MODEL_EFI_PPI', MODEL_EFI_PPI),
150 ('MODEL_EFI_GUID', MODEL_EFI_GUID),
151 ('MODEL_EFI_LIBRARY_CLASS', MODEL_EFI_LIBRARY_CLASS),
152 ('MODEL_EFI_LIBRARY_INSTANCE', MODEL_EFI_LIBRARY_INSTANCE),
153 ('MODEL_EFI_PCD', MODEL_EFI_PCD),
154 ('MODEL_EFI_SKU_ID', MODEL_EFI_SKU_ID),
155 ('MODEL_EFI_INCLUDE', MODEL_EFI_INCLUDE),
156 ('MODEL_EFI_DEPEX', MODEL_EFI_DEPEX),
157 ('MODEL_IDENTIFIER_UNION', MODEL_IDENTIFIER_UNION),
158 ('MODEL_EFI_SOURCE_FILE', MODEL_EFI_SOURCE_FILE),
159 ('MODEL_EFI_BINARY_FILE', MODEL_EFI_BINARY_FILE),
160 ('MODEL_PCD', MODEL_PCD),
161 ('MODEL_PCD_FIXED_AT_BUILD', MODEL_PCD_FIXED_AT_BUILD),
162 ('MODEL_PCD_PATCHABLE_IN_MODULE', MODEL_PCD_PATCHABLE_IN_MODULE),
163 ('MODEL_PCD_FEATURE_FLAG', MODEL_PCD_FEATURE_FLAG),
164 ('MODEL_PCD_DYNAMIC_EX', MODEL_PCD_DYNAMIC_EX),
165 ('MODEL_PCD_DYNAMIC_EX_DEFAULT', MODEL_PCD_DYNAMIC_EX_DEFAULT),
166 ('MODEL_PCD_DYNAMIC_EX_VPD', MODEL_PCD_DYNAMIC_EX_VPD),
167 ('MODEL_PCD_DYNAMIC_EX_HII', MODEL_PCD_DYNAMIC_EX_HII),
168 ('MODEL_PCD_DYNAMIC', MODEL_PCD_DYNAMIC),
169 ('MODEL_PCD_DYNAMIC_DEFAULT', MODEL_PCD_DYNAMIC_DEFAULT),
170 ('MODEL_PCD_DYNAMIC_VPD', MODEL_PCD_DYNAMIC_VPD),
171 ('MODEL_PCD_DYNAMIC_HII', MODEL_PCD_DYNAMIC_HII),
172 ("MODEL_META_DATA_HEADER", MODEL_META_DATA_HEADER),
173 ("MODEL_META_DATA_INCLUDE", MODEL_META_DATA_INCLUDE),
174 ("MODEL_META_DATA_DEFINE", MODEL_META_DATA_DEFINE),
175 ("MODEL_META_DATA_CONDITIONAL_STATEMENT_IF", MODEL_META_DATA_CONDITIONAL_STATEMENT_IF),
176 ("MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE", MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE),
177 ("MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF", MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF),
178 ("MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF", MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF),
179 ("MODEL_META_DATA_CONDITIONAL_STATEMENT_ERROR", MODEL_META_DATA_CONDITIONAL_STATEMENT_ERROR),
180 ("MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH", MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH),
181 ("MODEL_META_DATA_BUILD_OPTION", MODEL_META_DATA_BUILD_OPTION),
182 ("MODEL_META_DATA_COMPONENT", MODEL_META_DATA_COMPONENT),
183 ('MODEL_META_DATA_USER_EXTENSION', MODEL_META_DATA_USER_EXTENSION),
184 ('MODEL_META_DATA_PACKAGE', MODEL_META_DATA_PACKAGE),
185 ('MODEL_META_DATA_NMAKE', MODEL_META_DATA_NMAKE),
186 ('MODEL_META_DATA_COMMENT', MODEL_META_DATA_COMMENT)
187 ]
188
189 ## FunctionClass
190 #
191 # This class defines a structure of a function
192 #
193 # @param ID: ID of a Function
194 # @param Header: Header of a Function
195 # @param Modifier: Modifier of a Function
196 # @param Name: Name of a Function
197 # @param ReturnStatement: ReturnStatement of a Funciont
198 # @param StartLine: StartLine of a Function
199 # @param StartColumn: StartColumn of a Function
200 # @param EndLine: EndLine of a Function
201 # @param EndColumn: EndColumn of a Function
202 # @param BodyStartLine: BodyStartLine of a Function Body
203 # @param BodyStartColumn: BodyStartColumn of a Function Body
204 # @param BelongsToFile: The Function belongs to which file
205 # @param IdentifierList: IdentifierList of a File
206 # @param PcdList: PcdList of a File
207 #
208 # @var ID: ID of a Function
209 # @var Header: Header of a Function
210 # @var Modifier: Modifier of a Function
211 # @var Name: Name of a Function
212 # @var ReturnStatement: ReturnStatement of a Funciont
213 # @var StartLine: StartLine of a Function
214 # @var StartColumn: StartColumn of a Function
215 # @var EndLine: EndLine of a Function
216 # @var EndColumn: EndColumn of a Function
217 # @var BodyStartLine: StartLine of a Function Body
218 # @var BodyStartColumn: StartColumn of a Function Body
219 # @var BelongsToFile: The Function belongs to which file
220 # @var IdentifierList: IdentifierList of a File
221 # @var PcdList: PcdList of a File
222 #
223 class FunctionClass(object):
224 def __init__(self, ID = -1, Header = '', Modifier = '', Name = '', ReturnStatement = '', \
225 StartLine = -1, StartColumn = -1, EndLine = -1, EndColumn = -1, \
226 BodyStartLine = -1, BodyStartColumn = -1, BelongsToFile = -1, \
227 IdentifierList = [], PcdList = [], \
228 FunNameStartLine = -1, FunNameStartColumn = -1):
229 self.ID = ID
230 self.Header = Header
231 self.Modifier = Modifier
232 self.Name = Name
233 self.ReturnStatement = ReturnStatement
234 self.StartLine = StartLine
235 self.StartColumn = StartColumn
236 self.EndLine = EndLine
237 self.EndColumn = EndColumn
238 self.BodyStartLine = BodyStartLine
239 self.BodyStartColumn = BodyStartColumn
240 self.BelongsToFile = BelongsToFile
241 self.FunNameStartLine = FunNameStartLine
242 self.FunNameStartColumn = FunNameStartColumn
243
244 self.IdentifierList = IdentifierList
245 self.PcdList = PcdList
246
247 ## IdentifierClass
248 #
249 # This class defines a structure of a variable
250 #
251 # @param ID: ID of a Identifier
252 # @param Modifier: Modifier of a Identifier
253 # @param Type: Type of a Identifier
254 # @param Name: Name of a Identifier
255 # @param Value: Value of a Identifier
256 # @param Model: Model of a Identifier
257 # @param BelongsToFile: The Identifier belongs to which file
258 # @param BelongsToFunction: The Identifier belongs to which function
259 # @param StartLine: StartLine of a Identifier
260 # @param StartColumn: StartColumn of a Identifier
261 # @param EndLine: EndLine of a Identifier
262 # @param EndColumn: EndColumn of a Identifier
263 #
264 # @var ID: ID of a Identifier
265 # @var Modifier: Modifier of a Identifier
266 # @var Type: Type of a Identifier
267 # @var Name: Name of a Identifier
268 # @var Value: Value of a Identifier
269 # @var Model: Model of a Identifier
270 # @var BelongsToFile: The Identifier belongs to which file
271 # @var BelongsToFunction: The Identifier belongs to which function
272 # @var StartLine: StartLine of a Identifier
273 # @var StartColumn: StartColumn of a Identifier
274 # @var EndLine: EndLine of a Identifier
275 # @var EndColumn: EndColumn of a Identifier
276 #
277 class IdentifierClass(object):
278 def __init__(self, ID = -1, Modifier = '', Type = '', Name = '', Value = '', Model = MODEL_UNKNOWN, \
279 BelongsToFile = -1, BelongsToFunction = -1, StartLine = -1, StartColumn = -1, EndLine = -1, EndColumn = -1):
280 self.ID = ID
281 self.Modifier = Modifier
282 self.Type = Type
283 self.Name = Name
284 self.Value = Value
285 self.Model = Model
286 self.BelongsToFile = BelongsToFile
287 self.BelongsToFunction = BelongsToFunction
288 self.StartLine = StartLine
289 self.StartColumn = StartColumn
290 self.EndLine = EndLine
291 self.EndColumn = EndColumn
292
293 ## PcdClass
294 #
295 # This class defines a structure of a Pcd
296 #
297 # @param ID: ID of a Pcd
298 # @param CName: CName of a Pcd
299 # @param TokenSpaceGuidCName: TokenSpaceGuidCName of a Pcd
300 # @param Token: Token of a Pcd
301 # @param DatumType: DatumType of a Pcd
302 # @param Model: Model of a Pcd
303 # @param BelongsToFile: The Pcd belongs to which file
304 # @param BelongsToFunction: The Pcd belongs to which function
305 # @param StartLine: StartLine of a Pcd
306 # @param StartColumn: StartColumn of a Pcd
307 # @param EndLine: EndLine of a Pcd
308 # @param EndColumn: EndColumn of a Pcd
309 #
310 # @var ID: ID of a Pcd
311 # @var CName: CName of a Pcd
312 # @var TokenSpaceGuidCName: TokenSpaceGuidCName of a Pcd
313 # @var Token: Token of a Pcd
314 # @var DatumType: DatumType of a Pcd
315 # @var Model: Model of a Pcd
316 # @var BelongsToFile: The Pcd belongs to which file
317 # @var BelongsToFunction: The Pcd belongs to which function
318 # @var StartLine: StartLine of a Pcd
319 # @var StartColumn: StartColumn of a Pcd
320 # @var EndLine: EndLine of a Pcd
321 # @var EndColumn: EndColumn of a Pcd
322 #
323 class PcdDataClass(object):
324 def __init__(self, ID = -1, CName = '', TokenSpaceGuidCName = '', Token = '', DatumType = '', Model = MODEL_UNKNOWN, \
325 BelongsToFile = -1, BelongsToFunction = -1, StartLine = -1, StartColumn = -1, EndLine = -1, EndColumn = -1):
326 self.ID = ID
327 self.CName = CName
328 self.TokenSpaceGuidCName = TokenSpaceGuidCName
329 self.Token = Token
330 self.DatumType = DatumType
331 self.BelongsToFile = BelongsToFile
332 self.BelongsToFunction = BelongsToFunction
333 self.StartLine = StartLine
334 self.StartColumn = StartColumn
335 self.EndLine = EndLine
336 self.EndColumn = EndColumn
337
338 ## FileClass
339 #
340 # This class defines a structure of a file
341 #
342 # @param ID: ID of a File
343 # @param Name: Name of a File
344 # @param ExtName: ExtName of a File
345 # @param Path: Path of a File
346 # @param FullPath: FullPath of a File
347 # @param Model: Model of a File
348 # @param TimeStamp: TimeStamp of a File
349 # @param FunctionList: FunctionList of a File
350 # @param IdentifierList: IdentifierList of a File
351 # @param PcdList: PcdList of a File
352 #
353 # @var ID: ID of a File
354 # @var Name: Name of a File
355 # @var ExtName: ExtName of a File
356 # @var Path: Path of a File
357 # @var FullPath: FullPath of a File
358 # @var Model: Model of a File
359 # @var TimeStamp: TimeStamp of a File
360 # @var FunctionList: FunctionList of a File
361 # @var IdentifierList: IdentifierList of a File
362 # @var PcdList: PcdList of a File
363 #
364 class FileClass(object):
365 def __init__(self, ID = -1, Name = '', ExtName = '', Path = '', FullPath = '', Model = MODEL_UNKNOWN, TimeStamp = '', \
366 FunctionList = [], IdentifierList = [], PcdList = []):
367 self.ID = ID
368 self.Name = Name
369 self.ExtName = ExtName
370 self.Path = Path
371 self.FullPath = FullPath
372 self.Model = Model
373 self.TimeStamp = TimeStamp
374
375 self.FunctionList = FunctionList
376 self.IdentifierList = IdentifierList
377 self.PcdList = PcdList