reflection.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include <brl.mod/blitz.mod/blitz.h>
  2. //#include <cstdarg>
  3. void *bbRefFieldPtr( BBObject *obj,int index ){
  4. return (char*)obj+index;
  5. }
  6. void *bbRefMethodPtr( BBObject *obj,int index ){
  7. return *( (void**) ((char*)obj->clas+index) );
  8. }
  9. void *bbRefArrayElementPtr( int sz,BBArray *array,int index ){
  10. return (char*)BBARRAYDATA( array,array->dims )+sz*index;
  11. }
  12. void * bbRefArrayClass(){
  13. return &bbArrayClass;
  14. }
  15. void * bbRefStringClass(){
  16. return &bbStringClass;
  17. }
  18. void * bbRefObjectClass(){
  19. return &bbObjectClass;
  20. }
  21. int bbRefArrayLength( BBArray *array, int dim ){
  22. return array->scales[((dim <= array->dims)? dim : 0)];
  23. }
  24. int bbRefArrayDimensions( BBArray *array ){
  25. return array->dims;
  26. }
  27. BBClass * bbRefClassSuper( BBClass* clas ){
  28. return clas->super;
  29. }
  30. BBDebugScope * bbRefClassDebugScope( BBClass* clas ){
  31. return clas->debug_scope;
  32. }
  33. const char * bbRefClassDebugScopeName( BBClass* clas ){
  34. return clas->debug_scope->name;
  35. }
  36. BBDebugDecl * bbRefClassDebugDecl( BBClass* clas ){
  37. return clas->debug_scope->decls;
  38. }
  39. int bbDebugDeclKind( BBDebugDecl * decl ){
  40. return decl->kind;
  41. }
  42. const char * bbDebugDeclName( BBDebugDecl * decl ){
  43. return decl->name;
  44. }
  45. const char * bbDebugDeclType( BBDebugDecl * decl ){
  46. return decl->type_tag;
  47. }
  48. BBString * bbDebugDeclConstValue( BBDebugDecl * decl ){
  49. return decl->const_value;
  50. }
  51. int bbDebugDeclFieldOffset( BBDebugDecl * decl ){
  52. return decl->field_offset;
  53. }
  54. void * bbDebugDeclVarAddress( BBDebugDecl * decl ){
  55. return decl->var_address;
  56. }
  57. BBDebugDecl * bbDebugDeclNext( BBDebugDecl * decl ){
  58. return decl + 1;
  59. }
  60. //Note: arrDims must be 1D int array...
  61. BBArray *bbRefArrayCreate( const char *type,BBArray *arrDims ){
  62. // assert( arrDims->dims==1 );
  63. // assert( arrDims->type[0]=='i' );
  64. int dims=arrDims->scales[0];
  65. int *lens=(int*)BBARRAYDATA( arrDims,1 );
  66. return bbArrayNewEx( type,dims,lens );
  67. }
  68. BBString *bbRefArrayTypeTag( BBArray *array ){
  69. return bbStringFromCString( array->type );
  70. }
  71. BBObject *bbRefGetObject( BBObject **p ){
  72. return *p;
  73. }
  74. void bbRefPushObject( BBObject **p,BBObject *t ){
  75. *p=t;
  76. }
  77. void bbRefInitObject( BBObject **p,BBObject *t ){
  78. *p=t;
  79. }
  80. void bbRefAssignObject( BBObject **p,BBObject *t ){
  81. *p=t;
  82. }
  83. BBClass *bbRefGetObjectClass( BBObject *p ){
  84. return p->clas;
  85. }
  86. BBClass *bbRefGetSuperClass( BBClass *clas ){
  87. return clas->super;
  88. }
  89. BBString * bbStringFromRef(void * ref) {
  90. return (BBString*)ref;
  91. }
  92. BBArray * bbRefArrayNull() {
  93. return &bbEmptyArray;
  94. }
  95. const char * bbInterfaceName(BBInterface * ifc) {
  96. return ifc->clas->debug_scope->name;
  97. }
  98. BBClass * bbInterfaceClass(BBInterface * ifc) {
  99. return ifc->clas;
  100. }
  101. int bbObjectImplementsInterfaces(BBClass *clas) {
  102. return clas->itable != 0;
  103. }
  104. int bbObjectImplementedCount(BBClass *clas) {
  105. return clas->itable->ifc_size;
  106. }
  107. BBInterface * bbObjectImplementedInterface(BBClass * clas, int index) {
  108. return clas->itable->ifc_offsets[index].ifc;
  109. }