cst_val_defs.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*************************************************************************/
  2. /* */
  3. /* Language Technologies Institute */
  4. /* Carnegie Mellon University */
  5. /* Copyright (c) 1999 */
  6. /* All Rights Reserved. */
  7. /* */
  8. /* Permission is hereby granted, free of charge, to use and distribute */
  9. /* this software and its documentation without restriction, including */
  10. /* without limitation the rights to use, copy, modify, merge, publish, */
  11. /* distribute, sublicense, and/or sell copies of this work, and to */
  12. /* permit persons to whom this work is furnished to do so, subject to */
  13. /* the following conditions: */
  14. /* 1. The code must retain the above copyright notice, this list of */
  15. /* conditions and the following disclaimer. */
  16. /* 2. Any modifications must be clearly marked as such. */
  17. /* 3. Original authors' names are not deleted. */
  18. /* 4. The authors' names are not used to endorse or promote products */
  19. /* derived from this software without specific prior written */
  20. /* permission. */
  21. /* */
  22. /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
  23. /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
  24. /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
  25. /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
  26. /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
  27. /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
  28. /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
  29. /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
  30. /* THIS SOFTWARE. */
  31. /* */
  32. /*************************************************************************/
  33. /* Author: Alan W Black (awb@cs.cmu.edu) */
  34. /* Date: December 1999 */
  35. /*************************************************************************/
  36. /* */
  37. /* Macros for user defined type objects */
  38. /* */
  39. /*************************************************************************/
  40. #ifndef _CST_VAL_DEFS_H__
  41. #define _CST_VAL_DEFS_H__
  42. #include <stdlib.h>
  43. /* Macro for defining new user structs as vals */
  44. #define CST_VAL_USER_TYPE_DCLS(NAME,TYPE) \
  45. extern const int cst_val_type_##NAME; \
  46. TYPE *val_##NAME(const cst_val *v); \
  47. cst_val *NAME##_val(const TYPE *v);
  48. #define CST_VAL_USER_FUNCPTR_DCLS(NAME,TYPE) \
  49. extern const int cst_val_type_##NAME; \
  50. TYPE val_##NAME(const cst_val *v); \
  51. cst_val *NAME##_val(const TYPE v);
  52. #define CST_VAL_REGISTER_TYPE(NAME,TYPE) \
  53. TYPE *val_##NAME(const cst_val *v) \
  54. { \
  55. return (TYPE *)val_generic(v,cst_val_type_##NAME,#NAME); \
  56. } \
  57. void val_delete_##NAME(void *v) \
  58. { \
  59. delete_##NAME((TYPE *)v); \
  60. } \
  61. \
  62. cst_val *NAME##_val(const TYPE *v) \
  63. { \
  64. return val_new_typed(cst_val_type_##NAME, \
  65. (void *)v); \
  66. } \
  67. #define CST_VAL_REG_TD_TYPE(NAME,TYPE,NUM) \
  68. extern const int cst_val_type_##NAME; \
  69. const int cst_val_type_##NAME=NUM; \
  70. void val_delete_##NAME(void *v); \
  71. /* When objects of this type can never be owned by vals */
  72. #define CST_VAL_REGISTER_TYPE_NODEL(NAME,TYPE) \
  73. TYPE *val_##NAME(const cst_val *v) \
  74. { \
  75. return (TYPE *)val_generic(v,cst_val_type_##NAME,#NAME); \
  76. } \
  77. \
  78. cst_val *NAME##_val(const TYPE *v) \
  79. { \
  80. return val_new_typed(cst_val_type_##NAME, \
  81. (void *)v); \
  82. } \
  83. #define CST_VAL_REG_TD_TYPE_NODEL(NAME,TYPE,NUM) \
  84. extern const int cst_val_type_##NAME; \
  85. const int cst_val_type_##NAME=NUM; \
  86. void val_delete_##NAME(void *v) { (void)v; } \
  87. #define CST_VAL_REGISTER_FUNCPTR(NAME,TYPE) \
  88. TYPE val_##NAME(const cst_val *v) \
  89. { \
  90. return (TYPE)val_generic(v,cst_val_type_##NAME,#NAME); \
  91. } \
  92. \
  93. cst_val *NAME##_val(const TYPE v) \
  94. { \
  95. return val_new_typed(cst_val_type_##NAME, \
  96. (void *)v); \
  97. } \
  98. #define CST_VAL_REG_TD_FUNCPTR(NAME,TYPE,NUM) \
  99. extern const int cst_val_type_##NAME; \
  100. const int cst_val_type_##NAME=NUM; \
  101. void val_delete_##NAME(void *v) { (void)v; } \
  102. #endif