Minor code refactoring and cleanup in "conreactor"
This commit is contained in:
parent
760b2d541f
commit
890bc59932
|
|
@ -35,7 +35,7 @@ class Occurrence(val constraint: Constraint,
|
|||
val arguments: List<*>,
|
||||
override val evidence: Evidence,
|
||||
private val justifications: Justifications,
|
||||
val sourceRule: Rule.Tag? = null):
|
||||
val source: Rule?):
|
||||
ConstraintOccurrence, Justified, Reactivatable
|
||||
{
|
||||
|
||||
|
|
@ -51,8 +51,6 @@ class Occurrence(val constraint: Constraint,
|
|||
|
||||
override fun logicalContext(): LogicalContext = logicalContext
|
||||
|
||||
override fun sourceRule(): Rule.Tag? = sourceRule
|
||||
|
||||
override fun justifications(): Justifications = justifications
|
||||
|
||||
override fun reactivate(controller: Controller) = doReactivate(controller)
|
||||
|
|
@ -100,5 +98,5 @@ fun Constraint.occurrence(arguments: List<*>,
|
|||
evidence: Evidence,
|
||||
justifications: Justifications,
|
||||
logicalContext: LogicalContext,
|
||||
ruleUniqueTag: Rule.Tag? = null): Occurrence =
|
||||
Occurrence(this, logicalContext, arguments, evidence, justifications, ruleUniqueTag)
|
||||
rule: Rule? = null): Occurrence =
|
||||
Occurrence(this, logicalContext, arguments, evidence, justifications, rule)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ interface RuleMatchEx : RuleMatch {
|
|||
/**
|
||||
* Returns an array of matched constraint occurrences wrapped in [Id].
|
||||
*/
|
||||
@Deprecated(message = "unused")
|
||||
fun signature(): ArrayList<Id<Occurrence>?>
|
||||
|
||||
fun signatureArray(): IntArray
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ internal class ConstraintsProcessing(
|
|||
fun Constraint.occurrence(
|
||||
arguments: List<*>,
|
||||
logicalContext: LogicalContext,
|
||||
ruleUniqueTag: Rule.Tag? = null
|
||||
rule: Rule?
|
||||
): Occurrence {
|
||||
|
||||
// By default share justifications (as a small optimization)
|
||||
|
|
@ -170,7 +170,7 @@ internal class ConstraintsProcessing(
|
|||
|
||||
return Occurrence(
|
||||
this, logicalContext, arguments, evidence,
|
||||
justifications, ruleUniqueTag
|
||||
justifications, rule
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ internal class ControllerImpl (
|
|||
.then { processGuard(match, it) }
|
||||
|
||||
private fun checkMatchPreconditions(match: RuleMatchEx, inStatus: FeedbackStatus) : FeedbackStatus {
|
||||
val context = Context(inStatus, true, match.logicalContext(), match.rule().uniqueTag(), trace)
|
||||
val context = Context(inStatus, true, match.logicalContext(), match.rule(), trace)
|
||||
|
||||
// invoke matched pattern predicates
|
||||
for (prd in match.patternPredicates()) {
|
||||
|
|
@ -116,7 +116,7 @@ internal class ControllerImpl (
|
|||
}
|
||||
|
||||
private fun processGuard(match: RuleMatchEx, inStatus: FeedbackStatus) : FeedbackStatus {
|
||||
val context = Context(inStatus, match.logicalContext(), match.rule().uniqueTag(), trace)
|
||||
val context = Context(inStatus, match.logicalContext(), match.rule(), trace)
|
||||
|
||||
// check guard
|
||||
for (gprd in match.rule().guard()) {
|
||||
|
|
@ -127,7 +127,7 @@ internal class ControllerImpl (
|
|||
}
|
||||
|
||||
override fun processBody(match: RuleMatchEx, inStatus: FeedbackStatus) : FeedbackStatus {
|
||||
val context = Context(inStatus, match.logicalContext(), match.rule().uniqueTag(), trace)
|
||||
val context = Context(inStatus, match.logicalContext(), match.rule(), trace)
|
||||
|
||||
val altIt = match.rule().bodyAlternation().iterator()
|
||||
while (altIt.hasNext()) {
|
||||
|
|
@ -230,7 +230,7 @@ internal class ControllerImpl (
|
|||
profiler.profile<FeedbackStatus>("activate_${constraint.symbol()}") {
|
||||
|
||||
with(creator) {
|
||||
constraint.occurrence(args, context.logicalContext, context.ruleUniqueTag).let { occ ->
|
||||
constraint.occurrence(args, context.logicalContext, context.rule).let { occ ->
|
||||
trace.activate(occ)
|
||||
processing.processActivated(this@ControllerImpl, occ, status)
|
||||
}
|
||||
|
|
@ -277,7 +277,7 @@ internal class ControllerImpl (
|
|||
inner private class Context(inStatus: FeedbackStatus,
|
||||
val checking: Boolean,
|
||||
val logicalContext: LogicalContext,
|
||||
val ruleUniqueTag: Rule.Tag? = null,
|
||||
val rule: Rule?,
|
||||
val trace: EvaluationTrace = EvaluationTrace.NULL) : InvocationContext
|
||||
{
|
||||
|
||||
|
|
@ -285,9 +285,9 @@ internal class ControllerImpl (
|
|||
|
||||
constructor(inStatus: FeedbackStatus,
|
||||
logicalContext: LogicalContext,
|
||||
ruleUniqueTag: Rule.Tag? = null,
|
||||
rule: Rule? = null,
|
||||
trace: EvaluationTrace = EvaluationTrace.NULL) :
|
||||
this(inStatus, false, logicalContext, ruleUniqueTag, trace) { }
|
||||
this(inStatus, false, logicalContext, rule, trace) { }
|
||||
|
||||
fun currentStatus(): FeedbackStatus = status
|
||||
|
||||
|
|
|
|||
|
|
@ -36,8 +36,4 @@ public interface ConstraintOccurrence {
|
|||
|
||||
LogicalContext logicalContext();
|
||||
|
||||
default Rule.Tag sourceRule() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ import jetbrains.mps.logic.reactor.program.Predicate
|
|||
* @author Fedor Isakov
|
||||
*/
|
||||
|
||||
data class MockConstraint(val symbol: ConstraintSymbol, val arguments: List<Any>, val principal: Boolean = false) : Constraint {
|
||||
data class MockConstraint(val symbol: ConstraintSymbol, val arguments: List<Any>) : Constraint {
|
||||
|
||||
constructor(symbol: ConstraintSymbol, vararg args: Any) : this(symbol, listOf(* args)) {}
|
||||
|
||||
constructor(symbol: ConstraintSymbol, principal: Boolean, vararg args: Any) : this(symbol, listOf(* args), principal) {}
|
||||
constructor(symbol: ConstraintSymbol, principal: Boolean, vararg args: Any) : this(symbol, listOf(* args)) {}
|
||||
|
||||
override fun arguments(): List<Any> = arguments
|
||||
|
||||
|
|
@ -22,8 +22,6 @@ data class MockConstraint(val symbol: ConstraintSymbol, val arguments: List<Any>
|
|||
|
||||
override fun argumentTypes(): List<Class<*>> = arguments.map { arg -> arg.javaClass }
|
||||
|
||||
override fun isPrincipal(): Boolean = principal
|
||||
|
||||
override fun toString(): String = "${symbol()}(${arguments().joinToString()})"
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,10 +104,6 @@ fun occurrence(id: String, vararg args: Any): Occurrence =
|
|||
MockConstraint(ConstraintSymbol.symbol(id, args.size))
|
||||
.occurrence(listOf(* args), 0, justsOf(0), noLogicalContext)
|
||||
|
||||
fun taggedOccurrence(ruleUniqueTag: String, id: String, vararg args: Any): Occurrence =
|
||||
MockConstraint(ConstraintSymbol.symbol(id, args.size))
|
||||
.occurrence(listOf(* args), 0, justsOf(0), noLogicalContext, Rule.Tag(ruleUniqueTag))
|
||||
|
||||
fun justifiedOccurrence(id: String, evidence: Evidence, justifications: Justifications, principal: Boolean, vararg args: Any): Occurrence =
|
||||
MockConstraint(ConstraintSymbol.symbol(id, args.size), principal)
|
||||
.occurrence(listOf(* args), evidence, justifications, noLogicalContext)
|
||||
|
|
|
|||
Loading…
Reference in New Issue