## @file
# This file is used to define helper class and function for DEC parser
#
# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
'''
DecParserMisc
'''
## Import modules
#
import os
## FileContent
# Class to hold DEC file information
#
class FileContent:
self.HeadComment = []
self.TailComment = []
self.CurrentScope = None
return ''
return Line
self.HeadComment = []
self.TailComment = []
## StripRoot
#
# Strip root path
#
# @param Root: Root must be absolute path
# @param Path: Path to be stripped
#
return OrigPath
return Path
return OrigPath
## CleanString
#
# Split comments in a string
# Remove spaces
#
# @param Line: The string to be cleaned
# @param CommentCharacter: Comment char, used to ignore comment content,
# default is DataType.TAB_COMMENT_SPLIT
#
#
# remove whitespace
#
#
# Replace EDK1's comment character
#
#
# separate comments and statements
#
Comment = ''
continue
break
## IsValidHexByte
#
# Check if Token is HexByte: <HexByte> ::= 0x <HexDigit>{1,2}
#
# @param Token: Token to be checked
#
return False
try:
except BaseException:
return False
return True
## IsValidNList
#
# Check if Value has the format of <HexByte> ["," <HexByte>]{0,}
# <HexByte> ::= "0x" <HexDigit>{1,2}
#
# @param Value: Value to be checked
#
return False
if not IsValidHexByte(Token):
return False
return False
continue
else:
break
## IsValidCArray
#
# check Array is valid
#
# @param Array: The input Array
#
return False
return False
#
# 0xa, 0xaa
#
if not IsValidHexByte(Token):
return False
return False
continue
#
# End of C array
#
break
else:
return False
## IsValidPcdDatum
#
# check PcdDatum is valid
#
# @param Type: The pcd Type
# @param Value: The pcd Value
#
if Type == "VOID*":
):
if RealString:
if not IsValidBareCString(RealString):
elif Type == 'BOOLEAN':
'0x1', '0x01', '1', '0x0', '0x00', '0']:
return True, ""
if not Valid:
if not Valid:
else:
try:
if not Value:
return True, ""
TypeLenMap = {
#
# 0x00 - 0xff
#
'UINT8' : 2,
#
# 0x0000 - 0xffff
#
'UINT16' : 4,
#
# 0x00000000 - 0xffffffff
#
'UINT32' : 8,
#
# 0x0 - 0xffffffffffffffff
#
'UINT64' : 16
}
#
# First two chars of HexStr are 0x and tail char is L
#
except BaseException:
return True, ""
## ParserHelper
#
class ParserHelper:
## End
#
# End
#
## __SkipWhitespace
#
# Skip whitespace
#
if Char not in ' \t':
break
## Expect
#
# Expect char in string
#
# @param ExpectChar: char expected in index of string
#
if Char != ExpectChar:
return False
else:
return True
#
# Index out of bound of String
#
return False
## GetToken
#
# Get token until encounter StopChar, front whitespace is consumed
#
# @param StopChar: Get token until encounter char in StopChar
# @param StkipPair: Only can be ' or ", StopChar in SkipPair are skipped
#
LastChar = ''
break
LastChar = ''
else:
## AssertChar
#
# Assert char at current index of string is AssertChar, or will report
# error message
#
# @param AssertChar: AssertChar
# @param ErrorString: ErrorString
# @param ErrorLineNum: ErrorLineNum
#
## AssertEnd
#
# @param ErrorString: ErrorString
# @param ErrorLineNum: ErrorLineNum
#