From 0d202a710a006fd10cc48adf1b4de98634094634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net> Date: Fri, 20 Oct 1995 09:43:12 +0100 Subject: [PATCH] committing Rev: src/language.y:1.5 Rev: src/las.c:1.4 Rev: src/lex.c:1.4 Rev: src/lex.h:1.3 Rev: src/lpc_types.c:1.5 Rev: src/program.c:1.5 Rev: src/stralloc.c:1.4 Rev: src/svalue.h:1.3 --- src/language.y | 53 ++++++++-- src/las.c | 11 +-- src/lex.c | 12 +++ src/lex.h | 5 + src/lpc_types.c | 32 +++--- src/program.c | 258 ++++++++++++++++++++++++------------------------ src/stralloc.c | 3 + src/svalue.h | 3 +- 8 files changed, 214 insertions(+), 163 deletions(-) diff --git a/src/language.y b/src/language.y index ad711c7416..65bd610f4f 100644 --- a/src/language.y +++ b/src/language.y @@ -396,7 +396,6 @@ arguments2: new_arg_name { $$ = 1; } | arguments2 ',' new_arg_name { $$ = $1 + 1; } ; - modifier: F_NO_MASK { $$ = ID_NOMASK; } | F_STATIC { $$ = ID_STATIC; } | F_PRIVATE { $$ = ID_PRIVATE; } @@ -441,15 +440,53 @@ type3: F_INT_ID { push_type(T_INT); } | F_MAPPING_ID opt_mapping_type { push_type(T_MAPPING); } | F_ARRAY_ID opt_array_type { push_type(T_ARRAY); } | F_LIST_ID opt_array_type { push_type(T_LIST); } - | F_FUNCTION_ID - { - push_type(T_TRUE); - push_type(T_MIXED); - push_type(T_MANY); - push_type(T_FUNCTION); - } + | F_FUNCTION_ID opt_function_type { push_type(T_FUNCTION); } ; +opt_function_type: '(' + { + type_stack_mark(); + type_stack_mark(); + } + function_type_list + optional_dot_dot_dot + ':' + { + if ($4) + { + push_type(T_MANY); + type_stack_reverse(); + }else{ + type_stack_reverse(); + push_type(T_MANY); + push_type(T_VOID); + } + type_stack_mark(); + } + type ')' + { + type_stack_reverse(); + type_stack_reverse(); + } + | { + push_type(T_MIXED); + push_type(T_MIXED); + push_type(T_MANY); + }; + +function_type_list: /* Empty */ optional_comma + | function_type_list2 optional_comma + ; + +function_type_list2: type + | function_type_list2 ',' + { + type_stack_reverse(); + type_stack_mark(); + } + type + ; + opt_array_type: '(' type ')' | { push_type(T_MIXED); } ; diff --git a/src/las.c b/src/las.c index a00bfef91d..1320574b69 100644 --- a/src/las.c +++ b/src/las.c @@ -632,14 +632,14 @@ static void low_print_tree(node *foo,int needlval) default: if(!car_is_node(foo) && !cdr_is_node(foo)) { - printf("%s",get_f_name(foo->token)); + printf("%s",get_token_name(foo->token)); return; } if(foo->token<256) { printf("%c(",foo->token); }else{ - printf("%s(",get_f_name(foo->token)); + printf("%s(",get_token_name(foo->token)); } if(car_is_node(foo)) low_print_tree(CAR(foo),0); if(car_is_node(foo) && cdr_is_node(foo)) @@ -885,7 +885,7 @@ static void low_build_function_type(node *n) case F_PUSH_ARRAY: /* We let this ruin type-checking for now.. */ reset_type_stack(); - push_type(T_TRUE); + push_type(T_MIXED); push_type(T_MIXED); /* is varargs */ push_type(T_MANY); return; @@ -937,7 +937,7 @@ void fix_type_field(node *n) case F_APPLY: { struct lpc_string *s; - push_type(T_TRUE); /* match any return type, even void */ + push_type(T_MIXED); /* match any return type, even void */ push_type(T_VOID); /* not varargs */ push_type(T_MANY); low_build_function_type(CDR(n)); @@ -1289,7 +1289,7 @@ static void optimize(node *n) mknode(F_ARG_LIST, mkcastnode(void_type_string, CADR(n)), mkcastnode(void_type_string, CDDR(n)))); - CADR(n)=CADR(n)=CAAR(n)=0; + CDDR(n)=CADR(n)=CAAR(n)=0; goto use_tmp1; } @@ -1426,7 +1426,6 @@ static void optimize(node *n) int eval_low(node *n) { - INT32 num_strings, jump, num_constants; struct svalue *save_sp = sp; int ret; diff --git a/src/lex.c b/src/lex.c index 8368029a90..4ce79d8654 100644 --- a/src/lex.c +++ b/src/lex.c @@ -311,6 +311,18 @@ char *get_f_name(int n) } } +char *get_token_name(int n) +{ + static char buf[30]; + if (n<F_MAX_INSTR && instrs[n-F_OFFSET].name) + { + return instrs[n-F_OFFSET].name; + }else{ + sprintf(buf, "<OTHER %d>", n); + return buf; + } +} + /* foo must be a shared string */ static int lookup_resword(struct lpc_string *s) { diff --git a/src/lex.h b/src/lex.h index 10c1054cec..ee6990038b 100644 --- a/src/lex.h +++ b/src/lex.h @@ -42,9 +42,14 @@ void init_lex(); void free_reswords(); char *low_get_f_name(int n,struct program *p); char *get_f_name(int n); +char *get_token_name(int n); struct inputstate; struct define; void free_one_define(struct hash_entry *h); +void insert_current_line(); +void insert_current_file_as_string(); +void insert_current_time_as_string(); +void insert_current_date_as_string(); void start_new_file(int fd,struct lpc_string *filename); void start_new_string(char *s,INT32 len,struct lpc_string *name); void end_new_file(); diff --git a/src/lpc_types.c b/src/lpc_types.c index cad91651f8..3a2aa02d6f 100644 --- a/src/lpc_types.c +++ b/src/lpc_types.c @@ -32,7 +32,6 @@ * they are coded like this: * T_FUNCTION <arg type> <arg type> ... <arg type> T_MANY <arg type> <return type> * note that the type after T_MANY can be T_VOID - * T_TRUE matches anything * T_MIXED matches anything except T_VOID * T_UNKNOWN only matches T_MIXED and T_UNKNOWN */ @@ -94,7 +93,6 @@ static int type_length(char *t) case T_PROGRAM: case T_MIXED: case T_VOID: - case T_TRUE: case T_UNKNOWN: break; } @@ -173,7 +171,7 @@ static void internal_parse_type(char **s) ++*s; type_stack_reverse(); }else{ - push_type(T_TRUE); + push_type(T_MIXED); push_type(T_MIXED); push_type(T_MANY); } @@ -280,7 +278,6 @@ void stupid_describe_type(char *a,INT32 len) case T_LIST: printf("list"); break; case T_UNKNOWN: printf("unknown"); break; - case T_TRUE: printf("true"); break; case T_MANY: printf("many"); break; case T_OR: printf("or"); break; case T_VOID: printf("void"); break; @@ -291,6 +288,11 @@ void stupid_describe_type(char *a,INT32 len) } printf("\n"); } + +void simple_describe_type(struct lpc_string *s) +{ + stupid_describe_type(s->str,s->len); +} #endif char *low_describe_type(char *t) @@ -305,10 +307,6 @@ char *low_describe_type(char *t) my_strcat("mixed"); break; - case T_TRUE: - my_strcat("true"); - break; - case T_UNKNOWN: my_strcat("unknown"); break; @@ -395,7 +393,6 @@ TYPE_T compile_type_to_runtime_type(struct lpc_string *s) { case T_OR: case T_MANY: - case T_TRUE: case T_UNKNOWN: return T_MIXED; @@ -431,12 +428,9 @@ static char *low_match_types(char *a,char *b) return low_match_types(a,b); } - if(EXTRACT_UCHAR(a)==T_TRUE) return a; - if(EXTRACT_UCHAR(b)==T_TRUE) return a; - - /* 'mixed' matches anything except 'void' */ - if(EXTRACT_UCHAR(a) == T_MIXED && EXTRACT_UCHAR(b) != T_VOID) return a; - if(EXTRACT_UCHAR(b) == T_MIXED && EXTRACT_UCHAR(a) != T_VOID) return a; + /* 'mixed' matches anything */ + if(EXTRACT_UCHAR(a) == T_MIXED) return a; + if(EXTRACT_UCHAR(b) == T_MIXED) return a; if(EXTRACT_UCHAR(a) != EXTRACT_UCHAR(b)) return 0; ret=a; @@ -458,7 +452,7 @@ static char *low_match_types(char *a,char *b) if(EXTRACT_UCHAR(b)==T_MANY) { - b_tmp=a+1; + b_tmp=b+1; }else{ b_tmp=b; b+=type_length(b); @@ -469,10 +463,10 @@ static char *low_match_types(char *a,char *b) /* check the 'many' type */ a++; b++; - if(EXTRACT_UCHAR(b)==T_VOID) + if(EXTRACT_UCHAR(b)==T_VOID || EXTRACT_UCHAR(a)==T_VOID) { - b++; a+=type_length(a); + b+=type_length(b); }else{ if(!low_match_types(a,b)) return 0; } @@ -496,10 +490,8 @@ static char *low_match_types(char *a,char *b) case T_PROGRAM: case T_VOID: case T_MIXED: - case T_TRUE: break; - default: fatal("error in type string.\n"); } diff --git a/src/program.c b/src/program.c index 3cb3d256be..9ed490be20 100644 --- a/src/program.c +++ b/src/program.c @@ -178,7 +178,132 @@ void toss_current_program() toss_buffer(& inherit_names); } +#ifdef DEBUG +void check_program(struct program *p, int pass) +{ + INT32 size,e; + unsigned INT32 checksum; + + if(pass) + { + if(checked((void *)p,0) != p->refs) + fatal("Program has wrong number of references.\n"); + + return; + } + + if(p->refs <=0) + fatal("Program has zero refs.\n"); + + if(p->next && p->next->prev != p) + fatal("Program ->next->prev != program.\n"); + + if(p->prev) + { + if(p->prev->next != p) + fatal("Program ->prev->next != program.\n"); + }else{ + if(first_program != p) + fatal("Program ->prev == 0 but first_program != program.\n"); + } + + if(p->id > current_program_id || p->id < 0) + fatal("Program id is wrong.\n"); + + if(p->storage_needed < 0) + fatal("Program->storage_needed < 0.\n"); + + size=MY_ALIGN(sizeof(struct program)); + size+=MY_ALIGN(p->num_linenumbers); + size+=MY_ALIGN(p->program_size); + size+=MY_ALIGN(p->num_constants * sizeof(struct svalue)); + size+=MY_ALIGN(p->num_strings * sizeof(struct lpc_string *)); + size+=MY_ALIGN(p->num_identifiers * sizeof(struct identifier)); + size+=MY_ALIGN(p->num_identifier_references * sizeof(struct reference)); + size+=MY_ALIGN(p->num_inherits * sizeof(struct inherit)); + + size+=MY_ALIGN(p->num_identifier_indexes * sizeof(INT16)); + + if(size > p->total_size) + fatal("Program size is in error.\n"); + size-=MY_ALIGN(p->num_identifier_indexes * sizeof(INT16)); + size+=MY_ALIGN(p->num_identifier_references * sizeof(INT16)); + + if(size < p->total_size) + fatal("Program size is in error.\n"); + + +#define CHECKRANGE(X,Y) if((char *)(p->X) < (char *)p || (char *)(p->X)> ((char *)p)+size) fatal("Program->%s is wrong.\n",Y) + + CHECKRANGE(program,"program"); + CHECKRANGE(strings,"strings"); + CHECKRANGE(inherits,"inherits"); + CHECKRANGE(identifier_references,"identifier_references"); + CHECKRANGE(identifiers,"identifier"); + CHECKRANGE(identifier_index,"identifier_index"); + CHECKRANGE(constants,"constants"); + CHECKRANGE(linenumbers,"linenumbers"); + + checksum=hashmem(p->program, p->program_size, p->program_size) + + hashmem((unsigned char*)p->linenumbers,p->num_linenumbers,p->num_linenumbers); + + if(!checksum) checksum=1; + + if(!p->checksum) + { + p->checksum=checksum; + }else{ + if(p->checksum != checksum) + fatal("Someone changed a program!!!\n"); + } + + for(e=0;e<p->num_constants;e++) + { + check_svalue(p->constants + e); + } + + for(e=0;e<p->num_strings;e++) + check_string(p->strings[e]); + + for(e=0;e<p->num_identifiers;e++) + { + check_string(p->identifiers[e].name); + check_string(p->identifiers[e].type); + + if(p->identifiers[e].flags & ~7) + fatal("Unknown flags in identifier flag field.\n"); + + if(p->identifiers[e].run_time_type!=T_MIXED) + check_type(p->identifiers[e].run_time_type); + } + + for(e=0;e<p->num_identifier_references;e++) + { + if(p->identifier_references[e].inherit_offset > p->num_inherits) + fatal("Inherit offset is wrong!\n"); + + if(p->identifier_references[e].identifier_offset > + p->inherits[p->identifier_references[e].inherit_offset].prog->num_identifiers) + fatal("Identifier offset is wrong!\n"); + } + + for(e=0;e<p->num_identifier_indexes;e++) + { + if(p->identifier_index[e] > p->num_identifier_references) + fatal("Program->identifier_indexes[%ld] is wrong\n",(long)e); + } + + for(e=0;e<p->num_inherits;e++) + { + if(p->inherits[e].storage_offset < 0) + fatal("Inherit->storage_offset is wrong.\n"); + + checked((void *)p->inherits[e].prog,1); + } + checked((void *)p,-1); /* One too many were added above */ +} +#endif /* internal function to make the index-table */ static int funcmp(const void *a,const void *b) @@ -304,6 +429,10 @@ struct program *end_program() if(prog->next=first_program) first_program->prev=prog; first_program=prog; + +#ifdef DEBUG + check_program(prog,0); +#endif } if(previous_compilation) @@ -390,7 +519,7 @@ int low_reference_inherited_identifier(int e,struct lpc_string *name) return -1; funp=p->identifier_references[i]; - funp.inherit_offset=e; + funp.inherit_offset+=e; funp.flags|=ID_HIDDEN; for(d=0;d<fake_program.num_identifier_references;d++) @@ -664,7 +793,7 @@ INT32 define_function(struct lpc_string *name, )) { /* match types against earlier prototype or vice versa */ - if(!match_types(funp->type, type)) + if(!match_types(type, funp->type)) { my_yyerror("Prototype doesn't match for function %s.",name->str); } @@ -1093,131 +1222,6 @@ void add_function(char *name,void (*cfun)(INT32),char *type,INT16 flags) } #ifdef DEBUG -void check_program(struct program *p, int pass) -{ - INT32 size,e; - unsigned INT32 checksum; - - if(pass) - { - if(checked((void *)p,0) != p->refs) - fatal("Program has wrong number of references.\n"); - - return; - } - - if(p->refs <=0) - fatal("Program has zero refs.\n"); - - if(p->next && p->next->prev != p) - fatal("Program ->next->prev != program.\n"); - - if(p->prev) - { - if(p->prev->next != p) - fatal("Program ->prev->next != program.\n"); - }else{ - if(first_program != p) - fatal("Program ->prev == 0 but first_program != program.\n"); - } - - if(p->id > current_program_id || p->id < 0) - fatal("Program id is wrong.\n"); - - if(p->storage_needed < 0) - fatal("Program->storage_needed < 0.\n"); - - size=MY_ALIGN(sizeof(struct program)); - size+=MY_ALIGN(p->num_linenumbers); - size+=MY_ALIGN(p->program_size); - size+=MY_ALIGN(p->num_constants * sizeof(struct svalue)); - size+=MY_ALIGN(p->num_strings * sizeof(struct lpc_string *)); - size+=MY_ALIGN(p->num_identifiers * sizeof(struct identifier)); - size+=MY_ALIGN(p->num_identifier_references * sizeof(struct reference)); - size+=MY_ALIGN(p->num_inherits * sizeof(struct inherit)); - - size+=MY_ALIGN(p->num_identifier_indexes * sizeof(INT16)); - - if(size > p->total_size) - fatal("Program size is in error.\n"); - - size-=MY_ALIGN(p->num_identifier_indexes * sizeof(INT16)); - size+=MY_ALIGN(p->num_identifier_references * sizeof(INT16)); - - if(size < p->total_size) - fatal("Program size is in error.\n"); - - -#define CHECKRANGE(X,Y) if((char *)(p->X) < (char *)p || (char *)(p->X)> ((char *)p)+size) fatal("Program->%s is wrong.\n",Y) - - CHECKRANGE(program,"program"); - CHECKRANGE(strings,"strings"); - CHECKRANGE(inherits,"inherits"); - CHECKRANGE(identifier_references,"identifier_references"); - CHECKRANGE(identifiers,"identifier"); - CHECKRANGE(identifier_index,"identifier_index"); - CHECKRANGE(constants,"constants"); - CHECKRANGE(linenumbers,"linenumbers"); - - checksum=hashmem(p->program, p->program_size, p->program_size) + - hashmem((unsigned char*)p->linenumbers,p->num_linenumbers,p->num_linenumbers); - - if(!checksum) checksum=1; - - if(!p->checksum) - { - p->checksum=checksum; - }else{ - if(p->checksum != checksum) - fatal("Someone changed a program!!!\n"); - } - - for(e=0;e<p->num_constants;e++) - { - check_svalue(p->constants + e); - } - - for(e=0;e<p->num_strings;e++) - check_string(p->strings[e]); - - for(e=0;e<p->num_identifiers;e++) - { - check_string(p->identifiers[e].name); - check_string(p->identifiers[e].type); - - if(p->identifiers[e].flags & ~7) - fatal("Unknown flags in identifier flag field.\n"); - - if(p->identifiers[e].run_time_type!=T_MIXED) - check_type(p->identifiers[e].run_time_type); - } - - for(e=0;e<p->num_identifier_references;e++) - { - if(p->identifier_references[e].inherit_offset > p->num_inherits) - fatal("Inherit offset is wrong!\n"); - - if(p->identifier_references[e].identifier_offset > - p->inherits[p->identifier_references[e].inherit_offset].prog->num_identifiers) - fatal("Identifier offset is wrong!\n"); - } - - for(e=0;e<p->num_identifier_indexes;e++) - { - if(p->identifier_index[e] > p->num_identifier_references) - fatal("Program->identifier_indexes[%ld] is wrong\n",(long)e); - } - - for(e=0;e<p->num_inherits;e++) - { - if(p->inherits[e].storage_offset < 0) - fatal("Inherit->storage_offset is wrong.\n"); - - checked((void *)p->inherits[e].prog,1); - } - checked((void *)p,-1); /* One too many were added above */ -} - void check_all_programs(int pass) { struct program *p; diff --git a/src/stralloc.c b/src/stralloc.c index a6e1ccd6c3..c915693f90 100644 --- a/src/stralloc.c +++ b/src/stralloc.c @@ -28,6 +28,9 @@ void check_string(struct lpc_string *s) if(debug_findstring(s) !=s) fatal("Shared string not shared.\n"); + if(s->str[s->len]) + fatal("Shared string is not zero terminated properly.\n"); + checked((void *)s,1); } diff --git a/src/svalue.h b/src/svalue.h index 1accfb2a80..1834145f0b 100644 --- a/src/svalue.h +++ b/src/svalue.h @@ -55,8 +55,7 @@ struct svalue #define T_FLOAT 7 #define T_INT 8 -#define T_UNKNOWN 248 -#define T_TRUE 249 +#define T_UNKNOWN 249 #define T_MANY 250 #define T_OR 251 #define T_SHORT_LVALUE 252 -- GitLab