from Common.GlobalData import *\r
from CommonDataClass.Exceptions import BadExpression\r
from CommonDataClass.Exceptions import WrnExpression\r
-from Misc import GuidStringToGuidStructureString, ParseFieldValue\r
+from Misc import GuidStringToGuidStructureString, ParseFieldValue, IsFieldValueAnArray\r
import Common.EdkLogger as EdkLogger\r
import copy\r
\r
ERR_EMPTY_EXPR = 'Empty expression is not allowed.'\r
ERR_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARCH), $(TOOL_CHAIN_TAG) and $(TARGET).'\r
\r
+__ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')\r
+\r
## SplitString\r
# Split string to list according double quote\r
# For example: abc"de\"f"ghi"jkl"mn will be: ['abc', '"de\"f"', 'ghi', '"jkl"', 'mn']\r
#\r
def SplitString(String):\r
# There might be escaped quote: "abc\"def\\\"ghi", 'abc\'def\\\'ghi'\r
- Str = String\r
RetList = []\r
InSingleQuote = False\r
InDoubleQuote = False\r
Item = ''\r
- for i, ch in enumerate(Str):\r
+ for i, ch in enumerate(String):\r
if ch == '"' and not InSingleQuote:\r
- if Str[i - 1] != '\\':\r
+ if String[i - 1] != '\\':\r
InDoubleQuote = not InDoubleQuote\r
if not InDoubleQuote:\r
Item += String[i]\r
RetList.append(Item)\r
Item = ''\r
elif ch == "'" and not InDoubleQuote:\r
- if Str[i - 1] != '\\':\r
+ if String[i - 1] != '\\':\r
InSingleQuote = not InSingleQuote\r
if not InSingleQuote:\r
Item += String[i]\r
def SplitPcdValueString(String):\r
# There might be escaped comma in GUID() or DEVICE_PATH() or " "\r
# or ' ' or L' ' or L" "\r
- Str = String\r
RetList = []\r
InParenthesis = 0\r
InSingleQuote = False\r
InDoubleQuote = False\r
Item = ''\r
- for i, ch in enumerate(Str):\r
+ for i, ch in enumerate(String):\r
if ch == '(':\r
InParenthesis += 1\r
- if ch == ')':\r
+ elif ch == ')':\r
if InParenthesis:\r
InParenthesis -= 1\r
else:\r
raise BadExpression(ERR_STRING_TOKEN % Item)\r
- if ch == '"' and not InSingleQuote:\r
+ elif ch == '"' and not InSingleQuote:\r
if String[i-1] != '\\':\r
InDoubleQuote = not InDoubleQuote\r
- if ch == "'" and not InDoubleQuote:\r
+ elif ch == "'" and not InDoubleQuote:\r
if String[i-1] != '\\':\r
InSingleQuote = not InSingleQuote\r
- if ch == ',':\r
+ elif ch == ',':\r
if InParenthesis or InSingleQuote or InDoubleQuote:\r
Item += String[i]\r
continue\r
RetList.append(Item)\r
return RetList\r
\r
-def IsValidCString(Str):\r
- ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')\r
- if not ValidString.match(Str):\r
- return False\r
- return True\r
+def IsValidCName(Str):\r
+ return True if __ValidString.match(Str) else False\r
+\r
+def BuildOptionValue(PcdValue, GuidDict):\r
+ if PcdValue.startswith('H'):\r
+ InputValue = PcdValue[1:]\r
+ elif PcdValue.startswith("L'") or PcdValue.startswith("'"):\r
+ InputValue = PcdValue\r
+ elif PcdValue.startswith('L'):\r
+ InputValue = 'L"' + PcdValue[1:] + '"'\r
+ else:\r
+ InputValue = PcdValue\r
+ if IsFieldValueAnArray(InputValue):\r
+ try:\r
+ PcdValue = ValueExpressionEx(InputValue, 'VOID*', GuidDict)(True)\r
+ except:\r
+ pass\r
+ return PcdValue\r
\r
## ReplaceExprMacro\r
#\r
LabelOffset = 0\r
for Index, Item in enumerate(PcdValueList):\r
# compute byte offset of every LABEL\r
- Item = Item.strip()\r
LabelList = ReLabel.findall(Item)\r
+ Item = ReLabel.sub('', Item)\r
+ Item = Item.strip()\r
if LabelList:\r
for Label in LabelList:\r
- if not IsValidCString(Label):\r
+ if not IsValidCName(Label):\r
raise BadExpression('%s is not a valid c variable name' % Label)\r
if Label not in LabelDict.keys():\r
LabelDict[Label] = str(LabelOffset)\r