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

/*
 * Copyright (c) 1990, 1991, 1992, 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.
 */

#ifndef ROUTINE_DEFS_H
#define ROUTINE_DEFS_H

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

#ifndef ROUTINE_EXPORTS_H
#include "routine_exports.h"
#endif

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

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

struct Routine_struct {
	Vec(Block_entry) block_entrys;	/* Parameter block entry list */
	Breakpoint	breakpoint_enter; /* Breakpoint at routine entry */
	Breakpoint	breakpoint_return; /* Breakpoint at routine return */
	Vec(Breakpoint)	breakpoints;	/* List of breakpoints */
	Str		comment;	/* Comment on definition line */
	Vec(Str)	comments;	/* Comments before the defintion */
	Str		external;	/* External function */
	Str		external_comment;
	int		is_procedure;	/* 1=>procedure; 0=>iterator */
	Module		module;		/* Parent module */
	Str		name;
	Need_table	need_table;	/* Table of need entrys */
	Type_needs	needs;		/* Needs clauses */
	Str		needs_comment;
	Type_refs	parameters;	/* Orginal parameter list */
	int		position;	/* Location of routine name */
	Type_refs	returns;
	Str		returns_comment;
	int		returns_position; /* Location of returns decl */
	Routine_entry	routine_entry;	/* Routine entry for routine */
	Routine_ref	routine_ref;	/* Routine reference for routine */
	Vec(Routine_type) routine_types; /* List of routine types */
	Vec(Signal)	signals;
	Str		signals_comment;
	Vec(Statement)	statements;	/* Statements of routine */
	Vars		takes;		/* List of arguments */
	int		temp_first;	/* First temporary */
	int		temp_last;	/* Last temporary */
	Type_proto	type_proto;	/* Routine proto type */
	Type_ref	type_ref;	/* Type of function */
	Var_table	var_table;
	Vars		vars;
	Type_refs	yields;
	Str		yields_comment;
	int		yields_position;
};

/* Representation for routine@type: */
struct Routine_entry_struct {
	int		deleted;	/* 1 => routine entry is inactive */
	Str		routine_name;	/* Routine name (key */
	Routine		routine;	/* Associated routine object or 0 */
	Str		type_name;	/* Routine type (key */
	Vec(Routine_ref) routine_refs;	/* All routine refs containing this */
	Type_proto	type_proto;	/* Prototype for routine */
	int		used;		/* >0 => routine was used */
};

/* Repesentation for routine@type{[...]}: */
struct Routine_ref_struct {
	Str		name;		/* Routine name (key */
	Type_ref	type_ref;	/* Routine type (key */
	int		constant;	/* >0 => routine used as a constant */
	Routine_entry	routine_entry;	/* More information about routine */
	Type_proto	type_proto;	/* Routine prototype */
};

/* Table of routine information: */
struct Routine_table_struct {
	Heap		heap;		/* Heap to allocate from */
	Routine_entry	entry_key;	/* Temporary type entry key */
	Table(Routine_entry, Routine_entry) entry_table; /* Routine entry tbl */
	Vec(Routine_entry) entrys;	/* Vector of all routine entries */
	Msg		msg;		/* Error message object */
	Vec(Type_refs)	parameters;	/* Parameter number list */
	Routine_ref	ref_key;	/* Temporary type ref. key */
	Table(Routine_ref, Routine_ref) ref_table; /* Routine ref. table */
	Type_tables	type_tables;	/* Type tables */
};

/* Used for parsing: */
struct Routine_type_struct {
	Str		name;		/* Name of routine type */
	int		position;	/* Position of routine type */
	Type_proto	type_proto;	/* Prototype of routine type */
};

#endif /* ROUTINE_DEFS_H */
