2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
19 // gcc and clang minimal demangling
20 // Both follow Itanium C++ ABI
22 // We only decode namespaces and class typeid names for simplicity as its all we need.
24 // From http://mentorembedded.github.io/cxx-abi/abi.html#mangling-structure
26 // <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
27 // ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
29 // <prefix> ::= <prefix> <unqualified-name>
30 // ::= <template-prefix> <template-args>
31 // ::= <template-param>
35 // ::= <prefix> <data-member-prefix>
37 // <template-prefix> ::= <prefix> <template unqualified-name>
38 // ::= <template-param>
40 // <unqualified-name> ::= <operator-name>
41 // ::= <ctor-dtor-name>
43 // ::= <unnamed-type-name>
45 // <source-name> ::= <positive length number> <identifier>
46 // <number> ::= [n] <non-negative decimal integer>
47 // <identifier> ::= <unqualified source code identifier>
51 // Dali::Internal::Actor would be
53 // N4Dali8Internal5ActorE
57 #include <dali/internal/event/common/demangler.h>
62 // true if character represent a digit
63 inline bool IsDigit(char c)
65 return (c >= '0' && c <= '9');
68 // Gets the number of characters (number is in string)
69 // start The start position to look for a number
70 // result The number as an integer
71 // returns the number of characters used to define the number ie '12' is 2
72 size_t GetNumberOfCharacters(const std::string& s, const size_t& start, int& result)
74 size_t size = s.size();
80 for( ; i < size; ++i )
89 number = 10 * number + (c - '0');
110 #if defined(__clang__) || defined(__GNUC__)
112 // Demangle class name mangled according to the Itanium C++ ABI
113 // Returns demangled names ie "N4Dali8Internal5ActorE" is ["Dali","Internal","Actor"]
114 std::vector<std::string> DemangleNestedNames(const char *typeIdName)
116 std::vector<std::string> ret;
118 const std::string mangledName(typeIdName);
121 size_t size = mangledName.size();
128 // If the class isnt nested in a namespace then it just starts with the
129 // number of characters
130 if(mangledName[0] == 'N' && mangledName[size-1] == 'E')
135 while( size_t chars = GetNumberOfCharacters(mangledName, start, number) )
137 ret.push_back( mangledName.substr( start + chars, number ) );
139 start += chars + number;
147 # error Unsupported Compiler
151 const std::string DemangleClassName(const char *typeIdName)
154 std::vector<std::string> names = DemangleNestedNames(typeIdName);
158 name = names[ names.size() - 1 ];
164 } // namespace Internal