/** * get the structure for a given symbol * * @param[in] symbols a symbol def tree containing symbol definitions * @param[in] s the symbol * @returns a Structure * * <b>Examples (from test suite):</b> * @snippet spec/def_spec.h testGetSymbolStructure */ Structure _d_get_symbol_structure(T *symbols,Symbol s) { if (is_sys_symbol(s) || is_sys_test_symbol(s)) symbols = G_sys_defs.symbols; T *def = _t_child(symbols,s.id); T *t = _t_child(def,2); // second child of the def is the structure return *(Structure *)_t_surface(t); }
/** * get symbol's label * * @param[in] symbols a symbol def tree containing symbol definitions * @param[in] s the Symbol to return the name for * @returns char * pointing to label * * <b>Examples (from test suite):</b> * @snippet spec/def_spec.h testSymbolGetName */ char *_d_get_symbol_name(T *symbols,Symbol s) { if (is_sys_symbol(s)) { if (s.id == 0) return "NULL_SYMBOL"; symbols = G_sys_defs.symbols; } if (is_sys_test_symbol(s)) symbols = G_sys_defs.symbols; if (symbols) { int c = _t_children(symbols); if (s.id > c || s.id < 1) { raise_error2("Bad symbol:%d--%d symbols in decl list",s.id,c); } T *def = _t_child(symbols,s.id); T *l = _t_child(def,1); return (char *)_t_surface(_t_child(def,1)); } sprintf(__d_extra_buf,"<unknown symbol:%d.%d.%d>",s.context,s.flags,s.id); return __d_extra_buf; }
// internal check to see if a symbol is valid void __d_validate_symbol(SemTable *sem,Symbol s,char *n) { if (!is_symbol(s)) raise_error("Bad symbol in %s def: semantic type not SEM_TYPE_SYMBOL",n); if (is_sys_symbol(s) && (s.id == 0)) return; // NULL_SYMBOL ok T *symbols = _sem_get_defs(sem,s); if (!_t_child(symbols,s.id)) raise_error("Bad symbol in %s def: definition not found in context",n); }