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
|
2013-09-13 10:35:29 +00:00
|
|
|
#include <string>
|
2013-07-16 01:43:32 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2013-08-13 10:40:51 +00:00
|
|
|
namespace lean {
|
2013-08-13 15:18:01 +00:00
|
|
|
constexpr char const * lean_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-09-04 06:15:37 +00:00
|
|
|
/**
|
|
|
|
\brief Create a hierarchical name using the given strings.
|
|
|
|
Example: <code>name{"foo", "bla", "tst"}</code> creates the hierarchical
|
|
|
|
name <tt>foo::bla::tst</tt>.
|
|
|
|
*/
|
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();
|
2013-08-13 22:13:54 +00:00
|
|
|
static name const & anonymous();
|
2013-07-16 01:43:32 +00:00
|
|
|
name & operator=(name const & other);
|
|
|
|
name & operator=(name && other);
|
2013-08-19 18:43:09 +00:00
|
|
|
/** \brief Return true iff \c n1 is a prefix of \c n2. */
|
|
|
|
friend bool is_prefix_of(name const & n1, name const & n2);
|
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-09-04 06:15:37 +00:00
|
|
|
/**
|
|
|
|
\brief 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;
|
2013-09-04 06:15:37 +00:00
|
|
|
/**
|
|
|
|
\brief If the tail of the given hierarchical name is a string, then it returns this string.
|
|
|
|
\pre is_string()
|
|
|
|
*/
|
2013-07-16 01:43:32 +00:00
|
|
|
char const * get_string() const;
|
|
|
|
bool is_atomic() const;
|
2013-08-08 02:10:12 +00:00
|
|
|
/**
|
2013-09-04 06:15:37 +00:00
|
|
|
\brief Return the prefix of a hierarchical name
|
|
|
|
\pre !is_atomic()
|
2013-08-08 02:10:12 +00:00
|
|
|
*/
|
2013-09-04 06:15:37 +00:00
|
|
|
name get_prefix() const;
|
|
|
|
/** \brief Convert this hierarchical name into a string. */
|
2013-08-09 01:35:49 +00:00
|
|
|
std::string to_string() const;
|
2013-09-03 17:09:19 +00:00
|
|
|
/** \brief Size of the this name (in characters). */
|
2013-08-09 01:35:49 +00:00
|
|
|
size_t size() const;
|
2013-07-20 21:15:54 +00:00
|
|
|
unsigned hash() const;
|
2013-09-03 17:09:19 +00:00
|
|
|
/** \brief Return true iff the name contains only safe ASCII chars */
|
|
|
|
bool is_safe_ascii() const;
|
2013-07-16 01:43:32 +00:00
|
|
|
friend std::ostream & operator<<(std::ostream & out, name const & n);
|
2013-09-03 18:07:28 +00:00
|
|
|
/** \brief Concatenate the two given names. */
|
|
|
|
friend name operator+(name const & n1, name const & n2);
|
2013-07-16 01:43:32 +00:00
|
|
|
};
|
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-07-16 01:43:32 +00:00
|
|
|
}
|