2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 // gcc and clang minimal demangling
19 // Both follow Itanium C++ ABI
21 // We only decode namespaces and class typeid names for simplicity as its all we need.
23 // From http://mentorembedded.github.io/cxx-abi/abi.html#mangling-structure
25 // <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
26 // ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
28 // <prefix> ::= <prefix> <unqualified-name>
29 // ::= <template-prefix> <template-args>
30 // ::= <template-param>
34 // ::= <prefix> <data-member-prefix>
36 // <template-prefix> ::= <prefix> <template unqualified-name>
37 // ::= <template-param>
39 // <unqualified-name> ::= <operator-name>
40 // ::= <ctor-dtor-name>
42 // ::= <unnamed-type-name>
44 // <source-name> ::= <positive length number> <identifier>
45 // <number> ::= [n] <non-negative decimal integer>
46 // <identifier> ::= <unqualified source code identifier>
50 // Dali::Internal::Actor would be
52 // N4Dali8Internal5ActorE
56 #include <dali/internal/event/common/demangler.h>
61 // true if character represent a digit
62 inline bool IsDigit(char c)
64 return (c >= '0' && c <= '9');
67 // Gets the number of characters (number is in string)
68 // start The start position to look for a number
69 // result The number as an integer
70 // returns the number of characters used to define the number ie '12' is 2
71 size_t GetNumberOfCharacters(const std::string& s, const size_t& start, int& result)
73 size_t size = s.size();
79 for( ; i < size; ++i )
88 number = 10 * number + (c - '0');
109 #if defined(__clang__) || defined(__GNUC__)
111 // Demangle class name mangled according to the Itanium C++ ABI
112 // Returns demangled names ie "N4Dali8Internal5ActorE" is ["Dali","Internal","Actor"]
113 std::vector<std::string> DemangleNestedNames(const char *typeIdName)
115 std::vector<std::string> ret;
117 const std::string mangledName(typeIdName);
120 size_t size = mangledName.size();
127 // If the class isnt nested in a namespace then it just starts with the
128 // number of characters
129 if(mangledName[0] == 'N' && mangledName[size-1] == 'E')
134 while( size_t chars = GetNumberOfCharacters(mangledName, start, number) )
136 ret.push_back( mangledName.substr( start + chars, number ) );
138 start += chars + number;
146 # error Unsupported Compiler
150 const std::string DemangleClassName(const char *typeIdName)
153 std::vector<std::string> names = DemangleNestedNames(typeIdName);
157 name = names[ names.size() - 1 ];
163 } // namespace Internal