Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicating Function Names #141

Open
pattersonz opened this issue Apr 8, 2021 · 0 comments
Open

Duplicating Function Names #141

pattersonz opened this issue Apr 8, 2021 · 0 comments

Comments

@pattersonz
Copy link
Contributor

pattersonz commented Apr 8, 2021

The following example creates duplicate names of function b, as well as the internal field c.

void b(
#ifdef A
         int a
#endif
) {
#if defined(A) && defined(B)
  int c = 2;
#endif
  int d;
}

This code results in this desugared output:

#include <stdbool.h>

extern void __static_type_error(char *msg);
extern void __static_renaming(char *renaming, char *original);
extern void __static_condition_renaming(char *expression, char *renaming);

TODO: record original presence condition strings in file as well once raw strings are collected
void __static_initializer_default();

extern const bool __static_condition_default_7;
extern const bool __static_condition_default_6;
extern const bool __static_condition_default_8;
void __static_initializer_default() {
__static_renaming("__b_1", "b");
__static_renaming("__b_2", "b");
__static_renaming("__c_3", "c");
__static_renaming("__d_4", "d");
__static_renaming("__d_5", "d");

__static_condition_renaming("__static_condition_default_6", "(defined A) && !(defined B)");
__static_condition_renaming("__static_condition_default_7", "!(defined A)");
__static_condition_renaming("__static_condition_default_8", "(defined A) && (defined B)");

};
TODO: account for bitfield sizes in forward refs

void  __b_2 (int  __a_0) {

if (__static_condition_default_6) {
{
int  __c_3= 2;
int  __c_3= 2;
int  __d_4;
int  __d_5;
}

}

}
void  __b_1 () {

if (__static_condition_default_7) {
{
int  __c_3= 2;
int  __c_3= 2;
int  __d_4;
int  __d_5;
}

}

}
void  __b_2 (int  __a_0) {

if (__static_condition_default_8) {
{
int  __c_3= 2;
int  __c_3= 2;
int  __d_4;
int  __d_5;
}

}

}

and with this AST

TranslationUnit(
  ExternalDeclarationList(
    Conditional(
      1,
      ExternalDeclaration(
        FunctionDefinitionExtension(
          FunctionDefinition(
            Conditional(
              (defined A) && !(defined B),
              FunctionPrototype(
                TypeSpecifier(
                  BasicTypeSpecifier(
                    BasicTypeName(
                      superc.core.Syntax$Language(
                        "void"
                      )
                    )
                  )
                ),
                IdentifierDeclarator(
                  IdentifierDeclaratorMain(
                    UnaryIdentifierDeclarator(
                      PostfixIdentifierDeclarator(
                        FunctionDeclarator(
                          ParenIdentifierDeclarator(
                            SimpleDeclarator(
                              superc.core.Syntax$Text(
                                "b"
                              )
                            )
                          ),
                          PostfixingFunctionDeclarator(
                            superc.core.Syntax$Language(
                              "("
                            ),
                            $@23(),
                            ParameterTypeListOpt(
                              ParameterTypeList(
                                ParameterList(
                                  Conditional(
                                    (defined A),
                                    ParameterDeclaration(
                                      ParameterIdentifierDeclaration(
                                        TypeSpecifier(
                                          BasicTypeSpecifier(
                                            BasicTypeName(
                                              superc.core.Syntax$Language(
                                                "int"
                                              )
                                            )
                                          )
                                        ),
                                        IdentifierDeclarator(
                                          IdentifierDeclaratorMain(
                                            ParenIdentifierDeclarator(
                                              SimpleDeclarator(
                                                superc.core.Syntax$Text(
                                                  "a"
                                                )
                                              )
                                            )
                                          )
                                        ),
                                        $@20(),
                                        AttributeSpecifierListOpt()
                                      )
                                    )
                                  )
                                )
                              )
                            ),
                            $@24(),
                            superc.core.Syntax$Language(
                              ")"
                            )
                          )
                        )
                      )
                    )
                  )
                )
              ),
              !(defined A) || (defined A) && (defined B),
              Conditional(
                !(defined A),
                FunctionPrototype(
                  TypeSpecifier(
                    BasicTypeSpecifier(
                      BasicTypeName(
                        superc.core.Syntax$Language(
                          "void"
                        )
                      )
                    )
                  ),
                  IdentifierDeclarator(
                    IdentifierDeclaratorMain(
                      UnaryIdentifierDeclarator(
                        PostfixIdentifierDeclarator(
                          FunctionDeclarator(
                            ParenIdentifierDeclarator(
                              SimpleDeclarator(
                                superc.core.Syntax$Text(
                                  "b"
                                )
                              )
                            ),
                            PostfixingFunctionDeclarator(
                              superc.core.Syntax$Language(
                                "("
                              ),
                              $@23(),
                              ParameterTypeListOpt(),
                              $@24(),
                              superc.core.Syntax$Language(
                                ")"
                              )
                            )
                          )
                        )
                      )
                    )
                  )
                ),
                (defined A) && (defined B),
                FunctionPrototype(
                  TypeSpecifier(
                    BasicTypeSpecifier(
                      BasicTypeName(
                        superc.core.Syntax$Language(
                          "void"
                        )
                      )
                    )
                  ),
                  IdentifierDeclarator(
                    IdentifierDeclaratorMain(
                      UnaryIdentifierDeclarator(
                        PostfixIdentifierDeclarator(
                          FunctionDeclarator(
                            ParenIdentifierDeclarator(
                              SimpleDeclarator(
                                superc.core.Syntax$Text(
                                  "b"
                                )
                              )
                            ),
                            PostfixingFunctionDeclarator(
                              superc.core.Syntax$Language(
                                "("
                              ),
                              $@23(),
                              ParameterTypeListOpt(
                                ParameterTypeList(
                                  ParameterList(
                                    Conditional(
                                      (defined A),
                                      ParameterDeclaration(
                                        ParameterIdentifierDeclaration(
                                          TypeSpecifier(
                                            BasicTypeSpecifier(
                                              BasicTypeName(
                                                superc.core.Syntax$Language(
                                                  "int"
                                                )
                                              )
                                            )
                                          ),
                                          IdentifierDeclarator(
                                            IdentifierDeclaratorMain(
                                              ParenIdentifierDeclarator(
                                                SimpleDeclarator(
                                                  superc.core.Syntax$Text(
                                                    "a"
                                                  )
                                                )
                                              )
                                            )
                                          ),
                                          $@20(),
                                          AttributeSpecifierListOpt()
                                        )
                                      )
                                    )
                                  )
                                )
                              ),
                              $@24(),
                              superc.core.Syntax$Language(
                                ")"
                              )
                            )
                          )
                        )
                      )
                    )
                  )
                )
              )
            ),
            Conditional(
              (defined A) && !(defined B),
              $@1(),
              !(defined A) || (defined A) && (defined B),
              Conditional(
                !(defined A),
                $@1(),
                (defined A) && (defined B),
                $@1()
              )
            ),
            CompoundStatement(
              superc.core.Syntax$Language(
                "{"
              ),
              Conditional(
                (defined A) && !(defined B),
                $@27(),
                !(defined A) || (defined A) && (defined B),
                Conditional(
                  !(defined A),
                  $@27(),
                  (defined A) && (defined B),
                  $@27()
                )
              ),
              CompoundStatementBody(
                Conditional(
                  (defined A) && !(defined B),
                  LocalLabelDeclarationListOpt(),
                  !(defined A) || (defined A) && (defined B),
                  Conditional(
                    !(defined A),
                    LocalLabelDeclarationListOpt(),
                    (defined A) && (defined B),
                    LocalLabelDeclarationListOpt()
                  )
                ),
                DeclarationOrStatementList(
                  Conditional(
                    1,
                    Conditional(
                      (defined A) && !(defined B),
                      DeclarationOrStatementList(
                        Conditional(
                          (defined A) && (defined B),
                          DeclarationOrStatement(
                            DeclarationExtension(
                              Declaration(
                                DeclaringList(
                                  TypeSpecifier(
                                    BasicTypeSpecifier(
                                      BasicTypeName(
                                        superc.core.Syntax$Language(
                                          "int"
                                        )
                                      )
                                    )
                                  ),
                                  Declarator(
                                    IdentifierDeclarator(
                                      IdentifierDeclaratorMain(
                                        ParenIdentifierDeclarator(
                                          SimpleDeclarator(
                                            superc.core.Syntax$Text(
                                              "c"
                                            )
                                          )
                                        )
                                      )
                                    )
                                  ),
                                  AssemblyExpressionOpt(),
                                  AttributeSpecifierListOpt(),
                                  InitializerOpt(
                                    superc.core.Syntax$Language(
                                      "="
                                    ),
                                    Initializer(
                                      Constant(
                                        superc.core.Syntax$Text(
                                          "2"
                                        )
                                      )
                                    )
                                  )
                                ),
                                $@9(),
                                superc.core.Syntax$Language(
                                  ";"
                                )
                              )
                            )
                          )
                        )
                      ),
                      !(defined A) || (defined A) && (defined B),
                      Conditional(
                        !(defined A),
                        DeclarationOrStatementList(),
                        (defined A) && (defined B),
                        DeclarationOrStatementList(
                          Conditional(
                            (defined A) && (defined B),
                            DeclarationOrStatement(
                              DeclarationExtension(
                                Declaration(
                                  DeclaringList(
                                    TypeSpecifier(
                                      BasicTypeSpecifier(
                                        BasicTypeName(
                                          superc.core.Syntax$Language(
                                            "int"
                                          )
                                        )
                                      )
                                    ),
                                    Declarator(
                                      IdentifierDeclarator(
                                        IdentifierDeclaratorMain(
                                          ParenIdentifierDeclarator(
                                            SimpleDeclarator(
                                              superc.core.Syntax$Text(
                                                "c"
                                              )
                                            )
                                          )
                                        )
                                      )
                                    ),
                                    AssemblyExpressionOpt(),
                                    AttributeSpecifierListOpt(),
                                    InitializerOpt(
                                      superc.core.Syntax$Language(
                                        "="
                                      ),
                                      Initializer(
                                        Constant(
                                          superc.core.Syntax$Text(
                                            "2"
                                          )
                                        )
                                      )
                                    )
                                  ),
                                  $@9(),
                                  superc.core.Syntax$Language(
                                    ";"
                                  )
                                )
                              )
                            )
                          )
                        )
                      )
                    )
                  ),
                  Conditional(
                    1,
                    DeclarationOrStatement(
                      DeclarationExtension(
                        Declaration(
                          DeclaringList(
                            TypeSpecifier(
                              Conditional(
                                (defined A) && !(defined B),
                                BasicTypeSpecifier(
                                  BasicTypeName(
                                    superc.core.Syntax$Language(
                                      "int"
                                    )
                                  )
                                ),
                                !(defined A) || (defined A) && (defined B),
                                BasicTypeSpecifier(
                                  BasicTypeName(
                                    superc.core.Syntax$Language(
                                      "int"
                                    )
                                  )
                                )
                              )
                            ),
                            Declarator(
                              IdentifierDeclarator(
                                IdentifierDeclaratorMain(
                                  ParenIdentifierDeclarator(
                                    SimpleDeclarator(
                                      superc.core.Syntax$Text(
                                        "d"
                                      )
                                    )
                                  )
                                )
                              )
                            ),
                            AssemblyExpressionOpt(),
                            AttributeSpecifierListOpt(),
                            InitializerOpt()
                          ),
                          $@9(),
                          superc.core.Syntax$Language(
                            ";"
                          )
                        )
                      )
                    )
                  )
                )
              ),
              $@28(),
              superc.core.Syntax$Language(
                "}"
              )
            )
          )
        )
      )
    )
  )
)


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant