def TestToolFuncs(): assert IsValidCArray('{0x1, 0x23}') # Empty after comma assert not IsValidCArray('{0x1, 0x23, }') # 0x2345 too long assert not IsValidCArray('{0x1, 0x2345}') # Must end with '}' assert not IsValidCArray('{0x1, 0x23, ') # Whitespace between numbers assert not IsValidCArray('{0x1, 0x2 3, }') assert IsValidPcdDatum('VOID*', '"test"')[0] assert IsValidPcdDatum('VOID*', 'L"test"')[0] assert IsValidPcdDatum('BOOLEAN', 'TRUE')[0] assert IsValidPcdDatum('BOOLEAN', 'FALSE')[0] assert IsValidPcdDatum('BOOLEAN', '0')[0] assert IsValidPcdDatum('BOOLEAN', '1')[0] assert IsValidPcdDatum('UINT8', '0xab')[0] assert not IsValidPcdDatum('UNKNOWNTYPE', '0xabc')[0] assert not IsValidPcdDatum('UINT8', 'not number')[0] assert (IsValidCFormatGuid( '{ 0xfa0b1735 , 0x87a0, 0x4193, {0xb2, 0x66 , 0x53, 0x8c , 0x38, 0xaf, 0x48, 0xce }}' )) assert (not IsValidCFormatGuid( '{ 0xfa0b1735 , 0x87a0, 0x4193, {0xb2, 0x66 , 0x53, 0x8c , 0x38, 0xaf, 0x48, 0xce }} 0xaa' ))
def _ParseItem(self): Line = self._RawData.CurrentLine TokenList = Line.split(DT.TAB_VALUE_SPLIT) if len(TokenList) < 4: self._LoggerError(ST.ERR_DECPARSE_PCD_SPLIT) # # Token space guid C name # PcdName = GetSplitValueList(TokenList[0], DT.TAB_SPLIT) if len(PcdName) != 2 or PcdName[0] == '' or PcdName[1] == '': self._LoggerError(ST.ERR_DECPARSE_PCD_NAME) Guid = PcdName[0] if not IsValidToken(CVAR_PATTERN, Guid): self._LoggerError(ST.ERR_DECPARSE_PCD_CVAR_GUID) # # PCD C name # CName = PcdName[1] if not IsValidToken(CVAR_PATTERN, CName): self._LoggerError(ST.ERR_DECPARSE_PCD_CVAR_PCDCNAME) self._CheckReDefine(Guid + DT.TAB_SPLIT + CName) # # Default value, may be C array, string or number # Data = DT.TAB_VALUE_SPLIT.join(TokenList[1:-2]).strip() # # PCD data type # DataType = TokenList[-2].strip() Valid, Cause = IsValidPcdDatum(DataType, Data) if not Valid: self._LoggerError(Cause) PcdType = self._RawData.CurrentScope[0][0] if PcdType == DT.TAB_PCDS_FEATURE_FLAG_NULL.upper() and DataType != 'BOOLEAN': self._LoggerError(ST.ERR_DECPARSE_PCD_FEATUREFLAG) # # Token value is the last element in list. # Token = TokenList[-1].strip() if not IsValidToken(PCD_TOKEN_PATTERN, Token): self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN % Token) elif not Token.startswith('0x') and not Token.startswith('0X'): if long(Token) > 4294967295: self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN_INT % Token) Token = hex(long(Token))[:-1] IntToken = long(Token, 0) if (Guid, IntToken) in self.TokenMap: if self.TokenMap[Guid, IntToken] != CName: self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN_UNIQUE%(Token)) else: self.TokenMap[Guid, IntToken] = CName Item = DecPcdItemObject(Guid, CName, Data, DataType, Token) self.ItemObject.AddItem(Item, self._RawData.CurrentScope) return Item