/* 
 *  
 *
 *  Samba IDL Compiler
 *  Copyright (C) Sander Striker                    2000.
 *  
 *  This program 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 of the License, or
 *  (at your option) any later version.
 *  
 *  This program 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef DECLARATOR_H
#define DECLARATOR_H

#include "literal.h"
#include "attribute.h"

/* we have a looping reference between type_specifier and declarator
 * so we declare type_specifier here
 */
struct _TypeSpecifier;

typedef enum _DeclaratorType
{
  DT_IDENTIFIER,
  DT_POINTER,
  DT_ARRAY,
  DT_FUNCTION
} DeclaratorType;

struct _DeclaratorList;

typedef struct _Declarator
{
  struct _DeclaratorList *list;
  struct _Declarator     *prev;
  struct _Declarator     *next;  
  DeclaratorType type;
} Declarator;

typedef struct _DeclaratorList
{
  int size;
  Declarator *head;
  Declarator *tail;  
} DeclaratorList;

typedef struct _IdentifierDeclarator
{
  Declarator header;
  const char *identifier;
} IdentifierDeclarator;

typedef struct _PointerDeclarator
{
  Declarator header;
  Declarator *lhs;
} PointerDeclarator;

typedef struct _ArrayDeclarator
{
  Declarator header;
  Declarator *lhs;
} ArrayDeclarator;

struct _FunctionArgumentList;

typedef struct _FunctionArgument
{
  struct _FunctionArgumentList *list;
  struct _FunctionArgument     *prev;
  struct _FunctionArgument     *next;
  AttributeList                *attribute_list;
  struct _TypeSpecifier        *type_specifier;
  Declarator                   *declarator;
} FunctionArgument;

typedef struct _FunctionArgumentList
{
  int size;
  FunctionArgument *head;
  FunctionArgument *tail;  
} FunctionArgumentList;

typedef struct _FunctionDeclarator
{
  Declarator            header;
  Declarator           *lhs;
  FunctionArgumentList *argument_list;
} FunctionDeclarator;

DeclaratorList *make_declarator_list();
void free_declarator_list(DeclaratorList *list);

Declarator *make_declarator(DeclaratorType type);
void free_declarator(Declarator *declarator);

Declarator *make_identifier_declarator(const char *identifier);
Declarator *make_pointer_declarator(Declarator *lhs);
Declarator *make_array_declarator(Declarator *lhs);
Declarator *make_function_declarator(Declarator *lhs, FunctionArgumentList *argument_list);

FunctionArgumentList *make_function_argument_list(void);
void free_function_argument_list(FunctionArgumentList *list);

FunctionArgument *make_function_argument(AttributeList *attribute_list, struct _TypeSpecifier *type_specifier, Declarator *declarator);
void free_function_argument(FunctionArgument *argument);

#endif /* DECLARATOR_H */
