GnuCOBOL  2.0
A free COBOL compiler
cobc.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2001-2012, 2014-2015 Free Software Foundation, Inc.
3  Written by Keisuke Nishida, Roger While, Simon Sobisch
4 
5  This file is part of GnuCOBOL.
6 
7  The GnuCOBOL compiler is free software: you can redistribute it
8  and/or modify it under the terms of the GNU General Public License
9  as published by the Free Software Foundation, either version 3 of the
10  License, or (at your option) any later version.
11 
12  GnuCOBOL is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with GnuCOBOL. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #ifndef CB_COBC_H
23 #define CB_COBC_H
24 
25 #include <stdio.h>
26 #ifdef HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
29 #ifdef HAVE_STRINGS_H
30 #include <strings.h>
31 #endif
32 
33 #include "libcob.h"
34 
35 #ifdef ENABLE_NLS
36 #include "lib/gettext.h"
37 #define _(s) gettext(s)
38 #define N_(s) gettext_noop(s)
39 #else
40 #define _(s) s
41 #define N_(s) s
42 #endif
43 
44 /* Defines for access() */
45 #ifndef F_OK
46 #define F_OK 0
47 #endif
48 
49 #ifndef X_OK
50 #define X_OK 1
51 #endif
52 
53 #ifndef W_OK
54 #define W_OK 2
55 #endif
56 
57 #ifndef R_OK
58 #define R_OK 4
59 #endif
60 
61 #define COBC_ABORT() cobc_abort(__FILE__, __LINE__)
62 #define COBC_DUMB_ABORT() cobc_dumb_abort(__FILE__, __LINE__)
63 
64 /* Source format defines */
65 #define CB_FORMAT_FIXED 0
66 #define CB_FORMAT_FREE 1
67 
68 /* COPY extended syntax defines */
69 #define CB_REPLACE_LEADING 1U
70 #define CB_REPLACE_TRAILING 2U
71 
72 /* Stringify macros */
73 #define CB_STRINGIFY(s) #s
74 #define CB_XSTRINGIFY(s) CB_STRINGIFY(s)
75 
76 /* ASSIGN clause interpretation */
77 #define CB_ASSIGN_MF 0 /* Micro Focus compatibility */
78 #define CB_ASSIGN_IBM 1U /* IBM compatibility */
79 #define CB_ASSIGN_COBOL2002 2U /* COBOL 2002 standard */
80 
81 /* COMP/BINARY byte order */
82 #define CB_BYTEORDER_BIG_ENDIAN 0
83 #define CB_BYTEORDER_NATIVE 1U
84 
85 /* Binary field sizes */
86 #define CB_BINARY_SIZE_1_2_4_8 0 /* 1,2,4,8 bytes */
87 #define CB_BINARY_SIZE_1__8 1U /* 1,2,3,4,5,6,7,8 bytes */
88 #define CB_BINARY_SIZE_2_4_8 2U /* 2,4,8 bytes */
89 
90 /* Flex directive actions */
91 #define PLEX_ACT_IF 0
92 #define PLEX_ACT_ELSE 1U
93 #define PLEX_ACT_END 2U
94 #define PLEX_ACT_ELIF 3U
95 
96 /* Flex value types */
97 #define PLEX_DEF_NONE 0
98 #define PLEX_DEF_LIT 1U
99 #define PLEX_DEF_NUM 2U
100 #define PLEX_DEF_DEL 3U
101 
102 /* Context sensitive keyword defines (trigger words) */
103 #define CB_CS_ACCEPT (1U << 0)
104 #define CB_CS_ALPHABET (1U << 1)
105 #define CB_CS_ASSIGN (1U << 2)
106 #define CB_CS_CALL (1U << 3)
107 #define CB_CS_CONSTANT (1U << 4)
108 #define CB_CS_DATE (1U << 5)
109 #define CB_CS_DAY (1U << 6)
110 #define CB_CS_DISPLAY (1U << 7)
111 #define CB_CS_ERASE (1U << 8)
112 #define CB_CS_EXIT (1U << 9)
113 #define CB_CS_FROM (1U << 10)
114 #define CB_CS_PROGRAM_ID (1U << 11)
115 #define CB_CS_ROUNDED (1U << 12)
116 #define CB_CS_SET (1U << 13)
117 #define CB_CS_STOP (1U << 14)
118 #define CB_CS_WITH (1U << 15)
119 
120 /* Support for cobc from stdin */
121 #define COB_DASH "-"
122 #define COB_DASH_NAME "a.cob"
123 #define COB_DASH_OUT "a.out"
124 
125 
126 /* Operand operation type */
131 };
132 
133 /* Config dialect support types */
135  CB_OK = 0,
143 };
144 
145 /* Config dialect support types */
156 };
157 
158 /* Generic text list structure */
159 struct cb_text_list {
160  struct cb_text_list *next; /* next pointer */
162  const char *text;
163 };
164 
165 /* Generic replace list structure */
167  struct cb_replace_list *next; /* next pointer */
170  const struct cb_text_list *old_text;
171  const struct cb_text_list *new_text;
172  unsigned int lead_trail;
173 };
174 
175 /* Generic define list structure */
177  struct cb_define_struct *next; /* next pointer */
179  char *name;
180  char *value;
181  unsigned int deftype;
182  int sign;
183  int int_part;
184  int dec_part;
185 };
186 
187 /* Structure for extended filenames */
189  struct local_filename *next; /* next pointer */
190  char *local_name;
191  FILE *local_fp;
192 };
193 
194 /* Structure for filename */
195 struct filename {
196  struct filename *next;
197  const char *source; /* foo.cob (path from command line) */
198  const char *preprocess; /* foo.i (full path) */
199  const char *translate; /* foo.c (full path) */
200  const char *trstorage; /* foo.c.h (full path) */
201  const char *object; /* foo.o (full path) */
202  const char *demangle_source; /* foo */
203  const char *listing_file; /* foo.lst */
204  struct local_filename *localfile; /* foo.c.l[n].h */
205  size_t translate_len; /* strlen translate */
206  size_t object_len; /* strlen object */
207  unsigned int need_preprocess; /* Needs preprocess */
208  unsigned int need_translate; /* Needs parse */
209  unsigned int need_assemble; /* Needs C compile */
210  int has_error; /* Error detected */
211  int file_is_stdin; /* dash used as filename */
212 };
213 
214 /* Exception structure */
215 struct cb_exception {
216  const char *name; /* Exception name */
217  const int code; /* Exception code */
218  int enable; /* If turned on */
219 };
220 
221 /* Structure for reserved words that have been reverted */
223  struct reserved_word_list *next; /* next pointer */
224  char *word;
226  char *alias_for;
227 };
228 
229 /* Basic memory structure */
231  struct cobc_mem_struct *next; /* next pointer */
232  void *memptr;
233  size_t memlen;
234 };
235 
236 
237 extern int cb_source_format;
238 
239 extern struct cb_exception cb_exception_table[];
240 
241 #define CB_EXCEPTION_NAME(id) cb_exception_table[id].name
242 #define CB_EXCEPTION_CODE(id) cb_exception_table[id].code
243 #define CB_EXCEPTION_ENABLE(id) cb_exception_table[id].enable
244 
245 #undef CB_FLAG
246 #undef CB_FLAG_RQ
247 #undef CB_FLAG_NQ
248 #define CB_FLAG(var,pdok,name,doc) extern int var;
249 #define CB_FLAG_RQ(var,pdok,name,def,opt,doc) extern int var;
250 #define CB_FLAG_NQ(pdok,name,opt,doc)
251 #include "flag.def"
252 #undef CB_FLAG
253 #undef CB_FLAG_RQ
254 #undef CB_FLAG_nQ
255 
256 #undef CB_WARNDEF
257 #undef CB_NOWARNDEF
258 #define CB_WARNDEF(var,name,doc) extern int var;
259 #define CB_NOWARNDEF(var,name,doc) extern int var;
260 #include "warning.def"
261 #undef CB_WARNDEF
262 #undef CB_NOWARNDEF
263 
264 #undef CB_OPTIM_DEF
265 #define CB_OPTIM_DEF(x) x,
266 enum cb_optim {
268 #include "codeoptim.def"
270 };
271 #undef CB_OPTIM_DEF
272 
273 extern int cb_id;
274 extern int cb_attr_id;
275 extern int cb_literal_id;
276 extern int cb_field_id;
277 extern int cobc_flag_main;
278 extern int cb_flag_functions_all;
279 extern int cb_flag_main;
280 extern int cobc_wants_debug;
281 extern int cobc_seen_stdin;
282 
283 extern int errorcount;
284 extern int warningcount;
285 extern int warningopt;
286 extern int no_physical_cancel;
287 extern cob_u32_t optimize_defs[];
288 
289 extern char *cb_oc_build_stamp;
290 extern const char *cb_source_file;
291 extern int cb_source_line;
293 extern const char *cob_config_dir;
295 extern unsigned int cobc_gen_listing;
297 extern const char *demangle_name;
298 extern FILE *cb_storage_file;
299 extern const char *cb_storage_file_name;
301 extern char **cb_saveargv;
302 extern int cb_saveargc;
304 extern FILE *cb_listing_file;
311 extern struct cb_program *current_program;
313 extern struct cb_label *current_section;
315 extern int cb_exp_line;
316 extern int functions_are_all;
318 
319 /* Functions */
321 /* cobc.c */
325 extern void *cobc_malloc (const size_t);
326 extern void cobc_free (void *);
327 extern void *cobc_strdup (const char *);
328 extern void *cobc_realloc (void *, const size_t);
330 extern void *cobc_main_malloc (const size_t);
331 extern void *cobc_main_strdup (const char *);
332 extern void *cobc_main_realloc (void *, const size_t);
333 extern void cobc_main_free (void *);
335 extern void *cobc_parse_malloc (const size_t);
336 extern void *cobc_parse_strdup (const char *);
337 extern void *cobc_parse_realloc (void *, const size_t);
338 extern void cobc_parse_free (void *);
340 extern void *cobc_plex_malloc (const size_t);
341 extern void *cobc_plex_strdup (const char *);
342 
343 extern void *cobc_check_string (const char *);
344 extern void cobc_abort_pr (const char *, ...) COB_A_FORMAT12;
346 DECLNORET extern void cobc_abort (const char *,
347  const int) COB_A_NORETURN;
348 DECLNORET extern void cobc_too_many_errors (void) COB_A_NORETURN;
349 DECLNORET extern void cobc_dumb_abort (const char *, const int);
351 extern size_t cobc_check_valid_name (const char *,
352  const unsigned int);
354 /* config.c */
356 #undef CB_CONFIG_ANY
357 #undef CB_CONFIG_INT
358 #undef CB_CONFIG_STRING
359 #undef CB_CONFIG_BOOLEAN
360 #undef CB_CONFIG_SUPPORT
362 #define CB_CONFIG_ANY(type,var,name) extern type var;
363 #define CB_CONFIG_INT(var,name) extern unsigned int var;
364 #define CB_CONFIG_STRING(var,name) extern const char *var;
365 #define CB_CONFIG_BOOLEAN(var,name) extern unsigned int var;
366 #define CB_CONFIG_SUPPORT(var,name) extern enum cb_support var;
368 #include "config.def"
370 #undef CB_CONFIG_ANY
371 #undef CB_CONFIG_INT
372 #undef CB_CONFIG_STRING
373 #undef CB_CONFIG_BOOLEAN
374 #undef CB_CONFIG_SUPPORT
376 extern int cb_load_std (const char *);
377 extern int cb_config_entry (char *, const char *, const int);
378 extern int cb_load_conf (const char *, const int);
380 #ifndef HAVE_DESIGNATED_INITS
381 /* Initialization routines in scanner.l, typeck.c, reserved.c */
382 extern void cobc_init_scanner (void);
383 extern void cobc_init_typeck (void);
384 extern void cobc_init_reserved (void);
385 #endif
387 /* preprocessor (in pplex.l, ppparse.y) */
388 #if !defined (COB_IN_SCANNER ) && !defined (COB_IN_PPLEX)
389 extern FILE *ppin;
390 extern FILE *ppout;
391 extern int pplex (void);
392 #endif
394 #ifndef COB_IN_PPPARSE
395 extern int ppparse (void);
396 #endif
398 extern int ppopen (const char *, struct cb_replace_list *);
399 extern int ppcopy (const char *, const char *,
400  struct cb_replace_list *);
401 extern void pp_set_replace_list (struct cb_replace_list *,
402  const cob_u32_t);
403 extern void ppparse_error (const char *);
404 extern void ppparse_clear_vars (const struct cb_define_struct *);
405 extern void plex_clear_vars (void);
406 extern void plex_clear_all (void);
407 extern void plex_call_destroy (void);
408 extern void plex_action_directive (const unsigned int,
409  const unsigned int);
411 /* parser (in scanner.l, parser.y) */
412 extern char *cobc_glob_line;
414 #if !defined (COB_IN_SCANNER ) && !defined (COB_IN_PPLEX) && \
415  !defined (COB_IN_PPPARSE)
416 extern FILE *yyin;
417 extern FILE *yyout;
418 extern int yylex (void);
419 #endif
421 #if !defined (COB_IN_PPPARSE) && !defined (COB_IN_PARSER)
422 extern int yyparse (void);
423 #endif
425 extern void ylex_clear_all (void);
426 extern void ylex_call_destroy (void);
428 /* typeck.c */
429 extern size_t suppress_warn;
431 /* codeoptim.c */
432 extern void cob_gen_optim (const enum cb_optim);
434 /* error.c */
435 #define CB_MSG_STYLE_GCC 0
436 #define CB_MSG_STYLE_MSC 1U
438 extern size_t cb_msg_style;
439 
440 extern void cb_warning (const char *, ...) COB_A_FORMAT12;
441 extern void cb_error (const char *, ...) COB_A_FORMAT12;
442 extern void cb_plex_warning (const size_t,
443  const char *, ...) COB_A_FORMAT23;
444 extern void cb_plex_error (const size_t,
445  const char *, ...) COB_A_FORMAT23;
446 extern void configuration_warning (const char *, const int,
447  const char *, ...) COB_A_FORMAT34;
448 extern void configuration_error (const char *, const int,
449  const int, const char *, ...) COB_A_FORMAT45;
450 
451 extern unsigned int cb_verify (const enum cb_support, const char *);
452 
453 /* reserved.c */
455 
456 extern void remove_reserved_word (const char *);
457 extern void add_reserved_word (const char *, const char *,
458  const int);
459 
460 #endif /* CB_COBC_H */
struct cb_text_list * next
Definition: cobc.h:160
struct cb_tree_common * defined_prog_list
Definition: parser.c:172
void ylex_call_destroy(void)
Definition: scanner.c:4757
struct cb_text_list * cb_intrinsic_list
Definition: cobc.c:150
#define COB_A_FORMAT23
Definition: common.h:368
Definition: cobc.h:139
#define cob_u32_t
Definition: common.h:31
void plex_call_destroy(void)
Definition: pplex.c:4583
int warningcount
Definition: cobc.c:174
int cb_saveargc
Definition: cobc.c:179
const char * text
Definition: cobc.h:162
int errorcount
Definition: cobc.c:173
size_t suppress_warn
Definition: typeck.c:90
int int_part
Definition: cobc.h:183
const int code
Definition: cobc.h:217
struct reserved_word_list * cobc_user_res_list
Definition: reserved.c:36
Definition: cobc.h:141
FILE * yyin
void cb_plex_warning(const size_t, const char *,...) COB_A_FORMAT23
Definition: error.c:119
struct cb_define_struct * next
Definition: cobc.h:177
void * memptr
Definition: cobc.h:232
void * cobc_main_malloc(const size_t)
Definition: cobc.c:702
unsigned int need_assemble
Definition: cobc.h:209
unsigned int cb_verify(const enum cb_support, const char *)
Definition: error.c:246
FILE * cb_listing_file
Definition: cobc.c:157
int cb_load_conf(const char *, const int)
Definition: config.c:476
const char * listing_file
Definition: cobc.h:203
int dec_part
Definition: cobc.h:184
const char * preprocess
Definition: cobc.h:198
int yyparse(void)
Definition: parser.c:6565
struct cb_text_list * cb_extension_list
Definition: cobc.c:151
int no_physical_cancel
Definition: cobc.c:177
int warningopt
Definition: cobc.c:176
void ppparse_clear_vars(const struct cb_define_struct *)
Definition: ppparse.c:490
int cb_id
Definition: cobc.c:163
int ppcopy(const char *, const char *, struct cb_replace_list *)
Definition: pplex.c:4508
struct reserved_word_list * cob_user_res_list
void plex_clear_all(void)
Definition: pplex.c:4570
int cb_source_format
Definition: cobc.c:162
int enable
Definition: cobc.h:218
#define COB_A_FORMAT12
Definition: common.h:367
void ylex_clear_all(void)
Definition: scanner.c:4736
const char * demangle_source
Definition: cobc.h:202
void ppparse_error(const char *)
Definition: pplex.c:4553
void plex_action_directive(const unsigned int, const unsigned int)
Definition: pplex.c:4589
unsigned int need_translate
Definition: cobc.h:208
void * cobc_malloc(const size_t)
Definition: cobc.c:643
void cobc_main_free(void *)
Definition: cobc.c:778
void remove_reserved_word(const char *)
Definition: reserved.c:2882
void configuration_warning(const char *, const int, const char *,...) COB_A_FORMAT34
Definition: error.c:144
int yylex(void)
The main scanner function which does all the work.
Definition: scanner.c:1705
struct cb_exception cb_exception_table[]
Definition: cobc.c:186
Definition: cobc.h:135
void * cobc_realloc(void *, const size_t)
Definition: cobc.c:687
char * name
Definition: cobc.h:179
int is_context_sensitive
Definition: cobc.h:225
const char * trstorage
Definition: cobc.h:200
struct local_filename * localfile
Definition: cobc.h:204
cb_support
Definition: cobc.h:134
FILE * cb_storage_file
Definition: cobc.c:156
FILE * ppin
Definition: pplex.c:367
const char * source
Definition: cobc.h:197
size_t object_len
Definition: cobc.h:206
char * cb_oc_build_stamp
Definition: cobc.c:146
int cb_attr_id
Definition: cobc.c:164
unsigned int deftype
Definition: cobc.h:181
void * cobc_parse_realloc(void *, const size_t)
Definition: cobc.c:845
cob_u32_t optimize_defs[]
Definition: cobc.c:182
int cb_flag_main
Definition: cobc.c:168
struct cb_replace_list * last
Definition: cobc.h:168
size_t cobc_check_valid_name(const char *, const unsigned int)
Definition: cobc.c:1142
void cobc_init_scanner(void)
Definition: scanner.c:4922
int pplex(void)
The main scanner function which does all the work.
Definition: pplex.c:2352
void cobc_free(void *)
Definition: cobc.c:657
struct reserved_word_list * next
Definition: cobc.h:223
cb_optim
Definition: cobc.h:266
const char * cb_storage_file_name
Definition: cobc.c:148
void cobc_parse_free(void *)
Definition: cobc.c:885
const char * cob_config_dir
Definition: cobc.c:155
size_t translate_len
Definition: cobc.h:205
void plex_clear_vars(void)
Definition: pplex.c:4559
const char * name
Definition: cobc.h:216
struct cb_text_list * last
Definition: cobc.h:161
int ppparse(void)
Definition: ppparse.c:1656
#define COB_A_NORETURN
Definition: common.h:366
cb_std_def
Definition: cobc.h:146
int ppopen(const char *, struct cb_replace_list *)
Definition: pplex.c:4420
struct cb_define_struct * last
Definition: cobc.h:178
void pp_set_replace_list(struct cb_replace_list *, const cob_u32_t)
Definition: pplex.c:4394
FILE * ppout
Definition: pplex.c:367
size_t memlen
Definition: cobc.h:233
struct cb_text_list * cb_include_list
Definition: cobc.c:149
void * cobc_main_realloc(void *, const size_t)
Definition: cobc.c:738
size_t cb_msg_style
Definition: error.c:43
cb_operation_type
Definition: cobc.h:127
int cb_field_id
Definition: cobc.c:166
char * value
Definition: cobc.h:180
DECLNORET void cobc_abort(const char *, const int) COB_A_NORETURN
Definition: cobc.c:606
void * cobc_plex_strdup(const char *)
Definition: cobc.c:933
unsigned int lead_trail
Definition: cobc.h:172
struct cb_label * current_paragraph
Definition: parser.c:171
int cb_source_line
Definition: cobc.c:178
void cobc_abort_pr(const char *,...) COB_A_FORMAT12
Definition: cobc.c:587
void * cobc_plex_malloc(const size_t)
Definition: cobc.c:916
char * alias_for
Definition: cobc.h:226
void cb_error(const char *,...) COB_A_FORMAT12
Definition: error.c:98
#define COB_A_FORMAT45
Definition: common.h:370
int has_error
Definition: cobc.h:210
void * cobc_strdup(const char *)
Definition: cobc.c:669
struct cb_replace_list * next
Definition: cobc.h:167
int functions_are_all
Definition: parser.c:177
int file_is_stdin
Definition: cobc.h:211
void configuration_error(const char *, const int, const int, const char *,...) COB_A_FORMAT45
Definition: error.c:178
struct cb_program * current_program
Definition: parser.c:168
char ** cb_saveargv
Definition: cobc.c:154
void cob_gen_optim(const enum cb_optim)
Definition: codeoptim.c:48
struct filename * next
Definition: cobc.h:196
int cb_load_std(const char *)
Definition: config.c:147
const char * cb_source_file
Definition: cobc.c:145
void cb_warning(const char *,...) COB_A_FORMAT12
Definition: error.c:87
void add_reserved_word(const char *, const char *, const int)
Definition: reserved.c:2903
#define DECLNORET
Definition: common.h:376
int cobc_flag_main
Definition: cobc.c:167
int cb_literal_id
Definition: cobc.c:165
Definition: tree.h:764
FILE * yyout
int cb_exp_line
Definition: parser.c:174
void * cobc_main_strdup(const char *)
Definition: cobc.c:720
void * cobc_parse_malloc(const size_t)
Definition: cobc.c:809
struct cb_label * current_section
Definition: parser.c:170
unsigned int need_preprocess
Definition: cobc.h:207
Definition: cobc.h:195
struct local_filename * next
Definition: cobc.h:189
void * cobc_check_string(const char *)
Definition: cobc.c:951
char * word
Definition: cobc.h:224
const struct cb_text_list * old_text
Definition: cobc.h:170
unsigned int cobc_gen_listing
Definition: cobc.c:180
const char * translate
Definition: cobc.h:199
const struct cb_text_list * new_text
Definition: cobc.h:171
DECLNORET void cobc_dumb_abort(const char *, const int)
Definition: cobc.c:613
char * cobc_glob_line
Definition: parser.c:173
const char * demangle_name
Definition: cobc.c:147
void * cobc_parse_strdup(const char *)
Definition: cobc.c:827
const char * object
Definition: cobc.h:201
int cobc_wants_debug
Definition: cobc.c:169
FILE * local_fp
Definition: cobc.h:191
void cobc_init_typeck(void)
Definition: typeck.c:8747
struct cb_text_list * cb_static_call_list
Definition: cobc.c:152
struct cb_text_list * cb_early_exit_list
Definition: cobc.c:153
int cb_flag_functions_all
Definition: cobc.c:170
void cb_plex_error(const size_t, const char *,...) COB_A_FORMAT23
Definition: error.c:130
struct cb_statement * current_statement
Definition: parser.c:169
DECLNORET void cobc_too_many_errors(void) COB_A_NORETURN
Definition: cobc.c:599
char * local_name
Definition: cobc.h:190
int cb_config_entry(char *, const char *, const int)
Definition: config.c:153
struct cb_replace_list * prev
Definition: cobc.h:169
#define COB_A_FORMAT34
Definition: common.h:369
void cobc_init_reserved(void)
Definition: reserved.c:3133
int cobc_seen_stdin
Definition: cobc.c:171
struct cobc_mem_struct * next
Definition: cobc.h:231