2020-10-11 17:05:00 +03:00
|
|
|
#include "conCaseHelper.h"
|
2021-07-17 05:59:32 +03:00
|
|
|
#include "refc_util.h"
|
2020-10-11 17:05:00 +03:00
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
AConAlt *newConstructorField(int nr) {
|
|
|
|
AConAlt *retVal = (AConAlt *)malloc(nr * sizeof(AConAlt));
|
|
|
|
IDRIS2_REFC_VERIFY(retVal, "malloc failed");
|
|
|
|
for (int i = 0; i < nr; i++) {
|
|
|
|
retVal[i].tag = -1;
|
|
|
|
}
|
|
|
|
return retVal;
|
2020-10-11 17:05:00 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
void freeConstructorField(AConAlt *cf) { free(cf); }
|
2020-10-11 17:05:00 +03:00
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
void constructorFieldFNextEntry(AConAlt *field, char *name, int tag) {
|
|
|
|
AConAlt *nextEntry = field;
|
|
|
|
while (nextEntry->tag == -1) {
|
|
|
|
nextEntry++;
|
|
|
|
}
|
|
|
|
nextEntry->name = name;
|
|
|
|
nextEntry->tag = tag;
|
2020-10-11 17:05:00 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
int compareConstructors(Value *sc, AConAlt *field, int nr) {
|
|
|
|
Value_Constructor *constr = (Value_Constructor *)sc;
|
|
|
|
for (int i = 0; i < nr; i++) {
|
|
|
|
if (field->name) // decide my name
|
|
|
|
{
|
|
|
|
if (!strcmp(field->name, constr->name)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
} else // decide by tag
|
2020-10-11 17:05:00 +03:00
|
|
|
{
|
2022-09-21 13:13:15 +03:00
|
|
|
if (field->tag == constr->tag) {
|
|
|
|
return i;
|
|
|
|
}
|
2020-10-11 17:05:00 +03:00
|
|
|
}
|
2022-09-21 13:13:15 +03:00
|
|
|
field++;
|
|
|
|
}
|
|
|
|
return -1;
|
2020-10-11 17:05:00 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
int multiStringCompare(Value *sc, int nrDecicionOptions, char **options) {
|
|
|
|
for (int i = 0; i < nrDecicionOptions; i++) {
|
|
|
|
if (!strcmp(((Value_String *)sc)->str, options[i])) {
|
|
|
|
return i;
|
2020-10-11 17:05:00 +03:00
|
|
|
}
|
2022-09-21 13:13:15 +03:00
|
|
|
}
|
|
|
|
return -1;
|
2020-10-11 17:05:00 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
int multiDoubleCompare(Value *sc, int nrDecicionOptions, double *options) {
|
|
|
|
for (int i = 0; i < nrDecicionOptions; i++) {
|
|
|
|
if (((Value_Double *)sc)->d == options[i]) {
|
|
|
|
return i;
|
2020-10-11 17:05:00 +03:00
|
|
|
}
|
2022-09-21 13:13:15 +03:00
|
|
|
}
|
|
|
|
return -1;
|
2020-10-11 17:05:00 +03:00
|
|
|
}
|