chromium/third_party/flatbuffers/src/src/idl_parser.cpp

/*
 * Copyright 2014 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <string>
#include <utility>

#include "flatbuffers/base.h"
#include "flatbuffers/buffer.h"
#include "flatbuffers/idl.h"
#include "flatbuffers/reflection_generated.h"
#include "flatbuffers/util.h"

namespace flatbuffers {

// Reflects the version at the compiling time of binary(lib/dll/so).
const char *FLATBUFFERS_VERSION() {}

namespace {

static const double kPi =;

// The enums in the reflection schema should match the ones we use internally.
// Compare the last element to check if these go out of sync.
static_assert;

// Any parsing calls have to be wrapped in this macro, which automates
// handling of recursive error checking a bit. It will check the received
// CheckedError object, and return straight away on error.
#define ECHECK(call)

// These two functions are called hundreds of times below, so define a short
// form:
#define NEXT()
#define EXPECT(tok)

static bool ValidateUTF8(const std::string &str) {}

static bool IsLowerSnakeCase(const std::string &str) {}

static void DeserializeDoc(std::vector<std::string> &doc,
                           const Vector<Offset<String>> *documentation) {}

static CheckedError NoError() {}

template<typename T> static std::string TypeToIntervalString() {}

// atot: template version of atoi/atof: convert a string to an instance of T.
template<typename T>
static bool atot_scalar(const char *s, T *val, bool_constant<false>) {}

template<typename T>
static bool atot_scalar(const char *s, T *val, bool_constant<true>) {}

template<typename T>
static CheckedError atot(const char *s, Parser &parser, T *val) {}
template<>
CheckedError atot<Offset<void>>(const char *s, Parser &parser,
                                Offset<void> *val) {}

template<>
CheckedError atot<Offset64<void>>(const char *s, Parser &parser,
                                  Offset64<void> *val) {}

template<typename T>
static T *LookupTableByName(const SymbolTable<T> &table,
                            const std::string &name,
                            const Namespace &current_namespace,
                            size_t skip_top) {}

// Declare tokens we'll use. Single character tokens are represented by their
// ascii character code (e.g. '{'), others above 256.
// clang-format off
#define FLATBUFFERS_GEN_TOKENS(TD)
#ifdef __GNUC__
__extension__  // Stop GCC complaining about trailing comma with -Wpendantic.
#endif
enum {};

static std::string TokenToString(int t) {}
// clang-format on

static bool IsIdentifierStart(char c) {}

static bool CompareSerializedScalars(const uint8_t *a, const uint8_t *b,
                                     const FieldDef &key) {}

static bool CompareTablesByScalarKey(const Offset<Table> *_a,
                                     const Offset<Table> *_b,
                                     const FieldDef &key) {}

static bool CompareTablesByStringKey(const Offset<Table> *_a,
                                     const Offset<Table> *_b,
                                     const FieldDef &key) {}

static void SwapSerializedTables(Offset<Table> *a, Offset<Table> *b) {}

// See below for why we need our own sort :(
template<typename T, typename F, typename S>
static void SimpleQsort(T *begin, T *end, size_t width, F comparator,
                        S swapper) {}

template<typename T> static inline void SingleValueRepack(Value &e, T val) {}

#if defined(FLATBUFFERS_HAS_NEW_STRTOD) && (FLATBUFFERS_HAS_NEW_STRTOD > 0)
// Normalize defaults NaN to unsigned quiet-NaN(0) if value was parsed from
// hex-float literal.
static void SingleValueRepack(Value &e, float val) {}
static void SingleValueRepack(Value &e, double val) {}
#endif

template<typename T> static uint64_t EnumDistanceImpl(T e1, T e2) {}

static bool compareFieldDefs(const FieldDef *a, const FieldDef *b) {}

static Namespace *GetNamespace(
    const std::string &qualified_name, std::vector<Namespace *> &namespaces,
    std::map<std::string, Namespace *> &namespaces_index) {}

// Generate a unique hash for a file based on its name and contents (if any).
static uint64_t HashFile(const char *source_filename, const char *source) {}

template<typename T> static bool compareName(const T *a, const T *b) {}

template<typename T> static void AssignIndices(const std::vector<T *> &defvec) {}

}  // namespace

void Parser::Message(const std::string &msg) {}

void Parser::Warning(const std::string &msg) {}

CheckedError Parser::Error(const std::string &msg) {}

CheckedError Parser::RecurseError() {}

const std::string &Parser::GetPooledString(const std::string &s) const {}

class Parser::ParseDepthGuard {};

std::string Namespace::GetFullyQualifiedName(const std::string &name,
                                             size_t max_components) const {}

std::string Parser::TokenToStringId(int t) const {}

// Parses exactly nibbles worth of hex digits into a number, or error.
CheckedError Parser::ParseHexNum(int nibbles, uint64_t *val) {}

CheckedError Parser::SkipByteOrderMark() {}

CheckedError Parser::Next() {}

// Check if a given token is next.
bool Parser::Is(int t) const {}

bool Parser::IsIdent(const char *id) const {}

// Expect a given token to be next, consume it, or error if not present.
CheckedError Parser::Expect(int t) {}

CheckedError Parser::ParseNamespacing(std::string *id, std::string *last) {}

EnumDef *Parser::LookupEnum(const std::string &id) {}

StructDef *Parser::LookupStruct(const std::string &id) const {}

StructDef *Parser::LookupStructThruParentNamespaces(
    const std::string &id) const {}

CheckedError Parser::ParseTypeIdent(Type &type) {}

// Parse any IDL type.
CheckedError Parser::ParseType(Type &type) {}

CheckedError Parser::AddField(StructDef &struct_def, const std::string &name,
                              const Type &type, FieldDef **dest) {}

CheckedError Parser::ParseField(StructDef &struct_def) {}

CheckedError Parser::ParseString(Value &val, bool use_string_pooling) {}

CheckedError Parser::ParseComma() {}

CheckedError Parser::ParseAnyValue(Value &val, FieldDef *field,
                                   size_t parent_fieldn,
                                   const StructDef *parent_struct_def,
                                   size_t count, bool inside_vector) {}

void Parser::SerializeStruct(const StructDef &struct_def, const Value &val) {}

void Parser::SerializeStruct(FlatBufferBuilder &builder,
                             const StructDef &struct_def, const Value &val) {}

template<typename F>
CheckedError Parser::ParseTableDelimiters(size_t &fieldn,
                                          const StructDef *struct_def, F body) {}

CheckedError Parser::ParseTable(const StructDef &struct_def, std::string *value,
                                uoffset_t *ovalue) {}

template<typename F>
CheckedError Parser::ParseVectorDelimiters(size_t &count, F body) {}

CheckedError Parser::ParseAlignAttribute(const std::string &align_constant,
                                         size_t min_align, size_t *align) {}

CheckedError Parser::ParseVector(const Type &vector_type, uoffset_t *ovalue,
                                 FieldDef *field, size_t fieldn) {}

CheckedError Parser::ParseArray(Value &array) {}

CheckedError Parser::ParseNestedFlatbuffer(Value &val, FieldDef *field,
                                           size_t fieldn,
                                           const StructDef *parent_struct_def) {}

CheckedError Parser::ParseMetaData(SymbolTable<Value> *attributes) {}

CheckedError Parser::ParseEnumFromString(const Type &type,
                                         std::string *result) {}

CheckedError Parser::ParseHash(Value &e, FieldDef *field) {}

CheckedError Parser::TokenError() {}

CheckedError Parser::ParseFunction(const std::string *name, Value &e) {}

CheckedError Parser::TryTypedValue(const std::string *name, int dtoken,
                                   bool check, Value &e, BaseType req,
                                   bool *destmatch) {}

CheckedError Parser::ParseSingleValue(const std::string *name, Value &e,
                                      bool check_now) {}

StructDef *Parser::LookupCreateStruct(const std::string &name,
                                      bool create_if_new, bool definition) {}

const EnumVal *EnumDef::MinValue() const {}
const EnumVal *EnumDef::MaxValue() const {}

uint64_t EnumDef::Distance(const EnumVal *v1, const EnumVal *v2) const {}

std::string EnumDef::AllFlags() const {}

EnumVal *EnumDef::ReverseLookup(int64_t enum_idx,
                                bool skip_union_default) const {}

EnumVal *EnumDef::FindByValue(const std::string &constant) const {}

void EnumDef::SortByValue() {}

void EnumDef::RemoveDuplicates() {}

template<typename T> void EnumDef::ChangeEnumValue(EnumVal *ev, T new_value) {}

namespace EnumHelper {
template<BaseType E> struct EnumValType {};
template<> struct EnumValType<BASE_TYPE_ULONG> {};
}  // namespace EnumHelper

struct EnumValBuilder {};

CheckedError Parser::ParseEnum(const bool is_union, EnumDef **dest,
                               const char *filename) {}

CheckedError Parser::StartStruct(const std::string &name, StructDef **dest) {}

CheckedError Parser::CheckClash(std::vector<FieldDef *> &fields,
                                StructDef *struct_def, const char *suffix,
                                BaseType basetype) {}

std::vector<IncludedFile> Parser::GetIncludedFiles() const {}

bool Parser::SupportsOptionalScalars(const flatbuffers::IDLOptions &opts) {}
bool Parser::SupportsOptionalScalars() const {}

bool Parser::SupportsDefaultVectorsAndStrings() const {}

bool Parser::SupportsAdvancedUnionFeatures() const {}

bool Parser::SupportsAdvancedArrayFeatures() const {}

bool Parser::Supports64BitOffsets() const {}

bool Parser::SupportsUnionUnderlyingType() const {}

Namespace *Parser::UniqueNamespace(Namespace *ns) {}

std::string Parser::UnqualifiedName(const std::string &full_qualified_name) {}

CheckedError Parser::ParseDecl(const char *filename) {}

CheckedError Parser::ParseService(const char *filename) {}

bool Parser::SetRootType(const char *name) {}

void Parser::MarkGenerated() {}

CheckedError Parser::ParseNamespace() {}

// Best effort parsing of .proto declarations, with the aim to turn them
// in the closest corresponding FlatBuffer equivalent.
// We parse everything as identifiers instead of keywords, since we don't
// want protobuf keywords to become invalid identifiers in FlatBuffers.
CheckedError Parser::ParseProtoDecl() {}

CheckedError Parser::StartEnum(const std::string &name, bool is_union,
                               EnumDef **dest) {}

CheckedError Parser::ParseProtoFields(StructDef *struct_def, bool isextend,
                                      bool inside_oneof) {}

CheckedError Parser::ParseProtoMapField(StructDef *struct_def) {}

CheckedError Parser::ParseProtoKey() {}

CheckedError Parser::ParseProtoCurliesOrIdent() {}

CheckedError Parser::ParseProtoOption() {}

// Parse a protobuf type, and map it to the corresponding FlatBuffer one.
CheckedError Parser::ParseTypeFromProtoType(Type *type) {}

CheckedError Parser::SkipAnyJsonValue() {}

CheckedError Parser::ParseFlexBufferNumericConstant(
    flexbuffers::Builder *builder) {}

CheckedError Parser::ParseFlexBufferValue(flexbuffers::Builder *builder) {}

bool Parser::ParseFlexBuffer(const char *source, const char *source_filename,
                             flexbuffers::Builder *builder) {}

bool Parser::Parse(const char *source, const char **include_paths,
                   const char *source_filename) {}

bool Parser::ParseJson(const char *json, const char *json_filename) {}

std::ptrdiff_t Parser::BytesConsumed() const {}

CheckedError Parser::StartParseFile(const char *source,
                                    const char *source_filename) {}

CheckedError Parser::ParseRoot(const char *source, const char **include_paths,
                               const char *source_filename) {}

CheckedError Parser::CheckPrivateLeak() {}

CheckedError Parser::CheckPrivatelyLeakedFields(const Definition &def,
                                                const Definition &value_type) {}

CheckedError Parser::DoParse(const char *source, const char **include_paths,
                             const char *source_filename,
                             const char *include_filename) {}

CheckedError Parser::DoParseJson() {}

std::set<std::string> Parser::GetIncludedFilesRecursive(
    const std::string &file_name) const {}

// Schema serialization functionality:

static flatbuffers::Offset<
    flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
SerializeAttributesCommon(const SymbolTable<Value> &attributes,
                          FlatBufferBuilder *builder, const Parser &parser) {}

static bool DeserializeAttributesCommon(
    SymbolTable<Value> &attributes, Parser &parser,
    const Vector<Offset<reflection::KeyValue>> *attrs) {}

void Parser::Serialize() {}

Offset<reflection::Object> StructDef::Serialize(FlatBufferBuilder *builder,
                                                const Parser &parser) const {}

bool StructDef::Deserialize(Parser &parser, const reflection::Object *object) {}

Offset<reflection::Field> FieldDef::Serialize(FlatBufferBuilder *builder,
                                              uint16_t id,
                                              const Parser &parser) const {}

bool FieldDef::Deserialize(Parser &parser, const reflection::Field *field) {}

Offset<reflection::RPCCall> RPCCall::Serialize(FlatBufferBuilder *builder,
                                               const Parser &parser) const {}

bool RPCCall::Deserialize(Parser &parser, const reflection::RPCCall *call) {}

Offset<reflection::Service> ServiceDef::Serialize(FlatBufferBuilder *builder,
                                                  const Parser &parser) const {}

bool ServiceDef::Deserialize(Parser &parser,
                             const reflection::Service *service) {}

Offset<reflection::Enum> EnumDef::Serialize(FlatBufferBuilder *builder,
                                            const Parser &parser) const {}

bool EnumDef::Deserialize(Parser &parser, const reflection::Enum *_enum) {}

flatbuffers::Offset<
    flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
EnumVal::SerializeAttributes(FlatBufferBuilder *builder,
                             const Parser &parser) const {}

bool EnumVal::DeserializeAttributes(
    Parser &parser, const Vector<Offset<reflection::KeyValue>> *attrs) {}

Offset<reflection::EnumVal> EnumVal::Serialize(FlatBufferBuilder *builder,
                                               const Parser &parser) const {}

bool EnumVal::Deserialize(Parser &parser, const reflection::EnumVal *val) {}

Offset<reflection::Type> Type::Serialize(FlatBufferBuilder *builder) const {}

bool Type::Deserialize(const Parser &parser, const reflection::Type *type) {}

flatbuffers::Offset<
    flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
Definition::SerializeAttributes(FlatBufferBuilder *builder,
                                const Parser &parser) const {}

bool Definition::DeserializeAttributes(
    Parser &parser, const Vector<Offset<reflection::KeyValue>> *attrs) {}

/************************************************************************/
/* DESERIALIZATION                                                      */
/************************************************************************/
bool Parser::Deserialize(const uint8_t *buf, const size_t size) {}

bool Parser::Deserialize(const reflection::Schema *schema) {}

std::string Parser::ConformTo(const Parser &base) {}

}  // namespace flatbuffers