Bug 22033 – importC: Add C++ helper function to return Type for given Identifier or string
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-06-17T16:36:34Z
Last change time
2021-07-17T07:11:45Z
Keywords
GDC, ImportC
Assigned to
No Owner
Creator
Iain Buclaw
Comments
Comment #0 by ibuclaw — 2021-06-17T16:36:34Z
For example, GCC provides the "C" wchar_t type as a macro, which could be defined as "int", or "short unsigned int", or "long int", or "long unsigned int", etc...
As DMD now has the ability to parse C types, it would be great to expose this from CParser to convert these strings to get D Types.
e.g:
---
Type *ctype = CParser::getType("short unsigned int");
assert(ctype->ty == TY::Tuns16);
Comment #1 by bugzilla — 2021-07-16T08:49:09Z
I'm not sure what good this will do. As wchar_t is a macro, it gets replaced with a C type by the preprocessor, and ImportC will never see it.
Comment #2 by ibuclaw — 2021-07-16T11:03:33Z
(In reply to Walter Bright from comment #1)
> I'm not sure what good this will do. As wchar_t is a macro, it gets replaced
> with a C type by the preprocessor, and ImportC will never see it.
Was thinking about possible portability issues, and I was referring to internally within the compiler it's a macro "string", which gets parsed and resolved as the appropriate AST type.
e.g: These are defaults
---
#define WCHAR_TYPE "int"
#define PTRDIFF_TYPE "long int"
#define WINT_TYPE "unsigned int"
Which could be overridden by the backend target.
If these eventually point to their respective special cpp macros __WCHAR_TYPE__, __PTRDIFF_TYPE__, __WINT_TYPE__, etc... then of course these will be all be expanded by the preprocessor leaving us not having to deal with it.
Comment #3 by bugzilla — 2021-07-17T07:11:45Z
Yes, I see no reason for ImportC to deal with this. It's the preprocessor's job.