+ return FieldList\r
+\r
+def ParseFieldValue (Value):\r
+ if type(Value) == type(0):\r
+ return Value, (Value.bit_length() + 7) / 8\r
+ if type(Value) <> type(''):\r
+ raise ValueError\r
+ Value = Value.strip()\r
+ if Value.startswith('UINT8') and Value.endswith(')'):\r
+ Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])\r
+ if Size > 1:\r
+ raise ValueError\r
+ return Value, 1\r
+ if Value.startswith('UINT16') and Value.endswith(')'):\r
+ Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])\r
+ if Size > 2:\r
+ raise ValueError\r
+ return Value, 2\r
+ if Value.startswith('UINT32') and Value.endswith(')'):\r
+ Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])\r
+ if Size > 4:\r
+ raise ValueError\r
+ return Value, 4\r
+ if Value.startswith('UINT64') and Value.endswith(')'):\r
+ Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])\r
+ if Size > 8:\r
+ raise ValueError\r
+ return Value, 8\r
+ if Value.startswith('GUID') and Value.endswith(')'):\r
+ Value = Value.split('(', 1)[1][:-1].strip()\r
+ if Value[0] == '{' and Value[-1] == '}':\r
+ Value = Value[1:-1].strip()\r
+ Value = Value.split('{', 1)\r
+ Value = [Item.strip()[2:] for Item in (Value[0] + Value[1][:-1]).split(',')]\r
+ Value = '-'.join(Value[0:3]) + '-' + ''.join(Value[3:5]) + '-' + ''.join(Value[5:11])\r
+ if Value[0] == '"' and Value[-1] == '"':\r
+ Value = Value[1:-1]\r
+ Value = "'" + uuid.UUID(Value).get_bytes_le() + "'"\r
+ Value, Size = ParseFieldValue(Value)\r
+ return Value, 16\r
+ if Value.startswith('L"') and Value.endswith('"'):\r
+ # Unicode String\r
+ List = list(Value[2:-1])\r
+ List.reverse()\r
+ Value = 0\r
+ for Char in List:\r
+ Value = (Value << 16) | ord(Char)\r
+ return Value, (len(List) + 1) * 2\r
+ if Value.startswith('"') and Value.endswith('"'):\r
+ # ASCII String\r
+ List = list(Value[1:-1])\r
+ List.reverse()\r
+ Value = 0\r
+ for Char in List:\r
+ Value = (Value << 8) | ord(Char)\r
+ return Value, len(List) + 1\r
+ if Value.startswith("L'") and Value.endswith("'"):\r
+ # Unicode Character Constant\r
+ List = list(Value[2:-1])\r
+ List.reverse()\r
+ Value = 0\r
+ for Char in List:\r
+ Value = (Value << 16) | ord(Char)\r
+ return Value, len(List) * 2\r
+ if Value.startswith("'") and Value.endswith("'"):\r
+ # Character constant\r
+ List = list(Value[1:-1])\r
+ List.reverse()\r
+ Value = 0\r
+ for Char in List:\r
+ Value = (Value << 8) | ord(Char)\r
+ return Value, len(List)\r
+ if Value.startswith('{') and Value.endswith('}'):\r
+ # Byte array\r
+ Value = Value[1:-1]\r
+ List = [Item.strip() for Item in Value.split(',')]\r
+ List.reverse()\r
+ Value = 0\r
+ for Item in List:\r
+ ItemValue, Size = ParseFieldValue(Item)\r
+ if Size > 1:\r
+ raise ValueError\r
+ Value = (Value << 8) | ItemValue\r
+ return Value, len(List)\r
+ if Value.lower().startswith('0x'):\r
+ Value = int(Value, 16)\r
+ return Value, (Value.bit_length() + 7) / 8\r
+ if Value[0].isdigit():\r
+ Value = int(Value, 10)\r
+ return Value, (Value.bit_length() + 7) / 8\r
+ if Value.lower() == 'true':\r
+ return 1, 1\r
+ if Value.lower() == 'false':\r
+ return 0, 1\r
+ return Value, 1\r
+\r
+## AnalyzeDscPcd\r
+#\r
+# Analyze DSC PCD value, since there is no data type info in DSC\r
+# This fuction is used to match functions (AnalyzePcdData, AnalyzeHiiPcdData, AnalyzeVpdPcdData) used for retrieving PCD value from database\r
+# 1. Feature flag: TokenSpace.PcdCName|PcdValue\r
+# 2. Fix and Patch:TokenSpace.PcdCName|PcdValue[|MaxSize]\r
+# 3. Dynamic default:\r
+# TokenSpace.PcdCName|PcdValue[|VOID*[|MaxSize]]\r
+# TokenSpace.PcdCName|PcdValue\r
+# 4. Dynamic VPD:\r
+# TokenSpace.PcdCName|VpdOffset[|VpdValue]\r
+# TokenSpace.PcdCName|VpdOffset[|MaxSize[|VpdValue]]\r
+# 5. Dynamic HII:\r
+# TokenSpace.PcdCName|HiiString|VaiableGuid|VariableOffset[|HiiValue]\r
+# PCD value needs to be located in such kind of string, and the PCD value might be an expression in which\r
+# there might have "|" operator, also in string value.\r
+#\r
+# @param Setting: String contain information described above with "TokenSpace.PcdCName|" stripped\r
+# @param PcdType: PCD type: feature, fixed, dynamic default VPD HII\r
+# @param DataType: The datum type of PCD: VOID*, UNIT, BOOL\r
+# @retval:\r
+# ValueList: A List contain fields described above\r
+# IsValid: True if conforming EBNF, otherwise False\r
+# Index: The index where PcdValue is in ValueList\r
+#\r
+def AnalyzeDscPcd(Setting, PcdType, DataType=''):\r
+ FieldList = AnalyzePcdExpression(Setting)\r
+\r