18 #define AFW_IMPLEMENTATION_ID "afw_value_compiler_listing_writer"
33 for (result = 1; i > 9; i /= 10) {
46 impl_afw_writer_write_raw_cb(
57 for (i = 0; i < size; i++) {
58 APR_ARRAY_PUSH(self->ary,
char) =
70 impl_afw_writer_release(
83 impl_afw_writer_flush(
93 impl_write_source_line(
101 char buffer[
sizeof(impl_empty_prefix)];
104 src =
self->compiled_value->full_source;
106 if (self->source_eof || src->len < self->cursor_written) {
109 self->last_line_written++;
111 if (!line_written && self->empty_line_between_switch) {
112 APR_ARRAY_PUSH(self->ary,
char) =
'\n';
116 len = snprintf(buffer,
sizeof(buffer),
118 self->last_line_written);
119 len = (int)self->prefix_size - len - 3;
120 len = snprintf(buffer,
sizeof(buffer),
123 &impl_empty_prefix[0],
124 self->last_line_written);
125 for (i = 0; i < len; i++) {
126 APR_ARRAY_PUSH(self->ary,
char) = buffer[i];
131 s = src->s + self->cursor_written,
132 end = src->s + src->len;
138 APR_ARRAY_PUSH(self->ary,
char) = *s;
142 self->source_eof =
true;
150 APR_ARRAY_PUSH(self->ary,
char) =
'\n';
151 self->source_eof =
true;
158 self->cursor_written = s - src->s;
159 return !
self->source_eof;
187 if (self->is_new_line &&
189 (size >= 1 && *(
char *)buffer ==
'#') ||
190 (size >= 1 && *(
char *)buffer ==
'\n') ||
191 (size >= 3 && (memcmp(buffer,
"---", 3) == 0))
194 if (self->include_source) {
195 for (line_written =
false;
196 self->max_value_cursor >=
self->cursor_written;
199 if (!impl_write_source_line(
self, line_written, xctx)) {
204 if (self->empty_line_between_switch && line_written) {
205 APR_ARRAY_PUSH(self->ary,
char) =
'\n';
208 if (!self->current_prefix) {
209 self->current_prefix = &
self->empty_prefix;
211 for (i = 0; i <
self->current_prefix->len; i++) {
212 APR_ARRAY_PUSH(self->ary,
char) =
self->current_prefix->s[i];
214 self->current_prefix = NULL;
215 for (count = 0; count <
self->writer.indent; count++) {
216 for (i = 0; i <
self->writer.tab->len; i++) {
217 APR_ARRAY_PUSH(self->ary,
char) =
self->writer.tab->s[i];
226 self->current_prefix = NULL;
229 self->is_new_line =
false;
231 for (count = 0; count < size; count++) {
232 APR_ARRAY_PUSH(self->ary,
char) = *c++;
248 if (self->writer.tab) {
249 APR_ARRAY_PUSH(self->ary,
char) =
'\n';
250 self->is_new_line =
true;
258 impl_afw_writer_increment_indent(
265 self->writer.indent++;
272 impl_afw_writer_decrement_indent(
279 if (self->writer.indent == 0) {
281 "decrement indent when indent already 0",
285 self->writer.indent--;
291 afw_value_compiler_listing_for_child(
299 if (writer->inf != &impl_afw_writer_inf) {
301 "afw_value_compiler_listing_for_child() can only be called by"
302 "afw_value_compiler_listing implementation of writer",
308 instance, parent, parent->writer.tab, parent->p, xctx);
310 return self->reference_id;
338 for (e = block->first_entry; e; e = e->next_entry) {
370 for (child = block->first_child_block;
372 child = child->next_sibling_block)
374 impl_symbol_listing(writer, child, xctx);
397 writer = &
self->writer;
398 self->writer.inf = &impl_afw_writer_inf;
401 self->writer.write_raw_cb = impl_afw_writer_write_raw_cb;
403 self->writer.tab = tab;
404 if (tab->len == 1 && *(tab->s) ==
'\t') {
405 self->writer.tab = &impl_default_tab;
407 self->tab_size = (int)tab->len;
411 self->parent = parent;
412 if (parent->final_child) {
413 parent->final_child->next_sibling =
self;
414 parent->final_child =
self;
417 parent->first_child =
self;
418 parent->final_child =
self;
431 "# Adaptive Value is fully evaluated at compile time", xctx);
448 self->reference_id =
self->compiled_value->reference_id;
451 self->include_source =
true;
452 self->empty_line_between_switch =
true;
458 if (self->compiled_value->source_location) {
461 self->compiled_value->source_location, xctx);
468 self->is_new_line =
true;
469 if (self->compiled_value->line_count == 0) {
470 self->offset_only =
true;
473 impl_digits_needed(self->compiled_value->full_source->len) * 2 +
480 impl_digits_needed(self->compiled_value->line_count) * 2 +
481 impl_digits_needed(self->compiled_value->longest_line) * 2 +
486 if (self->tab_size != 0) {
488 (
self->prefix_size +
self->tab_size - 1) /
489 self->tab_size * self->tab_size;
493 if (self->prefix_size >
sizeof(impl_empty_prefix)) {
498 self->empty_prefix.s = &impl_empty_prefix[
499 sizeof(impl_empty_prefix) - self->prefix_size - 1];
500 self->empty_prefix.len = self->prefix_size;
507 afw_value_compiler_listing_begin_value(writer, value, NULL, xctx);
520 if (self->include_source && !self->source_eof) {
522 while (impl_write_source_line(
self,
true, xctx));
526 self->current_prefix = NULL;
527 self->empty_prefix.len = 0;
528 self->empty_prefix.s = NULL;
536 impl_symbol_listing(writer, self->compiled_value->top_block, xctx);
567 result =
self->ary->nelts;
568 for (child = self->first_child; child; child = child->next_sibling) {
569 result += impl_total_buffer_needed(child);
583 memcpy(*buffer, self->ary->elts, self->ary->nelts);
584 *buffer = *buffer +
self->ary->nelts;
585 for (child = self->first_child; child; child = child->next_sibling) {
586 impl_move_to_buffer(child, buffer);
610 value, NULL, tab, temp_pool, xctx);
612 len = impl_total_buffer_needed(
self);
617 impl_move_to_buffer(
self, &buffer);
628 afw_value_compiler_listing_begin_value(
642 char buffer[
sizeof(impl_empty_prefix)];
645 if (contextual->
value_offset > self->max_value_cursor) {
648 if (self->offset_only) {
649 len = snprintf(buffer,
sizeof(buffer),
657 self->tab_size, xctx);
661 self->tab_size, xctx);
662 len = snprintf(buffer,
sizeof(buffer),
664 line_number, column_number,
665 end_line_number, end_column_number);
667 prefix.s = &buffer[0];
668 prefix.len =
self->empty_prefix.len;
670 &impl_empty_prefix[len + (
sizeof(impl_empty_prefix) - prefix.len) - 1],
672 self->current_prefix = &prefix;
675 self->current_prefix = &
self->empty_prefix;
680 &value->inf->rti.implementation_id,
688 afw_value_compiler_listing_end_value(
699 afw_value_compiler_listing_call_args(
706 AFW_VALUE_COMPILER_LISTING_IF_NOT_LIMIT_EXCEEDED
707 for (i = 0; i <= args->
argc; i++) {
708 afw_value_compiler_listing_value(args->
argv[i], writer, xctx);
716 afw_value_compiler_listing_value(
AFW_DEFINE(const afw_object_t *)
#define AFW_DEFINE_INTERNAL(type)
Define an internal function for /src/afw/ source*.c files.
Adaptive Framework Core Internal.
Interface afw_interface implementation declares.
#define AFW_UTF8_LITERAL(A_STRING)
String literal initializer.
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
apr_size_t afw_size_t
size_t.
unsigned char afw_octet_t
8 bits (unsigned).
#define AFW_SIZE_T_FMT
Format string specifier used for afw_size_t.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
#define afw_pool_malloc(instance, size, xctx)
Call method malloc of interface afw_pool.
#define afw_pool_get_apr_pool(instance)
Call method get_apr_pool of interface afw_pool.
#define afw_pool_release(instance, xctx)
Call method release of interface afw_pool.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
const afw_pool_t * afw_pool_create(const afw_pool_t *parent, afw_xctx_t *xctx)
Create a new pool.
#define afw_pool_malloc_type(instance, type, xctx)
Macro to allocate uncleared memory to hold type in pool.
afw_utf8_line_column_of_offset(afw_size_t *line_number, afw_size_t *column_number, const afw_utf8_t *s, afw_size_t offset, int tab_size, afw_xctx_t *xctx)
Determine the line and column of an offset in a string.
#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_get_info(instance, info, p, xctx)
Call method get_info of interface afw_value.
afw_value_compiler_listing_to_string_instance(const afw_value_t *value, afw_value_compiler_listing_t *parent, const afw_utf8_t *tab, const afw_pool_t *p, afw_xctx_t *xctx)
afw_value_compiler_listing_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 compiler listing string.
#define afw_value_is_undefined_or_evaluated(A_VALUE)
Macro to determine if value is undefined or evaluated.
#define AFW_VALUE_ASSERT_IS(A_VALUE, A_TYPE_ID, A_SCOPE)
Throw and error if A_VALUE is not value inf id.
#define afw_value_is_undefined(A_VALUE)
Determine if value is undefined.
impl_afw_writer_write(const afw_writer_t *instance, const void *buffer, afw_size_t size, afw_xctx_t *xctx)
impl_afw_writer_write_eol(const afw_writer_t *instance, afw_xctx_t *xctx)
#define afw_writer_increment_indent(instance, xctx)
Call method increment_indent of interface afw_writer.
#define afw_writer_write(instance, buffer, size, xctx)
Call method write 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.
afw_writer_write_size(const afw_writer_t *writer, afw_size_t size, afw_xctx_t *xctx)
Call afw_writer_write() with an size.
#define afw_writer_write_utf8(writer, S, xctx)
Call afw_writer_write() with a afw_utf8_t string.
Contextual information provided in some values.
afw_size_t value_size
Size in full_source of value source.
const afw_utf8_t * source_location
Source location.
const afw_value_compiled_value_t * compiled_value
Compiled value this value is part of.
afw_size_t value_offset
Offset in full source of compiled value to this value.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
struct for afw_value_block_t
struct for afw_value_block_symbol_t
Struct for contextual and args for call values.
const afw_value_t *const * argv
Filled in by afw_value get_info method.
Struct for compiled value value.
const afw_utf8_t * full_source
The full source that was compiled.
Interface afw_value public struct.
const afw_object_t * value_meta_object
AdaptiveValueMeta object or NULL.
const afw_data_type_t * data_type
data type or NULL.
const afw_compile_value_contextual_t * data_type_parameter_contextual
contextual for data type parameter or NULL.
Interface afw_writer public struct.
Interface afw_xctx public struct.