GPUSource: Fix failure case in the enum preprocessor
Some C headers might define the typedefs of the enum themselves. Even if they are guarded by preprocessor `#if`, our enum preprocessor has no idea of the validity of the statement. So we just bypass if there is a typedef just before any `enum` keywords. Note that the typedef matching is quite fragile.
This commit is contained in:
@@ -189,7 +189,7 @@ struct GPUSource {
|
||||
{
|
||||
const StringRefNull input = source;
|
||||
std::string output;
|
||||
int64_t cursor = 0;
|
||||
int64_t cursor = -1;
|
||||
int64_t last_pos = 0;
|
||||
const bool is_cpp = filename.endswith(".hh");
|
||||
|
||||
@@ -204,10 +204,14 @@ struct GPUSource {
|
||||
}
|
||||
|
||||
while (true) {
|
||||
cursor = find_keyword(input, "enum ", cursor);
|
||||
cursor = find_keyword(input, "enum ", cursor + 1);
|
||||
if (cursor == -1) {
|
||||
break;
|
||||
}
|
||||
/* Skip matches like `typedef enum myEnum myType;` */
|
||||
if (cursor >= 8 && input.substr(cursor - 8, 8) == "typedef ") {
|
||||
continue;
|
||||
}
|
||||
/* Output anything between 2 enums blocks. */
|
||||
output += input.substr(last_pos, cursor - last_pos);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user