aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_enum_field.cc6
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_file.cc6
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message.cc2
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_helpers.cc2
-rw-r--r--src/google/protobuf/compiler/importer.cc2
-rw-r--r--src/google/protobuf/compiler/importer.h15
-rw-r--r--src/google/protobuf/compiler/java/java_enum_field.cc8
-rw-r--r--src/google/protobuf/compiler/java/java_lazy_message_field.cc5
-rw-r--r--src/google/protobuf/compiler/java/java_message_field.cc23
-rw-r--r--src/google/protobuf/compiler/java/java_primitive_field.cc22
-rw-r--r--src/google/protobuf/compiler/java/java_string_field.cc8
-rw-r--r--src/google/protobuf/compiler/js/embed.cc110
-rw-r--r--[-rwxr-xr-x]src/google/protobuf/compiler/js/js_generator.cc40
-rw-r--r--[-rwxr-xr-x]src/google/protobuf/compiler/js/js_generator.h9
-rw-r--r--src/google/protobuf/compiler/js/well_known_types_embed.cc225
-rw-r--r--src/google/protobuf/compiler/plugin.pb.cc6
16 files changed, 327 insertions, 162 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
index 50c7b5f3..828d0be5 100644
--- a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
@@ -128,7 +128,7 @@ GenerateCopyConstructorCode(io::Printer* printer) const {
void EnumFieldGenerator::
GenerateMergeFromCodedStream(io::Printer* printer) const {
printer->Print(variables_,
- "int value;\n"
+ "int value = 0;\n"
"DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n"
" int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(\n"
" input, &value)));\n");
@@ -334,7 +334,7 @@ void RepeatedEnumFieldGenerator::
GenerateMergeFromCodedStream(io::Printer* printer) const {
// Don't use ReadRepeatedPrimitive here so that the enum can be validated.
printer->Print(variables_,
- "int value;\n"
+ "int value = 0;\n"
"DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n"
" int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(\n"
" input, &value)));\n");
@@ -399,7 +399,7 @@ GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const {
"::google::protobuf::io::CodedInputStream::Limit limit = "
"input->PushLimit(static_cast<int>(length));\n"
"while (input->BytesUntilLimit() > 0) {\n"
- " int value;\n"
+ " int value = 0;\n"
" DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n"
" int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(\n"
" input, &value)));\n");
diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc
index 42525687..02f360bb 100644
--- a/src/google/protobuf/compiler/cpp/cpp_file.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_file.cc
@@ -791,7 +791,7 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) {
// AssignDescriptors(). All later times, waits for the first call to
// complete and then returns.
printer->Print(
- "void protobuf_AssignDescriptors() {\n"
+ "static void protobuf_AssignDescriptors() {\n"
// Make sure the file has found its way into the pool. If a descriptor
// is requested *during* static init then AddDescriptors() may not have
// been called yet, so we call it manually. Note that it's fine if
@@ -812,7 +812,7 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) {
printer->Print(
"}\n"
"\n"
- "void protobuf_AssignDescriptorsOnce() {\n"
+ "static void protobuf_AssignDescriptorsOnce() {\n"
" static ::google::protobuf::internal::once_flag once;\n"
" ::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);\n"
"}\n"
@@ -850,7 +850,7 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) {
// Now generate the AddDescriptors() function.
printer->Print(
- "void AddDescriptorsImpl() {\n"
+ "static void AddDescriptorsImpl() {\n"
" InitDefaults();\n");
printer->Indent();
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc
index 8c2336af..778fc406 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message.cc
@@ -2280,7 +2280,7 @@ GenerateArenaDestructorCode(io::Printer* printer) {
"classname", classname_);
} else {
printer->Print(
- "void $classname$::RegisterArenaDtor(::google::protobuf::Arena* arena) {\n"
+ "void $classname$::RegisterArenaDtor(::google::protobuf::Arena*) {\n"
"}\n",
"classname", classname_);
}
diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc
index 5bca1ffa..04b61074 100644
--- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc
@@ -169,7 +169,7 @@ std::string UnderscoresToCamelCase(const std::string& input,
}
}
// Add a trailing "_" if the name should be altered.
- if (input[input.size() - 1] == '#') {
+ if (input.size() > 0 && input[input.size() - 1] == '#') {
result += '_';
}
return result;
diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc
index c3831e72..58498aaa 100644
--- a/src/google/protobuf/compiler/importer.cc
+++ b/src/google/protobuf/compiler/importer.cc
@@ -103,7 +103,7 @@ class SourceTreeDescriptorDatabase::SingleFileErrorCollector
bool had_errors() { return had_errors_; }
// implements ErrorCollector ---------------------------------------
- void AddError(int line, int column, const string& message) {
+ void AddError(int line, int column, const string& message) override {
if (multi_file_error_collector_ != NULL) {
multi_file_error_collector_->AddError(filename_, line, column, message);
}
diff --git a/src/google/protobuf/compiler/importer.h b/src/google/protobuf/compiler/importer.h
index a4ffcf87..bf6d3de3 100644
--- a/src/google/protobuf/compiler/importer.h
+++ b/src/google/protobuf/compiler/importer.h
@@ -96,12 +96,13 @@ class LIBPROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabas
}
// implements DescriptorDatabase -----------------------------------
- bool FindFileByName(const string& filename, FileDescriptorProto* output);
+ bool FindFileByName(const string& filename,
+ FileDescriptorProto* output) override;
bool FindFileContainingSymbol(const string& symbol_name,
- FileDescriptorProto* output);
+ FileDescriptorProto*output) override;
bool FindFileContainingExtension(const string& containing_type,
int field_number,
- FileDescriptorProto* output);
+ FileDescriptorProto* output) override;
private:
class SingleFileErrorCollector;
@@ -119,13 +120,13 @@ class LIBPROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabas
const string& element_name,
const Message* descriptor,
ErrorLocation location,
- const string& message);
+ const string& message) override;
virtual void AddWarning(const string& filename,
const string& element_name,
const Message* descriptor,
ErrorLocation location,
- const string& message);
+ const string& message) override;
private:
SourceTreeDescriptorDatabase* owner_;
@@ -293,9 +294,9 @@ class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree {
bool VirtualFileToDiskFile(const string& virtual_file, string* disk_file);
// implements SourceTree -------------------------------------------
- virtual io::ZeroCopyInputStream* Open(const string& filename);
+ virtual io::ZeroCopyInputStream* Open(const string& filename) override;
- virtual string GetLastErrorMessage();
+ virtual string GetLastErrorMessage() override;
private:
struct Mapping {
diff --git a/src/google/protobuf/compiler/java/java_enum_field.cc b/src/google/protobuf/compiler/java/java_enum_field.cc
index 0686ea0f..ef64d88b 100644
--- a/src/google/protobuf/compiler/java/java_enum_field.cc
+++ b/src/google/protobuf/compiler/java/java_enum_field.cc
@@ -305,11 +305,15 @@ GenerateBuildingCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n"
+ " result.$name$_ = $name$_;\n"
" $set_has_field_bit_to_local$;\n"
+ "} else {\n"
+ " result.$name$_ = $default_number$;\n"
"}\n");
+ } else {
+ printer->Print(variables_,
+ "result.$name$_ = $name$_;\n");
}
- printer->Print(variables_,
- "result.$name$_ = $name$_;\n");
}
void ImmutableEnumFieldGenerator::
diff --git a/src/google/protobuf/compiler/java/java_lazy_message_field.cc b/src/google/protobuf/compiler/java/java_lazy_message_field.cc
index abf8e55c..6544bea0 100644
--- a/src/google/protobuf/compiler/java/java_lazy_message_field.cc
+++ b/src/google/protobuf/compiler/java/java_lazy_message_field.cc
@@ -233,12 +233,9 @@ void ImmutableLazyMessageFieldGenerator::
GenerateBuildingCode(io::Printer* printer) const {
printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n"
+ " result.$name$_.set($name$_);\n"
" $set_has_field_bit_to_local$;\n"
"}\n");
-
- printer->Print(variables_,
- "result.$name$_.set(\n"
- " $name$_);\n");
}
void ImmutableLazyMessageFieldGenerator::
diff --git a/src/google/protobuf/compiler/java/java_message_field.cc b/src/google/protobuf/compiler/java/java_message_field.cc
index baa7f872..bda4fcc0 100644
--- a/src/google/protobuf/compiler/java/java_message_field.cc
+++ b/src/google/protobuf/compiler/java/java_message_field.cc
@@ -255,7 +255,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
bool support_field_presence = SupportFieldPresence(descriptor_->file());
printer->Print(variables_,
- "private $type$ $name$_ = null;\n");
+ "private $type$ $name$_;\n");
printer->Print(variables_,
// If this builder is non-null, it is used and the other fields are
@@ -444,15 +444,20 @@ void ImmutableMessageFieldGenerator::
GenerateBuildingCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_,
- "if ($get_has_field_bit_from_local$) {\n"
- " $set_has_field_bit_to_local$;\n"
- "}\n");
+ "if ($get_has_field_bit_from_local$) {\n");
+ printer->Indent();
+ PrintNestedBuilderCondition(printer,
+ "result.$name$_ = $name$_;\n",
+ "result.$name$_ = $name$Builder_.build();\n");
+ printer->Outdent();
+ printer->Print(variables_,
+ " $set_has_field_bit_to_local$;\n"
+ "}\n");
+ } else {
+ PrintNestedBuilderCondition(printer,
+ "result.$name$_ = $name$_;\n",
+ "result.$name$_ = $name$Builder_.build();\n");
}
-
- PrintNestedBuilderCondition(printer,
- "result.$name$_ = $name$_;\n",
-
- "result.$name$_ = $name$Builder_.build();\n");
}
void ImmutableMessageFieldGenerator::
diff --git a/src/google/protobuf/compiler/java/java_primitive_field.cc b/src/google/protobuf/compiler/java/java_primitive_field.cc
index 71ee0992..e6ce69c7 100644
--- a/src/google/protobuf/compiler/java/java_primitive_field.cc
+++ b/src/google/protobuf/compiler/java/java_primitive_field.cc
@@ -264,7 +264,9 @@ GenerateFieldBuilderInitializationCode(io::Printer* printer) const {
void ImmutablePrimitiveFieldGenerator::
GenerateInitializationCode(io::Printer* printer) const {
- printer->Print(variables_, "$name$_ = $default$;\n");
+ if (!IsDefaultValueJavaDefault(descriptor_)) {
+ printer->Print(variables_, "$name$_ = $default$;\n");
+ }
}
void ImmutablePrimitiveFieldGenerator::
@@ -294,11 +296,21 @@ GenerateBuildingCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n"
- " $set_has_field_bit_to_local$;\n"
- "}\n");
+ " result.$name$_ = $name$_;\n"
+ " $set_has_field_bit_to_local$;\n");
+ if (IsDefaultValueJavaDefault(descriptor_)) {
+ printer->Print(variables_,
+ "}\n");
+ } else {
+ printer->Print(variables_,
+ "} else {\n"
+ " result.$name$_ = $default$;\n"
+ "}\n");
+ }
+ } else {
+ printer->Print(variables_,
+ "result.$name$_ = $name$_;\n");
}
- printer->Print(variables_,
- "result.$name$_ = $name$_;\n");
}
void ImmutablePrimitiveFieldGenerator::
diff --git a/src/google/protobuf/compiler/java/java_string_field.cc b/src/google/protobuf/compiler/java/java_string_field.cc
index 2b6e9381..b08febc0 100644
--- a/src/google/protobuf/compiler/java/java_string_field.cc
+++ b/src/google/protobuf/compiler/java/java_string_field.cc
@@ -405,11 +405,15 @@ GenerateBuildingCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n"
+ " result.$name$_ = $name$_;\n"
" $set_has_field_bit_to_local$;\n"
+ "} else {\n"
+ " result.$name$_ = $default$;\n"
"}\n");
+ } else {
+ printer->Print(variables_,
+ "result.$name$_ = $name$_;\n");
}
- printer->Print(variables_,
- "result.$name$_ = $name$_;\n");
}
void ImmutableStringFieldGenerator::
diff --git a/src/google/protobuf/compiler/js/embed.cc b/src/google/protobuf/compiler/js/embed.cc
deleted file mode 100644
index f0f946e5..00000000
--- a/src/google/protobuf/compiler/js/embed.cc
+++ /dev/null
@@ -1,110 +0,0 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cassert>
-#include <cstdlib>
-#include <fstream>
-#include <iostream>
-#include <string>
-
-static bool AsciiIsPrint(unsigned char c) {
- return c >= 32 && c < 127;
-}
-
-static char ToDecimalDigit(int num) {
- assert(num < 10);
- return '0' + num;
-}
-
-static std::string CEscape(const std::string& str) {
- std::string dest;
-
- for (size_t i = 0; i < str.size(); ++i) {
- unsigned char ch = str[i];
- switch (ch) {
- case '\n': dest += "\\n"; break;
- case '\r': dest += "\\r"; break;
- case '\t': dest += "\\t"; break;
- case '\"': dest += "\\\""; break;
- case '\\': dest += "\\\\"; break;
- default:
- if (AsciiIsPrint(ch)) {
- dest += ch;
- } else {
- dest += "\\";
- dest += ToDecimalDigit(ch / 64);
- dest += ToDecimalDigit((ch % 64) / 8);
- dest += ToDecimalDigit(ch % 8);
- }
- break;
- }
- }
-
- return dest;
-}
-
-static void AddFile(const char* name, std::basic_ostream<char>* out) {
- std::ifstream in(name);
-
- if (!in.is_open()) {
- std::cerr << "Couldn't open input file: " << name << "\n";
- std::exit(EXIT_FAILURE);
- }
-
- // Make canonical name only include the final element.
- for (const char *p = name; *p; p++) {
- if (*p == '/') {
- name = p + 1;
- }
- }
-
- *out << "{\"" << CEscape(name) << "\",\n";
-
- for (std::string line; std::getline(in, line); ) {
- *out << " \"" << CEscape(line) << "\\n\"\n";
- }
-
- *out << "},\n";
-}
-
-int main(int argc, char *argv[]) {
- std::cout << "#include "
- "\"google/protobuf/compiler/js/well_known_types_embed.h\"\n";
- std::cout << "struct FileToc well_known_types_js[] = {\n";
-
- for (int i = 1; i < argc; i++) {
- AddFile(argv[i], &std::cout);
- }
-
- std::cout << " {NULL, NULL} // Terminate the list.\n";
- std::cout << "};\n";
-
- return EXIT_SUCCESS;
-}
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc
index b5771f26..d25a3668 100755..100644
--- a/src/google/protobuf/compiler/js/js_generator.cc
+++ b/src/google/protobuf/compiler/js/js_generator.cc
@@ -276,7 +276,8 @@ string GetEnumPath(const GeneratorOptions& options,
string MaybeCrossFileRef(const GeneratorOptions& options,
const FileDescriptor* from_file,
const Descriptor* to_message) {
- if (options.import_style == GeneratorOptions::kImportCommonJs &&
+ if ((options.import_style == GeneratorOptions::kImportCommonJs ||
+ options.import_style == GeneratorOptions::kImportCommonJsStrict) &&
from_file != to_message->file()) {
// Cross-file ref in CommonJS needs to use the module alias instead of
// the global name.
@@ -1675,8 +1676,19 @@ void Generator::GenerateProvides(const GeneratorOptions& options,
//
// // Later generated code expects foo.bar = {} to exist:
// foo.bar.Baz = function() { /* ... */ }
- printer->Print("goog.exportSymbol('$name$', null, global);\n", "name",
- *it);
+
+ // Do not use global scope in strict mode
+ if (options.import_style == GeneratorOptions::kImportCommonJsStrict) {
+ string namespaceObject = *it;
+ // Remove "proto." from the namespace object
+ GOOGLE_CHECK(namespaceObject.compare(0, 6, "proto."));
+ namespaceObject.erase(0, 6);
+ printer->Print("goog.exportSymbol('$name$', null, proto);\n", "name",
+ namespaceObject);
+ } else {
+ printer->Print("goog.exportSymbol('$name$', null, global);\n", "name",
+ *it);
+ }
}
}
}
@@ -3325,6 +3337,8 @@ bool GeneratorOptions::ParseFromOptions(
import_style = kImportClosure;
} else if (options[i].second == "commonjs") {
import_style = kImportCommonJs;
+ } else if (options[i].second == "commonjs_strict") {
+ import_style = kImportCommonJsStrict;
} else if (options[i].second == "browser") {
import_style = kImportBrowser;
} else if (options[i].second == "es6") {
@@ -3434,15 +3448,23 @@ void Generator::GenerateFile(const GeneratorOptions& options,
GenerateHeader(options, printer);
// Generate "require" statements.
- if (options.import_style == GeneratorOptions::kImportCommonJs) {
+ if ((options.import_style == GeneratorOptions::kImportCommonJs ||
+ options.import_style == GeneratorOptions::kImportCommonJsStrict)) {
printer->Print("var jspb = require('google-protobuf');\n");
printer->Print("var goog = jspb;\n");
- printer->Print("var global = Function('return this')();\n\n");
+
+ // Do not use global scope in strict mode
+ if (options.import_style == GeneratorOptions::kImportCommonJsStrict) {
+ printer->Print("var proto = {};\n\n");
+ } else {
+ printer->Print("var global = Function('return this')();\n\n");
+ }
for (int i = 0; i < file->dependency_count(); i++) {
const string& name = file->dependency(i)->name();
printer->Print(
- "var $alias$ = require('$file$');\n",
+ "var $alias$ = require('$file$');\n"
+ "goog.object.extend(proto, $alias$);\n",
"alias", ModuleAlias(name),
"file",
GetRootPath(file->name(), name) + GetJSFilename(options, name));
@@ -3481,9 +3503,13 @@ void Generator::GenerateFile(const GeneratorOptions& options,
GenerateExtension(options, printer, *it);
}
- if (options.import_style == GeneratorOptions::kImportCommonJs) {
+ // if provided is empty, do not export anything
+ if (options.import_style == GeneratorOptions::kImportCommonJs && !provided.empty()) {
printer->Print("goog.object.extend(exports, $package$);\n",
"package", GetFilePath(options, file));
+ } else if(options.import_style == GeneratorOptions::kImportCommonJsStrict) {
+ printer->Print("goog.object.extend(exports, proto);\n",
+ "package", GetFilePath(options, file));
}
// Emit well-known type methods.
diff --git a/src/google/protobuf/compiler/js/js_generator.h b/src/google/protobuf/compiler/js/js_generator.h
index 3cc60e22..b50ef7fd 100755..100644
--- a/src/google/protobuf/compiler/js/js_generator.h
+++ b/src/google/protobuf/compiler/js/js_generator.h
@@ -63,10 +63,11 @@ struct GeneratorOptions {
bool binary;
// What style of imports should be used.
enum ImportStyle {
- kImportClosure, // goog.require()
- kImportCommonJs, // require()
- kImportBrowser, // no import statements
- kImportEs6, // import { member } from ''
+ kImportClosure, // goog.require()
+ kImportCommonJs, // require()
+ kImportCommonJsStrict, // require() with no global export
+ kImportBrowser, // no import statements
+ kImportEs6, // import { member } from ''
} import_style;
GeneratorOptions()
diff --git a/src/google/protobuf/compiler/js/well_known_types_embed.cc b/src/google/protobuf/compiler/js/well_known_types_embed.cc
new file mode 100644
index 00000000..e5ee5510
--- /dev/null
+++ b/src/google/protobuf/compiler/js/well_known_types_embed.cc
@@ -0,0 +1,225 @@
+#include <google/protobuf/compiler/js/well_known_types_embed.h>
+
+struct FileToc well_known_types_js[] = {
+ {"any.js",
+ "/* This code will be inserted into generated code for\n"
+ " * google/protobuf/any.proto. */\n"
+ "\n"
+ "/**\n"
+ " * Returns the type name contained in this instance, if any.\n"
+ " * @return {string|undefined}\n"
+ " */\n"
+ "proto.google.protobuf.Any.prototype.getTypeName = function() {\n"
+ " return this.getTypeUrl().split('/').pop();\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Packs the given message instance into this Any.\n"
+ " * @param {!Uint8Array} serialized The serialized data to pack.\n"
+ " * @param {string} name The type name of this message object.\n"
+ " * @param {string=} opt_typeUrlPrefix the type URL prefix.\n"
+ " */\n"
+ "proto.google.protobuf.Any.prototype.pack = function(serialized, name,\n"
+ " opt_typeUrlPrefix) "
+ "{\n"
+ " if (!opt_typeUrlPrefix) {\n"
+ " opt_typeUrlPrefix = 'type.googleapis.com/';\n"
+ " }\n"
+ "\n"
+ " if (opt_typeUrlPrefix.substr(-1) != '/') {\n"
+ " this.setTypeUrl(opt_typeUrlPrefix + '/' + name);\n"
+ " } else {\n"
+ " this.setTypeUrl(opt_typeUrlPrefix + name);\n"
+ " }\n"
+ "\n"
+ " this.setValue(serialized);\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * @template T\n"
+ " * Unpacks this Any into the given message object.\n"
+ " * @param {function(Uint8Array):T} deserialize Function that will "
+ "deserialize\n"
+ " * the binary data properly.\n"
+ " * @param {string} name The expected type name of this message object.\n"
+ " * @return {?T} If the name matched the expected name, returns the "
+ "deserialized\n"
+ " * object, otherwise returns null.\n"
+ " */\n"
+ "proto.google.protobuf.Any.prototype.unpack = function(deserialize, name) "
+ "{\n"
+ " if (this.getTypeName() == name) {\n"
+ " return deserialize(this.getValue_asU8());\n"
+ " } else {\n"
+ " return null;\n"
+ " }\n"
+ "};\n"},
+ {"timestamp.js",
+ "/* This code will be inserted into generated code for\n"
+ " * google/protobuf/timestamp.proto. */\n"
+ "\n"
+ "/**\n"
+ " * Returns a JavaScript 'Date' object corresponding to this Timestamp.\n"
+ " * @return {!Date}\n"
+ " */\n"
+ "proto.google.protobuf.Timestamp.prototype.toDate = function() {\n"
+ " var seconds = this.getSeconds();\n"
+ " var nanos = this.getNanos();\n"
+ "\n"
+ " return new Date((seconds * 1000) + (nanos / 1000000));\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Sets the value of this Timestamp object to be the given Date.\n"
+ " * @param {!Date} value The value to set.\n"
+ " */\n"
+ "proto.google.protobuf.Timestamp.prototype.fromDate = function(value) {\n"
+ " this.setSeconds(Math.floor(value.getTime() / 1000));\n"
+ " this.setNanos(value.getMilliseconds() * 1000000);\n"
+ "};\n"},
+ {"struct.js",
+ "/* This code will be inserted into generated code for\n"
+ " * google/protobuf/struct.proto. */\n"
+ "\n"
+ "/**\n"
+ " * Typedef representing plain JavaScript values that can go into a\n"
+ " * Struct.\n"
+ " * @typedef {null|number|string|boolean|Array|Object}\n"
+ " */\n"
+ "proto.google.protobuf.JavaScriptValue;\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Converts this Value object to a plain JavaScript value.\n"
+ " * @return {?proto.google.protobuf.JavaScriptValue} a plain JavaScript\n"
+ " * value representing this Struct.\n"
+ " */\n"
+ "proto.google.protobuf.Value.prototype.toJavaScript = function() {\n"
+ " var kindCase = proto.google.protobuf.Value.KindCase;\n"
+ " switch (this.getKindCase()) {\n"
+ " case kindCase.NULL_VALUE:\n"
+ " return null;\n"
+ " case kindCase.NUMBER_VALUE:\n"
+ " return this.getNumberValue();\n"
+ " case kindCase.STRING_VALUE:\n"
+ " return this.getStringValue();\n"
+ " case kindCase.BOOL_VALUE:\n"
+ " return this.getBoolValue();\n"
+ " case kindCase.STRUCT_VALUE:\n"
+ " return this.getStructValue().toJavaScript();\n"
+ " case kindCase.LIST_VALUE:\n"
+ " return this.getListValue().toJavaScript();\n"
+ " default:\n"
+ " throw new Error('Unexpected struct type');\n"
+ " }\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Converts this JavaScript value to a new Value proto.\n"
+ " * @param {!proto.google.protobuf.JavaScriptValue} value The value to\n"
+ " * convert.\n"
+ " * @return {!proto.google.protobuf.Value} The newly constructed value.\n"
+ " */\n"
+ "proto.google.protobuf.Value.fromJavaScript = function(value) {\n"
+ " var ret = new proto.google.protobuf.Value();\n"
+ " switch (goog.typeOf(value)) {\n"
+ " case 'string':\n"
+ " ret.setStringValue(/** @type {string} */ (value));\n"
+ " break;\n"
+ " case 'number':\n"
+ " ret.setNumberValue(/** @type {number} */ (value));\n"
+ " break;\n"
+ " case 'boolean':\n"
+ " ret.setBoolValue(/** @type {boolean} */ (value));\n"
+ " break;\n"
+ " case 'null':\n"
+ " ret.setNullValue(proto.google.protobuf.NullValue.NULL_VALUE);\n"
+ " break;\n"
+ " case 'array':\n"
+ " ret.setListValue(proto.google.protobuf.ListValue.fromJavaScript(\n"
+ " /** @type{!Array} */ (value)));\n"
+ " break;\n"
+ " case 'object':\n"
+ " ret.setStructValue(proto.google.protobuf.Struct.fromJavaScript(\n"
+ " /** @type{!Object} */ (value)));\n"
+ " break;\n"
+ " default:\n"
+ " throw new Error('Unexpected struct type.');\n"
+ " }\n"
+ "\n"
+ " return ret;\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Converts this ListValue object to a plain JavaScript array.\n"
+ " * @return {!Array} a plain JavaScript array representing this List.\n"
+ " */\n"
+ "proto.google.protobuf.ListValue.prototype.toJavaScript = function() {\n"
+ " var ret = [];\n"
+ " var values = this.getValuesList();\n"
+ "\n"
+ " for (var i = 0; i < values.length; i++) {\n"
+ " ret[i] = values[i].toJavaScript();\n"
+ " }\n"
+ "\n"
+ " return ret;\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Constructs a ListValue protobuf from this plain JavaScript array.\n"
+ " * @param {!Array} array a plain JavaScript array\n"
+ " * @return {proto.google.protobuf.ListValue} a new ListValue object\n"
+ " */\n"
+ "proto.google.protobuf.ListValue.fromJavaScript = function(array) {\n"
+ " var ret = new proto.google.protobuf.ListValue();\n"
+ "\n"
+ " for (var i = 0; i < array.length; i++) {\n"
+ " "
+ "ret.addValues(proto.google.protobuf.Value.fromJavaScript(array[i]));\n"
+ " }\n"
+ "\n"
+ " return ret;\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Converts this Struct object to a plain JavaScript object.\n"
+ " * @return {!Object<string, !proto.google.protobuf.JavaScriptValue>} a "
+ "plain\n"
+ " * JavaScript object representing this Struct.\n"
+ " */\n"
+ "proto.google.protobuf.Struct.prototype.toJavaScript = function() {\n"
+ " var ret = {};\n"
+ "\n"
+ " this.getFieldsMap().forEach(function(value, key) {\n"
+ " ret[key] = value.toJavaScript();\n"
+ " });\n"
+ "\n"
+ " return ret;\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Constructs a Struct protobuf from this plain JavaScript object.\n"
+ " * @param {!Object} obj a plain JavaScript object\n"
+ " * @return {proto.google.protobuf.Struct} a new Struct object\n"
+ " */\n"
+ "proto.google.protobuf.Struct.fromJavaScript = function(obj) {\n"
+ " var ret = new proto.google.protobuf.Struct();\n"
+ " var map = ret.getFieldsMap();\n"
+ "\n"
+ " for (var property in obj) {\n"
+ " var val = obj[property];\n"
+ " map.set(property, proto.google.protobuf.Value.fromJavaScript(val));\n"
+ " }\n"
+ "\n"
+ " return ret;\n"
+ "};\n"},
+ {NULL, NULL} // Terminate the list.
+};
diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc
index ef52def3..20aa82c7 100644
--- a/src/google/protobuf/compiler/plugin.pb.cc
+++ b/src/google/protobuf/compiler/plugin.pb.cc
@@ -183,14 +183,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::compiler::_CodeGeneratorResponse_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/compiler/plugin.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, NULL, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -201,7 +201,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 4);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n%google/protobuf/compiler/plugin.proto\022"