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