opcheck.h 3.0 KB

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