2013-07-16 01:43:32 +00:00
|
|
|
/*
|
2013-07-19 17:29:33 +00:00
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
2013-07-16 01:43:32 +00:00
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
2013-07-19 17:29:33 +00:00
|
|
|
Author: Leonardo de Moura
|
2013-07-16 01:43:32 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
|
2013-08-09 01:35:49 +00:00
|
|
|
constexpr char const * default_name_separator = "::";
|
2013-07-22 11:14:01 +00:00
|
|
|
enum class name_kind { ANONYMOUS, STRING, NUMERAL };
|
2013-07-16 01:43:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Hierarchical names.
|
|
|
|
*/
|
|
|
|
class name {
|
|
|
|
struct imp;
|
2013-07-21 22:56:18 +00:00
|
|
|
friend int cmp(imp * i1, imp * i2);
|
2013-07-29 05:34:39 +00:00
|
|
|
imp * m_ptr;
|
2013-07-21 22:56:18 +00:00
|
|
|
explicit name(imp * p);
|
2013-07-16 01:43:32 +00:00
|
|
|
public:
|
|
|
|
name();
|
2013-08-09 21:29:30 +00:00
|
|
|
name(char const * name);
|
2013-07-21 21:25:56 +00:00
|
|
|
explicit name(unsigned k);
|
2013-07-16 01:43:32 +00:00
|
|
|
name(name const & prefix, char const * name);
|
|
|
|
name(name const & prefix, unsigned k);
|
|
|
|
name(name const & other);
|
|
|
|
name(name && other);
|
2013-08-09 00:05:11 +00:00
|
|
|
name(std::initializer_list<char const *> const & l);
|
2013-07-16 01:43:32 +00:00
|
|
|
~name();
|
|
|
|
name & operator=(name const & other);
|
|
|
|
name & operator=(name && other);
|
2013-07-21 22:08:14 +00:00
|
|
|
friend bool operator==(name const & a, name const & b);
|
|
|
|
friend bool operator!=(name const & a, name const & b) { return !(a == b); }
|
2013-08-08 23:30:35 +00:00
|
|
|
friend bool operator==(name const & a, char const * b);
|
|
|
|
friend bool operator!=(name const & a, char const * b) { return !(a == b); }
|
2013-07-21 22:56:18 +00:00
|
|
|
// total order on hierarchical names.
|
2013-07-29 05:34:39 +00:00
|
|
|
friend int cmp(name const & a, name const & b) { return cmp(a.m_ptr, b.m_ptr); }
|
2013-07-21 22:56:18 +00:00
|
|
|
friend bool operator<(name const & a, name const & b) { return cmp(a, b) < 0; }
|
|
|
|
friend bool operator>(name const & a, name const & b) { return cmp(a, b) > 0; }
|
|
|
|
friend bool operator<=(name const & a, name const & b) { return cmp(a, b) <= 0; }
|
|
|
|
friend bool operator>=(name const & a, name const & b) { return cmp(a, b) >= 0; }
|
2013-07-22 11:14:01 +00:00
|
|
|
name_kind kind() const;
|
|
|
|
bool is_anonymous() const { return kind() == name_kind::ANONYMOUS; }
|
|
|
|
bool is_string() const { return kind() == name_kind::STRING; }
|
|
|
|
bool is_numeral() const { return kind() == name_kind::NUMERAL; }
|
2013-07-16 01:43:32 +00:00
|
|
|
unsigned get_numeral() const;
|
|
|
|
char const * get_string() const;
|
|
|
|
bool is_atomic() const;
|
|
|
|
name get_prefix() const;
|
2013-08-08 02:10:12 +00:00
|
|
|
/**
|
|
|
|
\brief Convert this hierarchical name into a string using the given separator to "glue" the different limbs.
|
|
|
|
*/
|
2013-08-09 01:35:49 +00:00
|
|
|
std::string to_string(char const * sep) const;
|
|
|
|
std::string to_string() const;
|
2013-07-16 01:43:32 +00:00
|
|
|
/**
|
|
|
|
\brief Size of the this name (in characters) when using the given separator.
|
|
|
|
*/
|
2013-08-09 01:35:49 +00:00
|
|
|
size_t size(char const * sep) const;
|
|
|
|
size_t size() const;
|
2013-07-20 21:15:54 +00:00
|
|
|
unsigned hash() const;
|
2013-07-16 01:43:32 +00:00
|
|
|
friend std::ostream & operator<<(std::ostream & out, name const & n);
|
|
|
|
class sep {
|
|
|
|
name const & m_name;
|
|
|
|
char const * m_sep;
|
|
|
|
public:
|
|
|
|
sep(name const & n, char const * s);
|
|
|
|
friend std::ostream & operator<<(std::ostream & out, sep const & s);
|
|
|
|
};
|
|
|
|
friend std::ostream & operator<<(std::ostream & out, sep const & s);
|
|
|
|
};
|
2013-08-05 03:52:14 +00:00
|
|
|
struct name_hash { unsigned operator()(name const & n) const { return n.hash(); } };
|
|
|
|
struct name_eq { bool operator()(name const & n1, name const & n2) const { return n1 == n2; } };
|
2013-08-09 01:35:49 +00:00
|
|
|
|
|
|
|
class options;
|
|
|
|
/** \brief Return the separator for hierarchical names */
|
|
|
|
char const * get_name_separator(options const & o);
|
2013-07-16 01:43:32 +00:00
|
|
|
}
|