/* This file is part of cqual.
   Copyright (C) 2000-2001 The Regents of the University of California.

cqual is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

cqual is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with cqual; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */

#ifndef HASH_INFO_H
#define HASH_INFO_H

#include "parser.h"
#include "cqual.h"
#include "dd_list.h"
#include "linkage.h"

EXTERN_C_BEGIN

typedef struct Hash_key
{
  enum { key_field, key_id, key_loc } kind;
  union
  {
    field_declaration field;
    data_declaration id;
    aloc loc;
    void *generic;
  } u;
} hash_key;

typedef struct Hash_data
{
  enum { data_qtype } kind;
  union
  {
    qtype qt;
  } u;
} hash_data;

hash_key id_to_key(data_declaration data);
hash_key field_to_key(field_declaration field);
hash_key aloc_to_key(aloc loc);
hash_data qtype_to_data(qtype qt);
qtype data_to_qtype(hash_data hd);

/* Return true iff k1 and k2 are the same */
bool key_eq(hash_key k1, hash_key k2);

/* Return -1, 0, or 1 if k1 is less than, equal to, or greater than
   k2 (in some consistent sense) */
int keycmp(hash_key k1, hash_key k2);

/* Return a hash of k */
int key_to_hash(hash_key k);

/* Print hash key */
void print_hash_key(printf_func pf, hash_key k);

/* Print hash data */
void print_hash_data(printf_func pf, hash_data d);

typedef struct Hash_key_list
{
  hash_key key;
  struct Hash_key_list *next;
} *hash_key_list;

/* Make a new hash key list */
hash_key_list new_hash_key_list(region r);

/* Add k to the front of hkl */
void insert_hash_key_list(region r, hash_key_list *hkl, hash_key k);

/* Destructively add hkl2 to the end of hkl1. */
void append_hash_key_list(hash_key_list *hkl1, hash_key_list hkl2);

/* Scan the list.  List must not be modified during scanning */
#define scan_hash_key_list(hkl, var) for (var = hkl; var; var = var->next)

/* Return the length of hkl */
int length_hash_key_list(hash_key_list hkl);

/* Return TRUE iff k is in hkl */
bool in_hash_key_list(hash_key_list hkl, hash_key hk);

EXTERN_C_END

#endif
