Files
swift-mirror/include/swift/Basic/Demangle.h
Enrico Granata ff3ea6e3ce <rdar://problem/14830080> & <rdar://problem/14822344>
The previous implementation of the tree structure for the demangler had a bug in the low-level tree management code which caused the tree structure to diverge depending on whether
nodes were added as siblings or children. This checkin fixes the issue by making sure that the tree of nodes is kept coherent at all times.
Some adjustments are necessary to ensure the nodes were still generated properly and correctly turned into strings
Added a new test case



Swift SVN r7643
2013-08-27 22:56:48 +00:00

216 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,
Union,
Protocol,
Substitution,
TypeName,
MetaType,
ReturnType,
Constructor,
Destructor,
BaseName,
ObjCAttribute,
Directness,
GenericTypeMetadataPattern,
ProtocolWitness,
Metaclass,
TypeMetadata,
ArrayType,
Number,
BuiltinTypeName,
FunctionType,
UncurriedFunctionType,
UncurriedFunctionMetaType,
UncurriedFunctionFunctionType,
ObjCBlock,
GenericTypeApplication,
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,
ArchetypeRef,
ArchetypeAndProtocol,
ArchetypeList,
ByRef,
GenericType,
Unowned,
Weak,
Unknown,
TupleElementName,
TupleElementType,
TypeListEntry,
FunctionName,
NominalType,
DeclarationName,
DeclarationContext,
DeclarationIdentifier,
DeclarationType
};
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* 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