4 #define __INITIAL_VALUE(...) __VA_ARGS__ |
4 #define __INITIAL_VALUE(...) __VA_ARGS__ |
5 |
5 |
6 // variable declaration macros |
6 // variable declaration macros |
7 #define __DECLARE_VAR(type, name)\ |
7 #define __DECLARE_VAR(type, name)\ |
8 __IEC_##type##_t name; |
8 __IEC_##type##_t name; |
9 #define __DECLARE_GLOBAL(type, resource, name)\ |
9 #define __DECLARE_GLOBAL(type, domain, name)\ |
10 __IEC_##type##_t resource##__##name;\ |
10 __IEC_##type##_t domain##__##name;\ |
11 static __IEC_##type##_t *GLOBAL__##name = &resource##__##name;\ |
11 static __IEC_##type##_t *GLOBAL__##name = &(domain##__##name);\ |
12 void __INIT_GLOBAL_##name(type value) {\ |
12 void __INIT_GLOBAL_##name(type value) {\ |
13 (*GLOBAL__##name).value = value;\ |
13 (*GLOBAL__##name).value = value;\ |
14 }\ |
14 }\ |
15 void __SET_GLOBAL_##name(type value) {\ |
15 IEC_BYTE __IS_GLOBAL_##name##_FORCED(void) {\ |
16 if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\ |
16 return (*GLOBAL__##name).flags & __IEC_FORCE_FLAG;\ |
17 (*GLOBAL__##name).value = value;\ |
|
18 }\ |
17 }\ |
19 type* __GET_GLOBAL_##name(void) {\ |
18 type* __GET_GLOBAL_##name(void) {\ |
20 return &((*GLOBAL__##name).value);\ |
19 return &((*GLOBAL__##name).value);\ |
21 } |
20 } |
22 #define __DECLARE_GLOBAL_LOCATION(type, location)\ |
21 #define __DECLARE_GLOBAL_LOCATION(type, location)\ |
23 extern type *location; |
22 extern type *location; |
24 #define __DECLARE_GLOBAL_LOCATED(type, resource, name)\ |
23 #define __DECLARE_GLOBAL_LOCATED(type, resource, name)\ |
25 __IEC_##type##_p resource##__##name;\ |
24 __IEC_##type##_p resource##__##name;\ |
26 static __IEC_##type##_p *GLOBAL__##name = &resource##__##name;\ |
25 static __IEC_##type##_p *GLOBAL__##name = &(resource##__##name);\ |
27 void __INIT_GLOBAL_##name(type value) {\ |
26 void __INIT_GLOBAL_##name(type value) {\ |
28 *((*GLOBAL__##name).value) = value;\ |
27 *((*GLOBAL__##name).value) = value;\ |
29 }\ |
28 }\ |
30 void __SET_GLOBAL_##name(type value) {\ |
29 IEC_BYTE __IS_GLOBAL_##name##_FORCED(void) {\ |
31 if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\ |
30 return (*GLOBAL__##name).flags & __IEC_FORCE_FLAG;\ |
32 *((*GLOBAL__##name).value) = value;\ |
|
33 }\ |
31 }\ |
34 type* __GET_GLOBAL_##name(void) {\ |
32 type* __GET_GLOBAL_##name(void) {\ |
35 return (*GLOBAL__##name).value;\ |
33 return (*GLOBAL__##name).value;\ |
36 } |
34 } |
37 #define __DECLARE_EXTERNAL(type, name)\ |
35 #define __DECLARE_EXTERNAL(type, name)\ |
50 {\ |
48 {\ |
51 static const type temp = initial;\ |
49 static const type temp = initial;\ |
52 __INIT_GLOBAL_##name(temp);\ |
50 __INIT_GLOBAL_##name(temp);\ |
53 __INIT_RETAIN((*GLOBAL__##name), retained)\ |
51 __INIT_RETAIN((*GLOBAL__##name), retained)\ |
54 } |
52 } |
55 #define __INIT_GLOBAL_LOCATED(resource, name, location, retained)\ |
53 #define __INIT_GLOBAL_LOCATED(domain, name, location, retained)\ |
56 resource##__##name.value = location;\ |
54 domain##__##name.value = location;\ |
57 __INIT_RETAIN(resource##__##name, retained) |
55 __INIT_RETAIN(domain##__##name, retained) |
58 #define __INIT_EXTERNAL(type, global, name, retained)\ |
56 #define __INIT_EXTERNAL(type, global, name, retained)\ |
59 name.value = __GET_GLOBAL_##global();\ |
57 {\ |
60 __INIT_RETAIN(name, retained) |
58 extern type* __GET_GLOBAL_##global();\ |
|
59 name.value = __GET_GLOBAL_##global();\ |
|
60 __INIT_RETAIN(name, retained)\ |
|
61 } |
61 #define __INIT_LOCATED(type, location, name, retained)\ |
62 #define __INIT_LOCATED(type, location, name, retained)\ |
62 {extern type *location;\ |
63 {\ |
63 name.value = location;\ |
64 extern type *location;\ |
64 __INIT_RETAIN(name, retained)} |
65 name.value = location;\ |
|
66 __INIT_RETAIN(name, retained)\ |
|
67 } |
65 #define __INIT_LOCATED_VALUE(name, initial)\ |
68 #define __INIT_LOCATED_VALUE(name, initial)\ |
66 *(name.value) = initial; |
69 *(name.value) = initial; |
67 |
70 |
68 |
71 |
69 // variable getting macros |
72 // variable getting macros |
79 ((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__)) |
82 ((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__)) |
80 #define __GET_LOCATED_BY_REF(name, ...)\ |
83 #define __GET_LOCATED_BY_REF(name, ...)\ |
81 ((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__)) |
84 ((name.flags & __IEC_FORCE_FLAG) ? &(name.fvalue __VA_ARGS__) : &(*(name.value) __VA_ARGS__)) |
82 |
85 |
83 // variable setting macros |
86 // variable setting macros |
84 #define __SET_VAR(name, new_value, ...)\ |
87 #define __SET_VAR(prefix, name, new_value, ...)\ |
85 if (!(name.flags & __IEC_FORCE_FLAG)) name.value __VA_ARGS__ = new_value |
88 if (!(prefix name.flags & __IEC_FORCE_FLAG)) prefix name.value __VA_ARGS__ = new_value |
86 #define __SET_EXTERNAL(global, name, new_value)\ |
89 #define __SET_EXTERNAL(prefix, name, new_value, ...)\ |
87 if (!(name.flags & __IEC_FORCE_FLAG))\ |
90 if (!(prefix name.flags & __IEC_FORCE_FLAG || __IS_GLOBAL_##name##_FORCED()))\ |
88 __SET_GLOBAL_##global(new_value) |
91 (*(prefix name.value)) __VA_ARGS__ = new_value |
89 #define __SET_COMPLEX_EXTERNAL(name, new_value, ...)\ |
92 #define __SET_LOCATED(prefix, name, new_value, ...)\ |
90 *(name.value) __VA_ARGS__ = new_value |
93 if (!(prefix name.flags & __IEC_FORCE_FLAG)) *(prefix name.value) __VA_ARGS__ = new_value |
91 #define __SET_LOCATED(name, new_value, ...)\ |
|
92 if (!(name.flags & __IEC_FORCE_FLAG)) *(name.value) __VA_ARGS__ = new_value |
|
93 |
94 |
94 #endif //__ACCESSOR_H |
95 #endif //__ACCESSOR_H |