Debian Codegraph @

sys/Formula.h

raw symbols SCIP
1 #cxx . . $ `<file>/sys/Formula.h`/ifndef _Formula_h_
2 #define _Formula_h_cxx . . $ `sys/Formula.h:2:9`!
3 /* Formula.h
4 *
5 * Copyright (C) 1990-2005,2007,2008,2011-2020,2023 Paul Boersma
6 *
7 * This code is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This code is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this work. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "Data.h"cxx . . $ `<file>/sys/Data.h`/
22 #include <new>
23
24 #define kFormula_EXPRESSION_TYPE_NUMERICcxx . . $ `sys/Formula.h:24:9`! 0
25 #define kFormula_EXPRESSION_TYPE_STRINGcxx . . $ `sys/Formula.h:25:9`! 1
26 #define kFormula_EXPRESSION_TYPE_NUMERIC_VECTORcxx . . $ `sys/Formula.h:26:9`! 2
27 #define kFormula_EXPRESSION_TYPE_NUMERIC_MATRIXcxx . . $ `sys/Formula.h:27:9`! 3
28 #define kFormula_EXPRESSION_TYPE_NUMERIC_TENSOR3cxx . . $ `sys/Formula.h:28:9`! 4
29 #define kFormula_EXPRESSION_TYPE_NUMERIC_TENSOR4cxx . . $ `sys/Formula.h:29:9`! 5
30 #define kFormula_EXPRESSION_TYPE_STRING_ARRAYcxx . . $ `sys/Formula.h:30:9`! 6
31 #define kFormula_EXPRESSION_TYPE_UNKNOWNcxx . . $ `sys/Formula.h:31:9`! 7
32
33 Thing_declarecxx . . $ autoInterpreterVariable# (InterpreterVariable);
34
35 /*
36 A stack element may be 32 bytes large, so with a stack size of 1'000'000
37 we have 32 MB for the stack. A formula instruction may be 16 bytes large,
38 so we have 16 MB for lexical analysis and 16 MB for the parse.
39 */
40 #define Formula_MAXIMUM_STACK_SIZEcxx . . $ `sys/Formula.h:40:9`! 1'000'000
41
42 /*
43 `Stackel` is short for 'stack element'.
44 */
45 typedef struct structStackelcxx . . $ structStackel# {
46 #define Stackel_NUMBERcxx . . $ `sys/Formula.h:46:10`! 0
47 #define Stackel_STRINGcxx . . $ `sys/Formula.h:47:10`! 1
48 #define Stackel_NUMERIC_VECTORcxx . . $ `sys/Formula.h:48:10`! 2
49 #define Stackel_NUMERIC_MATRIXcxx . . $ `sys/Formula.h:49:10`! 3
50 #define Stackel_NUMERIC_TENSOR3cxx . . $ `sys/Formula.h:50:10`! 4
51 #define Stackel_NUMERIC_TENSOR4cxx . . $ `sys/Formula.h:51:10`! 5
52 #define Stackel_STRING_ARRAYcxx . . $ `sys/Formula.h:52:10`! 6
53 #define Stackel_VARIABLEcxx . . $ `sys/Formula.h:53:10`! -1
54 #define Stackel_OBJECTcxx . . $ `sys/Formula.h:54:10`! -2
55 int whichcxx . . $ structStackel#which.; // 0 or negative = no clean-up required, positive = requires clean-up
56 bool ownedcxx . . $ structStackel#owned.; // relevant only to numeric vector/matrix/tensor3/tensor4/strvec/strmat
57 /*
58 The following member of structStackel can either be a struct or a union.
59 The struct option is the easy option: no special care will have to be taken when assigning to its members.
60 The union option attempts to optimize for space and perhaps speed by putting the variants into a smaller space,
61 but it requires special logic for initialization, deletion, and assignment.
62 The special logic is partly implemented by encapsulating _string as a "private" member.
63 */
64 #define STACKEL_VARIANTS_ARE_PACKED_IN_A_UNIONcxx . . $ `sys/Formula.h:64:10`! 1
65 #if STACKEL_VARIANTS_ARE_PACKED_IN_A_UNIONcxx . . $ `sys/Formula.h:64:10`!
66 unioncxx . . $ structStackel#$anonymous_type_0#
67 #else
68 struct
69 #endif
70 {
71 double numbercxx . . $ structStackel#$anonymous_type_0#number.;
72 autostring32cxx . . $ autostring32# _stringcxx . . $ structStackel#$anonymous_type_0#_string.;
73 Daatacxx . . $ Daata# objectcxx . . $ structStackel#$anonymous_type_0#object.;
74 VECcxx . . $ VEC# numericVectorcxx . . $ structStackel#$anonymous_type_0#numericVector.;
75 MATcxx . . $ MAT# numericMatrixcxx . . $ structStackel#$anonymous_type_0#numericMatrix.;
76 STRVECcxx . . $ STRVEC# stringArraycxx . . $ structStackel#$anonymous_type_0#stringArray.;
77 InterpreterVariablecxx . . $ InterpreterVariable# variablecxx . . $ structStackel#$anonymous_type_0#variable.;
78 };
79 structStackelcxx . . $ structStackel#structStackel(49f6e7a06ebc5aa8). () {
80 memset ((void *) this, 0, sizeof (structStackelcxx . . $ structStackel#)); // union-safe zeroing of all members of structStackel
81 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ourcxx . . $ `melder/melder.h:42:9`! which == Stackel_NUMBERcxx . . $ `sys/Formula.h:46:10`!); // check that on this computer, 0 is represented with zero bits only
82 Melder_assertcxx . . $ abort(15d318a79ddce9e0). (ourcxx . . $ `melder/melder.h:42:9`! number == 0.0); // check that on this computer, 0.0 is represented with zero bits only
83 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! ourcxx . . $ `melder/melder.h:42:9`! _string); // check that on this computer, a plain-old-data null pointer is represented with zero bits only
84 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! ourcxx . . $ `melder/melder.h:42:9`! object); // check that on this computer, a class null pointer is represented with zero bits only
85 Melder_assertcxx . . $ abort(15d318a79ddce9e0). (! ourcxx . . $ `melder/melder.h:42:9`! owned); // check that on this computer, false is represented with zero bits only
86 }
87 void resetcxx . . $ structStackel#reset(49f6e7a06ebc5aa8). () { // union-safe destruction: test which variant we have
88 if (ourcxx . . $ `melder/melder.h:42:9`! whichcxx . . $ structStackel#which. <= Stackel_NUMBERcxx . . $ `sys/Formula.h:46:10`!)
89 return;
90 if (ourcxx . . $ `melder/melder.h:42:9`! whichcxx . . $ structStackel#which. == Stackel_STRINGcxx . . $ `sys/Formula.h:47:10`!) {
91 ourcxx . . $ `melder/melder.h:42:9`! _stringcxx . . $ structStackel#$anonymous_type_0#_string.. resetcxx . . $ _autostring#reset(49f6e7a06ebc5aa8).();
92 } else if (ourcxx . . $ `melder/melder.h:42:9`! whichcxx . . $ structStackel#which. == Stackel_NUMERIC_VECTORcxx . . $ `sys/Formula.h:48:10`!) {
93 if (ourcxx . . $ `melder/melder.h:42:9`! ownedcxx . . $ structStackel#owned.) {
94 {// scope
95 autoVECcxx . . $ autoVEC# removablecxx . . $ autovector#autovector(49f6e7a06ebc5aa8).;
96 removable. adoptFromAmbiguousOwnercxx . . $ autovector#adoptFromAmbiguousOwner(bc17ed9a4b778f50). (ourcxx . . $ `melder/melder.h:42:9`! numericVectorcxx . . $ structStackel#$anonymous_type_0#numericVector.);
97 }
98 ourcxx . . $ `melder/melder.h:42:9`! numericVectorcxx . . $ structStackel#$anonymous_type_0#numericVector. =cxx . . $ vector#`operator=`(b5ebf627ac2fae1e). VECcxx . . $ VEC# (); // undangle
99 }
100 } else if (ourcxx . . $ `melder/melder.h:42:9`! whichcxx . . $ structStackel#which. == Stackel_NUMERIC_MATRIXcxx . . $ `sys/Formula.h:49:10`!) {
101 if (ourcxx . . $ `melder/melder.h:42:9`! ownedcxx . . $ structStackel#owned.) {
102 {// scope
103 autoMATcxx . . $ autoMAT# removablecxx . . $ automatrix#automatrix(49f6e7a06ebc5aa8).;
104 removable. adoptFromAmbiguousOwnercxx . . $ automatrix#adoptFromAmbiguousOwner(eed9513d24570b3d). (ourcxx . . $ `melder/melder.h:42:9`! numericMatrixcxx . . $ structStackel#$anonymous_type_0#numericMatrix.);
105 }
106 ourcxx . . $ `melder/melder.h:42:9`! numericMatrixcxx . . $ structStackel#$anonymous_type_0#numericMatrix. =cxx . . $ matrix#`operator=`(4523e359477ec8fe). MATcxx . . $ MAT# (); // undangle
107 }
108 } else if (ourcxx . . $ `melder/melder.h:42:9`! whichcxx . . $ structStackel#which. == Stackel_STRING_ARRAYcxx . . $ `sys/Formula.h:52:10`!) {
109 if (ourcxx . . $ `melder/melder.h:42:9`! ownedcxx . . $ structStackel#owned.) {
110 {// scope
111 autoSTRVECcxx . . $ autoSTRVEC# removablecxx . . $ _autostringautovector#_autostringautovector(49f6e7a06ebc5aa8).;
112 removable. adoptFromAmbiguousOwnercxx . . $ _autostringautovector#adoptFromAmbiguousOwner(889d620ca03d505c). (ourcxx . . $ `melder/melder.h:42:9`! stringArraycxx . . $ structStackel#$anonymous_type_0#stringArray.);
113 }
114 ourcxx . . $ `melder/melder.h:42:9`! stringArraycxx . . $ structStackel#$anonymous_type_0#stringArray. =cxx . . $ _stringvector#`operator=`(be866ce0e0aaecab). STRVECcxx . . $ STRVEC# (); // undangle
115 }
116 }
117 }
118 ~cxx . . $ structStackel#`~structStackel`(ced63f7c635d850d).structStackelcxx . . $ structStackel# () { // union-safe destruction: test which variant we have
119 ourcxx . . $ `melder/melder.h:42:9`! resetcxx . . $ structStackel#reset(49f6e7a06ebc5aa8).();
120 }
121 structStackelcxx . . $ structStackel#& operatorcxx . . $ structStackel#`operator=`(51a4fe52c0d81ef2).= (structStackelcxx . . $ structStackel#&& other) noexcept { // generalized move assignment
122 if (& other != this) {
123 ourcxx . . $ `melder/melder.h:42:9`! resetcxx . . $ structStackel#reset(49f6e7a06ebc5aa8).();
124 memmove ((void *) this, & other, sizeof (structStackelcxx . . $ structStackel#)); // union-safe: even our biggest variant is bit-copied entirely
125 memset ((void *) & other, 0, sizeof (structStackelcxx . . $ structStackel#)); // union-safe: even the biggest variant in `other` is erased
126 }
127 return *this;
128 }
129 conststring32cxx . . $ conststring32# getStringcxx . . $ structStackel#getString(1912f6684645c851). () {
130 return ourcxx . . $ `melder/melder.h:42:9`! _stringcxx . . $ structStackel#$anonymous_type_0#_string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
131 }
132 autostring32cxx . . $ autostring32# moveStringcxx . . $ structStackel#moveString(19b925b58261db21). () {
133 return ourcxx . . $ _autostring#_autostring(39021ecceedcc7d2). _stringcxx . . $ structStackel#$anonymous_type_0#_string..movecxx . . $ _autostring#move(bd43c759570f178f).();
134 }
135 void setStringcxx . . $ structStackel#setString(c3bcb1467d3e4c86). (autostring32cxx . . $ autostring32# newString) {
136 ourcxx . . $ `melder/melder.h:42:9`! resetcxx . . $ structStackel#reset(49f6e7a06ebc5aa8).();
137 #if STACKEL_VARIANTS_ARE_PACKED_IN_A_UNIONcxx . . $ `sys/Formula.h:64:10`!
138 ::new (& ourcxx . . $ `melder/melder.h:42:9`! _stringcxx . . $ structStackel#$anonymous_type_0#_string.) autostring32cxx . . $ autostring32#(); // a convoluted and type-unsafe, but portable, way to null those 32 or 64 bits
139 #endif
140 ourcxx . . $ `melder/melder.h:42:9`! whichcxx . . $ structStackel#which. = Stackel_STRINGcxx . . $ `sys/Formula.h:47:10`!;
141 ourcxx . . $ `melder/melder.h:42:9`! _stringcxx . . $ structStackel#$anonymous_type_0#_string. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). newString.movecxx . . $ _autostring#move(bd43c759570f178f).();
142 }
143 conststring32cxx . . $ conststring32# whichTextcxx . . $ structStackel#whichText(1912f6684645c851). ();
144 } *Stackelcxx . . $ Stackel#;
145
146 struct Formula_Resultcxx . . $ Formula_Result# {
147 int expressionTypecxx . . $ Formula_Result#expressionType.;
148 double numericResultcxx . . $ Formula_Result#numericResult.;
149 autostring32cxx . . $ autostring32# stringResultcxx . . $ Formula_Result#stringResult.;
150 VECcxx . . $ VEC# numericVectorResultcxx . . $ Formula_Result#numericVectorResult.;
151 MATcxx . . $ MAT# numericMatrixResultcxx . . $ Formula_Result#numericMatrixResult.;
152 STRVECcxx . . $ STRVEC# stringArrayResultcxx . . $ Formula_Result#stringArrayResult.;
153 bool ownedcxx . . $ Formula_Result#owned.;
154 Formula_Resultcxx . . $ Formula_Result#Formula_Result(49f6e7a06ebc5aa8). () {
155 ourcxx . . $ `melder/melder.h:42:9`! expressionTypecxx . . $ Formula_Result#expressionType. = kFormula_EXPRESSION_TYPE_NUMERICcxx . . $ `sys/Formula.h:24:9`!;
156 ourcxx . . $ `melder/melder.h:42:9`! numericResultcxx . . $ Formula_Result#numericResult. = 0.0;
157 ourcxx . . $ `melder/melder.h:42:9`! stringResultcxx . . $ Formula_Result#stringResult. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). autostring32cxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).();
158 ourcxx . . $ `melder/melder.h:42:9`! numericVectorResultcxx . . $ Formula_Result#numericVectorResult. =cxx . . $ vector#`operator=`(b5ebf627ac2fae1e). VECcxx . . $ VEC# ();
159 ourcxx . . $ `melder/melder.h:42:9`! numericMatrixResultcxx . . $ Formula_Result#numericMatrixResult. =cxx . . $ matrix#`operator=`(4523e359477ec8fe). MATcxx . . $ MAT# ();
160 ourcxx . . $ `melder/melder.h:42:9`! stringArrayResultcxx . . $ Formula_Result#stringArrayResult. =cxx . . $ _stringvector#`operator=`(be866ce0e0aaecab). STRVECcxx . . $ STRVEC# ();
161 ourcxx . . $ `melder/melder.h:42:9`! ownedcxx . . $ Formula_Result#owned. = false;
162 }
163 void resetcxx . . $ Formula_Result#reset(49f6e7a06ebc5aa8). () {
164 ourcxx . . $ `melder/melder.h:42:9`! stringResultcxx . . $ Formula_Result#stringResult.. resetcxx . . $ _autostring#reset(49f6e7a06ebc5aa8).();
165 if (ourcxx . . $ `melder/melder.h:42:9`! ownedcxx . . $ Formula_Result#owned.) {
166 {// scope
167 autoVECcxx . . $ autoVEC# removablecxx . . $ autovector#autovector(49f6e7a06ebc5aa8).;
168 removable. adoptFromAmbiguousOwnercxx . . $ autovector#adoptFromAmbiguousOwner(bc17ed9a4b778f50). (ourcxx . . $ `melder/melder.h:42:9`! numericVectorResultcxx . . $ Formula_Result#numericVectorResult.);
169 }
170 ourcxx . . $ `melder/melder.h:42:9`! numericVectorResultcxx . . $ Formula_Result#numericVectorResult. =cxx . . $ vector#`operator=`(b5ebf627ac2fae1e). VECcxx . . $ vector#vector(49f6e7a06ebc5aa8). (); // undangle
171 {// scope
172 autoMATcxx . . $ autoMAT# removablecxx . . $ automatrix#automatrix(49f6e7a06ebc5aa8).;
173 removable. adoptFromAmbiguousOwnercxx . . $ automatrix#adoptFromAmbiguousOwner(eed9513d24570b3d). (ourcxx . . $ `melder/melder.h:42:9`! numericMatrixResultcxx . . $ Formula_Result#numericMatrixResult.);
174 }
175 ourcxx . . $ `melder/melder.h:42:9`! numericMatrixResultcxx . . $ Formula_Result#numericMatrixResult. =cxx . . $ matrix#`operator=`(4523e359477ec8fe). MATcxx . . $ matrix#matrix(49f6e7a06ebc5aa8). (); // undangle
176 {// scope
177 autoSTRVECcxx . . $ autoSTRVEC# removablecxx . . $ _autostringautovector#_autostringautovector(49f6e7a06ebc5aa8).;
178 removable. adoptFromAmbiguousOwnercxx . . $ _autostringautovector#adoptFromAmbiguousOwner(889d620ca03d505c). (ourcxx . . $ `melder/melder.h:42:9`! stringArrayResultcxx . . $ Formula_Result#stringArrayResult.);
179 }
180 ourcxx . . $ `melder/melder.h:42:9`! stringArrayResultcxx . . $ Formula_Result#stringArrayResult. =cxx . . $ _stringvector#`operator=`(be866ce0e0aaecab). STRVECcxx . . $ _stringvector#_stringvector(49f6e7a06ebc5aa8). (); // undangle
181 }
182 }
183 ~cxx . . $ Formula_Result#`~Formula_Result`(ced63f7c635d850d). Formula_Resultcxx . . $ Formula_Result# () {
184 ourcxx . . $ `melder/melder.h:42:9`! resetcxx . . $ Formula_Result#reset(49f6e7a06ebc5aa8).();
185 }
186 };
187
188 Thing_declarecxx . . $ mutableInterpreter# (Interpreter);
189
190 void Formula_compilecxx . . $ Formula_compile(3f9bc12732facfd). (Interpretercxx . . $ Interpreter# interpreter, Daatacxx . . $ Daata# data, conststring32cxx . . $ conststring32# expression, int expressionType, bool optimize);
191
192 void Formula_runcxx . . $ Formula_run(4cd939002183d562). (integercxx . . $ integer# row, integercxx . . $ integer# col, Formula_Resultcxx . . $ Formula_Result# *result);
193
194 /* End of file Formula.h */
195 #endif