(MOD) Changed returning type of Var_Delete and Array_Delete from "void" to "Status": It requires more plaination when encountering non-alive instances.

(MOD) Implemented Array_Equals.

(MOD) Replaced struct member "description" from InstanceStillAlive from "Given instance was yet alive." to "Given instance was still alive.".

(MOD) Removed String_GetIdx and String_SetIdx:  Meaningless functions.

(MOD) Changed the assignment value of struct member "identity" of macro unknown, normal and error from "nameof(e)" to "e.identity".
This commit is contained in:
2024-06-28 13:32:48 +08:00
parent 9f2b44bf99
commit 8c056d1a39
9 changed files with 83 additions and 132 deletions

View File

@@ -52,9 +52,9 @@ typedef struct {
Status Var_Create(Var *inst, size_t size) throws(InsufficientMemory);
Status Var_CopyOf(Var *inst, Var *other);
Status Var_Delete(Var *inst);
Status Var_Literalise(Var *inst, char *buff);
bool Var_Equals(Var *a, Var *b);
void Var_Delete(Var *inst);
void VarUtils_Swap(Var *v1, Var *v2);
// bool VarUtils_IsIdentityLegal(char *identity);

View File

@@ -1,3 +1,4 @@
#include <Compound/status.h>
#include <Compound/var.h>
Status Var_Create(Var *inst, size_t size)
@@ -14,22 +15,6 @@ Status Var_Create(Var *inst, size_t size)
return apply(NormalStatus);
}
// Status Var_Create(Var *inst, void *addr, size_t size, char *identity)
// {
// /* Skip when inst is unavailable. */
// nonull(inst, apply(UnavailableInstance));
// /* Skip when identity is unavailable. */
// nonull(identity, NullPointerAccounted);
// /* Skip when identity does not pass the examine. */
// state(!VarUtils_IsIdentityLegal(identity), IllegalVarIdentity);
// inst->addr = addr;
// inst->size = size;
// *inst->identity = *identity;
// return apply(NormalStatus);
// }
Status Var_CopyOf(Var *inst, Var *other)
{
/* Skip when inst or other is unavailable. */
@@ -45,34 +30,17 @@ Status Var_CopyOf(Var *inst, Var *other)
return apply(NormalStatus);
}
void Var_Delete(Var *inst)
Status Var_Delete(Var *inst)
{
svoid(!inst || !inst->alive);
nonull(!inst, apply(UnavailableInstance));
state(!inst->alive, apply(InstanceNotAlive));
free(inst->addr);
inst->alive = false;
inst->addr = NULL;
inst->size = 0;
}
// void Var_Delete(Var *inst)
// {
// /* Skip when inst or inst->addr is unavailable. */
// svoid(!inst || inst->addr == NULL);
// inst->addr = NULL;
// inst->size = 0;
// *inst->identity = 0;
// }
void VarUtils_Swap(Var *v1, Var *v2)
{
/* Skip when v1 or v2 is unavailable. */
svoid(!v1 || !v2);
Var v3 = *v1;
*v1 = *v2;
*v2 = v3;
return apply(NormalStatus);
}
Status Var_Literalise(Var *inst, char *buff)
@@ -96,32 +64,12 @@ bool Var_Equals(Var *a, Var *b)
return (a->addr == b->addr && a->size == b->size);
}
// bool VarUtils_IsIdentityLegal(char *identity)
// {
// /* Skip when identity is unavailable. */
// state(identity == NULL, false);
void VarUtils_Swap(Var *v1, Var *v2)
{
/* Skip when v1 or v2 is unavailable. */
svoid(!v1 || !v2);
// const int len = strlen(identity);
// /* Skip when identity is empty. */
// state(len == 0, false);
// /* Skip when the first char is not within alphabet. */
// state(ATRANGE('a', 'z', identity[0])
// || ATRANGE('A', 'Z', identity[0]), false);
// /* Skip when the length of identity is greater that VAR_IDENTITY_LENGTH. */
// state(len > VAR_IDENTITY_LENGTH, false);
// /* Skip when identity has space and illegal characters in it. */
// const int illegal_len = strlen(VAR_IDENTITY_ILLEGAL_CHAR);
// for (register int i = 0; i < len; i++) {
// for (register int j = 0; j < illegal_len; j++) {
// if (identity[i] == VAR_IDENTITY_ILLEGAL_CHAR[j]) {
// return false;
// }
// }
// }
// return true;
// }
Var v3 = *v1;
*v1 = *v2;
*v2 = v3;
}