laurent@219: #ifndef __ACCESSOR_H laurent@219: #define __ACCESSOR_H laurent@219: laurent@377: #define __INITIAL_VALUE(...) __VA_ARGS__ laurent@221: laurent@219: // variable declaration macros laurent@219: #define __DECLARE_VAR(type, name)\ laurent@221: __IEC_##type##_t name; laurent@392: #define __DECLARE_GLOBAL(type, domain, name)\ laurent@392: __IEC_##type##_t domain##__##name;\ laurent@392: static __IEC_##type##_t *GLOBAL__##name = &(domain##__##name);\ laurent@242: void __INIT_GLOBAL_##name(type value) {\ laurent@242: (*GLOBAL__##name).value = value;\ laurent@242: }\ laurent@392: IEC_BYTE __IS_GLOBAL_##name##_FORCED(void) {\ laurent@392: return (*GLOBAL__##name).flags & __IEC_FORCE_FLAG;\ laurent@242: }\ laurent@242: type* __GET_GLOBAL_##name(void) {\ laurent@242: return &((*GLOBAL__##name).value);\ laurent@231: } Laurent@706: #define __DECLARE_GLOBAL_FB(type, domain, name)\ Laurent@706: type domain##__##name;\ Laurent@706: static type *GLOBAL__##name = &(domain##__##name);\ Laurent@706: type* __GET_GLOBAL_##name(void) {\ Laurent@706: return &(*GLOBAL__##name);\ Laurent@708: }\ Laurent@708: extern void type##_init__(type* data__, BOOL retain); laurent@219: #define __DECLARE_GLOBAL_LOCATION(type, location)\ laurent@219: extern type *location; laurent@219: #define __DECLARE_GLOBAL_LOCATED(type, resource, name)\ laurent@221: __IEC_##type##_p resource##__##name;\ laurent@392: static __IEC_##type##_p *GLOBAL__##name = &(resource##__##name);\ laurent@242: void __INIT_GLOBAL_##name(type value) {\ laurent@242: *((*GLOBAL__##name).value) = value;\ laurent@242: }\ laurent@392: IEC_BYTE __IS_GLOBAL_##name##_FORCED(void) {\ laurent@392: return (*GLOBAL__##name).flags & __IEC_FORCE_FLAG;\ laurent@242: }\ laurent@242: type* __GET_GLOBAL_##name(void) {\ laurent@242: return (*GLOBAL__##name).value;\ laurent@242: } laurent@396: #define __DECLARE_GLOBAL_PROTOTYPE(type, name)\ Laurent@713: extern type* __GET_GLOBAL_##name(void); laurent@219: #define __DECLARE_EXTERNAL(type, name)\ laurent@221: __IEC_##type##_p name; Laurent@706: #define __DECLARE_EXTERNAL_FB(type, name)\ Laurent@706: type* name; laurent@219: #define __DECLARE_LOCATED(type, name)\ laurent@221: __IEC_##type##_p name; laurent@219: laurent@219: laurent@219: // variable initialization macros laurent@225: #define __INIT_RETAIN(name, retained)\ laurent@227: name.flags |= retained?__IEC_RETAIN_FLAG:0; laurent@221: #define __INIT_VAR(name, initial, retained)\ laurent@225: name.value = initial;\ laurent@225: __INIT_RETAIN(name, retained) laurent@377: #define __INIT_GLOBAL(type, name, initial, retained)\ laurent@377: {\ beltyukov@1051: type temp = initial;\ laurent@377: __INIT_GLOBAL_##name(temp);\ laurent@377: __INIT_RETAIN((*GLOBAL__##name), retained)\ laurent@377: } Laurent@706: #define __INIT_GLOBAL_FB(type, name, retained)\ Laurent@706: type##_init__(&(*GLOBAL__##name), retained); laurent@392: #define __INIT_GLOBAL_LOCATED(domain, name, location, retained)\ laurent@392: domain##__##name.value = location;\ laurent@392: __INIT_RETAIN(domain##__##name, retained) laurent@221: #define __INIT_EXTERNAL(type, global, name, retained)\ laurent@392: {\ laurent@392: name.value = __GET_GLOBAL_##global();\ laurent@392: __INIT_RETAIN(name, retained)\ laurent@392: } Laurent@706: #define __INIT_EXTERNAL_FB(type, global, name, retained)\ Laurent@706: name = __GET_GLOBAL_##global(); laurent@221: #define __INIT_LOCATED(type, location, name, retained)\ laurent@392: {\ laurent@392: extern type *location;\ laurent@392: name.value = location;\ laurent@392: __INIT_RETAIN(name, retained)\ laurent@392: } laurent@219: #define __INIT_LOCATED_VALUE(name, initial)\ laurent@221: *(name.value) = initial; laurent@219: laurent@219: laurent@219: // variable getting macros laurent@221: #define __GET_VAR(name, ...)\ laurent@221: name.value __VA_ARGS__ laurent@225: #define __GET_EXTERNAL(name, ...)\ Edouard@1096: ((*(name.value)) __VA_ARGS__) Laurent@706: #define __GET_EXTERNAL_FB(name, ...)\ Laurent@706: __GET_VAR(((*name) __VA_ARGS__)) laurent@225: #define __GET_LOCATED(name, ...)\ Edouard@1096: ((*(name.value)) __VA_ARGS__) mjsousa@873: laurent@235: #define __GET_VAR_BY_REF(name, ...)\ Edouard@1096: (&(name.value __VA_ARGS__)) laurent@235: #define __GET_EXTERNAL_BY_REF(name, ...)\ Edouard@1096: (&((*(name.value)) __VA_ARGS__)) Laurent@706: #define __GET_EXTERNAL_FB_BY_REF(name, ...)\ Laurent@706: __GET_EXTERNAL_BY_REF(((*name) __VA_ARGS__)) laurent@235: #define __GET_LOCATED_BY_REF(name, ...)\ Edouard@1096: (&((*(name.value)) __VA_ARGS__)) laurent@219: mjsousa@873: #define __GET_VAR_REF(name, ...)\ mjsousa@873: (&(name.value __VA_ARGS__)) mjsousa@873: #define __GET_EXTERNAL_REF(name, ...)\ mjsousa@873: (&((*(name.value)) __VA_ARGS__)) mjsousa@873: #define __GET_EXTERNAL_FB_REF(name, ...)\ mjsousa@873: (&(__GET_VAR(((*name) __VA_ARGS__)))) mjsousa@873: #define __GET_LOCATED_REF(name, ...)\ mjsousa@873: (&((*(name.value)) __VA_ARGS__)) mjsousa@873: mjsousa@933: #define __GET_VAR_DREF(name, ...)\ mjsousa@933: (*(name.value __VA_ARGS__)) mjsousa@933: #define __GET_EXTERNAL_DREF(name, ...)\ mjsousa@933: (*((*(name.value)) __VA_ARGS__)) mjsousa@933: #define __GET_EXTERNAL_FB_DREF(name, ...)\ mjsousa@933: (*(__GET_VAR(((*name) __VA_ARGS__)))) mjsousa@933: #define __GET_LOCATED_DREF(name, ...)\ mjsousa@933: (*((*(name.value)) __VA_ARGS__)) mjsousa@933: mjsousa@873: laurent@219: // variable setting macros mjsousa@885: #define __SET_VAR(prefix, name, suffix, new_value)\ mjsousa@885: if (!(prefix name.flags & __IEC_FORCE_FLAG)) prefix name.value suffix = new_value mjsousa@885: #define __SET_EXTERNAL(prefix, name, suffix, new_value)\ andrej@1006: {extern IEC_BYTE __IS_GLOBAL_##name##_FORCED(void);\ Laurent@817: if (!(prefix name.flags & __IEC_FORCE_FLAG || __IS_GLOBAL_##name##_FORCED()))\ mjsousa@885: (*(prefix name.value)) suffix = new_value;} mjsousa@885: #define __SET_EXTERNAL_FB(prefix, name, suffix, new_value)\ Edouard@1095: __SET_VAR(prefix, name, suffix, new_value) mjsousa@885: #define __SET_LOCATED(prefix, name, suffix, new_value)\ mjsousa@885: if (!(prefix name.flags & __IEC_FORCE_FLAG)) *(prefix name.value) suffix = new_value laurent@219: laurent@219: #endif //__ACCESSOR_H