2 # This file contained the parser for [Pcds] sections in INF file
4 # Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 import Logger
.Log
as Logger
22 from Logger
import StringTable
as ST
23 from Logger
.ToolError
import FORMAT_INVALID
24 from Parser
.InfParserMisc
import InfExpandMacro
25 from Library
import DataType
as DT
26 from Library
.Parsing
import MacroParser
27 from Library
.Misc
import GetSplitValueList
28 from Library
import GlobalData
29 from Library
.String
import SplitPcdEntry
30 from Parser
.InfParserMisc
import InfParserSectionRoot
32 class InfPcdSectionParser(InfParserSectionRoot
):
33 ## Section PCD related parser
35 # For 5 types of PCD list below, all use this function.
36 # 'FixedPcd', 'FeaturePcd', 'PatchPcd', 'Pcd', 'PcdEx'
38 # This is a INF independent parser, the validation in this parser only
40 # INF spec scope, will not cross DEC/DSC to check pcd value
42 def InfPcdParser(self
, SectionString
, InfSectionObject
, FileName
):
48 # Current section archs
51 for Item
in self
.LastSectionHeaderContent
:
52 if (Item
[0], Item
[1], Item
[3]) not in KeysList
:
53 KeysList
.append((Item
[0], Item
[1], Item
[3]))
56 if (Item
[0].upper() == DT
.TAB_INF_FIXED_PCD
.upper() or \
57 Item
[0].upper() == DT
.TAB_INF_FEATURE_PCD
.upper() or \
58 Item
[0].upper() == DT
.TAB_INF_PCD
.upper()) and GlobalData
.gIS_BINARY_INF
:
59 Logger
.Error('InfParser', FORMAT_INVALID
, ST
.ERR_ASBUILD_PCD_SECTION_TYPE
%("\"" + Item
[0] + "\""),
60 File
=FileName
, Line
=LineIndex
)
65 if not GlobalData
.gIS_BINARY_INF
:
67 # Macro defined in this section
70 for Line
in SectionString
:
71 PcdLineContent
= Line
[0]
73 if PcdLineContent
.strip() == '':
77 if PcdLineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
78 CommentsList
.append(Line
)
82 # Encounter a PCD entry
84 if PcdLineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
86 PcdLineContent
[PcdLineContent
.find(DT
.TAB_COMMENT_SPLIT
):],
88 PcdLineContent
= PcdLineContent
[:PcdLineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
90 if PcdLineContent
!= '':
94 Name
, Value
= MacroParser((PcdLineContent
, PcdLineNo
),
99 SectionMacros
[Name
] = Value
104 PcdEntryReturn
= SplitPcdEntry(PcdLineContent
)
106 if not PcdEntryReturn
[1]:
109 TokenList
= PcdEntryReturn
[0]
111 ValueList
[0:len(TokenList
)] = TokenList
114 # Replace with Local section Macro and [Defines] section Macro.
116 ValueList
= [InfExpandMacro(Value
, (FileName
, PcdLineContent
, PcdLineNo
),
117 self
.FileLocalMacros
, SectionMacros
, True)
118 for Value
in ValueList
]
120 if len(ValueList
) >= 1:
121 PcdList
.append((ValueList
, CommentsList
, (PcdLineContent
, PcdLineNo
, FileName
)))
126 # For Binary INF file
129 for Line
in SectionString
:
130 LineContent
= Line
[0].strip()
133 if LineContent
== '':
137 if LineContent
.startswith(DT
.TAB_COMMENT_SPLIT
):
138 CommentsList
.append(LineContent
)
141 # Have comments at tail.
143 CommentIndex
= LineContent
.find(DT
.TAB_COMMENT_SPLIT
)
144 if CommentIndex
> -1:
145 CommentsList
.append(LineContent
[CommentIndex
+1:])
146 LineContent
= LineContent
[:CommentIndex
]
148 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_VALUE_SPLIT
)
151 # TokenSpace.CName | Value | Offset
153 if KeysList
[0][0].upper() == DT
.TAB_INF_PATCH_PCD
.upper():
154 if len(TokenList
) != 3:
155 Logger
.Error('InfParser',
157 ST
.ERR_ASBUILD_PATCHPCD_FORMAT_INVALID
,
160 ExtraData
=LineContent
)
162 elif KeysList
[0][0].upper() == DT
.TAB_INF_PCD_EX
.upper():
163 if len(TokenList
) != 1:
164 Logger
.Error('InfParser',
166 ST
.ERR_ASBUILD_PCDEX_FORMAT_INVALID
,
169 ExtraData
=LineContent
)
170 ValueList
[0:len(TokenList
)] = TokenList
171 if len(ValueList
) >= 1:
172 PcdList
.append((ValueList
, CommentsList
, (LineContent
, LineNo
, FileName
)))
177 if not InfSectionObject
.SetPcds(PcdList
, KeysList
= KeysList
,
178 PackageInfo
= self
.InfPackageSection
.GetPackages()):
179 Logger
.Error('InfParser',
181 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
%("[PCD]"),