embedded_tags_visitor::embedded_tags_visitor(bool all_tags)
{
- tags["/* guru */"] = false;
- tags["/* unprivileged */"] = false;
- tags["/* myproc-unprivileged */"] = false;
+ // populate the set of tags that could appear in embedded code/expressions
+ available_tags.insert("/* guru */");
+ available_tags.insert("/* unprivileged */");
+ available_tags.insert("/* myproc-unprivileged */");
if (all_tags)
{
- tags["/* pure */"] = false;
- tags["/* unmangled */"] = false;
- tags["/* unmodified-fnargs */"] = false;
+ available_tags.insert("/* pure */");
+ available_tags.insert("/* unmangled */");
+ available_tags.insert("/* unmodified-fnargs */");
}
}
+bool embedded_tags_visitor::tagged_p (const std::string& tag)
+{
+ return tags.count(tag);
+}
+
void embedded_tags_visitor::find_tags_in_code (const string& s)
{
- map<string, bool>::iterator tag;
- for (tag = tags.begin(); tag != tags.end(); ++tag)
- if (!tag->second)
- tag->second = s.find(tag->first) != string::npos;
+ set<string>::iterator tag;
+ for (tag = available_tags.begin(); tag != available_tags.end(); ++tag)
+ if(s.find(*tag) != string::npos)
+ tags.insert(*tag);
}
void embedded_tags_visitor::visit_embeddedcode (embeddedcode *s)
embedded_tags_visitor etv(all_tags);
this->body->visit(&etv);
- map<string, bool>::const_iterator tag;
- for (tag = etv.tags.begin(); tag != etv.tags.end(); ++tag)
- if (tag->second)
- o << " " << tag->first;
+ set<string, bool>::const_iterator tag;
+ for (tag = etv.available_tags.begin(); tag != etv.available_tags.end(); ++tag)
+ if (etv.tagged_p(*tag))
+ o << " " << *tag;
}
void arrayindex::print (ostream& o) const
struct embedded_tags_visitor: public traversing_visitor
{
- std::map<std::string, bool> tags;
+ std::set<std::string> available_tags;
+ std::set<std::string> tags; // set of the tags that appear in the code
embedded_tags_visitor(bool all_tags);
+ bool tagged_p (const std::string &tag);
void find_tags_in_code (const std::string& s);
void visit_embeddedcode (embeddedcode *s);
void visit_embedded_expr (embedded_expr *e);