2019-03-23 02:06:09 +02:00
|
|
|
[Inter::Reference::] The Reference Construct.
|
|
|
|
|
|
|
|
Defining the Reference construct.
|
|
|
|
|
|
|
|
@
|
|
|
|
|
|
|
|
@e REFERENCE_IST
|
|
|
|
|
|
|
|
=
|
|
|
|
void Inter::Reference::define(void) {
|
2022-02-08 01:30:40 +02:00
|
|
|
inter_construct *IC = InterConstruct::create_construct(REFERENCE_IST, I"reference");
|
2022-02-09 02:00:30 +02:00
|
|
|
InterConstruct::specify_syntax(IC, I"reference");
|
2022-02-24 01:37:43 +02:00
|
|
|
InterConstruct::fix_instruction_length_between(IC, EXTENT_RCE_IFR, EXTENT_RCE_IFR);
|
2022-02-08 01:30:40 +02:00
|
|
|
InterConstruct::allow_in_depth_range(IC, 1, INFINITELY_DEEP);
|
|
|
|
InterConstruct::permit(IC, INSIDE_CODE_PACKAGE_ICUP);
|
|
|
|
InterConstruct::permit(IC, CAN_HAVE_CHILDREN_ICUP);
|
2019-07-09 08:45:46 +03:00
|
|
|
METHOD_ADD(IC, CONSTRUCT_READ_MTID, Inter::Reference::read);
|
|
|
|
METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, Inter::Reference::write);
|
2022-02-09 12:33:49 +02:00
|
|
|
METHOD_ADD(IC, CONSTRUCT_VERIFY_CHILDREN_MTID, Inter::Reference::verify_children);
|
2019-03-23 02:06:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@
|
|
|
|
|
2022-02-24 01:37:43 +02:00
|
|
|
Used to be BLOCK_RCE_IFLD 2 with extent 3
|
2019-03-23 02:06:09 +02:00
|
|
|
|
2022-02-24 01:37:43 +02:00
|
|
|
@d EXTENT_RCE_IFR 2
|
2019-03-23 02:06:09 +02:00
|
|
|
|
|
|
|
=
|
2019-07-14 12:44:07 +03:00
|
|
|
void Inter::Reference::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
|
2022-03-01 00:24:58 +02:00
|
|
|
if (SymbolAnnotation::nonempty(&(ilp->set))) { *E = InterErrors::plain(I"__annotations are not allowed", eloc); return; }
|
2019-03-23 02:06:09 +02:00
|
|
|
|
2022-02-09 12:33:49 +02:00
|
|
|
*E = InterConstruct::check_level_in_package(IBM, REFERENCE_IST, ilp->indent_level, eloc);
|
2019-07-09 08:45:46 +03:00
|
|
|
if (*E) return;
|
2019-03-23 02:06:09 +02:00
|
|
|
|
2022-02-14 01:44:50 +02:00
|
|
|
inter_package *routine = InterBookmark::package(IBM);
|
2022-03-01 00:24:58 +02:00
|
|
|
if (routine == NULL) { *E = InterErrors::plain(I"'reference' used outside function", eloc); return; }
|
2019-03-23 02:06:09 +02:00
|
|
|
|
2019-07-27 13:16:22 +03:00
|
|
|
*E = Inter::Reference::new(IBM, ilp->indent_level, eloc);
|
2019-03-23 02:06:09 +02:00
|
|
|
}
|
|
|
|
|
2019-07-27 13:16:22 +03:00
|
|
|
inter_error_message *Inter::Reference::new(inter_bookmark *IBM, int level, inter_error_location *eloc) {
|
2022-02-24 01:37:43 +02:00
|
|
|
inter_tree_node *P = Inode::new_with_0_data_fields(IBM, REFERENCE_IST, eloc, (inter_ti) level);
|
|
|
|
inter_error_message *E = Inter::Verify::instruction(InterBookmark::package(IBM), P); if (E) return E;
|
2022-01-27 01:59:02 +02:00
|
|
|
NodePlacement::move_to_moving_bookmark(P, IBM);
|
2019-03-23 02:06:09 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-24 20:15:07 +03:00
|
|
|
void Inter::Reference::write(inter_construct *IC, OUTPUT_STREAM, inter_tree_node *P, inter_error_message **E) {
|
2019-03-23 02:06:09 +02:00
|
|
|
WRITE("reference");
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:15:07 +03:00
|
|
|
void Inter::Reference::verify_children(inter_construct *IC, inter_tree_node *P, inter_error_message **E) {
|
2019-07-10 12:27:52 +03:00
|
|
|
LOOP_THROUGH_INTER_CHILDREN(C, P) {
|
2022-01-30 15:32:38 +02:00
|
|
|
if ((C->W.instruction[0] != INV_IST) && (C->W.instruction[0] != REF_IST) && (C->W.instruction[0] != SPLAT_IST) && (C->W.instruction[0] != VAL_IST) && (C->W.instruction[0] != LABEL_IST)) {
|
2020-05-11 17:21:29 +03:00
|
|
|
*E = Inode::error(C, I"only an inv, a ref, a splat, a val, or a label can be below a reference", NULL);
|
2019-07-08 13:21:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-03-23 02:06:09 +02:00
|
|
|
}
|
2021-09-26 13:01:13 +03:00
|
|
|
|
|
|
|
int Inter::Reference::node_is_ref_to(inter_tree *I, inter_tree_node *P, inter_ti seek_bip) {
|
|
|
|
int reffed = FALSE;
|
2022-01-30 15:32:38 +02:00
|
|
|
while (P->W.instruction[ID_IFLD] == REFERENCE_IST) {
|
2021-09-26 13:01:13 +03:00
|
|
|
P = InterTree::first_child(P);
|
|
|
|
reffed = TRUE;
|
|
|
|
}
|
2022-01-30 15:32:38 +02:00
|
|
|
if (P->W.instruction[ID_IFLD] == INV_IST) {
|
|
|
|
if (P->W.instruction[METHOD_INV_IFLD] == INVOKED_PRIMITIVE) {
|
2021-09-26 13:01:13 +03:00
|
|
|
inter_symbol *prim = Inter::Inv::invokee(P);
|
2022-01-14 12:56:42 +02:00
|
|
|
inter_ti bip = Primitives::to_BIP(I, prim);
|
2021-09-26 13:01:13 +03:00
|
|
|
if ((bip == seek_bip) && (reffed)) return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|