OSDN Git Service

[Support] Add a fancy helper function to get a static name for a type.
authorChandler Carruth <chandlerc@gmail.com>
Thu, 25 Feb 2016 03:58:21 +0000 (03:58 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Thu, 25 Feb 2016 03:58:21 +0000 (03:58 +0000)
commit0e5b32301d8eebde599ca34ce9ca3130d87195aa
tree736404710303466d77f576e095ac382f46096ca2
parentec0c489bcfb452f710687f666952189d9a7d3859
[Support] Add a fancy helper function to get a static name for a type.

This extracts the type name from __PRETTY_FUNCTION__ for compilers that
support it (I've opted Clang, GCC, and ICC into this as I've tested that
they work) and from __FUNCSIG__ which is very similar on MSVC. The
routine falls back gracefully on a stub "UNKNOWN_TYPE" string with
compilers or formats it doesn't understand.

This should be enough for a lot of common cases in LLVM where the real
goal is just to log or print a type name as a debugging aid, and save
a ton of boilerplate in the process. Notably, I'm planning to use this
to remove all the getName() boiler plate from the new pass manager.

The design and implementation is based on a bunch of advice and
discussion with Richard Smith and experimenting with most versions of
Clang and GCC. David Majnemer also provided excellent advice on how best
to do this with MSVC. Richard also checked that ICC does something
reasonable and I'll watch the build bots for other compilers. It'd be
great if someone could contribute logic for xlC and/or other toolchains.

Differential Revision: http://reviews.llvm.org/D17565

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261819 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Support/TypeName.h [new file with mode: 0644]
unittests/Support/CMakeLists.txt
unittests/Support/TypeNameTest.cpp [new file with mode: 0644]