GabrielDosReis/ipr

Type inequality for forward declarations?

Opened this issue · 2 comments

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?

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!