Commit eac0bc64 authored by Paul Reimer's avatar Paul Reimer Committed by Wouter van Oortmerssen

Add FLATBUFFERS_ prefix to defines [C++] (#4695)

* Rename STRUCT_END to add FLATBUFFERS_ prefix, now FLATBUFFERS_STRUCT_END. Via running `ag -l STRUCT_END | xargs rpl STRUCT_END FLATBUFFERS_STRUCT_END`

* Rename MANUALLY_ALIGNED_STRUCT to add FLATBUFFERS_ prefix, now FLATBUFFERS_MANUALLY_ALIGNED_STRUCT. Via running `ag -l MANUALLY_ALIGNED_STRUCT | xargs rpl MANUALLY_ALIGNED_STRUCT FLATBUFFERS_MANUALLY_ALIGNED_STRUCT && cd tests && sh generate_code.sh`

* Rename DEFINE_BITMASK_OPERATORS to add FLATBUFFERS_ prefix, now FLATBUFFERS_DEFINE_BITMASK_OPERATORS. Via running `ag -l DEFINE_BITMASK_OPERATORS | xargs rpl DEFINE_BITMASK_OPERATORS FLATBUFFERS_DEFINE_BITMASK_OPERATORS`
parent 20a400e9
......@@ -169,7 +169,7 @@ Unions share a lot with enums.
Predeclare all data types since circular references between types are allowed
(circular references between object are not, though).
MANUALLY_ALIGNED_STRUCT(4) Vec3 {
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vec3 {
private:
float x_;
float y_;
......@@ -183,7 +183,7 @@ Predeclare all data types since circular references between types are allowed
float y() const { return flatbuffers::EndianScalar(y_); }
float z() const { return flatbuffers::EndianScalar(z_); }
};
STRUCT_END(Vec3, 12);
FLATBUFFERS_STRUCT_END(Vec3, 12);
These ugly macros do a couple of things: they turn off any padding the compiler
might normally do, since we add padding manually (though none in this example),
......
......@@ -2131,17 +2131,17 @@ inline int LookupEnum(const char **names, const char *name) {
// clang-format off
#if defined(_MSC_VER)
#define MANUALLY_ALIGNED_STRUCT(alignment) \
#define FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(alignment) \
__pragma(pack(1)); \
struct __declspec(align(alignment))
#define STRUCT_END(name, size) \
#define FLATBUFFERS_STRUCT_END(name, size) \
__pragma(pack()); \
static_assert(sizeof(name) == size, "compiler breaks packing rules")
#elif defined(__GNUC__) || defined(__clang__)
#define MANUALLY_ALIGNED_STRUCT(alignment) \
#define FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(alignment) \
_Pragma("pack(1)") \
struct __attribute__((aligned(alignment)))
#define STRUCT_END(name, size) \
#define FLATBUFFERS_STRUCT_END(name, size) \
_Pragma("pack()") \
static_assert(sizeof(name) == size, "compiler breaks packing rules")
#else
......@@ -2240,7 +2240,7 @@ volatile __attribute__((weak)) const char *flatbuffer_version_string =
#endif // !defined(_WIN32) && !defined(__CYGWIN__)
#define DEFINE_BITMASK_OPERATORS(E, T)\
#define FLATBUFFERS_DEFINE_BITMASK_OPERATORS(E, T)\
inline E operator | (E lhs, E rhs){\
return E(T(lhs) | T(rhs));\
}\
......
......@@ -170,7 +170,7 @@ MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
flatbuffers::WriteScalar(&z_, _z);
}
};
STRUCT_END(Vec3, 12);
FLATBUFFERS_STRUCT_END(Vec3, 12);
struct MonsterT : public flatbuffers::NativeTable {
typedef Monster TableType;
......
......@@ -922,7 +922,7 @@ class CppGenerator : public BaseGenerator {
code_ += "};";
if (parser_.opts.scoped_enums && enum_def.attributes.Lookup("bit_flags")) {
code_ += "DEFINE_BITMASK_OPERATORS({{ENUM_NAME}}, {{BASE_TYPE}})";
code_ += "FLATBUFFERS_DEFINE_BITMASK_OPERATORS({{ENUM_NAME}}, {{BASE_TYPE}})";
}
code_ += "";
......@@ -2434,7 +2434,7 @@ class CppGenerator : public BaseGenerator {
code_.SetValue("STRUCT_NAME", Name(struct_def));
code_ +=
"MANUALLY_ALIGNED_STRUCT({{ALIGN}}) "
"FLATBUFFERS_MANUALLY_ALIGNED_STRUCT({{ALIGN}}) "
"{{STRUCT_NAME}} FLATBUFFERS_FINAL_CLASS {";
code_ += " private:";
......@@ -2576,7 +2576,7 @@ class CppGenerator : public BaseGenerator {
code_ += "};";
code_.SetValue("STRUCT_BYTE_SIZE", NumToString(struct_def.bytesize));
code_ += "STRUCT_END({{STRUCT_NAME}}, {{STRUCT_BYTE_SIZE}});";
code_ += "FLATBUFFERS_STRUCT_END({{STRUCT_NAME}}, {{STRUCT_BYTE_SIZE}});";
code_ += "";
}
......
......@@ -247,7 +247,7 @@ MANUALLY_ALIGNED_STRUCT(2) Test FLATBUFFERS_FINAL_CLASS {
flatbuffers::WriteScalar(&b_, _b);
}
};
STRUCT_END(Test, 4);
FLATBUFFERS_STRUCT_END(Test, 4);
MANUALLY_ALIGNED_STRUCT(16) Vec3 FLATBUFFERS_FINAL_CLASS {
private:
......@@ -316,7 +316,7 @@ MANUALLY_ALIGNED_STRUCT(16) Vec3 FLATBUFFERS_FINAL_CLASS {
return test3_;
}
};
STRUCT_END(Vec3, 32);
FLATBUFFERS_STRUCT_END(Vec3, 32);
MANUALLY_ALIGNED_STRUCT(4) Ability FLATBUFFERS_FINAL_CLASS {
private:
......@@ -351,7 +351,7 @@ MANUALLY_ALIGNED_STRUCT(4) Ability FLATBUFFERS_FINAL_CLASS {
flatbuffers::WriteScalar(&distance_, _distance);
}
};
STRUCT_END(Ability, 8);
FLATBUFFERS_STRUCT_END(Ability, 8);
} // namespace Example
......
......@@ -75,7 +75,7 @@ MANUALLY_ALIGNED_STRUCT(4) StructInNestedNS FLATBUFFERS_FINAL_CLASS {
flatbuffers::WriteScalar(&b_, _b);
}
};
STRUCT_END(StructInNestedNS, 8);
FLATBUFFERS_STRUCT_END(StructInNestedNS, 8);
struct TableInNestedNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
......
......@@ -159,7 +159,7 @@ MANUALLY_ALIGNED_STRUCT(4) Rapunzel FLATBUFFERS_FINAL_CLASS {
flatbuffers::WriteScalar(&hair_length_, _hair_length);
}
};
STRUCT_END(Rapunzel, 4);
FLATBUFFERS_STRUCT_END(Rapunzel, 4);
MANUALLY_ALIGNED_STRUCT(4) BookReader FLATBUFFERS_FINAL_CLASS {
private:
......@@ -179,7 +179,7 @@ MANUALLY_ALIGNED_STRUCT(4) BookReader FLATBUFFERS_FINAL_CLASS {
flatbuffers::WriteScalar(&books_read_, _books_read);
}
};
STRUCT_END(BookReader, 4);
FLATBUFFERS_STRUCT_END(BookReader, 4);
struct AttackerT : public flatbuffers::NativeTable {
typedef Attacker TableType;
......
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