Made the parser not have any hard-coded keywords.

This prevented any keywords showing up as JSON field names, for example.

Change-Id: Ie9d0cada96778e06016ca02ca96d052410a37038
Tested: on Linux.
parent 72a99abf
...@@ -40,29 +40,28 @@ namespace flatbuffers { ...@@ -40,29 +40,28 @@ namespace flatbuffers {
// Additionally, Parser::ParseType assumes bool..string is a contiguous range // Additionally, Parser::ParseType assumes bool..string is a contiguous range
// of type tokens. // of type tokens.
#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \ #define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
TD(NONE, "", "", uint8_t, byte, byte, byte, uint8) \ TD(NONE, "", uint8_t, byte, byte, byte, uint8) \
TD(UTYPE, "", "", uint8_t, byte, byte, byte, uint8) /* begin scalar/int */ \ TD(UTYPE, "", uint8_t, byte, byte, byte, uint8) /* begin scalar/int */ \
TD(BOOL, "bool", "", uint8_t, boolean,byte, bool, bool) \ TD(BOOL, "bool", uint8_t, boolean,byte, bool, bool) \
TD(CHAR, "byte", "int8", int8_t, byte, int8, sbyte, int8) \ TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8) \
TD(UCHAR, "ubyte", "uint8", uint8_t, byte, byte, byte, uint8) \ TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8) \
TD(SHORT, "short", "int16", int16_t, short, int16, short, int16) \ TD(SHORT, "short", int16_t, short, int16, short, int16) \
TD(USHORT, "ushort", "uint16", uint16_t, short, uint16, ushort, uint16) \ TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16) \
TD(INT, "int", "int32", int32_t, int, int32, int, int32) \ TD(INT, "int", int32_t, int, int32, int, int32) \
TD(UINT, "uint", "uint32", uint32_t, int, uint32, uint, uint32) \ TD(UINT, "uint", uint32_t, int, uint32, uint, uint32) \
TD(LONG, "long", "int64", int64_t, long, int64, long, int64) \ TD(LONG, "long", int64_t, long, int64, long, int64) \
TD(ULONG, "ulong", "uint64", uint64_t, long, uint64, ulong, uint64) /* end int */ \ TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64) /* end int */ \
TD(FLOAT, "float", "float32", float, float, float32, float, float32) /* begin float */ \ TD(FLOAT, "float", float, float, float32, float, float32) /* begin float */ \
TD(DOUBLE, "double", "float64", double, double, float64, double, float64) /* end float/scalar */ TD(DOUBLE, "double", double, double, float64, double, float64) /* end float/scalar */
#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \ #define FLATBUFFERS_GEN_TYPES_POINTER(TD) \
TD(STRING, "string", "", Offset<void>, int, int, StringOffset, int) \ TD(STRING, "string", Offset<void>, int, int, StringOffset, int) \
TD(VECTOR, "", "", Offset<void>, int, int, VectorOffset, int) \ TD(VECTOR, "", Offset<void>, int, int, VectorOffset, int) \
TD(STRUCT, "", "", Offset<void>, int, int, int, int) \ TD(STRUCT, "", Offset<void>, int, int, int, int) \
TD(UNION, "", "", Offset<void>, int, int, int, int) TD(UNION, "", Offset<void>, int, int, int, int)
// The fields are: // The fields are:
// - enum // - enum
// - FlatBuffers schema type. // - FlatBuffers schema type.
// - FlatBuffers schema alias type.
// - C++ type. // - C++ type.
// - Java type. // - Java type.
// - Go type. // - Go type.
...@@ -73,7 +72,7 @@ namespace flatbuffers { ...@@ -73,7 +72,7 @@ namespace flatbuffers {
/* /*
switch (type) { switch (type) {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ALIASTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
case BASE_TYPE_ ## ENUM: \ case BASE_TYPE_ ## ENUM: \
// do something specific to CTYPE here // do something specific to CTYPE here
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
...@@ -90,13 +89,13 @@ switch (type) { ...@@ -90,13 +89,13 @@ switch (type) {
__extension__ // Stop GCC complaining about trailing comma with -Wpendantic. __extension__ // Stop GCC complaining about trailing comma with -Wpendantic.
#endif #endif
enum BaseType { enum BaseType {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ALIASTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
BASE_TYPE_ ## ENUM, BASE_TYPE_ ## ENUM,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
}; };
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ALIASTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \ static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \
"define largest_scalar_t as " #CTYPE); "define largest_scalar_t as " #CTYPE);
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
...@@ -575,6 +574,7 @@ private: ...@@ -575,6 +574,7 @@ private:
FLATBUFFERS_CHECKED_ERROR Next(); FLATBUFFERS_CHECKED_ERROR Next();
FLATBUFFERS_CHECKED_ERROR SkipByteOrderMark(); FLATBUFFERS_CHECKED_ERROR SkipByteOrderMark();
bool Is(int t); bool Is(int t);
bool IsIdent(const char *id);
FLATBUFFERS_CHECKED_ERROR Expect(int t); FLATBUFFERS_CHECKED_ERROR Expect(int t);
std::string TokenToStringId(int t); std::string TokenToStringId(int t);
EnumDef *LookupEnum(const std::string &id); EnumDef *LookupEnum(const std::string &id);
......
...@@ -333,7 +333,7 @@ class CppGenerator : public BaseGenerator { ...@@ -333,7 +333,7 @@ class CppGenerator : public BaseGenerator {
// Return a C++ type from the table in idl.h // Return a C++ type from the table in idl.h
std::string GenTypeBasic(const Type &type, bool user_facing_type) const { std::string GenTypeBasic(const Type &type, bool user_facing_type) const {
static const char *ctypename[] = { static const char *ctypename[] = {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ALIASTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#CTYPE, #CTYPE,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
......
...@@ -241,7 +241,7 @@ static bool IsEnum(const Type& type) { ...@@ -241,7 +241,7 @@ static bool IsEnum(const Type& type) {
std::string GenTypeBasic(const Type &type, bool enableLangOverrides) { std::string GenTypeBasic(const Type &type, bool enableLangOverrides) {
static const char *java_typename[] = { static const char *java_typename[] = {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ALIASTYPE, \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, \
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#JTYPE, #JTYPE,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
...@@ -249,7 +249,7 @@ std::string GenTypeBasic(const Type &type, bool enableLangOverrides) { ...@@ -249,7 +249,7 @@ std::string GenTypeBasic(const Type &type, bool enableLangOverrides) {
}; };
static const char *csharp_typename[] = { static const char *csharp_typename[] = {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ALIASTYPE, \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, \
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#NTYPE, #NTYPE,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
......
...@@ -694,7 +694,7 @@ static std::string GenMethod(const FieldDef &field) { ...@@ -694,7 +694,7 @@ static std::string GenMethod(const FieldDef &field) {
static std::string GenTypeBasic(const Type &type) { static std::string GenTypeBasic(const Type &type) {
static const char *ctypename[] = { static const char *ctypename[] = {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ALIASTYPE, \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, \
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#GTYPE, #GTYPE,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
......
...@@ -909,7 +909,7 @@ namespace php { ...@@ -909,7 +909,7 @@ namespace php {
static std::string GenTypeBasic(const Type &type) { static std::string GenTypeBasic(const Type &type) {
static const char *ctypename[] = { static const char *ctypename[] = {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ALIASTYPE, \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, \
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#NTYPE, #NTYPE,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
......
...@@ -580,7 +580,7 @@ static std::string GenMethod(const FieldDef &field) { ...@@ -580,7 +580,7 @@ static std::string GenMethod(const FieldDef &field) {
static std::string GenTypeBasic(const Type &type) { static std::string GenTypeBasic(const Type &type) {
static const char *ctypename[] = { static const char *ctypename[] = {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ALIASTYPE, \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, \
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#PTYPE, #PTYPE,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
......
...@@ -135,7 +135,7 @@ template<> bool Print<const void *>(const void *val, ...@@ -135,7 +135,7 @@ template<> bool Print<const void *>(const void *val,
type = type.VectorType(); type = type.VectorType();
// Call PrintVector above specifically for each element type: // Call PrintVector above specifically for each element type:
switch (type.base_type) { switch (type.base_type) {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ALIASTYPE, \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, \
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
case BASE_TYPE_ ## ENUM: \ case BASE_TYPE_ ## ENUM: \
if (!PrintVector<CTYPE>( \ if (!PrintVector<CTYPE>( \
...@@ -226,7 +226,7 @@ static bool GenStruct(const StructDef &struct_def, const Table *table, ...@@ -226,7 +226,7 @@ static bool GenStruct(const StructDef &struct_def, const Table *table,
text += " "; text += " ";
if (is_present) { if (is_present) {
switch (fd.value.type.base_type) { switch (fd.value.type.base_type) {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ALIASTYPE, \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, \
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
case BASE_TYPE_ ## ENUM: \ case BASE_TYPE_ ## ENUM: \
if (!GenField<CTYPE>(fd, table, struct_def.fixed, \ if (!GenField<CTYPE>(fd, table, struct_def.fixed, \
...@@ -237,7 +237,7 @@ static bool GenStruct(const StructDef &struct_def, const Table *table, ...@@ -237,7 +237,7 @@ static bool GenStruct(const StructDef &struct_def, const Table *table,
FLATBUFFERS_GEN_TYPES_SCALAR(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES_SCALAR(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
// Generate drop-thru case statements for all pointer types: // Generate drop-thru case statements for all pointer types:
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ALIASTYPE, \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, \
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
case BASE_TYPE_ ## ENUM: case BASE_TYPE_ ## ENUM:
FLATBUFFERS_GEN_TYPES_POINTER(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES_POINTER(FLATBUFFERS_TD)
......
This diff is collapsed.
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