/* %Z%%M% %I% %E% */

/*
 * Copyright (c) 1990, 1991, 1992, 1993, 1995 by Wayne C. Gramlich.
 * All rights reserved.
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * for any purpose is hereby granted without fee provided that the above
 * copyright notice and this permission are retained.  The author makes
 * no representations about the suitability of this software for any purpose.
 * It is provided "as is" without express or implied warranty.
 */

/* This file contains the structure declarations for call objects: */

#ifndef CALL_DEFS_H
#define CALL_DEFS_H

#ifndef CALL_EXPORTS_H
#include "call_exports.h"
#endif

#ifndef FLAGS_TYPES_H
#include "flags_types.h"
#endif

#ifndef GEN_TYPES_H
#include "gen_types.h"
#endif

#ifndef HEAP_TYPES_H
#include "heap_types.h"
#endif

#ifndef MSG_TYPES_H
#include "msg_types.h"
#endif

#ifndef NEED_TYPES_H
#include "need_types.h"
#endif

#ifndef OBJECT_TYPES_H
#include "object_types.h"
#endif

#ifndef TABLE_TYPES_H
#include "table_types.h"
#endif

#ifndef TYPE_TYPES_H
#include "type_types.h"
#endif

#ifndef VAR_TYPES_H
#include "var_types.h"
#endif

/* <var> := <call> or <temp> := <call> */
struct Call_assign_struct {
	Call		left;		/* Must be either a <temp> or <var> */
	Call		right;		/* Can be an arbitrary call tree */
};

/* <call> && <call> or <call> || <call */
struct Call_binary_struct {
	Call		left;		/* Left call */
	Call		right;		/* Right call */
};

/* (type_ref) <call> */
struct Call_cast_struct {
	Call		call;		/* Sub-call */
	Type_ref	type_ref;	/* Type reference */
};

/* <call> : <call> ? <call> */
struct Call_if_struct {
	Call		condition;	/* Condition */
	Call		true;		/* True call */
	Call		false;		/* False call */
};

/* <call>(<call>, {, <call>}* */
struct Call_invoke_struct {
	Call		call;		/* Routine expression being called */
	Vec(Call)	actuals;	/* Actual arguments */
};

/* <temp1>, ..., <tempN> := <call> */
struct Call_multi_struct {
	Call		invoke;		/* Routine invocation */
	Type_refs	type_refs;	/* Pre-replaced type references */
	Vec(Call)	vars;		/* List of <var>'s and/or <temp>'s */
};

/* parameter block name */
struct Call_routine_param_struct {
	Routine_ref	routine_ref;	/* Name of routine */
	int		parameterized;	/* 1 => Use parameter block */
};

/* type_ref@name */
struct Call_routine_struct {
	Routine_ref	routine_ref;	/* Routine reference */
};

/* <temp> */
struct Call_temp_struct {
	int		number;		/* Number of temporary variable */
};

/* <var> */
struct Call_var_struct {
	Str		name;		/* Variable being looked up */
};

union Call_value_union {
	Call_binary	binary;		/* && or || */
	Call_assign	assign;		/* Variable assign */
	Call_cast	cast;		/* Value cast */
	Str		error;		/* Error message */
	Call_if		xif;		/* <call> ? <call> : <call> */
	int		integer;	/* Number constant */
	Call_invoke	invoke;		/* Routine invocation */
	Call_multi	multi;		/* Mutliple return */
	Call		not;		/* Not call */
	Object_ref	object;		/* Object constant */
	Call_routine	routine;	/* Routine constant */
	Call_routine_param routine_param; /* Routine parameter */
	Str		string;		/* String constant */
	Call_temp	temp;		/* Temporary variable */
	Str		text;		/* Text constant */
	Call_var	var;		/* Variable reference */
};

struct Call_struct {
	int		position;	/* File position for errors */
	Type_refs	type_refs;	/* Types of call return values */
	Call_type	type;		/* Type of call */
	Call_value	value;		/* Value of call */
};

/* Conversion tables used by the expression tree to call tree converter: */
struct Convert_struct {
	Flags		flags;		/* Compiler flags */
	Heap		heap;		/* Heap to allocate from */
	Msg		msg;		/* Error message object */
	Object_table	object_table;	/* Object table */
	Routine		routine;	/* Current routine */
	Table(Str, Type_ref) synonyms;	/* Synonym table */
	Vec(Type_ref)	temps;		/* Temporary variable list */
	Routine_table	routine_table;	/* Routine table */
	Type_def_table	type_def_table; /* Table of type definitions */

	Type_ref	type_ref_heap;
	Type_ref	type_ref_in_stream;
	Type_ref	type_ref_global;
	Type_ref	type_ref_logical;
	Type_ref	type_ref_out_stream;
	Type_ref	type_ref_integer;
	Type_ref	type_ref_string;
	Type_ref	type_ref_unsigned;
	Type_refs	type_refs_empty;
	Type_refs	type_refs_logical;

	Type_tables	type_tables;	/* Type tables */
	Var_table	var_table;	/* Current variable table */
};

#endif /* CALL_DEFS_H */
