| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // particular proto file in a particular language. A number of these may | 59 // particular proto file in a particular language. A number of these may |
| 60 // be registered with CommandLineInterface to support various languages. | 60 // be registered with CommandLineInterface to support various languages. |
| 61 class LIBPROTOC_EXPORT CodeGenerator { | 61 class LIBPROTOC_EXPORT CodeGenerator { |
| 62 public: | 62 public: |
| 63 inline CodeGenerator() {} | 63 inline CodeGenerator() {} |
| 64 virtual ~CodeGenerator(); | 64 virtual ~CodeGenerator(); |
| 65 | 65 |
| 66 // Generates code for the given proto file, generating one or more files in | 66 // Generates code for the given proto file, generating one or more files in |
| 67 // the given output directory. | 67 // the given output directory. |
| 68 // | 68 // |
| 69 // A parameter to be passed to the generator can be specified on the | 69 // A parameter to be passed to the generator can be specified on the command |
| 70 // command line. This is intended to be used by Java and similar languages | 70 // line. This is intended to be used to pass generator specific parameters. |
| 71 // to specify which specific class from the proto file is to be generated, | 71 // It is empty if no parameter was given. ParseGeneratorParameter (below), |
| 72 // though it could have other uses as well. It is empty if no parameter was | 72 // can be used to accept multiple parameters within the single parameter |
| 73 // given. | 73 // command line flag. |
| 74 // | 74 // |
| 75 // Returns true if successful. Otherwise, sets *error to a description of | 75 // Returns true if successful. Otherwise, sets *error to a description of |
| 76 // the problem (e.g. "invalid parameter") and returns false. | 76 // the problem (e.g. "invalid parameter") and returns false. |
| 77 virtual bool Generate(const FileDescriptor* file, | 77 virtual bool Generate(const FileDescriptor* file, |
| 78 const string& parameter, | 78 const string& parameter, |
| 79 GeneratorContext* generator_context, | 79 GeneratorContext* generator_context, |
| 80 string* error) const = 0; | 80 string* error) const = 0; |
| 81 | 81 |
| 82 // Generates code for all given proto files, generating one or more files in | 82 // Generates code for all given proto files. |
| 83 // the given output directory. | |
| 84 // | 83 // |
| 85 // This method should be called instead of |Generate()| when | 84 // WARNING: The canonical code generator design produces one or two output |
| 86 // |HasGenerateAll()| returns |true|. It is used to emulate legacy semantics | 85 // files per input .proto file, and we do not wish to encourage alternate |
| 87 // when more than one `.proto` file is specified on one compiler invocation. | 86 // designs. |
| 88 // | |
| 89 // WARNING: Please do not use unless legacy semantics force the code generator | |
| 90 // to produce a single output file for all input files, or otherwise require | |
| 91 // an examination of all input files first. The canonical code generator | |
| 92 // design produces one output file per input .proto file, and we do not wish | |
| 93 // to encourage alternate designs. | |
| 94 // | 87 // |
| 95 // A parameter is given as passed on the command line, as in |Generate()| | 88 // A parameter is given as passed on the command line, as in |Generate()| |
| 96 // above. | 89 // above. |
| 97 // | 90 // |
| 98 // Returns true if successful. Otherwise, sets *error to a description of | 91 // Returns true if successful. Otherwise, sets *error to a description of |
| 99 // the problem (e.g. "invalid parameter") and returns false. | 92 // the problem (e.g. "invalid parameter") and returns false. |
| 100 virtual bool GenerateAll(const vector<const FileDescriptor*>& files, | 93 virtual bool GenerateAll(const vector<const FileDescriptor*>& files, |
| 101 const string& parameter, | 94 const string& parameter, |
| 102 GeneratorContext* generator_context, | 95 GeneratorContext* generator_context, |
| 103 string* error) const { | 96 string* error) const; |
| 104 *error = "Unimplemented GenerateAll() method."; | |
| 105 return false; | |
| 106 } | |
| 107 | 97 |
| 108 // Returns true if the code generator expects to receive all FileDescriptors | 98 // This is no longer used, but this class is part of the opensource protobuf |
| 109 // at once (via |GenerateAll()|), rather than one at a time (via | 99 // library, so it has to remain to keep vtables the same for the current |
| 110 // |Generate()|). This is required to implement legacy semantics. | 100 // version of the library. When protobufs does a api breaking change, the |
| 111 virtual bool HasGenerateAll() const { return false; } | 101 // method can be removed. |
| 102 virtual bool HasGenerateAll() const { return true; } |
| 112 | 103 |
| 113 private: | 104 private: |
| 114 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodeGenerator); | 105 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodeGenerator); |
| 115 }; | 106 }; |
| 116 | 107 |
| 117 // CodeGenerators generate one or more files in a given directory. This | 108 // CodeGenerators generate one or more files in a given directory. This |
| 118 // abstract interface represents the directory to which the CodeGenerator is | 109 // abstract interface represents the directory to which the CodeGenerator is |
| 119 // to write and other information about the context in which the Generator | 110 // to write and other information about the context in which the Generator |
| 120 // runs. | 111 // runs. |
| 121 class LIBPROTOC_EXPORT GeneratorContext { | 112 class LIBPROTOC_EXPORT GeneratorContext { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // parses to the pairs: | 158 // parses to the pairs: |
| 168 // ("foo", "bar"), ("baz", ""), ("qux", "corge") | 159 // ("foo", "bar"), ("baz", ""), ("qux", "corge") |
| 169 extern void ParseGeneratorParameter(const string&, | 160 extern void ParseGeneratorParameter(const string&, |
| 170 vector<pair<string, string> >*); | 161 vector<pair<string, string> >*); |
| 171 | 162 |
| 172 } // namespace compiler | 163 } // namespace compiler |
| 173 } // namespace protobuf | 164 } // namespace protobuf |
| 174 | 165 |
| 175 } // namespace google | 166 } // namespace google |
| 176 #endif // GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ | 167 #endif // GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ |
| OLD | NEW |