| 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 <list> |
| 19 | #include <string> |
| 20 | |
| 21 | #include <math.h> |
| 22 | |
| 23 | #include "flatbuffers/idl.h" |
| 24 | #include "flatbuffers/util.h" |
| 25 | |
| 26 | namespace flatbuffers { |
| 27 | |
| 28 | const double kPi = 3.14159265358979323846; |
| 29 | |
| 30 | const char *const kTypeNames[] = { |
| 31 | // clang-format off |
| 32 | #define FLATBUFFERS_TD(ENUM, IDLTYPE, \ |
| 33 | CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, RTYPE) \ |
| 34 | IDLTYPE, |
| 35 | FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) |
| 36 | #undef FLATBUFFERS_TD |
| 37 | // clang-format on |
| 38 | nullptr |
| 39 | }; |
| 40 | |
| 41 | const char kTypeSizes[] = { |
| 42 | // clang-format off |
| 43 | #define FLATBUFFERS_TD(ENUM, IDLTYPE, \ |
| 44 | CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, RTYPE) \ |
| 45 | sizeof(CTYPE), |
| 46 | FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) |
| 47 | #undef FLATBUFFERS_TD |
| 48 | // clang-format on |
| 49 | }; |
| 50 | |
| 51 | // The enums in the reflection schema should match the ones we use internally. |
| 52 | // Compare the last element to check if these go out of sync. |
| 53 | static_assert(BASE_TYPE_UNION == static_cast<BaseType>(reflection::Union), |
| 54 | "enums don't match" ); |
| 55 | |
| 56 | // Any parsing calls have to be wrapped in this macro, which automates |
| 57 | // handling of recursive error checking a bit. It will check the received |
| 58 | // CheckedError object, and return straight away on error. |
| 59 | #define ECHECK(call) \ |
| 60 | { \ |
| 61 | auto |
|---|