use PhpCode\Language\Cpp\Mangling\ItaniumMangler;
use PhpCode\Language\Cpp\Specification\LanguageContextFactory;
use PhpCode\Language\Cpp\Specification\Standard;
// Create a language context.
// Standard::CPP2017 is for C++ 2017.
// Standard::CPP2003, Standard::CPP2011 or Standard::CPP2014 can also be used.
$languageContextFactory = new LanguageContextFactory();
$languageContext = $languageContextFactory->create(Standard::CPP2017);
// Create the mangler.
$mangler = new ItaniumMangler($languageContext);
To mangle a name, first, the mangler uses an instance of PhpCode\Language\Cpp\Parsing\Parser
to create a declarator, that is a representation of the name. Then, it encodes that declarator.
An exception, that implements PhpCode\Exception\PhpCodeExceptionInterface
, is thrown when the name cannot be mangled.
Parser
supports the rules defined in the C++ grammar documentation.
ItaniumMangler
supports the rules defined in the Itanium grammar documentation.
- Identifier
// '_Z4mainv'
\var_dump($mangler->mangleFunction('main()'));
- Qualified identifier
// '_ZN9Framework7Logging6Logger3logEv'
\var_dump($mangler->mangleFunction('Framework::Logging::Logger::log()'));
- None
// '_Z4mainv'
\var_dump($mangler->mangleFunction('calc()'));
- Boolean
// '_Z4calcb'
\var_dump($mangler->mangleFunction('calc(bool)'));
- Character
// '_Z4calccw'
\var_dump($mangler->mangleFunction('calc(char, wchar_t)'));
- Integer
// '_Z4calcsilij'
\var_dump($mangler->mangleFunction('calc(short, int, long, signed, unsigned)'));
- Float
// '_Z4calcfd'
\var_dump($mangler->mangleFunction('calc(float, double)'));
- Identifier
// '_Z4calc6EState'
\var_dump($mangler->mangleFunction('calc(EState)'));
- Qualified identifier
// '_Z4calcN3Dom7ElementE'
\var_dump($mangler->mangleFunction('calc(Dom::Element)'));
- Ellipsis
// '_Z4calciz'
\var_dump($mangler->mangleFunction('calc(int, ...)'));
// '_Z4calciz'
\var_dump($mangler->mangleFunction('calc(int ...)'));