Fix some error

This commit is contained in:
吴凡
2016-07-01 11:17:03 +08:00
parent 70deb70b76
commit 5ea2b49f58
13 changed files with 1 additions and 647 deletions

View File

@@ -29,12 +29,7 @@ static void Error(const std::string &err, bool usage = false,
struct Generator {
bool (*generate)(const flatbuffers::Parser &parser,
const std::string &path,
<<<<<<< HEAD
const std::string &file_name,
const flatbuffers::GeneratorOptions &opts);
=======
const std::string &file_name);
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
const char *generator_opt_short;
const char *generator_opt_long;
const char *lang_name;
@@ -48,41 +43,6 @@ struct Generator {
const Generator generators[] = {
{ flatbuffers::GenerateBinary, "-b", "--binary", "binary",
<<<<<<< HEAD
flatbuffers::GeneratorOptions::kMAX,
"Generate wire format binaries for any data definitions",
flatbuffers::BinaryMakeRule },
{ flatbuffers::GenerateTextFile, "-t", "--json", "text",
flatbuffers::GeneratorOptions::kMAX,
"Generate text output for any data definitions",
flatbuffers::TextMakeRule },
{ flatbuffers::GenerateCPP, "-c", "--cpp", "C++",
flatbuffers::GeneratorOptions::kMAX,
"Generate C++ headers for tables/structs",
flatbuffers::CPPMakeRule },
{ flatbuffers::GenerateGo, "-g", "--go", "Go",
flatbuffers::GeneratorOptions::kGo,
"Generate Go files for tables/structs",
flatbuffers::GeneralMakeRule },
{ flatbuffers::GenerateGeneral, "-j", "--java", "Java",
flatbuffers::GeneratorOptions::kJava,
"Generate Java classes for tables/structs",
flatbuffers::GeneralMakeRule },
{ flatbuffers::GenerateJS, "-s", "--js", "JavaScript",
flatbuffers::GeneratorOptions::kMAX,
"Generate JavaScript code for tables/structs",
flatbuffers::JSMakeRule },
{ flatbuffers::GenerateGeneral, "-n", "--csharp", "C#",
flatbuffers::GeneratorOptions::kCSharp,
"Generate C# classes for tables/structs",
flatbuffers::GeneralMakeRule },
{ flatbuffers::GeneratePython, "-p", "--python", "Python",
flatbuffers::GeneratorOptions::kMAX,
"Generate Python files for tables/structs",
flatbuffers::GeneralMakeRule },
{ flatbuffers::GeneratePhp, nullptr, "--php", "PHP",
flatbuffers::GeneratorOptions::kMAX,
=======
flatbuffers::IDLOptions::kMAX,
"Generate wire format binaries for any data definitions",
flatbuffers::BinaryMakeRule },
@@ -116,7 +76,6 @@ const Generator generators[] = {
flatbuffers::GeneralMakeRule },
{ flatbuffers::GeneratePhp, nullptr, "--php", "PHP",
flatbuffers::IDLOptions::kMAX,
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
"Generate PHP files for tables/structs",
flatbuffers::GeneralMakeRule },
{ flatbuffers::GenerateGRPC, nullptr, "--grpc", "GRPC",
@@ -270,11 +229,7 @@ int main(int argc, const char *argv[]) {
}
// Now process the files:
<<<<<<< HEAD
parser = new flatbuffers::Parser(opts.strict_json, proto_mode);
=======
parser = new flatbuffers::Parser(opts);
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
for (auto file_it = filenames.begin();
file_it != filenames.end();
++file_it) {
@@ -310,23 +265,16 @@ int main(int argc, const char *argv[]) {
}
}
} else {
<<<<<<< HEAD
=======
// Check if file contains 0 bytes.
if (contents.length() != strlen(contents.c_str())) {
Error("input file appears to be binary: " + *file_it, true);
}
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
if (flatbuffers::GetExtension(*file_it) == "fbs") {
// If we're processing multiple schemas, make sure to start each
// one from scratch. If it depends on previous schemas it must do
// so explicitly using an include.
delete parser;
<<<<<<< HEAD
parser = new flatbuffers::Parser(opts.strict_json, proto_mode);
=======
parser = new flatbuffers::Parser(opts);
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
}
auto local_include_directory = flatbuffers::StripFileName(*file_it);
include_directories.push_back(local_include_directory.c_str());
@@ -350,11 +298,7 @@ int main(int argc, const char *argv[]) {
if (generator_enabled[i]) {
if (!print_make_rules) {
flatbuffers::EnsureDirExists(output_path);
<<<<<<< HEAD
if (!generators[i].generate(*parser, output_path, filebase, opts)) {
=======
if (!generators[i].generate(*parser, output_path, filebase)) {
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
Error(std::string("Unable to generate ") +
generators[i].lang_name +
" for " +
@@ -362,11 +306,7 @@ int main(int argc, const char *argv[]) {
}
} else {
std::string make_rule = generators[i].make_rule(
<<<<<<< HEAD
*parser, output_path, *file_it, opts);
=======
*parser, output_path, *file_it);
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
if (!make_rule.empty())
printf("%s\n", flatbuffers::WordWrap(
make_rule, 80, " ", " \\").c_str());
@@ -374,15 +314,11 @@ int main(int argc, const char *argv[]) {
}
}
<<<<<<< HEAD
if (proto_mode) GenerateFBS(*parser, output_path, filebase, opts);
=======
if (opts.proto_mode) GenerateFBS(*parser, output_path, filebase);
// We do not want to generate code for the definitions in this file
// in any files coming up next.
parser->MarkGenerated();
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
}
delete parser;

View File

@@ -208,40 +208,6 @@ class CppGenerator : public BaseGenerator {
// This tracks the current namespace so we can insert namespace declarations.
const Namespace *cur_name_space_ = nullptr;
<<<<<<< HEAD
// Return a C++ type from the table in idl.h
static std::string GenTypeBasic(const Parser &parser, const Type &type,
bool user_facing_type) {
static const char *ctypename[] = {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
#CTYPE,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD
};
if (user_facing_type) {
if (type.enum_def) return WrapInNameSpace(parser, *type.enum_def);
if (type.base_type == BASE_TYPE_BOOL) return "bool";
}
return ctypename[type.base_type];
}
static std::string GenTypeWire(const Parser &parser, const Type &type,
const char *postfix, bool user_facing_type);
// Return a C++ pointer type, specialized to the actual struct/table types,
// and vector element types.
static std::string GenTypePointer(const Parser &parser, const Type &type) {
switch (type.base_type) {
case BASE_TYPE_STRING:
return "flatbuffers::String";
case BASE_TYPE_VECTOR:
return "flatbuffers::Vector<" +
GenTypeWire(parser, type.VectorType(), "", false) + ">";
case BASE_TYPE_STRUCT: {
return WrapInNameSpace(parser, *type.struct_def);
}
case BASE_TYPE_UNION:
=======
const Namespace *CurrentNameSpace() { return cur_name_space_; }
// Translates a qualified name in flatbuffer text format to the same name in
@@ -283,25 +249,12 @@ static std::string GenTypePointer(const Parser &parser, const Type &type) {
return WrapInNameSpace(*type.struct_def);
}
case BASE_TYPE_UNION:
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
// fall through
default:
return "void";
}
}
<<<<<<< HEAD
// Return a C++ type for any type (scalar/pointer) specifically for
// building a flatbuffer.
static std::string GenTypeWire(const Parser &parser, const Type &type,
const char *postfix, bool user_facing_type) {
return IsScalar(type.base_type)
? GenTypeBasic(parser, type, user_facing_type) + postfix
: IsStruct(type)
? "const " + GenTypePointer(parser, type) + " *"
: "flatbuffers::Offset<" + GenTypePointer(parser, type) + ">" + postfix;
}
=======
// Return a C++ type for any type (scalar/pointer) specifically for
// building a flatbuffer.
std::string GenTypeWire(const Type &type,
@@ -313,7 +266,6 @@ static std::string GenTypeWire(const Parser &parser, const Type &type,
: "flatbuffers::Offset<" + GenTypePointer(type) +
">" + postfix;
}
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
// Return a C++ type for any type (scalar/pointer) that reflects its
// serialized size.
@@ -324,17 +276,6 @@ static std::string GenTypeWire(const Parser &parser, const Type &type,
: "flatbuffers::uoffset_t";
}
<<<<<<< HEAD
// Return a C++ type for any type (scalar/pointer) specifically for
// using a flatbuffer.
static std::string GenTypeGet(const Parser &parser, const Type &type,
const char *afterbasic, const char *beforeptr,
const char *afterptr, bool user_facing_type) {
return IsScalar(type.base_type)
? GenTypeBasic(parser, type, user_facing_type) + afterbasic
: beforeptr + GenTypePointer(parser, type) + afterptr;
}
=======
// Return a C++ type for any type (scalar/pointer) specifically for
// using a flatbuffer.
std::string GenTypeGet(const Type &type,
@@ -344,7 +285,6 @@ static std::string GenTypeGet(const Parser &parser, const Type &type,
? GenTypeBasic(type, user_facing_type) + afterbasic
: beforeptr + GenTypePointer(type) + afterptr;
}
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
static std::string GenEnumDecl(const EnumDef &enum_def,
const IDLOptions &opts) {
@@ -387,20 +327,6 @@ static std::string GenTypeGet(const Parser &parser, const Type &type,
EnumVal *minv = nullptr, *maxv = nullptr;
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
++it) {
<<<<<<< HEAD
while (val++ != (*it)->value) code += "\"\", ";
code += "\"" + (*it)->name + "\", ";
}
code += "nullptr };\n return names;\n}\n\n";
code += "inline const char *EnumName" + enum_def.name;
code += "(" + enum_def.name + " e) { return EnumNames" + enum_def.name;
code += "()[static_cast<int>(e)";
if (enum_def.vals.vec.front()->value) {
code += " - static_cast<int>(";
code += GetEnumVal(enum_def, *enum_def.vals.vec.front(), opts) +")";
}
code += "]; }\n\n";
=======
auto &ev = **it;
GenComment(ev.doc_comment, code_ptr, nullptr, " ");
code += " " + GenEnumVal(enum_def, ev.name, parser_.opts) + " = ";
@@ -464,7 +390,6 @@ static std::string GenTypeGet(const Parser &parser, const Type &type,
if (enum_def.is_union) {
code += EnumSignature(enum_def) + ";\n\n";
}
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
}
void GenEnumPost(EnumDef &enum_def, std::string *code_ptr_post) {
@@ -490,90 +415,6 @@ static std::string GenTypeGet(const Parser &parser, const Type &type,
code_post += " default: return false;\n }\n}\n\n";
}
<<<<<<< HEAD
// Generates a value with optionally a cast applied if the field has a
// different underlying type from its interface type (currently only the
// case for enums. "from" specify the direction, true meaning from the
// underlying type to the interface type.
std::string GenUnderlyingCast(const Parser &parser, const FieldDef &field,
bool from, const std::string &val) {
return (field.value.type.enum_def && IsScalar(field.value.type.base_type)) ||
field.value.type.base_type == BASE_TYPE_BOOL
? "static_cast<" + GenTypeBasic(parser, field.value.type, from) + ">(" +
val + ")"
: val;
}
std::string GenFieldOffsetName(const FieldDef &field) {
std::string uname = field.name;
std::transform(uname.begin(), uname.end(), uname.begin(), ::toupper);
return "VT_" + uname;
}
// Generate an accessor struct, builder structs & function for a table.
static void GenTable(const Parser &parser, StructDef &struct_def,
const GeneratorOptions &opts, std::string *code_ptr) {
if (struct_def.generated) return;
std::string &code = *code_ptr;
// Generate an accessor struct, with methods of the form:
// type name() const { return GetField<type>(offset, defaultval); }
GenComment(struct_def.doc_comment, code_ptr, nullptr);
code += "struct " + struct_def.name;
code += " FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table";
code += " {\n";
// Generate field id constants.
code += " enum {\n";
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end();
++it) {
auto &field = **it;
if (!field.deprecated) { // Deprecated fields won't be accessible.
code += " " + GenFieldOffsetName(field) + " = ";
code += NumToString(field.value.offset) + ",\n";
}
}
code += " };\n";
// Generate the accessors.
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end();
++it) {
auto &field = **it;
if (!field.deprecated) { // Deprecated fields won't be accessible.
auto is_scalar = IsScalar(field.value.type.base_type);
GenComment(field.doc_comment, code_ptr, nullptr, " ");
code += " " + GenTypeGet(parser, field.value.type, " ", "const ", " *",
true);
code += field.name + "() const { return ";
// Call a different accessor for pointers, that indirects.
auto accessor = is_scalar
? "GetField<"
: (IsStruct(field.value.type) ? "GetStruct<" : "GetPointer<");
auto offsetstr = GenFieldOffsetName(field);
auto call =
accessor +
GenTypeGet(parser, field.value.type, "", "const ", " *", false) +
">(" + offsetstr;
// Default value as second arg for non-pointer types.
if (IsScalar(field.value.type.base_type))
call += ", " + field.value.constant;
call += ")";
code += GenUnderlyingCast(parser, field, true, call);
code += "; }\n";
if (opts.mutable_buffer) {
if (is_scalar) {
code += " bool mutate_" + field.name + "(";
code += GenTypeBasic(parser, field.value.type, true);
code += " _" + field.name + ") { return SetField(" + offsetstr + ", ";
code += GenUnderlyingCast(parser, field, false, "_" + field.name);
code += "); }\n";
} else {
auto type = GenTypeGet(parser, field.value.type, " ", "", " *", true);
code += " " + type + "mutable_" + field.name + "() { return ";
code += GenUnderlyingCast(parser, field, true,
accessor + type + ">(" + offsetstr + ")");
code += "; }\n";
=======
// Generates a value with optionally a cast applied if the field has a
// different underlying type from its interface type (currently only the
// case for enums. "from" specify the direction, true meaning from the
@@ -646,7 +487,6 @@ static void GenTable(const Parser &parser, StructDef &struct_def,
}
code += " " + GenFieldOffsetName(field) + " = ";
code += NumToString(field.value.offset);
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
}
}
code += "\n };\n";
@@ -732,42 +572,6 @@ static void GenTable(const Parser &parser, StructDef &struct_def,
}
}
}
<<<<<<< HEAD
}
// Generate a verifier function that can check a buffer from an untrusted
// source will never cause reads outside the buffer.
code += " bool Verify(flatbuffers::Verifier &verifier) const {\n";
code += " return VerifyTableStart(verifier)";
std::string prefix = " &&\n ";
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end();
++it) {
auto &field = **it;
if (!field.deprecated) {
code += prefix + "VerifyField";
if (field.required) code += "Required";
code += "<" + GenTypeSize(parser, field.value.type);
code += ">(verifier, " + GenFieldOffsetName(field) + ")";
switch (field.value.type.base_type) {
case BASE_TYPE_UNION:
code += prefix + "Verify" + field.value.type.enum_def->name;
code += "(verifier, " + field.name + "(), " + field.name + "_type())";
break;
case BASE_TYPE_STRUCT:
if (!field.value.type.struct_def->fixed) {
code += prefix + "verifier.VerifyTable(" + field.name;
code += "())";
}
break;
case BASE_TYPE_STRING:
code += prefix + "verifier.Verify(" + field.name + "())";
break;
case BASE_TYPE_VECTOR:
code += prefix + "verifier.Verify(" + field.name + "())";
switch (field.value.type.element) {
case BASE_TYPE_STRING: {
code += prefix + "verifier.VerifyVectorOfStrings(" + field.name;
=======
// Generate a verifier function that can check a buffer from an untrusted
// source will never cause reads outside the buffer.
code += " bool Verify(flatbuffers::Verifier &verifier) const {\n";
@@ -790,7 +594,6 @@ static void GenTable(const Parser &parser, StructDef &struct_def,
case BASE_TYPE_STRUCT:
if (!field.value.type.struct_def->fixed) {
code += prefix + "verifier.VerifyTable(" + field.name;
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
code += "())";
}
break;
@@ -853,32 +656,6 @@ static void GenTable(const Parser &parser, StructDef &struct_def,
code += ", " + GenDefaultConstant(field);
code += "); }\n";
}
<<<<<<< HEAD
code += "(" + struct_def.name + "::" + GenFieldOffsetName(field) + ", ";
code += GenUnderlyingCast(parser, field, false, field.name);
if (IsScalar(field.value.type.base_type))
code += ", " + field.value.constant;
code += "); }\n";
}
}
code += " " + struct_def.name;
code += "Builder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) ";
code += "{ start_ = fbb_.StartTable(); }\n";
code += " " + struct_def.name + "Builder &operator=(const ";
code += struct_def.name + "Builder &);\n";
code += " flatbuffers::Offset<" + struct_def.name;
code += "> Finish() {\n auto o = flatbuffers::Offset<" + struct_def.name;
code += ">(fbb_.EndTable(start_, ";
code += NumToString(struct_def.fields.vec.size()) + "));\n";
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end();
++it) {
auto &field = **it;
if (!field.deprecated && field.required) {
code += " fbb_.Required(o, ";
code += struct_def.name + "::" + GenFieldOffsetName(field);
code += "); // " + field.name + "\n";
=======
}
code += " " + struct_def.name;
code += "Builder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) ";
@@ -897,7 +674,6 @@ static void GenTable(const Parser &parser, StructDef &struct_def,
code += struct_def.name + "::" + GenFieldOffsetName(field);
code += "); // " + field.name + "\n";
}
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
}
code += " return o;\n }\n};\n\n";
@@ -928,13 +704,6 @@ static void GenTable(const Parser &parser, StructDef &struct_def,
} else {
code += GenDefaultConstant(field);
}
<<<<<<< HEAD
} else if (field.value.type.base_type == BASE_TYPE_BOOL) {
code += field.value.constant == "0" ? "false" : "true";
} else {
code += field.value.constant;
=======
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
}
}
code += ") {\n " + struct_def.name + "Builder builder_(_fbb);\n";
@@ -952,118 +721,6 @@ static void GenTable(const Parser &parser, StructDef &struct_def,
code += " return builder_.Finish();\n}\n\n";
}
<<<<<<< HEAD
static void GenPadding(const FieldDef &field,
const std::function<void (int bits)> &f) {
if (field.padding) {
for (int i = 0; i < 4; i++)
if (static_cast<int>(field.padding) & (1 << i))
f((1 << i) * 8);
assert(!(field.padding & ~0xF));
}
}
// Generate an accessor struct with constructor for a flatbuffers struct.
static void GenStruct(const Parser &parser, StructDef &struct_def,
const GeneratorOptions &opts, std::string *code_ptr) {
if (struct_def.generated) return;
std::string &code = *code_ptr;
// Generate an accessor struct, with private variables of the form:
// type name_;
// Generates manual padding and alignment.
// Variables are private because they contain little endian data on all
// platforms.
GenComment(struct_def.doc_comment, code_ptr, nullptr);
code += "MANUALLY_ALIGNED_STRUCT(" + NumToString(struct_def.minalign) + ") ";
code += struct_def.name + " FLATBUFFERS_FINAL_CLASS {\n private:\n";
int padding_id = 0;
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end();
++it) {
auto &field = **it;
code += " " + GenTypeGet(parser, field.value.type, " ", "", " ", false);
code += field.name + "_;\n";
GenPadding(field, [&code, &padding_id](int bits) {
code += " int" + NumToString(bits) +
"_t __padding" + NumToString(padding_id++) + ";\n";
});
}
// Generate a constructor that takes all fields as arguments.
code += "\n public:\n " + struct_def.name + "(";
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end();
++it) {
auto &field = **it;
if (it != struct_def.fields.vec.begin()) code += ", ";
code += GenTypeGet(parser, field.value.type, " ", "const ", " &", true);
code += "_" + field.name;
}
code += ")\n : ";
padding_id = 0;
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end();
++it) {
auto &field = **it;
if (it != struct_def.fields.vec.begin()) code += ", ";
code += field.name + "_(";
if (IsScalar(field.value.type.base_type)) {
code += "flatbuffers::EndianScalar(";
code += GenUnderlyingCast(parser, field, false, "_" + field.name);
code += "))";
} else {
code += "_" + field.name + ")";
}
GenPadding(field, [&code, &padding_id](int bits) {
(void)bits;
code += ", __padding" + NumToString(padding_id++) + "(0)";
});
}
code += " {";
padding_id = 0;
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end();
++it) {
auto &field = **it;
GenPadding(field, [&code, &padding_id](int bits) {
(void)bits;
code += " (void)__padding" + NumToString(padding_id++) + ";";
});
}
code += " }\n\n";
// Generate accessor methods of the form:
// type name() const { return flatbuffers::EndianScalar(name_); }
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end();
++it) {
auto &field = **it;
GenComment(field.doc_comment, code_ptr, nullptr, " ");
auto is_scalar = IsScalar(field.value.type.base_type);
code += " " + GenTypeGet(parser, field.value.type, " ", "const ", " &",
true);
code += field.name + "() const { return ";
code += GenUnderlyingCast(parser, field, true,
is_scalar
? "flatbuffers::EndianScalar(" + field.name + "_)"
: field.name + "_");
code += "; }\n";
if (opts.mutable_buffer) {
if (is_scalar) {
code += " void mutate_" + field.name + "(";
code += GenTypeBasic(parser, field.value.type, true);
code += " _" + field.name + ") { flatbuffers::WriteScalar(&";
code += field.name + "_, ";
code += GenUnderlyingCast(parser, field, false, "_" + field.name);
code += "); }\n";
} else {
code += " ";
code += GenTypeGet(parser, field.value.type, "", "", " &", true);
code += "mutable_" + field.name + "() { return " + field.name;
code += "_; }\n";
}
=======
static void GenPadding(const FieldDef &field, std::string &code,
int &padding_id,
const std::function<void(int bits, std::string &code,
@@ -1073,7 +730,6 @@ static void GenStruct(const Parser &parser, StructDef &struct_def,
if (static_cast<int>(field.padding) & (1 << i))
f((1 << i) * 8, code, padding_id);
assert(!(field.padding & ~0xF));
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
}
}

View File

@@ -112,7 +112,7 @@ class FlatBufPrinter : public grpc_cpp_generator::Printer {
// Current indentation.
str_->insert(str_->end(), indent_ * 2, ' ');
// See if this contains more than one line.
auto lf = strchr(s, '\n');
const char * lf = strchr(s, '\n');
if (lf) {
(*str_) += std::string(s, lf + 1);
s = lf + 1;

View File

@@ -1167,11 +1167,7 @@ CheckedError Parser::ParseEnum(bool is_union, EnumDef **dest) {
EXPECT(kTokenIdentifier);
auto &enum_def = *new EnumDef();
enum_def.name = enum_name;
<<<<<<< HEAD
enum_def.file = files_being_parsed_;
=======
enum_def.file = file_being_parsed_;
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
enum_def.doc_comment = enum_comment;
enum_def.is_union = is_union;
enum_def.defined_namespace = namespaces_.back();
@@ -1268,11 +1264,7 @@ CheckedError Parser::StartStruct(const std::string &name, StructDef **dest) {
if (!struct_def.predecl) return Error("datatype already exists: " + name);
struct_def.predecl = false;
struct_def.name = name;
<<<<<<< HEAD
struct_def.file = files_being_parsed_;
=======
struct_def.file = file_being_parsed_;
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
// Move this struct to the back of the vector just in case it was predeclared,
// to preserve declaration order.
*remove(structs_.vec.begin(), structs_.vec.end(), &struct_def) = &struct_def;
@@ -1787,16 +1779,12 @@ CheckedError Parser::SkipJsonString() {
bool Parser::Parse(const char *source, const char **include_paths,
const char *source_filename) {
<<<<<<< HEAD
files_being_parsed_ = source_filename ? source_filename : "";
=======
return !DoParse(source, include_paths, source_filename).Check();
}
CheckedError Parser::DoParse(const char *source, const char **include_paths,
const char *source_filename) {
file_being_parsed_ = source_filename ? source_filename : "";
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
if (source_filename &&
included_files_.find(source_filename) == included_files_.end()) {
included_files_[source_filename] = true;
@@ -1937,23 +1925,8 @@ CheckedError Parser::DoParse(const char *source, const char **include_paths,
return Error("only tables can be union elements: " + val.name);
}
}
<<<<<<< HEAD
} catch (const std::string &msg) {
error_ = source_filename ? AbsolutePath(source_filename) : "";
#ifdef _WIN32
error_ += "(" + NumToString(line_) + ")"; // MSVC alike
#else
if (source_filename) error_ += ":";
error_ += NumToString(line_) + ":0"; // gcc alike
#endif
error_ += ": error: " + msg;
return false;
}
return true;
=======
}
return NoError();
>>>>>>> 48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
}
std::set<std::string> Parser::GetIncludedFilesRecursive(