Exemplo n.º 1
0
void decl_resolve(struct decl* d,int x)
{
	if(!d)return;
	if(scope_lookup_local(d->name)!=NULL && d->type->kind!=TYPE_FUNCTION)
	{
		if(x == 1)printf("Resolve error: %s already declared\n",d->name);
		get_incrementError(1);
	}
	else{
		if(scope_level() == 1){
			struct symbol *sym = symbol_create(SYMBOL_GLOBAL,d->type,d->name,0,0);
			d->symbol = sym;
			scope_bind(d->name,sym);
		}
		else {
			params_local_varibles++;
			local_variables_cont++;	
			struct symbol *sym = symbol_create(SYMBOL_LOCAL,d->type,d->name,0,0);
			d->symbol = sym;
			scope_bind(d->name,sym);
		}
		expr_resolve(d->value,x);
		if(d->type->kind == TYPE_FUNCTION){
		  	param_list_resolve(d->type->params,0);
			if(!parametro)parametro = hash_table_create(0,0);
			hash_table_insert(parametro,d->name,d->type);
		}
		if(d->code){
			scope_enter();
			stmt_resolve(d->code,x);
			d->symbol->total_locals = local_variables_cont;
			local_variables_cont = 0;
			params_local_varibles = 0;
			scope_leave();	
		}
		if(d->next){
			decl_resolve(d->next,x);
		}
	}	
}
Exemplo n.º 2
0
void param_list_resolve(struct param_list *p){
    if (p == NULL) {
        return;
    }
    struct symbol *sym = symbol_create(SYMBOL_PARAM, p->type, p->name);
    if (scope_lookup_local(p->name) != NULL) {
        fprintf(stderr,"No redeclarations allowed: %s\n",p->name);
        return;
    }

    scope_bind(p->name,sym);
    param_list_resolve(p->next);
}
Exemplo n.º 3
0
struct param_list * param_list_resolve( struct param_list *a ) {
	//struct param_list * params = a;
	while (a) {	
		if (scope_lookup_local(a->name)) {
			printf("resolve error: %s is already declared\n", a->name);
			exit(1);
			//return;
		}
		struct symbol *sym = symbol_create(SYMBOL_PARAM, a->type, a->name);
		scope_bind(a->name, sym);
	 	 a = a->next;
	}
	return a;
}
Exemplo n.º 4
0
void decl_resolve( struct decl *d, symbol_t sym_type )
{
	if (!d) return;
		
	if (scope_lookup_local(d->name)) {
		printf("resolve error: %s is already declared\n", d->name);
		exit(1);
	}
	struct symbol *sym = symbol_create(sym_type, d->type, d->name);
	scope_bind(d->name, sym);
	// resolve type num_subtype for arrays
	struct type *temp_t = d->type;
	while (temp_t) {
		expr_resolve(temp_t->num_subtype);
		temp_t = temp_t->subtype;
	}
	
	if (d->code) {
		scope_enter();
		if (d->type->params) {
			sym->params = d->type->params;
			param_list_resolve(d->type->params);
		}
		
		stmt_resolve(d->code);
		scope_exit();
	} else if (d->value) {
		expr_resolve(d->value);
	}

	// function prototype 
	if ((!d->code) && d->type->params ) {
		scope_enter();
		sym->params = d->type->params;
		param_list_resolve(d->type->params);
		scope_exit();
	}
	if (d->next)
		decl_resolve(d->next, sym_type);
	
}
Exemplo n.º 5
0
// have to store params in a place where they can be resolved in block.
void param_list_resolve(struct param_list *p){
	if(!p) return;
	
	if(scope_lookup_single(p->name)){
		printf("resolve error: %s already defined in this scope\n", p->name);
		error_count++;
	}else{
		int *which = hash_table_lookup(h,"0params");  // which grabs the number of locals from the hash table
		if(*which >6){
			printf("resolve error: too many parameters");
			error_count++;
			printf("Error count: %d\n", error_count);
			exit(1);
		}
		struct symbol *sym = symbol_create(SYMBOL_PARAM, p->type, p->name);
		sym->which = *which;
		*which += 1;
		scope_bind(p->name, sym);
		p->symbol = sym;
		//printf("%s resolves to param %d\n", p->name, sym->which);
	}
	param_list_resolve(p->next);
}