[RFC] `_Mangle` compiler extension.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[RFC] `_Mangle` compiler extension.

Oleg Smolsky via cfe-dev
Hi,

I was wondering, is there any interest in the following compiler
extension for Clang (converting strings to identifiers/symbols) and
tackling the issue with C++ mangling and the fact that there is no
way to generically address anything in another TU without going through
`dlsym` or alike unless it's exposed via a header.

This simple extension allows for doing just that, it's something I wrote
out of need mostly to save time and simplify a lot of existing code
in some codebase based around the idea of components.

The test below should be illustrative enough of what the extension does
and as far as its applications. It's already developed and has test
coverage in my fork as well as necessary diagnostics so I was wondering
if there was general interest in seeing this upstreamed.

I don't mind if there's no interest, since as I said, this was written
for the sake of convenience, others may have different views on whether
this is useful or not.

Thanks.
- Kristina

-----------------------------------------------------------------------

// RUN: %clang_cc1 -E %s | FileCheck -strict-whitespace %s

#define SECOND_PART "createInstance"
#define WITH_PREFIX(_rest) "_Z" _rest

// Reference
1: _Mangle("_ZNK{ MyClassName }{ createInstance }Ei")

// String macro
2: _Mangle("_ZNK{ MyClassName }{ " SECOND_PART " }Ei")

// Macro with parameter
3: _Mangle(WITH_PREFIX("NK{ MyClassName }{ createInstance }Ei"))

// Whitespace insigificance
4: _Mangle("_ZNK  {MyClassName}{createInstance}Ei")

// Less synthetic example
5: _Mangle("_ZN{google}{protobuf}{RepeatedField}IdED2Ev")

// CHECK: {{^}}1:_ZNK11MyClassName14createInstanceEi
// CHECK: {{^}}2:_ZNK11MyClassName14createInstanceEi
// CHECK: {{^}}3:_ZNK11MyClassName14createInstanceEi
// CHECK: {{^}}4:_ZNK11MyClassName14createInstanceEi
// CHECK: {{^}}5:_ZN6google8protobuf13RepeatedFieldIdED2Ev


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

smime.p7s (5K) Download Attachment