| 1 |
#ifndef RBIMPL_RCLASS_H /*-*-C++-*-vi:se ft=cpp:*/ |
| 2 |
#define RBIMPL_RCLASS_H |
| 3 |
/** |
| 4 |
* @file |
| 5 |
* @author Ruby developers <[email protected]> |
| 6 |
* @copyright This file is a part of the programming language Ruby. |
| 7 |
* Permission is hereby granted, to either redistribute and/or |
| 8 |
* modify this file, provided that the conditions mentioned in the |
| 9 |
* file COPYING are met. Consult the file for details. |
| 10 |
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are |
| 11 |
* implementation details. Don't take them as canon. They could |
| 12 |
* rapidly appear then vanish. The name (path) of this header file |
| 13 |
* is also an implementation detail. Do not expect it to persist |
| 14 |
* at the place it is now. Developers are free to move it anywhere |
| 15 |
* anytime at will. |
| 16 |
* @note To ruby-core: remember that this header can be possibly |
| 17 |
* recursively included from extension libraries written in C++. |
| 18 |
* Do not expect for instance `__VA_ARGS__` is always available. |
| 19 |
* We assume C99 for ruby itself but we don't assume languages of |
| 20 |
* extension libraries. They could be written in C++98. |
| 21 |
* @brief Routines to manipulate struct RClass. |
| 22 |
* @note The struct RClass itself is opaque. |
| 23 |
*/ |
| 24 |
#include "ruby/internal/dllexport.h" |
| 25 |
#include "ruby/internal/value.h" |
| 26 |
#include "ruby/internal/cast.h" |
| 27 |
|
| 28 |
/** @cond INTERNAL_MACRO */ |
| 29 |
#define RMODULE_IS_REFINEMENT RMODULE_IS_REFINEMENT |
| 30 |
/** @endcond */ |
| 31 |
|
| 32 |
/** |
| 33 |
* Convenient casting macro. |
| 34 |
* |
| 35 |
* @param obj An object, which is in fact an RClass. |
| 36 |
* @return The passed object casted to RClass. |
| 37 |
*/ |
| 38 |
#define RCLASS(obj) RBIMPL_CAST((struct RClass *)(obj)) |
| 39 |
|
| 40 |
/** @alias{RCLASS} */ |
| 41 |
#define RMODULE RCLASS |
| 42 |
|
| 43 |
/** @alias{rb_class_get_superclass} */ |
| 44 |
#define RCLASS_SUPER rb_class_get_superclass |
| 45 |
|
| 46 |
/** |
| 47 |
* @private |
| 48 |
* |
| 49 |
* Bits that you can set to ::RBasic::flags. |
| 50 |
* |
| 51 |
* @internal |
| 52 |
* |
| 53 |
* Why is it here, given RClass itself is not? |
| 54 |
*/ |
| 55 |
enum ruby_rmodule_flags { |
| 56 |
/** |
| 57 |
* This flag has something to do with refinements. A module created using |
| 58 |
* rb_mod_refine() has this flag set. This is the bit which controls |
| 59 |
* difference between normal inclusion versus refinements. |
| 60 |
*/ |
| 61 |
RMODULE_IS_REFINEMENT = RUBY_FL_USER3 |
| 62 |
}; |
| 63 |
|
| 64 |
struct RClass; /* Opaque, declared here for RCLASS() macro. */ |
| 65 |
|
| 66 |
RBIMPL_SYMBOL_EXPORT_BEGIN() |
| 67 |
/** |
| 68 |
* Returns the superclass of a class. |
| 69 |
* @param[in] klass An object of RClass. |
| 70 |
* @retval RUBY_Qfalse `klass` has no super class. |
| 71 |
* @retval otherwise Raw superclass of `klass` |
| 72 |
* @see rb_class_superclass |
| 73 |
* |
| 74 |
* ### Q&A ### |
| 75 |
* |
| 76 |
* - Q: How can a class have no super class? |
| 77 |
* |
| 78 |
* - A: `klass` could be a module. Or it could be ::rb_cBasicObject. |
| 79 |
* |
| 80 |
* - Q: What do you mean by "raw" superclass? |
| 81 |
* |
| 82 |
* - A: This is a really good question. The answer is that this function |
| 83 |
* returns something different from what you would normally expect. On |
| 84 |
* occasions ruby inserts hidden classes in a hierarchy of class |
| 85 |
* inheritance behind-the-scene. Such classes are called "iclass"es and |
| 86 |
* distinguished using ::RUBY_T_ICLASS in C level. They are truly |
| 87 |
* transparent from Ruby level but can be accessed from C, by using this |
| 88 |
* API. |
| 89 |
*/ |
| 90 |
VALUE rb_class_get_superclass(VALUE klass); |
| 91 |
RBIMPL_SYMBOL_EXPORT_END() |
| 92 |
|
| 93 |
#endif /* RBIMPL_RCLASS_H */ |