386BSD 0.1 development
[unix-history] / usr / src / usr.bin / awk / symtype.h
CommitLineData
a7e60862
WJ
1
2/********************************************
3symtype.h
4copyright 1991, Michael D. Brennan
5
6This is a source file for mawk, an implementation of
7the AWK programming language.
8
9Mawk is distributed without warranty under the terms of
10the GNU General Public License, version 2, 1991.
11********************************************/
12
13/*$Log: symtype.h,v $
14 * Revision 5.1 91/12/05 07:59:37 brennan
15 * 1.1 pre-release
16 *
17*/
18
19/* types related to symbols are defined here */
20
21#ifndef SYMTYPE_H
22#define SYMTYPE_H
23
24
25/* struct to hold info about builtins */
26typedef struct {
27char *name ;
28PF_CP fp ; /* ptr to function that does the builtin */
29unsigned char min_args, max_args ;
30/* info for parser to check correct number of arguments */
31} BI_REC ;
32
33/*---------------------------
34 structures and types for arrays
35 *--------------------------*/
36
37/* array hash nodes */
38
39/* string node */
40typedef struct anode {
41struct anode *link , *ilink ;
42STRING *sval ;
43int ival ;
44CELL *cp ;
45} ANODE ;
46
47
48typedef struct array {
49ANODE *link , *ilink ;
50} *ARRAY ;
51
52#define CREATE 1
53#define NO_CREATE 0
54
55/* note ARRAY is a ptr to a hash table */
56
57CELL *PROTO(array_find, (ARRAY,CELL *, int) ) ;
58INST *PROTO(array_loop, (INST *, CELL *, CELL *) ) ;
59void PROTO(array_delete, (ARRAY, CELL *) ) ;
60CELL *PROTO(array_cat, (CELL *, int) ) ;
61void PROTO(array_free, (ARRAY) ) ;
62void PROTO(load_array, (ARRAY,int)) ;
63
64#define new_ARRAY() (ARRAY)memset(zmalloc(A_HASH_PRIME *\
65 sizeof(struct array)),\
66 0 , SIZE_T(A_HASH_PRIME*sizeof(struct array)))
67
68extern ARRAY Argv ;
69
70/* struct to hold the state of an array loop */
71typedef struct {
72CELL *var ;
73ARRAY A ;
74int index ; /* A[index] */
75ANODE *ptr ;
76} ALOOP_STATE ;
77
78int PROTO( inc_aloop_state, (ALOOP_STATE*)) ;
79
80/* for parsing (i,j) in A */
81typedef struct {
82INST *start ;
83int cnt ;
84} ARG2_REC ;
85
86/*------------------------
87 user defined functions
88 ------------------------*/
89
90typedef struct fblock {
91char *name ;
92INST *code ;
93unsigned short nargs ;
94char *typev ; /* array of size nargs holding types */
95} FBLOCK ; /* function block */
96
97void PROTO(add_to_fdump_list, (FBLOCK *) ) ;
98void PROTO( fdump, (void) ) ;
99
100/*-------------------------
101 elements of the symbol table
102 -----------------------*/
103
104#define ST_NONE 0
105#define ST_VAR 1
106#define ST_KEYWORD 2
107#define ST_BUILTIN 3 /* a pointer to a builtin record */
108#define ST_ARRAY 4 /* a void * ptr to a hash table */
109#define ST_FIELD 5 /* a cell ptr to a field */
110#define ST_FUNCT 6
111#define ST_NR 7 /* NR is special */
112#define ST_ENV 8 /* and so is ENVIRON */
113#define ST_LOCAL_NONE 9
114#define ST_LOCAL_VAR 10
115#define ST_LOCAL_ARRAY 11
116
117#define is_local(stp) ((stp)->type>=ST_LOCAL_NONE)
118
119typedef struct {
120char *name ;
121char type ;
122unsigned char offset ; /* offset in stack frame for local vars */
123union {
124CELL *cp ;
125int kw ;
126PF_CP fp ;
127BI_REC *bip ;
128ARRAY array ;
129FBLOCK *fbp ;
130} stval ;
131} SYMTAB ;
132
133
134/*****************************
135 structures for type checking function calls
136 ******************************/
137
138typedef struct ca_rec {
139struct ca_rec *link ;
140short type ;
141short arg_num ; /* position in callee's stack */
142/*--------- this data only set if we'll need to patch -------*/
143/* happens if argument is an ID or type ST_NONE or ST_LOCAL_NONE */
144
145int call_offset ;
146/* where the type is stored */
147SYMTAB *sym_p ; /* if type is ST_NONE */
148char *type_p ; /* if type is ST_LOCAL_NONE */
149} CA_REC ; /* call argument record */
150
151/* type field of CA_REC matches with ST_ types */
152#define CA_EXPR ST_LOCAL_VAR
153#define CA_ARRAY ST_LOCAL_ARRAY
154
155typedef struct fcall {
156struct fcall *link ;
157FBLOCK *callee ;
158short call_scope ;
159FBLOCK *call ; /* only used if call_scope == SCOPE_FUNCT */
160INST *call_start ; /* computed later as code may be moved */
161CA_REC *arg_list ;
162short arg_cnt_checked ;
163unsigned line_no ; /* for error messages */
164} FCALL_REC ;
165
166extern FCALL_REC *resolve_list ;
167
168void PROTO(resolve_fcalls, (void) ) ;
169void PROTO(check_fcall, (FBLOCK*,int,FBLOCK*,CA_REC*,unsigned) ) ;
170
171/* hash.c */
172unsigned PROTO( hash, (char *) ) ;
173SYMTAB *PROTO( insert, (char *) ) ;
174SYMTAB *PROTO( find, (char *) ) ;
175char *PROTO( reverse_find, (int, PTR)) ;
176SYMTAB *PROTO( save_id, (char *) ) ;
177void PROTO( restore_ids, (void) ) ;
178
179/* error.c */
180void PROTO(type_error, (SYMTAB *) ) ;
181
182#endif /* SYMTYPE_H */