Merge branch 'master' into verilog-ams
[sverilog.git] / HName.cc
blobc0db77008f940c944f5333b0410efe6cd5dd3359
1 /*
2 * Copyright (c) 2001 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
8 * any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 #ifdef HAVE_CVS_IDENT
20 #ident "$Id: HName.cc,v 1.8 2007/06/02 03:42:12 steve Exp $"
21 #endif
23 # include "config.h"
24 # include "HName.h"
25 # include <iostream>
26 # include <cstring>
27 # include <cstdlib>
28 # include <climits>
29 #ifdef HAVE_MALLOC_H
30 # include <malloc.h>
31 #endif
34 hname_t::hname_t()
36 number_ = INT_MIN;
39 hname_t::hname_t(perm_string text)
41 name_ = text;
42 number_ = INT_MIN;
45 hname_t::hname_t(perm_string text, int num)
47 name_ = text;
48 number_ = num;
51 hname_t::hname_t(const hname_t&that)
53 name_ = that.name_;
54 number_ = that.number_;
57 hname_t& hname_t::operator = (const hname_t&that)
59 name_ = that.name_;
60 number_ = that.number_;
61 return *this;
64 hname_t::~hname_t()
68 perm_string hname_t::peek_name(void) const
70 return name_;
73 bool hname_t::has_number() const
75 return number_ != INT_MIN;
78 int hname_t::peek_number() const
80 return number_;
83 bool operator < (const hname_t&l, const hname_t&r)
85 int cmp = strcmp(l.peek_name(), r.peek_name());
86 if (cmp < 0) return true;
87 if (cmp > 0) return false;
88 if (l.has_number() && r.has_number())
89 return l.peek_number() < r.peek_number();
90 else
91 return false;
94 bool operator == (const hname_t&l, const hname_t&r)
96 if (l.peek_name() == r.peek_name()) {
97 if (l.has_number() && r.has_number())
98 return l.peek_number() == r.peek_number();
99 else
100 return true;
103 return false;
106 bool operator != (const hname_t&l, const hname_t&r)
107 { return ! (l==r); }
109 ostream& operator<< (ostream&out, const hname_t&that)
111 if (that.peek_name() == 0) {
112 out << "";
113 return out;
116 out << that.peek_name();
117 if (that.has_number())
118 out << "[" << that.peek_number() << "]";
120 return out;
124 * $Log: HName.cc,v $
125 * Revision 1.8 2007/06/02 03:42:12 steve
126 * Properly evaluate scope path expressions.
128 * Revision 1.7 2007/05/16 19:12:33 steve
129 * Fix hname_t use of space for 1 perm_string.
131 * Revision 1.6 2007/04/26 03:06:21 steve
132 * Rework hname_t to use perm_strings.
134 * Revision 1.5 2002/11/02 03:27:52 steve
135 * Allow named events to be referenced by
136 * hierarchical names.
138 * Revision 1.4 2002/08/12 01:34:58 steve
139 * conditional ident string using autoconfig.
141 * Revision 1.3 2002/01/05 04:36:06 steve
142 * include malloc.h only when available.
144 * Revision 1.2 2001/12/18 04:52:45 steve
145 * Include config.h for namespace declaration.
147 * Revision 1.1 2001/12/03 04:47:14 steve
148 * Parser and pform use hierarchical names as hname_t
149 * objects instead of encoded strings.