Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_value_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 "variable_reference"
28 #define AFW_IMPLEMENTATION_INF_SPECIFIER AFW_DEFINE_CONST_DATA
29 #define AFW_IMPLEMENTATION_INF_LABEL afw_value_variable_reference_inf
31 
32 
33 
34 /* Create function for variable reference value. */
35 AFW_DEFINE(const afw_value_t *)
37  const afw_compile_value_contextual_t *contextual,
38  const afw_value_block_symbol_t *symbol,
39  const afw_pool_t *p,
40  afw_xctx_t *xctx)
41 {
43 
46  self->contextual = contextual;
47  self->symbol = symbol;
48 
49  return (afw_value_t *)self;
50 }
51 
52 
53 
54 /*
55  * Implementation of method optional_evaluate for interface afw_value.
56  */
57 const afw_value_t *
59  const afw_value_t * instance,
60  const afw_pool_t * p,
61  afw_xctx_t *xctx)
62 {
63  const afw_value_variable_reference_t *self =
64  (const afw_value_variable_reference_t *)instance;
65  const afw_value_t *result;
66  const afw_compile_value_contextual_t *saved_contextual;
67 
68  /* Push value on evaluation stack. */
70  saved_contextual = xctx->error->contextual;
71  xctx->error->contextual = self->contextual;
72 
73  /* Try to locate a variable. */
74  result = afw_xctx_get_qualified_variable(NULL, self->symbol->name, xctx);
75 
76  /* Pop value from evaluation stack and return result. */
78  xctx->error->contextual = saved_contextual;
79  return result;
80 }
81 
82 /*
83  * Implementation of method get_data_type for interface afw_value.
84  */
85 const afw_data_type_t *
86 impl_afw_value_get_data_type(
87  const afw_value_t * instance,
88  afw_xctx_t *xctx)
89 {
90  return NULL;
91 }
92 
93 /*
94  * Implementation of method get_evaluated_data_type for interface afw_value.
95  */
96 const afw_data_type_t *
97 impl_afw_value_get_evaluated_data_type(
98  const afw_value_t * instance,
99  afw_xctx_t *xctx)
100 {
101  return NULL;
102 }
103 
104 
105 /*
106  * Implementation of method get_evaluated_data_type_parameter for interface
107  * afw_value.
108  */
109 const afw_utf8_t *
110 impl_afw_value_get_evaluated_data_type_parameter(
111  const afw_value_t * instance,
112  afw_xctx_t *xctx)
113 {
114  return NULL;
115 }
116 
117 
118 /*
119  * Implementation of method get_evaluated_meta for interface afw_value.
120  */
121 const afw_value_t *
123  const afw_value_t *instance,
124  const afw_pool_t *p,
125  afw_xctx_t *xctx)
126 {
127  const afw_value_variable_reference_t *self =
128  (const afw_value_variable_reference_t *)instance;
130 
131  meta = afw_value_internal_create_meta_object_self(
132  instance, p, xctx);
133  meta->key = self->symbol->name;
134  if (afw_value_is_object(meta->evaluated_value)) {
135  meta->additional =
136  (((const afw_value_object_t *)meta->evaluated_value)->
137  internal)->meta.meta_object;
138  }
139  return (const afw_value_t *)& meta->meta_object_value;
140 }
141 
142 
143 /*
144  * Implementation of method decompile for interface afw_value.
145  */
146 void
147 impl_afw_value_produce_compiler_listing(
148  const afw_value_t *instance,
149  const afw_writer_t *writer,
150  afw_xctx_t *xctx)
151 {
152  const afw_value_variable_reference_t *self =
153  (const afw_value_variable_reference_t *)instance;
154 
155  afw_value_compiler_listing_begin_value(writer, instance,
156  self->contextual, xctx);
157  afw_writer_write_z(writer, " name=", xctx);
158  afw_writer_write_utf8(writer, self->symbol->name, xctx);
159  afw_writer_write_z(writer, " block=", xctx);
160  afw_writer_write_size(writer, self->symbol->parent_block->number, xctx);
161  afw_writer_write_z(writer, " depth=", xctx);
162  afw_writer_write_size(writer, self->symbol->parent_block->depth, xctx);
163  afw_writer_write_z(writer, " index=", xctx);
164  afw_writer_write_size(writer, self->symbol->index, xctx);
165  afw_writer_write_eol(writer, xctx);
166 }
167 
168 
169 /*
170  * Implementation of method decompile for interface afw_value.
171  */
172 void
173 impl_afw_value_decompile(
174  const afw_value_t * instance,
175  const afw_writer_t * writer,
176  afw_xctx_t *xctx)
177 {
178  const afw_value_variable_reference_t *self =
179  (const afw_value_variable_reference_t *)instance;
180 
181  afw_writer_write_utf8(writer, self->symbol->name, xctx);
182 }
183 
184 
185 /*
186  * Implementation of method get_info for interface afw_value.
187  */
188 void
189 impl_afw_value_get_info(
190  const afw_value_t *instance,
191  afw_value_info_t *info,
192  const afw_pool_t *p,
193  afw_xctx_t *xctx)
194 {
195  const afw_value_variable_reference_t *self =
196  (const afw_value_variable_reference_t *)instance;
197 
198  afw_memory_clear(info);
199  info->value_inf_id = &instance->inf->rti.implementation_id;
200  info->contextual = self->contextual;
201 }
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_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_variable_reference_inf
Value variable_reference inf.
Definition: afw_value.h:309
afw_value_variable_reference_create(const afw_compile_value_contextual_t *contextual, const afw_value_block_symbol_t *symbol, 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
afw_writer_write_size(const afw_writer_t *writer, afw_size_t size, afw_xctx_t *xctx)
Call afw_writer_write() with an size.
Definition: afw_writer.c:162
#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
struct for afw_value_block_symbol_t
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.