2 # This file contained the parser for [Pcds] sections in INF file
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
15 import Logger
.Log
as Logger
16 from Logger
import StringTable
as ST
17 from Logger
.ToolError
import FORMAT_INVALID
18 from Parser
.InfParserMisc
import InfExpandMacro
19 from Library
import DataType
as DT
20 from Library
.Parsing
import MacroParser
21 from Library
.Misc
import GetSplitValueList
22 from Library
import GlobalData
23 from Library
.StringUtils
import SplitPcdEntry
24 from Parser
.InfParserMisc
import InfParserSectionRoot
26 class InfPcdSectionParser(InfParserSectionRoot
):
27 ## Section PCD related parser
29 # For 5 types of PCD list below, all use this function.
30 # 'FixedPcd', 'FeaturePcd', 'PatchPcd', 'Pcd', 'PcdEx'
32 # This is a INF independent parser, the validation in this parser only
34 # INF spec scope, will not cross DEC/DSC to check pcd value
36 def InfPcdParser(self
, SectionString
, InfSectionObject
, FileName
):
42 # Current section archs
45 for Item
in self
.LastSectionHeaderContent
:
46 if (Item
[0], Item
[1], Item
[3]) not in KeysList
:
47 KeysList
.append((Item
[0], Item
[1], Item
[3]))
50 if (Item
[0].upper() == DT
.TAB_INF_FIXED_PCD
.upper() or \
51 Item
[0].upper() == DT
.TAB_INF_FEATURE_PCD
.upper() or \
52 Item
[0].upper() == DT
.TAB_INF_PCD
.upper()) and GlobalData
.gIS_BINARY_INF
:
53 Logger
.Error('InfParser', FORMAT_INVALID
, ST
.ERR_ASBUILD_PCD_SECTION_TYPE
%("\"" + Item
[0] + "\""),
54 File
=FileName
, Line
=LineIndex
)
59 if not GlobalData
.gIS_BINARY_INF
:
61 # Macro defined in this section
64 for Line
in SectionString
:
65 PcdLineContent
= Line
[0]
67 if PcdLineContent
.strip() == '':
71 if PcdLineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
72 CommentsList
.append(Line
)
76 # Encounter a PCD entry
78 if PcdLineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
80 PcdLineContent
[PcdLineContent
.find(DT
.TAB_COMMENT_SPLIT
):],
82 PcdLineContent
= PcdLineContent
[:PcdLineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
84 if PcdLineContent
!= '':
88 Name
, Value
= MacroParser((PcdLineContent
, PcdLineNo
),
93 SectionMacros
[Name
] = Value
98 PcdEntryReturn
= SplitPcdEntry(PcdLineContent
)
100 if not PcdEntryReturn
[1]:
103 TokenList
= PcdEntryReturn
[0]
105 ValueList
[0:len(TokenList
)] = TokenList
108 # Replace with Local section Macro and [Defines] section Macro.
110 ValueList
= [InfExpandMacro(Value
, (FileName
, PcdLineContent
, PcdLineNo
),
111 self
.FileLocalMacros
, SectionMacros
, True)
112 for Value
in ValueList
]
114 if len(ValueList
) >= 1:
115 PcdList
.append((ValueList
, CommentsList
, (PcdLineContent
, PcdLineNo
, FileName
)))
120 # For Binary INF file
123 for Line
in SectionString
:
124 LineContent
= Line
[0].strip()
127 if LineContent
== '':
131 if LineContent
.startswith(DT
.TAB_COMMENT_SPLIT
):
132 CommentsList
.append(LineContent
)
135 # Have comments at tail.
137 CommentIndex
= LineContent
.find(DT
.TAB_COMMENT_SPLIT
)
138 if CommentIndex
> -1:
139 CommentsList
.append(LineContent
[CommentIndex
+1:])
140 LineContent
= LineContent
[:CommentIndex
]
142 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_VALUE_SPLIT
)
145 # TokenSpace.CName | Value | Offset
147 if KeysList
[0][0].upper() == DT
.TAB_INF_PATCH_PCD
.upper():
148 if len(TokenList
) != 3:
149 Logger
.Error('InfParser',
151 ST
.ERR_ASBUILD_PATCHPCD_FORMAT_INVALID
,
154 ExtraData
=LineContent
)
156 elif KeysList
[0][0].upper() == DT
.TAB_INF_PCD_EX
.upper():
157 if len(TokenList
) != 1:
158 Logger
.Error('InfParser',
160 ST
.ERR_ASBUILD_PCDEX_FORMAT_INVALID
,
163 ExtraData
=LineContent
)
164 ValueList
[0:len(TokenList
)] = TokenList
165 if len(ValueList
) >= 1:
166 PcdList
.append((ValueList
, CommentsList
, (LineContent
, LineNo
, FileName
)))
171 if not InfSectionObject
.SetPcds(PcdList
, KeysList
= KeysList
,
172 PackageInfo
= self
.InfPackageSection
.GetPackages()):
173 Logger
.Error('InfParser',
175 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
%("[PCD]"),