forked from solstice/solstice
Fixes for structs
This commit is contained in:
@@ -41,6 +41,72 @@ ResultType(SolsType, charptr) createIdentifiedSolsType(char* in) {
|
||||
}));
|
||||
}
|
||||
|
||||
ResultType(SolsType, charptr) copySolsType(SolsType* type) {
|
||||
SolsType ret = {
|
||||
.type = type->type,
|
||||
.identifierType = NULL,
|
||||
.typeIsKnown = type->typeIsKnown,
|
||||
.needsGroundStruct = type->needsGroundStruct,
|
||||
.returnType = NULL,
|
||||
.children.count = type->children.count,
|
||||
.children.capacity = type->children.capacity,
|
||||
.children.at = NULL
|
||||
};
|
||||
|
||||
if (type->identifierType != NULL) {
|
||||
ret.identifierType = malloc(strlen(type->identifierType) + 1);
|
||||
if (ret.identifierType == NULL) {
|
||||
return Error(SolsType, charptr, "Couldn't allocate memory (in copySolsType() function)");
|
||||
}
|
||||
strcpy(ret.identifierType, type->identifierType);
|
||||
}
|
||||
|
||||
if (type->returnType != NULL) {
|
||||
ResultType(SolsType, charptr) copiedReturn = copySolsType(type->returnType);
|
||||
if (copiedReturn.error) {
|
||||
Estr err = CREATE_ESTR(copiedReturn.as.error);
|
||||
APPEND_ESTR(err, " (in copySolsType() function)");
|
||||
return Error(SolsType, charptr, err.str);
|
||||
}
|
||||
|
||||
ret.returnType = malloc(sizeof(SolsType));
|
||||
if (ret.returnType == NULL) {
|
||||
return Error(SolsType, charptr, "Couldn't allocate memory (in copySolsType() function)");
|
||||
}
|
||||
*ret.returnType = copiedReturn.as.success;
|
||||
}
|
||||
|
||||
if (type->children.capacity > 0) {
|
||||
SolsTypeField* ptr = malloc(sizeof(SolsTypeField) * type->children.capacity);
|
||||
if (ptr == NULL) {
|
||||
return Error(SolsType, charptr, "Couldn't allocate memory (in copySolsType() function)");
|
||||
}
|
||||
ret.children.at = ptr;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < type->children.count; i++) {
|
||||
ResultType(SolsType, charptr) copied = copySolsType(&type->children.at[i].type);
|
||||
if (copied.error) {
|
||||
Estr err = CREATE_ESTR(copied.as.error);
|
||||
APPEND_ESTR(err, " (in copySolsType() function)");
|
||||
return Error(SolsType, charptr, err.str);
|
||||
}
|
||||
ret.children.at[i].type = copied.as.success;
|
||||
|
||||
if (type->children.at[i].name == NULL) {
|
||||
ret.children.at[i].name = NULL;
|
||||
} else {
|
||||
ret.children.at[i].name = malloc(strlen(type->children.at[i].name) + 1);
|
||||
if (ret.children.at[i].name == NULL) {
|
||||
return Error(SolsType, charptr, "Couldn't allocate memory (in copySolsType() function)");
|
||||
}
|
||||
strcpy(ret.children.at[i].name, type->children.at[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
return Success(SolsType, charptr, ret);
|
||||
}
|
||||
/*
|
||||
ResultType(SolsType, charptr) copySolsType(SolsType* type) {
|
||||
SolsType ret = { .type = type->type, .children.count = type->children.count, .children.capacity = type->children.capacity};
|
||||
|
||||
@@ -75,6 +141,7 @@ ResultType(SolsType, charptr) copySolsType(SolsType* type) {
|
||||
}
|
||||
return Success(SolsType, charptr, ret);
|
||||
}
|
||||
*/
|
||||
|
||||
ResultType(Nothing, charptr) addChildToSolsType(SolsType* type, SolsType child, const char* name) {
|
||||
if (type->children.capacity < type->children.count + 1) {
|
||||
|
||||
Reference in New Issue
Block a user