Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_value_annotated.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 annotated
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 
15 #include "afw_internal.h"
16 
17 #define impl_afw_value_optional_release NULL
18 #define impl_afw_value_get_reference NULL
19 
20 #define impl_afw_value_get_evaluated_meta \
21  afw_value_internal_get_evaluated_meta_default
22 
23 #define impl_afw_value_get_evaluated_metas \
24  afw_value_internal_get_evaluated_metas_default
25 
26 /* Declares and rti/inf defines for interface afw_value */
27 #define AFW_IMPLEMENTATION_ID "annotated"
28 #define AFW_IMPLEMENTATION_INF_SPECIFIER AFW_DEFINE_CONST_DATA
29 #define AFW_IMPLEMENTATION_INF_LABEL afw_value_annotated_inf
31 
32 
33 /* Allocate function for annotation value. */
36  const afw_pool_t *p,
37  afw_xctx_t *xctx)
38 {
39  afw_value_annotated_t *result;
40 
42  result->inf = &afw_value_annotated_inf;
43 
44  return result;
45 }
46 
47 
48 
49 /* Create function for annotated value. */
50 AFW_DEFINE(const afw_value_t *)
52  const afw_compile_value_contextual_t *contextual,
53  const afw_value_t *value,
54  const afw_object_t *annotation,
55  const afw_pool_t *p,
56  afw_xctx_t *xctx)
57 {
58  afw_value_annotated_t *result;
59 
61  result->inf = &afw_value_annotated_inf;
62  result->contextual = contextual;
63  result->value = value;
64  result->annotation = annotation;
65 
66  return (const afw_value_t *)result;
67 }
68 
69 
70 
71 /*
72  * Implementation of method optional_evaluate for interface afw_value.
73  */
74 const afw_value_t *
76  const afw_value_t * instance,
77  const afw_pool_t * p,
78  afw_xctx_t *xctx)
79 {
80  const afw_value_annotated_t *self = (const afw_value_annotated_t *)instance;
81  const afw_value_t *result;
82 
83  /* Push value on evaluation stack. */
85 
87  result = afw_value_evaluate(self->value, p, xctx);
88 
89  /* Pop value from evaluation stack and return result. */
91  return result;
92 }
93 
94 /*
95  * Implementation of method get_data_type for interface afw_value.
96  */
97 const afw_data_type_t *
98 impl_afw_value_get_data_type(
99  const afw_value_t * instance,
100  afw_xctx_t *xctx)
101 {
102  return NULL;
103 }
104 
105 /*
106  * Implementation of method get_evaluated_data_type for interface afw_value.
107  */
108 const afw_data_type_t *
109 impl_afw_value_get_evaluated_data_type(
110  const afw_value_t * instance,
111  afw_xctx_t *xctx)
112 {
113  return NULL;
114 }
115 
116 /*
117  * Implementation of method get_evaluated_data_type_parameter for interface
118  * afw_value.
119  */
120 const afw_utf8_t *
121 impl_afw_value_get_evaluated_data_type_parameter(
122  const afw_value_t * instance,
123  afw_xctx_t *xctx)
124 {
125  return NULL;
126 }
127 
128 
129 /*
130  * Implementation of method compiler_listing for interface afw_value.
131  */
132 void
133 impl_afw_value_produce_compiler_listing(
134  const afw_value_t *instance,
135  const afw_writer_t *writer,
136  afw_xctx_t *xctx)
137 {
138  const afw_value_annotated_t *self =
139  (const afw_value_annotated_t *)instance;
140  afw_value_object_t annotation;
141 
142  if (self->annotation) {
143  afw_value_compiler_listing_begin_value(writer, instance, NULL, xctx);
144  afw_writer_write_z(writer, ": [", xctx);
145  afw_writer_write_eol(writer, xctx);
146  afw_writer_increment_indent(writer, xctx);
147 
148  annotation.inf = &afw_value_evaluated_object_inf;
149  annotation.internal = self->annotation;
150 
151  afw_value_produce_compiler_listing((const afw_value_t *)&annotation, writer, xctx);
152  afw_value_produce_compiler_listing(self->value, writer, xctx);
153 
154  afw_writer_decrement_indent(writer, xctx);
155  afw_writer_write_z(writer, "]", xctx);
156  afw_writer_write_eol(writer, xctx);
157  }
158  else {
159  afw_value_produce_compiler_listing(self->value, writer, xctx);
160  }
161 }
162 
163 /*
164  * Implementation of method decompile for interface afw_value.
165  */
166 void
167 impl_afw_value_decompile(
168  const afw_value_t * instance,
169  const afw_writer_t * writer,
170  afw_xctx_t *xctx)
171 {
172  const afw_value_annotated_t *self =
173  (const afw_value_annotated_t *)instance;
174  afw_value_object_t annotation;
175 
176  if (self->annotation) {
177  afw_writer_write_z(writer, "annotate(", xctx);
178  if (writer->tab) {
179  afw_writer_write_eol(writer, xctx);
180  afw_writer_increment_indent(writer, xctx);
181  }
182  annotation.inf = &afw_value_evaluated_object_inf;
183  annotation.internal = self->annotation;
184  afw_value_decompile((const afw_value_t *)&annotation, writer, xctx);
185  afw_writer_write_z(writer, ",", xctx);
186  if (writer->tab) {
187  afw_writer_write_eol(writer, xctx);
188  }
189  afw_value_decompile(self->value, writer, xctx);
190  if (writer->tab) {
191  afw_writer_write_eol(writer, xctx);
192  afw_writer_decrement_indent(writer, xctx);
193  }
194  afw_writer_write_z(writer, ")", xctx);
195  }
196  else {
197  afw_value_decompile(self->value, writer, xctx);
198  }
199 }
200 
201 /*
202  * Implementation of method get_info for interface afw_value.
203  */
204 void
205 impl_afw_value_get_info(
206  const afw_value_t *instance,
207  afw_value_info_t *info,
208  const afw_pool_t *p,
209  afw_xctx_t *xctx)
210 {
211  const afw_value_annotated_t *self =
212  (const afw_value_annotated_t *)instance;
213 
214  afw_memory_clear(info);
215  info->value_inf_id = &instance->inf->rti.implementation_id;
216  info->contextual = self->contextual;
217 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
Interface afw_interface implementation declares.
afw_value_evaluated_object_inf
Unmanaged evaluated value inf for data type object.
#define afw_memory_clear(to)
Clear preallocated memory for sizeof(*(to)).
Definition: afw_memory.h:47
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
Definition: afw_pool.h:167
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_produce_compiler_listing(instance, writer, xctx)
Call method produce_compiler_listing of interface afw_value.
#define afw_value_decompile(instance, writer, xctx)
Call method decompile of interface afw_value.
#define afw_value_evaluate(value, p, xctx)
Evaluate value if needed using specific pool.
Definition: afw_value.h:841
afw_value_annotated_create(const afw_compile_value_contextual_t *contextual, const afw_value_t *value, const afw_object_t *annotation, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for annotated value.
afw_value_annotated_inf
Value annotated inf.
Definition: afw_value.h:219
afw_value_annotation_allocate(const afw_pool_t *p, afw_xctx_t *xctx)
Allocate function for annotation value.
#define afw_writer_increment_indent(instance, xctx)
Call method increment_indent of interface afw_writer.
#define afw_writer_write_eol(instance, xctx)
Call method write_eol of interface afw_writer.
#define afw_writer_decrement_indent(instance, xctx)
Call method decrement_indent of interface afw_writer.
#define afw_writer_write_z(writer, s_z, xctx)
Call afw_writer_write() with zero terminated string.
Definition: afw_writer.h:35
#define afw_xctx_evaluation_stack_push_value(VALUE, xctx)
Push VALUE onto execution stack.
Definition: afw_xctx.h:78
#define afw_xctx_evaluation_stack_pop_parameter_number(xctx)
Pop top PARAMETER_NUMBER off execution stack.
Definition: afw_xctx.h:124
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 for annotated value.
Filled in by afw_value get_info method.
Definition: afw_value.h:49
struct for data type object values.
Interface afw_value public struct.
Interface afw_writer public struct.
Interface afw_xctx public struct.