def PreProcess(Filename, MergeMultipleLines=True, LineNo=-1): Lines = [] Filename = os.path.normpath(Filename) if not os.path.isfile(Filename): EdkLogger.error("Eot", EdkLogger.FILE_NOT_FOUND, ExtraData=Filename) IsFindBlockComment = False IsFindBlockCode = False ReservedLine = '' ReservedLineLength = 0 for Line in open(Filename, 'r'): Line = Line.strip() # Remove comment block if Line.find(TAB_COMMENT_R8_START) > -1: ReservedLine = GetSplitValueList(Line, TAB_COMMENT_R8_START, 1)[0] IsFindBlockComment = True if Line.find(TAB_COMMENT_R8_END) > -1: Line = ReservedLine + GetSplitValueList(Line, TAB_COMMENT_R8_END, 1)[1] ReservedLine = '' IsFindBlockComment = False if IsFindBlockComment: Lines.append('') continue # Remove comments at tail and remove spaces again Line = CleanString(Line) if Line == '': Lines.append('') continue if MergeMultipleLines: # Add multiple lines to one line if IsFindBlockCode and Line[-1] != TAB_SLASH: ReservedLine = (ReservedLine + TAB_SPACE_SPLIT + Line).strip() Lines.append(ReservedLine) for Index in (0, ReservedLineLength): Lines.append('') ReservedLine = '' ReservedLineLength = 0 IsFindBlockCode = False continue if Line[-1] == TAB_SLASH: ReservedLine = ReservedLine + TAB_SPACE_SPLIT + Line[ 0:-1].strip() ReservedLineLength = ReservedLineLength + 1 IsFindBlockCode = True continue Lines.append(Line) return Lines
def GetParameter(Parameter, Index=1): ParameterList = GetSplitValueList(Parameter, TAB_COMMA_SPLIT) if len(ParameterList) > Index: Parameter = GetParameterName(ParameterList[Index]) return Parameter return ''
def SearchProtocols(SqlCommand, Table, SourceFileID, SourceFileFullPath, ItemMode, ProtocolMode): ItemName, ItemType, GuidName, GuidMacro, GuidValue = '', 'Protocol', '', '', '' BelongsToFunctionID, BelongsToFunction = -1, '' Db = EotGlobalData.gDb.TblReport RecordSet = Db.Exec(SqlCommand) for Record in RecordSet: Parameter = '' BelongsToFile, StartLine, EndLine = Record[2], Record[3], Record[4] # Get BelongsToFunction BelongsToFunctionID, BelongsToFunction = SearchBelongsToFunction( BelongsToFile, StartLine, EndLine) # Default is Not Found IsFound = False if ProtocolMode == 0 or ProtocolMode == 1: Parameter = GetProtocolParameter(Record[0], ProtocolMode) if Parameter.startswith('g') or Parameter.endswith( 'Guid' ) or Parameter == 'ShellEnvProtocol' or Parameter == 'ShellInterfaceProtocol': GuidName = GetParameterName(Parameter) Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0) IsFound = True if ProtocolMode == 2: Protocols = GetSplitValueList(Record[0], TAB_COMMA_SPLIT) for Protocol in Protocols: if Protocol.startswith('&') and Protocol.endswith('Guid'): GuidName = GetParameterName(Protocol) Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0) IsFound = True else: NewValue = FindKeyValue(EotGlobalData.gDb.TblFile, Table, Protocol) if Protocol != NewValue and NewValue.endswith('Guid'): GuidName = GetParameterName(NewValue) Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0) IsFound = True if not IsFound: if BelongsToFunction in EotGlobalData.gProducedProtocolLibrary or BelongsToFunction in EotGlobalData.gConsumedProtocolLibrary: EotGlobalData.gOP_UN_MATCHED_IN_LIBRARY_CALLING.write( '%s, %s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, Parameter, BelongsToFunction)) else: EotGlobalData.gOP_UN_MATCHED.write( '%s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, Parameter))
def AddToSelfMacro(SelfMacro, Line): Name, Value = '', '' List = GetSplitValueList(Line, TAB_EQUAL_SPLIT, 1) if len(List) == 2: Name = List[0] Value = List[1] Value = ReplaceMacro(Value, EotGlobalData.gMACRO, True) Value = ReplaceMacro(Value, SelfMacro, True) SelfMacro[Name] = Value return (Name, Value)
def SearchFunctionCalling(Table, SourceFileID, SourceFileFullPath, ItemType, ItemMode): LibraryList = sdict() Db = EotGlobalData.gDb.TblReport Parameters, ItemName, GuidName, GuidMacro, GuidValue, BelongsToFunction = [], '', '', '', '', '' if ItemType == 'Protocol' and ItemMode == 'Produced': LibraryList = EotGlobalData.gProducedProtocolLibrary elif ItemType == 'Protocol' and ItemMode == 'Consumed': LibraryList = EotGlobalData.gConsumedProtocolLibrary elif ItemType == 'Protocol' and ItemMode == 'Callback': LibraryList = EotGlobalData.gCallbackProtocolLibrary elif ItemType == 'Ppi' and ItemMode == 'Produced': LibraryList = EotGlobalData.gProducedPpiLibrary elif ItemType == 'Ppi' and ItemMode == 'Consumed': LibraryList = EotGlobalData.gConsumedPpiLibrary for Library in LibraryList: Index = LibraryList[Library] SqlCommand = """select Value, StartLine from %s where Name like '%%%s%%' and Model = %s""" \ % (Table, Library, MODEL_IDENTIFIER_FUNCTION_CALLING) RecordSet = Db.Exec(SqlCommand) for Record in RecordSet: IsFound = False if Index == -1: ParameterList = GetSplitValueList(Record[0], TAB_COMMA_SPLIT) for Parameter in ParameterList: Parameters.append(GetParameterName(Parameter)) else: Parameters = [GetProtocolParameter(Record[0], Index)] StartLine = Record[1] for Parameter in Parameters: if Parameter.startswith('g') or Parameter.endswith( 'Guid' ) or Parameter == 'ShellEnvProtocol' or Parameter == 'ShellInterfaceProtocol': GuidName = GetParameterName(Parameter) Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0) IsFound = True if not IsFound: EotGlobalData.gOP_UN_MATCHED.write( '%s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, Parameter))
def SearchPpi(SqlCommand, Table, SourceFileID, SourceFileFullPath, ItemMode, PpiMode=1): ItemName, ItemType, GuidName, GuidMacro, GuidValue = '', 'Ppi', '', '', '' BelongsToFunctionID, BelongsToFunction = -1, '' Db = EotGlobalData.gDb.TblReport RecordSet = Db.Exec(SqlCommand) for Record in RecordSet: Parameter = GetPpiParameter(Record[0], PpiMode) BelongsToFile, StartLine, EndLine = Record[2], Record[3], Record[4] # Get BelongsToFunction BelongsToFunctionID, BelongsToFunction = SearchBelongsToFunction( BelongsToFile, StartLine, EndLine) # Default is Not Found IsFound = False # For Consumed Ppi if ItemMode == 'Consumed': if Parameter.startswith('g'): Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, Parameter, GuidMacro, GuidValue, BelongsToFunction, 0) else: EotGlobalData.gOP_UN_MATCHED.write( '%s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, Parameter)) continue # Direct Parameter.Guid SqlCommand = """select Value from %s where (Name like '%%%s.Guid%%' or Name like '%%%s->Guid%%') and Model = %s""" % ( Table, Parameter, Parameter, MODEL_IDENTIFIER_ASSIGNMENT_EXPRESSION) NewRecordSet = Db.Exec(SqlCommand) for NewRecord in NewRecordSet: GuidName = GetParameterName(NewRecord[0]) Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0) IsFound = True # Defined Parameter if not IsFound: Key = Parameter if Key.rfind(' ') > -1: Key = Key[Key.rfind(' '):].strip().replace('&', '') Value = FindKeyValue(EotGlobalData.gDb.TblFile, Table, Key) List = GetSplitValueList(Value.replace('\n', ''), TAB_COMMA_SPLIT) if len(List) > 1: GuidName = GetParameterName(List[1]) Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0) IsFound = True # A list Parameter if not IsFound: Start = Parameter.find('[') End = Parameter.find(']') if Start > -1 and End > -1 and Start < End: try: Index = int(Parameter[Start + 1:End]) Parameter = Parameter[0:Start] SqlCommand = """select Value from %s where Name = '%s' and Model = %s""" % ( Table, Parameter, MODEL_IDENTIFIER_VARIABLE) NewRecordSet = Db.Exec(SqlCommand) for NewRecord in NewRecordSet: NewParameter = GetSplitValueList(NewRecord[0], '}')[Index] GuidName = GetPpiParameter( NewParameter[NewParameter.find('{'):]) Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0) IsFound = True except Exception: pass # A External Parameter if not IsFound: SqlCommand = """select File.ID from Inf, File where BelongsToFile = (select BelongsToFile from Inf where Value1 = '%s') and Inf.Model = %s and Inf.Value1 = File.FullPath and File.Model = %s""" % ( SourceFileFullPath, MODEL_EFI_SOURCE_FILE, MODEL_FILE_C) NewRecordSet = Db.Exec(SqlCommand) for NewRecord in NewRecordSet: Table = 'Identifier' + str(NewRecord[0]) SqlCommand = """select Value from %s where Name = '%s' and Modifier = 'EFI_PEI_PPI_DESCRIPTOR' and Model = %s""" % ( Table, Parameter, MODEL_IDENTIFIER_VARIABLE) PpiSet = Db.Exec(SqlCommand) if PpiSet != []: GuidName = GetPpiParameter(PpiSet[0][0]) if GuidName != '': Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0) IsFound = True break if not IsFound: EotGlobalData.gOP_UN_MATCHED.write( '%s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, Parameter))
def SearchPpi(SqlCommand, Table, SourceFileID, SourceFileFullPath, ItemMode, PpiMode = 1): ItemName, ItemType, GuidName, GuidMacro, GuidValue = '', 'Ppi', '', '', '' BelongsToFunctionID, BelongsToFunction = -1, '' Db = EotGlobalData.gDb.TblReport RecordSet = Db.Exec(SqlCommand) for Record in RecordSet: Parameter = GetPpiParameter(Record[0], PpiMode) BelongsToFile, StartLine, EndLine = Record[2], Record[3], Record[4] # Get BelongsToFunction BelongsToFunctionID, BelongsToFunction = SearchBelongsToFunction(BelongsToFile, StartLine, EndLine) # Default is Not Found IsFound = False # For Consumed Ppi if ItemMode == 'Consumed': if Parameter.startswith('g'): Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, Parameter, GuidMacro, GuidValue, BelongsToFunction, 0) else: EotGlobalData.gOP_UN_MATCHED.write('%s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, Parameter)) continue # Direct Parameter.Guid SqlCommand = """select Value from %s where (Name like '%%%s.Guid%%' or Name like '%%%s->Guid%%') and Model = %s""" % (Table, Parameter, Parameter, MODEL_IDENTIFIER_ASSIGNMENT_EXPRESSION) NewRecordSet = Db.Exec(SqlCommand) for NewRecord in NewRecordSet: GuidName = GetParameterName(NewRecord[0]) Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0) IsFound = True # Defined Parameter if not IsFound: Key = Parameter if Key.rfind(' ') > -1: Key = Key[Key.rfind(' ') : ].strip().replace('&', '') Value = FindKeyValue(EotGlobalData.gDb.TblFile, Table, Key) List = GetSplitValueList(Value.replace('\n', ''), TAB_COMMA_SPLIT) if len(List) > 1: GuidName = GetParameterName(List[1]) Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0) IsFound = True # A list Parameter if not IsFound: Start = Parameter.find('[') End = Parameter.find(']') if Start > -1 and End > -1 and Start < End: try: Index = int(Parameter[Start + 1 : End]) Parameter = Parameter[0 : Start] SqlCommand = """select Value from %s where Name = '%s' and Model = %s""" % (Table, Parameter, MODEL_IDENTIFIER_VARIABLE) NewRecordSet = Db.Exec(SqlCommand) for NewRecord in NewRecordSet: NewParameter = GetSplitValueList(NewRecord[0], '}')[Index] GuidName = GetPpiParameter(NewParameter[NewParameter.find('{') : ]) Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0) IsFound = True except Exception: pass # A External Parameter if not IsFound: SqlCommand = """select File.ID from Inf, File where BelongsToFile = (select BelongsToFile from Inf where Value1 = '%s') and Inf.Model = %s and Inf.Value1 = File.FullPath and File.Model = %s""" % (SourceFileFullPath, MODEL_EFI_SOURCE_FILE, MODEL_FILE_C) NewRecordSet = Db.Exec(SqlCommand) for NewRecord in NewRecordSet: Table = 'Identifier' + str(NewRecord[0]) SqlCommand = """select Value from %s where Name = '%s' and Modifier = 'EFI_PEI_PPI_DESCRIPTOR' and Model = %s""" % (Table, Parameter, MODEL_IDENTIFIER_VARIABLE) PpiSet = Db.Exec(SqlCommand) if PpiSet != []: GuidName = GetPpiParameter(PpiSet[0][0]) if GuidName != '': Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0) IsFound = True break if not IsFound: EotGlobalData.gOP_UN_MATCHED.write('%s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, Parameter))