/********************************************************************************
*
* File: typecheck.h
* Title: The type-checking algorithm for the relational database system SDB.
* Programmer: Leonidas Fegaras, UTA
* Date: 2/21/97
*
********************************************************************************/

typedef Expr Type;

/* the relation schema is a binding of attribute names to types */
typedef binding<Type>* Schema;


/*--------------------------------------------------------------------------------
-  the typechecking environment used for checking the correctness of an sql
-  query against the database scheme
--------------------------------------------------------------------------------*/

class typecheck;

typedef typecheck* Typecheck;


class typecheck: public gc {

  binding<Schema>* env;

public:

  /* constructors */
  typecheck() { env = new binding<Schema>; };
  typecheck( Typecheck e ) { env = e->env; };

  /* typecheck a projection e equal to project(table,attribute) */
  Type column ( Expr e, Expr grouping );

  /* typecheck a query */
  Schema query ( Expr e, Expr grouping );

  /* typecheck an expression */
  Type expression ( Expr e, Expr grouping );

  /* typecheck a predicate */
  predicate ( Expr e, Expr grouping );

};


/* a type error is a fatal error: it causes the program to abort */
type_error ( string msg, Expr e );
