2 |
- |
1 |
/* Copyright (C) 1993, 1995, 1997, 1998 Aladdin Enterprises. All rights reserved.
|
|
|
2 |
|
|
|
3 |
This software is provided AS-IS with no warranty, either express or
|
|
|
4 |
implied.
|
|
|
5 |
|
|
|
6 |
This software is distributed under license and may not be copied,
|
|
|
7 |
modified or distributed except as expressly authorized under the terms
|
|
|
8 |
of the license contained in the file LICENSE in this distribution.
|
|
|
9 |
|
|
|
10 |
For more information about licensing, please refer to
|
|
|
11 |
http://www.ghostscript.com/licensing/. For information on
|
|
|
12 |
commercial licensing, go to http://www.artifex.com/licensing/ or
|
|
|
13 |
contact Artifex Software, Inc., 101 Lucas Valley Road #110,
|
|
|
14 |
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
/* $Id: opcheck.h,v 1.6 2003/09/03 03:22:59 giles Exp $ */
|
|
|
18 |
/* Definitions for operator operand checking */
|
|
|
19 |
/* Requires ialloc.h (for imemory), iref.h, ierrors.h */
|
|
|
20 |
|
|
|
21 |
#ifndef opcheck_INCLUDED
|
|
|
22 |
# define opcheck_INCLUDED
|
|
|
23 |
|
|
|
24 |
/*
|
|
|
25 |
* Check the type of an object. Operators almost always use check_type,
|
|
|
26 |
* which is defined in oper.h; check_type_only is for checking
|
|
|
27 |
* subsidiary objects obtained from places other than the stack.
|
|
|
28 |
*/
|
|
|
29 |
#define check_type_only(rf,typ)\
|
|
|
30 |
BEGIN if ( !r_has_type(&rf,typ) ) return_error(e_typecheck); END
|
|
|
31 |
#define check_stype_only(rf,styp)\
|
|
|
32 |
BEGIN if ( !r_has_stype(&rf,imemory,styp) ) return_error(e_typecheck); END
|
|
|
33 |
/* Check for array */
|
|
|
34 |
#define check_array_else(rf,errstat)\
|
|
|
35 |
BEGIN if ( !r_has_type(&rf, t_array) ) errstat; END
|
|
|
36 |
#define check_array_only(rf)\
|
|
|
37 |
check_array_else(rf, return_error(e_typecheck))
|
|
|
38 |
/* Check for procedure. check_proc_failed includes the stack underflow */
|
|
|
39 |
/* check, but it doesn't do any harm in the off-stack case. */
|
|
|
40 |
int check_proc_failed(const ref *);
|
|
|
41 |
|
|
|
42 |
#define check_proc(rf)\
|
|
|
43 |
BEGIN if ( !r_is_proc(&rf) ) return_error(check_proc_failed(&rf)); END
|
|
|
44 |
#define check_proc_only(rf) check_proc(rf)
|
|
|
45 |
|
|
|
46 |
/* Check for read, write, or execute access. */
|
|
|
47 |
#define check_access(rf,acc1)\
|
|
|
48 |
BEGIN if ( !r_has_attr(&rf,acc1) ) return_error(e_invalidaccess); END
|
|
|
49 |
#define check_read(rf) check_access(rf,a_read)
|
|
|
50 |
#define check_write(rf) check_access(rf,a_write)
|
|
|
51 |
#define check_execute(rf) check_access(rf,a_execute)
|
|
|
52 |
#define check_type_access_only(rf,typ,acc1)\
|
|
|
53 |
BEGIN\
|
|
|
54 |
if ( !r_has_type_attrs(&rf,typ,acc1) )\
|
|
|
55 |
return_error((!r_has_type(&rf,typ) ? e_typecheck : e_invalidaccess));\
|
|
|
56 |
END
|
|
|
57 |
#define check_read_type_only(rf,typ)\
|
|
|
58 |
check_type_access_only(rf,typ,a_read)
|
|
|
59 |
#define check_write_type_only(rf,typ)\
|
|
|
60 |
check_type_access_only(rf,typ,a_write)
|
|
|
61 |
|
|
|
62 |
/* Check for an integer value within an unsigned bound. */
|
|
|
63 |
#define check_int_leu(orf, u)\
|
|
|
64 |
BEGIN\
|
|
|
65 |
check_type(orf, t_integer);\
|
|
|
66 |
if ( (ulong)(orf).value.intval > (u) ) return_error(e_rangecheck);\
|
|
|
67 |
END
|
|
|
68 |
#define check_int_leu_only(rf, u)\
|
|
|
69 |
BEGIN\
|
|
|
70 |
check_type_only(rf, t_integer);\
|
|
|
71 |
if ( (ulong)(rf).value.intval > (u) ) return_error(e_rangecheck);\
|
|
|
72 |
END
|
|
|
73 |
#define check_int_ltu(orf, u)\
|
|
|
74 |
BEGIN\
|
|
|
75 |
check_type(orf, t_integer);\
|
|
|
76 |
if ( (ulong)(orf).value.intval >= (u) ) return_error(e_rangecheck);\
|
|
|
77 |
END
|
|
|
78 |
|
|
|
79 |
#endif /* opcheck_INCLUDED */
|