Bash++
Bash++ compiler internal documentation
templates.h
Go to the documentation of this file.
1
7#pragma once
8
23[[maybe_unused]] static const char* bpp_supershell_function = R"EOF(function bpp____initsupershell() {
24 local bpp____supershellDirectory="/dev/shm/"
25 if [[ ! -d "${bpp____supershellDirectory}" ]]; then
26 bpp____supershellDirectory="${TMPDIR:-/tmp/}"
27 fi
28 local bpp____supershelltempfile="$(mktemp "${bpp____supershellDirectory}/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")"
29 eval "exec {bpp____supershellFD__$BASHPID}<>\"$bpp____supershelltempfile\""
30 rm "$bpp____supershelltempfile"
31}
32function bpp____supershell() {
33 local __outputVar="$1" __command="$2" __supershellFD="bpp____supershellFD__$BASHPID" __temporaryStorage=""
34 if [[ -z "${!__supershellFD}" ]]; then
35 bpp____initsupershell
36 else
37 __temporaryStorage=$(< "/dev/fd/${!__supershellFD}")
38 fi
39 $__command 1>"/dev/fd/${!__supershellFD}"
40 eval "$__outputVar=\$(< "/dev/fd/${!__supershellFD}")"
41 echo "${__temporaryStorage}">"/dev/fd/${!__supershellFD}"
42}
43)EOF";
44
45[[maybe_unused]] static const char* bpp_repeat = R"EOF(function bpp____repeat() {
46 return $1
47})EOF";
48
49[[maybe_unused]] static const char* bpp_vtable_lookup = R"EOF(function bpp____vTable__lookup() {
50 local __this="$1" __method="$2" __outputVar="$3"
51 ([[ -z "${__this}" ]] || [[ -z "${__method}" ]] || [[ -z "${__outputVar}" ]]) && >&2 echo "Bash++: Error: Invalid vTable lookup" && exit 1
52 while : ; do
53 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
54 break
55 fi
56 [[ -z "${!__this}" ]] && break
57 __this="${!__this}"
58 done
59 local __vTable="${__this}____vPointer"
60 if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
61 return 1
62 fi
63 local __result="${!__vTable}[\"${__method}\"]"
64 [[ -z "${!__result}" ]] && >&2 echo "Bash++: Error: Method '${__method}' not found in vTable for object '${__this}'" && return 1
65 eval "${__outputVar}=\$__result"
66}
67)EOF";
68
69[[maybe_unused]] static const char* bpp_dynamic_cast = R"EOF(function bpp____dynamic__cast() {
70 local __type="$1" __outputVar="$2" __this="$3"
71 ([[ -z "${__outputVar}" ]]) && >&2 echo "Bash++: Error: Invalid dynamic_cast" && exit 1
72 eval "${__outputVar}=0"
73 while : ; do
74 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
75 break
76 fi
77 [[ -z "${!__this}" ]] && break
78 __this="${!__this}"
79 done
80 local __vTable="${__this}____vPointer"
81 if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
82 return 1
83 fi
84 while [[ ! -z "${!__vTable}" ]] 2>/dev/null; do
85 [[ "${!__vTable}" == "bpp__${__type}____vTable" ]] && eval "${__outputVar}=\"${__this}\"" && return 0
86 __vTable="${!__vTable}[\"__parent__\"]"
87 done
88 return 1
89}
90)EOF";
91
92[[maybe_unused]] static const char* bpp_typeof_function = R"EOF(function bpp____typeof() {
93 local __this="$1" __outputVar="$2"
94 [[ -z "${__this}" ]] && >&2 echo "Bash++: Error: Invalid type name request" && exit 1
95 while : ; do
96 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
97 break
98 fi
99 [[ -z "${!__this}" ]] && break
100 __this="${!__this}"
101 done
102 local __vTable="${__this}____vPointer"
103 if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
104 return 1
105 fi
106 __vTable="${!__vTable}"
107 local __typeName="${__vTable/bpp__/}"
108 __typeName="${__typeName/____vTable/}"
109 eval "${__outputVar}=\"${__typeName}\""
110}
111)EOF";
112
113[[maybe_unused]] static const char* template_method = R"EOF(function bpp__%CLASS%__%SIGNATURE%() {
114 local __this="$1"
115 shift 1
116 %PARAMS%
117 %THIS_POINTER_VALIDATION%
118%METHODBODY%
119}
120)EOF";
121
122[[maybe_unused]] static const char* this_pointer_validation = R"EOF(while : ; do
123 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
124 break
125 fi
126 [[ -z "${!__this}" ]] && break
127 __this="${!__this}"
128 done
129 local __vPointer="${__this}____vPointer"
130 if [[ "${__this}" == "0" ]] || [[ -z "${!__vPointer}" ]]; then
131 >&2 echo "Bash++: Error: Attempted to call @%CLASS%.%SIGNATURE% on null object"
132 return 1
133 fi
134)EOF";
static const char * bpp_vtable_lookup
Definition templates.h:49
static const char * bpp_typeof_function
Definition templates.h:92
static const char * this_pointer_validation
Definition templates.h:122
static const char * bpp_dynamic_cast
Definition templates.h:69
static const char * bpp_supershell_function
Definition templates.h:23
static const char * template_method
Definition templates.h:113
static const char * bpp_repeat
Definition templates.h:45