PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/src/cpp/cpp_file.cc

http://protoc-gen-luabind.googlecode.com/
C++ | 617 lines | 417 code | 90 blank | 110 comment | 52 complexity | 0ef2ec0b77805db1ef938db3ab05ebf2 MD5 | raw file
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // http://code.google.com/p/protobuf/
  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. // Author: kenton@google.com (Kenton Varda)
  31. // Based on original Protocol Buffers design by
  32. // Sanjay Ghemawat, Jeff Dean, and others.
  33. #include "cpp/cpp_file.h"
  34. #include "cpp/cpp_enum.h"
  35. #include "cpp/cpp_service.h"
  36. #include "cpp/cpp_extension.h"
  37. #include "cpp/cpp_helpers.h"
  38. #include "cpp/cpp_message.h"
  39. #include "cpp/cpp_field.h"
  40. #include <google/protobuf/io/printer.h>
  41. #include <google/protobuf/descriptor.pb.h>
  42. #include <google/protobuf/stubs/strutil.h>
  43. namespace google {
  44. namespace protobuf {
  45. namespace compiler {
  46. namespace cpp {
  47. // ===================================================================
  48. FileGenerator::FileGenerator(const FileDescriptor* file,
  49. const string& dllexport_decl)
  50. : file_(file),
  51. message_generators_(
  52. new scoped_ptr<MessageGenerator>[file->message_type_count()]),
  53. enum_generators_(
  54. new scoped_ptr<EnumGenerator>[file->enum_type_count()]),
  55. service_generators_(
  56. new scoped_ptr<ServiceGenerator>[file->service_count()]),
  57. extension_generators_(
  58. new scoped_ptr<ExtensionGenerator>[file->extension_count()]),
  59. dllexport_decl_(dllexport_decl) {
  60. for (int i = 0; i < file->message_type_count(); i++) {
  61. message_generators_[i].reset(
  62. new MessageGenerator(file->message_type(i), dllexport_decl));
  63. }
  64. for (int i = 0; i < file->enum_type_count(); i++) {
  65. enum_generators_[i].reset(
  66. new EnumGenerator(file->enum_type(i), dllexport_decl));
  67. }
  68. for (int i = 0; i < file->service_count(); i++) {
  69. service_generators_[i].reset(
  70. new ServiceGenerator(file->service(i), dllexport_decl));
  71. }
  72. for (int i = 0; i < file->extension_count(); i++) {
  73. extension_generators_[i].reset(
  74. new ExtensionGenerator(file->extension(i), dllexport_decl));
  75. }
  76. SplitStringUsing(file_->package(), ".", &package_parts_);
  77. }
  78. FileGenerator::~FileGenerator() {}
  79. void FileGenerator::GenerateHeader(io::Printer* printer) {
  80. string filename_identifier = FilenameIdentifier(file_->name());
  81. // Generate top of header.
  82. printer->Print(
  83. "// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
  84. "// source: $filename$\n"
  85. "\n"
  86. "#ifndef PROTOBUF_$filename_identifier$__INCLUDED\n"
  87. "#define PROTOBUF_$filename_identifier$__INCLUDED\n"
  88. "\n"
  89. "#include <string>\n"
  90. "\n",
  91. "filename", file_->name(),
  92. "filename_identifier", filename_identifier);
  93. INC_LUA_HEADERS
  94. LUA_CONST_DEFINITION
  95. printer->Print(
  96. "#include <google/protobuf/stubs/common.h>\n"
  97. "\n");
  98. // Verify the protobuf library header version is compatible with the protoc
  99. // version before going any further.
  100. printer->Print(
  101. "#if GOOGLE_PROTOBUF_VERSION < $min_header_version$\n"
  102. "#error This file was generated by a newer version of protoc which is\n"
  103. "#error incompatible with your Protocol Buffer headers. Please update\n"
  104. "#error your headers.\n"
  105. "#endif\n"
  106. "#if $protoc_version$ < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION\n"
  107. "#error This file was generated by an older version of protoc which is\n"
  108. "#error incompatible with your Protocol Buffer headers. Please\n"
  109. "#error regenerate this file with a newer version of protoc.\n"
  110. "#endif\n"
  111. "\n",
  112. "min_header_version",
  113. SimpleItoa(protobuf::internal::kMinHeaderVersionForProtoc),
  114. "protoc_version", SimpleItoa(GOOGLE_PROTOBUF_VERSION));
  115. // OK, it's now safe to #include other files.
  116. printer->Print(
  117. "#include <google/protobuf/generated_message_util.h>\n"
  118. "#include <google/protobuf/repeated_field.h>\n"
  119. "#include <google/protobuf/extension_set.h>\n");
  120. if (HasDescriptorMethods(file_)) {
  121. printer->Print(
  122. "#include <google/protobuf/generated_message_reflection.h>\n");
  123. }
  124. if (HasGenericServices(file_)) {
  125. printer->Print(
  126. "#include <google/protobuf/service.h>\n");
  127. }
  128. for (int i = 0; i < file_->dependency_count(); i++) {
  129. printer->Print(
  130. "#include \"$dependency$.pb.h\"\n",
  131. "dependency", StripProto(file_->dependency(i)->name()));
  132. }
  133. printer->Print(
  134. "// @@protoc_insertion_point(includes)\n");
  135. // Open namespace.
  136. GenerateNamespaceOpeners(printer);
  137. // Forward-declare the AddDescriptors, AssignDescriptors, and ShutdownFile
  138. // functions, so that we can declare them to be friends of each class.
  139. printer->Print(
  140. "\n"
  141. "// Internal implementation detail -- do not call these.\n"
  142. "void $dllexport_decl$ $adddescriptorsname$();\n",
  143. "adddescriptorsname", GlobalAddDescriptorsName(file_->name()),
  144. "dllexport_decl", dllexport_decl_);
  145. printer->Print(
  146. // Note that we don't put dllexport_decl on these because they are only
  147. // called by the .pb.cc file in which they are defined.
  148. "void $assigndescriptorsname$();\n"
  149. "void $shutdownfilename$();\n"
  150. "\n",
  151. "assigndescriptorsname", GlobalAssignDescriptorsName(file_->name()),
  152. "shutdownfilename", GlobalShutdownFileName(file_->name()));
  153. // Generate forward declarations of classes.
  154. for (int i = 0; i < file_->message_type_count(); i++) {
  155. message_generators_[i]->GenerateForwardDeclaration(printer);
  156. }
  157. printer->Print("\n");
  158. // Generate enum definitions.
  159. for (int i = 0; i < file_->message_type_count(); i++) {
  160. message_generators_[i]->GenerateEnumDefinitions(printer);
  161. }
  162. for (int i = 0; i < file_->enum_type_count(); i++) {
  163. enum_generators_[i]->GenerateDefinition(printer);
  164. }
  165. printer->Print(kThickSeparator);
  166. printer->Print("\n");
  167. // Generate class definitions.
  168. for (int i = 0; i < file_->message_type_count(); i++) {
  169. if (i > 0) {
  170. printer->Print("\n");
  171. printer->Print(kThinSeparator);
  172. printer->Print("\n");
  173. }
  174. message_generators_[i]->GenerateClassDefinition(printer);
  175. }
  176. printer->Print("\n");
  177. printer->Print(kThickSeparator);
  178. printer->Print("\n");
  179. if (HasGenericServices(file_)) {
  180. // Generate service definitions.
  181. for (int i = 0; i < file_->service_count(); i++) {
  182. if (i > 0) {
  183. printer->Print("\n");
  184. printer->Print(kThinSeparator);
  185. printer->Print("\n");
  186. }
  187. service_generators_[i]->GenerateDeclarations(printer);
  188. }
  189. printer->Print("\n");
  190. printer->Print(kThickSeparator);
  191. printer->Print("\n");
  192. }
  193. // Declare extension identifiers.
  194. for (int i = 0; i < file_->extension_count(); i++) {
  195. extension_generators_[i]->GenerateDeclaration(printer);
  196. }
  197. printer->Print("\n");
  198. printer->Print(kThickSeparator);
  199. printer->Print("\n");
  200. // Generate class inline methods.
  201. for (int i = 0; i < file_->message_type_count(); i++) {
  202. if (i > 0) {
  203. printer->Print(kThinSeparator);
  204. printer->Print("\n");
  205. }
  206. message_generators_[i]->GenerateInlineMethods(printer);
  207. }
  208. this->GenerateLuaBindCode(printer);
  209. printer->Print(
  210. "\n"
  211. "// @@protoc_insertion_point(namespace_scope)\n");
  212. // Close up namespace.
  213. GenerateNamespaceClosers(printer);
  214. // Emit GetEnumDescriptor specializations into google::protobuf namespace:
  215. if (HasDescriptorMethods(file_)) {
  216. // The SWIG conditional is to avoid a null-pointer dereference
  217. // (bug 1984964) in swig-1.3.21 resulting from the following syntax:
  218. // namespace X { void Y<Z::W>(); }
  219. // which appears in GetEnumDescriptor() specializations.
  220. printer->Print(
  221. "\n"
  222. "#ifndef SWIG\n"
  223. "namespace google {\nnamespace protobuf {\n"
  224. "\n");
  225. for (int i = 0; i < file_->message_type_count(); i++) {
  226. message_generators_[i]->GenerateGetEnumDescriptorSpecializations(printer);
  227. }
  228. for (int i = 0; i < file_->enum_type_count(); i++) {
  229. enum_generators_[i]->GenerateGetEnumDescriptorSpecializations(printer);
  230. }
  231. printer->Print(
  232. "\n"
  233. "} // namespace google\n} // namespace protobuf\n"
  234. "#endif // SWIG\n");
  235. }
  236. printer->Print(
  237. "\n"
  238. "// @@protoc_insertion_point(global_scope)\n"
  239. "\n");
  240. printer->Print(
  241. "#endif // PROTOBUF_$filename_identifier$__INCLUDED\n",
  242. "filename_identifier", filename_identifier);
  243. }
  244. void FileGenerator::GenerateSource(io::Printer* printer) {
  245. printer->Print(
  246. "// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
  247. "\n"
  248. // The generated code calls accessors that might be deprecated. We don't
  249. // want the compiler to warn in generated code.
  250. "#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION\n"
  251. "#include \"$basename$.pb.h\"\n"
  252. "\n"
  253. "#include <algorithm>\n" // for swap()
  254. "\n"
  255. "#include <google/protobuf/stubs/once.h>\n"
  256. "#include <google/protobuf/io/coded_stream.h>\n"
  257. "#include <google/protobuf/wire_format_lite_inl.h>\n",
  258. "basename", StripProto(file_->name()));
  259. if (HasDescriptorMethods(file_)) {
  260. printer->Print(
  261. "#include <google/protobuf/descriptor.h>\n"
  262. "#include <google/protobuf/reflection_ops.h>\n"
  263. "#include <google/protobuf/wire_format.h>\n");
  264. }
  265. printer->Print(
  266. "// @@protoc_insertion_point(includes)\n");
  267. GenerateNamespaceOpeners(printer);
  268. if (HasDescriptorMethods(file_)) {
  269. printer->Print(
  270. "\n"
  271. "namespace {\n"
  272. "\n");
  273. for (int i = 0; i < file_->message_type_count(); i++) {
  274. message_generators_[i]->GenerateDescriptorDeclarations(printer);
  275. }
  276. for (int i = 0; i < file_->enum_type_count(); i++) {
  277. printer->Print(
  278. "const ::google::protobuf::EnumDescriptor* $name$_descriptor_ = NULL;\n",
  279. "name", ClassName(file_->enum_type(i), false));
  280. }
  281. if (HasGenericServices(file_)) {
  282. for (int i = 0; i < file_->service_count(); i++) {
  283. printer->Print(
  284. "const ::google::protobuf::ServiceDescriptor* $name$_descriptor_ = NULL;\n",
  285. "name", file_->service(i)->name());
  286. }
  287. }
  288. printer->Print(
  289. "\n"
  290. "} // namespace\n"
  291. "\n");
  292. }
  293. // Define our externally-visible BuildDescriptors() function. (For the lite
  294. // library, all this does is initialize default instances.)
  295. GenerateBuildDescriptors(printer);
  296. // Generate enums.
  297. for (int i = 0; i < file_->enum_type_count(); i++) {
  298. enum_generators_[i]->GenerateMethods(printer);
  299. }
  300. // Generate classes.
  301. for (int i = 0; i < file_->message_type_count(); i++) {
  302. printer->Print("\n");
  303. printer->Print(kThickSeparator);
  304. printer->Print("\n");
  305. message_generators_[i]->GenerateClassMethods(printer);
  306. }
  307. if (HasGenericServices(file_)) {
  308. // Generate services.
  309. for (int i = 0; i < file_->service_count(); i++) {
  310. if (i == 0) printer->Print("\n");
  311. printer->Print(kThickSeparator);
  312. printer->Print("\n");
  313. service_generators_[i]->GenerateImplementation(printer);
  314. }
  315. }
  316. // Define extensions.
  317. for (int i = 0; i < file_->extension_count(); i++) {
  318. extension_generators_[i]->GenerateDefinition(printer);
  319. }
  320. printer->Print(
  321. "\n"
  322. "// @@protoc_insertion_point(namespace_scope)\n");
  323. GenerateNamespaceClosers(printer);
  324. printer->Print(
  325. "\n"
  326. "// @@protoc_insertion_point(global_scope)\n");
  327. }
  328. void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
  329. // AddDescriptors() is a file-level procedure which adds the encoded
  330. // FileDescriptorProto for this .proto file to the global DescriptorPool
  331. // for generated files (DescriptorPool::generated_pool()). It always runs
  332. // at static initialization time, so all files will be registered before
  333. // main() starts. This procedure also constructs default instances and
  334. // registers extensions.
  335. //
  336. // Its sibling, AssignDescriptors(), actually pulls the compiled
  337. // FileDescriptor from the DescriptorPool and uses it to populate all of
  338. // the global variables which store pointers to the descriptor objects.
  339. // It also constructs the reflection objects. It is called the first time
  340. // anyone calls descriptor() or GetReflection() on one of the types defined
  341. // in the file.
  342. // In optimize_for = LITE_RUNTIME mode, we don't generate AssignDescriptors()
  343. // and we only use AddDescriptors() to allocate default instances.
  344. if (HasDescriptorMethods(file_)) {
  345. printer->Print(
  346. "\n"
  347. "void $assigndescriptorsname$() {\n",
  348. "assigndescriptorsname", GlobalAssignDescriptorsName(file_->name()));
  349. printer->Indent();
  350. // Make sure the file has found its way into the pool. If a descriptor
  351. // is requested *during* static init then AddDescriptors() may not have
  352. // been called yet, so we call it manually. Note that it's fine if
  353. // AddDescriptors() is called multiple times.
  354. printer->Print(
  355. "$adddescriptorsname$();\n",
  356. "adddescriptorsname", GlobalAddDescriptorsName(file_->name()));
  357. // Get the file's descriptor from the pool.
  358. printer->Print(
  359. "const ::google::protobuf::FileDescriptor* file =\n"
  360. " ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(\n"
  361. " \"$filename$\");\n"
  362. // Note that this GOOGLE_CHECK is necessary to prevent a warning about "file"
  363. // being unused when compiling an empty .proto file.
  364. "GOOGLE_CHECK(file != NULL);\n",
  365. "filename", file_->name());
  366. // Go through all the stuff defined in this file and generated code to
  367. // assign the global descriptor pointers based on the file descriptor.
  368. for (int i = 0; i < file_->message_type_count(); i++) {
  369. message_generators_[i]->GenerateDescriptorInitializer(printer, i);
  370. }
  371. for (int i = 0; i < file_->enum_type_count(); i++) {
  372. enum_generators_[i]->GenerateDescriptorInitializer(printer, i);
  373. }
  374. if (HasGenericServices(file_)) {
  375. for (int i = 0; i < file_->service_count(); i++) {
  376. service_generators_[i]->GenerateDescriptorInitializer(printer, i);
  377. }
  378. }
  379. printer->Outdent();
  380. printer->Print(
  381. "}\n"
  382. "\n");
  383. // ---------------------------------------------------------------
  384. // protobuf_AssignDescriptorsOnce(): The first time it is called, calls
  385. // AssignDescriptors(). All later times, waits for the first call to
  386. // complete and then returns.
  387. printer->Print(
  388. "namespace {\n"
  389. "\n"
  390. "GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);\n"
  391. "inline void protobuf_AssignDescriptorsOnce() {\n"
  392. " ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,\n"
  393. " &$assigndescriptorsname$);\n"
  394. "}\n"
  395. "\n",
  396. "assigndescriptorsname", GlobalAssignDescriptorsName(file_->name()));
  397. // protobuf_RegisterTypes(): Calls
  398. // MessageFactory::InternalRegisterGeneratedType() for each message type.
  399. printer->Print(
  400. "void protobuf_RegisterTypes(const ::std::string&) {\n"
  401. " protobuf_AssignDescriptorsOnce();\n");
  402. printer->Indent();
  403. for (int i = 0; i < file_->message_type_count(); i++) {
  404. message_generators_[i]->GenerateTypeRegistrations(printer);
  405. }
  406. printer->Outdent();
  407. printer->Print(
  408. "}\n"
  409. "\n"
  410. "} // namespace\n");
  411. }
  412. // -----------------------------------------------------------------
  413. // ShutdownFile(): Deletes descriptors, default instances, etc. on shutdown.
  414. printer->Print(
  415. "\n"
  416. "void $shutdownfilename$() {\n",
  417. "shutdownfilename", GlobalShutdownFileName(file_->name()));
  418. printer->Indent();
  419. for (int i = 0; i < file_->message_type_count(); i++) {
  420. message_generators_[i]->GenerateShutdownCode(printer);
  421. }
  422. printer->Outdent();
  423. printer->Print(
  424. "}\n");
  425. // -----------------------------------------------------------------
  426. // Now generate the AddDescriptors() function.
  427. printer->Print(
  428. "\n"
  429. "void $adddescriptorsname$() {\n"
  430. // We don't need any special synchronization here because this code is
  431. // called at static init time before any threads exist.
  432. " static bool already_here = false;\n"
  433. " if (already_here) return;\n"
  434. " already_here = true;\n"
  435. " GOOGLE_PROTOBUF_VERIFY_VERSION;\n"
  436. "\n",
  437. "adddescriptorsname", GlobalAddDescriptorsName(file_->name()));
  438. printer->Indent();
  439. // Call the AddDescriptors() methods for all of our dependencies, to make
  440. // sure they get added first.
  441. for (int i = 0; i < file_->dependency_count(); i++) {
  442. const FileDescriptor* dependency = file_->dependency(i);
  443. // Print the namespace prefix for the dependency.
  444. vector<string> dependency_package_parts;
  445. SplitStringUsing(dependency->package(), ".", &dependency_package_parts);
  446. printer->Print("::");
  447. for (int i = 0; i < dependency_package_parts.size(); i++) {
  448. printer->Print("$name$::",
  449. "name", dependency_package_parts[i]);
  450. }
  451. // Call its AddDescriptors function.
  452. printer->Print(
  453. "$name$();\n",
  454. "name", GlobalAddDescriptorsName(dependency->name()));
  455. }
  456. if (HasDescriptorMethods(file_)) {
  457. // Embed the descriptor. We simply serialize the entire FileDescriptorProto
  458. // and embed it as a string literal, which is parsed and built into real
  459. // descriptors at initialization time.
  460. FileDescriptorProto file_proto;
  461. file_->CopyTo(&file_proto);
  462. string file_data;
  463. file_proto.SerializeToString(&file_data);
  464. printer->Print(
  465. "::google::protobuf::DescriptorPool::InternalAddGeneratedFile(");
  466. // Only write 40 bytes per line.
  467. static const int kBytesPerLine = 40;
  468. for (int i = 0; i < file_data.size(); i += kBytesPerLine) {
  469. printer->Print("\n \"$data$\"",
  470. "data", EscapeTrigraphs(CEscape(file_data.substr(i, kBytesPerLine))));
  471. }
  472. printer->Print(
  473. ", $size$);\n",
  474. "size", SimpleItoa(file_data.size()));
  475. // Call MessageFactory::InternalRegisterGeneratedFile().
  476. printer->Print(
  477. "::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(\n"
  478. " \"$filename$\", &protobuf_RegisterTypes);\n",
  479. "filename", file_->name());
  480. }
  481. // Allocate and initialize default instances. This can't be done lazily
  482. // since default instances are returned by simple accessors and are used with
  483. // extensions. Speaking of which, we also register extensions at this time.
  484. for (int i = 0; i < file_->message_type_count(); i++) {
  485. message_generators_[i]->GenerateDefaultInstanceAllocator(printer);
  486. }
  487. for (int i = 0; i < file_->extension_count(); i++) {
  488. extension_generators_[i]->GenerateRegistration(printer);
  489. }
  490. for (int i = 0; i < file_->message_type_count(); i++) {
  491. message_generators_[i]->GenerateDefaultInstanceInitializer(printer);
  492. }
  493. printer->Print(
  494. "::google::protobuf::internal::OnShutdown(&$shutdownfilename$);\n",
  495. "shutdownfilename", GlobalShutdownFileName(file_->name()));
  496. printer->Outdent();
  497. printer->Print(
  498. "}\n"
  499. "\n"
  500. "// Force AddDescriptors() to be called at static initialization time.\n"
  501. "struct StaticDescriptorInitializer_$filename$ {\n"
  502. " StaticDescriptorInitializer_$filename$() {\n"
  503. " $adddescriptorsname$();\n"
  504. " }\n"
  505. "} static_descriptor_initializer_$filename$_;\n"
  506. "\n",
  507. "adddescriptorsname", GlobalAddDescriptorsName(file_->name()),
  508. "filename", FilenameIdentifier(file_->name()));
  509. }
  510. void FileGenerator::GenerateNamespaceOpeners(io::Printer* printer) {
  511. if (package_parts_.size() > 0) printer->Print("\n");
  512. for (int i = 0; i < package_parts_.size(); i++) {
  513. printer->Print("namespace $part$ {\n",
  514. "part", package_parts_[i]);
  515. }
  516. }
  517. void FileGenerator::GenerateNamespaceClosers(io::Printer* printer) {
  518. if (package_parts_.size() > 0) printer->Print("\n");
  519. for (int i = package_parts_.size() - 1; i >= 0; i--) {
  520. printer->Print("} // namespace $part$\n",
  521. "part", package_parts_[i]);
  522. }
  523. }
  524. } // namespace cpp
  525. } // namespace compiler
  526. } // namespace protobuf
  527. } // namespace google