Ion C
C library for Ion
ion_symbol_table.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Amazon.com, Inc. or its affiliates. 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  * A copy of the License is located at:
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
12  * language governing permissions and limitations under the License.
13  */
14 
17 #ifndef ION_SYMBOL_TABLE_H_
18 #define ION_SYMBOL_TABLE_H_
19 
20 #include "ion_types.h"
21 #include "ion_platform_config.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
28 {
29  ION_STRING name;
30  SID location;
32 
34 {
35  SID sid;
36  ION_STRING value;
37  ION_SYMBOL_IMPORT_LOCATION import_location;
38  // TODO this is only needed for symbol usage metrics. Consider removal.
39  int32_t add_count;
40 };
41 
42 typedef enum _ION_SYMBOL_TABLE_TYPE {
43  ist_EMPTY = 0,
44  ist_LOCAL = 1,
45  ist_SHARED = 2,
46  ist_SYSTEM = 3
47 } ION_SYMBOL_TABLE_TYPE;
48 
49 #define ION_SYMBOL_IMPORT_LOCATION_IS_NULL(symbol) ION_STRING_IS_NULL(&(symbol)->import_location.name)
50 #define ION_SYMBOL_IS_NULL(symbol) (symbol == NULL || (ION_STRING_IS_NULL(&(symbol)->value) && ION_SYMBOL_IMPORT_LOCATION_IS_NULL(symbol) && (symbol)->sid == UNKNOWN_SID))
51 #define ION_SYMBOL_INIT(symbol) ION_STRING_INIT(&(symbol)->value); ION_STRING_INIT(&(symbol)->import_location.name); (symbol)->sid = UNKNOWN_SID
52 
53 #define UNKNOWN_SID -1 /* symbol id's presume not only is this unknown, but sid's must be positive */
54 
55 //
56 // Ion Symbol table implementation
57 //
58 #define ION_SYS_SYMBOL_SHARED_SYMBOL_TABLE "$ion_shared_symbol_table"
59 #define ION_SYS_STRLEN_SHARED_SYMBOL_TABLE 24 /* "$ion_shared_symbol_table" */
60 
61 #define ION_SYS_SYMBOL_ION "$ion"
62 #define ION_SYS_SYMBOL_IVM "$ion_1_0" /* ion type marker */
63 #define ION_SYS_SYMBOL_ION_SYMBOL_TABLE "$ion_symbol_table"
64 #define ION_SYS_SYMBOL_NAME "name"
65 #define ION_SYS_SYMBOL_VERSION "version"
66 #define ION_SYS_SYMBOL_IMPORTS "imports"
67 #define ION_SYS_SYMBOL_SYMBOLS "symbols"
68 #define ION_SYS_SYMBOL_MAX_ID "max_id"
69 
70 #define ION_SYS_SYMBOL_MAX_ID_UNDEFINED -1
71 
72 #define ION_SYS_SID_ION 1 /* "$ion" */
73 #define ION_SYS_SID_IVM 2 /* "$ion_1_0" aka ion type marker */
74 #define ION_SYS_SID_SYMBOL_TABLE 3 /* "$ion_symbol_table" */
75 #define ION_SYS_SID_NAME 4 /* "name" */
76 #define ION_SYS_SID_VERSION 5 /* "version" */
77 #define ION_SYS_SID_IMPORTS 6 /* "imports" */
78 #define ION_SYS_SID_SYMBOLS 7 /* "symbols" */
79 #define ION_SYS_SID_MAX_ID 8 /* "max_id" */
80 #define ION_SYS_SID_SHARED_SYMBOL_TABLE 9 /* "$ion_shared_symbol_table" */
81 
82 #define ION_SYS_STRLEN_ION 4 /* "$ion" */
83 #define ION_SYS_STRLEN_IVM 8 /* "$ion_1_0" */
84 #define ION_SYS_STRLEN_SYMBOL_TABLE 17 /* "$ion_symbol_table" */
85 #define ION_SYS_STRLEN_NAME 4 /* "name" */
86 #define ION_SYS_STRLEN_VERSION 7 /* "version" */
87 #define ION_SYS_STRLEN_IMPORTS 7 /* "imports" */
88 #define ION_SYS_STRLEN_SYMBOLS 7 /* "symbols" */
89 #define ION_SYS_STRLEN_MAX_ID 6 /* "max_id" */
90 
91 GLOBAL BYTE ION_SYMBOL_ION_BYTES[]
92 #ifdef INIT_STATICS
93 = { '$', 'i', 'o', 'n', 0 }
94 #endif
95 ;
96 GLOBAL BYTE ION_SYMBOL_VTM_BYTES[]
97 #ifdef INIT_STATICS
98 = { '$', 'i', 'o', 'n', '_', '1', '_', '0', 0 }
99 #endif
100 ;
101 GLOBAL BYTE ION_SYMBOL_SYMBOL_TABLE_BYTES[]
102 #ifdef INIT_STATICS
103 = { '$', 'i', 'o', 'n', '_', 's', 'y', 'm', 'b', 'o', 'l', '_', 't', 'a', 'b', 'l', 'e', 0 }
104 #endif
105 ;
106 GLOBAL BYTE ION_SYMBOL_NAME_BYTES[]
107 #ifdef INIT_STATICS
108 = { 'n', 'a', 'm', 'e', 0 }
109 #endif
110 ;
111 GLOBAL BYTE ION_SYMBOL_VERSION_BYTES[]
112 #ifdef INIT_STATICS
113 = { 'v', 'e', 'r', 's', 'i', 'o', 'n', 0 }
114 #endif
115 ;
116 GLOBAL BYTE ION_SYMBOL_IMPORTS_BYTES[]
117 #ifdef INIT_STATICS
118 = { 'i', 'm', 'p', 'o', 'r', 't', 's', 0 }
119 #endif
120 ;
121 GLOBAL BYTE ION_SYMBOL_SYMBOLS_BYTES[]
122 #ifdef INIT_STATICS
123 = { 's', 'y', 'm', 'b', 'o', 'l', 's', 0 }
124 #endif
125 ;
126 GLOBAL BYTE ION_SYMBOL_MAX_ID_BYTES[]
127 #ifdef INIT_STATICS
128 = { 'm', 'a', 'x', '_', 'i', 'd', 0 }
129 #endif
130 ;
131 
132 GLOBAL BYTE ION_SYMBOL_SHARED_SYMBOL_TABLE_BYTES[]
133 #ifdef INIT_STATICS
134 = { '$', 'i', 'o', 'n', '_', 's', 'h', 'a', 'r', 'e', 'd', '_', 's', 'y', 'm', 'b', 'o', 'l', '_', 't', 'a', 'b', 'l', 'e', 0 }
135 #endif
136 ;
137 
138 
139 GLOBAL ION_STRING ION_SYMBOL_ION_STRING
140 #ifdef INIT_STATICS
141 = {
142  ION_SYS_STRLEN_ION,
143  ION_SYMBOL_ION_BYTES
144 }
145 #endif
146 ;
147 GLOBAL ION_STRING ION_SYMBOL_VTM_STRING
148 #ifdef INIT_STATICS
149 = {
150  ION_SYS_STRLEN_IVM,
151  ION_SYMBOL_VTM_BYTES
152 }
153 #endif
154 ;
155 GLOBAL ION_STRING ION_SYMBOL_SYMBOL_TABLE_STRING
156 #ifdef INIT_STATICS
157 = {
158  ION_SYS_STRLEN_SYMBOL_TABLE,
159  ION_SYMBOL_SYMBOL_TABLE_BYTES
160 }
161 #endif
162 ;
163 GLOBAL ION_STRING ION_SYMBOL_NAME_STRING
164 #ifdef INIT_STATICS
165 ={
166  ION_SYS_STRLEN_NAME,
167  ION_SYMBOL_NAME_BYTES
168 }
169 #endif
170 ;
171 GLOBAL ION_STRING ION_SYMBOL_VERSION_STRING
172 #ifdef INIT_STATICS
173 ={
174  ION_SYS_STRLEN_VERSION,
175  ION_SYMBOL_VERSION_BYTES
176 }
177 #endif
178 ;
179 GLOBAL ION_STRING ION_SYMBOL_IMPORTS_STRING
180 #ifdef INIT_STATICS
181 ={
182  ION_SYS_STRLEN_IMPORTS,
183  ION_SYMBOL_IMPORTS_BYTES
184 }
185 #endif
186 ;
187 GLOBAL ION_STRING ION_SYMBOL_SYMBOLS_STRING
188 #ifdef INIT_STATICS
189 ={
190  ION_SYS_STRLEN_SYMBOLS,
191  ION_SYMBOL_SYMBOLS_BYTES
192 }
193 #endif
194 ;
195 GLOBAL ION_STRING ION_SYMBOL_MAX_ID_STRING
196 #ifdef INIT_STATICS
197 ={
198  ION_SYS_STRLEN_MAX_ID,
199  ION_SYMBOL_MAX_ID_BYTES
200 }
201 #endif
202 ;
203 GLOBAL ION_STRING ION_SYMBOL_SHARED_SYMBOL_TABLE_STRING
204 #ifdef INIT_STATICS
205 ={
206  ION_SYS_STRLEN_SHARED_SYMBOL_TABLE,
207  ION_SYMBOL_SHARED_SYMBOL_TABLE_BYTES
208 }
209 #endif
210 ;
211 
212 
217 #ifdef INIT_STATICS
218 = {
219  ION_SYS_SYMBOL_ION,
220  ION_SYS_SYMBOL_IVM,
221  ION_SYS_SYMBOL_ION_SYMBOL_TABLE,
222  ION_SYS_SYMBOL_NAME,
223  ION_SYS_SYMBOL_VERSION,
224  ION_SYS_SYMBOL_IMPORTS,
225  ION_SYS_SYMBOL_SYMBOLS,
226  ION_SYS_SYMBOL_MAX_ID,
227  ION_SYS_SYMBOL_SHARED_SYMBOL_TABLE,
228  NULL
229 }
230 #endif
231 ;
232 
239 ION_API_EXPORT iERR ion_symbol_table_open (hSYMTAB *p_hsymtab, hOWNER owner);
240 
247 ION_API_EXPORT iERR ion_symbol_table_open_with_type (hSYMTAB *p_hsymtab, hOWNER owner, ION_SYMBOL_TABLE_TYPE type);
248 
255 ION_API_EXPORT iERR ion_symbol_table_clone (hSYMTAB hsymtab, hSYMTAB *p_hclone);
256 
264 ION_API_EXPORT iERR ion_symbol_table_clone_with_owner (hSYMTAB hsymtab, hSYMTAB *p_hclone, hOWNER owner);
265 
271 ION_API_EXPORT iERR ion_symbol_table_get_system_table (hSYMTAB *p_hsystem_table, int32_t version);
272 
280 ION_API_EXPORT iERR ion_symbol_table_load (hREADER hreader, hOWNER owner, hSYMTAB *p_hsymtab);
281 
287 ION_API_EXPORT iERR ion_symbol_table_unload (hSYMTAB hsymtab, hWRITER hwriter);
288 
289 ION_API_EXPORT iERR ion_symbol_table_lock (hSYMTAB hsymtab);
290 ION_API_EXPORT iERR ion_symbol_table_is_locked (hSYMTAB hsymtab, BOOL *p_is_locked);
291 ION_API_EXPORT iERR ion_symbol_table_get_type (hSYMTAB hsymtab, ION_SYMBOL_TABLE_TYPE *p_type);
292 
293 ION_API_EXPORT iERR ion_symbol_table_get_name (hSYMTAB hsymtab, iSTRING p_name);
294 ION_API_EXPORT iERR ion_symbol_table_get_version (hSYMTAB hsymtab, int32_t *p_version);
295 ION_API_EXPORT iERR ion_symbol_table_get_max_sid (hSYMTAB hsymtab, SID *p_max_id);
296 
297 ION_API_EXPORT iERR ion_symbol_table_set_name (hSYMTAB hsymtab, iSTRING name);
298 ION_API_EXPORT iERR ion_symbol_table_set_version (hSYMTAB hsymtab, int32_t version);
299 ION_API_EXPORT iERR ion_symbol_table_set_max_sid (hSYMTAB hsymtab, SID max_id);
300 
301 ION_API_EXPORT iERR ion_symbol_table_get_imports (hSYMTAB hsymtab, ION_COLLECTION **p_imports);
302 
312 ION_API_EXPORT iERR ion_symbol_table_add_import (hSYMTAB hsymtab, ION_SYMBOL_TABLE_IMPORT_DESCRIPTOR *pimport, hCATALOG catalog);
313 
319 ION_API_EXPORT iERR ion_symbol_table_import_symbol_table(hSYMTAB hsymtab, hSYMTAB hsymtab_import);
320 
321 ION_API_EXPORT iERR ion_symbol_table_find_by_name (hSYMTAB hsymtab, iSTRING name, SID *p_sid);
322 ION_API_EXPORT iERR ion_symbol_table_find_by_sid (hSYMTAB hsymtab, SID sid, iSTRING *p_name);
323 ION_API_EXPORT iERR ion_symbol_table_is_symbol_known (hSYMTAB hsymtab, SID sid, BOOL *p_is_known);
324 
325 ION_API_EXPORT iERR ion_symbol_table_get_symbol (hSYMTAB hsymtab, SID sid, ION_SYMBOL **p_sym); // get symbols by sid, iterate from 1 to max_sid - returns all symbols
326 ION_API_EXPORT iERR ion_symbol_table_get_local_symbol (hSYMTAB hsymtab, SID sid, ION_SYMBOL **p_sym); // get symbols by sid, iterate from 1 to max_sid - returns only locally defined symbols
327 
328 ION_API_EXPORT iERR ion_symbol_table_add_symbol (hSYMTAB hsymtab, iSTRING name, SID *p_sid);
329 
337 ION_API_EXPORT iERR ion_symbol_table_close (hSYMTAB hsymtab);
338 
342 ION_API_EXPORT iERR ion_symbol_copy_to_owner(hOWNER owner, ION_SYMBOL *dst, ION_SYMBOL *src);
343 
347 ION_API_EXPORT iERR ion_symbol_is_equal(ION_SYMBOL *lhs, ION_SYMBOL *rhs, BOOL *is_equal);
348 
349 ION_API_EXPORT const char *ion_symbol_table_type_to_str (ION_SYMBOL_TABLE_TYPE t);
350 
351 #ifdef __cplusplus
352 }
353 #endif
354 
355 #endif /* ION_SYMBOL_TABLE_H_ */
ION_API_EXPORT iERR ion_symbol_table_load(hREADER hreader, hOWNER owner, hSYMTAB *p_hsymtab)
ION_API_EXPORT iERR ion_symbol_is_equal(ION_SYMBOL *lhs, ION_SYMBOL *rhs, BOOL *is_equal)
ION_API_EXPORT iERR ion_symbol_table_open(hSYMTAB *p_hsymtab, hOWNER owner)
ION_API_EXPORT iERR ion_symbol_table_add_import(hSYMTAB hsymtab, ION_SYMBOL_TABLE_IMPORT_DESCRIPTOR *pimport, hCATALOG catalog)
ION_API_EXPORT iERR ion_symbol_table_clone(hSYMTAB hsymtab, hSYMTAB *p_hclone)
ION_API_EXPORT iERR ion_symbol_table_clone_with_owner(hSYMTAB hsymtab, hSYMTAB *p_hclone, hOWNER owner)
ION_API_EXPORT iERR ion_symbol_table_import_symbol_table(hSYMTAB hsymtab, hSYMTAB hsymtab_import)
GLOBAL char * SYSTEM_SYMBOLS[]
Definition: ion_symbol_table.h:231
ION_API_EXPORT iERR ion_symbol_table_close(hSYMTAB hsymtab)
ION_API_EXPORT iERR ion_symbol_table_unload(hSYMTAB hsymtab, hWRITER hwriter)
ION_API_EXPORT iERR ion_symbol_copy_to_owner(hOWNER owner, ION_SYMBOL *dst, ION_SYMBOL *src)
ION_API_EXPORT iERR ion_symbol_table_open_with_type(hSYMTAB *p_hsymtab, hOWNER owner, ION_SYMBOL_TABLE_TYPE type)
ION_API_EXPORT iERR ion_symbol_table_get_system_table(hSYMTAB *p_hsystem_table, int32_t version)
#define GLOBAL
Definition: ion_types.h:41
Definition: ion_collection.h:72
Definition: ion_string.h:40
Definition: ion_symbol_table.h:28
Definition: ion_symbol_table.h:34