From 3f089edac96f9c0f37aa36b3ed3bc2ecc9b85ffa Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 23 Mar 2017 23:00:01 -0700 Subject: Warn when a nonexistent slot is referenced. Implementing warning for the situaton when the qref, uref, usl and umeth macro operators are asked to refer to a slot that doesn't exist in any struct type. This won't catch errors referencing a slot on the wrong type, but it will catch slots that are misspelled in such a way that the typo doesn't land on any slot. * share/txr/stdlib/struct.tl (defstruct): Register tenative slot definitions for all slots to nuke warnings. (sys:check-slot): New function. (qref, usl, umeth): Check slots with sys:check-slot. (uref): Drop :whole argument, which is unused. (defmeth): Register tentative definition for slot. * struct.c (slot_s, static_slot_s): New symbol variables. (slot_type_hash, static_slot_type_hash): New hash tables, associating symbols with lists of struct type names in which they are defined. (struct_init): Initialize and gc-protect hashes. Initialize new symbols, interning in system package. Register new intrinsic funtions sys:slot-types and sys:static-slot-types. (make_struct_type): Register slots in new hashes. (static_slot_ens_rec): Register new slow in static slot hash. (slot_types, static_slot_types): New functions, registered as intrinsics. (slot_type_reg, static_slot_type_reg): New functions. * struct.h (print_s): Declared. (slot_s, static_slot_s): Declared. (slot_types, static_slot_types, slot_type_reg, static_slot_type_reg): Declared. --- struct.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'struct.h') diff --git a/struct.h b/struct.h index 10f87f72..e558745f 100644 --- a/struct.h +++ b/struct.h @@ -25,7 +25,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -extern val struct_type_s, meth_s, make_struct_lit_s; +extern val struct_type_s, meth_s, print_s, make_struct_lit_s; +extern val slot_s, static_slot_s; val make_struct_type(val name, val super, val static_slots, val slots, val static_initfun, val initfun, val boactor, @@ -64,4 +65,8 @@ val uslot(val slot); val umethod(val slot, struct args *); val method_name(val fun); val get_slot_syms(val package, val is_current, val method_only); +val slot_types(val slot); +val static_slot_types(val slot); +val slot_type_reg(val slot, val strct); +val static_slot_type_reg(val slot, val strct); void struct_init(void); -- cgit v1.2.3