Commit 95004218 authored by Vladimir Glavnyy's avatar Vladimir Glavnyy Committed by Wouter van Oortmerssen

Fix multi-line comments for cpp enums (#5345) (#5346)

- fix CSharp comments generation
- fix Python comments generation
- fix Lua comments generation
- fix PHP comments generation
- fix Dart comments generation
- add brief description of Color enum
- add multi-line comments to the Monster:Color
parent bc7ede8f
...@@ -948,7 +948,6 @@ class CppGenerator : public BaseGenerator { ...@@ -948,7 +948,6 @@ class CppGenerator : public BaseGenerator {
void GenEnum(const EnumDef &enum_def) { void GenEnum(const EnumDef &enum_def) {
code_.SetValue("ENUM_NAME", Name(enum_def)); code_.SetValue("ENUM_NAME", Name(enum_def));
code_.SetValue("BASE_TYPE", GenTypeBasic(enum_def.underlying_type, false)); code_.SetValue("BASE_TYPE", GenTypeBasic(enum_def.underlying_type, false));
code_.SetValue("SEP", "");
GenComment(enum_def.doc_comment); GenComment(enum_def.doc_comment);
code_ += GenEnumDecl(enum_def) + "\\"; code_ += GenEnumDecl(enum_def) + "\\";
...@@ -961,19 +960,18 @@ class CppGenerator : public BaseGenerator { ...@@ -961,19 +960,18 @@ class CppGenerator : public BaseGenerator {
if (add_type) code_ += " : {{BASE_TYPE}}\\"; if (add_type) code_ += " : {{BASE_TYPE}}\\";
code_ += " {"; code_ += " {";
code_.SetValue("SEP", ",");
auto add_sep = false;
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) { for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
const auto &ev = **it; const auto &ev = **it;
if (!ev.doc_comment.empty()) { if (add_sep) code_ += "{{SEP}}";
auto prefix = code_.GetValue("SEP") + " "; GenComment(ev.doc_comment, " ");
GenComment(ev.doc_comment, prefix.c_str());
code_.SetValue("SEP", "");
}
code_.SetValue("KEY", GenEnumValDecl(enum_def, Name(ev))); code_.SetValue("KEY", GenEnumValDecl(enum_def, Name(ev)));
code_.SetValue("VALUE", code_.SetValue("VALUE",
NumToStringCpp(enum_def.ToString(ev), NumToStringCpp(enum_def.ToString(ev),
enum_def.underlying_type.base_type)); enum_def.underlying_type.base_type));
code_ += "{{SEP}} {{KEY}} = {{VALUE}}\\"; code_ += " {{KEY}} = {{VALUE}}\\";
code_.SetValue("SEP", ",\n"); add_sep = true;
} }
const EnumVal *minv = enum_def.MinValue(); const EnumVal *minv = enum_def.MinValue();
const EnumVal *maxv = enum_def.MaxValue(); const EnumVal *maxv = enum_def.MaxValue();
......
...@@ -181,7 +181,6 @@ class DartGenerator : public BaseGenerator { ...@@ -181,7 +181,6 @@ class DartGenerator : public BaseGenerator {
} }
auto &code = *code_ptr; auto &code = *code_ptr;
if (indent) code += indent;
for (auto it = dc.begin(); it != dc.end(); ++it) { for (auto it = dc.begin(); it != dc.end(); ++it) {
if (indent) code += indent; if (indent) code += indent;
...@@ -495,7 +494,7 @@ class DartGenerator : public BaseGenerator { ...@@ -495,7 +494,7 @@ class DartGenerator : public BaseGenerator {
std::string type_name = GenDartTypeName( std::string type_name = GenDartTypeName(
field.value.type, struct_def.defined_namespace, field, false); field.value.type, struct_def.defined_namespace, field, false);
GenDocComment(field.doc_comment, &code, ""); GenDocComment(field.doc_comment, &code, "", " ");
code += " " + type_name + " get " + field_name; code += " " + type_name + " get " + field_name;
if (field.value.type.base_type == BASE_TYPE_UNION) { if (field.value.type.base_type == BASE_TYPE_UNION) {
......
...@@ -510,17 +510,17 @@ class GeneralGenerator : public BaseGenerator { ...@@ -510,17 +510,17 @@ class GeneralGenerator : public BaseGenerator {
std::string &code = *code_ptr; std::string &code = *code_ptr;
if (enum_def.generated) return; if (enum_def.generated) return;
// In C# this indicates enumeration values can be treated as bit flags.
if (lang_.language == IDLOptions::kCSharp && enum_def.attributes.Lookup("bit_flags")) {
code += "[System.FlagsAttribute]\n";
}
// Generate enum definitions of the form: // Generate enum definitions of the form:
// public static (final) int name = value; // public static (final) int name = value;
// In Java, we use ints rather than the Enum feature, because we want them // In Java, we use ints rather than the Enum feature, because we want them
// to map directly to how they're used in C/C++ and file formats. // to map directly to how they're used in C/C++ and file formats.
// That, and Java Enums are expensive, and not universally liked. // That, and Java Enums are expensive, and not universally liked.
GenComment(enum_def.doc_comment, code_ptr, &lang_.comment_config); GenComment(enum_def.doc_comment, code_ptr, &lang_.comment_config);
// In C# this indicates enumeration values can be treated as bit flags.
if (lang_.language == IDLOptions::kCSharp && enum_def.attributes.Lookup("bit_flags")) {
code += "[System.FlagsAttribute]\n";
}
if (enum_def.attributes.Lookup("private")) { if (enum_def.attributes.Lookup("private")) {
// For Java, we leave the enum unmarked to indicate package-private // For Java, we leave the enum unmarked to indicate package-private
// For C# we mark the enum as internal // For C# we mark the enum as internal
...@@ -547,7 +547,8 @@ class GeneralGenerator : public BaseGenerator { ...@@ -547,7 +547,8 @@ class GeneralGenerator : public BaseGenerator {
code += lang_.const_decl; code += lang_.const_decl;
code += GenTypeBasic(enum_def.underlying_type, false); code += GenTypeBasic(enum_def.underlying_type, false);
} }
code += " " + ev.name + " = "; code += (lang_.language == IDLOptions::kJava) ? " " : " ";
code += ev.name + " = ";
code += enum_def.ToString(ev); code += enum_def.ToString(ev);
code += lang_.enum_separator; code += lang_.enum_separator;
} }
......
...@@ -29,6 +29,7 @@ namespace flatbuffers { ...@@ -29,6 +29,7 @@ namespace flatbuffers {
namespace lua { namespace lua {
// Hardcode spaces per indentation. // Hardcode spaces per indentation.
const CommentConfig def_comment = { nullptr, "--", nullptr };
const char * Indent = " "; const char * Indent = " ";
const char * Comment = "-- "; const char * Comment = "-- ";
const char * End = "end\n"; const char * End = "end\n";
...@@ -472,7 +473,7 @@ namespace lua { ...@@ -472,7 +473,7 @@ namespace lua {
// Generate a struct field, conditioned on its child type(s). // Generate a struct field, conditioned on its child type(s).
void GenStructAccessor(const StructDef &struct_def, void GenStructAccessor(const StructDef &struct_def,
const FieldDef &field, std::string *code_ptr) { const FieldDef &field, std::string *code_ptr) {
GenComment(field.doc_comment, code_ptr, nullptr, Comment); GenComment(field.doc_comment, code_ptr, &def_comment);
if (IsScalar(field.value.type.base_type)) { if (IsScalar(field.value.type.base_type)) {
if (struct_def.fixed) { if (struct_def.fixed) {
GetScalarFieldOfStruct(struct_def, field, code_ptr); GetScalarFieldOfStruct(struct_def, field, code_ptr);
...@@ -535,7 +536,7 @@ namespace lua { ...@@ -535,7 +536,7 @@ namespace lua {
void GenStruct(const StructDef &struct_def, std::string *code_ptr) { void GenStruct(const StructDef &struct_def, std::string *code_ptr) {
if (struct_def.generated) return; if (struct_def.generated) return;
GenComment(struct_def.doc_comment, code_ptr, nullptr, Comment); GenComment(struct_def.doc_comment, code_ptr, &def_comment);
BeginClass(struct_def, code_ptr); BeginClass(struct_def, code_ptr);
GenerateNewObjectPrototype(struct_def, code_ptr); GenerateNewObjectPrototype(struct_def, code_ptr);
...@@ -571,12 +572,12 @@ namespace lua { ...@@ -571,12 +572,12 @@ namespace lua {
void GenEnum(const EnumDef &enum_def, std::string *code_ptr) { void GenEnum(const EnumDef &enum_def, std::string *code_ptr) {
if (enum_def.generated) return; if (enum_def.generated) return;
GenComment(enum_def.doc_comment, code_ptr, nullptr, Comment); GenComment(enum_def.doc_comment, code_ptr, &def_comment);
BeginEnum(NormalizedName(enum_def), code_ptr); BeginEnum(NormalizedName(enum_def), code_ptr);
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
++it) { ++it) {
auto &ev = **it; auto &ev = **it;
GenComment(ev.doc_comment, code_ptr, nullptr, Comment); GenComment(ev.doc_comment, code_ptr, &def_comment, Indent);
EnumMember(enum_def, ev, code_ptr); EnumMember(enum_def, ev, code_ptr);
} }
EndEnum(code_ptr); EndEnum(code_ptr);
......
...@@ -673,7 +673,7 @@ class PhpGenerator : public BaseGenerator { ...@@ -673,7 +673,7 @@ class PhpGenerator : public BaseGenerator {
// Generate a struct field, conditioned on its child type(s). // Generate a struct field, conditioned on its child type(s).
void GenStructAccessor(const StructDef &struct_def, const FieldDef &field, void GenStructAccessor(const StructDef &struct_def, const FieldDef &field,
std::string *code_ptr) { std::string *code_ptr) {
GenComment(field.doc_comment, code_ptr, nullptr); GenComment(field.doc_comment, code_ptr, nullptr, Indent.c_str());
if (IsScalar(field.value.type.base_type)) { if (IsScalar(field.value.type.base_type)) {
if (struct_def.fixed) { if (struct_def.fixed) {
...@@ -818,7 +818,7 @@ class PhpGenerator : public BaseGenerator { ...@@ -818,7 +818,7 @@ class PhpGenerator : public BaseGenerator {
BeginEnum(enum_def.name, code_ptr); BeginEnum(enum_def.name, code_ptr);
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) { for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
auto &ev = **it; auto &ev = **it;
GenComment(ev.doc_comment, code_ptr, nullptr); GenComment(ev.doc_comment, code_ptr, nullptr, Indent.c_str());
EnumMember(enum_def, ev, code_ptr); EnumMember(enum_def, ev, code_ptr);
} }
......
...@@ -29,6 +29,7 @@ namespace flatbuffers { ...@@ -29,6 +29,7 @@ namespace flatbuffers {
namespace python { namespace python {
// Hardcode spaces per indentation. // Hardcode spaces per indentation.
const CommentConfig def_comment = { nullptr, "#", nullptr };
const std::string Indent = " "; const std::string Indent = " ";
class PythonGenerator : public BaseGenerator { class PythonGenerator : public BaseGenerator {
...@@ -497,7 +498,7 @@ class PythonGenerator : public BaseGenerator { ...@@ -497,7 +498,7 @@ class PythonGenerator : public BaseGenerator {
// Generate a struct field, conditioned on its child type(s). // Generate a struct field, conditioned on its child type(s).
void GenStructAccessor(const StructDef &struct_def, void GenStructAccessor(const StructDef &struct_def,
const FieldDef &field, std::string *code_ptr) { const FieldDef &field, std::string *code_ptr) {
GenComment(field.doc_comment, code_ptr, nullptr, "# "); GenComment(field.doc_comment, code_ptr, &def_comment, Indent.c_str());
if (IsScalar(field.value.type.base_type)) { if (IsScalar(field.value.type.base_type)) {
if (struct_def.fixed) { if (struct_def.fixed) {
GetScalarFieldOfStruct(struct_def, field, code_ptr); GetScalarFieldOfStruct(struct_def, field, code_ptr);
...@@ -557,7 +558,7 @@ class PythonGenerator : public BaseGenerator { ...@@ -557,7 +558,7 @@ class PythonGenerator : public BaseGenerator {
void GenStruct(const StructDef &struct_def, std::string *code_ptr) { void GenStruct(const StructDef &struct_def, std::string *code_ptr) {
if (struct_def.generated) return; if (struct_def.generated) return;
GenComment(struct_def.doc_comment, code_ptr, nullptr, "# "); GenComment(struct_def.doc_comment, code_ptr, &def_comment);
BeginClass(struct_def, code_ptr); BeginClass(struct_def, code_ptr);
if (!struct_def.fixed) { if (!struct_def.fixed) {
// Generate a special accessor for the table that has been declared as // Generate a special accessor for the table that has been declared as
...@@ -588,11 +589,11 @@ class PythonGenerator : public BaseGenerator { ...@@ -588,11 +589,11 @@ class PythonGenerator : public BaseGenerator {
void GenEnum(const EnumDef &enum_def, std::string *code_ptr) { void GenEnum(const EnumDef &enum_def, std::string *code_ptr) {
if (enum_def.generated) return; if (enum_def.generated) return;
GenComment(enum_def.doc_comment, code_ptr, nullptr, "# "); GenComment(enum_def.doc_comment, code_ptr, &def_comment);
BeginEnum(NormalizedName(enum_def), code_ptr); BeginEnum(NormalizedName(enum_def), code_ptr);
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) { for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
auto &ev = **it; auto &ev = **it;
GenComment(ev.doc_comment, code_ptr, nullptr, "# "); GenComment(ev.doc_comment, code_ptr, &def_comment, Indent.c_str());
EnumMember(enum_def, ev, code_ptr); EnumMember(enum_def, ev, code_ptr);
} }
EndEnum(code_ptr); EndEnum(code_ptr);
......
...@@ -7,10 +7,10 @@ namespace MyGame.Example ...@@ -7,10 +7,10 @@ namespace MyGame.Example
public enum Any : byte public enum Any : byte
{ {
NONE = 0, NONE = 0,
Monster = 1, Monster = 1,
TestSimpleTableWithEnum = 2, TestSimpleTableWithEnum = 2,
MyGame_Example2_Monster = 3, MyGame_Example2_Monster = 3,
}; };
......
...@@ -7,10 +7,10 @@ namespace MyGame.Example ...@@ -7,10 +7,10 @@ namespace MyGame.Example
public enum AnyAmbiguousAliases : byte public enum AnyAmbiguousAliases : byte
{ {
NONE = 0, NONE = 0,
M1 = 1, M1 = 1,
M2 = 2, M2 = 2,
M3 = 3, M3 = 3,
}; };
......
...@@ -7,10 +7,10 @@ namespace MyGame.Example ...@@ -7,10 +7,10 @@ namespace MyGame.Example
public enum AnyUniqueAliases : byte public enum AnyUniqueAliases : byte
{ {
NONE = 0, NONE = 0,
M = 1, M = 1,
TS = 2, TS = 2,
M2 = 3, M2 = 3,
}; };
......
...@@ -5,12 +5,16 @@ ...@@ -5,12 +5,16 @@
namespace MyGame.Example namespace MyGame.Example
{ {
/// Composite components of Monster color.
[System.FlagsAttribute] [System.FlagsAttribute]
public enum Color : byte public enum Color : byte
{ {
Red = 1, Red = 1,
Green = 2, /// \brief color Green
Blue = 8, /// Green is bit_flag with value (1u << 1)
Green = 2,
/// \brief color Blue (1u << 3)
Blue = 8,
}; };
......
...@@ -4,11 +4,15 @@ package Example ...@@ -4,11 +4,15 @@ package Example
import "strconv" import "strconv"
/// Composite components of Monster color.
type Color byte type Color byte
const ( const (
ColorRed Color = 1 ColorRed Color = 1
/// \brief color Green
/// Green is bit_flag with value (1u << 1)
ColorGreen Color = 2 ColorGreen Color = 2
/// \brief color Blue (1u << 3)
ColorBlue Color = 8 ColorBlue Color = 8
) )
......
...@@ -2,10 +2,20 @@ ...@@ -2,10 +2,20 @@
package MyGame.Example; package MyGame.Example;
/**
* Composite components of Monster color.
*/
public final class Color { public final class Color {
private Color() { } private Color() { }
public static final byte Red = 1; public static final byte Red = 1;
/**
* \brief color Green
* Green is bit_flag with value (1u << 1)
*/
public static final byte Green = 2; public static final byte Green = 2;
/**
* \brief color Blue (1u << 3)
*/
public static final byte Blue = 8; public static final byte Blue = 8;
public static final String[] names = { "Red", "Green", "", "", "", "", "", "Blue", }; public static final String[] names = { "Red", "Green", "", "", "", "", "", "Blue", };
......
...@@ -2,9 +2,13 @@ ...@@ -2,9 +2,13 @@
-- namespace: Example -- namespace: Example
-- Composite components of Monster color.
local Color = { local Color = {
Red = 1, Red = 1,
-- \brief color Green
-- Green is bit_flag with value (1u << 1)
Green = 2, Green = 2,
-- \brief color Blue (1u << 3)
Blue = 8, Blue = 8,
} }
......
...@@ -3,10 +3,14 @@ ...@@ -3,10 +3,14 @@
namespace MyGame\Example; namespace MyGame\Example;
/// Composite components of Monster color.
class Color class Color
{ {
const Red = 1; const Red = 1;
/// \brief color Green
/// Green is bit_flag with value (1u << 1)
const Green = 2; const Green = 2;
/// \brief color Blue (1u << 3)
const Blue = 8; const Blue = 8;
private static $names = array( private static $names = array(
......
...@@ -2,8 +2,12 @@ ...@@ -2,8 +2,12 @@
# namespace: Example # namespace: Example
# Composite components of Monster color.
class Color(object): class Color(object):
Red = 1 Red = 1
# \brief color Green
# Green is bit_flag with value (1u << 1)
Green = 2 Green = 2
# \brief color Blue (1u << 3)
Blue = 8 Blue = 8
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
local flatbuffers = require('flatbuffers') local flatbuffers = require('flatbuffers')
-- /// an example documentation comment: monster object -- an example documentation comment: monster object
local Monster = {} -- the module local Monster = {} -- the module
local Monster_mt = {} -- the class metatable local Monster_mt = {} -- the class metatable
...@@ -120,8 +120,8 @@ function Monster_mt:TestarrayofstringLength() ...@@ -120,8 +120,8 @@ function Monster_mt:TestarrayofstringLength()
end end
return 0 return 0
end end
-- /// an example documentation comment: this will end up in the generated code -- an example documentation comment: this will end up in the generated code
-- /// multiline too -- multiline too
function Monster_mt:Testarrayoftables(j) function Monster_mt:Testarrayoftables(j)
local o = self.view:Offset(26) local o = self.view:Offset(26)
if o ~= 0 then if o ~= 0 then
......
...@@ -171,8 +171,8 @@ class Monster extends Table ...@@ -171,8 +171,8 @@ class Monster extends Table
return $o != 0 ? $this->__vector_len($o) : 0; return $o != 0 ? $this->__vector_len($o) : 0;
} }
/// an example documentation comment: this will end up in the generated code /// an example documentation comment: this will end up in the generated code
/// multiline too /// multiline too
/** /**
* @returnVectorOffset * @returnVectorOffset
*/ */
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import flatbuffers import flatbuffers
# /// an example documentation comment: monster object # an example documentation comment: monster object
class Monster(object): class Monster(object):
__slots__ = ['_tab'] __slots__ = ['_tab']
...@@ -131,8 +131,8 @@ class Monster(object): ...@@ -131,8 +131,8 @@ class Monster(object):
return self._tab.VectorLen(o) return self._tab.VectorLen(o)
return 0 return 0
# /// an example documentation comment: this will end up in the generated code # an example documentation comment: this will end up in the generated code
# /// multiline too # multiline too
# Monster # Monster
def Testarrayoftables(self, j): def Testarrayoftables(self, j):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(26)) o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(26))
......
No preview for this file type
...@@ -14,7 +14,15 @@ namespace MyGame.Example; ...@@ -14,7 +14,15 @@ namespace MyGame.Example;
attribute "priority"; attribute "priority";
enum Color:ubyte (bit_flags) { Red = 0, Green, Blue = 3, } /// Composite components of Monster color.
enum Color:ubyte (bit_flags) {
Red = 0, // color Red = (1u << 0)
/// \brief color Green
/// Green is bit_flag with value (1u << 1)
Green,
/// \brief color Blue (1u << 3)
Blue = 3,
}
union Any { Monster, TestSimpleTableWithEnum, MyGame.Example2.Monster } union Any { Monster, TestSimpleTableWithEnum, MyGame.Example2.Monster }
......
...@@ -99,9 +99,13 @@ inline const flatbuffers::TypeTable *MonsterTypeTable(); ...@@ -99,9 +99,13 @@ inline const flatbuffers::TypeTable *MonsterTypeTable();
inline const flatbuffers::TypeTable *TypeAliasesTypeTable(); inline const flatbuffers::TypeTable *TypeAliasesTypeTable();
/// Composite components of Monster color.
enum Color { enum Color {
Color_Red = 1, Color_Red = 1,
/// \brief color Green
/// Green is bit_flag with value (1u << 1)
Color_Green = 2, Color_Green = 2,
/// \brief color Blue (1u << 3)
Color_Blue = 8, Color_Blue = 8,
Color_NONE = 0, Color_NONE = 0,
Color_ANY = 11 Color_ANY = 11
......
...@@ -25,20 +25,42 @@ MyGame.Example2 = MyGame.Example2 || {}; ...@@ -25,20 +25,42 @@ MyGame.Example2 = MyGame.Example2 || {};
MyGame.OtherNameSpace = MyGame.OtherNameSpace || {}; MyGame.OtherNameSpace = MyGame.OtherNameSpace || {};
/** /**
* Composite components of Monster color.
*
* @enum {number} * @enum {number}
*/ */
MyGame.Example.Color = { MyGame.Example.Color = {
Red: 1, Red: 1,
/**
* \brief color Green
* Green is bit_flag with value (1u << 1)
*/
Green: 2, Green: 2,
/**
* \brief color Blue (1u << 3)
*/
Blue: 8 Blue: 8
}; };
/** /**
* Composite components of Monster color.
*
* @enum {string} * @enum {string}
*/ */
MyGame.Example.ColorName = { MyGame.Example.ColorName = {
1: 'Red', 1: 'Red',
/**
* \brief color Green
* Green is bit_flag with value (1u << 1)
*/
2: 'Green', 2: 'Green',
/**
* \brief color Blue (1u << 3)
*/
8: 'Blue' 8: 'Blue'
}; };
......
...@@ -3,9 +3,13 @@ import flatbuffers ...@@ -3,9 +3,13 @@ import flatbuffers
namespace MyGame_Example namespace MyGame_Example
/// Composite components of Monster color.
enum Color: enum Color:
Color_Red = 1 Color_Red = 1
/// \brief color Green
/// Green is bit_flag with value (1u << 1)
Color_Green = 2 Color_Green = 2
/// \brief color Blue (1u << 3)
Color_Blue = 8 Color_Blue = 8
enum Any: enum Any:
......
...@@ -163,12 +163,16 @@ pub mod example { ...@@ -163,12 +163,16 @@ pub mod example {
extern crate flatbuffers; extern crate flatbuffers;
use self::flatbuffers::EndianScalar; use self::flatbuffers::EndianScalar;
/// Composite components of Monster color.
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
#[repr(u8)] #[repr(u8)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum Color { pub enum Color {
Red = 1, Red = 1,
/// \brief color Green
/// Green is bit_flag with value (1u << 1)
Green = 2, Green = 2,
/// \brief color Blue (1u << 3)
Blue = 8, Blue = 8,
} }
......
// automatically generated by the FlatBuffers compiler, do not modify // automatically generated by the FlatBuffers compiler, do not modify
/** /**
* Composite components of Monster color.
*
* @enum {number} * @enum {number}
*/ */
export namespace MyGame.Example{ export namespace MyGame.Example{
export enum Color{ export enum Color{
Red= 1, Red= 1,
/**
* \brief color Green
* Green is bit_flag with value (1u << 1)
*/
Green= 2, Green= 2,
/**
* \brief color Blue (1u << 3)
*/
Blue= 8 Blue= 8
}}; }};
......
...@@ -9,6 +9,7 @@ import 'package:flat_buffers/flat_buffers.dart' as fb; ...@@ -9,6 +9,7 @@ import 'package:flat_buffers/flat_buffers.dart' as fb;
import './monster_test_my_game_generated.dart' as my_game; import './monster_test_my_game_generated.dart' as my_game;
import './monster_test_my_game.example2_generated.dart' as my_game_example2; import './monster_test_my_game.example2_generated.dart' as my_game_example2;
/// Composite components of Monster color.
class Color { class Color {
final int value; final int value;
const Color._(this.value); const Color._(this.value);
...@@ -24,7 +25,12 @@ class Color { ...@@ -24,7 +25,12 @@ class Color {
static bool containsValue(int value) => values.containsKey(value); static bool containsValue(int value) => values.containsKey(value);
static const Color Red = const Color._(1); static const Color Red = const Color._(1);
/// \brief color Green
/// Green is bit_flag with value (1u << 1)
static const Color Green = const Color._(2); static const Color Green = const Color._(2);
/// \brief color Blue (1u << 3)
static const Color Blue = const Color._(8); static const Color Blue = const Color._(8);
static get values => {1: Red,2: Green,8: Blue,}; static get values => {1: Red,2: Green,8: Blue,};
...@@ -700,8 +706,8 @@ class Monster { ...@@ -700,8 +706,8 @@ class Monster {
} }
List<Test> get test4 => const fb.ListReader<Test>(Test.reader).vTableGet(_bc, _bcOffset, 22, null); List<Test> get test4 => const fb.ListReader<Test>(Test.reader).vTableGet(_bc, _bcOffset, 22, null);
List<String> get testarrayofstring => const fb.ListReader<String>(const fb.StringReader()).vTableGet(_bc, _bcOffset, 24, null); List<String> get testarrayofstring => const fb.ListReader<String>(const fb.StringReader()).vTableGet(_bc, _bcOffset, 24, null);
/// an example documentation comment: this will end up in the generated code /// an example documentation comment: this will end up in the generated code
/// multiline too /// multiline too
List<Monster> get testarrayoftables => const fb.ListReader<Monster>(Monster.reader).vTableGet(_bc, _bcOffset, 26, null); List<Monster> get testarrayoftables => const fb.ListReader<Monster>(Monster.reader).vTableGet(_bc, _bcOffset, 26, null);
Monster get enemy => Monster.reader.vTableGet(_bc, _bcOffset, 28, null); Monster get enemy => Monster.reader.vTableGet(_bc, _bcOffset, 28, null);
List<int> get testnestedflatbuffer => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGet(_bc, _bcOffset, 30, null); List<int> get testnestedflatbuffer => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGet(_bc, _bcOffset, 30, null);
......
...@@ -7,9 +7,9 @@ namespace NamespaceA.NamespaceB ...@@ -7,9 +7,9 @@ namespace NamespaceA.NamespaceB
public enum EnumInNestedNS : sbyte public enum EnumInNestedNS : sbyte
{ {
A = 0, A = 0,
B = 1, B = 1,
C = 2, C = 2,
}; };
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
public enum Character : byte public enum Character : byte
{ {
NONE = 0, NONE = 0,
MuLan = 1, MuLan = 1,
Rapunzel = 2, Rapunzel = 2,
Belle = 3, Belle = 3,
BookFan = 4, BookFan = 4,
Other = 5, Other = 5,
Unused = 6, Unused = 6,
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment