Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-27 09:30:24

0001 /*
0002  * Copyright 2023 Google Inc. All rights reserved.
0003  *
0004  * Licensed under the Apache License, Version 2.0 (the "License");
0005  * you may not use this file except in compliance with the License.
0006  * You may obtain a copy of the License at
0007  *
0008  *     http://www.apache.org/licenses/LICENSE-2.0
0009  *
0010  * Unless required by applicable law or agreed to in writing, software
0011  * distributed under the License is distributed on an "AS IS" BASIS,
0012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013  * See the License for the specific language governing permissions and
0014  * limitations under the License.
0015  */
0016 
0017 #ifndef FLATBUFFERS_CODE_GENERATOR_H_
0018 #define FLATBUFFERS_CODE_GENERATOR_H_
0019 
0020 #include <string>
0021 
0022 #include "flatbuffers/idl.h"
0023 
0024 namespace flatbuffers {
0025 
0026 struct CodeGenOptions {
0027   std::string output_path;
0028 };
0029 
0030 // A code generator interface for producing converting flatbuffer schema into
0031 // code.
0032 class CodeGenerator {
0033  public:
0034   virtual ~CodeGenerator() = default;
0035 
0036   enum Status {
0037     OK = 0,
0038     ERROR = 1,
0039     FAILED_VERIFICATION = 2,
0040     NOT_IMPLEMENTED = 3
0041   };
0042 
0043   std::string status_detail;
0044 
0045   // Generate code from the provided `parser`.
0046   //
0047   // DEPRECATED: prefer using the other overload of GenerateCode for bfbs.
0048   virtual Status GenerateCode(const Parser &parser, const std::string &path,
0049                               const std::string &filename) = 0;
0050 
0051   // Generate code from the provided `parser` and place it in the output.
0052   virtual Status GenerateCodeString(const Parser &parser,
0053                                     const std::string &filename,
0054                                     std::string &output) {
0055     (void)parser;
0056     (void)filename;
0057     (void)output;
0058     return Status::NOT_IMPLEMENTED;
0059   }
0060 
0061   // Generate code from the provided `buffer` of given `length`. The buffer is a
0062   // serialized reflection.fbs.
0063   virtual Status GenerateCode(const uint8_t *buffer, int64_t length,
0064                               const CodeGenOptions &options) = 0;
0065 
0066   virtual Status GenerateMakeRule(const Parser &parser, const std::string &path,
0067                                   const std::string &filename,
0068                                   std::string &output) = 0;
0069 
0070   virtual Status GenerateGrpcCode(const Parser &parser, const std::string &path,
0071                                   const std::string &filename) = 0;
0072 
0073   virtual Status GenerateRootFile(const Parser &parser,
0074                                   const std::string &path) = 0;
0075 
0076   virtual bool IsSchemaOnly() const = 0;
0077 
0078   virtual bool SupportsBfbsGeneration() const = 0;
0079 
0080   virtual bool SupportsRootFileGeneration() const = 0;
0081 
0082   virtual IDLOptions::Language Language() const = 0;
0083 
0084   virtual std::string LanguageName() const = 0;
0085 
0086  protected:
0087   CodeGenerator() = default;
0088 
0089  private:
0090   // Copying is not supported.
0091   CodeGenerator(const CodeGenerator &) = delete;
0092   CodeGenerator &operator=(const CodeGenerator &) = delete;
0093 };
0094 
0095 }  // namespace flatbuffers
0096 
0097 #endif  // FLATBUFFERS_CODE_GENERATOR_H_