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 
9 const char* bpp_supershell_function = R"EOF(function bpp____initsupershell() {
10  local bpp____supershellDirectory="/dev/shm/"
11  if [[ ! -d "${bpp____supershellDirectory}" ]]; then
12  bpp____supershellDirectory="${TMPDIR:-/tmp/}"
13  fi
14  local bpp____supershelltempfile="$(mktemp "${bpp____supershellDirectory}/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")"
15  eval "exec {bpp____supershellFD__$BASHPID}<>\"$bpp____supershelltempfile\""
16  rm "$bpp____supershelltempfile"
17 }
18 function bpp____supershell() {
19  local __outputVar="$1" __command="$2" __supershellFD="bpp____supershellFD__$BASHPID" __temporaryStorage=""
20  if [[ -z "${!__supershellFD}" ]]; then
21  bpp____initsupershell
22  else
23  __temporaryStorage=$(< "/dev/fd/${!__supershellFD}")
24  fi
25  $__command 1>"/dev/fd/${!__supershellFD}" 2>/dev/null
26  eval "$__outputVar=\$(< "/dev/fd/${!__supershellFD}")"
27  echo "${__temporaryStorage}">"/dev/fd/${!__supershellFD}"
28 }
29 )EOF";
30 
31 const char* bpp_vtable_lookup = R"EOF(function bpp____vTable__lookup() {
32  local __objectAddress="$1" __method="$2" __outputVar="$3"
33  ([[ -z "${__objectAddress}" ]] || [[ -z "${__method}" ]] || [[ -z "${__outputVar}" ]]) && >&2 echo "Bash++: Error: Invalid vTable lookup" && exit 1
34  while : ; do
35  if ! eval "declare -p \"${__objectAddress}\"" &>/dev/null; then
36  break
37  fi
38  [[ -z "${!__objectAddress}" ]] && break
39  __objectAddress="${!__objectAddress}"
40  done
41  local __vTable="${__objectAddress}____vPointer"
42  if ! eval "declare -p \"${__vTable}\"" &>/dev/null; then
43  >&2 echo "Bash++: Error: vTable not found for object '${__objectAddress}'"
44  exit 1
45  fi
46  local __result="${!__vTable}[\"${__method}\"]"
47  [[ -z "${!__result}" ]] && >&2 echo "Bash++: Error: Method '${__method}' not found in vTable for object '${__objectAddress}'" && exit 1
48  eval "${__outputVar}=\$__result"
49 }
50 )EOF";
51 
52 const char* bpp_dynamic_cast = R"EOF(function bpp____dynamic__cast() {
53  local __objectAddress="$1" __type="$2" __outputVar="$3"
54  ([[ -z "${__objectAddress}" ]] || [[ -z "${__type}" ]] || [[ -z "${__outputVar}" ]]) && >&2 echo "Bash++: Error: Invalid dynamic_cast" && exit 1
55  eval "${__outputVar}=0"
56  while [[ ! -z "${!__objectAddress}" ]] 2>/dev/null; do
57  __objectAddress="${!__objectAddress}"
58  done
59  local __vTable="${__objectAddress}____vPointer"
60  while [[ ! -z "${!__vTable}" ]] 2>/dev/null; do
61  [[ "${!__vTable}" == "bpp__${__type}____vTable" ]] && eval "${__outputVar}=\"${__objectAddress}\"" && return 0
62  __vTable="${!__vTable}[\"__parent__\"]"
63  done
64  return 1
65 }
66 )EOF";
67 
68 const char* template_new_function = R"EOF(function bpp__%CLASS%____new() {
69  local __objectAddress="$1"
70  if [[ "${__objectAddress}" == "" ]]; then
71  while : ; do
72  __objectAddress="bpp__%CLASS%__$RANDOM$RANDOM$RANDOM$RANDOM"
73  local __unusedVar="${__objectAddress}____vPointer"
74  [[ -z "${!__unusedVar+x}" ]] && break
75  done
76  fi
77  eval "${__objectAddress}____vPointer=bpp__%CLASS%____vTable"
78 %ASSIGNMENTS%
79  echo "${__objectAddress}"
80 }
81 )EOF";
82 
83 const char* template_delete_function = R"EOF(function bpp__%CLASS%____delete() {
84  local __objectAddress="$1"
85  local __vPointer="${__objectAddress}____vPointer"
86  if [[ "${__objectAddress}" == "0" ]] || [[ -z "${!__vPointer}" ]]; then
87  >&2 echo "Bash++: Error: %CLASS%: Attempted to delete null object"
88  return
89  fi
90 %DELETIONS%
91  unset ${__objectAddress}____vPointer
92 }
93 )EOF";
94 
95 const char* template_copy_function = R"EOF(function bpp__%CLASS%____copy() {
96  local __copyFromAddress="$1" __copyToAddress="$2"
97  local __copyFromVPointer="${__copyFromAddress}____vPointer" __copyToVPointer="${__copyToAddress}____vPointer"
98  if [[ "${__copyFromAddress}" == "0" ]] || [[ -z "${!__copyFromVPointer}" ]]; then
99  >&2 echo "Bash++: Error: %CLASS%: Attempted to copy from null object"
100  return
101  fi
102  if [[ "${__copyToAddress}" == "0" ]] || [[ -z "${!__copyToVPointer}" ]]; then
103  >&2 echo "Bash++: Error: %CLASS%: Attempted to copy to null object"
104  return
105  fi
106 %COPIES%
107  eval "${__copyToVPointer}=${!__copyFromVPointer}"
108 }
109 )EOF";
110 
111 const char* template_method = R"EOF(function bpp__%CLASS%__%SIGNATURE%() {
112  local __objectAddress="$1"
113  shift 1
114  %PARAMS%
115  local __vPointer="${__objectAddress}____vPointer"
116  if [[ "${__objectAddress}" == "0" ]] || [[ -z "${!__vPointer}" ]]; then
117  >&2 echo "Bash++: Error: Attempted to call @%CLASS%.%SIGNATURE% on null object"
118  return
119  fi
120 %METHODBODY%
121 }
122 )EOF";
123 
124 const char* template_constructor = R"EOF(function bpp__%CLASS%____constructor() {
125  local __objectAddress="$1"
126  local __vPointer="${__objectAddress}____vPointer"
127  if [[ "${__objectAddress}" == "0" ]] || [[ -z "${!__vPointer}" ]]; then
128  >&2 echo "Bash++: Error: %CLASS%: Attempted to construct null object"
129  return
130  fi
131 %CONSTRUCTORBODY%
132 }
133 )EOF";
134 
135 const char* template_destructor = R"EOF(function bpp__%CLASS%____destructor() {
136  local __objectAddress="$1"
137  local __vPointer="${__objectAddress}____vPointer"
138  if [[ "${__objectAddress}" == "0" ]] || [[ -z "${!__vPointer}" ]]; then
139  >&2 echo "Bash++: Error: %CLASS%: Attempted to destruct null object"
140  return
141  fi
142 %DESTRUCTORBODY%
143 }
144 )EOF";
145 
146 #endif // SRC_BPP_INCLUDE_TEMPLATES_H_
const char * bpp_vtable_lookup
Definition: templates.h:31
const char * template_delete_function
Definition: templates.h:83
const char * template_destructor
Definition: templates.h:135
const char * template_constructor
Definition: templates.h:124
const char * bpp_dynamic_cast
Definition: templates.h:52
const char * template_new_function
Definition: templates.h:68
const char * bpp_supershell_function
Definition: templates.h:9
const char * template_copy_function
Definition: templates.h:95
const char * template_method
Definition: templates.h:111