Ejemplo n.º 1
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);
	
}
Ejemplo n.º 2
0
int resolve(char *filename, int should_print) {
	yyin = fopen(filename,"r");
	if (!yyin) {
		fprintf(stderr,"unable to open %s\n",filename);
		exit(1);
	}
	if (yyparse() != 0) {
		return 1;
	}
	fclose(yyin);

	//do name resolution
	scope_enter();
	decl_resolve(parser_result, should_print);
	scope_exit();
	
	if(resolve_error_count > 0)
		return 1;
	return 0;
}
Ejemplo n.º 3
0
void stmt_resolve(struct stmt *s, int *which) {
  if(!s) return;
  switch(s -> kind) {
    case STMT_DECL:
      decl_resolve(s -> decl, SYMBOL_LOCAL, which);
      (*which)++;
      break;
    case STMT_EXPR:
      expr_resolve(s -> expr);
      break;
    case STMT_IF_ELSE:
      expr_resolve(s -> expr);
      stmt_resolve(s -> body, which);
      stmt_resolve(s -> else_body, which);
      break;
    case STMT_FOR:
      expr_resolve(s -> init_expr);
      expr_resolve(s -> expr);
      expr_resolve(s -> next_expr);
      stmt_resolve(s -> body, which);
      break;
    case STMT_WHILE:
      break;
    case STMT_PRINT:
      expr_resolve(s -> expr);
      break;
    case STMT_RET:
      expr_resolve(s -> expr);
      break;
    case STMT_BLOCK:
      scope_enter();
      // a new block does not equal a new stack frame
      // (so should not have new which value of 1)
      stmt_resolve(s -> body, which);
      scope_exit();
      break;
  }
  stmt_resolve(s -> next, which);
}
Ejemplo n.º 4
0
void stmt_resolve(struct stmt *s) {
	if (!s) { return; }
	switch (s->kind) {
		case STMT_DECL: 
			decl_resolve(s->decl);
			break;
		case STMT_IF_ELSE:
			expr_resolve(s->expr);
			stmt_resolve(s->body);
			stmt_resolve(s->else_body);
			break;
		case STMT_BLOCK:
			scope_enter();
			stmt_resolve(s->body);
			scope_exit();
			break;
		case STMT_EXPR:
			expr_resolve(s->expr);
			break;
		case STMT_FOR:
			expr_resolve(s->init_expr);
			expr_resolve(s->expr);
			expr_resolve(s->next_expr);
			stmt_resolve(s->body);
			break;
		case STMT_PRINT:
			expr_resolve(s->expr);
			break;
		case STMT_RETURN:
			expr_resolve(s->expr);
			break;
		case STMT_EMPTY:
			break;
	}
	stmt_resolve(s->next);
}
Ejemplo n.º 5
0
 explicit scope_exit(Fun &&fun)
     noexcept(noexcept(scope_exit(std::move(fun), nothrow_move_t{})))
   : scope_exit(std::move(fun), nothrow_move_t{})
 {}
Ejemplo n.º 6
0
 explicit scope_exit(Fun const &fun)
     noexcept(noexcept(scope_exit(fun, nothrow_copy_t{})))
   : scope_exit(fun, nothrow_copy_t{})
 {}