]> matita.cs.unibo.it Git - pkg-cerco/acc.git/blob - cparser/C.mli
Package description and copyright added.
[pkg-cerco/acc.git] / cparser / C.mli
1 (* *********************************************************************)
2 (*                                                                     *)
3 (*              The Compcert verified compiler                         *)
4 (*                                                                     *)
5 (*          Xavier Leroy, INRIA Paris-Rocquencourt                     *)
6 (*                                                                     *)
7 (*  Copyright Institut National de Recherche en Informatique et en     *)
8 (*  Automatique.  All rights reserved.  This file is distributed       *)
9 (*  under the terms of the GNU General Public License as published by  *)
10 (*  the Free Software Foundation, either version 2 of the License, or  *)
11 (*  (at your option) any later version.  This file is also distributed *)
12 (*  under the terms of the INRIA Non-Commercial License Agreement.     *)
13 (*                                                                     *)
14 (* *********************************************************************)
15
16 (* C abstract syntax after elaboration *)
17
18 (* Locations *)
19
20 type location = string * int            (* filename, line number *)
21
22 (* Identifiers *)
23
24 type ident =
25   { name: string;                       (* name as in the source *)
26     stamp: int }                        (* unique ID *)
27
28 (* kinds of integers *)
29
30 type ikind = 
31   | IBool       (** [_Bool] *)
32   | IChar       (** [char] *)
33   | ISChar      (** [signed char] *)
34   | IUChar      (** [unsigned char] *)
35   | IInt        (** [int] *)
36   | IUInt       (** [unsigned int] *)
37   | IShort      (** [short] *)
38   | IUShort     (** [unsigned short] *)
39   | ILong       (** [long] *)
40   | IULong      (** [unsigned long] *)
41   | ILongLong   (** [long long] (or [_int64] on Microsoft Visual C) *)
42   | IULongLong  (** [unsigned long long] (or [unsigned _int64] on Microsoft 
43                     Visual C) *)
44
45 (** Kinds of floating-point numbers*)
46
47 type fkind = 
48     FFloat      (** [float] *)
49   | FDouble     (** [double] *)
50   | FLongDouble (** [long double] *)
51
52
53 (** Constants *)
54
55 type constant =
56   | CInt of int64 * ikind * string      (* as it appeared in the source *)
57   | CFloat of float * fkind * string    (* as it appeared in the source *)
58   | CStr of string
59   | CWStr of int64 list
60   | CEnum of ident * int64              (* enum tag, integer value *)
61
62 (** Attributes *)
63
64 type attribute = AConst | AVolatile | ARestrict
65
66 type attributes = attribute list
67
68 (** Storage classes *)
69
70 type storage =
71   | Storage_default
72   | Storage_extern
73   | Storage_static
74   | Storage_register
75
76 (** Unary operators *)
77
78 type unary_operator =
79   | Ominus      (* unary "-" *)
80   | Oplus       (* unary "+" *)
81   | Olognot     (* "!" *)
82   | Onot        (* "~" *)
83   | Oderef      (* unary "*" *)
84   | Oaddrof     (* "&" *)
85   | Opreincr    (* "++" prefix *)
86   | Opredecr    (* "--" prefix *)
87   | Opostincr   (* "++" postfix *)
88   | Opostdecr   (* "--" postfix *)
89   | Odot of string (* ".field" *)
90   | Oarrow of string (* "->field" *)
91
92 type binary_operator =
93   | Oadd        (* binary "+" *)
94   | Osub        (* binary "-" *)
95   | Omul        (* binary "*" *)
96   | Odiv        (* "/" *)
97   | Omod        (* "%" *)
98   | Oand        (* "&" *)
99   | Oor         (* "|" *)
100   | Oxor        (* "^" *)
101   | Oshl        (* "<<" *)
102   | Oshr        (* ">>" *)
103   | Oeq         (* "==" *)
104   | One         (* "!=" *)
105   | Olt         (* "<" *)
106   | Ogt         (* ">" *)
107   | Ole         (* "<=" *)
108   | Oge         (* ">=" *)
109   | Oindex      (* "a[i]" *)
110   | Oassign     (* "=" *)
111   | Oadd_assign (* "+=" *)
112   | Osub_assign (* "-=" *)
113   | Omul_assign (* "*=" *)
114   | Odiv_assign (* "/=" *)
115   | Omod_assign (* "%=" *)
116   | Oand_assign (* "&=" *)
117   | Oor_assign  (* "|=" *)
118   | Oxor_assign (* "^=" *)
119   | Oshl_assign (* "<<=" *)
120   | Oshr_assign (* ">>=" *)
121   | Ocomma      (* "," *)
122   | Ologand     (* "&&" *)
123   | Ologor      (* "||" *)
124
125 (** Types *)
126
127 type typ =
128   | TVoid of attributes
129   | TInt of ikind * attributes
130   | TFloat of fkind * attributes
131   | TPtr of typ * attributes
132   | TArray of typ * int64 option * attributes
133   | TFun of typ * (ident * typ) list option * bool * attributes
134   | TNamed of ident * attributes
135   | TStruct of ident * attributes
136   | TUnion of ident * attributes
137
138 (** Expressions *)
139
140 type exp = { edesc: exp_desc; etyp: typ }
141
142 and exp_desc =
143   | EConst of constant
144   | ESizeof of typ
145   | EVar of ident
146   | EUnop of unary_operator * exp
147   | EBinop of binary_operator * exp * exp * typ
148                            (* the type at which the operation is performed *)
149   | EConditional of exp * exp * exp
150   | ECast of typ * exp
151   | ECall of exp * exp list
152
153 (** Statements *)
154
155 type stmt = { sdesc: stmt_desc; sloc: location }
156
157 and stmt_desc =
158   | Sskip
159   | Sdo of exp
160   | Sseq of stmt * stmt
161   | Sif of exp * stmt * stmt
162   | Swhile of exp * stmt
163   | Sdowhile of stmt * exp
164   | Sfor of stmt * exp * stmt * stmt
165   | Sbreak
166   | Scontinue
167   | Sswitch of exp * stmt
168   | Slabeled of slabel * stmt
169   | Sgoto of string
170   | Sreturn of exp option
171   | Sblock of stmt list
172   | Sdecl of decl
173
174 and slabel = 
175   | Slabel of string
176   | Scase of exp
177   | Sdefault
178
179 (** Declarations *)
180
181 and decl =
182   storage * ident * typ * init option
183
184 (** Initializers *)
185
186 and init =
187   | Init_single of exp
188   | Init_array of init list
189   | Init_struct of ident * (field * init) list
190   | Init_union of ident * field * init
191
192 (** Struct or union field *)
193
194 and field = {
195     fld_name: string;
196     fld_typ: typ;
197     fld_bitfield: int option
198 }
199
200 type struct_or_union =
201   | Struct
202   | Union
203
204 (** Function definitions *)
205
206 type fundef = {
207     fd_storage: storage;
208     fd_inline: bool;
209     fd_name: ident;
210     fd_ret: typ; (* return type *)
211     fd_params: (ident * typ) list; (* formal parameters *)
212     fd_vararg: bool;               (* variable arguments? *)
213     fd_locals: decl list;          (* local variables *)
214     fd_body: stmt
215 }
216
217 (** Global declarations *)
218
219 type globdecl =
220   { gdesc: globdecl_desc; gloc: location }
221
222 and globdecl_desc =
223   | Gdecl of decl           (* variable declaration, function prototype *)
224   | Gfundef of fundef                   (* function definition *)
225   | Gcompositedecl of struct_or_union * ident (* struct/union declaration *)
226   | Gcompositedef of struct_or_union * ident * field list
227                                         (* struct/union definition *)
228   | Gtypedef of ident * typ             (* typedef *)
229   | Genumdef of ident * (ident * exp option) list  (* enum definition *)
230   | Gpragma of string                   (* #pragma directive *)
231
232 type program = globdecl list