1## @file
2# This file is used to define class objects of INF file [UserExtension] section.
3# It will consumed by InfParser.
4#
5# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
6#
7# This program and the accompanying materials are licensed and made available
8# under the terms and conditions of the BSD License which accompanies this
9# distribution. The full text of the license may be found at
10# http://opensource.org/licenses/bsd-license.php
11#
12# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15'''
16InfUserExtensionsObject
17'''
18
19from Logger import StringTable as ST
20from Logger import ToolError
21import Logger.Log as Logger
22from Library import GlobalData
23
24from Library.Misc import Sdict
25
26class InfUserExtensionItem():
27    def __init__(self,
28                 Content = '',
29                 UserId = '',
30                 IdString = ''):
31        self.Content  = Content
32        self.UserId   = UserId
33        self.IdString = IdString
34        self.SupArchList = []
35
36    def SetContent(self, Content):
37        self.Content = Content
38    def GetContent(self):
39        return self.Content
40
41    def SetUserId(self, UserId):
42        self.UserId = UserId
43    def GetUserId(self):
44        return self.UserId
45
46    def SetIdString(self, IdString):
47        self.IdString = IdString
48    def GetIdString(self):
49        return self.IdString
50
51    def SetSupArchList(self, SupArchList):
52        self.SupArchList = SupArchList
53    def GetSupArchList(self):
54        return self.SupArchList
55
56##
57#
58#
59#
60class InfUserExtensionObject():
61    def __init__(self):
62        self.UserExtension = Sdict()
63
64    def SetUserExtension(self, UserExtensionCont, IdContent=None, LineNo=None):
65        if not UserExtensionCont or UserExtensionCont == '':
66            return True
67        #
68        # IdContent is a list contain UserId and IdString
69        # For this call the general section header  parser, if no definition of
70        # IdString/UserId, it will return 'COMMON'
71        #
72        for IdContentItem in IdContent:
73            InfUserExtensionItemObj = InfUserExtensionItem()
74            if IdContentItem[0] == 'COMMON':
75                UserId = ''
76            else:
77                UserId = IdContentItem[0]
78
79            if IdContentItem[1] == 'COMMON':
80                IdString = ''
81            else:
82                IdString = IdContentItem[1]
83
84            #
85            # Fill UserExtensionObj members.
86            #
87            InfUserExtensionItemObj.SetUserId(UserId)
88            InfUserExtensionItemObj.SetIdString(IdString)
89            InfUserExtensionItemObj.SetContent(UserExtensionCont)
90            InfUserExtensionItemObj.SetSupArchList(IdContentItem[2])
91
92#            for CheckItem in self.UserExtension:
93#                if IdContentItem[0] == CheckItem[0] and IdContentItem[1] == CheckItem[1]:
94#                    if IdContentItem[2].upper() == 'COMMON' or CheckItem[2].upper() == 'COMMON':
95#                        #
96#                        # For COMMON ARCH type, do special check.
97#                        #
98#                        Logger.Error('InfParser',
99#                            ToolError.FORMAT_INVALID,
100#                            ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR%\
101#                            (IdContentItem[0] + '.' + IdContentItem[1] + '.' + IdContentItem[2]),
102#                            File=GlobalData.gINF_MODULE_NAME,
103#                            Line=LineNo,
104#                            ExtraData=None)
105
106            if self.UserExtension.has_key(IdContentItem):
107                #
108                # Each UserExtensions section header must have a unique set
109                # of UserId, IdString and Arch values.
110                # This means that the same UserId can be used in more than one
111                # section header, provided the IdString or Arch values are
112                # different. The same IdString values can be used in more than
113                # one section header if the UserId or Arch values are
114                # different. The same UserId and the same IdString can be used
115                # in a section header if the Arch values are different in each
116                # of the section headers.
117                #
118                Logger.Error('InfParser',
119                             ToolError.FORMAT_INVALID,
120                             ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR%\
121                             (IdContentItem[0] + '.' + IdContentItem[1] + '.' + IdContentItem[2]),
122                             File=GlobalData.gINF_MODULE_NAME,
123                             Line=LineNo,
124                             ExtraData=None)
125            else:
126                UserExtensionList = []
127                UserExtensionList.append(InfUserExtensionItemObj)
128                self.UserExtension[IdContentItem] = UserExtensionList
129
130        return True
131
132    def GetUserExtension(self):
133        return self.UserExtension