(FEA) Compound is now fully featured with literalisation of Status along with its printting!
This commit is contained in:
@@ -4,7 +4,74 @@ project (Compound)
|
|||||||
|
|
||||||
set(CMAKE_C_COMPILER gcc)
|
set(CMAKE_C_COMPILER gcc)
|
||||||
|
|
||||||
add_compile_options(-g -std=c99 -Wall -Wextra -D__DEBUG__)
|
set(WALL -Waddress
|
||||||
|
-Warray-compare
|
||||||
|
-Warray-parameter=2
|
||||||
|
-Wbool-compare
|
||||||
|
-Wbool-operation
|
||||||
|
-Wchar-subscripts
|
||||||
|
-Wcomment
|
||||||
|
-Wdangling-else
|
||||||
|
-Wdangling-pointer=2
|
||||||
|
-Wenum-compare
|
||||||
|
-Wenum-int-mismatch
|
||||||
|
-Wformat=1
|
||||||
|
-Wformat-contains-nul
|
||||||
|
-Wformat-diag
|
||||||
|
-Wformat-extra-args
|
||||||
|
-Wformat-overflow=1
|
||||||
|
-Wformat-truncation=1
|
||||||
|
-Wformat-zero-length
|
||||||
|
-Wframe-address
|
||||||
|
-Wimplicit
|
||||||
|
-Wimplicit-function-declaration
|
||||||
|
-Wimplicit-int
|
||||||
|
-Winfinite-recursion
|
||||||
|
-Wint-in-bool-context
|
||||||
|
-Wlogical-not-parentheses
|
||||||
|
-Wmain
|
||||||
|
-Wmaybe-uninitialized
|
||||||
|
-Wmemset-elt-size
|
||||||
|
-Wmemset-transposed-args
|
||||||
|
-Wmisleading-indentation
|
||||||
|
-Wmismatched-dealloc
|
||||||
|
-Wmissing-attributes
|
||||||
|
-Wmissing-braces
|
||||||
|
-Wmultistatement-macros
|
||||||
|
-Wnonnull
|
||||||
|
-Wnonnull-compare
|
||||||
|
-Wopenmp-simd
|
||||||
|
-Wpacked-not-aligned
|
||||||
|
-Wparentheses
|
||||||
|
-Wpointer-sign
|
||||||
|
-Wrestrict
|
||||||
|
-Wreturn-type
|
||||||
|
-Wsequence-point
|
||||||
|
-Wsizeof-array-div
|
||||||
|
-Wsizeof-pointer-div
|
||||||
|
-Wsizeof-pointer-memaccess
|
||||||
|
-Wstrict-aliasing
|
||||||
|
-Wstrict-overflow=1
|
||||||
|
-Wswitch
|
||||||
|
-Wtautological-compare
|
||||||
|
-Wtrigraphs
|
||||||
|
-Wuninitialized
|
||||||
|
-Wunknown-pragmas
|
||||||
|
-Wunused
|
||||||
|
-Wunused-but-set-variable
|
||||||
|
-Wunused-const-variable=1
|
||||||
|
-Wunused-function
|
||||||
|
-Wunused-label
|
||||||
|
-Wunused-local-typedefs
|
||||||
|
-Wunused-value
|
||||||
|
-Wunused-variable
|
||||||
|
-Wuse-after-free=2
|
||||||
|
-Wvla-parameter
|
||||||
|
-Wvolatile-register-var
|
||||||
|
-Wzero-length-bounds
|
||||||
|
)
|
||||||
|
|
||||||
|
add_compile_options(-g -std=c99 ${WALL} -Wextra -D__DEBUG__)
|
||||||
|
|
||||||
set(SHARED_SOURCE
|
set(SHARED_SOURCE
|
||||||
MemMan/src/memman.c
|
MemMan/src/memman.c
|
||||||
|
@@ -187,7 +187,8 @@ bool Location_Equals(Location lc1, Location lc2);
|
|||||||
Status Status_Literalise(Status *inst, char *buff);
|
Status Status_Literalise(Status *inst, char *buff);
|
||||||
Status Status_LiteraliseForReport(Status *inst, char *buff);
|
Status Status_LiteraliseForReport(Status *inst, char *buff);
|
||||||
bool Status_Equal(Status *stat1, Status *stat2);
|
bool Status_Equal(Status *stat1, Status *stat2);
|
||||||
void StatusUtils_Dump(Status *inst, Status *store, int idx);
|
// void StatusUtils_Dump(Status *inst, Status **store, int idx);
|
||||||
|
void StatusUtils_Dump(Status *inst, Status *store);
|
||||||
bool StatusUtils_HasPrev(Status inst);
|
bool StatusUtils_HasPrev(Status inst);
|
||||||
bool StatusUtils_IsOkay(Status inst);
|
bool StatusUtils_IsOkay(Status inst);
|
||||||
bool StatusUtils_IsRecursive(Status inst);
|
bool StatusUtils_IsRecursive(Status inst);
|
||||||
@@ -406,28 +407,39 @@ static inline Status PrintStatus(Status s)
|
|||||||
static inline void PrintStatusDump(Status s)
|
static inline void PrintStatusDump(Status s)
|
||||||
{
|
{
|
||||||
/* Create dump. */
|
/* Create dump. */
|
||||||
Status store = s;
|
const int dump_len = StatusUtils_Depth(&s);
|
||||||
const int dump_len = StatusUtils_Depth(&store);
|
|
||||||
Status dump[dump_len];
|
Status dump[dump_len];
|
||||||
StatusUtils_Dump(&store, dump, dump_len);
|
Status current = s;
|
||||||
|
dump[0] = current; // Put self at leading.
|
||||||
|
for (register int i = 1; i < dump_len; i++) {
|
||||||
|
// StatusUtils_Dump will only access (storage) the prev.
|
||||||
|
// It does not include this status itself.
|
||||||
|
StatusUtils_Dump(¤t, &dump[i]);
|
||||||
|
current = *current.prev;
|
||||||
|
}
|
||||||
|
|
||||||
/* Output by iterating. */
|
/* Output by iterating. */
|
||||||
for (register int i = 0; i < dump_len; i++) {
|
for (register int i = 0; i < dump_len; i++) {
|
||||||
seek(PrintStatus(dump[i]), { // Get returning status.
|
|
||||||
|
unsure(PrintStatus(dump[i]), !_.value, {
|
||||||
|
(void)fprintf(stderr, "Unable to literalise.\n");
|
||||||
|
})
|
||||||
|
|
||||||
|
// seek(PrintStatus(dump[i]), { // Get returning status.
|
||||||
|
|
||||||
/* Handle TraditionalFunctionReturn. */
|
// /* Handle TraditionalFunctionReturn. */
|
||||||
nest(_, __, unsure(__, !__.value, { // No bytes were written to buffer.
|
// nest(_, __, unsure(__, !__.value, { // No bytes were written to buffer.
|
||||||
(void)fprintf(stderr, "Unable to literalise.\n");
|
// (void)fprintf(stderr, "Unable to literalise.\n");
|
||||||
return;
|
// return;
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
// Handle abnormal status.
|
// // Handle abnormal status.
|
||||||
nest(_, __, notok(__, {
|
// nest(_, __, notok(__, {
|
||||||
/* Output the description as explanation. */
|
// /* Output the description as explanation. */
|
||||||
(void)fprintf(stderr, "%s\n", __.description);
|
// (void)fprintf(stderr, "%s\n", __.description);
|
||||||
return;
|
// return;
|
||||||
}));
|
// }));
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,11 +6,11 @@ Status Location_Literalise(Location *inst, char *buff)
|
|||||||
nonull(buff, apply(UnavailableBuffer));
|
nonull(buff, apply(UnavailableBuffer));
|
||||||
|
|
||||||
/* Literalise line. */
|
/* Literalise line. */
|
||||||
char line_buff[LITERALISATION_LENGTH_MAXIMUM];
|
char line_buff[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
||||||
Utils_LiteraliseInteger(inst->line, line_buff);
|
Utils_LiteraliseInteger(inst->line, line_buff);
|
||||||
|
|
||||||
where(
|
where(
|
||||||
!snprintf(buff, LITERALISATION_LENGTH_MAXIMUM,
|
snprintf(buff, LITERALISATION_LENGTH_MAXIMUM,
|
||||||
LOCATION_LITERALISE_FORMAT,inst->file,inst->line,inst->func),
|
LOCATION_LITERALISE_FORMAT,inst->file,inst->line,inst->func),
|
||||||
return apply(value(TraditionalFunctionReturn, _));
|
return apply(value(TraditionalFunctionReturn, _));
|
||||||
);
|
);
|
||||||
@@ -48,8 +48,10 @@ Status Status_Literalise(Status *inst, char *buff)
|
|||||||
nonull(buff, apply(UnavailableBuffer));
|
nonull(buff, apply(UnavailableBuffer));
|
||||||
|
|
||||||
/* Literalise loc. */
|
/* Literalise loc. */
|
||||||
char loc_buff[LITERALISATION_LENGTH_MAXIMUM];
|
char loc_buff[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
||||||
notok(Location_Literalise(&inst->loc, loc_buff), {
|
(void)printf("%s\n", loc_buff);
|
||||||
|
unsure(Location_Literalise(&inst->loc, loc_buff), !_.value, {
|
||||||
|
(void)printf("failed on loc liter.\n");
|
||||||
return apply(_);
|
return apply(_);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -107,31 +109,61 @@ bool StatusUtils_IsRecursive(Status stat)
|
|||||||
return (stat.prev && stat.prev == &stat);
|
return (stat.prev && stat.prev == &stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusUtils_Dump(Status *inst, Status *store, int idx)
|
void StatusUtils_Dump(Status *inst, Status *store)
|
||||||
{
|
{
|
||||||
/* Skip when either stat or stat.prev is unavailable, or, idx is invalid. */
|
/* Skip when store is unavailable, or, inst is unavailable,
|
||||||
svoid((!inst || !store || idx < 0));
|
recursive or does not have any predecessor. */
|
||||||
|
svoid(!inst || !store
|
||||||
store[idx] = *inst;
|
|| StatusUtils_IsRecursive(*inst) || !StatusUtils_HasPrev(*inst));
|
||||||
|
|
||||||
StatusUtils_Dump(inst->prev, store, --idx);
|
*store = *inst->prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void StatusUtils_Dump(Status *inst, Status **store, int idx)
|
||||||
|
// {
|
||||||
|
// /* Skip when having invalid inst, store or idx. */
|
||||||
|
// svoid(!inst || !store || idx < 0 || StatusUtils_IsRecursive(*inst));
|
||||||
|
|
||||||
|
// // store[idx] = *inst;
|
||||||
|
// *store[idx] = (Status){
|
||||||
|
// .identity = inst->identity,
|
||||||
|
// .value = inst->value,
|
||||||
|
// .description = inst->description,
|
||||||
|
// .characteristic = inst->characteristic,
|
||||||
|
// .loc = inst->loc,
|
||||||
|
// .prev = inst->prev
|
||||||
|
// };
|
||||||
|
|
||||||
|
// (void)printf("idx: %d\n", idx);
|
||||||
|
|
||||||
|
// StatusUtils_Dump(inst->prev, store, (idx - 1));
|
||||||
|
// }
|
||||||
|
|
||||||
int StatusUtils_Depth(Status *stat)
|
int StatusUtils_Depth(Status *stat)
|
||||||
{
|
{
|
||||||
/* Skip unavailable stat. */
|
/* Skip unavailable stat. */
|
||||||
state((!stat || !stat->prev), -1);
|
state((!stat || !stat->prev), -1);
|
||||||
|
|
||||||
Status *p = stat; // Include this layer of Status.
|
/* Set up counter. */
|
||||||
register int cnt;
|
int cnt = 1;
|
||||||
for (cnt = 0; (!StatusUtils_IsRecursive(*p)
|
/* Set up current status indication representor. */
|
||||||
&& StatusUtils_HasPrev(*p)); cnt++) {
|
Status current = *stat;
|
||||||
(void)printf("Depth: %d\n", cnt);
|
/* Iterate to accumulate. */
|
||||||
p = p->prev;
|
while (current.prev) {
|
||||||
|
current = *current.prev;
|
||||||
|
cnt += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)printf("Depth returns: %d\n", cnt);
|
|
||||||
return cnt;
|
return cnt;
|
||||||
|
|
||||||
|
// Status *current = stat; // Include this layer of Status.
|
||||||
|
// register int cnt;
|
||||||
|
// for (cnt = 0; (!StatusUtils_IsRecursive(*current)
|
||||||
|
// && StatusUtils_HasPrev(*current)); cnt++) {
|
||||||
|
// current = current->prev;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status Report_Create(Report *inst, Status *stat, FILE *dest, char *initiator,
|
Status Report_Create(Report *inst, Status *stat, FILE *dest, char *initiator,
|
||||||
@@ -199,10 +231,10 @@ Status Report_Literalise(Report *inst, char *buff)
|
|||||||
nonull(buff, apply(UnavailableBuffer));
|
nonull(buff, apply(UnavailableBuffer));
|
||||||
|
|
||||||
/* Report literalisation. */
|
/* Report literalisation. */
|
||||||
char report_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
char report_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
||||||
|
|
||||||
/** Status literalisation. **/
|
/** Status literalisation. **/
|
||||||
char status_literalising[LITERALISATION_LENGTH_MAXIMUM];
|
char status_literalising[LITERALISATION_LENGTH_MAXIMUM] = EMPTY;
|
||||||
|
|
||||||
/* Fault detection on status literalisation. */
|
/* Fault detection on status literalisation. */
|
||||||
// settle(Status_LiteraliseForReport(&inst->status, status_literalising),
|
// settle(Status_LiteraliseForReport(&inst->status, status_literalising),
|
||||||
|
Reference in New Issue
Block a user