•  


GitHub - baryluk/d-demangle-cpp: D language symbol demangler for C++
Skip to content

baryluk/d-demangle-cpp

Repository files navigation

D programming language (dlang) symbol name demangler for C++

std::cout << demangle_d::demangle(
"
_D3std5stdio__T8writeflnTaTiZQoFNfxAaiZv
"
) << std::endl;
//
 Will print: void std.stdio.writefln!(char, int)(const char[], int) @safe

Goals

  • Easy of integration into any C++ codebase
  • Flexible licensing
  • Code simplicity following the spec closely in shape

Status

Alpha. It mostly works. For example it can demangle all symbols in Phobos without crashing, invalid accesses or going into infinite loops.

While performance is not its goal (in fact there are is plenty of slow string copying patterns in it), it is not slow. Demangling phobos symbols at a rate of 22000 symbols per second on a weak CPU.

Simple test script is provided to test few symbols.

Missing / untested features:

  • Underspecified features of demangling spec
  • wstring and dstring literals
  • assosciative array literals
  • inner functions are not demangled properly fully (but it is okish)
  • 64-bit integers and float values are untested (should work, but validation is not complete).

A full fuzzing testing would also be good to have.

Building

Just take d-demangle.h and d-demangle.cc and integrate into your code base.

It can also be built as a library and linked statically or dynamically.

You can also combine both files and use if you want.

Example working Makefile is provided.

Test program

A simple command line interface (similar to c++filt ) is provided.

$ make d-demangle
$ ./d-demangle _D3std5stdio__T8writeflnTaTiZQoFNfxAaiZv
void std.stdio.writefln
!
(char, int)writefln(const char[], int) @safe
$

Check ./d-demangle --help for extra options.

API stability

demangle_d::demangle(const std::string&) will be provided.

Extra parameters or overrides are not guaranteed to exist long term. (But are likely to be easy to change later).

Compatibility

We strive to support C++98 and anything after that. If C++11 is detected, it will internally use std::unordered_map for back references. Otherwise it will use std::map . So no modern features like auto , brace initalization , range based for loops, move semantics, etc.

The intent is code execution correctness and compatibility, not speed.

Routinly tested on gcc and clang on Linux.

Library facilities required: size_t , std::string , std::to_string(size_t) (For C++11. For C++98 it will use sprintf from cstdio ), std::runtime_error , standard allocator.

It would be nice to not require exceptions to be enabled. Patches welcome.

If desired std::string can be swapped for any other type with similar interface.

Note: On 32-bit systems, some extremally large or malformed mangled symbols, might fail to demangle. Hopefully just throw exception or return back the input without changes, without crashing or corrupting anything.

The code does not use too many C++ specific or complex features, which should make it easy to port to other languages like C, Go, Rust, Java, JavaScript, Python, PHP or even D, while keeping most of the code the same.

License

To facilitate wide adoption in any other software, the code is multi licensed.

Select any non-empty subset of licenses available for your project.

  • The Boost Source License (BSL)
  • MIT License
  • BSD 3-Clouse license
  • LGPL License
  • GPL v2 or later license

Contributing

Contributions, especially for compiler compatibility and correctess are welcome. By submitting pull requests you agree for the code to be released using any of the above licenses (including Copyright lines). You name will remain in the Git history, but not necassarily in a redistributed code.

Coding style follow Google style guidelines in formatting with 80 columns width, and * / & in types attached to the variable name. Function names are lower snake case tho.

Releases

No releases published

Packages

No packages published

Languages

- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본