Bash++
Bash++ compiler internal documentation
templates.h
Go to the documentation of this file.
1
6#ifndef SRC_BPP_INCLUDE_TEMPLATES_H_
7#define SRC_BPP_INCLUDE_TEMPLATES_H_
8
23static 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}" 2>/dev/null
40 eval "$__outputVar=\$(< "/dev/fd/${!__supershellFD}")"
41 echo "${__temporaryStorage}">"/dev/fd/${!__supershellFD}"
42}
43)EOF";
44
45static const char* bpp_vtable_lookup = R"EOF(function bpp____vTable__lookup() {
46 local __this="$1" __method="$2" __outputVar="$3"
47 ([[ -z "${__this}" ]] || [[ -z "${__method}" ]] || [[ -z "${__outputVar}" ]]) && >&2 echo "Bash++: Error: Invalid vTable lookup" && exit 1
48 while : ; do
49 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
50 break
51 fi
52 [[ -z "${!__this}" ]] && break
53 __this="${!__this}"
54 done
55 local __vTable="${__this}____vPointer"
56 if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
57 return 1
58 fi
59 local __result="${!__vTable}[\"${__method}\"]"
60 [[ -z "${!__result}" ]] && >&2 echo "Bash++: Error: Method '${__method}' not found in vTable for object '${__this}'" && return 1
61 eval "${__outputVar}=\$__result"
62}
63)EOF";
64
65static const char* bpp_dynamic_cast = R"EOF(function bpp____dynamic__cast() {
66 local __type="$1" __outputVar="$2" __this="$3"
67 ([[ -z "${__type}" ]] || [[ -z "${__outputVar}" ]]) && >&2 echo "Bash++: Error: Invalid dynamic_cast" && exit 1
68 eval "${__outputVar}=0"
69 while : ; do
70 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
71 break
72 fi
73 [[ -z "${!__this}" ]] && break
74 __this="${!__this}"
75 done
76 local __vTable="${__this}____vPointer"
77 if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
78 return 1
79 fi
80 while [[ ! -z "${!__vTable}" ]] 2>/dev/null; do
81 [[ "${!__vTable}" == "bpp__${__type}____vTable" ]] && eval "${__outputVar}=\"${__this}\"" && return 0
82 __vTable="${!__vTable}[\"__parent__\"]"
83 done
84 return 1
85}
86)EOF";
87
88static const char* bpp_typeof_function = R"EOF(function bpp____typeof() {
89 local __this="$1" __outputVar="$2"
90 [[ -z "${__this}" ]] && >&2 echo "Bash++: Error: Invalid type name request" && exit 1
91 while : ; do
92 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
93 break
94 fi
95 [[ -z "${!__this}" ]] && break
96 __this="${!__this}"
97 done
98 local __vTable="${__this}____vPointer"
99 if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
100 return 1
101 fi
102 __vTable="${!__vTable}"
103 local __typeName="${__vTable/bpp__/}"
104 __typeName="${__typeName/____vTable/}"
105 eval "${__outputVar}=\"${__typeName}\""
106}
107)EOF";
108
109static const char* template_new_function = R"EOF(function bpp__%CLASS%____new() {
110 local __this="$1"
111 if [[ "${__this}" == "" ]]; then
112 while : ; do
113 __this="bpp__%CLASS%__$RANDOM$RANDOM$RANDOM$RANDOM"
114 local __unusedVar="${__this}____vPointer"
115 [[ -z "${!__unusedVar+x}" ]] && break
116 done
117 fi
118 eval "${__this}____vPointer=bpp__%CLASS%____vTable"
119%ASSIGNMENTS%
120 echo "${__this}"
121}
122)EOF";
123
124static const char* template_copy_function = R"EOF(function bpp__%CLASS%____copy() {
125 local __copyFromAddress="$1" __copyToAddress="$2"
126 while : ; do
127 if ! eval "declare -p \"${__copyFromAddress}\"" &>/dev/null; then
128 break
129 fi
130 [[ -z "${!__copyFromAddress}" ]] && break
131 __copyFromAddress="${!__copyFromAddress}"
132 done
133 while : ; do
134 if ! eval "declare -p \"${__copyToAddress}\"" &>/dev/null; then
135 break
136 fi
137 [[ -z "${!__copyToAddress}" ]] && break
138 __copyToAddress="${!__copyToAddress}"
139 done
140 local __copyFromVPointer="${__copyFromAddress}____vPointer" __copyToVPointer="${__copyToAddress}____vPointer"
141 if [[ "${__copyFromAddress}" == "0" ]] || [[ -z "${!__copyFromVPointer}" ]]; then
142 >&2 echo "Bash++: Error: %CLASS%: Attempted to copy from null object"
143 return
144 fi
145 if [[ "${__copyToAddress}" == "0" ]] || [[ -z "${!__copyToVPointer}" ]]; then
146 >&2 echo "Bash++: Error: %CLASS%: Attempted to copy to null object"
147 return
148 fi
149 if [[ "${!__copyFromVPointer}" != "${!__copyToVPointer}" ]]; then
150 >&2 echo "Bash++: Error: %CLASS%: Attempted to copy between different types"
151 return
152 fi
153%COPIES%
154 eval "${__copyToVPointer}=${!__copyFromVPointer}"
155}
156)EOF";
157
158static const char* template_method = R"EOF(function bpp__%CLASS%__%SIGNATURE%() {
159 local __this="$1"
160 shift 1
161 %PARAMS%
162 while : ; do
163 if ! eval "declare -p \"${__this}\"" &>/dev/null; then
164 break
165 fi
166 [[ -z "${!__this}" ]] && break
167 __this="${!__this}"
168 done
169 local __vPointer="${__this}____vPointer"
170 if [[ "${__this}" == "0" ]] || [[ -z "${!__vPointer}" ]]; then
171 >&2 echo "Bash++: Error: Attempted to call @%CLASS%.%SIGNATURE% on null object"
172 return
173 fi
174%METHODBODY%
175}
176)EOF";
177
178#endif // SRC_BPP_INCLUDE_TEMPLATES_H_
static const char * bpp_vtable_lookup
Definition templates.h:45
static const char * bpp_typeof_function
Definition templates.h:88
static const char * bpp_dynamic_cast
Definition templates.h:65
static const char * template_new_function
Definition templates.h:109
static const char * bpp_supershell_function
Definition templates.h:23
static const char * template_copy_function
Definition templates.h:124
static const char * template_method
Definition templates.h:158