Files
swift-mirror/include/swift/Basic/Demangle.h
Enrico Granata b3576d8599 Replacing the GenericTypeApplication node with more specific BoundGeneric{Class|Structure|Union} nodes
Removing the TypeList node underneath a TypeList, a TypeList just needs to wrap a list of Type nodes



Swift SVN r7990
2013-09-06 17:47:06 +00:00

216 lines
4.7 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,
ObjCBlock,
BoundGenericClass,
BoundGenericStructure,
BoundGenericUnion,
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,
FunctionName,
DeclarationName,
Path,
DeclarationType,
Type
};
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