|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GOOGLE_PROTOBUF_COMPILER_JS_GENERATOR_H__
|
|
|
#define GOOGLE_PROTOBUF_COMPILER_JS_GENERATOR_H__
|
|
|
|
|
|
#include <string>
|
|
|
#include <set>
|
|
|
|
|
|
#include <google/protobuf/stubs/logging.h>
|
|
|
#include <google/protobuf/stubs/common.h>
|
|
|
#include <google/protobuf/compiler/code_generator.h>
|
|
|
|
|
|
namespace google {
|
|
|
namespace protobuf {
|
|
|
|
|
|
class Descriptor;
|
|
|
class EnumDescriptor;
|
|
|
class FieldDescriptor;
|
|
|
class OneofDescriptor;
|
|
|
class FileDescriptor;
|
|
|
|
|
|
namespace io { class Printer; }
|
|
|
|
|
|
namespace compiler {
|
|
|
namespace js {
|
|
|
|
|
|
struct GeneratorOptions {
|
|
|
|
|
|
string output_dir;
|
|
|
|
|
|
string namespace_prefix;
|
|
|
|
|
|
bool binary;
|
|
|
|
|
|
enum ImportStyle {
|
|
|
kImportClosure,
|
|
|
kImportCommonJs,
|
|
|
kImportBrowser,
|
|
|
kImportEs6,
|
|
|
} import_style;
|
|
|
|
|
|
GeneratorOptions()
|
|
|
: output_dir("."),
|
|
|
namespace_prefix(""),
|
|
|
binary(false),
|
|
|
import_style(kImportClosure),
|
|
|
add_require_for_enums(false),
|
|
|
testonly(false),
|
|
|
library(""),
|
|
|
error_on_name_conflict(false),
|
|
|
extension(".js"),
|
|
|
one_output_file_per_input_file(false),
|
|
|
annotate_code(false) {}
|
|
|
|
|
|
bool ParseFromOptions(
|
|
|
const std::vector< std::pair< string, string > >& options,
|
|
|
string* error);
|
|
|
|
|
|
|
|
|
string GetFileNameExtension() const {
|
|
|
return import_style == kImportClosure ? extension : "_pb.js";
|
|
|
}
|
|
|
|
|
|
enum OutputMode {
|
|
|
|
|
|
kOneOutputFilePerInputFile,
|
|
|
|
|
|
kOneOutputFilePerType,
|
|
|
|
|
|
kEverythingInOneFile,
|
|
|
};
|
|
|
|
|
|
|
|
|
OutputMode output_mode() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool add_require_for_enums;
|
|
|
|
|
|
bool testonly;
|
|
|
|
|
|
|
|
|
string library;
|
|
|
|
|
|
bool error_on_name_conflict;
|
|
|
|
|
|
string extension;
|
|
|
|
|
|
bool one_output_file_per_input_file;
|
|
|
|
|
|
|
|
|
bool annotate_code;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LIBPROTOC_EXPORT Generator : public CodeGenerator {
|
|
|
public:
|
|
|
Generator() {}
|
|
|
virtual ~Generator() {}
|
|
|
|
|
|
virtual bool Generate(const FileDescriptor* file,
|
|
|
const string& parameter,
|
|
|
GeneratorContext* context,
|
|
|
string* error) const {
|
|
|
*error = "Unimplemented Generate() method. Call GenerateAll() instead.";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
virtual bool HasGenerateAll() const { return true; }
|
|
|
|
|
|
virtual bool GenerateAll(const std::vector<const FileDescriptor*>& files,
|
|
|
const string& parameter,
|
|
|
GeneratorContext* context,
|
|
|
string* error) const;
|
|
|
|
|
|
private:
|
|
|
void GenerateHeader(const GeneratorOptions& options,
|
|
|
io::Printer* printer) const;
|
|
|
|
|
|
|
|
|
void FindProvides(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const std::vector<const FileDescriptor*>& file,
|
|
|
std::set<string>* provided) const;
|
|
|
void FindProvidesForFile(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const FileDescriptor* file,
|
|
|
std::set<string>* provided) const;
|
|
|
void FindProvidesForMessage(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc,
|
|
|
std::set<string>* provided) const;
|
|
|
void FindProvidesForEnum(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const EnumDescriptor* enumdesc,
|
|
|
std::set<string>* provided) const;
|
|
|
|
|
|
void FindProvidesForFields(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const std::vector<const FieldDescriptor*>& fields,
|
|
|
std::set<string>* provided) const;
|
|
|
|
|
|
void GenerateProvides(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
std::set<string>* provided) const;
|
|
|
|
|
|
|
|
|
void GenerateTestOnly(const GeneratorOptions& options,
|
|
|
io::Printer* printer) const;
|
|
|
|
|
|
|
|
|
void GenerateRequiresForLibrary(
|
|
|
const GeneratorOptions& options, io::Printer* printer,
|
|
|
const std::vector<const FileDescriptor*>& files,
|
|
|
std::set<string>* provided) const;
|
|
|
void GenerateRequiresForMessage(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc,
|
|
|
std::set<string>* provided) const;
|
|
|
|
|
|
void GenerateRequiresForExtensions(
|
|
|
const GeneratorOptions& options, io::Printer* printer,
|
|
|
const std::vector<const FieldDescriptor*>& fields,
|
|
|
std::set<string>* provided) const;
|
|
|
void GenerateRequiresImpl(const GeneratorOptions& options,
|
|
|
io::Printer* printer, std::set<string>* required,
|
|
|
std::set<string>* forwards,
|
|
|
std::set<string>* provided, bool require_jspb,
|
|
|
bool require_extension, bool require_map) const;
|
|
|
void FindRequiresForMessage(const GeneratorOptions& options,
|
|
|
const Descriptor* desc,
|
|
|
std::set<string>* required,
|
|
|
std::set<string>* forwards,
|
|
|
bool* have_message) const;
|
|
|
void FindRequiresForField(const GeneratorOptions& options,
|
|
|
const FieldDescriptor* field,
|
|
|
std::set<string>* required,
|
|
|
std::set<string>* forwards) const;
|
|
|
void FindRequiresForExtension(const GeneratorOptions& options,
|
|
|
const FieldDescriptor* field,
|
|
|
std::set<string>* required,
|
|
|
std::set<string>* forwards) const;
|
|
|
|
|
|
void GenerateFile(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const FileDescriptor* file) const;
|
|
|
|
|
|
|
|
|
|
|
|
void GenerateFilesInDepOrder(
|
|
|
const GeneratorOptions& options, io::Printer* printer,
|
|
|
const std::vector<const FileDescriptor*>& file) const;
|
|
|
|
|
|
void GenerateFileAndDeps(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const FileDescriptor* root,
|
|
|
std::set<const FileDescriptor*>* all_files,
|
|
|
std::set<const FileDescriptor*>* generated) const;
|
|
|
|
|
|
|
|
|
void GenerateClassesAndEnums(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const FileDescriptor* file) const;
|
|
|
|
|
|
void GenerateFieldValueExpression(io::Printer* printer,
|
|
|
const char* obj_reference,
|
|
|
const FieldDescriptor* field,
|
|
|
bool use_default) const;
|
|
|
|
|
|
|
|
|
void GenerateClass(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateClassConstructor(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateClassFieldInfo(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateClassXid(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateOneofCaseDefinition(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const OneofDescriptor* oneof) const;
|
|
|
void GenerateClassToObject(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateClassFieldToObject(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const FieldDescriptor* field) const;
|
|
|
void GenerateClassFromObject(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateClassFieldFromObject(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const FieldDescriptor* field) const;
|
|
|
void GenerateClassClone(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateClassRegistration(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateClassFields(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateClassField(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const FieldDescriptor* desc) const;
|
|
|
void GenerateClassExtensionFieldInfo(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateClassDeserialize(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateClassDeserializeBinary(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateClassDeserializeBinaryField(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const FieldDescriptor* field) const;
|
|
|
void GenerateClassSerializeBinary(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const Descriptor* desc) const;
|
|
|
void GenerateClassSerializeBinaryField(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const FieldDescriptor* field) const;
|
|
|
|
|
|
|
|
|
void GenerateEnum(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const EnumDescriptor* enumdesc) const;
|
|
|
|
|
|
|
|
|
void GenerateExtension(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const FieldDescriptor* field) const;
|
|
|
|
|
|
|
|
|
void GenerateRepeatedPrimitiveHelperMethods(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const FieldDescriptor* field,
|
|
|
bool untyped) const;
|
|
|
|
|
|
|
|
|
void GenerateRepeatedMessageHelperMethods(const GeneratorOptions& options,
|
|
|
io::Printer* printer,
|
|
|
const FieldDescriptor* field) const;
|
|
|
|
|
|
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Generator);
|
|
|
};
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
#endif
|
|
|
|