The following message is a courtesy copy of an article
that has been posted to lrde.proj as well.
>> "Benoît" == Benoît Perrot
<benoit(a)lrde.epita.fr> writes:
Index: src/vm/virtual_machine.cc
--- src/vm/virtual_machine.cc (revision 187)
+++ src/vm/virtual_machine.cc (revision 188)
@@ -35,7 +35,7 @@
{
reset();
- const misc::unique_string &main =
misc::unique_string::create("main");
+ misc::unique_string main("main");
if (! program.text_section ().has_label(main))
I don't even think you need to create the variable main. The whole
point is to be able to write
if (! program.text_section ().has_label("main"))
(unless you need the variable afterward, of course).
Then you should (IMHO) also introduce a conversion operator to
std::string.
Index: src/misc/unique_string.hh
--- src/misc/unique_string.hh (revision 187)
+++ src/misc/unique_string.hh (revision 188)
@@ -26,7 +26,7 @@
the implementation is quite different. */
#include <string>
-#include <map>
+#include <set>
#include <iostream>
namespace misc
@@ -44,32 +44,28 @@
}
};
- typedef std::map<const std::string*,
unique_string,
+ typedef std::set<const std::string*,
string_ptr_less>
string_to_unique_type;
Why a set of pointers instead of a set of strings?
private:
static string_to_unique_type pool_;
private:
- const std::string &str_;
+ const std::string *str_;
This guy should be a set::const_iterator, no?
{id}\":\" {
- std::string label = yytext;
+ std::string label(yytext);
label.resize(yyleng - 1);
- yylval->id = &misc::unique_string::create(label);
+ yylval->id = new misc::unique_string(label);
return LABEL_DEF;
You don't need to introduce label IMHO.