mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
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:
parent
1b65b724eb
commit
27ed6ec1f9
@ -20,10 +20,17 @@ void t_perl_generator::init_generator() {
|
|||||||
// Make output directory
|
// Make output directory
|
||||||
mkdir(T_PERL_DIR, S_IREAD | S_IWRITE | S_IEXEC);
|
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
|
// 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());
|
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());
|
f_consts_.open(f_consts_name.c_str());
|
||||||
|
|
||||||
// Print header
|
// Print header
|
||||||
@ -458,7 +465,7 @@ void t_perl_generator::generate_service(t_service* tservice) {
|
|||||||
perl_includes();
|
perl_includes();
|
||||||
|
|
||||||
f_service_ <<
|
f_service_ <<
|
||||||
"use " << program_name_ << "_types;" << endl;
|
"use " << perl_namespace(tservice->get_program()) << "Types;" << endl;
|
||||||
|
|
||||||
if (tservice->get_extends() != NULL) {
|
if (tservice->get_extends() != NULL) {
|
||||||
f_service_ <<
|
f_service_ <<
|
||||||
|
@ -141,8 +141,8 @@ class t_perl_generator : public t_oop_generator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string perl_namespace(t_program* p) {
|
std::string perl_namespace(t_program* p) {
|
||||||
std::string ns = p->get_perl_namespace();
|
std::string ns = p->get_perl_package();
|
||||||
return ""; //ns.size() ? (ns + "::") : "";
|
return ns.empty() ? ns : (ns + "::");
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -154,12 +154,12 @@ class t_program : public t_doc {
|
|||||||
return ruby_namespace_;
|
return ruby_namespace_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_perl_namespace(std::string perl_namespace) {
|
void set_perl_package(std::string perl_package) {
|
||||||
perl_namespace_ = perl_namespace;
|
perl_package_ = perl_package;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& get_perl_namespace() const {
|
const std::string& get_perl_package() const {
|
||||||
return perl_namespace_;
|
return perl_package_;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -206,7 +206,7 @@ class t_program : public t_doc {
|
|||||||
std::string ruby_namespace_;
|
std::string ruby_namespace_;
|
||||||
|
|
||||||
// Perl namespace
|
// Perl namespace
|
||||||
std::string perl_namespace_;
|
std::string perl_package_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ sliteral ("'"[^']*"'")
|
|||||||
"cpp_type" { return tok_cpp_type; }
|
"cpp_type" { return tok_cpp_type; }
|
||||||
"java_package" { return tok_java_package; }
|
"java_package" { return tok_java_package; }
|
||||||
"php_namespace" { return tok_php_namespace; }
|
"php_namespace" { return tok_php_namespace; }
|
||||||
|
"perl_package" { return tok_perl_package; }
|
||||||
"ruby_namespace" { return tok_ruby_namespace; }
|
"ruby_namespace" { return tok_ruby_namespace; }
|
||||||
"xsd_all" { return tok_xsd_all; }
|
"xsd_all" { return tok_xsd_all; }
|
||||||
"xsd_optional" { return tok_xsd_optional; }
|
"xsd_optional" { return tok_xsd_optional; }
|
||||||
|
@ -75,6 +75,7 @@ int y_field_val = -1;
|
|||||||
%token tok_cpp_include
|
%token tok_cpp_include
|
||||||
%token tok_cpp_type
|
%token tok_cpp_type
|
||||||
%token tok_php_namespace
|
%token tok_php_namespace
|
||||||
|
%token tok_perl_package
|
||||||
%token tok_java_package
|
%token tok_java_package
|
||||||
%token tok_xsd_all
|
%token tok_xsd_all
|
||||||
%token tok_xsd_optional
|
%token tok_xsd_optional
|
||||||
@ -209,8 +210,7 @@ CaptureDocText:
|
|||||||
if (g_parse_mode == PROGRAM) {
|
if (g_parse_mode == PROGRAM) {
|
||||||
$$ = g_doctext;
|
$$ = g_doctext;
|
||||||
g_doctext = NULL;
|
g_doctext = NULL;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$$ = NULL;
|
$$ = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -269,6 +269,13 @@ Header:
|
|||||||
g_program->set_php_namespace($2);
|
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
|
| tok_ruby_namespace tok_identifier
|
||||||
{
|
{
|
||||||
pdebug("Header -> tok_ruby_namespace tok_identifier");
|
pdebug("Header -> tok_ruby_namespace tok_identifier");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
java_package thrift.test
|
java_package thrift.test
|
||||||
cpp_namespace thrift.test
|
cpp_namespace thrift.test
|
||||||
ruby_namespace Thrift.Test
|
ruby_namespace Thrift.Test
|
||||||
|
perl_package ThriftTest
|
||||||
|
|
||||||
enum Numberz
|
enum Numberz
|
||||||
{
|
{
|
||||||
@ -79,7 +80,6 @@ service ThriftTest
|
|||||||
map<UserId, map<Numberz,Insanity>> testInsanity(1: Insanity argument),
|
map<UserId, map<Numberz,Insanity>> testInsanity(1: Insanity argument),
|
||||||
|
|
||||||
/* Multiple parameters */
|
/* Multiple parameters */
|
||||||
|
|
||||||
Xtruct testMulti(byte arg0, i32 arg1, i64 arg2, map<i16, string> arg3, Numberz arg4, UserId arg5),
|
Xtruct testMulti(byte arg0, i32 arg1, i64 arg2, map<i16, string> arg3, Numberz arg4, UserId arg5),
|
||||||
|
|
||||||
/* Exception specifier */
|
/* Exception specifier */
|
||||||
|
@ -7,7 +7,7 @@ use Data::Dumper;
|
|||||||
use Time::HiRes qw(gettimeofday);
|
use Time::HiRes qw(gettimeofday);
|
||||||
|
|
||||||
use lib '../../lib/perl/lib';
|
use lib '../../lib/perl/lib';
|
||||||
use lib 'gen-perl';
|
use lib '../gen-perl';
|
||||||
|
|
||||||
use Thrift;
|
use Thrift;
|
||||||
use Thrift::BinaryProtocol;
|
use Thrift::BinaryProtocol;
|
||||||
@ -15,7 +15,7 @@ use Thrift::Socket;
|
|||||||
use Thrift::BufferedTransport;
|
use Thrift::BufferedTransport;
|
||||||
|
|
||||||
use ThriftTest;
|
use ThriftTest;
|
||||||
use ThriftTest_types;
|
use ThriftTest::Types;
|
||||||
|
|
||||||
$|++;
|
$|++;
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
(defconst thrift-font-lock-keywords
|
(defconst thrift-font-lock-keywords
|
||||||
(list
|
(list
|
||||||
'("#.*$" . font-lock-comment-face) ;; perl style comments
|
'("#.*$" . 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
|
'("\\<\\(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
|
'("\\<\\([0-9]+\\)\\>" . font-lock-variable-name-face) ;; ordinals
|
||||||
'("\\<\\(\\w+\\)\\s-*(" (1 font-lock-function-name-face)) ;; functions
|
'("\\<\\(\\w+\\)\\s-*(" (1 font-lock-function-name-face)) ;; functions
|
||||||
|
@ -30,7 +30,7 @@ syn region thriftStringDouble matchgroup=None start=+"+ end=+"+
|
|||||||
syn match thriftNumber "-\=\<\d\+\>" contained
|
syn match thriftNumber "-\=\<\d\+\>" contained
|
||||||
|
|
||||||
" Keywords
|
" 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 xsd_all xsd_optional xsd_nillable xsd_namespace xsd_attrs
|
||||||
syn keyword thriftKeyword include cpp_include cpp_type const optional required
|
syn keyword thriftKeyword include cpp_include cpp_type const optional required
|
||||||
syn keyword thriftBasicTypes void bool byte i16 i32 i64 double string binary
|
syn keyword thriftBasicTypes void bool byte i16 i32 i64 double string binary
|
||||||
|
@ -12,9 +12,9 @@ use Thrift::Socket;
|
|||||||
use Thrift::BufferedTransport;
|
use Thrift::BufferedTransport;
|
||||||
|
|
||||||
use SharedService;
|
use SharedService;
|
||||||
use shared_types;
|
|
||||||
use Calculator;
|
use Calculator;
|
||||||
use tutorial_types;
|
use shared::Types;
|
||||||
|
use tutorial::Types;
|
||||||
|
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
cpp_namespace shared
|
cpp_namespace shared
|
||||||
java_package shared
|
java_package shared
|
||||||
|
perl_package shared
|
||||||
|
|
||||||
struct SharedStruct {
|
struct SharedStruct {
|
||||||
1: i32 key
|
1: i32 key
|
||||||
|
@ -47,6 +47,7 @@ include "shared.thrift"
|
|||||||
cpp_namespace tutorial
|
cpp_namespace tutorial
|
||||||
java_package tutorial
|
java_package tutorial
|
||||||
php_namespace tutorial
|
php_namespace tutorial
|
||||||
|
perl_package tutorial
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrift lets you do typedefs to get pretty names for your types. Standard
|
* Thrift lets you do typedefs to get pretty names for your types. Standard
|
||||||
|
Loading…
Reference in New Issue
Block a user