void unifier::operator()(const type_operator& x, const type_operator& y) { if(!x.compare_kind(y)) throw type_mismatch(x, y); for(auto xi = x.begin(), yi = y.begin(); xi != x.end(); xi++, yi++) { _stack.push_back(std::make_pair(*xi, *yi)); } }
int assert_type(ast::types::Type ltype, ast::types::Type rtype, std::string operation, int id = -1) { if(ltype != rtype) { std::cout << "Bad type of " << operation; print_id(id); std::cout << std::endl; type_mismatch(ltype, rtype); return EXIT_FAILURE; } return EXIT_SUCCESS; }
/* * value = TOK_STRING | TOK_INTEGER | TOK_BOOLEAN | TOK_KEYWORD * >> value (',' value)* '}' */ static int parse_array_or_section (section_t **section,scan_t *sc,char **keyword) { int result,saved = 0; stmt_t *nw = NULL; SCAN(); if (result == TOK_KEYWORD) { char *tmp = sc->token.keyword; if ((result = scan (sc)) < 0) { mem_free (tmp); return (ERR); } saved = result; if (result == '=') { if ((*section)->child == NULL) { if (((*section)->child = (section_t **) mem_alloc (sizeof (section_t *))) == NULL) { out_of_memory: log_printf (LOG_ERROR,"Out of memory\n"); mem_free (tmp); return (ERR); } if (((*section)->child[0] = (section_t *) mem_alloc (sizeof (section_t))) == NULL) { mem_free ((*section)->child); (*section)->child = NULL; goto out_of_memory; } } else { section_t **ptr; if ((ptr = (section_t **) mem_realloc ((*section)->child,((*section)->n + 1) * sizeof (section_t *))) == NULL) goto out_of_memory; (*section)->child = ptr; if (((*section)->child[(*section)->n] = (section_t *) mem_alloc (sizeof (section_t))) == NULL) goto out_of_memory; } (*section)->child[(*section)->n]->n = 0; (*section)->child[(*section)->n]->name = *keyword; (*section)->child[(*section)->n]->stmt = NULL; (*section)->child[(*section)->n]->child = NULL; ((*section)->n)++; return (parse_section (&(*section)->child[(*section)->n - 1],sc,&tmp)); } result = TOK_KEYWORD; sc->token.keyword = tmp; } if (result != TOK_STRING && result != TOK_INTEGER && result != TOK_BOOLEAN && result != TOK_KEYWORD) { mem_free (*keyword); missing_value: parse_error (sc,"TOK_STRING, TOK_INTEGER, TOK_BOOLEAN, or TOK_ENUM",result); goto error; } if ((nw = stmt_init (keyword,result)) == NULL) { unable_to_add: if (result == TOK_STRING) mem_free (sc->token.string); else if (result == TOK_KEYWORD) mem_free (sc->token.keyword); goto error; } if (stmt_add (nw,sc) < 0) goto unable_to_add; if (result == TOK_KEYWORD) result = saved; else if ((result = scan (sc)) < 0) goto error; while (result == ',') { if ((result = scan (sc)) < 0) goto error; if (result != TOK_STRING && result != TOK_INTEGER && result != TOK_BOOLEAN && result != TOK_KEYWORD) goto missing_value; if (result != nw->type && (result != TOK_KEYWORD || nw->type != TOK_ENUM)) { type_mismatch (sc,nw->type,result); goto error; } if (stmt_add (nw,sc) < 0) goto unable_to_add; if ((result = scan (sc)) < 0) goto error; } if (result != '}') { parse_error (sc,"'}'",result); goto error; } stmt_save (*section,&nw); return (OK); error: if (nw != NULL) stmt_destroy (&nw); return (ERR); }