## @file\r
# This file is used to parse DEC file. It will consumed by DecParser\r
#\r
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials are licensed and made available \r
# under the terms and conditions of the BSD License which accompanies this \r
from Logger.ToolError import FILE_PARSE_FAILURE\r
from Logger.ToolError import FILE_OPEN_FAILURE\r
from Logger import StringTable as ST\r
+from Logger.ToolError import FORMAT_INVALID\r
\r
import Library.DataType as DT\r
from Library.ParserValidate import IsValidToken\r
_DecComments.__init__(self)\r
_DecBase.__init__(self, RawData)\r
\r
+ self.BinaryHeadComment = [] \r
self._Define = _DecDefine(RawData)\r
self._Include = _DecInclude(RawData)\r
self._Guid = _DecGuid(RawData)\r
# Parse DEC file\r
#\r
def ParseDecComment(self):\r
+ IsFileHeader = False\r
+ IsBinaryHeader = False\r
+ FileHeaderLineIndex = -1\r
+ BinaryHeaderLineIndex = -1\r
while not self._RawData.IsEndOfFile():\r
Line, Comment = CleanString(self._RawData.GetNextLine())\r
+\r
#\r
# Header must be pure comment\r
#\r
self._RawData.UndoNextLine()\r
break\r
\r
- if Comment:\r
+ if Comment and Comment.startswith(DT.TAB_SPECIAL_COMMENT) and Comment.find(DT.TAB_HEADER_COMMENT) > 0 \\r
+ and not Comment[2:Comment.find(DT.TAB_HEADER_COMMENT)].strip():\r
+ IsFileHeader = True\r
+ IsBinaryHeader = False\r
+ FileHeaderLineIndex = self._RawData.LineIndex\r
+ \r
+ #\r
+ # Get license information before '@file' \r
+ # \r
+ if not IsFileHeader and not IsBinaryHeader and Comment and Comment.startswith(DT.TAB_COMMENT_SPLIT) and \\r
+ DT.TAB_BINARY_HEADER_COMMENT not in Comment:\r
self._HeadComment.append((Comment, self._RawData.LineIndex))\r
+ \r
+ if Comment and IsFileHeader and \\r
+ not(Comment.startswith(DT.TAB_SPECIAL_COMMENT) \\r
+ and Comment.find(DT.TAB_BINARY_HEADER_COMMENT) > 0):\r
+ self._HeadComment.append((Comment, self._RawData.LineIndex))\r
+ #\r
+ # Double '#' indicates end of header comments\r
+ #\r
+ if (not Comment or Comment == DT.TAB_SPECIAL_COMMENT) and IsFileHeader:\r
+ IsFileHeader = False \r
+ continue\r
+ \r
+ if Comment and Comment.startswith(DT.TAB_SPECIAL_COMMENT) \\r
+ and Comment.find(DT.TAB_BINARY_HEADER_COMMENT) > 0:\r
+ IsBinaryHeader = True\r
+ IsFileHeader = False\r
+ BinaryHeaderLineIndex = self._RawData.LineIndex\r
+ \r
+ if Comment and IsBinaryHeader:\r
+ self.BinaryHeadComment.append((Comment, self._RawData.LineIndex))\r
#\r
# Double '#' indicates end of header comments\r
#\r
- if not Comment or Comment == DT.TAB_SPECIAL_COMMENT:\r
+ if (not Comment or Comment == DT.TAB_SPECIAL_COMMENT) and IsBinaryHeader:\r
+ IsBinaryHeader = False\r
break\r
- \r
+ \r
+ if FileHeaderLineIndex > -1 and not IsFileHeader and not IsBinaryHeader:\r
+ break\r
+\r
+ if FileHeaderLineIndex > BinaryHeaderLineIndex and FileHeaderLineIndex > -1 and BinaryHeaderLineIndex > -1:\r
+ self._LoggerError(ST.ERR_BINARY_HEADER_ORDER)\r
+ \r
+ if FileHeaderLineIndex == -1:\r
+ Logger.Error(TOOL_NAME, FORMAT_INVALID, \r
+ ST.ERR_NO_SOURCE_HEADER,\r
+ File=self._RawData.Filename) \r
return\r
\r
def _StopCurrentParsing(self, Line):\r