diff options
Diffstat (limited to 'awk.h')
-rw-r--r-- | awk.h | 118 |
1 files changed, 70 insertions, 48 deletions
@@ -49,9 +49,7 @@ #include <stdio.h> #include <assert.h> -#ifdef HAVE_LIMITS_H #include <limits.h> -#endif /* HAVE_LIMITS_H */ #include <ctype.h> #include <setjmp.h> @@ -71,11 +69,8 @@ #endif #endif -#if defined(HAVE_STDARG_H) #include <stdarg.h> -#else -#error "gawk no longer supports <varargs.h>. Please update your compiler and runtime" -#endif +#include <stdbool.h> #include <signal.h> #include <time.h> #include <errno.h> @@ -87,11 +82,6 @@ extern int errno; #include <stdlib.h> #endif /* not STDC_HEADERS */ -#ifdef HAVE_STDBOOL_H -#include <stdbool.h> -#else -#include "missing_d/gawkbool.h" -#endif /* We can handle multibyte strings. */ #include <wchar.h> @@ -306,6 +296,12 @@ typedef union bucket_item { } hi; } BUCKET; +enum commenttype { + EOL_COMMENT = 1, + BLOCK_COMMENT, + FOR_COMMENT // special case +}; + /* string hash table */ #define ahnext hs.next #define ahname hs.name /* a string index node */ @@ -324,6 +320,19 @@ struct exp_instruction; typedef int (*Func_print)(FILE *, const char *, ...); typedef struct exp_node **(*afunc_t)(struct exp_node *, struct exp_node *); +typedef struct { + const char *name; + afunc_t init; + afunc_t type_of; /* avoid reserved word typeof */ + afunc_t lookup; + afunc_t exists; + afunc_t clear; + afunc_t remove; + afunc_t list; + afunc_t copy; + afunc_t dump; + afunc_t store; +} array_funcs_t; /* * NOTE - this struct is a rather kludgey -- it is packed to minimize @@ -336,7 +345,7 @@ typedef struct exp_node { struct exp_node *lptr; struct exp_instruction *li; long ll; - afunc_t *lp; + const array_funcs_t *lp; } l; union { struct exp_node *rptr; @@ -350,6 +359,7 @@ typedef struct exp_node { struct exp_node *extra; void (*aptr)(void); long xl; + void *cmnt; // used by pretty printer } x; char *name; size_t reserved; @@ -378,6 +388,7 @@ typedef struct exp_node { wchar_t *wsp; size_t wslen; struct exp_node *typre; + enum commenttype comtype; } val; } sub; NODETYPE type; @@ -542,29 +553,16 @@ typedef struct exp_node { #define xarray sub.nodep.rn #define parent_array sub.nodep.x.extra -#define ainit array_funcs[0] -#define ainit_ind 0 -#define atypeof array_funcs[1] -#define atypeof_ind 1 -#define alength array_funcs[2] -#define alength_ind 2 -#define alookup array_funcs[3] -#define alookup_ind 3 -#define aexists array_funcs[4] -#define aexists_ind 4 -#define aclear array_funcs[5] -#define aclear_ind 5 -#define aremove array_funcs[6] -#define aremove_ind 6 -#define alist array_funcs[7] -#define alist_ind 7 -#define acopy array_funcs[8] -#define acopy_ind 8 -#define adump array_funcs[9] -#define adump_ind 9 -#define astore array_funcs[10] -#define astore_ind 10 -#define NUM_AFUNCS 11 /* # of entries in array_funcs */ +#define ainit array_funcs->init +#define atypeof array_funcs->type_of +#define alookup array_funcs->lookup +#define aexists array_funcs->exists +#define aclear array_funcs->clear +#define aremove array_funcs->remove +#define alist array_funcs->list +#define acopy array_funcs->copy +#define adump array_funcs->dump +#define astore array_funcs->store /* Node_array_ref: */ #define orig_array lnode @@ -575,9 +573,7 @@ typedef struct exp_node { #define alevel sub.nodep.x.xl /* Op_comment */ -#define comment_type sub.val.idx -#define EOL_COMMENT 1 -#define FULL_COMMENT 2 +#define comment_type sub.val.comtype /* --------------------------------lint warning types----------------------------*/ typedef enum lintvals { @@ -673,6 +669,7 @@ typedef enum opcodeval { Op_K_getline_redir, Op_K_getline, Op_K_nextfile, + Op_K_namespace, Op_builtin, Op_sub_builtin, /* sub, gsub and gensub */ @@ -774,6 +771,7 @@ typedef struct exp_instruction { awk_ext_func_t *exf; } x; + struct exp_instruction *comment; short source_line; short pool_size; // memory management in symbol.c OPCODE opcode; @@ -924,6 +922,9 @@ typedef struct exp_instruction { #define condpair_left d.di #define condpair_right x.xi +/* Op_Rule, Op_Func */ +#define ns_name d.name + /* Op_store_var */ #define initval x.xn @@ -1019,11 +1020,13 @@ typedef struct srcfile { char *lexeme; char *lexptr_begin; int lasttok; + INSTRUCTION *comment; /* comment on @load line */ + const char *namespace; } SRCFILE; // structure for INSTRUCTION pool, needed mainly for debugger typedef struct instruction_pool { -#define MAX_INSTRUCTION_ALLOC 3 // we don't call bcalloc with more than this +#define MAX_INSTRUCTION_ALLOC 4 // we don't call bcalloc with more than this struct instruction_mem_pool { struct instruction_block *block_list; INSTRUCTION *free_space; // free location in active block @@ -1119,9 +1122,9 @@ extern NODE *(*format_val)(const char *, int, NODE *); extern int (*cmp_numbers)(const NODE *, const NODE *); /* built-in array types */ -extern afunc_t str_array_func[]; -extern afunc_t cint_array_func[]; -extern afunc_t int_array_func[]; +extern const array_funcs_t str_array_func; +extern const array_funcs_t cint_array_func; +extern const array_funcs_t int_array_func; /* special node used to indicate success in array routines (not NULL) */ extern NODE *success_node; @@ -1206,6 +1209,10 @@ extern char envsep; extern char casetable[]; /* for case-independent regexp matching */ +extern const char awk_namespace[]; /* "awk" */ +extern const char *current_namespace; +extern bool namespace_changed; + /* ------------------------- Runtime stack -------------------------------- */ typedef union stack_item { @@ -1345,7 +1352,7 @@ DEREF(NODE *r) extern jmp_buf fatal_tag; extern int fatal_tag_valid; -#define assoc_length(a) ((*((a)->alength(a, NULL)))->table_size) +#define assoc_length(a) ((a)->table_size) #define assoc_empty(a) (assoc_length(a) == 0) #define assoc_lookup(a, s) ((a)->alookup(a, s)) @@ -1355,6 +1362,7 @@ extern int fatal_tag_valid; /* assoc_remove --- remove an index from symbol[] */ #define assoc_remove(a, s) ((a)->aremove(a, s) != NULL) + /* ------------- Function prototypes or defs (as appropriate) ------------- */ /* array.c */ typedef enum { SORTED_IN = 1, ASORT, ASORTI } sort_context_t; @@ -1377,8 +1385,6 @@ extern NODE *force_array(NODE *symbol, bool canfatal); extern const char *make_aname(const NODE *symbol); extern const char *array_vname(const NODE *symbol); extern void array_init(void); -extern int register_array_func(afunc_t *afunc); -extern NODE **null_length(NODE *symbol, NODE *subs); extern NODE **null_afunc(NODE *symbol, NODE *subs); extern void set_SUBSEP(void); extern NODE *concat_exp(int nargs, bool do_subsep); @@ -1400,7 +1406,7 @@ extern int parse_program(INSTRUCTION **pcode); extern void track_ext_func(const char *name); extern void dump_funcs(void); extern void dump_vars(const char *fname); -extern const char *getfname(NODE *(*)(int)); +extern const char *getfname(NODE *(*)(int), bool prepend_awk); extern NODE *stopme(int nargs); extern void shadow_funcs(void); extern int check_special(const char *name); @@ -1417,6 +1423,7 @@ extern bool is_alnum(int c); extern bool is_letter(int c); extern bool is_identchar(int c); extern NODE *make_regnode(int type, NODE *exp); +extern bool validate_qualified_name(char *token); /* builtin.c */ extern double double_to_int(double d); extern NODE *do_exp(int nargs); @@ -1507,9 +1514,10 @@ extern NODE *do_ext(int nargs); void load_ext(const char *lib_name); /* temporary */ extern void close_extensions(void); #ifdef DYNAMIC -extern awk_bool_t make_builtin(const awk_ext_func_t *); +extern awk_bool_t make_builtin(const char *name_space, const awk_ext_func_t *); extern NODE *get_argument(int); extern NODE *get_actual_argument(NODE *, int, bool); +extern bool is_valid_identifier(const char *name); #define get_scalar_argument(n, i) get_actual_argument((n), (i), false) #define get_array_argument(n, i) get_actual_argument((n), (i), true) #endif @@ -1705,7 +1713,7 @@ extern NODE *remove_symbol(NODE *r); extern void destroy_symbol(NODE *r); extern void release_symbols(NODE *symlist, int keep_globals); extern void append_symbol(NODE *r); -extern NODE *lookup(const char *name); +extern NODE *lookup(const char *name, bool do_qualify); extern NODE *make_params(char **pnames, int pcount); extern void install_params(NODE *func); extern void remove_params(NODE *func); @@ -2016,6 +2024,20 @@ make_number_node(unsigned int flags) return r; } +/* assoc_set -- set an element in an array. Does unref(sub)! */ + +static inline void +assoc_set(NODE *array, NODE *sub, NODE *value) +{ + + NODE **lhs = assoc_lookup(array, sub); + unref(*lhs); + *lhs = value; + if (array->astore != NULL) + (*array->astore)(array, sub); + unref(sub); +} + /* * str_terminate_f, str_terminate, str_restore: function and macros to * reduce chances of typos when terminating and restoring strings. |