#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "semantics.h"
#include "ast.h"
#define NEW(type) ((type *)malloc(sizeof(type)))
#define CHECK_TYPE(p, _type) assert(p->type == _type)
#define ERROR(x) do { error_print x; } while (0)
#define WARNING(x) do { warning_print x; } while (0)
#define NOT_IGNORE_VOID(et, ast) \
if (et->type == CVOID) \
do { \
ERROR((ast, "void value not ignored as it ought to be")); \
} while (0)
#define INCOMP_TYPE(ast) \
do { \
ERROR((ast, "incompatible types when assigning")); \
} while (0)
/* pointer to function conversion (std 6.3.2/4) */
#define FUNC_POINTER_CONV(t) \
do { \
if ((t)->type == CFUNC) \
{ \
CType_t f = ctype_create("", CPTR, p); \
f->rec.ref = t; \
t = f; \
} \
} while (0)
#define CHECK_CVOID(name, ast) \
if (type_spec->type == CVOID) \
do { \
ERROR((ast, "variable or field '%s' declared void", name)); \
} while (0)
#define IS_INT(tt) ((tt) == CINT || (tt) == CCHAR)
#define IS_PTR(tt) ((tt) == CPTR || (tt) == CARR)
#define IS_SCALAR(tt) (!((tt) == CUNION || (tt) == CSTRUCT))
#define IS_ARITH(tt) IS_INT(tt)
extern void print_error(char *, char *, int, int, int);
extern char *load_line(int);
static char err_buff[MAX_ERROR_BUFF];
static CType_t basic_type_int;
static CType_t basic_type_char;
static CType_t basic_type_void;
static CVar_t builtin_printf;
static CVar_t builtin_scanf;
static CVar_t builtin_malloc;
static void error_print(CNode *ast, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vsprintf(err_buff, fmt, args);
print_error(err_buff, NULL, ast->loc.row, ast->loc.col, 0);
va_end(args);
}
static void warning_print(CNode *ast, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vsprintf(err_buff, fmt, args);