Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_value_decompile.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Value Decompile
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 
18 /* Decompile a value to a string. */
19 AFW_DEFINE(const afw_utf8_t *)
21  const afw_value_t *value,
22  const afw_utf8_t *tab,
23  const afw_pool_t *p,
24  afw_xctx_t *xctx)
25 {
26  const afw_writer_t *writer;
27  const afw_utf8_t *result;
28  afw_utf8_t current_string;
29 
30 
31  if (afw_value_is_undefined(value)) {
32  result = &afw_s_undefined;
33  }
34 
35  else {
36  writer = afw_utf8_writer_create(tab, p, xctx);
37  afw_value_decompile(value, writer, xctx);
38  afw_utf8_writer_current_string(writer, &current_string, xctx);
39  result = afw_utf8_create_copy(current_string.s, current_string.len,
40  p, xctx);
41  afw_writer_release(writer, xctx);
42  }
43 
44  return result;
45 }
46 
47 
48 /* Decompile call args. */
49 AFW_DEFINE(void)
51  const afw_writer_t *writer,
52  afw_size_t first_arg,
53  const afw_value_call_args_t *args,
54  afw_xctx_t *xctx)
55 {
56  afw_size_t i;
57 
58  afw_writer_write_z(writer, "(", xctx);
59  if (writer->tab) {
60  afw_writer_increment_indent(writer, xctx);
61  }
62 
63  for (i = first_arg; i < args->argc; i++) {
64  if (i != first_arg) {
65  afw_writer_write_z(writer, ",", xctx);
66  }
67  if (writer->tab) {
68  afw_writer_write_eol(writer, xctx);
69  }
70  afw_value_decompile_value(args->argv[i], writer, xctx);
71  }
72 
73  if (writer->tab) {
74  afw_writer_write_eol(writer, xctx);
75  afw_writer_decrement_indent(writer, xctx);
76  }
77  afw_writer_write_z(writer, ")", xctx);
78 }
79 
80 
81 /* Decompile Value::. */
82 AFW_DEFINE(void)
84  const afw_value_t *instance,
85  const afw_writer_t *writer,
86  afw_xctx_t *xctx)
87 {
88  if (!instance) {
89  afw_writer_write_utf8(writer, &afw_s_undefined, xctx);
90  }
91  else if (afw_value_is_expression_definition(instance)) {
92  afw_writer_write_z(writer, "(", xctx);
93  if (writer->tab) {
94  afw_writer_increment_indent(writer, xctx);
95  }
96  afw_value_decompile(instance, writer, xctx);
97  if (writer->tab) {
98  afw_writer_decrement_indent(writer, xctx);
99  }
100  afw_writer_write_z(writer, ")", xctx);
101  }
102  else {
103  afw_value_decompile(instance, writer, xctx);
104  }
105 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
void afw_utf8_writer_current_string(const afw_writer_t *writer, afw_utf8_t *current_string, afw_xctx_t *xctx)
Get the current string in a UTF-8 writer.
#define afw_utf8_create_copy(s, len, p, xctx)
Make a utf-8 sting from chars in pool specified.
Definition: afw_utf8.h:369
const afw_writer_t * afw_utf8_writer_create(const afw_utf8_t *tab, const afw_pool_t *p, afw_xctx_t *xctx)
Create UTF-8 writer.
#define afw_value_decompile(instance, writer, xctx)
Call method decompile of interface afw_value.
#define afw_value_is_expression_definition(A_VALUE)
Macro to determine if value is an expression definition.
Definition: afw_value.h:601
afw_value_decompile_to_string(const afw_value_t *value, const afw_utf8_t *tab, const afw_pool_t *p, afw_xctx_t *xctx)
Decompile a value to a string.
afw_value_decompile_call_args(const afw_writer_t *writer, afw_size_t first_arg, const afw_value_call_args_t *args, afw_xctx_t *xctx)
Decompile call args.
afw_value_decompile_value(const afw_value_t *instance, const afw_writer_t *writer, afw_xctx_t *xctx)
Decompile Value::.
#define afw_value_is_undefined(A_VALUE)
Determine if value is undefined.
Definition: afw_value.h:438
#define afw_writer_increment_indent(instance, xctx)
Call method increment_indent of interface afw_writer.
#define afw_writer_release(instance, xctx)
Call method release 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_writer_write_utf8(writer, S, xctx)
Call afw_writer_write() with a afw_utf8_t string.
Definition: afw_writer.h:45
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Struct for contextual and args for call values.
Interface afw_value public struct.
Interface afw_writer public struct.
Interface afw_xctx public struct.