## @file\r
# Trim files preprocessed by compiler\r
#\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
# which accompanies this distribution. The full text of the license may be found at\r
# Version and Copyright\r
__version_number__ = ("0.10" + " " + gBUILD_VERSION)\r
__version__ = "%prog Version " + __version_number__\r
-__copyright__ = "Copyright (c) 2007-2010, Intel Corporation. All rights reserved."\r
+__copyright__ = "Copyright (c) 2007-2016, Intel Corporation. All rights reserved."\r
\r
## Regular expression for matching Line Control directive like "#line xxx"\r
gLineControlDirective = re.compile('^\s*#(?:line)?\s+([0-9]+)\s+"*([^"]*)"')\r
gTypedefPattern = re.compile("^\s*typedef\s+struct(\s+\w+)?\s*[{]*$", re.MULTILINE)\r
## Regular expression for matching "#pragma pack"\r
gPragmaPattern = re.compile("^\s*#pragma\s+pack", re.MULTILINE)\r
+## Regular expression for matching "typedef"\r
+gTypedef_SinglePattern = re.compile("^\s*typedef", re.MULTILINE)\r
+## Regular expression for matching "typedef struct, typedef union, struct, union"\r
+gTypedef_MulPattern = re.compile("^\s*(typedef)?\s+(struct|union)(\s+\w+)?\s*[{]*$", re.MULTILINE)\r
\r
#\r
# The following number pattern match will only match if following criteria is met:\r
\r
# in case there's no line directive or linemarker found\r
if (not LineControlDirectiveFound) and NewLines == []:\r
- NewLines = Lines\r
+ MulPatternFlag = False\r
+ SinglePatternFlag = False\r
+ Brace = 0\r
+ for Index in range(len(Lines)):\r
+ Line = Lines[Index]\r
+ if MulPatternFlag == False and gTypedef_MulPattern.search(Line) == None:\r
+ if SinglePatternFlag == False and gTypedef_SinglePattern.search(Line) == None:\r
+ # remove "#pragram pack" directive\r
+ if gPragmaPattern.search(Line) == None:\r
+ NewLines.append(Line)\r
+ continue\r
+ elif SinglePatternFlag == False:\r
+ SinglePatternFlag = True\r
+ if Line.find(";") >= 0:\r
+ SinglePatternFlag = False\r
+ elif MulPatternFlag == False:\r
+ # found "typedef struct, typedef union, union, struct", keep its position and set a flag\r
+ MulPatternFlag = True\r
+\r
+ # match { and } to find the end of typedef definition\r
+ if Line.find("{") >= 0:\r
+ Brace += 1\r
+ elif Line.find("}") >= 0:\r
+ Brace -= 1\r
+\r
+ # "typedef struct, typedef union, union, struct" must end with a ";"\r
+ if Brace == 0 and Line.find(";") >= 0:\r
+ MulPatternFlag = False\r
\r
# save to file\r
try:\r