summaryrefslogtreecommitdiffstats
path: root/gcc/treelang/treelang.h
blob: f42a2e2e2e94a394e4c9feeef401899fe0675fde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* 

    TREELANG Compiler common definitions (treelang.h)

    Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.

    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, 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, 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.

    In other words, you are welcome to use, share and improve this program.
    You are forbidden to forbid anyone else to use, share and improve
    what you give them.   Help stamp out software-hoarding!  

    ---------------------------------------------------------------------------

    Written by Tim Josling 1999, 2000, 2001, based in part on other
    parts of the GCC compiler.

*/

/* Parse structure type.  */
enum category_enum 
{ /* These values less likely to be there by chance unlike 0/1,
      make checks more meaningful */
  token_category = 111,
  production_category = 222,
  parameter_category = 333
};

/* Input file name and FILE.  */
extern unsigned char* in_fname;
extern FILE* yyin;

/* Forward references to satisfy mutually recursive definitions.  */
struct token_part;
struct production_part;
struct prod_token_parm_item;
typedef struct GTY(()) prod_token_parm_item item;

/* A token from the input file.  */

struct token_part GTY(())
{
  unsigned int lineno;
  unsigned int charno;
  unsigned int length; /* The value.  */
  unsigned char* chars;
};

/* Definitions for fields in production.  */
#define NESTING_LEVEL(a) a->tp.pro.info[0]  /* Level used for variable definitions.  */
#define NUMERIC_TYPE(a)  a->tp.pro.info[1]  /* Numeric type used in type definitions and expressions.  */
#define SUB_COUNT 5
#define SYMBOL_TABLE_NAME(a) (a->tp.pro.sub[0]) /* Name token.  */
#define EXPRESSION_TYPE(a) (a->tp.pro.sub[1]) /* Type identifier.  */
#define OP1(a) (a->tp.pro.sub[2]) /* Exp operand1.  */
#define PARAMETERS(a) (a->tp.pro.sub[2]) /* Function parameters.  */
#define VARIABLE(a) (a->tp.pro.sub[2]) /* Parameter variable ptr.  */
#define VAR_INIT(a) (a->tp.pro.sub[2]) /* Variable init.  */
#define OP2(a) (a->tp.pro.sub[3]) /* Exp operand2.  */
#define FIRST_PARMS(a) (a->tp.pro.sub[3]) /* Function parameters linked via struct tree_parameter_list.  */
#define OP3(a) (a->tp.pro.sub[4]) /* Exp operand3.  */
#define STORAGE_CLASS_TOKEN(a) (a->tp.pro.sub[4]) /* Storage class token.  */
#define STORAGE_CLASS(a) a->tp.pro.flag1 /* Values in treetree.h.  */

struct production_part GTY(())
{
  struct prod_token_parm_item *main_token; /* Main token for error msgs; variable name token.  */

  unsigned int info[2]; /* Extra information.  */

  struct prod_token_parm_item *sub[SUB_COUNT]; /* Sub productions or tokens.  */
  tree code; /* Back end hook for this item.  */
  struct prod_token_parm_item *next; /* Next in chains of various types.  */

  unsigned int flag1:2;
  unsigned int flag2:1;
  unsigned int flag3:1;
  unsigned int flag4:1;
  unsigned int flag5:1;
  unsigned int flag6:1;
  unsigned int flag7:1;

};

/* Storage modes.  */
#define STATIC_STORAGE 0
#define AUTOMATIC_STORAGE 1
#define EXTERNAL_REFERENCE_STORAGE 2
#define EXTERNAL_DEFINITION_STORAGE 3

/* Numeric types.  */
#define SIGNED_CHAR 1
#define UNSIGNED_CHAR 2
#define SIGNED_INT 3 
#define UNSIGNED_INT 4
#define VOID_TYPE 5

/* Expression types.  */
#define EXP_PLUS 0 /* Addition expression.  */
#define EXP_REFERENCE 1 /* Variable reference.  */
#define EXP_ASSIGN 2 /* Assignment.  */
#define EXP_FUNCTION_INVOCATION 3  /* Call function.  */
#define EXP_MINUS 4  /* Subtraction.  */
#define EXP_EQUALS 5  /* Equality test.  */

/* Parameter list passed to back end.  */
struct parameter_part GTY(())
{
  struct prod_token_parm_item *next; /* Next entry.  */
  unsigned char* variable_name; /* Name. */
  tree * GTY ((length ("1"))) where_to_put_var_tree; /* Where to save decl.  */
};

/* A production or a token.  */
struct prod_token_parm_item GTY(())
{
  enum category_enum category; /* Token or production. */
  unsigned int type; /* Token or production type.  */
  union t_or_p
  {
    struct token_part GTY((tag ("token_category"))) tok;
    struct production_part GTY((tag ("production_category"))) pro;
    struct parameter_part GTY((tag ("parameter_category"))) par;
  } GTY((desc ("((item *)&%1)->category"))) tp;
};


/* For parser. Alternatively you can define it using %union (bison) or
   union. */
#define YYSTYPE void *

void *my_malloc (size_t size);
int insert_tree_name (struct prod_token_parm_item *prod);
struct prod_token_parm_item *lookup_tree_name (struct prod_token_parm_item *prod);
struct prod_token_parm_item *make_production (int type, struct prod_token_parm_item *main_tok);
void mark_production_used (struct prod_token_parm_item *pp);
void mark_token_used (struct prod_token_parm_item *tt);
void treelang_debug (void);

OpenPOWER on IntegriCloud