Skip to content

__extension__ before a typedef not working #103

Description

@4THEEND

When trying to parse and rewrite this source code (which compiles using gcc basic_exemple.c

#include <stdio.h>

__extension__ typedef unsigned long long uint64_t;

int main(){
    uint64_t my_number = 42;
    printf("Here's my numner %llu\n", my_number);

    return 0;
} 

using the following python script

from pycparser import c_ast
from pycparserext import ext_c_parser
from pycparserext.ext_c_generator import GnuCGenerator


parser = ext_c_parser.GnuCParser()
with open('basic_exemple.pp', "r") as pf:
    src = pf.read()
original_ast = parser.parse(src)

print(original_ast)


out_c = 'out.c'
with open(out_c, 'w') as newFile:
    for line in GnuCGenerator().visit(original_ast).splitlines():
        if "asm" in line:
            newFile.write(line + ";\n")
        else:
            newFile.write(line + "\n")

it seems that the __extension__ keyword rewritten correctly and the result in out_c is typedef __extension__ unsigned long long uint64_t. (the .pp file was generated using gcc -E basic_exemple -o basic_exemple.pp)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions