> I found this is a bug in my front end because I used the same type for the
> parameters in different functions, so the references to the parameter in
> the structure messed up.
>
> The thing I want to implement is creating something like this pointers in
> C++ of structure type whose variably modified fields depend on other
> fields.
>
> So the problem is the reference of this parameter differs from function to
> function, and therefore, in the most straightforward solution, I have to
> deep copy the whole structure for each function, so it can correctly refer
> to the parameter.
>
> However, I want to avoid the deep copy.
>
> So, first, I guess it's not safe to share the same PARM_DECL among
> different functions, is it true?
Yes, you cannot share a PARM_DECL.
> If true, is it possible to refer to the first parameter of whatever
> functions in the same way, so I can use the same type built upon that
> reference?
No, I don't think so, at least in GENERIC. Maybe the C++ front-end has some
mechanism for "this" though, but I'm no C++ expert.
> And if so, at which stage, I can build such a reference?
If you want to build the type once for all, generically, and instantiate it
for each function, you'll probably need to go the PLACEHOLDER_EXPR route as
suggested by Ian. The idea is to translate S.a in:
struct S { int a; int b[S.a]; };
as COMPONENT_REF <PLACEHOLDER_EXPR, FIELD_DECL> where PLACEHOLDER_EXPR has the
type of struct S and FIELD_DECL is a. This is supported by the middle-end.
Then, in the front-end, each time S.a is used _in the code_, you instantiate
it by means of SUBSTITUTE_PLACEHOLDER_IN_EXPR. The middle-end will do the
same when S.a is implicitly used as the size of the array for example.
See the Ada front-end for practical references (ada/gcc-interface).
--
Eric Botcazou