summaryrefslogtreecommitdiffstats
path: root/contrib/libs/flatbuffers/src/idl_gen_php.cpp
diff options
context:
space:
mode:
authorreshilkin <[email protected]>2023-08-11 12:01:29 +0300
committerreshilkin <[email protected]>2023-08-11 13:00:03 +0300
commit5894c3ce50a49a9f9bc1c0316e2ef0708e3a7ef8 (patch)
tree624e56690fe689e569d05612fa0e92f2c5bdb75b /contrib/libs/flatbuffers/src/idl_gen_php.cpp
parent1eb895279c52b0d2505a31b79ad326b56d0b2681 (diff)
Update contrib/libs/flatbuffers to 23.5.9
Diffstat (limited to 'contrib/libs/flatbuffers/src/idl_gen_php.cpp')
-rw-r--r--contrib/libs/flatbuffers/src/idl_gen_php.cpp120
1 files changed, 93 insertions, 27 deletions
diff --git a/contrib/libs/flatbuffers/src/idl_gen_php.cpp b/contrib/libs/flatbuffers/src/idl_gen_php.cpp
index dd3ed681890..a245b1a7c3a 100644
--- a/contrib/libs/flatbuffers/src/idl_gen_php.cpp
+++ b/contrib/libs/flatbuffers/src/idl_gen_php.cpp
@@ -16,6 +16,8 @@
// independent from idl_parser, since this code is not needed for most clients
+#include "idl_gen_php.h"
+
#include <string>
#include "flatbuffers/code_generators.h"
@@ -181,7 +183,7 @@ class PhpGenerator : public BaseGenerator {
code += Indent + " * @return int\n";
code += Indent + " */\n";
code += Indent + "public function get";
- code += MakeCamel(field.name) + "Length()\n";
+ code += ConvertCase(field.name, Case::kUpperCamel) + "Length()\n";
code += Indent + "{\n";
code += Indent + Indent + "$o = $this->__offset(";
code += NumToString(field.value.offset) + ");\n";
@@ -198,7 +200,7 @@ class PhpGenerator : public BaseGenerator {
code += Indent + " * @return string\n";
code += Indent + " */\n";
code += Indent + "public function get";
- code += MakeCamel(field.name) + "Bytes()\n";
+ code += ConvertCase(field.name, Case::kUpperCamel) + "Bytes()\n";
code += Indent + "{\n";
code += Indent + Indent + "return $this->__vector_as_bytes(";
code += NumToString(field.value.offset) + ");\n";
@@ -216,12 +218,12 @@ class PhpGenerator : public BaseGenerator {
code += GenTypeGet(field.value.type) + "\n";
code += Indent + " */\n";
code += Indent + "public function " + getter;
- code += MakeCamel(field.name) + "()\n";
+ code += ConvertCase(field.name, Case::kUpperCamel) + "()\n";
code += Indent + "{\n";
code += Indent + Indent + "return ";
code += "$this->bb->get";
- code += MakeCamel(GenTypeGet(field.value.type));
+ code += ConvertCase(GenTypeGet(field.value.type), Case::kUpperCamel);
code += "($this->bb_pos + ";
code += NumToString(field.value.offset) + ")";
code += ";\n";
@@ -237,14 +239,15 @@ class PhpGenerator : public BaseGenerator {
code += Indent + " * @return " + GenTypeGet(field.value.type) + "\n";
code += Indent + " */\n";
code += Indent + "public function get";
- code += MakeCamel(field.name);
+ code += ConvertCase(field.name, Case::kUpperCamel);
code += "()\n";
code += Indent + "{\n";
code += Indent + Indent + "$o = $this->__offset(" +
NumToString(field.value.offset) + ");\n" + Indent + Indent +
"return $o != 0 ? ";
code += "$this->bb->get";
- code += MakeCamel(GenTypeGet(field.value.type)) + "($o + $this->bb_pos)";
+ code += ConvertCase(GenTypeGet(field.value.type), Case::kUpperCamel) +
+ "($o + $this->bb_pos)";
code += " : " + GenDefaultValue(field.value) + ";\n";
code += Indent + "}\n\n";
}
@@ -258,7 +261,7 @@ class PhpGenerator : public BaseGenerator {
code += Indent + " * @return " + GenTypeGet(field.value.type) + "\n";
code += Indent + " */\n";
code += Indent + "public function get";
- code += MakeCamel(field.name) + "()\n";
+ code += ConvertCase(field.name, Case::kUpperCamel) + "()\n";
code += Indent + "{\n";
code += Indent + Indent + "$obj = new ";
code += GenTypeGet(field.value.type) + "();\n";
@@ -274,11 +277,12 @@ class PhpGenerator : public BaseGenerator {
std::string &code = *code_ptr;
code += Indent + "public function get";
- code += MakeCamel(field.name);
+ code += ConvertCase(field.name, Case::kUpperCamel);
code += "()\n";
code += Indent + "{\n";
code += Indent + Indent + "$obj = new ";
- code += MakeCamel(GenTypeGet(field.value.type)) + "();\n";
+ code +=
+ ConvertCase(GenTypeGet(field.value.type), Case::kUpperCamel) + "();\n";
code += Indent + Indent + "$o = $this->__offset(" +
NumToString(field.value.offset) + ");\n";
code += Indent + Indent;
@@ -296,7 +300,7 @@ class PhpGenerator : public BaseGenerator {
void GetStringField(const FieldDef &field, std::string *code_ptr) {
std::string &code = *code_ptr;
code += Indent + "public function get";
- code += MakeCamel(field.name);
+ code += ConvertCase(field.name, Case::kUpperCamel);
code += "()\n";
code += Indent + "{\n";
code += Indent + Indent + "$o = $this->__offset(" +
@@ -315,7 +319,7 @@ class PhpGenerator : public BaseGenerator {
code += Indent + " * @return" + GenTypeBasic(field.value.type) + "\n";
code += Indent + " */\n";
code += Indent + "public function get";
- code += MakeCamel(field.name) + "($obj)\n";
+ code += ConvertCase(field.name, Case::kUpperCamel) + "($obj)\n";
code += Indent + "{\n";
code += Indent + Indent + "$o = $this->__offset(" +
NumToString(field.value.offset) + ");\n";
@@ -334,13 +338,14 @@ class PhpGenerator : public BaseGenerator {
code += Indent + " * @return" + GenTypeBasic(field.value.type) + "\n";
code += Indent + " */\n";
code += Indent + "public function get";
- code += MakeCamel(field.name);
+ code += ConvertCase(field.name, Case::kUpperCamel);
code += "($j)\n";
code += Indent + "{\n";
code += Indent + Indent + "$o = $this->__offset(" +
NumToString(field.value.offset) + ");\n";
code += Indent + Indent + "$obj = new ";
- code += MakeCamel(GenTypeGet(field.value.type)) + "();\n";
+ code +=
+ ConvertCase(GenTypeGet(field.value.type), Case::kUpperCamel) + "();\n";
switch (field.value.type.base_type) {
case BASE_TYPE_STRUCT:
@@ -395,7 +400,7 @@ class PhpGenerator : public BaseGenerator {
code += Indent + " * @return " + GenTypeGet(field.value.type) + "\n";
code += Indent + " */\n";
code += Indent + "public function get";
- code += MakeCamel(field.name);
+ code += ConvertCase(field.name, Case::kUpperCamel);
code += "($j)\n";
code += Indent + "{\n";
code += Indent + Indent + "$o = $this->__offset(" +
@@ -408,7 +413,7 @@ class PhpGenerator : public BaseGenerator {
code += GenDefaultValue(field.value) + ";\n";
} else {
code += Indent + Indent + "return $o != 0 ? $this->bb->get";
- code += MakeCamel(GenTypeGet(field.value.type));
+ code += ConvertCase(GenTypeGet(field.value.type), Case::kUpperCamel);
code += "($this->__vector($o) + $j * ";
code += NumToString(InlineSize(vectortype)) + ") : ";
code += GenDefaultValue(field.value) + ";\n";
@@ -427,7 +432,7 @@ class PhpGenerator : public BaseGenerator {
code += Indent + " * @return " + GenTypeGet(field.value.type) + "\n";
code += Indent + " */\n";
code += Indent + "public function get";
- code += MakeCamel(field.name);
+ code += ConvertCase(field.name, Case::kUpperCamel);
code += "($j, $obj)\n";
code += Indent + "{\n";
code += Indent + Indent + "$o = $this->__offset(" +
@@ -455,7 +460,7 @@ class PhpGenerator : public BaseGenerator {
} else {
std::string &code = *code_ptr;
code += std::string(", $") + nameprefix;
- code += MakeCamel(field.name, false);
+ code += ConvertCase(field.name, Case::kLowerCamel);
}
}
}
@@ -480,7 +485,8 @@ class PhpGenerator : public BaseGenerator {
(nameprefix + (field.name + "_")).c_str(), code_ptr);
} else {
code += Indent + Indent + "$builder->put" + GenMethod(field) + "($";
- code += nameprefix + MakeCamel(field.name, false) + ");\n";
+ code +=
+ nameprefix + ConvertCase(field.name, Case::kLowerCamel) + ");\n";
}
}
}
@@ -528,7 +534,8 @@ class PhpGenerator : public BaseGenerator {
if (field.deprecated) continue;
code += Indent + Indent + "self::add";
- code += MakeCamel(field.name) + "($builder, $" + field.name + ");\n";
+ code += ConvertCase(field.name, Case::kUpperCamel) + "($builder, $" +
+ field.name + ");\n";
}
code += Indent + Indent + "$o = $builder->endObject();\n";
@@ -557,16 +564,16 @@ class PhpGenerator : public BaseGenerator {
code += Indent + " * @return void\n";
code += Indent + " */\n";
code += Indent + "public static function ";
- code += "add" + MakeCamel(field.name);
+ code += "add" + ConvertCase(field.name, Case::kUpperCamel);
code += "(FlatBufferBuilder $builder, ";
- code += "$" + MakeCamel(field.name, false);
+ code += "$" + ConvertCase(field.name, Case::kLowerCamel);
code += ")\n";
code += Indent + "{\n";
code += Indent + Indent + "$builder->add";
code += GenMethod(field) + "X(";
code += NumToString(offset) + ", ";
- code += "$" + MakeCamel(field.name, false);
+ code += "$" + ConvertCase(field.name, Case::kLowerCamel);
code += ", ";
if (field.value.type.base_type == BASE_TYPE_BOOL) {
@@ -591,7 +598,7 @@ class PhpGenerator : public BaseGenerator {
code += Indent + " * @return int vector offset\n";
code += Indent + " */\n";
code += Indent + "public static function create";
- code += MakeCamel(field.name);
+ code += ConvertCase(field.name, Case::kUpperCamel);
code += "Vector(FlatBufferBuilder $builder, array $data)\n";
code += Indent + "{\n";
code += Indent + Indent + "$builder->startVector(";
@@ -603,7 +610,8 @@ class PhpGenerator : public BaseGenerator {
if (IsScalar(field.value.type.VectorType().base_type)) {
code += Indent + Indent + Indent;
code += "$builder->put";
- code += MakeCamel(GenTypeBasic(field.value.type.VectorType()));
+ code += ConvertCase(GenTypeBasic(field.value.type.VectorType()),
+ Case::kUpperCamel);
code += "($data[$i]);\n";
} else {
code += Indent + Indent + Indent;
@@ -619,7 +627,7 @@ class PhpGenerator : public BaseGenerator {
code += Indent + " * @return void\n";
code += Indent + " */\n";
code += Indent + "public static function start";
- code += MakeCamel(field.name);
+ code += ConvertCase(field.name, Case::kUpperCamel);
code += "Vector(FlatBufferBuilder $builder, $numElems)\n";
code += Indent + "{\n";
code += Indent + Indent + "$builder->startVector(";
@@ -726,7 +734,7 @@ class PhpGenerator : public BaseGenerator {
if (field.value.type.base_type == BASE_TYPE_UNION) {
std::string &code = *code_ptr;
code += Indent + "public static function add";
- code += MakeCamel(field.name);
+ code += ConvertCase(field.name, Case::kUpperCamel);
code += "(FlatBufferBuilder $builder, $offset)\n";
code += Indent + "{\n";
code += Indent + Indent + "$builder->addOffsetX(";
@@ -853,7 +861,7 @@ class PhpGenerator : public BaseGenerator {
// Returns the method name for use with add/put calls.
static std::string GenMethod(const FieldDef &field) {
return IsScalar(field.value.type.base_type)
- ? MakeCamel(GenTypeBasic(field.value.type))
+ ? ConvertCase(GenTypeBasic(field.value.type), Case::kUpperCamel)
: (IsStruct(field.value.type) ? "Struct" : "Offset");
}
@@ -936,4 +944,62 @@ bool GeneratePhp(const Parser &parser, const std::string &path,
php::PhpGenerator generator(parser, path, file_name);
return generator.generate();
}
+
+namespace {
+
+class PhpCodeGenerator : public CodeGenerator {
+ public:
+ Status GenerateCode(const Parser &parser, const std::string &path,
+ const std::string &filename) override {
+ if (!GeneratePhp(parser, path, filename)) { return Status::ERROR; }
+ return Status::OK;
+ }
+
+ Status GenerateCode(const uint8_t *buffer, int64_t length) override {
+ (void)buffer;
+ (void)length;
+ return Status::NOT_IMPLEMENTED;
+ }
+
+ Status GenerateMakeRule(const Parser &parser, const std::string &path,
+ const std::string &filename,
+ std::string &output) override {
+ (void)parser;
+ (void)path;
+ (void)filename;
+ (void)output;
+ return Status::NOT_IMPLEMENTED;
+ }
+
+ Status GenerateGrpcCode(const Parser &parser, const std::string &path,
+ const std::string &filename) override {
+ (void)parser;
+ (void)path;
+ (void)filename;
+ return Status::NOT_IMPLEMENTED;
+ }
+
+ Status GenerateRootFile(const Parser &parser,
+ const std::string &path) override {
+ (void)parser;
+ (void)path;
+ return Status::NOT_IMPLEMENTED;
+ }
+
+ bool IsSchemaOnly() const override { return true; }
+
+ bool SupportsBfbsGeneration() const override { return false; }
+
+ bool SupportsRootFileGeneration() const override { return false; }
+
+ IDLOptions::Language Language() const override { return IDLOptions::kPhp; }
+
+ std::string LanguageName() const override { return "Php"; }
+};
+} // namespace
+
+std::unique_ptr<CodeGenerator> NewPhpCodeGenerator() {
+ return std::unique_ptr<PhpCodeGenerator>(new PhpCodeGenerator());
+}
+
} // namespace flatbuffers