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

Type inequality for forward declarations? #186

Open
Xazax-hun opened this issue Sep 30, 2021 · 2 comments
Open

Type inequality for forward declarations? #186

Xazax-hun opened this issue Sep 30, 2021 · 2 comments

Comments

@Xazax-hun
Copy link
Contributor

Xazax-hun commented Sep 30, 2021

Consider the following code:

struct X;

struct X
{
  void m();
};

It will produce the following IPR:

Namespace 'namespace '
|-Typedecl 'class' X
\-Typedecl 'class' X
  \-Class 'class X'
    \-Fundecl 'void (X *)' m
      \-Parameter 'X *' this

Currently, we are building this representation the following way:

  1. We create a Typedecl node with the name X and the type class (Typedecl(X) : class) for the forward declaration (the init of this Typedecl is null).
  2. We create a new Typedecl node for the definition, which has the same name and type (Typedecl(X) : class) but the init field is the actual class type with all the info from the definiton.

This approach is problematic, for the following reason. We get different types for the forward declaration, and the definition.
The type of the forward declaration: AsType(Typedecl(X))
The type of the definition: class X (from the init field of the second Typedecl)

Ideally, we want both the forward declaration and the definition to have the same type. One option would be, to also create an empty class for the forward declaration, but in that case we would either end up having two class types of the same name, or (in case they both refer to the same type that has all its details filled) we cannot tell which declaration is a forward declaration and which one is a definition.

Alternatively, I could also use AsType(Typedecl(X)) for the definition to have the same type, but it would also end up producing different types as we are talking about different Typedecl nodes.

How should we solve this? Do I miss something?

@d-winsor
Copy link
Contributor

d-winsor commented Sep 30, 2021 via email

@Xazax-hun
Copy link
Contributor Author

If you're referring to usages of the Type in other declarations such as Var or Parameter before and after the definition

Yep, this is exactly what I am referring to. Thanks for the clarification!

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

2 participants