mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Fixes for JS generator in VS
This commit is contained in:
@@ -271,6 +271,7 @@
|
||||
<ClCompile Include="..\..\src\idl_gen_go.cpp">
|
||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Level4</WarningLevel>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\idl_gen_js.cpp" />
|
||||
<ClCompile Include="..\..\src\idl_gen_python.cpp" />
|
||||
<ClCompile Include="..\..\src\idl_parser.cpp" />
|
||||
<ClCompile Include="..\..\src\idl_gen_cpp.cpp" />
|
||||
|
||||
@@ -90,8 +90,17 @@ inline std::string IntToStringHex(int i, int xdigits) {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
// Portable implementation of strtoull().
|
||||
// Portable implementation of strtoll().
|
||||
inline int64_t StringToInt(const char *str, int base = 10) {
|
||||
#ifdef _MSC_VER
|
||||
return _strtoi64(str, nullptr, base);
|
||||
#else
|
||||
return strtoll(str, nullptr, base);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Portable implementation of strtoull().
|
||||
inline int64_t StringToUInt(const char *str, int base = 10) {
|
||||
#ifdef _MSC_VER
|
||||
return _strtoui64(str, nullptr, base);
|
||||
#else
|
||||
|
||||
@@ -101,7 +101,7 @@ static void GenDocComment(const std::vector<std::string> &dc,
|
||||
}
|
||||
if (indent) code += indent;
|
||||
std::string::size_type start = 0;
|
||||
while (true) {
|
||||
for (;;) {
|
||||
auto end = extra_lines.find('\n', start);
|
||||
if (end != std::string::npos) {
|
||||
code += " * " + extra_lines.substr(start, end - start) + "\n";
|
||||
@@ -207,7 +207,7 @@ static std::string GenDefaultValue(const Value &value) {
|
||||
case BASE_TYPE_LONG:
|
||||
case BASE_TYPE_ULONG:
|
||||
if (value.constant != "0") {
|
||||
int64_t constant = std::atoll(value.constant.c_str());
|
||||
int64_t constant = StringToInt(value.constant.c_str());
|
||||
return "new flatbuffers.Long(" + NumToString((int32_t)constant) +
|
||||
", " + NumToString((int32_t)(constant >> 32)) + ")";
|
||||
}
|
||||
@@ -218,13 +218,8 @@ static std::string GenDefaultValue(const Value &value) {
|
||||
}
|
||||
}
|
||||
|
||||
enum struct InOut {
|
||||
IN,
|
||||
OUT,
|
||||
};
|
||||
|
||||
static std::string GenTypeName(const Type &type, InOut inOut) {
|
||||
if (inOut == InOut::OUT) {
|
||||
static std::string GenTypeName(const Type &type, bool input) {
|
||||
if (!input) {
|
||||
if (type.base_type == BASE_TYPE_STRING) {
|
||||
return "string|Uint8Array";
|
||||
}
|
||||
@@ -289,7 +284,7 @@ static void GenStructArgs(const StructDef &struct_def,
|
||||
GenStructArgs(*field.value.type.struct_def, annotations, arguments,
|
||||
nameprefix + field.name + "_");
|
||||
} else {
|
||||
*annotations += "@param {" + GenTypeName(field.value.type, InOut::IN);
|
||||
*annotations += "@param {" + GenTypeName(field.value.type, true);
|
||||
*annotations += "} " + nameprefix + field.name + "\n";
|
||||
*arguments += ", " + nameprefix + field.name;
|
||||
}
|
||||
@@ -406,7 +401,7 @@ static void GenStruct(const Parser &parser, StructDef &struct_def,
|
||||
GenDocComment(field.doc_comment, code_ptr,
|
||||
std::string(field.value.type.base_type == BASE_TYPE_STRING ?
|
||||
"@param {flatbuffers.Encoding=} optionalEncoding\n" : "") +
|
||||
"@returns {" + GenTypeName(field.value.type, InOut::OUT) + "}");
|
||||
"@returns {" + GenTypeName(field.value.type, false) + "}");
|
||||
code += object_name + ".prototype." + MakeCamel(field.name, false);
|
||||
code += " = function(";
|
||||
if (field.value.type.base_type == BASE_TYPE_STRING) {
|
||||
@@ -452,7 +447,7 @@ static void GenStruct(const Parser &parser, StructDef &struct_def,
|
||||
|
||||
case BASE_TYPE_VECTOR: {
|
||||
auto vectortype = field.value.type.VectorType();
|
||||
auto vectortypename = GenTypeName(vectortype, InOut::OUT);
|
||||
auto vectortypename = GenTypeName(vectortype, false);
|
||||
auto inline_size = InlineSize(vectortype);
|
||||
auto index = "this.bb.__vector(this.bb_pos + offset) + index" +
|
||||
MaybeScale(inline_size);
|
||||
@@ -559,7 +554,7 @@ static void GenStruct(const Parser &parser, StructDef &struct_def,
|
||||
// Generate the field insertion method
|
||||
GenDocComment(code_ptr,
|
||||
"@param {flatbuffers.Builder} builder\n"
|
||||
"@param {" + GenTypeName(field.value.type, InOut::IN) + "} " +
|
||||
"@param {" + GenTypeName(field.value.type, true) + "} " +
|
||||
argname);
|
||||
code += object_name + ".add" + MakeCamel(field.name);
|
||||
code += " = function(builder, " + argname + ") {\n";
|
||||
@@ -588,7 +583,7 @@ static void GenStruct(const Parser &parser, StructDef &struct_def,
|
||||
if (!IsStruct(vector_type)) {
|
||||
GenDocComment(code_ptr,
|
||||
"@param {flatbuffers.Builder} builder\n"
|
||||
"@param {Array.<" + GenTypeName(vector_type, InOut::IN) +
|
||||
"@param {Array.<" + GenTypeName(vector_type, true) +
|
||||
">} data\n"
|
||||
"@returns {flatbuffers.Offset}");
|
||||
code += object_name + ".create" + MakeCamel(field.name);
|
||||
|
||||
@@ -159,7 +159,7 @@ int64_t Parser::ParseHexNum(int nibbles) {
|
||||
Error("escape code must be followed by " + NumToString(nibbles) +
|
||||
" hex digits");
|
||||
std::string target(cursor_, cursor_ + nibbles);
|
||||
auto val = StringToInt(target.c_str(), 16);
|
||||
auto val = StringToUInt(target.c_str(), 16);
|
||||
cursor_ += nibbles;
|
||||
return val;
|
||||
}
|
||||
@@ -288,7 +288,7 @@ void Parser::Next() {
|
||||
cursor_++;
|
||||
while (isxdigit(static_cast<unsigned char>(*cursor_))) cursor_++;
|
||||
attribute_.append(start + 2, cursor_);
|
||||
attribute_ = NumToString(StringToInt(attribute_.c_str(), 16));
|
||||
attribute_ = NumToString(StringToUInt(attribute_.c_str(), 16));
|
||||
token_ = kTokenIntegerConstant;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user