1/*---------------------------------------------------------------------------*
2 *  SR_SymbolTable.h  *
3 *                                                                           *
4 *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
5 *                                                                           *
6 *  Licensed under the Apache License, Version 2.0 (the 'License');          *
7 *  you may not use this file except in compliance with the License.         *
8 *                                                                           *
9 *  You may obtain a copy of the License at                                  *
10 *      http://www.apache.org/licenses/LICENSE-2.0                           *
11 *                                                                           *
12 *  Unless required by applicable law or agreed to in writing, software      *
13 *  distributed under the License is distributed on an 'AS IS' BASIS,        *
14 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15 *  See the License for the specific language governing permissions and      *
16 *  limitations under the License.                                           *
17 *                                                                           *
18 *---------------------------------------------------------------------------*/
19
20#ifndef __SR_SYMBOLTABLE_H
21#define __SR_SYMBOLTABLE_H
22
23
24
25#include "SR_SemprocPrefix.h"
26#include "SR_SemprocDefinitions.h"
27
28#include "ESR_ReturnCode.h"
29
30#include "HashMap.h"
31
32#include "ptypes.h"
33#include "pstdio.h"
34
35#define MAX_SEMPROC_KEY   128 /* was 350 */
36#define MAX_SEMPROC_VALUE 512 /* was 300 */
37
38/**
39 * Entries in the Symbol table are symbols i.e. key-value pairs.
40 */
41typedef struct Symbol_t
42{
43  /**
44   * key string
45   */
46  LCHAR key[MAX_SEMPROC_KEY];
47  /**
48   * value string
49   */
50  LCHAR value[MAX_SEMPROC_VALUE];
51}
52Symbol;
53
54/**
55 * The Symbol Table
56 */
57typedef struct SymbolTable_t
58{
59  /**
60   * Keep track of symbols using a hashmap of pointers
61   */
62  HashMap* hashmap;
63
64  /**
65   * The symbols stored as an array
66   */
67  Symbol Symbols[MAX_SYMBOLS];
68
69  /**
70   * Pointer to the next available symbol slot for storing a symbol in the array
71   */
72  Symbol *next;
73
74  /**
75   * Any special symbols that are set prior to semantic processing and read by the semantic processor
76   */
77  Symbol SpecialSymbols[MAX_SPECIAL_SYMBOLS];
78
79  /**
80   * The number of special symbols set.
81   */
82  size_t num_special_symbols;
83
84}
85SymbolTable;
86
87/**
88 * The "undefined" symbol value
89 */
90//static LCHAR undefined_symbol[] = UNDEFINED_SYMBOL;
91
92/**
93 * Create and Initialize
94 * @param self pointer to the newly created object
95 */
96SREC_SEMPROC_API ESR_ReturnCode ST_Init(SymbolTable** self);
97
98/**
99 * Free
100 * @param self pointer to the symbol table
101 */
102SREC_SEMPROC_API ESR_ReturnCode ST_Free(SymbolTable* self);
103
104/**
105 * Copies the symbols to a new hashmap (creates values dynamically)
106 * @param self pointer to the symbol table
107 * @param dst destination hashmap
108 */
109ESR_ReturnCode ST_Copy(SymbolTable* self, HashMap* dst);
110
111/**
112 * Store a key value pair
113 * @param self pointer to the symbol table
114 * @param key the key for the entry
115 * @param value the value for the entry (associated with key)
116 */
117SREC_SEMPROC_API ESR_ReturnCode ST_putKeyValue(SymbolTable* self, const LCHAR* key, const LCHAR* value);
118
119/**
120 * Retrieve a value associated with the key
121 * @param self pointer to the symbol table
122 * @param key the key for the entry
123 * @param value pointer to buffer for the storing result
124 */
125SREC_SEMPROC_API ESR_ReturnCode ST_getKeyValue(SymbolTable* self, const LCHAR* key, LCHAR** value);
126
127/**
128 * Ask for a new sot in the symbol table
129 * @param self pointer to the symbol table
130 * @param slot pointer to the slot given (NULL if none available)
131 */
132SREC_SEMPROC_API ESR_ReturnCode ST_getSymbolSlot(SymbolTable* self, Symbol** slot);
133
134/**
135 * Reset and clear the Symbol Table for a new script
136 * @param self pointer to the symbol table
137 */
138SREC_SEMPROC_API ESR_ReturnCode ST_reset(SymbolTable* self);
139SREC_SEMPROC_API ESR_ReturnCode ST_reset_all(SymbolTable* self);
140
141/**
142 * Store a "special" key value pair. These are special symbols that are set prior to semantic
143 * processing and are ONLY read by the semantic processor during processing.
144 * @param self pointer to the symbol table
145 * @param key the key for the entry
146 * @param value the value for the entry (associated with key)
147 */
148SREC_SEMPROC_API ESR_ReturnCode ST_putSpecialKeyValue(SymbolTable* self, const const LCHAR* key, const LCHAR* value);
149
150
151#endif /* __SYMBOL_TABLE_H */
152