Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_value_object_expression.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Interface afw_value Implementation for Object Expression
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 #define impl_afw_value_optional_release NULL
18 #define impl_afw_value_get_reference NULL
19 
20 
21 #define impl_afw_value_get_evaluated_meta \
22  afw_value_internal_get_evaluated_meta_for_object
23 
24 #define impl_afw_value_get_evaluated_metas \
25  afw_value_internal_get_evaluated_metas_for_object
26 
27 /* Declares and rti/inf defines for interface afw_value */
28 #define AFW_IMPLEMENTATION_ID "object_expression"
29 #define AFW_IMPLEMENTATION_INF_SPECIFIER AFW_DEFINE_CONST_DATA
30 #define AFW_IMPLEMENTATION_INF_LABEL afw_value_object_expression_inf
32 
33 
37 /* Create function for object expression value. */
38 AFW_DEFINE(const afw_value_t *)
40  const afw_compile_value_contextual_t *contextual,
41  const afw_object_t * internal,
42  const afw_pool_t *p, afw_xctx_t *xctx)
43 {
45 
47  xctx);
49  self->internal = internal;
50  return (const afw_value_t *)self;
51 }
52 
53 /*
54  * Implementation of method optional_evaluate for interface afw_value.
55  */
56 const afw_value_t *
58  const afw_value_t * instance,
59  const afw_pool_t * p,
60  afw_xctx_t *xctx)
61 {
62  const afw_object_t *from;
63  const afw_object_t *to;
64  const afw_value_t *v;
65  const afw_iterator_t *iterator;
66  const afw_utf8_t *property_name;
67 
68  from = ((const afw_value_object_expression_t *)instance)->internal;
69  to = afw_object_create(p, xctx);
70 
71  for (iterator = NULL;;) {
72  v = afw_object_get_next_property(from, &iterator, &property_name,
73  xctx);
74  if (!v) {
75  break;
76  }
77  v = afw_value_evaluate(v, p, xctx);
78  afw_object_set_property(to, property_name, v, xctx);
79  }
80 
81  return afw_value_create_object(to, p, xctx);
82 }
83 
84 /*
85  * Implementation of method get_data_type for interface afw_value.
86  */
87 const afw_data_type_t *
88 impl_afw_value_get_data_type(
89  const afw_value_t *instance,
90  afw_xctx_t *xctx)
91 {
92  return afw_data_type_object;
93 }
94 
95 /*
96  * Implementation of method get_evaluated_data_type for interface afw_value.
97  */
98 const afw_data_type_t *
99 impl_afw_value_get_evaluated_data_type(
100  const afw_value_t *instance,
101  afw_xctx_t *xctx)
102 {
103  return afw_data_type_object;
104 }
105 
106 /*
107  * Implementation of method get_evaluated_data_type_parameter for interface
108  * afw_value.
109  */
110 const afw_utf8_t *
111 impl_afw_value_get_evaluated_data_type_parameter(
112  const afw_value_t *instance,
113  afw_xctx_t *xctx)
114 {
115  return NULL;
116 }
117 
118 /*
119  * Implementation of method compiler_listing for interface afw_value.
120  */
121 void
122 impl_afw_value_produce_compiler_listing(
123  const afw_value_t *instance,
124  const afw_writer_t *writer,
125  afw_xctx_t *xctx)
126 {
129  writer, instance, xctx);
130 }
131 
132 /*
133  * Implementation of method decompile for interface afw_value.
134  */
135 void
136 impl_afw_value_decompile(
137  const afw_value_t *instance,
138  const afw_writer_t *writer,
139  afw_xctx_t *xctx)
140 {
143  writer,
144  (const void *)&(((const afw_value_evaluated_t *)instance)->internal),
145  xctx);
146 }
147 
148 /*
149  * Implementation of method get_info for interface afw_value.
150  */
151 void
152 impl_afw_value_get_info(
153  const afw_value_t *instance,
154  afw_value_info_t *info,
155  const afw_pool_t *p,
156  afw_xctx_t *xctx)
157 {
158  const afw_value_object_expression_t *self =
159  (const afw_value_object_expression_t *)instance;
160 
161  afw_memory_clear(info);
162  info->value_inf_id = &instance->inf->rti.implementation_id;
163  info->contextual = self->contextual;
164 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
Interface afw_interface implementation declares.
afw_data_type_object
Data type struct for object.
afw_value_create_object(const afw_object_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type object value.
struct afw_iterator_s afw_iterator_t
#define afw_data_type_value_compiler_listing(instance, writer, value, xctx)
Call method value_compiler_listing of interface afw_data_type.
#define afw_data_type_write_as_expression(instance, writer, from_internal, xctx)
Call method write_as_expression of interface afw_data_type.
#define afw_memory_clear(to)
Clear preallocated memory for sizeof(*(to)).
Definition: afw_memory.h:47
#define afw_object_get_next_property(instance, iterator, property_name, xctx)
Call method get_next_property of interface afw_object.
#define afw_object_create(p, xctx)
Create an empty unmanaged object in memory.
Definition: afw_object.h:948
afw_object_set_property(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_value_t *value, afw_xctx_t *xctx)
Set the value of an object's property.
Definition: afw_object.c:46
#define afw_pool_calloc(instance, size, xctx)
Call method calloc of interface afw_pool.
const afw_value_t * impl_afw_value_optional_evaluate(const afw_value_t *instance, const afw_pool_t *p, afw_xctx_t *xctx)
#define afw_value_evaluate(value, p, xctx)
Evaluate value if needed using specific pool.
Definition: afw_value.h:841
afw_value_object_expression_inf
Value object expression inf.
Definition: afw_value.h:285
afw_value_create_object_expression(const afw_compile_value_contextual_t *contextual, const afw_object_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for object expression value.
Contextual information provided in some values.
Interface afw_data_type public struct.
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Struct to access internal of all evaluated values.
Definition: afw_value.h:60
Filled in by afw_value get_info method.
Definition: afw_value.h:49
struct for object expression value.
Interface afw_value public struct.
Interface afw_writer public struct.
Interface afw_xctx public struct.