1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-05 16:44:21 +03:00
inform7/inter/codegen-module/Chapter 2/Uniqueness.w

51 lines
1.6 KiB
OpenEdge ABL
Raw Normal View History

2019-02-05 02:44:07 +02:00
[CodeGen::Uniqueness::] Uniqueness.
To make sure certain symbol names translate into globally unique target symbols.
@h Pipeline stage.
=
void CodeGen::Uniqueness::create_pipeline_stage(void) {
CodeGen::Stage::new(I"make-identifiers-unique", CodeGen::Uniqueness::run_pipeline_stage, NO_STAGE_ARG, FALSE);
}
2019-06-11 02:38:15 +03:00
int CodeGen::Uniqueness::run_pipeline_stage(pipeline_step *step) {
2019-07-13 16:17:48 +03:00
dictionary *D = Dictionaries::new(INITIAL_INTER_SYMBOLS_ID_RANGE, FALSE);
2021-04-16 00:42:28 +03:00
InterTree::traverse(step->repository, CodeGen::Uniqueness::visitor, D, NULL, 0);
return TRUE;
}
2019-02-05 02:44:07 +02:00
typedef struct uniqueness_count {
int count;
2020-05-09 15:07:39 +03:00
CLASS_DEFINITION
2019-02-05 02:44:07 +02:00
} uniqueness_count;
2019-07-24 20:15:07 +03:00
void CodeGen::Uniqueness::visitor(inter_tree *I, inter_tree_node *P, void *state) {
2019-07-13 16:17:48 +03:00
dictionary *D = (dictionary *) state;
2019-07-24 20:15:07 +03:00
if (P->W.data[ID_IFLD] == PACKAGE_IST) {
2019-07-13 16:17:48 +03:00
inter_package *Q = Inter::Package::defined_by_frame(P);
2019-02-05 02:44:07 +02:00
inter_symbols_table *ST = Inter::Packages::scope(Q);
for (int i=0; i<ST->size; i++) {
inter_symbol *S = ST->symbol_array[i];
if ((S) && (S->equated_to == NULL) && (Inter::Symbols::get_flag(S, MAKE_NAME_UNIQUE))) {
text_stream *N = S->symbol_name;
uniqueness_count *U = NULL;
if (Dictionaries::find(D, N)) {
U = (uniqueness_count *) Dictionaries::read_value(D, N);
} else {
U = CREATE(uniqueness_count);
U->count = 0;
Dictionaries::create(D, N);
Dictionaries::write_value(D, N, (void *) U);
}
U->count++;
2020-06-28 01:18:54 +03:00
TEMPORARY_TEXT(T)
2019-02-05 02:44:07 +02:00
WRITE_TO(T, "%S_U%d", N, U->count);
Inter::Symbols::set_translate(S, T);
2020-06-28 01:18:54 +03:00
DISCARD_TEXT(T)
2019-02-05 02:44:07 +02:00
Inter::Symbols::clear_flag(S, MAKE_NAME_UNIQUE);
}
}
}
}