Skip to content

Add ability to contain DObjects in DRules #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions languages/DclareMPS/generator/template/main@generator.mps
Original file line number Diff line number Diff line change
Expand Up @@ -7107,6 +7107,31 @@
</node>
</node>
</node>
<node concept="3aamgX" id="5v48sNEOf99" role="3acgRq">
<ref role="30HIoZ" to="7ggn:5v48sNENHIV" resolve="ContainExpression" />
<node concept="gft3U" id="5v48sNEOf9a" role="1lVwrX">
<node concept="2YIFZM" id="5v48sNEOFkH" role="gfFT$">
<ref role="37wK5l" to="u4ym:5v48sNEv_iN" resolve="contain" />
<ref role="1Pybhc" to="u4ym:30fQumnG8Au" resolve="DclareUtil" />
<node concept="10Nm6u" id="5v48sNEOFkL" role="37wK5m">
<node concept="29HgVG" id="5v48sNEOFkM" role="lGtFl">
<node concept="3NFfHV" id="5v48sNEOFkN" role="3NFExx">
<node concept="3clFbS" id="5v48sNEOFkO" role="2VODD2">
<node concept="3clFbF" id="5v48sNEOFkP" role="3cqZAp">
<node concept="2OqwBi" id="5v48sNEOFkQ" role="3clFbG">
<node concept="3TrEf2" id="5v48sNEOFkR" role="2OqNvi">
<ref role="3Tt5mk" to="7ggn:5v48sNENHNw" resolve="expression" />
</node>
<node concept="30H73N" id="5v48sNEOFkS" role="2Oq$k0" />
</node>
</node>
</node>
</node>
</node>
</node>
</node>
</node>
</node>
<node concept="3aamgX" id="4FMPIyKAb_M" role="3acgRq">
<ref role="30HIoZ" to="tp25:3TEgbCBRn3N" resolve="LanguageRefExpression" />
<node concept="gft3U" id="4FMPIyKAij0" role="1lVwrX">
Expand Down
26 changes: 26 additions & 0 deletions languages/DclareMPS/models/constraints.mps
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
<concept id="4693937538533521280" name="jetbrains.mps.lang.smodel.structure.OfConceptOperation" flags="ng" index="v3k3i">
<child id="4693937538533538124" name="requestedConcept" index="v3oSu" />
</concept>
<concept id="1540150895035667832" name="jetbrains.mps.lang.smodel.structure.OperationParm_SameMetaLevel" flags="ng" index="yhA9G" />
<concept id="2396822768958367367" name="jetbrains.mps.lang.smodel.structure.AbstractTypeCastExpression" flags="nn" index="$5XWr">
<child id="6733348108486823193" name="leftExpression" index="1m5AlR" />
<child id="3906496115198199033" name="conceptArgument" index="3oSUPX" />
Expand Down Expand Up @@ -6051,5 +6052,30 @@
</node>
</node>
</node>
<node concept="1M2fIO" id="5v48sNENJ3F">
<property role="3GE5qa" value="expressions" />
<ref role="1M2myG" to="7ggn:5v48sNENHIV" resolve="ContainExpression" />
<node concept="9S07l" id="5v48sNENJ8Z" role="9Vyp8">
<node concept="3clFbS" id="5v48sNENJ90" role="2VODD2">
<node concept="3clFbF" id="5v48sNENJ91" role="3cqZAp">
<node concept="3y3z36" id="5v48sNENJ92" role="3clFbG">
<node concept="10Nm6u" id="5v48sNENJ93" role="3uHU7w" />
<node concept="2OqwBi" id="5v48sNENJ94" role="3uHU7B">
<node concept="nLn13" id="5v48sNENJ95" role="2Oq$k0" />
<node concept="2Xjw5R" id="5v48sNENJ96" role="2OqNvi">
<node concept="1xMEDy" id="5v48sNENJ97" role="1xVPHs">
<node concept="chp4Y" id="5v48sNENJ98" role="ri$Ld">
<ref role="cht4Q" to="7ggn:61p65V8x$6I" resolve="ThisContext" />
</node>
</node>
<node concept="1xIGOp" id="5v48sNENJ99" role="1xVPHs" />
<node concept="yhA9G" id="13G9pej025v" role="1xVPHs" />
</node>
</node>
</node>
</node>
</node>
</node>
</node>
</model>

24 changes: 24 additions & 0 deletions languages/DclareMPS/models/editor.mps
Original file line number Diff line number Diff line change
Expand Up @@ -9042,5 +9042,29 @@
<ref role="2ZyFGn" to="tpee:fz3vP1J" resolve="Expression" />
</node>
</node>
<node concept="24kQdi" id="5v48sNENHOl">
<property role="3GE5qa" value="expressions" />
<ref role="1XX52x" to="7ggn:5v48sNENHIV" resolve="ContainExpression" />
<node concept="3EZMnI" id="5v48sNENHOB" role="2wV5jI">
<node concept="l2Vlx" id="5v48sNENHOC" role="2iSdaV" />
<node concept="3F0ifn" id="5v48sNENHOD" role="3EZMnx">
<property role="3F0ifm" value="contain" />
<node concept="Vb9p2" id="5v48sNENHOE" role="3F10Kt">
<property role="Vbekb" value="g1_k_vY/BOLD" />
</node>
</node>
<node concept="3F0ifn" id="5v48sNENHOF" role="3EZMnx">
<property role="3F0ifm" value="(" />
<ref role="1k5W1q" to="tpen:hY9fg1G" resolve="LeftParenAfterName" />
</node>
<node concept="3F1sOY" id="5v48sNENHOG" role="3EZMnx">
<ref role="1NtTu8" to="7ggn:5v48sNENHNw" resolve="expression" />
</node>
<node concept="3F0ifn" id="5v48sNENHOH" role="3EZMnx">
<property role="3F0ifm" value=")" />
<ref role="1k5W1q" to="tpen:hFCSUmN" resolve="RightParen" />
</node>
</node>
</node>
</model>

15 changes: 15 additions & 0 deletions languages/DclareMPS/models/structure.mps
Original file line number Diff line number Diff line change
Expand Up @@ -1701,5 +1701,20 @@
<ref role="20lvS9" node="4$bpWrNHO7E" resolve="StructClass" />
</node>
</node>
<node concept="1TIwiD" id="5v48sNENHIV">
<property role="EcuMT" value="6324216940731489211" />
<property role="3GE5qa" value="expressions" />
<property role="TrG5h" value="ContainExpression" />
<property role="34LRSv" value="contain(expr)" />
<property role="R4oN_" value="contains the object(s) in the rule" />
<ref role="1TJDcQ" to="tpee:fz3vP1J" resolve="Expression" />
<node concept="1TJgyj" id="5v48sNENHNw" role="1TKVEi">
<property role="IQ2ns" value="6324216940731489504" />
<property role="20lmBu" value="fLJjDmT/aggregation" />
<property role="20kJfa" value="expression" />
<property role="20lbJX" value="fLJekj4/_1" />
<ref role="20lvS9" to="tpee:fz3vP1J" resolve="Expression" />
</node>
</node>
</model>

31 changes: 31 additions & 0 deletions languages/DclareMPS/models/typesystem.mps
Original file line number Diff line number Diff line change
Expand Up @@ -9044,5 +9044,36 @@
<ref role="1YaFvo" to="7ggn:7QGAU2f1kyq" resolve="StructIsInstanceOfOperation" />
</node>
</node>
<node concept="1YbPZF" id="5v48sNENJdY">
<property role="TrG5h" value="typeof_ContainExpression" />
<property role="3GE5qa" value="expressions" />
<node concept="3clFbS" id="5v48sNENJdZ" role="18ibNy">
<node concept="1Z5TYs" id="5v48sNENJel" role="3cqZAp">
<node concept="mw_s8" id="5v48sNENJem" role="1ZfhK$">
<node concept="1Z2H0r" id="5v48sNENJen" role="mwGJk">
<node concept="1YBJjd" id="5v48sNENJeo" role="1Z2MuG">
<ref role="1YBMHb" node="5v48sNENJe1" resolve="containExpression" />
</node>
</node>
</node>
<node concept="mw_s8" id="5v48sNENJep" role="1ZfhKB">
<node concept="1Z2H0r" id="5v48sNENJeq" role="mwGJk">
<node concept="2OqwBi" id="5v48sNENJer" role="1Z2MuG">
<node concept="1YBJjd" id="5v48sNENJes" role="2Oq$k0">
<ref role="1YBMHb" node="5v48sNENJe1" resolve="containExpression" />
</node>
<node concept="3TrEf2" id="5v48sNENJet" role="2OqNvi">
<ref role="3Tt5mk" to="7ggn:5v48sNENHNw" resolve="expression" />
</node>
</node>
</node>
</node>
</node>
</node>
<node concept="1YaCAy" id="5v48sNENJe1" role="1YuTPh">
<property role="TrG5h" value="containExpression" />
<ref role="1YaFvo" to="7ggn:5v48sNENHIV" resolve="ContainExpression" />
</node>
</node>
</model>

Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
public abstract class DObjectType<I> implements MutableClass {

private static final Constant<DObjectType<?>, Set<IRuleSet>> TYPE_RULE_SETS = Constant.of("TYPE_RULE_SETS", Set.of(), t -> t.getLanguages().flatMap(DClareMPS.ACTIVE_RULE_SETS::get).toSet());
private static final Constant<DObjectType<?>, Set<DObserver>> OBSERVERS = Constant.of("OBSERVERS", Set.of(), t -> t.getRules(TYPE_RULE_SETS.get(t)).map(DRule.OBSERVER::get).toSet());
private static final Constant<DObjectType<?>, Set<DRule>> RULES = Constant.of("RULES", Set.of(), t -> t.getRules(TYPE_RULE_SETS.get(t)).toSet());
private static final Constant<DObjectType<?>, Set<DObserver>> OBSERVERS = Constant.of("OBSERVERS", Set.of(), t -> RULES.get(t).map(DRule.OBSERVER::get).toSet());
private static final Constant<DObjectType<?>, List<INative>> NATIVES = Constant.of("NATIVES", List.of(), t -> t.getNatives(TYPE_RULE_SETS.get(t)).sorted(INative::compare).toList());
private static final Constant<DObjectType<?>, Set<DAttribute>> ATTRIBUTES = Constant.of("ATTRIBUTES", Set.of(), t -> t.getAttributes(TYPE_RULE_SETS.get(t)).toSet());
private static final Constant<DObjectType<?>, Set<DAttribute>> RULE_LOCALS = Constant.of("RULE_LOCALS", Set.of(), t -> RULES.get(t).map(r -> (DAttribute) DRule.LOCAL_CONTAINER_ATTRIBUTES.get(r)).toSet());
private static final Constant<DObjectType<?>, Set<DAttribute>> ATTRIBUTES = Constant.of("ATTRIBUTES", Set.of(), t -> t.getAttributes(TYPE_RULE_SETS.get(t)).addAll(RULE_LOCALS.get(t)));
private static final Constant<DObjectType<?>, Set<DAttribute>> CONTAINERS = Constant.of("CONTAINERS", Set.of(), t -> ATTRIBUTES.get(t).filter(DAttribute::isComposite).toSet());
private static final Constant<DObjectType<?>, Set<DAttribute>> NON_SYNTHETICS = Constant.of("NON_SYNTHETICS", Set.of(), t -> ATTRIBUTES.get(t).filter(a -> !a.isSynthetic()).toSet());
private static final Constant<DObjectType<?>, Set<DAttribute>> IDENTIFYING = Constant.of("IDENTIFYING", Set.of(), t -> ATTRIBUTES.get(t).filter(a -> !a.isSynthetic() && a.isIndetifying()).toSet());
Expand Down
25 changes: 23 additions & 2 deletions runtime/src/main/java/org/modelingvalue/dclare/mps/DRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,41 @@
package org.modelingvalue.dclare.mps;

import org.modelingvalue.collections.Collection;
import org.modelingvalue.collections.List;
import org.modelingvalue.collections.Set;
import org.modelingvalue.collections.util.Concurrent;
import org.modelingvalue.collections.util.Context;
import org.modelingvalue.collections.util.Pair;
import org.modelingvalue.dclare.*;

import java.util.ArrayList;

@SuppressWarnings("rawtypes")
public interface DRule<O> extends DFeature {

Constant<DRule, DObserver> OBSERVER = Constant.of("OBSERVER", DObserver::new);
Constant<DRule, DObserver> OBSERVER = Constant.of("OBSERVER", DObserver::new);
Constant<DRule, DAttribute<DObject, Set<DObject>>> LOCAL_CONTAINER_ATTRIBUTES = Constant.of("LOCAL_CONTAINER_ATTRIBUTES", dRule -> new DAttribute.DObservedAttribute<>(dRule, dRule.hashCode() + "", dRule.ruleSet(), false, false, null, Set.class, null, dRule::getSource, SetableModifier.containment, SetableModifier.plumbing));
Context<Set<DObject>> TO_LOCALLY_CONTAIN = Context.of(null);

static void contain(DObject object) {
var tlc = TO_LOCALLY_CONTAIN.get();
TO_LOCALLY_CONTAIN.setOnThread((tlc == null ? Set.<DObject>of() : tlc).add(object));
}

class DObserver<O extends Mutable> extends Observer<O> {

@SuppressWarnings("unchecked")
private DObserver(DRule rule) {
super(rule, rule::run, Collection.of(rule.targets()).toSet(), //
super(rule, (obj) -> {
TO_LOCALLY_CONTAIN.setOnThread(null);
try {
rule.run(obj);
} finally {
LOCAL_CONTAINER_ATTRIBUTES.get(rule).set((DObject) obj, TO_LOCALLY_CONTAIN.get());
TO_LOCALLY_CONTAIN.setOnThread(null);
}
}, //
Collection.of(rule.targets()).toSet(), //
rule.initialLowPriority() ? Priority.outer : Priority.immediate, //
IAspect.DIRECTION.get(rule.ruleSet().getAspect()), //
LeafModifier.anonymous.iff(rule.ruleSet().getAnonymousType() != null), //
Expand Down
99 changes: 99 additions & 0 deletions solutions/DclareMPSRuntime/models/DclareMPSRuntime.util.mps
Original file line number Diff line number Diff line change
Expand Up @@ -7009,6 +7009,105 @@
<node concept="3Tm1VV" id="RraJEThJqr" role="1B3o_S" />
<node concept="3cqZAl" id="RraJETikSZ" role="3clF45" />
</node>
<node concept="2tJIrI" id="5v48sNEuKp_" role="jymVt" />
<node concept="2YIFZL" id="5v48sNEv_iN" role="jymVt">
<property role="TrG5h" value="contain" />
<node concept="3clFbS" id="5v48sNEv_iQ" role="3clF47">
<node concept="3clFbJ" id="5v48sNECqyV" role="3cqZAp">
<node concept="2ZW3vV" id="5v48sNECsnt" role="3clFbw">
<node concept="3uibUv" id="5v48sNECtdX" role="2ZW6by">
<ref role="3uigEE" to="t4tl:~DObject" resolve="DObject" />
</node>
<node concept="37vLTw" id="5v48sNECrrC" role="2ZW6bz">
<ref role="3cqZAo" node="5v48sNEvTTT" resolve="toContain" />
</node>
</node>
<node concept="3clFbS" id="5v48sNECqyX" role="3clFbx">
<node concept="3clFbF" id="4HVexkVRf4g" role="3cqZAp">
<node concept="2YIFZM" id="2qAbdb7y19j" role="3clFbG">
<ref role="37wK5l" to="t4tl:~DRule.contain(org.modelingvalue.dclare.mps.DObject)" resolve="contain" />
<ref role="1Pybhc" to="t4tl:~DRule" resolve="DRule" />
<node concept="1eOMI4" id="5v48sNECyUE" role="37wK5m">
<node concept="10QFUN" id="5v48sNECyUB" role="1eOMHV">
<node concept="3uibUv" id="5v48sNECyUG" role="10QFUM">
<ref role="3uigEE" to="t4tl:~DObject" resolve="DObject" />
</node>
<node concept="37vLTw" id="5v48sNECyUH" role="10QFUP">
<ref role="3cqZAo" node="5v48sNEvTTT" resolve="toContain" />
</node>
</node>
</node>
</node>
</node>
</node>
<node concept="3eNFk2" id="5v48sNEDLk1" role="3eNLev">
<node concept="2ZW3vV" id="5v48sNEFxme" role="3eO9$A">
<node concept="3uibUv" id="5v48sNEFycW" role="2ZW6by">
<ref role="3uigEE" to="wyt6:~Iterable" resolve="Iterable" />
</node>
<node concept="37vLTw" id="5v48sNEFwAi" role="2ZW6bz">
<ref role="3cqZAo" node="5v48sNEvTTT" resolve="toContain" />
</node>
</node>
<node concept="3clFbS" id="5v48sNEDLk3" role="3eOfB_">
<node concept="3clFbF" id="5v48sNEFW8i" role="3cqZAp">
<node concept="2OqwBi" id="5v48sNEFK3g" role="3clFbG">
<node concept="1eOMI4" id="5v48sNEFDtM" role="2Oq$k0">
<node concept="10QFUN" id="5v48sNEFDtJ" role="1eOMHV">
<node concept="3uibUv" id="5v48sNEFDtO" role="10QFUM">
<ref role="3uigEE" to="wyt6:~Iterable" resolve="Iterable" />
</node>
<node concept="37vLTw" id="5v48sNEFDtP" role="10QFUP">
<ref role="3cqZAo" node="5v48sNEvTTT" resolve="toContain" />
</node>
</node>
</node>
<node concept="liA8E" id="5v48sNEFM8a" role="2OqNvi">
<ref role="37wK5l" to="wyt6:~Iterable.forEach(java.util.function.Consumer)" resolve="forEach" />
<node concept="1bVj0M" id="5v48sNEG11A" role="37wK5m">
<node concept="37vLTG" id="5v48sNEG20k" role="1bW2Oz">
<property role="TrG5h" value="e" />
<node concept="3uibUv" id="5v48sNEG3Lc" role="1tU5fm">
<ref role="3uigEE" to="wyt6:~Object" resolve="Object" />
</node>
</node>
<node concept="3clFbS" id="5v48sNEG11B" role="1bW5cS">
<node concept="3clFbF" id="5v48sNEG5$W" role="3cqZAp">
<node concept="1rXfSq" id="5v48sNEG5$V" role="3clFbG">
<ref role="37wK5l" node="5v48sNEv_iN" resolve="contain" />
<node concept="37vLTw" id="5v48sNEG62A" role="37wK5m">
<ref role="3cqZAo" node="5v48sNEG20k" resolve="e" />
</node>
</node>
</node>
</node>
</node>
</node>
</node>
</node>
</node>
</node>
</node>
<node concept="3cpWs6" id="5v48sNEGIY6" role="3cqZAp">
<node concept="37vLTw" id="5v48sNEGL2u" role="3cqZAk">
<ref role="3cqZAo" node="5v48sNEvTTT" resolve="toContain" />
</node>
</node>
</node>
<node concept="3Tm1VV" id="5v48sNEvluV" role="1B3o_S" />
<node concept="37vLTG" id="5v48sNEvTTT" role="3clF46">
<property role="TrG5h" value="toContain" />
<node concept="16syzq" id="5v48sNEvYL7" role="1tU5fm">
<ref role="16sUi3" node="5v48sNEvWma" resolve="T" />
</node>
</node>
<node concept="16euLQ" id="5v48sNEvWma" role="16eVyc">
<property role="TrG5h" value="T" />
</node>
<node concept="16syzq" id="5v48sNEvXWk" role="3clF45">
<ref role="16sUi3" node="5v48sNEvWma" resolve="T" />
</node>
</node>
<node concept="2tJIrI" id="98RYWu1Dqr" role="jymVt" />
</node>
<node concept="2ABs$o" id="rTfv3HeNOH">
Expand Down