Merging Jake Luciani's latest perl code gen fixes

Reviewed By: dreiss

Test Plan: Watch for any weirdness on Thrift code gen, perl specific


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665206 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Slee 2007-08-16 01:26:31 +00:00
parent 1b65b724eb
commit 27ed6ec1f9
12 changed files with 113 additions and 96 deletions

View File

@ -20,10 +20,17 @@ void t_perl_generator::init_generator() {
// Make output directory
mkdir(T_PERL_DIR, S_IREAD | S_IWRITE | S_IEXEC);
string outdir(T_PERL_DIR);
std::string ns = program_->get_perl_package();
if (ns.length() > 0) {
outdir += "/" + ns;
mkdir(outdir.c_str(), S_IREAD | S_IWRITE | S_IEXEC);
}
// Make output file
string f_types_name = string(T_PERL_DIR)+"/"+program_name_+"_types.pm";
string f_types_name = outdir+"/Types.pm";
f_types_.open(f_types_name.c_str());
string f_consts_name = string(T_PERL_DIR)+"/"+program_name_+"_constants.pm";
string f_consts_name = outdir+"/Constants.pm";
f_consts_.open(f_consts_name.c_str());
// Print header
@ -458,7 +465,7 @@ void t_perl_generator::generate_service(t_service* tservice) {
perl_includes();
f_service_ <<
"use " << program_name_ << "_types;" << endl;
"use " << perl_namespace(tservice->get_program()) << "Types;" << endl;
if (tservice->get_extends() != NULL) {
f_service_ <<

View File

@ -141,8 +141,8 @@ class t_perl_generator : public t_oop_generator {
}
std::string perl_namespace(t_program* p) {
std::string ns = p->get_perl_namespace();
return ""; //ns.size() ? (ns + "::") : "";
std::string ns = p->get_perl_package();
return ns.empty() ? ns : (ns + "::");
}
private:

View File

@ -154,12 +154,12 @@ class t_program : public t_doc {
return ruby_namespace_;
}
void set_perl_namespace(std::string perl_namespace) {
perl_namespace_ = perl_namespace;
void set_perl_package(std::string perl_package) {
perl_package_ = perl_package;
}
const std::string& get_perl_namespace() const {
return perl_namespace_;
const std::string& get_perl_package() const {
return perl_package_;
}
private:
@ -206,7 +206,7 @@ class t_program : public t_doc {
std::string ruby_namespace_;
// Perl namespace
std::string perl_namespace_;
std::string perl_package_;
};

View File

@ -72,6 +72,7 @@ sliteral ("'"[^']*"'")
"cpp_type" { return tok_cpp_type; }
"java_package" { return tok_java_package; }
"php_namespace" { return tok_php_namespace; }
"perl_package" { return tok_perl_package; }
"ruby_namespace" { return tok_ruby_namespace; }
"xsd_all" { return tok_xsd_all; }
"xsd_optional" { return tok_xsd_optional; }

View File

@ -75,6 +75,7 @@ int y_field_val = -1;
%token tok_cpp_include
%token tok_cpp_type
%token tok_php_namespace
%token tok_perl_package
%token tok_java_package
%token tok_xsd_all
%token tok_xsd_optional
@ -209,8 +210,7 @@ CaptureDocText:
if (g_parse_mode == PROGRAM) {
$$ = g_doctext;
g_doctext = NULL;
}
else {
} else {
$$ = NULL;
}
}
@ -269,6 +269,13 @@ Header:
g_program->set_php_namespace($2);
}
}
| tok_perl_package tok_identifier
{
pdebug("Header -> tok_perl_namespace tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_perl_package($2);
}
}
| tok_ruby_namespace tok_identifier
{
pdebug("Header -> tok_ruby_namespace tok_identifier");

View File

@ -1,6 +1,7 @@
java_package thrift.test
cpp_namespace thrift.test
ruby_namespace Thrift.Test
perl_package ThriftTest
enum Numberz
{
@ -79,7 +80,6 @@ service ThriftTest
map<UserId, map<Numberz,Insanity>> testInsanity(1: Insanity argument),
/* Multiple parameters */
Xtruct testMulti(byte arg0, i32 arg1, i64 arg2, map<i16, string> arg3, Numberz arg4, UserId arg5),
/* Exception specifier */

View File

@ -7,7 +7,7 @@ use Data::Dumper;
use Time::HiRes qw(gettimeofday);
use lib '../../lib/perl/lib';
use lib 'gen-perl';
use lib '../gen-perl';
use Thrift;
use Thrift::BinaryProtocol;
@ -15,7 +15,7 @@ use Thrift::Socket;
use Thrift::BufferedTransport;
use ThriftTest;
use ThriftTest_types;
use ThriftTest::Types;
$|++;

View File

@ -10,7 +10,7 @@
(defconst thrift-font-lock-keywords
(list
'("#.*$" . font-lock-comment-face) ;; perl style comments
'("\\<\\(include\\|struct\\|exception\\|typedef\\|cpp_namespace\\|java_package\\|php_namespace\\|const\\|enum\\|service\\|extends\\|void\\|async\\|throws\\|optional\\|required\\)\\>" . font-lock-keyword-face) ;; keywords
'("\\<\\(include\\|struct\\|exception\\|typedef\\|cpp_namespace\\|java_package\\|php_namespace\\|ruby_namespace\\|perl_package\\|const\\|enum\\|service\\|extends\\|void\\|async\\|throws\\|optional\\|required\\)\\>" . font-lock-keyword-face) ;; keywords
'("\\<\\(bool\\|byte\\|i16\\|i32\\|i64\\|double\\|string\\|binary\\|map\\|list\\|set\\)\\>" . font-lock-type-face) ;; built-in types
'("\\<\\([0-9]+\\)\\>" . font-lock-variable-name-face) ;; ordinals
'("\\<\\(\\w+\\)\\s-*(" (1 font-lock-function-name-face)) ;; functions

View File

@ -30,7 +30,7 @@ syn region thriftStringDouble matchgroup=None start=+"+ end=+"+
syn match thriftNumber "-\=\<\d\+\>" contained
" Keywords
syn keyword thriftKeyword namespace cpp_namespace java_package php_namespace ruby_namespace
syn keyword thriftKeyword namespace cpp_namespace java_package php_namespace ruby_namespace perl_package
syn keyword thriftKeyword xsd_all xsd_optional xsd_nillable xsd_namespace xsd_attrs
syn keyword thriftKeyword include cpp_include cpp_type const optional required
syn keyword thriftBasicTypes void bool byte i16 i32 i64 double string binary

View File

@ -12,9 +12,9 @@ use Thrift::Socket;
use Thrift::BufferedTransport;
use SharedService;
use shared_types;
use Calculator;
use tutorial_types;
use shared::Types;
use tutorial::Types;
use Data::Dumper;

View File

@ -7,6 +7,7 @@
cpp_namespace shared
java_package shared
perl_package shared
struct SharedStruct {
1: i32 key

View File

@ -47,6 +47,7 @@ include "shared.thrift"
cpp_namespace tutorial
java_package tutorial
php_namespace tutorial
perl_package tutorial
/**
* Thrift lets you do typedefs to get pretty names for your types. Standard