X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FCommon%2FExpression.py;h=4f0f377f37880a2eb9981ba52c778f4a9d93bc90;hp=5a0ade9e7ecad6d1fa6cbeb2dec09f7d4ef26eae;hb=47f7040ddbdfea033ef6e6b76f4c8fa19f67aaae;hpb=5ac0a5450bb87ccefa9f847d3d5bf579cb13925e diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index 5a0ade9e7e..4f0f377f37 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -15,7 +15,7 @@ from Common.GlobalData import * from CommonDataClass.Exceptions import BadExpression from CommonDataClass.Exceptions import WrnExpression -from Misc import GuidStringToGuidStructureString, ParseFieldValue +from Misc import GuidStringToGuidStructureString, ParseFieldValue, IsFieldValueAnArray import Common.EdkLogger as EdkLogger import copy @@ -40,20 +40,21 @@ ERR_ARRAY_ELE = 'This must be HEX value for NList or Array: [%s].' ERR_EMPTY_EXPR = 'Empty expression is not allowed.' ERR_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARCH), $(TOOL_CHAIN_TAG) and $(TARGET).' +__ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$') + ## SplitString # Split string to list according double quote # For example: abc"de\"f"ghi"jkl"mn will be: ['abc', '"de\"f"', 'ghi', '"jkl"', 'mn'] # def SplitString(String): # There might be escaped quote: "abc\"def\\\"ghi", 'abc\'def\\\'ghi' - Str = String RetList = [] InSingleQuote = False InDoubleQuote = False Item = '' - for i, ch in enumerate(Str): + for i, ch in enumerate(String): if ch == '"' and not InSingleQuote: - if Str[i - 1] != '\\': + if String[i - 1] != '\\': InDoubleQuote = not InDoubleQuote if not InDoubleQuote: Item += String[i] @@ -64,7 +65,7 @@ def SplitString(String): RetList.append(Item) Item = '' elif ch == "'" and not InDoubleQuote: - if Str[i - 1] != '\\': + if String[i - 1] != '\\': InSingleQuote = not InSingleQuote if not InSingleQuote: Item += String[i] @@ -84,27 +85,26 @@ def SplitString(String): def SplitPcdValueString(String): # There might be escaped comma in GUID() or DEVICE_PATH() or " " # or ' ' or L' ' or L" " - Str = String RetList = [] InParenthesis = 0 InSingleQuote = False InDoubleQuote = False Item = '' - for i, ch in enumerate(Str): + for i, ch in enumerate(String): if ch == '(': InParenthesis += 1 - if ch == ')': + elif ch == ')': if InParenthesis: InParenthesis -= 1 else: raise BadExpression(ERR_STRING_TOKEN % Item) - if ch == '"' and not InSingleQuote: + elif ch == '"' and not InSingleQuote: if String[i-1] != '\\': InDoubleQuote = not InDoubleQuote - if ch == "'" and not InDoubleQuote: + elif ch == "'" and not InDoubleQuote: if String[i-1] != '\\': InSingleQuote = not InSingleQuote - if ch == ',': + elif ch == ',': if InParenthesis or InSingleQuote or InDoubleQuote: Item += String[i] continue @@ -119,11 +119,24 @@ def SplitPcdValueString(String): RetList.append(Item) return RetList -def IsValidCString(Str): - ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$') - if not ValidString.match(Str): - return False - return True +def IsValidCName(Str): + return True if __ValidString.match(Str) else False + +def BuildOptionValue(PcdValue, GuidDict): + if PcdValue.startswith('H'): + InputValue = PcdValue[1:] + elif PcdValue.startswith("L'") or PcdValue.startswith("'"): + InputValue = PcdValue + elif PcdValue.startswith('L'): + InputValue = 'L"' + PcdValue[1:] + '"' + else: + InputValue = PcdValue + if IsFieldValueAnArray(InputValue): + try: + PcdValue = ValueExpressionEx(InputValue, 'VOID*', GuidDict)(True) + except: + pass + return PcdValue ## ReplaceExprMacro # @@ -890,11 +903,12 @@ class ValueExpressionEx(ValueExpression): LabelOffset = 0 for Index, Item in enumerate(PcdValueList): # compute byte offset of every LABEL - Item = Item.strip() LabelList = ReLabel.findall(Item) + Item = ReLabel.sub('', Item) + Item = Item.strip() if LabelList: for Label in LabelList: - if not IsValidCString(Label): + if not IsValidCName(Label): raise BadExpression('%s is not a valid c variable name' % Label) if Label not in LabelDict.keys(): LabelDict[Label] = str(LabelOffset)