def _ReplaceMacro(self, String): if gMACRO_PATTERN.findall(String): String = ReplaceMacro(String, self._LocalMacro, False, FileName = self._RawData.Filename, Line = ['', self._RawData.LineIndex]) String = ReplaceMacro(String, self._RawData.Macros, False, FileName = self._RawData.Filename, Line = ['', self._RawData.LineIndex]) MacroUsed = gMACRO_PATTERN.findall(String) if MacroUsed: Logger.Error(TOOL_NAME, FILE_PARSE_FAILURE, File=self._RawData.Filename, Line = self._RawData.LineIndex, ExtraData = ST.ERR_DECPARSE_MACRO_RESOLVE % (str(MacroUsed), String)) return String
def _ReplaceMacro(self, String): if gMACRO_PATTERN.findall(String): String = ReplaceMacro(String, self._LocalMacro, False, FileName = self._RawData.Filename, Line = ['', self._RawData.LineIndex]) String = ReplaceMacro(String, self._RawData.Macros, False, FileName = self._RawData.Filename, Line = ['', self._RawData.LineIndex]) MacroUsed = gMACRO_PATTERN.findall(String) if MacroUsed: Logger.Error(TOOL_NAME, FILE_PARSE_FAILURE, File=self._RawData.Filename, Line = self._RawData.LineIndex, ExtraData = ST.ERR_DECPARSE_MACRO_RESOLVE % (str(MacroUsed), String)) return String
def InfExpandMacro(Content, LineInfo, GlobalMacros=None, SectionMacros=None, Flag=False): if GlobalMacros is None: GlobalMacros = {} if SectionMacros is None: SectionMacros = {} FileName = LineInfo[0] LineContent = LineInfo[1] LineNo = LineInfo[2] # Don't expand macros in comments if LineContent.strip().startswith("#"): return Content NewLineInfo = (FileName, LineNo, LineContent) # # First, replace MARCOs with value defined in specific section # Content = ReplaceMacro (Content, SectionMacros, False, (LineContent, LineNo), FileName, Flag) # # Then replace MARCOs with value defined in [Defines] section # Content = ReplaceMacro (Content, GlobalMacros, False, (LineContent, LineNo), FileName, Flag) MacroUsed = gMACRO_PATTERN.findall(Content) # # no macro found in String, stop replacing # if len(MacroUsed) == 0: return Content else: for Macro in MacroUsed: gQuotedMacro = re.compile(".*\".*\$\(%s\).*\".*"%(Macro)) if not gQuotedMacro.match(Content): # # Still have MACROs can't be expanded. # ErrorInInf (ERR_MARCO_DEFINITION_MISS_ERROR, LineInfo=NewLineInfo) return Content
def InfExpandMacro(Content, LineInfo, GlobalMacros=None, SectionMacros=None, Flag=False): if GlobalMacros is None: GlobalMacros = {} if SectionMacros is None: SectionMacros = {} FileName = LineInfo[0] LineContent = LineInfo[1] LineNo = LineInfo[2] # Don't expand macros in comments if LineContent.strip().startswith("#"): return Content NewLineInfo = (FileName, LineNo, LineContent) # # First, replace MARCOs with value defined in specific section # Content = ReplaceMacro(Content, SectionMacros, False, (LineContent, LineNo), FileName, Flag) # # Then replace MARCOs with value defined in [Defines] section # Content = ReplaceMacro(Content, GlobalMacros, False, (LineContent, LineNo), FileName, Flag) MacroUsed = gMACRO_PATTERN.findall(Content) # # no macro found in String, stop replacing # if len(MacroUsed) == 0: return Content else: for Macro in MacroUsed: gQuotedMacro = re.compile(".*\".*\$\(%s\).*\".*" % (Macro)) if not gQuotedMacro.match(Content): # # Still have MACROs can't be expanded. # ErrorInInf(ERR_MARCO_DEFINITION_MISS_ERROR, LineInfo=NewLineInfo) return Content