Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_function_template.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * afw_function_execute_* functions for template
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw.h"
15 
16 
17 
18 /*
19  * Adaptive function: compile<template>
20  *
21  * afw_function_execute_compile_template
22  *
23  * See afw_function_bindings.h for more information.
24  *
25  * Compile template value and return either an unevaluated adaptive value or a
26  * string containing the compiler listing.
27  *
28  * This function is pure, so it will always return the same result
29  * given exactly the same parameters and has no side effects.
30  *
31  * Declaration:
32  *
33  * ```
34  * function compile<template>(
35  * source: template,
36  * listing?: any
37  * ): unevaluated;
38  * ```
39  *
40  * Parameters:
41  *
42  * source - (template) template string to compile.
43  *
44  * listing - (optional any dataType) If specified, a compiler listing is
45  * produced instead of an unevaluated expression value.
46  *
47  * This parameter can be an integer between 0 and 10 of a string that is
48  * used for indentation. If 0 is specified, no whitespace is added to the
49  * resulting string. If 1 through 10 is specified, that number of spaces
50  * is used.
51  *
52  * Returns:
53  *
54  * (unevaluated)
55  */
56 const afw_value_t *
59 {
60  const afw_value_string_t *template;
61  const afw_value_t *result;
62  const afw_utf8_t *listing;
63 
65 
66  result = afw_compile_to_value(
67  &template->internal, AFW_FUNCTION_SOURCE_LOCATION,
68  afw_compile_type_template,
69  NULL, NULL, x->p, x->xctx);
70 
72  listing = afw_function_evaluate_whitespace_parameter(x, 2);
73  result = afw_value_create_string(
75  x->p, x->xctx),
76  x->p, x->xctx);
77  }
78 
79  return result;
80 }
81 
82 
83 
84 /*
85  * Adaptive function: evaluate<template>
86  *
87  * afw_function_execute_evaluate_template
88  *
89  * See afw_function_bindings.h for more information.
90  *
91  * Compile and evaluate template value.
92  *
93  * This function is not pure, so it may return a different result
94  * given exactly the same parameters.
95  *
96  * Declaration:
97  *
98  * ```
99  * function evaluate<template>(
100  * source: template,
101  * additionalUntrustedQualifiedVariables?: (object _AdaptiveHybridPropertiesObjects_)
102  * ): unevaluated;
103  * ```
104  *
105  * Parameters:
106  *
107  * source - (template) template string to compile and evaluate.
108  *
109  * additionalUntrustedQualifiedVariables - (optional object
110  * _AdaptiveHybridPropertiesObjects_) This parameter supplies additional
111  * qualified variables that can be accessed during evaluation. These
112  * variables will not be used by anything that needs to ensure its
113  * qualified variables must come from a trusted source, such as
114  * authorization. This parameter is intended to be used for testing only
115  * and should not be used for anything running in production.
116  *
117  * Returns:
118  *
119  * (unevaluated)
120  */
121 const afw_value_t *
124 {
125  const afw_value_string_t *template;
126  const afw_value_t *compiled;
127  const afw_value_t *value;
128 
130 
131  compiled = afw_compile_to_value(
132  &template->internal, AFW_FUNCTION_SOURCE_LOCATION,
133  afw_compile_type_template,
134  NULL, NULL, x->p, x->xctx);
135 
138  compiled, x->argv[2], x->p, x->xctx);
139  }
140  else {
141  value = afw_value_evaluate(compiled, x->p, x->xctx);
142  }
143 
144  return value;
145 }
Adaptive Framework Core API.
afw_value_create_string(const afw_utf8_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type string value.
#define afw_compile_to_value(string, source_location, compile_type, parent, shared, p, xctx)
Compile string to adaptive value.
Definition: afw_compile.h:189
#define AFW_FUNCTION_SOURCE_LOCATION
Source location of a value.
Definition: afw_function.h:341
#define AFW_FUNCTION_EVALUATE_REQUIRED_DATA_TYPE_PARAMETER(A_RESULT, A_N, A_TYPE)
Evaluate an arg for a particular data type.
Definition: afw_function.h:328
#define AFW_FUNCTION_PARAMETER_IS_PRESENT(A_N)
Determine if a specific parameter value is present.
Definition: afw_function.h:242
const afw_value_t * afw_function_execute_compile_template(afw_function_execute_t *x)
Adaptive Function compile<template>
const afw_value_t * afw_function_execute_evaluate_template(afw_function_execute_t *x)
Adaptive Function evaluate<template>
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_evaluate(value, p, xctx)
Evaluate value if needed using specific pool.
Definition: afw_value.h:841
afw_value_evaluate_with_additional_untrusted_qualified_variables(const afw_value_t *value, const afw_value_t *untrusted_qualified_variables, const afw_pool_t *p, afw_xctx_t *xctx)
Evaluate a value with additional insecure context.
Definition: afw_value.c:534
Function execute parameter.
Definition: afw_function.h:53
const afw_value_t *const * argv
This is the function parameters.
Definition: afw_function.h:86
afw_xctx_t * xctx
The execution context (xctx) of caller.
Definition: afw_function.h:62
const afw_pool_t * p
Pool for result.
Definition: afw_function.h:59
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_value public struct.
struct for data type string values.