Accessing number of template parameter for a record type

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing number of template parameter for a record type

David Zarzycki via cfe-dev
Dear all,

I want to access the number of parameters given to a template class during object creation in collectTemplateParams() ( in CGDebugInfo.cpp). 

Ex
foo<int,>        a; // I want 1
foo<int,char> b; // I want 2
assuming foo is template class and its default parameters are <char,char>

In  collectTemplateParams(), I can find actual number of parameters, which is after desugaring the templateSpecialization type.

Is there any way that can give me the parameters count?


--
Thanking You
Awanish Pandey
PhD, CSE
IIT Kanpur

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Accessing number of template parameter for a record type

David Zarzycki via cfe-dev
On Sat, 7 Dec 2019 at 00:12, Awanish Pandey via cfe-dev <[hidden email]> wrote:
Dear all,

I want to access the number of parameters given to a template class during object creation in collectTemplateParams() ( in CGDebugInfo.cpp). 

Ex
foo<int,>        a; // I want 1
foo<int,char> b; // I want 2
assuming foo is template class and its default parameters are <char,char>

In  collectTemplateParams(), I can find actual number of parameters, which is after desugaring the templateSpecialization type.

Is there any way that can give me the parameters count?

You're looking for the number of template arguments, not the number of template parameters. You can find that by looking at TemplateSpecializationType::getNumArgs() (prior to desugaring, which will remove the difference between the types of a and b).

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Accessing number of template parameter for a record type

David Zarzycki via cfe-dev
Hi Richard,

Thanks for the suggestion. Yes, I have already retrieved that before the desugaring. I want to access this value after the desugaring. The main issue is after the desugaring it becomes the RecordType, in this type the number of parameters is always the same. 
So, I think, I have to pass this information in the RecordType even after desugaring. What will be the best way to achieve this goal?


On Mon, Dec 9, 2019 at 12:59 PM Richard Smith <[hidden email]> wrote:
On Sat, 7 Dec 2019 at 00:12, Awanish Pandey via cfe-dev <[hidden email]> wrote:
Dear all,

I want to access the number of parameters given to a template class during object creation in collectTemplateParams() ( in CGDebugInfo.cpp). 

Ex
foo<int,>        a; // I want 1
foo<int,char> b; // I want 2
assuming foo is template class and its default parameters are <char,char>

In  collectTemplateParams(), I can find actual number of parameters, which is after desugaring the templateSpecialization type.

Is there any way that can give me the parameters count?

You're looking for the number of template arguments, not the number of template parameters. You can find that by looking at TemplateSpecializationType::getNumArgs() (prior to desugaring, which will remove the difference between the types of a and b).


--
Thanking You
Awanish Pandey
PhD, CSE
IIT Kanpur

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Accessing number of template parameter for a record type

David Zarzycki via cfe-dev
On Sun, 8 Dec 2019 at 23:37, Awanish Pandey via cfe-dev <[hidden email]> wrote:
Hi Richard,

Thanks for the suggestion. Yes, I have already retrieved that before the desugaring. I want to access this value after the desugaring. The main issue is after the desugaring it becomes the RecordType, in this type the number of parameters is always the same. 
So, I think, I have to pass this information in the RecordType even after desugaring. What will be the best way to achieve this goal?

Desugaring necessarily removes this information: "a" and "b" below have the same type, so their fully-desugared (canonical) types are by definition the same. It's hard to say more than that without digging deeply into your use case, but if you want to present information on the type as written, you generally shouldn't be desugaring the type.

On Mon, Dec 9, 2019 at 12:59 PM Richard Smith <[hidden email]> wrote:
On Sat, 7 Dec 2019 at 00:12, Awanish Pandey via cfe-dev <[hidden email]> wrote:
Dear all,

I want to access the number of parameters given to a template class during object creation in collectTemplateParams() ( in CGDebugInfo.cpp). 

Ex
foo<int,>        a; // I want 1
foo<int,char> b; // I want 2
assuming foo is template class and its default parameters are <char,char>

In  collectTemplateParams(), I can find actual number of parameters, which is after desugaring the templateSpecialization type.

Is there any way that can give me the parameters count?

You're looking for the number of template arguments, not the number of template parameters. You can find that by looking at TemplateSpecializationType::getNumArgs() (prior to desugaring, which will remove the difference between the types of a and b).


--
Thanking You
Awanish Pandey
PhD, CSE
IIT Kanpur
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev