2019-02-05 02:44:07 +02:00
|
|
|
[Inter::Verify::] Verifying Inter.
|
|
|
|
|
|
|
|
Verifying that a chunk of inter is correct and consistent.
|
|
|
|
|
|
|
|
@ =
|
2019-07-24 20:15:07 +03:00
|
|
|
inter_error_message *Inter::Verify::defn(inter_package *owner, inter_tree_node *P, int index) {
|
2022-01-31 01:49:12 +02:00
|
|
|
inter_symbols_table *T = InterPackage::scope(owner);
|
2020-05-11 17:21:29 +03:00
|
|
|
if (T == NULL) T = Inode::globals(P);
|
2022-02-03 17:51:44 +02:00
|
|
|
inter_symbol *S = InterSymbolsTable::symbol_from_ID_not_equating(T, P->W.instruction[index]);
|
2020-05-11 17:21:29 +03:00
|
|
|
if (S == NULL) return Inode::error(P, I"no symbol for ID (case 1)", NULL);
|
2022-01-04 01:40:23 +02:00
|
|
|
if (Wiring::is_wired(S)) {
|
|
|
|
inter_symbol *E = Wiring::cable_end(S);
|
|
|
|
LOG("This is $6 but $3 is wired to $3 in $6\n",
|
2022-01-31 01:49:12 +02:00
|
|
|
InterPackage::container(P), S, E, InterPackage::container(E->definition));
|
2020-05-11 17:21:29 +03:00
|
|
|
return Inode::error(P, I"symbol defined outside its native scope", S->symbol_name);
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|
2022-02-03 21:44:57 +02:00
|
|
|
inter_tree_node *D = InterSymbol::definition(S);
|
|
|
|
if (D == NULL) InterSymbol::define(S, P);
|
2022-01-29 02:21:23 +02:00
|
|
|
else if (Inode::same_instruction(D, P) == FALSE) {
|
2022-02-03 21:44:57 +02:00
|
|
|
if (InterSymbol::is_predeclared(S)) {
|
|
|
|
InterSymbol::define(S, P);
|
2019-02-05 02:44:07 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2021-05-05 14:24:08 +03:00
|
|
|
LOG("So S ---> %S\n", S->translate_text);
|
2020-05-11 17:21:29 +03:00
|
|
|
return Inode::error(P, I"duplicated symbol", S->symbol_name);
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:15:07 +03:00
|
|
|
inter_error_message *Inter::Verify::local_defn(inter_tree_node *P, int index, inter_symbols_table *T) {
|
2022-02-03 17:51:44 +02:00
|
|
|
inter_symbol *S = InterSymbolsTable::symbol_from_ID(T, P->W.instruction[index]);
|
2020-05-11 17:21:29 +03:00
|
|
|
if (S == NULL) return Inode::error(P, I"no symbol for ID (case 2)", NULL);
|
2022-02-03 21:44:57 +02:00
|
|
|
if ((InterSymbol::is_defined(S)) &&
|
|
|
|
(InterSymbol::is_predeclared_local(S) == FALSE))
|
2020-05-11 17:21:29 +03:00
|
|
|
return Inode::error(P, I"duplicated local symbol", S->symbol_name);
|
2022-02-03 21:44:57 +02:00
|
|
|
InterSymbol::define(S, P);
|
2019-02-05 02:44:07 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-01 02:58:55 +03:00
|
|
|
inter_error_message *Inter::Verify::symbol(inter_package *owner, inter_tree_node *P, inter_ti ID, inter_ti construct) {
|
2022-01-31 01:49:12 +02:00
|
|
|
inter_symbols_table *T = InterPackage::scope(owner);
|
2020-05-11 17:21:29 +03:00
|
|
|
if (T == NULL) T = Inode::globals(P);
|
2022-02-03 17:51:44 +02:00
|
|
|
inter_symbol *S = InterSymbolsTable::symbol_from_ID(T, ID);
|
2020-05-11 17:21:29 +03:00
|
|
|
if (S == NULL) return Inode::error(P, I"no symbol for ID (case 3)", NULL);
|
2022-02-03 21:44:57 +02:00
|
|
|
inter_tree_node *D = InterSymbol::definition(S);
|
|
|
|
if (InterSymbol::is_extern(S)) return NULL;
|
|
|
|
if (InterSymbol::is_predeclared(S)) return NULL;
|
2020-05-11 17:21:29 +03:00
|
|
|
if (D == NULL) return Inode::error(P, I"undefined symbol", S->symbol_name);
|
2022-01-30 15:32:38 +02:00
|
|
|
if ((D->W.instruction[ID_IFLD] != construct) &&
|
2022-02-03 21:44:57 +02:00
|
|
|
(InterSymbol::is_extern(S) == FALSE) &&
|
|
|
|
(InterSymbol::is_predeclared(S) == FALSE)) {
|
2020-05-11 17:21:29 +03:00
|
|
|
return Inode::error(P, I"symbol of wrong type", S->symbol_name);
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-01 02:58:55 +03:00
|
|
|
inter_error_message *Inter::Verify::global_symbol(inter_tree_node *P, inter_ti ID, inter_ti construct) {
|
2022-02-03 17:51:44 +02:00
|
|
|
inter_symbol *S = InterSymbolsTable::symbol_from_ID(Inode::globals(P), ID);
|
2020-05-11 17:21:29 +03:00
|
|
|
if (S == NULL) { internal_error("IO"); return Inode::error(P, I"3no symbol for ID", NULL); }
|
2022-02-03 21:44:57 +02:00
|
|
|
inter_tree_node *D = InterSymbol::definition(S);
|
|
|
|
if (InterSymbol::is_extern(S)) return NULL;
|
|
|
|
if (InterSymbol::is_predeclared(S)) return NULL;
|
2020-05-11 17:21:29 +03:00
|
|
|
if (D == NULL) return Inode::error(P, I"undefined symbol", S->symbol_name);
|
2022-01-30 15:32:38 +02:00
|
|
|
if ((D->W.instruction[ID_IFLD] != construct) &&
|
2022-02-03 21:44:57 +02:00
|
|
|
(InterSymbol::is_extern(S) == FALSE) &&
|
|
|
|
(InterSymbol::is_predeclared(S) == FALSE)) {
|
2020-05-11 17:21:29 +03:00
|
|
|
return Inode::error(P, I"symbol of wrong type", S->symbol_name);
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-01 02:58:55 +03:00
|
|
|
inter_error_message *Inter::Verify::local_symbol(inter_tree_node *P, inter_ti ID, inter_ti construct, inter_symbols_table *T) {
|
2022-02-03 17:51:44 +02:00
|
|
|
inter_symbol *S = InterSymbolsTable::symbol_from_ID(T, ID);
|
2020-05-11 17:21:29 +03:00
|
|
|
if (S == NULL) return Inode::error(P, I"4no symbol for ID", NULL);
|
2022-02-03 21:44:57 +02:00
|
|
|
inter_tree_node *D = InterSymbol::definition(S);
|
|
|
|
if (InterSymbol::is_extern(S)) return NULL;
|
|
|
|
if (InterSymbol::is_predeclared(S)) return NULL;
|
2020-05-11 17:21:29 +03:00
|
|
|
if (D == NULL) return Inode::error(P, I"undefined symbol", S->symbol_name);
|
2022-01-30 15:32:38 +02:00
|
|
|
if ((D->W.instruction[ID_IFLD] != construct) &&
|
2022-02-03 21:44:57 +02:00
|
|
|
(InterSymbol::is_extern(S) == FALSE) &&
|
|
|
|
(InterSymbol::is_predeclared(S) == FALSE)) {
|
2020-05-11 17:21:29 +03:00
|
|
|
return Inode::error(P, I"symbol of wrong type", S->symbol_name);
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-01 02:58:55 +03:00
|
|
|
inter_error_message *Inter::Verify::symbol_KOI(inter_package *owner, inter_tree_node *P, inter_ti ID) {
|
2022-01-31 01:49:12 +02:00
|
|
|
inter_symbols_table *T = InterPackage::scope(owner);
|
2020-05-11 17:21:29 +03:00
|
|
|
if (T == NULL) T = Inode::globals(P);
|
2022-02-03 17:51:44 +02:00
|
|
|
inter_symbol *S = InterSymbolsTable::symbol_from_ID(T, ID);
|
2020-05-11 17:21:29 +03:00
|
|
|
if (S == NULL) return Inode::error(P, I"5no symbol for ID", NULL);
|
2022-02-03 21:44:57 +02:00
|
|
|
inter_tree_node *D = InterSymbol::definition(S);
|
|
|
|
if (InterSymbol::is_extern(S)) return NULL;
|
|
|
|
if (InterSymbol::is_predeclared(S)) return NULL;
|
2020-05-11 17:21:29 +03:00
|
|
|
if (D == NULL) return Inode::error(P, I"undefined symbol", S->symbol_name);
|
2022-01-30 15:32:38 +02:00
|
|
|
if ((D->W.instruction[ID_IFLD] != KIND_IST) &&
|
2022-02-03 21:44:57 +02:00
|
|
|
(InterSymbol::is_extern(S) == FALSE) &&
|
2022-01-30 15:32:38 +02:00
|
|
|
(D->W.instruction[ID_IFLD] != INSTANCE_IST) &&
|
2022-02-03 21:44:57 +02:00
|
|
|
(InterSymbol::is_predeclared(S) == FALSE)) return Inode::error(P, I"symbol of wrong type", S->symbol_name);
|
2019-02-05 02:44:07 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:15:07 +03:00
|
|
|
inter_error_message *Inter::Verify::data_type(inter_tree_node *P, int index) {
|
2022-01-30 15:32:38 +02:00
|
|
|
inter_ti ID = P->W.instruction[index];
|
2019-02-05 02:44:07 +02:00
|
|
|
inter_data_type *idt = Inter::Types::find_by_ID(ID);
|
2020-05-11 17:21:29 +03:00
|
|
|
if (idt == NULL) return Inode::error(P, I"unknown data type", NULL);
|
2019-02-05 02:44:07 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:15:07 +03:00
|
|
|
inter_error_message *Inter::Verify::value(inter_package *owner, inter_tree_node *P, int index, inter_symbol *kind_symbol) {
|
2022-01-31 01:49:12 +02:00
|
|
|
inter_symbols_table *T = InterPackage::scope(owner);
|
2020-05-11 17:21:29 +03:00
|
|
|
if (T == NULL) T = Inode::globals(P);
|
|
|
|
if (kind_symbol == NULL) return Inode::error(P, I"unknown kind for value", NULL);
|
2022-01-30 15:32:38 +02:00
|
|
|
inter_ti V1 = P->W.instruction[index];
|
|
|
|
inter_ti V2 = P->W.instruction[index+1];
|
2019-07-12 13:33:52 +03:00
|
|
|
return Inter::Types::verify(P, kind_symbol, V1, V2, T);
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|
|
|
|
|
2019-07-24 20:15:07 +03:00
|
|
|
inter_error_message *Inter::Verify::local_value(inter_tree_node *P, int index, inter_symbol *kind_symbol, inter_symbols_table *T) {
|
2020-05-11 17:21:29 +03:00
|
|
|
if (kind_symbol == NULL) return Inode::error(P, I"unknown kind for value", NULL);
|
2022-01-30 15:32:38 +02:00
|
|
|
inter_ti V1 = P->W.instruction[index];
|
|
|
|
inter_ti V2 = P->W.instruction[index+1];
|
2019-02-05 02:44:07 +02:00
|
|
|
return Inter::Types::verify(P, kind_symbol, V1, V2, T);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Inter::Verify::writer(OUTPUT_STREAM, char *format_string, void *vI) {
|
2019-07-24 20:15:07 +03:00
|
|
|
inter_tree_node *F = (inter_tree_node *) vI;
|
2019-02-05 02:44:07 +02:00
|
|
|
if (F == NULL) { WRITE("<no frame>"); return; }
|
2019-07-24 20:15:07 +03:00
|
|
|
WRITE("%05d -> ", F->W.index);
|
|
|
|
WRITE("%d {", F->W.extent);
|
2022-01-30 15:32:38 +02:00
|
|
|
for (int i=0; i<F->W.extent; i++) WRITE(" %08x", F->W.instruction[i]);
|
2019-02-05 02:44:07 +02:00
|
|
|
WRITE(" }");
|
|
|
|
}
|