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
NonLetterOpLst = ['+', '-', '*', '/', '%', '&', '|', '^', '~', '<<', '>>', '!', '=', '>', '<', '?', ':']\r
\r
PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')\r
- HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$')\r
- RegGuidPattern = re.compile(r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}')\r
\r
SymbolPattern = re.compile("("\r
"\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"\r
self._LiteralToken.endswith('}'):\r
return True\r
\r
- if self.HexPattern.match(self._LiteralToken):\r
+ if gHexPattern.match(self._LiteralToken):\r
Token = self._LiteralToken[2:]\r
if not Token:\r
self._LiteralToken = '0x0'\r
self._Token = ''\r
if Expr:\r
Ch = Expr[0]\r
- Match = self.RegGuidPattern.match(Expr)\r
+ Match = gGuidPattern.match(Expr)\r
if Match and not Expr[Match.end():Match.end()+1].isalnum() \\r
and Expr[Match.end():Match.end()+1] != '_':\r
self._Idx += Match.end()\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
Item = '0x%x' % TmpValue if type(TmpValue) != type('') else TmpValue\r
if ItemSize == 0:\r
ItemValue, ItemSize = ParseFieldValue(Item)\r
- if not (Item.startswith('"') or Item.startswith('L') or Item.startswith('{')) and ItemSize > 1:\r
+ if Item[0] not in ['"','L','{'] and ItemSize > 1:\r
raise BadExpression("Byte array number %s should less than 0xFF." % Item)\r
else:\r
ItemValue = ParseFieldValue(Item)[0]\r