Report prescan errors on their source lines
Some checks failed
akbasic CI Build / cmake_build (push) Has been cancelled
akbasic CI Build / sanitizers (push) Has been cancelled
akbasic CI Build / coverage (push) Has been cancelled
akbasic CI Build / akgl_build (push) Has been cancelled
akbasic CI Build / mutation_test (push) Has been cancelled
Some checks failed
akbasic CI Build / cmake_build (push) Has been cancelled
akbasic CI Build / sanitizers (push) Has been cancelled
akbasic CI Build / coverage (push) Has been cancelled
akbasic CI Build / akgl_build (push) Has been cancelled
akbasic CI Build / mutation_test (push) Has been cancelled
This commit is contained in:
@@ -260,11 +260,13 @@ static akerr_ErrorContext *scan_names(akbasic_Runtime *obj)
|
||||
size_t namelen = 0;
|
||||
bool matched = false;
|
||||
const akbasic_Verb *verb = NULL;
|
||||
int64_t entry = obj->environment->lineno;
|
||||
|
||||
for ( i = 0; i < AKBASIC_MAX_SOURCE_LINES; i++ ) {
|
||||
if ( obj->source[i].code[0] == '\0' ) {
|
||||
continue;
|
||||
}
|
||||
obj->environment->lineno = i;
|
||||
cursor = next_word(skip_lineno(obj->source[i].code), word, sizeof(word));
|
||||
|
||||
PASS(errctx, word_is(word, "END", &matched));
|
||||
@@ -327,6 +329,7 @@ static akerr_ErrorContext *scan_names(akbasic_Runtime *obj)
|
||||
|
||||
FAIL_NONZERO_RETURN(errctx, (open >= 0), AKBASIC_ERR_SYNTAX,
|
||||
"TYPE %s is never closed with END TYPE", table->types[open >= 0 ? open : 0].name);
|
||||
obj->environment->lineno = entry;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
@@ -440,7 +443,7 @@ static akerr_ErrorContext *parse_field(akbasic_StructTypeTable *table, akbasic_S
|
||||
* each other by value, which has no finite size. That is the diagnosis rather
|
||||
* than a stack overflow later.
|
||||
*/
|
||||
static akerr_ErrorContext *resolve_sizes(akbasic_StructTypeTable *table)
|
||||
static akerr_ErrorContext *resolve_sizes(akbasic_Runtime *runtime, akbasic_StructTypeTable *table)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
bool progress = true;
|
||||
@@ -477,6 +480,7 @@ static akerr_ErrorContext *resolve_sizes(akbasic_StructTypeTable *table)
|
||||
}
|
||||
|
||||
for ( i = 0; i < table->count; i++ ) {
|
||||
runtime->environment->lineno = table->types[i].firstline;
|
||||
FAIL_NONZERO_RETURN(errctx, (table->types[i].slotcount < 0), AKBASIC_ERR_VALUE,
|
||||
"TYPE %s contains itself by value, so it has no size. "
|
||||
"A type may only refer to itself through PTR TO",
|
||||
@@ -493,9 +497,13 @@ akerr_ErrorContext *akbasic_structtype_scan(akbasic_Runtime *obj)
|
||||
akbasic_StructTypeTable *table = NULL;
|
||||
int64_t i = 0;
|
||||
int t = 0;
|
||||
int64_t entry = 0;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, (obj != NULL), AKERR_NULLPOINTER, "NULL runtime in structtype scan");
|
||||
FAIL_ZERO_RETURN(errctx, (obj->environment != NULL), AKERR_NULLPOINTER,
|
||||
"Runtime has no environment; call akbasic_runtime_init() first");
|
||||
table = &obj->structtypes;
|
||||
entry = obj->environment->lineno;
|
||||
|
||||
/*
|
||||
* Drop what the *script* declared and keep what the *host* registered.
|
||||
@@ -525,10 +533,12 @@ akerr_ErrorContext *akbasic_structtype_scan(akbasic_Runtime *obj)
|
||||
if ( obj->source[i].code[0] == '\0' ) {
|
||||
continue;
|
||||
}
|
||||
obj->environment->lineno = i;
|
||||
PASS(errctx, parse_field(table, type, obj->source[i].code, i));
|
||||
}
|
||||
}
|
||||
|
||||
PASS(errctx, resolve_sizes(table));
|
||||
PASS(errctx, resolve_sizes(obj, table));
|
||||
obj->environment->lineno = entry;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user