New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C++] Fix unqualified namespaces #5374
Changes from all commits
869a563
d186d3f
1cf413d
1e4fced
154cfe4
d716bf8
d6f7874
a550d02
f5ba211
5a1d997
4d15878
929ff31
8574e5e
8522374
f96df49
4b61f03
f6e1cd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,19 +47,19 @@ namespace flatbuffers { | |
// of type tokens. | ||
// clang-format off | ||
#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \ | ||
TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8) \ | ||
TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8) /* begin scalar/int */ \ | ||
TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool) \ | ||
TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8) \ | ||
TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8, u8) \ | ||
TD(SHORT, "short", int16_t, short, int16, short, int16, i16) \ | ||
TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16, u16) \ | ||
TD(INT, "int", int32_t, int, int32, int, int32, i32) \ | ||
TD(UINT, "uint", uint32_t, int, uint32, uint, uint32, u32) \ | ||
TD(LONG, "long", int64_t, long, int64, long, int64, i64) \ | ||
TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64) /* end int */ \ | ||
TD(FLOAT, "float", float, float, float32, float, float32, f32) /* begin float */ \ | ||
TD(DOUBLE, "double", double, double, float64, double, float64, f64) /* end float/scalar */ | ||
TD(NONE, "", ::uint8_t, byte, byte, byte, uint8, u8) \ | ||
TD(UTYPE, "", ::uint8_t, byte, byte, byte, uint8, u8) /* begin scalar/int */ \ | ||
TD(BOOL, "bool", ::uint8_t, boolean,bool, bool, bool, bool) \ | ||
TD(CHAR, "byte", ::int8_t, byte, int8, sbyte, int8, i8) \ | ||
TD(UCHAR, "ubyte", ::uint8_t, byte, byte, byte, uint8, u8) \ | ||
TD(SHORT, "short", ::int16_t, short, int16, short, int16, i16) \ | ||
TD(USHORT, "ushort", ::uint16_t, short, uint16, ushort, uint16, u16) \ | ||
TD(INT, "int", ::int32_t, int, int32, int, int32, i32) \ | ||
TD(UINT, "uint", ::uint32_t, int, uint32, uint, uint32, u32) \ | ||
TD(LONG, "long", ::int64_t, long, int64, long, int64, i64) \ | ||
TD(ULONG, "ulong", ::uint64_t, long, uint64, ulong, uint64, u64) /* end int */ \ | ||
TD(FLOAT, "float", float, float, float32, float, float32, f32) /* begin float */ \ | ||
TD(DOUBLE, "double", double, double, float64, double, float64, f64) /* end float/scalar */ | ||
#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \ | ||
TD(STRING, "string", Offset<void>, int, int, StringOffset, int, unused) \ | ||
TD(VECTOR, "", Offset<void>, int, int, VectorOffset, int, unused) \ | ||
|
@@ -455,6 +455,17 @@ struct ServiceDef : public Definition { | |
SymbolTable<RPCCall> calls; | ||
}; | ||
|
||
struct FullyQualifiedType { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the use of this wrapper? If it was only useful during refactoring, please remove again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea was to enforce beginning with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a LOT of strings thruout FlatBuffers that have expectations of the format contained in them (e.g. paths). I don't feel this case is special enough to warrant encoding the invariant in a class. |
||
public: | ||
FullyQualifiedType() {} | ||
explicit FullyQualifiedType(const std::string &type_name); | ||
|
||
const std::string &Get() const { return value_; } | ||
|
||
private: | ||
std::string value_; | ||
}; | ||
|
||
// Container of options that may apply to any of the source/text generators. | ||
struct IDLOptions { | ||
bool strict_json; | ||
|
@@ -476,8 +487,8 @@ struct IDLOptions { | |
bool generate_name_strings; | ||
bool generate_object_based_api; | ||
bool gen_compare; | ||
std::string cpp_object_api_pointer_type; | ||
std::string cpp_object_api_string_type; | ||
FullyQualifiedType cpp_object_api_pointer_type; | ||
FullyQualifiedType cpp_object_api_string_type; | ||
bool cpp_object_api_string_flexible_constructor; | ||
bool gen_nullable; | ||
bool gen_generated; | ||
|
@@ -554,7 +565,7 @@ struct IDLOptions { | |
generate_name_strings(false), | ||
generate_object_based_api(false), | ||
gen_compare(false), | ||
cpp_object_api_pointer_type("std::unique_ptr"), | ||
cpp_object_api_pointer_type("::std::unique_ptr"), | ||
cpp_object_api_string_flexible_constructor(false), | ||
gen_nullable(false), | ||
gen_generated(false), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to do it for these basic types as well? They already end in
_t
which to me makes namespaces clashes very unlikely, and the clutter level is high.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly don't know if it makes sense. Technically, the user could define
uint8_t
etc types in their own namespace, which could break this, but this has a lower benefit than the other changes. I don't mind if it goes either way. Reverting the changes for these basic types seems fine to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that will be so rare, there is a benefit to readability to not have the
::
in this case.