[jira] [Commented] (THRIFT-1241) php namespace generation

2011-07-20 Thread Darius Staisiunas (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-1241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13068823#comment-13068823
 ] 

Darius Staisiunas commented on THRIFT-1241:
---

Changed according to your comments - now to generate php files with namespaces:
thrift --gen php:namespace example.thrift

> php namespace generation
> 
>
> Key: THRIFT-1241
> URL: https://issues.apache.org/jira/browse/THRIFT-1241
> Project: Thrift
>  Issue Type: Improvement
>  Components: PHP - Compiler
>Affects Versions: 0.7
> Environment: PHP 5.3
>Reporter: Darius Staisiunas
>  Labels: patch
> Fix For: 0.7
>
> Attachments: php_namespace_0.7.0.patch
>
>
> Patch is based mainly on https://issues.apache.org/jira/browse/THRIFT-777, 
> but some more improvements:
> namespace can be specified with dots '.' like for every other language
> for example:
> namespace php com.onego.thrift
> would generate in php file
> namespace com\onego\thrift
> to generate php files with namespaces use:
> thrift --gen php:namespace53 example.thrift

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira




[jira] [Updated] (THRIFT-1241) php namespace generation

2011-07-20 Thread Darius Staisiunas (JIRA)

 [ 
https://issues.apache.org/jira/browse/THRIFT-1241?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Darius Staisiunas updated THRIFT-1241:
--

Attachment: php_namespace_0.7.0.patch

enables namespace php support

> php namespace generation
> 
>
> Key: THRIFT-1241
> URL: https://issues.apache.org/jira/browse/THRIFT-1241
> Project: Thrift
>  Issue Type: Improvement
>  Components: PHP - Compiler
>Affects Versions: 0.7
> Environment: PHP 5.3
>Reporter: Darius Staisiunas
>  Labels: patch
> Fix For: 0.7
>
> Attachments: php_namespace_0.7.0.patch
>
>
> Patch is based mainly on https://issues.apache.org/jira/browse/THRIFT-777, 
> but some more improvements:
> namespace can be specified with dots '.' like for every other language
> for example:
> namespace php com.onego.thrift
> would generate in php file
> namespace com\onego\thrift
> to generate php files with namespaces use:
> thrift --gen php:namespace53 example.thrift

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira




[jira] [Updated] (THRIFT-1241) php namespace generation

2011-07-20 Thread Darius Staisiunas (JIRA)

 [ 
https://issues.apache.org/jira/browse/THRIFT-1241?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Darius Staisiunas updated THRIFT-1241:
--

Comment: was deleted

(was: --- compiler/cpp/src/generate/t_php_generator.cc.orig 2011-06-23 
12:28:07.0 +0300
+++ compiler/cpp/src/generate/t_php_generator.cc2011-07-20 
18:09:05.403366001 +0300
@@ -29,6 +29,12 @@
 #include "platform.h"
 using namespace std;
 
+#define NSGLOBAL  (nsglobal_.size() ? nsglobal_ : "")
+#define NSGLOBAL_A ("\\" + NSGLOBAL )
+#define NSGLOBAL_B ( NSGLOBAL + "\\")
+#define NSGLOBAL_AB ("\\" + NSGLOBAL + "\\")
+#define NS_ROOT ( namespace53_ ? "\\" : "")
+
 
 /**
  * PHP code generator.
@@ -60,6 +66,18 @@
 iter = parsed_options.find("oop");
 oop_ = (iter != parsed_options.end());
 
+iter = parsed_options.find("namespace53");
+namespace53_ = (iter != parsed_options.end());
+
+iter = parsed_options.find("nsglobal");
+if(iter != parsed_options.end()) {
+  if(namespace53_) nsglobal_ = iter->second;
+  else throw "cannot use nsglobal without namespace53.";
+}
+else {
+  nsglobal_ = ""; // by default global namespace is empty
+}
+
 if (oop_ && binary_inline_) {
   throw "oop and inlined are mutually exclusive.";
 }
@@ -183,7 +201,24 @@
 
   std::string php_namespace(t_program* p) {
 std::string ns = p->get_namespace("php");
-return ns.size() ? (ns + "_") : "";
+size_t position = ns.find( "." );
+while (position != string::npos) {
+  ns.replace(position, 1, "\\");
+  position = ns.find(".", position+1);
+}
+if(namespace53_) return (nsglobal_.size() ? NSGLOBAL_AB : NSGLOBAL_B) + 
(ns.size() ? (ns + "\\") : "");
+else return "";
+  }
+
+  std::string php_namespace_suffix(const t_program* p) {
+std::string ns = p->get_namespace("php");
+size_t position = ns.find( "." );
+while (position != string::npos) {
+  ns.replace(position, 1, "\\");
+  position = ns.find(".", position+1);
+}
+if (namespace53_) return (nsglobal_.size() ? NSGLOBAL_B : NSGLOBAL) + ns;
+else return "";
   }
 
   std::string php_path(t_program* p) {
@@ -199,7 +234,7 @@
   }
 }
 
-return ns + '/' + p->get_name();
+return ((namespace53_) ? ns + '/' : "" ) + p->get_name();
   }
 
  private:
@@ -237,7 +272,16 @@
* Whether to use OOP base class TBase
*/
   bool oop_;
-
+  
+  /**
+   * Generate namespaces in PHP5.3 style
+   */
+  bool namespace53_;
+ 
+  /**
+   * Global namespace for PHP 5.3
+   */
+  std::string nsglobal_;
 };
 
 
@@ -263,9 +307,9 @@
 
   // Print header
   f_types_ <<
-"& includes = program_->get_includes();
@@ -282,8 +326,9 @@
 string f_consts_name = package_dir_+program_name_+"_constants.php";
 f_consts_.open(f_consts_name.c_str());
 f_consts_ <<
-  "get_program()) << tenum->get_name() 
<< " {" << endl;
+"final class " << tenum->get_name() << " {" << endl;
   indent_up();
 
   for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
@@ -420,7 +465,7 @@
   } else if (type->is_enum()) {
 indent(out) << value->get_integer();
   } else if (type->is_struct() || type->is_xception()) {
-out << "new " << php_namespace(type->get_program()) << type->get_name() << 
"(array(" << endl;
+out << "new " << NS_ROOT << php_namespace(type->get_program()) << 
type->get_name() << "(array(" << endl;
 indent_up();
 const vector& fields = ((t_struct*)type)->get_members();
 vector::const_iterator f_iter;
@@ -513,7 +558,7 @@
 void t_php_generator::generate_php_type_spec(ofstream& out,
  t_type* t) {
   t = get_true_type(t);
-  indent(out) << "'type' => " << type_to_enum(t) << "," << endl;
+  indent(out) << "'type' => " << NS_ROOT << type_to_enum(t) << "," << endl;
 
   if (t->is_base_type() || t->is_enum()) {
 // Noop, type is all we need
@@ -522,8 +567,8 @@
   } else if (t->is_map()) {
 t_type* ktype = get_true_type(((t_map*)t)->get_key_type());
 t_type* vtype = get_true_type(((t_map*)t)->get_val_type());
-indent(out) << "'ktype' => " << type_to_enum(ktype) << "," << endl;
-indent(out) << "'vtype' => " << type_to_enum(vtype) << "," << endl;
+indent(out) << "'ktype' => " << NS_ROOT << type_to_enum(ktype) << "," << 
endl;
+indent(out) << "'vtype' => " << NS_ROOT << type_to_enum(vtype) << "," << 
endl;
 indent(out) << "'key' => array(" << endl;
 indent_up();
 generate_php_type_spec(out, ktype);
@@ -541,7 +586,7 @@
 } else {
   etype = get_true_type(((t_set*)t)->get_elem_type());
 }
-indent(out) << "'etype' => " << type_to_enum(etype) <<"," << endl;
+indent(out) << "'etype' => " << NS_ROOT << type_to_enum(etype) <<"," << 
endl;
 indent(out) << "'elem' => array(" << endl;
 indent_up();
 generate_php_type_spec(out, etype);
@@ -621,11 +666,11 @@
   vector::const_iterator m_iter;

[jira] [Commented] (THRIFT-1241) php namespace generation

2011-07-20 Thread Jake Farrell (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-1241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13068451#comment-13068451
 ] 

Jake Farrell commented on THRIFT-1241:
--

Thanks Darius, initial work looks great. Will want to change from namespace53 
to just namespace since php5.3+ will have this option available and php5.4 is 
in rc right now so no sense in defining a specific version in the option. Can 
you attach this as a patch with asf inclusion please.

> php namespace generation
> 
>
> Key: THRIFT-1241
> URL: https://issues.apache.org/jira/browse/THRIFT-1241
> Project: Thrift
>  Issue Type: Improvement
>  Components: PHP - Compiler
>Affects Versions: 0.7
> Environment: PHP 5.3
>Reporter: Darius Staisiunas
>  Labels: patch
> Fix For: 0.7
>
>
> Patch is based mainly on https://issues.apache.org/jira/browse/THRIFT-777, 
> but some more improvements:
> namespace can be specified with dots '.' like for every other language
> for example:
> namespace php com.onego.thrift
> would generate in php file
> namespace com\onego\thrift
> to generate php files with namespaces use:
> thrift --gen php:namespace53 example.thrift

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira




[jira] [Commented] (THRIFT-1241) php namespace generation

2011-07-20 Thread Darius Staisiunas (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-1241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13068435#comment-13068435
 ] 

Darius Staisiunas commented on THRIFT-1241:
---

--- compiler/cpp/src/generate/t_php_generator.cc.orig   2011-06-23 
12:28:07.0 +0300
+++ compiler/cpp/src/generate/t_php_generator.cc2011-07-20 
18:09:05.403366001 +0300
@@ -29,6 +29,12 @@
 #include "platform.h"
 using namespace std;
 
+#define NSGLOBAL  (nsglobal_.size() ? nsglobal_ : "")
+#define NSGLOBAL_A ("\\" + NSGLOBAL )
+#define NSGLOBAL_B ( NSGLOBAL + "\\")
+#define NSGLOBAL_AB ("\\" + NSGLOBAL + "\\")
+#define NS_ROOT ( namespace53_ ? "\\" : "")
+
 
 /**
  * PHP code generator.
@@ -60,6 +66,18 @@
 iter = parsed_options.find("oop");
 oop_ = (iter != parsed_options.end());
 
+iter = parsed_options.find("namespace53");
+namespace53_ = (iter != parsed_options.end());
+
+iter = parsed_options.find("nsglobal");
+if(iter != parsed_options.end()) {
+  if(namespace53_) nsglobal_ = iter->second;
+  else throw "cannot use nsglobal without namespace53.";
+}
+else {
+  nsglobal_ = ""; // by default global namespace is empty
+}
+
 if (oop_ && binary_inline_) {
   throw "oop and inlined are mutually exclusive.";
 }
@@ -183,7 +201,24 @@
 
   std::string php_namespace(t_program* p) {
 std::string ns = p->get_namespace("php");
-return ns.size() ? (ns + "_") : "";
+size_t position = ns.find( "." );
+while (position != string::npos) {
+  ns.replace(position, 1, "\\");
+  position = ns.find(".", position+1);
+}
+if(namespace53_) return (nsglobal_.size() ? NSGLOBAL_AB : NSGLOBAL_B) + 
(ns.size() ? (ns + "\\") : "");
+else return "";
+  }
+
+  std::string php_namespace_suffix(const t_program* p) {
+std::string ns = p->get_namespace("php");
+size_t position = ns.find( "." );
+while (position != string::npos) {
+  ns.replace(position, 1, "\\");
+  position = ns.find(".", position+1);
+}
+if (namespace53_) return (nsglobal_.size() ? NSGLOBAL_B : NSGLOBAL) + ns;
+else return "";
   }
 
   std::string php_path(t_program* p) {
@@ -199,7 +234,7 @@
   }
 }
 
-return ns + '/' + p->get_name();
+return ((namespace53_) ? ns + '/' : "" ) + p->get_name();
   }
 
  private:
@@ -237,7 +272,16 @@
* Whether to use OOP base class TBase
*/
   bool oop_;
-
+  
+  /**
+   * Generate namespaces in PHP5.3 style
+   */
+  bool namespace53_;
+ 
+  /**
+   * Global namespace for PHP 5.3
+   */
+  std::string nsglobal_;
 };
 
 
@@ -263,9 +307,9 @@
 
   // Print header
   f_types_ <<
-"& includes = program_->get_includes();
@@ -282,8 +326,9 @@
 string f_consts_name = package_dir_+program_name_+"_constants.php";
 f_consts_.open(f_consts_name.c_str());
 f_consts_ <<
-  "get_program()) << tenum->get_name() 
<< " {" << endl;
+"final class " << tenum->get_name() << " {" << endl;
   indent_up();
 
   for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
@@ -420,7 +465,7 @@
   } else if (type->is_enum()) {
 indent(out) << value->get_integer();
   } else if (type->is_struct() || type->is_xception()) {
-out << "new " << php_namespace(type->get_program()) << type->get_name() << 
"(array(" << endl;
+out << "new " << NS_ROOT << php_namespace(type->get_program()) << 
type->get_name() << "(array(" << endl;
 indent_up();
 const vector& fields = ((t_struct*)type)->get_members();
 vector::const_iterator f_iter;
@@ -513,7 +558,7 @@
 void t_php_generator::generate_php_type_spec(ofstream& out,
  t_type* t) {
   t = get_true_type(t);
-  indent(out) << "'type' => " << type_to_enum(t) << "," << endl;
+  indent(out) << "'type' => " << NS_ROOT << type_to_enum(t) << "," << endl;
 
   if (t->is_base_type() || t->is_enum()) {
 // Noop, type is all we need
@@ -522,8 +567,8 @@
   } else if (t->is_map()) {
 t_type* ktype = get_true_type(((t_map*)t)->get_key_type());
 t_type* vtype = get_true_type(((t_map*)t)->get_val_type());
-indent(out) << "'ktype' => " << type_to_enum(ktype) << "," << endl;
-indent(out) << "'vtype' => " << type_to_enum(vtype) << "," << endl;
+indent(out) << "'ktype' => " << NS_ROOT << type_to_enum(ktype) << "," << 
endl;
+indent(out) << "'vtype' => " << NS_ROOT << type_to_enum(vtype) << "," << 
endl;
 indent(out) << "'key' => array(" << endl;
 indent_up();
 generate_php_type_spec(out, ktype);
@@ -541,7 +586,7 @@
 } else {
   etype = get_true_type(((t_set*)t)->get_elem_type());
 }
-indent(out) << "'etype' => " << type_to_enum(etype) <<"," << endl;
+indent(out) << "'etype' => " << NS_ROOT << type_to_enum(etype) <<"," << 
endl;
 indent(out) << "'elem' => array(" << endl;
 indent_up();
 generate_php_type_spec(out, etype);
@@ -621,11 +666,11 @@
   vector::

[jira] [Created] (THRIFT-1241) php namespace generation

2011-07-20 Thread Darius Staisiunas (JIRA)
php namespace generation


 Key: THRIFT-1241
 URL: https://issues.apache.org/jira/browse/THRIFT-1241
 Project: Thrift
  Issue Type: Improvement
  Components: PHP - Compiler
Affects Versions: 0.7
 Environment: PHP 5.3
Reporter: Darius Staisiunas
 Fix For: 0.7


Patch is based mainly on https://issues.apache.org/jira/browse/THRIFT-777, but 
some more improvements:
namespace can be specified with dots '.' like for every other language
for example:
namespace php com.onego.thrift
would generate in php file
namespace com\onego\thrift

to generate php files with namespaces use:
thrift --gen php:namespace53 example.thrift

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira




[jira] [Updated] (THRIFT-1233) Remove unused include in generated C++ code

2011-07-20 Thread alexandre parenteau (JIRA)

 [ 
https://issues.apache.org/jira/browse/THRIFT-1233?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

alexandre parenteau updated THRIFT-1233:


Attachment: thrift-1233.2.tgz

@Diwaker: certainly! Find enclosed a description of the problem, the .thrift 
file, the generated file, and the new proposed patch

> Remove unused include in generated C++ code
> ---
>
> Key: THRIFT-1233
> URL: https://issues.apache.org/jira/browse/THRIFT-1233
> Project: Thrift
>  Issue Type: Improvement
>  Components: C++ - Compiler
> Environment: Ubuntu 11.04, latest trunk.
>Reporter: Diwaker Gupta
>Assignee: Jake Farrell
>Priority: Trivial
> Fix For: 0.7
>
> Attachments: THRIFT-1233.patch, thrift-1233.2.tgz
>
>
> When using cob_style with the CPP generator, the compiler adds an include for 
> TTransportUtils. This include doesn't seem to be used anywhere and creates an 
> unnecessary dependency. It also complicates compiling Thrift generated code 
> on other platforms.
> Patch available for review here:
> https://reviews.apache.org/r/1034/

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira