[phc-internals] [phc commit] r1787 - in trunk/src: codegen lib process_ir

codesite-noreply at google.com codesite-noreply at google.com
Tue Oct 14 23:51:41 IST 2008


Author: paul.biggar
Date: Tue Oct 14 15:50:15 2008
New Revision: 1787

Modified:
    trunk/src/codegen/Compile_C.cpp
    trunk/src/lib/AttrMap.cpp
    trunk/src/lib/AttrMap.h
    trunk/src/lib/List.h
    trunk/src/lib/Object.h
    trunk/src/lib/String.cpp
    trunk/src/lib/String.h
    trunk/src/process_ir/General.cpp
    trunk/src/process_ir/General.h
    trunk/src/process_ir/XML_unparser.h

Log:
Remove 'using namepsace std' from all header files, except those in the  
generated/ directory. That will come next.

This allows us to be clearer where std:: containers, such as maps, stacks  
etc are used.

Update GC plan. Ironically, it now looks like I'll use Map instead of  
phc::map (etc), so the above is not really needed (but it was ugly, and so  
good to remove).


Modified: trunk/src/codegen/Compile_C.cpp
==============================================================================
--- trunk/src/codegen/Compile_C.cpp	(original)
+++ trunk/src/codegen/Compile_C.cpp	Tue Oct 14 15:50:15 2008
@@ -20,6 +20,8 @@
  #include "pass_manager/Pass_manager.h"
  #include <lib/error.h>

+using namespace std;
+
  Compile_C::Compile_C (stringstream& os)
  : os(os)
  {

Modified: trunk/src/lib/AttrMap.cpp
==============================================================================
--- trunk/src/lib/AttrMap.cpp	(original)
+++ trunk/src/lib/AttrMap.cpp	Tue Oct 14 15:50:15 2008
@@ -10,6 +10,8 @@
  #include "Boolean.h"
  #include "Integer.h"

+using namespace std;
+
  AttrMap::AttrMap() : map<string, Object*>()
  {
  }

Modified: trunk/src/lib/AttrMap.h
==============================================================================
--- trunk/src/lib/AttrMap.h	(original)
+++ trunk/src/lib/AttrMap.h	Tue Oct 14 15:50:15 2008
@@ -8,18 +8,16 @@
  #ifndef PHC_ATTR_MAP_H
  #define PHC_ATTR_MAP_H

-using namespace std;
-
  #include <map>
-#include <string>

+#include "lib/String.h"
  #include "lib/Object.h"

  class String;
  class Integer;
  class Boolean;

-class AttrMap : public map<string, Object*>, virtual public Object
+class AttrMap : public std::map<string, Object*>, virtual public Object
  {
  public:
  	AttrMap();

Modified: trunk/src/lib/List.h
==============================================================================
--- trunk/src/lib/List.h	(original)
+++ trunk/src/lib/List.h	Tue Oct 14 15:50:15 2008
@@ -12,32 +12,30 @@
  #include "lib/Object.h"
  #include "process_ir/Foreach.h"

-using namespace std;
-
-template<typename _Tp, typename _Alloc = allocator<_Tp> >
-class List : public list<_Tp, _Alloc>, virtual public Object
+template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
+class List : public std::list<_Tp, _Alloc>, virtual public Object
  {
  public:
-	using list<_Tp, _Alloc>::push_back;
+	using std::list<_Tp, _Alloc>::push_back;

  public:
-	List() : list<_Tp, _Alloc>() {}
+	List() : std::list<_Tp, _Alloc>() {}
  	virtual ~List() {}

  // Create a list with one, two or three elements
  public:
-	List(_Tp elem1) : list<_Tp, _Alloc>()
+	List(_Tp elem1) : std::list<_Tp, _Alloc>()
  	{
  		push_back(elem1);
  	}

-	List(_Tp elem1, _Tp elem2) : list<_Tp, _Alloc>()
+	List(_Tp elem1, _Tp elem2) : std::list<_Tp, _Alloc>()
  	{
  		push_back(elem1);
  		push_back(elem2);
  	}

-	List(_Tp elem1, _Tp elem2, _Tp elem3) : list<_Tp, _Alloc>()
+	List(_Tp elem1, _Tp elem2, _Tp elem3) : std::list<_Tp, _Alloc>()
  	{
  		push_back(elem1);
  		push_back(elem2);
@@ -45,8 +43,8 @@
  	}

  public:
-	using list<_Tp, _Alloc>::begin;
-	using list<_Tp, _Alloc>::end;
+	using std::list<_Tp, _Alloc>::begin;
+	using std::list<_Tp, _Alloc>::end;

  	void push_back_all(List* other)
  	{

Modified: trunk/src/lib/Object.h
==============================================================================
--- trunk/src/lib/Object.h	(original)
+++ trunk/src/lib/Object.h	Tue Oct 14 15:50:15 2008
@@ -34,29 +34,38 @@
   *	leading to segfaults. (Note: object on the stack are NOt excepted).
   *
   *	1. _ALL_ (let me repeat, ALL) classes which we define need to inherit  
from GC_Obj.
- *	2. Never use STL objects without wrapping them. The naming scheme is as  
follows:
- *		- phc::map is identical to std::map, except that it uses it uses the  
GC allocator.
- *		- phc::Map is a phc::map with extra interface components such as the  
clone() method.
- *	3. When using embedded PHP, do garbage collection manually. If garbage
+ *	2. Its OK to use string or stringstream on the stack, since they dont
+ *		contain other objects, they get cleared up on going out of scope, and  
they
+ *		appear everywhere.
+ *		TODO: do we clear up the result of stringstream::str()
+ *	3. Never use STL objects without wrapping them. For example:
+ *		-	Create Map to wrap std::map, either using gc_allocator as the
+ *			allocator, or inheriting from Object. It _should_ inherit from Object  
and
+ *			support the clone() method, but that may not yet be implemented. If  
it is
+ *			not, it inherits from GC_obj instead.
+ *	4. When using embedded PHP, do garbage collection manually. If garbage
   *		collected objects need to be put in PHP structures (which they  
currently
   *		dont), then the memory must be allocated using libgc's traceable
   *		allocators, which traces, but doesn't deallocate memory.
- *	4. For exceptional objects allocated with new, use the placement new  
form:
+ *	5. For exceptional objects allocated with new, use the placement new  
form:
   *			int* a = new (GC) int;
   *		If they need to be traceable but not collectable, use the other  
placement new form:
   *			int* a = new (NoGC) int;
- *	5. Object which dont contain other objects and are allocated on the  
stack
- *		are OK: ie string, stringstream.
   *
   *
   * TODO: it may be necessary to include libgc within phc to ensure that it  
is
   * compiled correctly for our use.
+ *
+ * TODO: should libgc be mandatory (fail to compile without it)? it exists  
on all platforms...
+ *
+ * TODO: what does libgccpp do for us? It doesnt fix the bugs by magic...
   */



  #ifdef USE_GC
  #include "gc/gc_cpp.h"
+#include "gc/gc_allocator.h"
  class GC_Obj : public gc
  #else
  class GC_Obj

Modified: trunk/src/lib/String.cpp
==============================================================================
--- trunk/src/lib/String.cpp	(original)
+++ trunk/src/lib/String.cpp	Tue Oct 14 15:50:15 2008
@@ -7,7 +7,9 @@

  #include <algorithm>
  #include "String.h"
-#include "AttrMap.h"
+#include "AttrMap.h"
+
+using std::string;

  String::String()
  {
@@ -68,4 +70,9 @@
  void String::toLower ()
  {
  	transform (begin(), end(), begin (), phc_tolower);
+}
+
+String* s (const string& str)
+{
+	return new String (str);
  }

Modified: trunk/src/lib/String.h
==============================================================================
--- trunk/src/lib/String.h	(original)
+++ trunk/src/lib/String.h	Tue Oct 14 15:50:15 2008
@@ -12,9 +12,11 @@
  #include "lib/Object.h"
  #include "lib/List.h"

-class AttrMap;
+// We use these everywhere, so allow them to be used without std::.
+using std::string;
+using std::stringstream;

-using namespace std;
+class AttrMap;

  class String : public string, virtual public Object
  {
@@ -38,6 +40,9 @@
  	void toLower();
  	String* clone();
  };
+
+// 'new String' must be the most typed function in phc
+String* s (const string& s);

  typedef List<String*> String_list;


Modified: trunk/src/process_ir/General.cpp
==============================================================================
--- trunk/src/process_ir/General.cpp	(original)
+++ trunk/src/process_ir/General.cpp	Tue Oct 14 15:50:15 2008
@@ -7,7 +7,4 @@

  #include "process_ir/General.h"

-String* s (string str)
-{
-	return new String (str);
-}
+

Modified: trunk/src/process_ir/General.h
==============================================================================
--- trunk/src/process_ir/General.h	(original)
+++ trunk/src/process_ir/General.h	Tue Oct 14 15:50:15 2008
@@ -10,8 +10,6 @@

  #include "lib/String.h"

-// 'new String' must be the most typed function in phc
-String* s (string s);

  #include "debug.h"
  #include "Foreach.h"
@@ -20,6 +18,5 @@
  #include "boost/lexical_cast.hpp"

  using boost::lexical_cast;
-using std::string;

  #endif // PHC_GENERAL

Modified: trunk/src/process_ir/XML_unparser.h
==============================================================================
--- trunk/src/process_ir/XML_unparser.h	(original)
+++ trunk/src/process_ir/XML_unparser.h	Tue Oct 14 15:50:15 2008
@@ -15,12 +15,12 @@
  class XML_unparser_state
  {
  public:
-	ostream& os;
+	std::ostream& os;
  	bool print_attrs;
  	int indent;

  public:
-	XML_unparser_state (ostream& os, bool print_attrs);
+	XML_unparser_state (std::ostream& os, bool print_attrs);
  	void print_indent();
  };

@@ -28,10 +28,10 @@
  void xml_unparse (HIR::Node*, XML_unparser_state* state);
  void xml_unparse (MIR::Node*, XML_unparser_state* state);
  void xml_unparse (IR::Node*, XML_unparser_state* state);
-void xml_unparse (AST::Node*, ostream& os = cout, bool print_attrs = true);
-void xml_unparse (HIR::Node*, ostream& os = cout, bool print_attrs = true);
-void xml_unparse (MIR::Node*, ostream& os = cout, bool print_attrs = true);
-void xml_unparse (IR::PHP_script*, ostream& os = cout, bool print_attrs =  
true);
+void xml_unparse (AST::Node*, std::ostream& os = std::cout, bool  
print_attrs = true);
+void xml_unparse (HIR::Node*, std::ostream& os = std::cout, bool  
print_attrs = true);
+void xml_unparse (MIR::Node*, std::ostream& os = std::cout, bool  
print_attrs = true);
+void xml_unparse (IR::PHP_script*, std::ostream& os = std::cout, bool  
print_attrs = true);


  #endif // PHC_XML_UNPARSER


More information about the phc-internals mailing list