| 1 | /* |
| 2 | * Copyright 2014 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <algorithm> |
| 18 | #include <cmath> |
| 19 | #include <list> |
| 20 | #include <string> |
| 21 | #include <utility> |
| 22 | |
| 23 | #include "flatbuffers/base.h" |
| 24 | #include "flatbuffers/idl.h" |
| 25 | #include "flatbuffers/util.h" |
| 26 | |
| 27 | namespace flatbuffers { |
| 28 | |
| 29 | // Reflects the version at the compiling time of binary(lib/dll/so). |
| 30 | const char *FLATBUFFERS_VERSION() { |
| 31 | // clang-format off |
| 32 | return |
| 33 | FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MAJOR) "." |
| 34 | FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MINOR) "." |
| 35 | FLATBUFFERS_STRING(FLATBUFFERS_VERSION_REVISION); |
| 36 | // clang-format on |
| 37 | } |
| 38 | |
| 39 | const double kPi = 3.14159265358979323846; |
| 40 | |
| 41 | // clang-format off |
| 42 | const char *const kTypeNames[] = { |
| 43 | #define FLATBUFFERS_TD(ENUM, IDLTYPE, ...) \ |
| 44 | IDLTYPE, |
| 45 | FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) |
| 46 | #undef FLATBUFFERS_TD |
| 47 | nullptr |
| 48 | }; |
| 49 | |
| 50 | const char kTypeSizes[] = { |
| 51 | #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \ |
| 52 | sizeof(CTYPE), |
| 53 | FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) |
| 54 | #undef FLATBUFFERS_TD |
| 55 | }; |
| 56 | // clang-format on |
| 57 | |
| 58 | // The enums in the reflection schema should match the ones we use internally. |
| 59 | // Compare the last element to check if these go out of sync. |
| 60 | static_assert(BASE_TYPE_UNION == static_cast<BaseType>(reflection::Union), |
| 61 | "enums don't match" ); |
| 62 | |
| 63 | // Any parsing calls have to be wrapped in this macro, which automates |
| 64 | // handling of recursive error checking a bit. It will check the received |
| 65 | // CheckedError object, and return straight away on error. |
| 66 | #define ECHECK(call) \ |
| 67 | { \ |
| 68 | auto |
|---|