acpisrc: Allow simple typedef union/struct

acpisrc can only convert the followings:
  typedef union/struct foo {
      int bar;
  } FOO;
Into:
  union struct foo {
      int bar;
  };

It cannot detect the followings:
  typedef union/struct foo FOO;
And convert it into:
  typedef union/struct foo foo;

This patch facilitates acpisrc to detect such forms, thus allows some
typedefs to be converted using the latter style with "SIMPLE" conversion
(see ACPI_EFI_FILE in astable.c as a demo). Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
This commit is contained in:
Lv Zheng 2017-03-16 16:02:31 +08:00 committed by Zheng
parent c13298c518
commit 39411f710d
2 changed files with 70 additions and 35 deletions

View File

@ -550,6 +550,7 @@ AsReduceTypedefs (
{
char *SubString;
char *SubBuffer;
char *SubSubString;
int NestLevel;
@ -562,56 +563,89 @@ AsReduceTypedefs (
if (SubString)
{
/* Remove the typedef itself */
SubSubString = SubString + strlen (Keyword);
SubBuffer = SubString + strlen ("typedef") + 1;
SubBuffer = AsRemoveData (SubString, SubBuffer);
/* skip spaces */
/* Find the opening brace of the struct or union */
while (*SubString != '{')
while (strchr(" \t\r\n", *SubSubString))
{
SubString++;
SubSubString++;
}
SubString++;
/* Find the closing brace. Handles nested braces */
/* skip type name */
NestLevel = 1;
while (*SubString)
while (!strchr(" \t\r\n", *SubSubString))
{
if (*SubString == '{')
{
NestLevel++;
}
else if (*SubString == '}')
{
NestLevel--;
}
SubSubString++;
}
/* skip spaces */
while (strchr(" \t\r\n", *SubSubString))
{
SubSubString++;
}
if (*SubSubString == '{')
{
/* Remove the typedef itself */
SubBuffer = SubString + strlen ("typedef") + 1;
SubBuffer = AsRemoveData (SubString, SubBuffer);
/* Find the opening brace of the struct or union */
while (*SubString != '{')
{
SubString++;
}
SubString++;
if (NestLevel == 0)
/* Find the closing brace. Handles nested braces */
NestLevel = 1;
while (*SubString)
{
break;
if (*SubString == '{')
{
NestLevel++;
}
else if (*SubString == '}')
{
NestLevel--;
}
SubString++;
if (NestLevel == 0)
{
break;
}
}
/* Remove an extra line feed if present */
if (!strncmp (SubString - 3, "\n\n", 2))
{
*(SubString -2) = '}';
SubString--;
}
/* Find the end of the typedef name */
SubBuffer = AsSkipUntilChar (SubString, ';');
/* And remove the typedef name */
SubBuffer = AsRemoveData (SubString, SubBuffer);
}
/* Remove an extra line feed if present */
if (!strncmp (SubString - 3, "\n\n", 2))
else
{
*(SubString -2) = '}';
SubString--;
/* Skip the entire definition */
SubString = strchr (SubString, ';') + 1;
SubBuffer = SubString;
}
/* Find the end of the typedef name */
SubBuffer = AsSkipUntilChar (SubString, ';');
/* And remove the typedef name */
SubBuffer = AsRemoveData (SubString, SubBuffer);
}
}
}

View File

@ -317,6 +317,7 @@ ACPI_TYPED_IDENTIFIER_TABLE AcpiIdentifiers[] = {
{"ACPI_DMTABLE_DATA", SRC_TYPE_STRUCT},
{"ACPI_DMTABLE_INFO", SRC_TYPE_STRUCT},
{"ACPI_DMTABLE_HANDLER", SRC_TYPE_SIMPLE},
{"ACPI_EFI_FILE", SRC_TYPE_SIMPLE},
{"ACPI_EVALUATE_INFO", SRC_TYPE_STRUCT},
{"ACPI_EVENT_HANDLER", SRC_TYPE_SIMPLE},
{"ACPI_EVENT_STATUS", SRC_TYPE_SIMPLE},