1 /* Types for the symbol table. 2 */ 3 4 /* 5 6 Copyright (C) 1991-2003 The National Gallery 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License along 19 with this program; if not, write to the Free Software Foundation, Inc., 20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 22 */ 23 24 /* 25 26 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk 27 28 */ 29 30 #define TYPE_SYMBOL (symbol_get_type()) 31 #define SYMBOL( obj ) \ 32 (G_TYPE_CHECK_INSTANCE_CAST( (obj), TYPE_SYMBOL, Symbol )) 33 #define SYMBOL_CLASS( klass ) \ 34 (G_TYPE_CHECK_CLASS_CAST( (klass), TYPE_SYMBOL, SymbolClass)) 35 #define IS_SYMBOL( obj ) \ 36 (G_TYPE_CHECK_INSTANCE_TYPE( (obj), TYPE_SYMBOL )) 37 #define IS_SYMBOL_CLASS( klass ) \ 38 (G_TYPE_CHECK_CLASS_TYPE( (klass), TYPE_SYMBOL )) 39 #define SYMBOL_GET_CLASS( obj ) \ 40 (G_TYPE_INSTANCE_GET_CLASS( (obj), TYPE_SYMBOL, SymbolClass )) 41 42 /* The types of symbol we can have. 43 */ 44 typedef enum { 45 SYM_VALUE, /* Symbol with a value attached */ 46 SYM_PARAM, /* A parameter to a user function */ 47 SYM_ZOMBIE, /* A referred to but not defined */ 48 SYM_WORKSPACE, /* A loaded workspace */ 49 SYM_WORKSPACEROOT, /* Base of all workspaces */ 50 SYM_ROOT, /* The root symbol */ 51 SYM_EXTERNAL, /* A reference to an external function */ 52 SYM_BUILTIN /* A reference to a built-in function */ 53 } SymbolType; 54 55 /* A symbol. 56 */ 57 struct _Symbol { 58 Filemodel parent_class; 59 60 /* The type of this symbol. 61 */ 62 SymbolType type; 63 64 /* Track during parse. A list of pointers to pointers to this 65 * symbol which we need to patch if we resolve to an outer scope. 66 */ 67 GSList *patch; 68 69 /* Main expression for this sym. All expressions are icontainer 70 * children of us. 71 */ 72 Expr *expr; 73 74 /* Base of graph for value of this symbol. Use sym->expr->root to get 75 * value though .. we just hold pointer for GC here. Expressions on 76 * ext_expr have their GC handled by their enclosing Subcolumn. 77 */ 78 Element base; /* Value for this expr */ 79 80 /* Recomputation links. Use these to work out what to build next. 81 */ 82 gboolean dirty; /* True if this sym needs recalc */ 83 GSList *parents; /* Compiles which refer to this sym */ 84 85 GSList *topchildren; /* For top syms, all top-level children */ 86 GSList *topparents; /* For top syms, all top-level parents */ 87 int ndirtychildren; /* Number of dirty top syms we refer to */ 88 gboolean leaf; /* True for in recomp set */ 89 90 /* This is a generated symbol, like $$result, $$fn1, whatever. 91 */ 92 gboolean generated; 93 94 /* A temporary intermediate symbol generated during parse to hold 95 * stuff until we need it. Don't generate code for these. 96 */ 97 gboolean placeholder; 98 99 /* X-tras for definitions. 100 */ 101 Tool *tool; /* Tool and toolkit defined in */ 102 103 /* X-tras for SYM_EXTERNAL ... our im_function. 104 */ 105 im_function *function; /* Function we run */ 106 int fn_nargs; /* Number of args fn needs from nip */ 107 108 /* X-tras for SYM_BUILTIN ... our function. 109 */ 110 BuiltinInfo *builtin; 111 112 /* For WORKSPACEROOT ... the wsr we represent. 113 */ 114 Workspaceroot *wsr; 115 116 /* For WORKSPACE ... the ws we represent. 117 */ 118 Workspace *ws; 119 }; 120 121 typedef struct _SymbolClass { 122 FilemodelClass parent_class; 123 124 /* 125 126 new_value sym->expr has a new value (this signal is 127 fwd'd from sym->expr) 128 129 */ 130 131 void (*new_value)( Symbol *sym ); 132 } SymbolClass; 133 134 GType symbol_get_type( void ); 135 136 /* All symbols come off this. 137 */ 138 extern Symbol *symbol_root; 139 140 Symbol *symbol_map_all( Symbol *sym, symbol_map_fn fn, void *a, void *b ); 141 142 Symbol *symbol_get_parent( Symbol *sym ); 143 Workspace *symbol_get_workspace( Symbol *sym ); 144 Tool *symbol_get_tool( Symbol *sym ); 145 Symbol *symbol_get_scope( Symbol *sym ); 146 147 void symbol_qualified_name( Symbol *sym, VipsBuf *buf ); 148 void symbol_qualified_name_relative( Symbol *context, 149 Symbol *sym, VipsBuf *buf ); 150 void *symbol_name_error( Symbol *sym, VipsBuf *buf ); 151 const char *symbol_name( Symbol *sym ); 152 void *symbol_name_print( Symbol *sym ); 153 const char *symbol_name_scope( Symbol *sym ); 154 void symbol_name_scope_print( Symbol *sym ); 155 156 void symbol_new_value( Symbol *sym ); 157 158 void *symbol_patch_add( void **pnt, Symbol *sym ); 159 160 Symbol *symbol_root_init( void ); 161 162 Symbol *symbol_new( Compile *compile, const char *name ); 163 gboolean symbol_rename( Symbol *sym, const char *new_name ); 164 void symbol_error_redefine( Symbol *sym ); 165 Symbol *symbol_new_defining( Compile *compile, const char *name ); 166 Symbol *symbol_new_reference( Compile *compile, const char *name ); 167 void symbol_made( Symbol *sym ); 168 169 void symbol_not_defined( Symbol *sym ); 170 171 void *symbol_link_break( Symbol *child, Compile *compile ); 172 173 gboolean symbol_user_init( Symbol *sym ); 174 gboolean symbol_parameter_init( Symbol *sym ); 175 gboolean symbol_parameter_builtin_init( Symbol *sym ); 176 177 gboolean symbol_busy( void ); 178 179 void *symbol_sanity( Symbol *sym ); 180 void symbol_leaf_set_sanity( void ); 181 void *symbol_strip( Symbol *sym ); 182 183 void symbol_state_change( Symbol *sym ); 184 185 const char *symbol_get_last_calc( void ); 186 gboolean symbol_recalculate_check( Symbol *sym ); 187 void symbol_recalculate_all_force( gboolean now ); 188 void symbol_recalculate_all( void ); 189