This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Let state sub fwd decls and nested subs work in anons
[perl5.git] / x2p / a2p.h
CommitLineData
8665f9e4 1/* a2p.h
a687059c 2 *
4bb101f2
JH
3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, by Larry Wall and others
a687059c 5 *
2b317908
LW
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
8d063cd8
LW
8 */
9
be04251a 10#define VOIDUSED 1
d07c2202
GS
11
12#ifdef WIN32
13#define _INC_WIN32_PERL5 /* kludge around win32 stdio layer */
14#endif
15
54b3431f 16#ifdef __VMS
774d564b 17# include "config.h"
cf267c36
JH
18#elif defined(NETWARE)
19# include "../NetWare/config.h"
774d564b 20#else
21# include "../config.h"
22#endif
be04251a 23
4d09c4de 24#if defined(__STDC__) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
3730b96e
GS
25# define STANDARD_C 1
26#endif
27
d07c2202
GS
28#ifdef WIN32
29#undef USE_STDIO_PTR /* XXX fast gets won't work, must investigate */
30# ifndef STANDARD_C
31# define STANDARD_C
32# endif
d07c2202
GS
33#endif
34
9c8d0b29
AD
35/* Use all the "standard" definitions? */
36#if defined(STANDARD_C) && defined(I_STDLIB)
37# include <stdlib.h>
38#endif /* STANDARD_C */
fed7345c 39
9c8d0b29
AD
40#include <stdio.h>
41
42#ifdef I_MATH
43#include <math.h>
44#endif
45
fed7345c
AD
46#ifdef I_SYS_TYPES
47# include <sys/types.h>
48#endif
49
dfe0b228 50#ifdef USE_NEXT_CTYPE
51
52#if NX_CURRENT_COMPILER_RELEASE >= 400
53#include <objc/NXCType.h>
54#else /* NX_CURRENT_COMPILER_RELEASE < 400 */
9c8d0b29 55#include <appkit/NXCType.h>
dfe0b228 56#endif /* NX_CURRENT_COMPILER_RELEASE >= 400 */
57
58#else /* !USE_NEXT_CTYPE */
9c8d0b29 59#include <ctype.h>
dfe0b228 60#endif /* USE_NEXT_CTYPE */
9c8d0b29
AD
61
62#define MEM_SIZE Size_t
bc82975d 63#ifdef PERL_MEM_LOG
bc82975d
AD
64 typedef IVTYPE IV;
65 typedef UVTYPE UV;
66#endif
9c8d0b29 67
c1d22f6b 68#ifndef STANDARD_C
20ce7b12
GS
69 Malloc_t malloc (MEM_SIZE nbytes);
70 Malloc_t calloc (MEM_SIZE elements, MEM_SIZE size);
71 Malloc_t realloc (Malloc_t where, MEM_SIZE nbytes);
72 Free_t free (Malloc_t where);
55497cff 73#endif
74
9c8d0b29
AD
75#if defined(I_STRING) || defined(__cplusplus)
76# include <string.h>
77#else
78# include <strings.h>
79#endif
80
81#if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
82#define strchr index
83#define strrchr rindex
84#endif
85
1aef975c
AD
86#ifdef I_TIME
87# include <time.h>
88#endif
89
90#ifdef I_SYS_TIME
91# ifdef I_SYS_TIME_KERNEL
92# define KERNEL
93# endif
94# include <sys/time.h>
95# ifdef I_SYS_TIME_KERNEL
96# undef KERNEL
97# endif
98#endif
99
100#ifndef MSDOS
101# if defined(HAS_TIMES) && defined(I_SYS_TIMES)
102# include <sys/times.h>
103# endif
104#endif
105
4633a7c4
LW
106#ifdef DOSISH
107# if defined(OS2)
23da6c43 108# define PTHX_UNUSED
4633a7c4
LW
109# include "../os2ish.h"
110# else
111# include "../dosish.h"
112# endif
113#else
114# if defined(VMS)
44a8e56a 115# define NO_PERL_TYPEDEFS
774d564b 116# include "vmsish.h"
4633a7c4
LW
117# endif
118#endif
119
1aef975c
AD
120#ifndef STANDARD_C
121/* All of these are in stdlib.h or time.h for ANSI C */
122Time_t time();
123struct tm *gmtime(), *localtime();
043fec90 124#if defined(OEMVS)
092bebab
JH
125char *(strchr)(), *(strrchr)();
126char *(strcpy)(), *(strcat)();
127#else
1aef975c
AD
128char *strchr(), *strrchr();
129char *strcpy(), *strcat();
092bebab 130#endif
1aef975c
AD
131#endif /* ! STANDARD_C */
132
159e8d64
MHM
133#ifdef __cplusplus
134# define PERL_EXPORT_C extern "C"
135#else
136# define PERL_EXPORT_C extern
137#endif
138
774d564b 139#ifdef VMS
140# include "handy.h"
141#else
142# include "../handy.h"
143#endif
55497cff 144
8d063cd8
LW
145#define Nullop 0
146
147#define OPROG 1
148#define OJUNK 2
149#define OHUNKS 3
150#define ORANGE 4
151#define OPAT 5
152#define OHUNK 6
153#define OPPAREN 7
154#define OPANDAND 8
155#define OPOROR 9
156#define OPNOT 10
157#define OCPAREN 11
158#define OCANDAND 12
159#define OCOROR 13
160#define OCNOT 14
161#define ORELOP 15
162#define ORPAREN 16
163#define OMATCHOP 17
164#define OMPAREN 18
165#define OCONCAT 19
166#define OASSIGN 20
167#define OADD 21
a687059c 168#define OSUBTRACT 22
8d063cd8
LW
169#define OMULT 23
170#define ODIV 24
171#define OMOD 25
172#define OPOSTINCR 26
173#define OPOSTDECR 27
174#define OPREINCR 28
175#define OPREDECR 29
176#define OUMINUS 30
177#define OUPLUS 31
178#define OPAREN 32
179#define OGETLINE 33
180#define OSPRINTF 34
181#define OSUBSTR 35
182#define OSTRING 36
183#define OSPLIT 37
184#define OSNEWLINE 38
185#define OINDEX 39
186#define ONUM 40
187#define OSTR 41
188#define OVAR 42
189#define OFLD 43
190#define ONEWLINE 44
191#define OCOMMENT 45
192#define OCOMMA 46
193#define OSEMICOLON 47
194#define OSCOMMENT 48
195#define OSTATES 49
196#define OSTATE 50
197#define OPRINT 51
198#define OPRINTF 52
199#define OBREAK 53
200#define ONEXT 54
201#define OEXIT 55
202#define OCONTINUE 56
203#define OREDIR 57
204#define OIF 58
205#define OWHILE 59
206#define OFOR 60
207#define OFORIN 61
208#define OVFLD 62
209#define OBLOCK 63
210#define OREGEX 64
211#define OLENGTH 65
212#define OLOG 66
213#define OEXP 67
214#define OSQRT 68
215#define OINT 69
a687059c
LW
216#define ODO 70
217#define OPOW 71
218#define OSUB 72
219#define OGSUB 73
220#define OMATCH 74
221#define OUSERFUN 75
222#define OUSERDEF 76
223#define OCLOSE 77
224#define OATAN2 78
225#define OSIN 79
226#define OCOS 80
227#define ORAND 81
228#define OSRAND 82
229#define ODELETE 83
230#define OSYSTEM 84
231#define OCOND 85
232#define ORETURN 86
233#define ODEFINED 87
234#define OSTAR 88
8d063cd8
LW
235
236#ifdef DOINIT
aab39148 237const char *opname[] = {
8d063cd8
LW
238 "0",
239 "PROG",
240 "JUNK",
241 "HUNKS",
242 "RANGE",
243 "PAT",
244 "HUNK",
245 "PPAREN",
246 "PANDAND",
247 "POROR",
248 "PNOT",
249 "CPAREN",
250 "CANDAND",
251 "COROR",
252 "CNOT",
253 "RELOP",
254 "RPAREN",
255 "MATCHOP",
256 "MPAREN",
257 "CONCAT",
258 "ASSIGN",
259 "ADD",
a687059c 260 "SUBTRACT",
8d063cd8
LW
261 "MULT",
262 "DIV",
263 "MOD",
264 "POSTINCR",
265 "POSTDECR",
266 "PREINCR",
267 "PREDECR",
268 "UMINUS",
269 "UPLUS",
270 "PAREN",
271 "GETLINE",
272 "SPRINTF",
273 "SUBSTR",
274 "STRING",
275 "SPLIT",
276 "SNEWLINE",
277 "INDEX",
278 "NUM",
279 "STR",
280 "VAR",
281 "FLD",
282 "NEWLINE",
283 "COMMENT",
284 "COMMA",
285 "SEMICOLON",
286 "SCOMMENT",
287 "STATES",
288 "STATE",
289 "PRINT",
290 "PRINTF",
291 "BREAK",
292 "NEXT",
293 "EXIT",
294 "CONTINUE",
295 "REDIR",
296 "IF",
297 "WHILE",
298 "FOR",
299 "FORIN",
300 "VFLD",
301 "BLOCK",
302 "REGEX",
303 "LENGTH",
304 "LOG",
305 "EXP",
306 "SQRT",
307 "INT",
a687059c
LW
308 "DO",
309 "POW",
310 "SUB",
311 "GSUB",
312 "MATCH",
313 "USERFUN",
314 "USERDEF",
315 "CLOSE",
316 "ATAN2",
317 "SIN",
318 "COS",
319 "RAND",
320 "SRAND",
321 "DELETE",
322 "SYSTEM",
323 "COND",
324 "RETURN",
325 "DEFINED",
326 "STAR",
327 "89"
8d063cd8
LW
328};
329#else
aab39148 330extern const char *opname[];
8d063cd8
LW
331#endif
332
a687059c
LW
333EXT int mop INIT(1);
334
d8f2e4cc 335union u_ops {
8d063cd8
LW
336 int ival;
337 char *cval;
d8f2e4cc 338};
d8f2e4cc 339#define OPSMAX 50000
a0d0e21e 340EXT union u_ops ops[OPSMAX];
8d063cd8 341
8d063cd8
LW
342typedef struct string STR;
343typedef struct htbl HASH;
344
345#include "str.h"
346#include "hash.h"
347
9c8d0b29 348
8d063cd8
LW
349/* A string is TRUE if not "" or "0". */
350#define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
aab39148
RB
351EXT const char *Yes INIT("1");
352EXT const char *No INIT("");
8d063cd8 353
8d063cd8 354#define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
8d063cd8
LW
355EXT STR *Str;
356
357#define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
358
9c8d0b29 359/* Prototypes for things in a2p.c */
20ce7b12
GS
360int aryrefarg ( int arg );
361int bl ( int arg, int maybe );
362void dump ( int branch );
363int fixfargs ( int name, int arg, int prevargs );
364int fixrargs ( char *name, int arg, int prevargs );
365void fixup ( STR *str );
366int numary ( int arg );
367int oper0 ( int type );
368int oper1 ( int type, int arg1 );
369int oper2 ( int type, int arg1, int arg2 );
370int oper3 ( int type, int arg1, int arg2, int arg3 );
371int oper4 ( int type, int arg1, int arg2, int arg3, int arg4 );
372int oper5 ( int type, int arg1, int arg2, int arg3, int arg4, int arg5 );
373void putlines ( STR *str );
374void putone ( void );
375int rememberargs ( int arg );
376char * scannum ( char *s );
377char * scanpat ( char *s );
aab39148
RB
378int string ( const char *ptr, int len );
379void yyerror ( const char *s );
20ce7b12 380int yylex ( void );
8d063cd8
LW
381
382EXT int line INIT(0);
383
384EXT FILE *rsfp;
fe14fcc3 385EXT char buf[2048];
8d063cd8
LW
386EXT char *bufptr INIT(buf);
387
d34ed59f 388EXT STR *linestr INIT(NULL);
8d063cd8 389
fe14fcc3 390EXT char tokenbuf[2048];
8d063cd8
LW
391EXT int expectterm INIT(TRUE);
392
393#ifdef DEBUGGING
394EXT int debug INIT(0);
395EXT int dlevel INIT(0);
9bb9d9f7 396#define YYDEBUG 1
8d063cd8 397extern int yydebug;
9d116dd7
JH
398#else
399# ifndef YYDEBUG
400# define YYDEBUG 0
401# endif
8d063cd8
LW
402#endif
403
d34ed59f 404EXT STR *freestrroot INIT(NULL);
8d063cd8
LW
405
406EXT STR str_no;
407EXT STR str_yes;
408
409EXT bool do_split INIT(FALSE);
410EXT bool split_to_array INIT(FALSE);
8d063cd8
LW
411EXT bool saw_RS INIT(FALSE);
412EXT bool saw_OFS INIT(FALSE);
413EXT bool saw_ORS INIT(FALSE);
414EXT bool saw_line_op INIT(FALSE);
415EXT bool in_begin INIT(TRUE);
416EXT bool do_opens INIT(FALSE);
417EXT bool do_fancy_opens INIT(FALSE);
418EXT bool lval_field INIT(FALSE);
419EXT bool do_chop INIT(FALSE);
420EXT bool need_entire INIT(FALSE);
421EXT bool absmaxfld INIT(FALSE);
a687059c 422EXT bool saw_altinput INIT(FALSE);
8d063cd8 423
bf10efe7
LW
424EXT bool nomemok INIT(FALSE);
425
8d063cd8 426EXT char const_FS INIT(0);
d34ed59f 427EXT char *namelist INIT(NULL);
8d063cd8 428EXT char fswitch INIT(0);
a5571d59 429EXT bool old_awk INIT(0);
8d063cd8
LW
430
431EXT int saw_FS INIT(0);
432EXT int maxfld INIT(0);
433EXT int arymax INIT(0);
a0d0e21e 434EXT char *nameary[100];
8d063cd8
LW
435
436EXT STR *opens;
437
438EXT HASH *symtab;
a687059c
LW
439EXT HASH *curarghash;
440
441#define P_MIN 0
442#define P_LISTOP 5
443#define P_COMMA 10
444#define P_ASSIGN 15
445#define P_COND 20
446#define P_DOTDOT 25
447#define P_OROR 30
448#define P_ANDAND 35
449#define P_OR 40
450#define P_AND 45
451#define P_EQ 50
452#define P_REL 55
453#define P_UNI 60
454#define P_FILETEST 65
455#define P_SHIFT 70
456#define P_ADD 75
457#define P_MUL 80
458#define P_MATCH 85
459#define P_UNARY 90
460#define P_POW 95
461#define P_AUTO 100
462#define P_MAX 999
79072805
LW
463
464EXT int an;