1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-17 14:34:25 +03:00
inform7/inter/bytecode-module/Chapter 4/The PropertyValue Construct.w

150 lines
6.8 KiB
OpenEdge ABL
Raw Normal View History

2019-02-05 02:44:07 +02:00
[Inter::PropertyValue::] The PropertyValue Construct.
Defining the propertyvalue construct.
@
@e PROPERTYVALUE_IST
=
void Inter::PropertyValue::define(void) {
inter_construct *IC = InterConstruct::create_construct(PROPERTYVALUE_IST, I"propertyvalue");
InterConstruct::specify_syntax(IC, I"propertyvalue IDENTIFIER IDENTIFIER = TOKENS");
2022-02-24 01:37:43 +02:00
InterConstruct::fix_instruction_length_between(IC, EXTENT_PVAL_IFR, EXTENT_PVAL_IFR);
InterConstruct::permit(IC, INSIDE_PLAIN_PACKAGE_ICUP);
2019-07-09 08:45:46 +03:00
METHOD_ADD(IC, CONSTRUCT_READ_MTID, Inter::PropertyValue::read);
METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, Inter::PropertyValue::verify);
METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, Inter::PropertyValue::write);
2019-02-05 02:44:07 +02:00
}
@
@d PROP_PVAL_IFLD 2
@d OWNER_PVAL_IFLD 3
@d DVAL1_PVAL_IFLD 4
@d DVAL2_PVAL_IFLD 5
@d EXTENT_PVAL_IFR 6
=
2019-07-14 12:44:07 +03:00
void Inter::PropertyValue::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
2022-02-09 12:33:49 +02:00
*E = InterConstruct::check_level_in_package(IBM, PROPERTYVALUE_IST, ilp->indent_level, eloc);
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
if (SymbolAnnotation::nonempty(&(ilp->set))) { *E = Inter::Errors::plain(I"__annotations are not allowed", eloc); return; }
2019-02-05 02:44:07 +02:00
2022-02-11 12:48:26 +02:00
inter_symbol *prop_name = TextualInter::find_symbol(IBM, eloc, ilp->mr.exp[0], PROPERTY_IST, E);
2019-07-09 08:45:46 +03:00
if (*E) return;
inter_symbol *owner_name = Inter::PropertyValue::parse_owner(eloc, InterBookmark::scope(IBM), ilp->mr.exp[1], E);
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
2020-07-01 02:58:55 +03:00
inter_ti plist_ID;
2022-02-23 01:31:47 +02:00
if (Inter::Typename::is(owner_name)) plist_ID = Inter::Typename::properties_list(owner_name);
2019-02-05 02:44:07 +02:00
else plist_ID = Inter::Instance::properties_list(owner_name);
2022-01-30 15:32:38 +02:00
inter_node_list *FL = InterWarehouse::get_node_list(InterBookmark::warehouse(IBM), plist_ID);
2019-02-05 02:44:07 +02:00
if (FL == NULL) internal_error("no properties list");
2019-07-24 20:15:07 +03:00
inter_tree_node *X;
LOOP_THROUGH_INTER_NODE_LIST(X, FL) {
2022-02-03 17:51:44 +02:00
inter_symbol *prop_X = InterSymbolsTable::symbol_from_ID_at_node(X, PROP_PVAL_IFLD);
2019-02-05 02:44:07 +02:00
if (prop_X == prop_name)
2019-07-09 08:45:46 +03:00
{ *E = Inter::Errors::quoted(I"property already given", ilp->mr.exp[0], eloc); return; }
2019-02-05 02:44:07 +02:00
}
inter_type val_type = InterTypes::of_symbol(prop_name);
2020-07-01 02:58:55 +03:00
inter_ti con_val1 = 0;
inter_ti con_val2 = 0;
2022-02-21 15:05:50 +02:00
*E = InterValuePairs::parse(ilp->line, eloc, IBM, val_type, ilp->mr.exp[2], &con_val1, &con_val2, InterBookmark::scope(IBM));
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
2022-02-03 17:51:44 +02:00
*E = Inter::PropertyValue::new(IBM, InterSymbolsTable::id_from_symbol_at_bookmark(IBM, prop_name), InterSymbolsTable::id_from_symbol_at_bookmark(IBM, owner_name),
2020-07-01 02:58:55 +03:00
con_val1, con_val2, (inter_ti) ilp->indent_level, eloc);
2019-02-05 02:44:07 +02:00
}
inter_symbol *Inter::PropertyValue::parse_owner(inter_error_location *eloc, inter_symbols_table *T, text_stream *name, inter_error_message **E) {
*E = NULL;
inter_symbol *symb = InterSymbolsTable::symbol_from_name(T, name);
if (symb == NULL) { *E = Inter::Errors::quoted(I"no such symbol", name, eloc); return NULL; }
inter_tree_node *D = InterSymbol::definition(symb);
if (D == NULL) { *E = Inter::Errors::quoted(I"undefined symbol", name, eloc); return NULL; }
2022-02-23 01:31:47 +02:00
if ((D->W.instruction[ID_IFLD] != TYPENAME_IST) &&
(D->W.instruction[ID_IFLD] != INSTANCE_IST)) { *E = Inter::Errors::quoted(I"symbol of wrong type", name, eloc); return NULL; }
return symb;
}
2019-07-24 20:15:07 +03:00
int Inter::PropertyValue::permitted(inter_tree_node *F, inter_package *pack, inter_symbol *owner, inter_symbol *prop_name) {
2020-07-01 02:58:55 +03:00
inter_ti plist_ID;
2022-02-23 01:31:47 +02:00
if (Inter::Typename::is(owner)) plist_ID = Inter::Typename::permissions_list(owner);
2019-02-05 02:44:07 +02:00
else plist_ID = Inter::Instance::permissions_list(owner);
2020-05-11 17:21:29 +03:00
inter_node_list *FL = Inode::ID_to_frame_list(F, plist_ID);
2019-07-24 20:15:07 +03:00
inter_tree_node *X;
LOOP_THROUGH_INTER_NODE_LIST(X, FL) {
2022-02-03 17:51:44 +02:00
inter_symbol *prop_allowed = InterSymbolsTable::symbol_from_ID_at_node(X, PROP_PERM_IFLD);
2019-02-05 02:44:07 +02:00
if (prop_allowed == prop_name)
return TRUE;
}
inter_symbol *inst_kind;
2022-02-23 01:31:47 +02:00
if (Inter::Typename::is(owner)) inst_kind = Inter::Typename::super(owner);
2019-02-05 02:44:07 +02:00
else inst_kind = Inter::Instance::kind_of(owner);
while (inst_kind) {
inter_node_list *FL =
2022-02-23 01:31:47 +02:00
Inode::ID_to_frame_list(F, Inter::Typename::permissions_list(inst_kind));
2019-02-05 02:44:07 +02:00
if (FL == NULL) internal_error("no permissions list");
2019-07-24 20:15:07 +03:00
inter_tree_node *X;
LOOP_THROUGH_INTER_NODE_LIST(X, FL) {
2022-02-03 17:51:44 +02:00
inter_symbol *prop_allowed = InterSymbolsTable::symbol_from_ID_at_node(X, PROP_PERM_IFLD);
2019-02-05 02:44:07 +02:00
if (prop_allowed == prop_name)
return TRUE;
}
2022-02-23 01:31:47 +02:00
inst_kind = Inter::Typename::super(inst_kind);
2019-02-05 02:44:07 +02:00
}
return FALSE;
}
2020-07-01 02:58:55 +03:00
inter_error_message *Inter::PropertyValue::new(inter_bookmark *IBM, inter_ti PID, inter_ti OID,
inter_ti con_val1, inter_ti con_val2, inter_ti level, inter_error_location *eloc) {
2022-01-28 01:38:14 +02:00
inter_tree_node *P = Inode::new_with_4_data_fields(IBM, PROPERTYVALUE_IST,
2019-02-05 02:44:07 +02:00
PID, OID, con_val1, con_val2, eloc, level);
2022-02-24 01:37:43 +02:00
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-02-05 02:44:07 +02:00
return NULL;
}
2019-07-24 20:15:07 +03:00
void Inter::PropertyValue::verify(inter_construct *IC, inter_tree_node *P, inter_package *owner, inter_error_message **E) {
2022-02-24 01:37:43 +02:00
*E = Inter::Verify::SID_field(owner, P, PROP_PVAL_IFLD, PROPERTY_IST); if (*E) return;
*E = Inter::Verify::POID_field(owner, P, OWNER_PVAL_IFLD); if (*E) return;
2019-02-05 02:44:07 +02:00
2022-02-24 01:37:43 +02:00
inter_symbol *prop_name = InterSymbolsTable::symbol_from_ID(InterPackage::scope(owner), P->W.instruction[PROP_PVAL_IFLD]);;
inter_symbol *owner_name = InterSymbolsTable::symbol_from_ID(InterPackage::scope(owner), P->W.instruction[OWNER_PVAL_IFLD]);;
2019-02-05 02:44:07 +02:00
2022-02-24 01:37:43 +02:00
if (Inter::PropertyValue::permitted(P, owner, owner_name, prop_name) == FALSE) {
text_stream *err = Str::new();
WRITE_TO(err, "no permission for '%S' have this property", InterSymbol::identifier(owner_name));
*E = Inode::error(P, err, InterSymbol::identifier(prop_name)); return;
}
2019-02-05 02:44:07 +02:00
2022-02-24 01:37:43 +02:00
inter_ti plist_ID;
if (Inter::Typename::is(owner_name)) plist_ID = Inter::Typename::properties_list(owner_name);
else plist_ID = Inter::Instance::properties_list(owner_name);
2019-02-05 02:44:07 +02:00
2022-02-24 01:37:43 +02:00
inter_node_list *FL = Inode::ID_to_frame_list(P, plist_ID);
if (FL == NULL) internal_error("no properties list");
2019-02-05 02:44:07 +02:00
2022-02-24 01:37:43 +02:00
inter_tree_node *X;
LOOP_THROUGH_INTER_NODE_LIST(X, FL) {
if (X->W.instruction[PROP_PVAL_IFLD] == P->W.instruction[PROP_PVAL_IFLD]) { *E = Inode::error(P, I"duplicate property value", NULL); return; }
if (X->W.instruction[OWNER_PVAL_IFLD] != P->W.instruction[OWNER_PVAL_IFLD]) { *E = Inode::error(P, I"instance property list malformed", NULL); return; }
2019-02-05 02:44:07 +02:00
}
2022-02-24 01:37:43 +02:00
InterNodeList::add(FL, P);
2019-02-05 02:44:07 +02:00
}
2019-07-24 20:15:07 +03:00
void Inter::PropertyValue::write(inter_construct *IC, OUTPUT_STREAM, inter_tree_node *P, inter_error_message **E) {
2022-02-03 17:51:44 +02:00
inter_symbol *prop_name = InterSymbolsTable::symbol_from_ID_at_node(P, PROP_PVAL_IFLD);
inter_symbol *owner_name = InterSymbolsTable::symbol_from_ID_at_node(P, OWNER_PVAL_IFLD);
2019-02-05 02:44:07 +02:00
if ((prop_name) && (owner_name)) {
WRITE("propertyvalue %S %S = ", InterSymbol::identifier(prop_name), InterSymbol::identifier(owner_name));
2022-02-21 15:05:50 +02:00
InterValuePairs::write(OUT, P, P->W.instruction[DVAL1_PVAL_IFLD], P->W.instruction[DVAL2_PVAL_IFLD], InterPackage::scope_of(P), FALSE);
2020-05-11 17:21:29 +03:00
} else { *E = Inode::error(P, I"cannot write propertyvalue", NULL); return; }
2019-02-05 02:44:07 +02:00
}