mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This is only useful for unique-identification uses of the mangler, like in SourceKit, which has to deal with invalid code. Since this is not related to ABI, we can change the encoding anytime we want. Swift SVN r8557
219 lines
4.8 KiB
C++
219 lines
4.8 KiB
C++
//===--- Demangle.h - Interface to Swift symbol demangling -------*- C++ -*-==//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_BASIC_DEMANGLE_H
|
|
#define SWIFT_BASIC_DEMANGLE_H
|
|
|
|
#include "llvm/ADT/IntrusiveRefCntPtr.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "swift/Basic/LLVM.h"
|
|
|
|
namespace swift {
|
|
namespace Demangle {
|
|
|
|
class Node;
|
|
typedef llvm::IntrusiveRefCntPtr<Node> NodePointer;
|
|
|
|
class Node : public llvm::RefCountedBase<Node> {
|
|
public:
|
|
|
|
typedef llvm::SmallVector<NodePointer,10> NodeVector;
|
|
|
|
typedef NodeVector::iterator iterator;
|
|
typedef NodeVector::const_iterator const_iterator;
|
|
typedef NodeVector::size_type size_type;
|
|
|
|
enum class Kind {
|
|
Failure = 0,
|
|
Module,
|
|
Class,
|
|
Structure,
|
|
Enum,
|
|
Protocol,
|
|
Substitution,
|
|
TypeName,
|
|
MetaType,
|
|
ReturnType,
|
|
Constructor,
|
|
Destructor,
|
|
BaseName,
|
|
ObjCAttribute,
|
|
Directness,
|
|
GenericTypeMetadataPattern,
|
|
ProtocolWitness,
|
|
Metaclass,
|
|
TypeMetadata,
|
|
ArrayType,
|
|
Number,
|
|
BuiltinTypeName,
|
|
FunctionType,
|
|
UncurriedFunctionType,
|
|
ObjCBlock,
|
|
BoundGenericClass,
|
|
BoundGenericStructure,
|
|
BoundGenericEnum,
|
|
TypeList,
|
|
ArgumentTuple,
|
|
ValueWitnessKind,
|
|
ValueWitnessTable,
|
|
WitnessTableOffset,
|
|
FieldOffset,
|
|
ProtocolWitnessTable,
|
|
LazyProtocolWitnessTableAccessor,
|
|
LazyProtocolWitnessTableTemplate,
|
|
DependentProtocolWitnessTableGenerator,
|
|
DependentProtocolWitnessTableTemplate,
|
|
BridgeToBlockFunction,
|
|
ProtocolConformance,
|
|
PrefixOperator,
|
|
PostfixOperator,
|
|
InfixOperator,
|
|
Identifier,
|
|
LocalEntity,
|
|
Deallocator,
|
|
Allocator,
|
|
Declaration,
|
|
Addressor,
|
|
Getter,
|
|
Setter,
|
|
VariadicTuple,
|
|
NonVariadicTuple,
|
|
TupleElement,
|
|
ProtocolList,
|
|
AssociatedTypeRef,
|
|
SelfTypeRef,
|
|
ArchetypeRef,
|
|
ArchetypeAndProtocol,
|
|
ArchetypeList,
|
|
ByRef,
|
|
GenericType,
|
|
Unowned,
|
|
Weak,
|
|
Unknown,
|
|
TupleElementName,
|
|
TupleElementType,
|
|
FunctionName,
|
|
DeclarationName,
|
|
Path,
|
|
DeclarationType,
|
|
Type,
|
|
ErrorType
|
|
};
|
|
|
|
size_type size ();
|
|
iterator begin ();
|
|
iterator end ();
|
|
const_iterator begin () const;
|
|
const_iterator end () const;
|
|
|
|
NodePointer front ();
|
|
NodePointer back ();
|
|
|
|
NodePointer child_at (size_type idx);
|
|
|
|
Node (Kind k, std::string t);
|
|
|
|
Node (const Node& other);
|
|
|
|
Node* getParent ();
|
|
|
|
NodePointer getNextNode ();
|
|
Node* getPreviousNode ();
|
|
|
|
NodePointer push_back_child (NodePointer child);
|
|
|
|
void setParent (Node *parent);
|
|
void setNextNode (NodePointer successor);
|
|
|
|
Kind getKind();
|
|
void setKind (Kind k);
|
|
|
|
std::string getText();
|
|
void setText (const std::string &t);
|
|
|
|
static NodePointer makeNodePointer(Kind k, std::string t = "");
|
|
|
|
private:
|
|
struct FindPtr {
|
|
FindPtr(Node* v) : ptr_val(v) {}
|
|
bool operator () (NodePointer sp) {
|
|
return sp.getPtr() == ptr_val;
|
|
}
|
|
private:
|
|
Node* ptr_val;
|
|
};
|
|
|
|
Kind NodeKind;
|
|
std::string NodeText;
|
|
NodePointer Successor;
|
|
NodeVector Children;
|
|
Node* Parent;
|
|
Node* Predecessor;
|
|
|
|
void setParentImpl (Node *parent);
|
|
void setSuccessorImpl (NodePointer successor);
|
|
void push_back_childImpl (NodePointer child);
|
|
void insertSiblingImpl (NodePointer child);
|
|
};
|
|
|
|
/// \brief Demangle the given string as a Swift symbol.
|
|
///
|
|
/// Typical usage:
|
|
/// \code
|
|
/// NodePointer aDemangledName =
|
|
/// swift::Demangler::demangleSymbol("SomeSwiftMangledName")
|
|
/// \endcode
|
|
///
|
|
/// \param mangled The mangled string.
|
|
///
|
|
///
|
|
/// \returns A parse tree for the demangled string - or a Failure node on
|
|
/// failure.
|
|
///
|
|
NodePointer demangleSymbolAsNode(llvm::StringRef mangled);
|
|
|
|
/// \brief Transform the node structure in a string.
|
|
///
|
|
/// Typical usage:
|
|
/// \code
|
|
/// std::string aDemangledName =
|
|
/// swift::Demangler::nodeToString(aNode)
|
|
/// \endcode
|
|
///
|
|
/// \param pointer A pointer to a parse tree generated by the demangler.
|
|
///
|
|
///
|
|
/// \returns A string representing the demangled name.
|
|
///
|
|
std::string nodeToString(NodePointer pointer);
|
|
|
|
/// \brief Demangle the given string as a Swift symbol.
|
|
///
|
|
/// Typical usage:
|
|
/// \code
|
|
/// std::string aDemangledName =
|
|
/// swift::Demangler::demangleSymbol("SomeSwiftMangledName")
|
|
/// \endcode
|
|
///
|
|
/// \param mangled The mangled string.
|
|
///
|
|
///
|
|
/// \returns A string representing the demangled name.
|
|
///
|
|
std::string demangleSymbolAsString(llvm::StringRef mangled);
|
|
|
|
} // end namespace Demangle
|
|
} // end namespace swift
|
|
|
|
#endif
|