1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
#ifndef GOOGLE_PROTOBUF_COMPILER_PERLXS_GENERATOR_H__
#define GOOGLE_PROTOBUF_COMPILER_PERLXS_GENERATOR_H__
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/cpp/cpp_helpers.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/strutil.h>
namespace google {
namespace protobuf {
class Descriptor;
class EnumDescriptor;
class EnumValueDescriptor;
class FieldDescriptor;
class ServiceDescriptor;
namespace io { class Printer; }
namespace compiler {
namespace perlxs {
// CodeGenerator implementation for generated Perl/XS protocol buffer
// classes. If you create your own protocol compiler binary and you
// want it to support Perl/XS output, you can do so by registering an
// instance of this CodeGenerator with the CommandLineInterface in
// your main() function.
class LIBPROTOC_EXPORT PerlXSGenerator : public CodeGenerator {
public:
PerlXSGenerator();
virtual ~PerlXSGenerator();
// implements CodeGenerator ----------------------------------------
virtual bool Generate(const FileDescriptor* file,
const TProtoStringType& parameter,
OutputDirectory* output_directory,
TProtoStringType* error) const;
bool ProcessOption(const TProtoStringType& option);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PerlXSGenerator);
private:
void GenerateXS(const FileDescriptor* file,
OutputDirectory* output_directory,
TProtoStringType& base) const;
void GenerateMessageXS(const Descriptor* descriptor,
OutputDirectory* outdir) const;
void GenerateMessageModule(const Descriptor* descriptor,
OutputDirectory* outdir) const;
void GenerateMessagePOD(const Descriptor* descriptor,
OutputDirectory* outdir) const;
void GenerateDescriptorClassNamePOD(const Descriptor* descriptor,
io::Printer& printer) const;
void GenerateDescriptorMethodPOD(const Descriptor* descriptor,
io::Printer& printer) const;
void GenerateEnumModule(const EnumDescriptor* enum_descriptor,
OutputDirectory* outdir) const;
void GenerateMessageXSFieldAccessors(const FieldDescriptor* field,
io::Printer& printer,
const TProtoStringType& classname) const;
void GenerateMessageXSCommonMethods(const Descriptor* descriptor,
io::Printer& printer,
const TProtoStringType& classname) const;
void GenerateFileXSTypedefs(const FileDescriptor* file,
io::Printer& printer,
std::set<const Descriptor*>& seen) const;
void GenerateMessageXSTypedefs(const Descriptor* descriptor,
io::Printer& printer,
std::set<const Descriptor*>& seen) const;
void GenerateMessageStatics(const Descriptor* descriptor,
io::Printer& printer) const;
void GenerateMessageXSPackage(const Descriptor* descriptor,
io::Printer& printer) const;
void GenerateTypemapInput(const Descriptor* descriptor,
io::Printer& printer,
const TProtoStringType& svname) const;
TProtoStringType MessageModuleName(const Descriptor* descriptor) const;
TProtoStringType MessageClassName(const Descriptor* descriptor) const;
TProtoStringType EnumClassName(const EnumDescriptor* descriptor) const;
TProtoStringType PackageName(const TProtoStringType& name, const TProtoStringType& package) const;
void PerlSVGetHelper(io::Printer& printer,
const std::map<TProtoStringType, TProtoStringType>& vars,
FieldDescriptor::CppType fieldtype,
int depth) const;
void PODPrintEnumValue(const EnumValueDescriptor *value,
io::Printer& printer) const;
TProtoStringType PODFieldTypeString(const FieldDescriptor* field) const;
void StartFieldToHashref(const FieldDescriptor * field,
io::Printer& printer,
std::map<TProtoStringType, TProtoStringType>& vars,
int depth) const;
void FieldToHashrefHelper(io::Printer& printer,
std::map<TProtoStringType, TProtoStringType>& vars,
const FieldDescriptor* field) const;
void EndFieldToHashref(const FieldDescriptor * field,
io::Printer& printer,
std::map<TProtoStringType, TProtoStringType>& vars,
int depth) const;
void MessageToHashref(const Descriptor * descriptor,
io::Printer& printer,
std::map<TProtoStringType, TProtoStringType>& vars,
int depth) const;
void FieldFromHashrefHelper(io::Printer& printer,
std::map<TProtoStringType, TProtoStringType>& vars,
const FieldDescriptor * field) const;
void MessageFromHashref(const Descriptor * descriptor,
io::Printer& printer,
std::map<TProtoStringType, TProtoStringType>& vars,
int depth) const;
private:
// --perlxs-package option (if given)
TProtoStringType perlxs_package_;
};
} // namespace perlxs
} // namespace compiler
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_PERLXS_GENERATOR_H__
|