[phc-internals] [phc commit] r1495 - trunk/src/codegen

codesite-noreply at google.com codesite-noreply at google.com
Thu Jul 31 18:46:29 IST 2008


Author: paul.biggar
Date: Thu Jul 31 10:42:34 2008
New Revision: 1495

Modified:
   trunk/src/codegen/Generate_C.cpp

Log:
The PHP source code gets printed as comments in the generated code. 
However, we did not escape the code, and printed some characters which 
were not allowed (notable the windows \r\n character).

This also removes the <?php which appeared with each line of the output.


Modified: trunk/src/codegen/Generate_C.cpp
==============================================================================
--- trunk/src/codegen/Generate_C.cpp	(original)
+++ trunk/src/codegen/Generate_C.cpp	Thu Jul 31 10:42:34 2008
@@ -1141,10 +1141,10 @@
 			<<		"\"" << escape(rhs->value->value) << "\", "
 			<<		rhs->value->value->length() << ", 1);\n";
 	}
-
+public:
  	// Escape according to C rules (this varies slightly from unparsing 
for PHP
 	// and dot).
-	string escape(String* s)
+	static string escape(String* s)
 	{
 		stringstream ss;

@@ -2323,7 +2323,7 @@
 void Generate_C::children_statement(Statement* in)
 {
 	stringstream ss;
-	MIR_unparser (ss).unparse (in);
+	MIR_unparser (ss, true).unparse (in);

 	while (not ss.eof ())
 	{
@@ -2332,7 +2332,7 @@
 	  // allowed and result in syntax errors in C. Use // instead.
 		string str;
 		getline (ss, str);
-		code << "// " << str << endl;
+		code << "// " << Pattern_assign_string::escape (s(str)) << endl;
 	}

 	Pattern* patterns[] =


More information about the phc-internals mailing list