1## @file 2# This file contained the parser for [Sources] sections in INF file 3# 4# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR> 5# 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 10# 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. 13# 14''' 15InfSourceSectionParser 16''' 17## 18# Import Modules 19# 20 21import Logger.Log as Logger 22from Logger import StringTable as ST 23from Logger.ToolError import FORMAT_INVALID 24from Parser.InfParserMisc import InfExpandMacro 25from Library import DataType as DT 26from Library.Parsing import MacroParser 27from Library.Misc import GetSplitValueList 28from Object.Parser.InfCommonObject import InfLineCommentObject 29from Parser.InfParserMisc import InfParserSectionRoot 30 31class InfSourceSectionParser(InfParserSectionRoot): 32 ## InfSourceParser 33 # 34 # 35 def InfSourceParser(self, SectionString, InfSectionObject, FileName): 36 SectionMacros = {} 37 ValueList = [] 38 SourceList = [] 39 StillCommentFalg = False 40 HeaderComments = [] 41 LineComment = None 42 SectionContent = '' 43 for Line in SectionString: 44 SrcLineContent = Line[0] 45 SrcLineNo = Line[1] 46 47 if SrcLineContent.strip() == '': 48 continue 49 50 # 51 # Found Header Comments 52 # 53 if SrcLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT): 54 # 55 # Last line is comments, and this line go on. 56 # 57 if StillCommentFalg: 58 HeaderComments.append(Line) 59 SectionContent += SrcLineContent + DT.END_OF_LINE 60 continue 61 # 62 # First time encounter comment 63 # 64 else: 65 # 66 # Clear original data 67 # 68 HeaderComments = [] 69 HeaderComments.append(Line) 70 StillCommentFalg = True 71 SectionContent += SrcLineContent + DT.END_OF_LINE 72 continue 73 else: 74 StillCommentFalg = False 75 76 if len(HeaderComments) >= 1: 77 LineComment = InfLineCommentObject() 78 LineCommentContent = '' 79 for Item in HeaderComments: 80 LineCommentContent += Item[0] + DT.END_OF_LINE 81 LineComment.SetHeaderComments(LineCommentContent) 82 83 # 84 # Find Tail comment. 85 # 86 if SrcLineContent.find(DT.TAB_COMMENT_SPLIT) > -1: 87 TailComments = SrcLineContent[SrcLineContent.find(DT.TAB_COMMENT_SPLIT):] 88 SrcLineContent = SrcLineContent[:SrcLineContent.find(DT.TAB_COMMENT_SPLIT)] 89 if LineComment == None: 90 LineComment = InfLineCommentObject() 91 LineComment.SetTailComments(TailComments) 92 93 # 94 # Find Macro 95 # 96 Name, Value = MacroParser((SrcLineContent, SrcLineNo), 97 FileName, 98 DT.MODEL_EFI_SOURCE_FILE, 99 self.FileLocalMacros) 100 if Name != None: 101 SectionMacros[Name] = Value 102 LineComment = None 103 HeaderComments = [] 104 continue 105 106 # 107 # Replace with Local section Macro and [Defines] section Macro. 108 # 109 SrcLineContent = InfExpandMacro(SrcLineContent, 110 (FileName, SrcLineContent, SrcLineNo), 111 self.FileLocalMacros, 112 SectionMacros) 113 114 TokenList = GetSplitValueList(SrcLineContent, DT.TAB_VALUE_SPLIT, 4) 115 ValueList[0:len(TokenList)] = TokenList 116 117 # 118 # Store section content string after MACRO replaced. 119 # 120 SectionContent += SrcLineContent + DT.END_OF_LINE 121 122 SourceList.append((ValueList, LineComment, 123 (SrcLineContent, SrcLineNo, FileName))) 124 ValueList = [] 125 LineComment = None 126 TailComments = '' 127 HeaderComments = [] 128 continue 129 130 # 131 # Current section archs 132 # 133 ArchList = [] 134 for Item in self.LastSectionHeaderContent: 135 if Item[1] not in ArchList: 136 ArchList.append(Item[1]) 137 InfSectionObject.SetSupArchList(Item[1]) 138 139 InfSectionObject.SetAllContent(SectionContent) 140 if not InfSectionObject.SetSources(SourceList, Arch = ArchList): 141 Logger.Error('InfParser', 142 FORMAT_INVALID, 143 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Sources]"), 144 File=FileName, 145 Line=Item[3])