Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: third_party/protobuf/src/google/protobuf/compiler/js/js_generator.h

Issue 1842653006: Update //third_party/protobuf to version 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 #ifndef GOOGLE_PROTOBUF_COMPILER_JS_GENERATOR_H__
32 #define GOOGLE_PROTOBUF_COMPILER_JS_GENERATOR_H__
33
34 #include <string>
35 #include <set>
36
37 #include <google/protobuf/compiler/code_generator.h>
38
39 namespace google {
40 namespace protobuf {
41
42 class Descriptor;
43 class EnumDescriptor;
44 class FieldDescriptor;
45 class OneofDescriptor;
46 class FileDescriptor;
47
48 namespace io { class Printer; }
49
50 namespace compiler {
51 namespace js {
52
53 struct GeneratorOptions {
54 // Add a `goog.requires()` call for each enum type used. If not set, a forward
55 // declaration with `goog.forwardDeclare` is produced instead.
56 bool add_require_for_enums;
57 // Set this as a test-only module via `goog.setTestOnly();`.
58 bool testonly;
59 // Output path.
60 string output_dir;
61 // Namespace prefix.
62 string namespace_prefix;
63 // Create a library with name <name>_lib.js rather than a separate .js file
64 // per type?
65 string library;
66 // Error if there are two types that would generate the same output file?
67 bool error_on_name_conflict;
68 // Enable binary-format support?
69 bool binary;
70
71 GeneratorOptions()
72 : add_require_for_enums(false),
73 testonly(false),
74 output_dir("."),
75 namespace_prefix(""),
76 library(""),
77 error_on_name_conflict(false),
78 binary(false) {}
79
80 bool ParseFromOptions(
81 const vector< pair< string, string > >& options,
82 string* error);
83 };
84
85 class LIBPROTOC_EXPORT Generator : public CodeGenerator {
86 public:
87 Generator() {}
88 virtual ~Generator() {}
89
90 virtual bool Generate(const FileDescriptor* file,
91 const string& parameter,
92 GeneratorContext* context,
93 string* error) const {
94 *error = "Unimplemented Generate() method. Call GenerateAll() instead.";
95 return false;
96 }
97
98 virtual bool HasGenerateAll() const { return true; }
99
100 virtual bool GenerateAll(const vector<const FileDescriptor*>& files,
101 const string& parameter,
102 GeneratorContext* context,
103 string* error) const;
104
105 private:
106 void GenerateHeader(const GeneratorOptions& options,
107 io::Printer* printer) const;
108
109 // Generate goog.provides() calls.
110 void FindProvides(const GeneratorOptions& options,
111 io::Printer* printer,
112 const vector<const FileDescriptor*>& file,
113 std::set<string>* provided) const;
114 void FindProvidesForMessage(const GeneratorOptions& options,
115 io::Printer* printer,
116 const Descriptor* desc,
117 std::set<string>* provided) const;
118 void FindProvidesForEnum(const GeneratorOptions& options,
119 io::Printer* printer,
120 const EnumDescriptor* enumdesc,
121 std::set<string>* provided) const;
122 // For extension fields at file scope.
123 void FindProvidesForFields(const GeneratorOptions& options,
124 io::Printer* printer,
125 const vector<const FieldDescriptor*>& fields,
126 std::set<string>* provided) const;
127 // Print the goog.provides() found by the methods above.
128 void GenerateProvides(const GeneratorOptions& options,
129 io::Printer* printer,
130 std::set<string>* provided) const;
131
132 // Generate goog.setTestOnly() if indicated.
133 void GenerateTestOnly(const GeneratorOptions& options,
134 io::Printer* printer) const;
135
136 // Generate goog.requires() calls.
137 void GenerateRequires(const GeneratorOptions& options,
138 io::Printer* printer,
139 const vector<const FileDescriptor*>& file,
140 std::set<string>* provided) const;
141 void GenerateRequires(const GeneratorOptions& options,
142 io::Printer* printer,
143 const Descriptor* desc,
144 std::set<string>* provided) const;
145 // For extension fields at file scope.
146 void GenerateRequires(const GeneratorOptions& options,
147 io::Printer* printer,
148 const vector<const FieldDescriptor*>& fields,
149 std::set<string>* provided) const;
150 void GenerateRequiresImpl(const GeneratorOptions& options,
151 io::Printer* printer,
152 std::set<string>* required,
153 std::set<string>* forwards,
154 std::set<string>* provided,
155 bool require_jspb,
156 bool require_extension) const;
157 void FindRequiresForMessage(const GeneratorOptions& options,
158 const Descriptor* desc,
159 std::set<string>* required,
160 std::set<string>* forwards,
161 bool* have_message) const;
162 void FindRequiresForField(const GeneratorOptions& options,
163 const FieldDescriptor* field,
164 std::set<string>* required,
165 std::set<string>* forwards) const;
166 void FindRequiresForExtension(const GeneratorOptions& options,
167 const FieldDescriptor* field,
168 std::set<string>* required,
169 std::set<string>* forwards) const;
170
171 // Generate definitions for all message classes and enums in all files,
172 // processing the files in dependence order.
173 void GenerateFilesInDepOrder(const GeneratorOptions& options,
174 io::Printer* printer,
175 const vector<const FileDescriptor*>& file) const;
176 // Helper for above.
177 void GenerateFileAndDeps(const GeneratorOptions& options,
178 io::Printer* printer,
179 const FileDescriptor* root,
180 std::set<const FileDescriptor*>* all_files,
181 std::set<const FileDescriptor*>* generated) const;
182
183 // Generate definitions for all message classes and enums.
184 void GenerateClassesAndEnums(const GeneratorOptions& options,
185 io::Printer* printer,
186 const FileDescriptor* file) const;
187
188 // Generate definition for one class.
189 void GenerateClass(const GeneratorOptions& options,
190 io::Printer* printer,
191 const Descriptor* desc) const;
192 void GenerateClassConstructor(const GeneratorOptions& options,
193 io::Printer* printer,
194 const Descriptor* desc) const;
195 void GenerateClassFieldInfo(const GeneratorOptions& options,
196 io::Printer* printer,
197 const Descriptor* desc) const;
198 void GenerateClassXid(const GeneratorOptions& options,
199 io::Printer* printer,
200 const Descriptor* desc) const;
201 void GenerateOneofCaseDefinition(const GeneratorOptions& options,
202 io::Printer* printer,
203 const OneofDescriptor* oneof) const;
204 void GenerateClassToObject(const GeneratorOptions& options,
205 io::Printer* printer,
206 const Descriptor* desc) const;
207 void GenerateClassFieldToObject(const GeneratorOptions& options,
208 io::Printer* printer,
209 const FieldDescriptor* field) const;
210 void GenerateClassFromObject(const GeneratorOptions& options,
211 io::Printer* printer,
212 const Descriptor* desc) const;
213 void GenerateClassFieldFromObject(const GeneratorOptions& options,
214 io::Printer* printer,
215 const FieldDescriptor* field) const;
216 void GenerateClassClone(const GeneratorOptions& options,
217 io::Printer* printer,
218 const Descriptor* desc) const;
219 void GenerateClassRegistration(const GeneratorOptions& options,
220 io::Printer* printer,
221 const Descriptor* desc) const;
222 void GenerateClassFields(const GeneratorOptions& options,
223 io::Printer* printer,
224 const Descriptor* desc) const;
225 void GenerateClassField(const GeneratorOptions& options,
226 io::Printer* printer,
227 const FieldDescriptor* desc) const;
228 void GenerateClassExtensionFieldInfo(const GeneratorOptions& options,
229 io::Printer* printer,
230 const Descriptor* desc) const;
231 void GenerateClassDeserialize(const GeneratorOptions& options,
232 io::Printer* printer,
233 const Descriptor* desc) const;
234 void GenerateClassDeserializeBinary(const GeneratorOptions& options,
235 io::Printer* printer,
236 const Descriptor* desc) const;
237 void GenerateClassDeserializeBinaryField(const GeneratorOptions& options,
238 io::Printer* printer,
239 const FieldDescriptor* field) const;
240 void GenerateClassSerializeBinary(const GeneratorOptions& options,
241 io::Printer* printer,
242 const Descriptor* desc) const;
243 void GenerateClassSerializeBinaryField(const GeneratorOptions& options,
244 io::Printer* printer,
245 const FieldDescriptor* field) const;
246
247 // Generate definition for one enum.
248 void GenerateEnum(const GeneratorOptions& options,
249 io::Printer* printer,
250 const EnumDescriptor* enumdesc) const;
251
252 // Generate an extension definition.
253 void GenerateExtension(const GeneratorOptions& options,
254 io::Printer* printer,
255 const FieldDescriptor* field) const;
256
257 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Generator);
258 };
259
260 } // namespace js
261 } // namespace compiler
262 } // namespace protobuf
263
264 } // namespace google
265 #endif // GOOGLE_PROTOBUF_COMPILER_JS_GENERATOR_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698