Commit 72081162 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

2005-02-03 Benoît Perrot <benoit@lrde.epita.fr>

	* src/inst/section.hh: Store the labels in a set. Use Labels to get 
	the offset.
	* src/inst/label.hh (deref_ptr_less): Declare and define a label 
	pointer comparator.
parent cbd0b70b
2005-02-03 Benot Perrot <benoit@lrde.epita.fr>
* src/inst/section.hh: Store the labels in a set. Use Labels to get
the offset.
* src/inst/label.hh (deref_ptr_less): Declare and define a label
pointer comparator.
2005-02-03 Benot Perrot <benoit@lrde.epita.fr>
Store an iterator in TextLabels.
......
......@@ -30,6 +30,16 @@ namespace inst
class Label
{
public:
struct deref_ptr_less:
public std::binary_function<const Label*, const Label*, bool>
{
bool operator()(const Label* l1, const Label* l2) const
{
return *l1 < *l2;
}
};
protected:
Label(const std::string &s):
ustr_(misc::unique_string::create(s))
......
......@@ -35,10 +35,10 @@ namespace inst
{
protected:
typedef std::list<const Label*> label_list_type;
typedef std::set<const Label*, Label::deref_ptr_less> label_set_type;
public:
typedef std::map<int, label_list_type> offset_label_type;
typedef std::map<const Label, int> label_offset_type;
public:
/// Construct an abstract section `\a name'
......@@ -49,29 +49,28 @@ namespace inst
{}
protected:
void register_label(Label *label)
void register_label(Label *label)
{
// FIXME: check that this label has not already been added.
offsets_[*label] = label->get_offset();
sorted_labels_.insert(label);
labels_[label->get_offset()].push_back(label);
}
public:
bool has_label(const misc::unique_string &label) const
bool has_label(const misc::unique_string &label) const
{
label_offset_type::const_iterator it = offsets_.find(Label(label, 0));
return it != offsets_.end();
}
Label dummy(label, 0);
int get_offset(const misc::unique_string &label) const
{
label_offset_type::const_iterator it = offsets_.find(Label(label, 0));
assertion(it != offsets_.end());
return (*it).second;
label_set_type::const_iterator it = sorted_labels_.find(&dummy);
return it != sorted_labels_.end();
}
const label_offset_type& get_offsets() const
int get_offset(const misc::unique_string &label) const
{
return offsets_;
Label dummy(label, 0);
label_set_type::const_iterator it = sorted_labels_.find(&dummy);
assertion(it != sorted_labels_.end());
return (*it)->get_offset();
}
public:
......@@ -80,9 +79,10 @@ namespace inst
protected:
const misc::unique_string &name_;
label_set_type sorted_labels_;
// FIXME: Might be static, to avoid multi-definition of labels.
offset_label_type labels_;
label_offset_type offsets_;
};
inline std::ostream&
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment