[phc-internals] [phc commit] r1821 - trunk/src/lib
codesite-noreply at google.com
codesite-noreply at google.com
Sun Oct 26 19:10:55 GMT 2008
Author: paul.biggar
Date: Sun Oct 26 12:10:27 2008
New Revision: 1821
Modified:
trunk/src/lib/AttrMap.cpp
trunk/src/lib/AttrMap.h
trunk/src/lib/Map.h
trunk/src/lib/String.h
trunk/src/lib/error.h
Log:
A number of changes to lib/ had been done on the dataflow branch, this
brings them into trunk. Most changes are minor. The only non-minor one is
to move some of the AttrMap functionality into Map.
Modified: trunk/src/lib/AttrMap.cpp
==============================================================================
--- trunk/src/lib/AttrMap.cpp (original)
+++ trunk/src/lib/AttrMap.cpp Sun Oct 26 12:10:27 2008
@@ -9,9 +9,10 @@
#include "String.h"
#include "Boolean.h"
#include "Integer.h"
+#include <boost/tuple/tuple.hpp> // for tie
-
-AttrMap::AttrMap() : Map<string, Object*>()
+AttrMap::AttrMap()
+: Map<string, Object*>()
{
}
@@ -19,13 +20,6 @@
{
}
-Object* AttrMap::get(string key)
-{
- if (!has (key)) return NULL;
-
- return (*this)[key];
-}
-
Boolean* AttrMap::get_boolean(string key)
{
return dyc<Boolean> (get (key));
@@ -58,16 +52,6 @@
return ret->value();
}
-bool AttrMap::has(string key)
-{
- return find(key) != end();
-}
-
-void AttrMap::set(string key, Object* value)
-{
- (*this)[key] = value;
-}
-
void AttrMap::erase_with_prefix (string key_prefix)
{
AttrMap::iterator i;
@@ -85,19 +69,22 @@
}
}
-AttrMap* AttrMap::clone()
+AttrMap*
+AttrMap::clone()
{
AttrMap* result = new AttrMap;
result->clone_all_from(this);
return result;
}
-void AttrMap::clone_all_from(AttrMap* other)
+void
+AttrMap::clone_all_from(AttrMap* other)
{
- AttrMap::const_iterator i;
- for(i = other->begin(); i != other->end(); i++)
+ std::string str;
+ Object* obj;
+ foreach (boost::tie (str, obj), *other)
{
- assert ((*i).second != NULL);
- set((*i).first, (*i).second->clone());
+ assert (obj != NULL);
+ set(str, obj->clone());
}
}
Modified: trunk/src/lib/AttrMap.h
==============================================================================
--- trunk/src/lib/AttrMap.h (original)
+++ trunk/src/lib/AttrMap.h Sun Oct 26 12:10:27 2008
@@ -8,7 +8,6 @@
#ifndef PHC_ATTR_MAP_H
#define PHC_ATTR_MAP_H
-#include "lib/String.h"
#include "lib/Object.h"
#include "lib/Map.h"
@@ -16,7 +15,7 @@
class Integer;
class Boolean;
-class AttrMap : public Map<string, Object*>
+class AttrMap : public Map<std::string, Object*>
{
public:
AttrMap();
@@ -24,21 +23,18 @@
// Retrieve attributes of various types
public:
- Object* get(string key);
- Boolean* get_boolean(string key);
- Integer* get_integer(string key);
- String* get_string(string key);
- bool has(string key);
+ Boolean* get_boolean(std::string key);
+ Integer* get_integer(std::string key);
+ String* get_string(std::string key);
// Special support for bools
public:
- void set_true(string key);
- void set_false(string key);
- bool is_true(string key); // is_true returns false is not has(key)
+ void set_true(std::string key);
+ void set_false(std::string key);
+ bool is_true(std::string key); // is_true returns false is not has(key)
public:
- void set(string key, Object* value);
- void erase_with_prefix (string key_prefix);
+ void erase_with_prefix (std::string key_prefix);
public:
AttrMap* clone();
Modified: trunk/src/lib/Map.h
==============================================================================
--- trunk/src/lib/Map.h (original)
+++ trunk/src/lib/Map.h Sun Oct 26 12:10:27 2008
@@ -21,9 +21,30 @@
{
public:
Map() : std::map<_Key, _Tp, _Compare, _Alloc>() {}
+ Map(_Compare comparator) : std::map<_Key, _Tp, _Compare,
_Alloc>(comparator) {}
virtual ~Map() {}
Map* clone() { assert (0); }
+
+public:
+ bool has(_Key key)
+ {
+ return this->find(key) != this->end();
+ }
+
+ _Tp get(_Key key)
+ {
+ if (!has (key)) return NULL;
+
+ return (*this)[key];
+ }
+
+ void set(_Key key, _Tp value)
+ {
+ (*this)[key] = value;
+ }
+
+
};
#endif // PHC_MAP_H
Modified: trunk/src/lib/String.h
==============================================================================
--- trunk/src/lib/String.h (original)
+++ trunk/src/lib/String.h Sun Oct 26 12:10:27 2008
@@ -17,8 +17,11 @@
using std::stringstream;
class AttrMap;
+class String;
// TODO: strings are not garbage collected (it doesnt matter that they
arent traced)
+typedef List<String*> String_list;
+
class String : public string, virtual public Object
{
// This is a hack and will at some point be removed.
Modified: trunk/src/lib/error.h
==============================================================================
--- trunk/src/lib/error.h (original)
+++ trunk/src/lib/error.h Sun Oct 26 12:10:27 2008
@@ -41,4 +41,7 @@
void phc_warning (const char* message, HIR::Node*, ...);
void phc_warning (const char* message, MIR::Node*, ...);
+#define phc_unreachable() assert(0 && "Should be unreachable")
+#define phc_TODO() assert(0 && "TODO")
+
#endif // PHC_ERROR_H
More information about the phc-internals
mailing list