00001 /* Copyright (c) 2011-2013, Take Vos 00002 * All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are met: 00006 * 00007 * - Redistributions of source code must retain the above copyright notice, 00008 * this list of conditions and the following disclaimer. 00009 * - Redistributions in binary form must reproduce the above copyright notice, 00010 * this list of conditions and the following disclaimer in the documentation 00011 * and/or other materials provided with the distribution. 00012 * 00013 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00014 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00015 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00016 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00017 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00018 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00019 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00020 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00021 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00022 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00023 * POSSIBILITY OF SUCH DAMAGE. 00024 */ 00025 #ifndef YA_TYPES_H 00026 #define YA_TYPES_H 00027 00028 #define _GNU_SOURCE 00029 #include <stddef.h> 00030 #include <stdlib.h> 00031 #include <stdint.h> 00032 #include <string.h> 00033 #include <sys/param.h> 00034 00035 #if __STDC_VERSION__ < 199901L 00036 #define restrict 00037 #endif 00038 00039 typedef __uint128_t uint128_t; 00040 00041 typedef uint64_t ya_name_t; 00042 typedef uint8_t ya_type_t; 00043 00044 #define YA_NODE_TYPE_NULL 0 00045 #define YA_NODE_TYPE_LEAF 1 00046 #define YA_NODE_TYPE_BRANCH 2 00047 #define YA_NODE_TYPE_TEXT 3 00048 #define YA_NODE_TYPE_POSITIVE_INTEGER 4 00049 #define YA_NODE_TYPE_NEGATIVE_INTEGER 5 00050 #define YA_NODE_TYPE_BINARY_FLOAT 6 00051 #define YA_NODE_TYPE_DECIMAL_FLOAT 7 00052 00053 #define YA_NODE_TYPE_LIST 254 00054 #define YA_NODE_TYPE_COUNT 255 00055 00056 00058 struct ya_position_s { 00059 uint32_t line; 00060 uint32_t column; 00061 uint32_t file; 00062 } __attribute__((packed, aligned(4))); 00063 typedef struct ya_position_s ya_position_t; 00064 00069 struct ya_node_s { 00070 ya_name_t name; 00071 uint64_t size; 00072 ya_position_t position; 00073 uint16_t reserved_1; 00074 uint8_t reserved_2; 00075 ya_type_t type; 00076 char data[]; 00077 } __attribute__((packed, aligned(8))); 00078 typedef struct ya_node_s ya_node_t; 00079 00083 typedef struct { 00084 uint64_t size; //< Size including header and padding. 00085 ya_position_t position; //< Position where the start of the node is located in the source file. 00086 ya_type_t type; //< The type of node. 00087 ya_node_t *node; //< The complete data, including the header. 00088 } ya_t; 00089 00090 extern ya_t ya_start; 00091 00094 #define YYSTYPE ya_t 00095 00100 static inline ya_name_t ya_create_name(const char * restrict s) 00101 { 00102 unsigned int i; 00103 unsigned int s_len = strlen(s); 00104 ya_name_t name = 0; 00105 00106 for (i = 0; i < sizeof (name); i++) { 00107 name <<= 8; 00108 if (i < s_len) { 00109 // String is left justified. 00110 name |= s[i]; 00111 } else { 00112 // With trailing spaces. 00113 name |= ' '; 00114 } 00115 } 00116 return name; 00117 } 00118 00119 00120 #endif