1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-08 18:14:21 +03:00
inform7/inter/codegen-module/Chapter 2/Reconcile Verbs.w
2019-07-20 23:29:50 +01:00

62 lines
2.1 KiB
OpenEdge ABL

[CodeGen::ReconcileVerbs::] Reconcile Verbs.
To reconcile clashes between assimilated and originally generated verbs.
@h Pipeline stage.
=
void CodeGen::ReconcileVerbs::create_pipeline_stage(void) {
CodeGen::Stage::new(I"reconcile-verbs", CodeGen::ReconcileVerbs::run_pipeline_stage, NO_STAGE_ARG, FALSE);
}
int CodeGen::ReconcileVerbs::run_pipeline_stage(pipeline_step *step) {
CodeGen::ReconcileVerbs::reconcile(step->repository);
return TRUE;
}
@h Parsing.
=
void CodeGen::ReconcileVerbs::reconcile(inter_repository *I) {
dictionary *observed_verbs = Dictionaries::new(1024, TRUE);
Inter::traverse_tree(I, CodeGen::ReconcileVerbs::visitor1, observed_verbs, NULL, 0);
Inter::traverse_tree(I, CodeGen::ReconcileVerbs::visitor2, observed_verbs, NULL, 0);
}
void CodeGen::ReconcileVerbs::visitor1(inter_repository *I, inter_frame P, void *v_state) {
dictionary *observed_verbs = (dictionary *) v_state;
if (P.data[ID_IFLD] == CONSTANT_IST) {
inter_symbol *con_name = Inter::SymbolsTables::symbol_from_frame_data(P, DEFN_CONST_IFLD);
if ((Inter::Symbols::read_annotation(con_name, VERBARRAY_IANN) == 1) &&
(Inter::Symbols::read_annotation(con_name, METAVERB_IANN) != 1))
@<Attend to the verb@>;
}
}
void CodeGen::ReconcileVerbs::visitor2(inter_repository *I, inter_frame P, void *v_state) {
dictionary *observed_verbs = (dictionary *) v_state;
if (P.data[ID_IFLD] == CONSTANT_IST) {
inter_symbol *con_name = Inter::SymbolsTables::symbol_from_frame_data(P, DEFN_CONST_IFLD);
if ((Inter::Symbols::read_annotation(con_name, VERBARRAY_IANN) == 1) &&
(Inter::Symbols::read_annotation(con_name, METAVERB_IANN) == 1))
@<Attend to the verb@>;
}
}
@<Attend to the verb@> =
if (P.extent > DATA_CONST_IFLD+1) {
inter_t V1 = P.data[DATA_CONST_IFLD], V2 = P.data[DATA_CONST_IFLD+1];
if (V1 == DWORD_IVAL) {
text_stream *glob_text = Inter::get_text(I, V2);
if (Dictionaries::find(observed_verbs, glob_text)) {
TEMPORARY_TEXT(nv);
WRITE_TO(nv, "!%S", glob_text);
Str::clear(glob_text);
Str::copy(glob_text, nv);
DISCARD_TEXT(nv);
}
Dictionaries::create(observed_verbs, glob_text);
}
}