mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 05:27:24 +00:00
Refactoring of idl_parser (#4948)
* Refactoring of numbers parser More accurate parse of float and double. Hexadecimal floats. Check "out-of-range" of uint64 fields. Check correctness of default values and metadata. * Remove locale-independent code strtod/strtof from PR #4948. * small optimization * Add is_(ascii) functions * is_ascii cleanup * Fix format conversation * Refine number parser * Make code compatible with Android build * Remove unnecessary suppression of warning C4127
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
53ce80ce91
commit
4ed6fafdfa
@@ -149,19 +149,23 @@ bool Print<const void *>(const void *val, Type type, int indent,
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T> static T GetFieldDefault(const FieldDef &fd) {
|
||||
T val;
|
||||
auto check = StringToNumber(fd.value.constant.c_str(), &val);
|
||||
(void)check;
|
||||
FLATBUFFERS_ASSERT(check);
|
||||
return val;
|
||||
}
|
||||
|
||||
// Generate text for a scalar field.
|
||||
template<typename T> static bool GenField(const FieldDef &fd,
|
||||
const Table *table, bool fixed,
|
||||
const IDLOptions &opts,
|
||||
int indent,
|
||||
std::string *_text) {
|
||||
return Print(fixed ?
|
||||
reinterpret_cast<const Struct *>(table)->GetField<T>(fd.value.offset) :
|
||||
table->GetField<T>(fd.value.offset,
|
||||
IsFloat(fd.value.type.base_type) ?
|
||||
static_cast<T>(strtod(fd.value.constant.c_str(), nullptr)) :
|
||||
static_cast<T>(StringToInt(fd.value.constant.c_str()))),
|
||||
fd.value.type, indent, nullptr, opts, _text);
|
||||
template<typename T>
|
||||
static bool GenField(const FieldDef &fd, const Table *table, bool fixed,
|
||||
const IDLOptions &opts, int indent, std::string *_text) {
|
||||
return Print(
|
||||
fixed ? reinterpret_cast<const Struct *>(table)->GetField<T>(
|
||||
fd.value.offset)
|
||||
: table->GetField<T>(fd.value.offset, GetFieldDefault<T>(fd)),
|
||||
fd.value.type, indent, nullptr, opts, _text);
|
||||
}
|
||||
|
||||
static bool GenStruct(const StructDef &struct_def, const Table *table,
|
||||
|
||||
Reference in New Issue
Block a user