Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_value_qualified_variable_reference.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 Variable Reference
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 
15 #include "afw_internal.h"
16 
17 
18 #define impl_afw_value_optional_release NULL
19 #define impl_afw_value_get_reference NULL
20 
21 
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 "qualified_variable_reference"
28 #define AFW_IMPLEMENTATION_INF_SPECIFIER AFW_DEFINE_CONST_DATA
29 #define AFW_IMPLEMENTATION_INF_LABEL afw_value_qualified_variable_reference_inf
31 
32 
33 /* Create function for variable reference value. */
34 AFW_DEFINE(const afw_value_t *)
36  const afw_compile_value_contextual_t *contextual,
37  const afw_utf8_t *qualifier,
38  const afw_utf8_t *name,
39  const afw_pool_t *p,
40  afw_xctx_t *xctx)
41 {
45  result->contextual = contextual;
46  memcpy(&result->name, name, sizeof(afw_utf8_t));
47  if (qualifier) {
48  memcpy(&result->qualifier, qualifier, sizeof(afw_utf8_t));
49  result->optionally_qualified_name = afw_utf8_concat(p, xctx,
50  &result->qualifier, &afw_s_a_qualification_operator, &result->name,
51  NULL);
52  }
53  else {
54  result->optionally_qualified_name = &result->name;
55  }
56  result->backtrace_detail = result->optionally_qualified_name;
57 
58  return (afw_value_t *)result;
59 }
60 
61 
62 /*
63  * Implementation of method optional_evaluate for interface afw_value.
64  */
65 const afw_value_t *
67  const afw_value_t * instance,
68  const afw_pool_t * p,
69  afw_xctx_t *xctx)
70 {
73  const afw_value_t *result;
74  const afw_compile_value_contextual_t *saved_contextual;
75 
76  /* Push value on evaluation stack. */
78  saved_contextual = xctx->error->contextual;
79  xctx->error->contextual = self->contextual;
80 
81  /* Try to locate qualified variable. */
82  result = afw_xctx_get_qualified_variable(&self->qualifier, &self->name,
83  xctx);
84 
85  /* Pop value from evaluation stack and return result. */
87  xctx->error->contextual = saved_contextual;
88  return result;
89 }
90 
91 /*
92  * Implementation of method get_data_type for interface afw_value.
93  */
94 const afw_data_type_t *
95 impl_afw_value_get_data_type(
96  const afw_value_t * instance,
97  afw_xctx_t *xctx)
98 {
99  return NULL;
100 }
101 
102 /*
103  * Implementation of method get_evaluated_data_type for interface afw_value.
104  */
105 const afw_data_type_t *
106 impl_afw_value_get_evaluated_data_type(
107  const afw_value_t * instance,
108  afw_xctx_t *xctx)
109 {
110  return NULL;
111 }
112 
113 
114 /*
115  * Implementation of method get_evaluated_data_type_parameter for interface
116  * afw_value.
117  */
118 const afw_utf8_t *
119 impl_afw_value_get_evaluated_data_type_parameter(
120  const afw_value_t * instance,
121  afw_xctx_t *xctx)
122 {
123  return NULL;
124 }
125 
126 
127 /*
128  * Implementation of method get_evaluated_meta for interface afw_value.
129  */
130 const afw_value_t *
132  const afw_value_t *instance,
133  const afw_pool_t *p,
134  afw_xctx_t *xctx)
135 {
139 
140  meta = afw_value_internal_create_meta_object_self(
141  instance, p, xctx);
142  meta->key = self->optionally_qualified_name;
143  if (afw_value_is_object(meta->evaluated_value)) {
144  meta->additional =
145  (((const afw_value_object_t *)meta->evaluated_value)->
146  internal)->meta.meta_object;
147  }
148  return (const afw_value_t *)& meta->meta_object_value;
149 }
150 
151 
152 /*
153  * Implementation of method decompile for interface afw_value.
154  */
155 void
156 impl_afw_value_produce_compiler_listing(
157  const afw_value_t *instance,
158  const afw_writer_t *writer,
159  afw_xctx_t *xctx)
160 {
163 
164  afw_value_compiler_listing_begin_value(writer, instance,
165  self->contextual, xctx);
166  afw_writer_write_z(writer, " ", xctx);
167  if (self->qualifier.len > 0) {
168  afw_writer_write_utf8(writer, &self->qualifier, xctx);
169  afw_writer_write_z(writer, "::", xctx);
170  }
171  afw_writer_write_utf8(writer, &self->name, xctx);
172  afw_writer_write_eol(writer, xctx);
173 }
174 
175 
176 /*
177  * Implementation of method decompile for interface afw_value.
178  */
179 void
180 impl_afw_value_decompile(
181  const afw_value_t * instance,
182  const afw_writer_t * writer,
183  afw_xctx_t *xctx)
184 {
187 
188  if (self->qualifier.len > 0) {
189  afw_writer_write_utf8(writer, &self->qualifier, xctx);
190  afw_writer_write_z(writer, "::", xctx);
191  }
192  afw_writer_write_utf8(writer, &self->name, xctx);
193 
194 }
195 
196 
197 /*
198  * Implementation of method get_info for interface afw_value.
199  */
200 void
201 impl_afw_value_get_info(
202  const afw_value_t *instance,
203  afw_value_info_t *info,
204  const afw_pool_t *p,
205  afw_xctx_t *xctx)
206 {
209 
210  afw_memory_clear(info);
211  info->value_inf_id = &instance->inf->rti.implementation_id;
212  info->contextual = self->contextual;
213  info->detail = self->backtrace_detail;
214 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
Interface afw_interface implementation declares.
#define afw_value_is_object(A_VALUE)
Macro to determine if value is evaluated 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_utf8_t * afw_utf8_concat(const afw_pool_t *p, afw_xctx_t *xctx,...)
Concatenate strings with result in specifed pool.
const afw_value_t * impl_afw_value_get_evaluated_meta(const afw_value_t *instance, const afw_pool_t *p, afw_xctx_t *xctx)
const afw_value_t * impl_afw_value_optional_evaluate(const afw_value_t *instance, const afw_pool_t *p, afw_xctx_t *xctx)
afw_value_qualified_variable_reference_inf
Value qualified_variable_reference inf.
Definition: afw_value.h:291
afw_value_qualified_variable_reference_create(const afw_compile_value_contextual_t *contextual, const afw_utf8_t *qualifier, const afw_utf8_t *name, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for variable reference value.
#define afw_writer_write_eol(instance, xctx)
Call method write_eol 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_writer_write_utf8(writer, S, xctx)
Call afw_writer_write() with a afw_utf8_t string.
Definition: afw_writer.h:45
afw_xctx_get_qualified_variable(const afw_utf8_t *qualifier, const afw_utf8_t *name, afw_xctx_t *xctx)
Get a variable from xctx stack.
Definition: afw_xctx.c:176
#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_value(xctx)
Pop top VALUE off execution stack.
Definition: afw_xctx.h:113
Contextual information provided in some values.
Interface afw_data_type public struct.
const afw_compile_value_contextual_t * contextual
Contextual information or NULL.
Definition: afw_error.h:83
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Filled in by afw_value get_info method.
Definition: afw_value.h:49
struct for data type object values.
Struct for qualified variable reference value.
Interface afw_value public struct.
Interface afw_writer public struct.
Interface afw_xctx public struct.