Minor fixes of inspection results and typos
This commit is contained in:
parent
63c2786476
commit
31ea3fab65
|
|
@ -16,22 +16,16 @@
|
|||
|
||||
package jetbrains.mps.logic.reactor.core
|
||||
|
||||
import jetbrains.mps.logic.reactor.evaluation.EvaluationFeedback
|
||||
import jetbrains.mps.logic.reactor.evaluation.RuleMatch
|
||||
import jetbrains.mps.logic.reactor.evaluation.Supervisor
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.Arrays
|
||||
|
||||
/**
|
||||
* @author Fedor Isakov
|
||||
*/
|
||||
class CompositeFeedback private constructor(private val elements: List<Feedback>) : Feedback() {
|
||||
private val severity: EvaluationFeedback.Severity
|
||||
|
||||
init {
|
||||
this.severity = maxSeverity(elements)
|
||||
}
|
||||
private val severity: Severity = maxSeverity(elements)
|
||||
|
||||
override fun handle(currentRuleMatch: RuleMatch, feedbackKey: Any, feedbackBasis: List<Any>, supervisor: Supervisor): Boolean {
|
||||
var unhandled = 0
|
||||
|
|
@ -55,7 +49,7 @@ class CompositeFeedback private constructor(private val elements: List<Feedback>
|
|||
}
|
||||
}
|
||||
|
||||
override fun getSeverity(): EvaluationFeedback.Severity {
|
||||
override fun getSeverity(): Severity {
|
||||
return severity
|
||||
}
|
||||
|
||||
|
|
@ -109,23 +103,23 @@ class CompositeFeedback private constructor(private val elements: List<Feedback>
|
|||
left ?: right
|
||||
|
||||
} else (left as? CompositeFeedback)?.composeRight(right)
|
||||
?: ((right as? CompositeFeedback)?.composeLeft(left) ?: CompositeFeedback(Arrays.asList(left, right)))
|
||||
?: ((right as? CompositeFeedback)?.composeLeft(left) ?: CompositeFeedback(listOf(left, right)))
|
||||
}
|
||||
|
||||
fun dropLast(mayberComposite: Feedback?): Feedback? =
|
||||
if (mayberComposite == null || mayberComposite !is CompositeFeedback) {
|
||||
fun dropLast(maybeComposite: Feedback?): Feedback? =
|
||||
if (maybeComposite == null || maybeComposite !is CompositeFeedback) {
|
||||
null
|
||||
} else if (mayberComposite.elements.size > 2) {
|
||||
CompositeFeedback(mayberComposite.elements.dropLast(1))
|
||||
} else if (mayberComposite.elements.size == 2) {
|
||||
mayberComposite.elements[0]
|
||||
} else if (maybeComposite.elements.size > 2) {
|
||||
CompositeFeedback(maybeComposite.elements.dropLast(1))
|
||||
} else if (maybeComposite.elements.size == 2) {
|
||||
maybeComposite.elements[0]
|
||||
} else throw NoSuchElementException()
|
||||
|
||||
|
||||
private fun maxSeverity(efs: List<Feedback>): EvaluationFeedback.Severity {
|
||||
var sev: EvaluationFeedback.Severity = EvaluationFeedback.Severity.DEBUG
|
||||
private fun maxSeverity(efs: List<Feedback>): Severity {
|
||||
var sev: Severity = Severity.DEBUG
|
||||
for (ef in efs) {
|
||||
if (ef.severity.compareTo(sev) > 0) {
|
||||
if (ef.severity > sev) {
|
||||
sev = ef.severity
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package jetbrains.mps.logic.reactor.core
|
||||
|
||||
import jetbrains.mps.logic.reactor.core.internal.ConstraintsProcessing
|
||||
import jetbrains.mps.logic.reactor.core.internal.FeedbackStatus
|
||||
import jetbrains.mps.logic.reactor.core.internal.MatchJournal
|
||||
import jetbrains.mps.logic.reactor.evaluation.PredicateInvocation
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package jetbrains.mps.logic.reactor.core
|
||||
|
||||
import jetbrains.mps.logic.reactor.evaluation.EvaluationFeedback
|
||||
|
||||
/**
|
||||
* Encapsulates a detailed report to be provided by the code being evaluated.
|
||||
* Does not affect the evaluation flow.
|
||||
|
|
|
|||
|
|
@ -23,14 +23,12 @@ typealias DispatchingFrontState = Map<Any, RuleMatcher>
|
|||
|
||||
internal fun emptyFrontState(): DispatchingFrontState = emptyMap()
|
||||
|
||||
internal fun DispatchingFrontState.resetLookup() = apply { values.forEach(RuleMatcher::resetRuleLookup) }
|
||||
|
||||
/**
|
||||
* A front-end interface to [RuleMatcher].
|
||||
*
|
||||
* @author Fedor Isakov
|
||||
*/
|
||||
class Dispatcher (val ruleIndex: RuleIndex, prevState: DispatchingFrontState = emptyFrontState()) {
|
||||
class Dispatcher (val ruleIndex: RuleIndex) {
|
||||
|
||||
private val ruletag2matcher = HashMap<Any, RuleMatcher>()
|
||||
|
||||
|
|
@ -105,9 +103,7 @@ class Dispatcher (val ruleIndex: RuleIndex, prevState: DispatchingFrontState = e
|
|||
* be excluded from any further "match" set returned by [matches].
|
||||
*/
|
||||
internal fun consume(consumedMatch: RuleMatchEx): DispatchingFront {
|
||||
ruletag2probe[consumedMatch.rule().uniqueTag()]?.let {
|
||||
val probe = it.consume(consumedMatch)
|
||||
}
|
||||
ruletag2probe[consumedMatch.rule().uniqueTag()]?.consume(consumedMatch)
|
||||
return DispatchingFront(this)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,11 +17,8 @@
|
|||
package jetbrains.mps.logic.reactor.core
|
||||
|
||||
import jetbrains.mps.logic.reactor.evaluation.EvaluationFailureException
|
||||
import jetbrains.mps.logic.reactor.evaluation.EvaluationFeedback
|
||||
import jetbrains.mps.logic.reactor.evaluation.Solver
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
/**
|
||||
*
|
||||
* Possible kinds of failure:
|
||||
|
|
|
|||
|
|
@ -56,6 +56,5 @@ abstract class Feedback : EvaluationFeedback() {
|
|||
}
|
||||
|
||||
typealias FeedbackKeySet = Set<Any>
|
||||
typealias MutableFeedbackKeySet = MutableSet<Any>
|
||||
|
||||
internal val RuleMatch.feedbackKey: Any get() = System.identityHashCode(this)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ fun justsCopy(other: Justifications): Justifications = TIntHashSet(other)
|
|||
/**
|
||||
* A logical entity whose existence is supported by some
|
||||
* facts (or premises, or evidences, or justifications).
|
||||
* Hence it is said that its existence is justified by them.
|
||||
* Hence, it is said that its existence is justified by them.
|
||||
* In its turn can serve as an evidence for other justified entities.
|
||||
*/
|
||||
interface Justified {
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package jetbrains.mps.logic.reactor.core
|
||||
|
||||
import jetbrains.mps.logic.reactor.core.internal.LogicalImpl
|
||||
import jetbrains.mps.logic.reactor.core.internal.LogicalState
|
||||
import jetbrains.mps.logic.reactor.logical.Logical
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -46,10 +46,6 @@ class Occurrence (observable: LogicalStateObservable,
|
|||
|
||||
val identity = System.identityHashCode(this)
|
||||
|
||||
init {
|
||||
// revive(observable)
|
||||
}
|
||||
|
||||
override fun constraint(): Constraint = constraint
|
||||
|
||||
override fun arguments(): List<*> = arguments
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import jetbrains.mps.logic.reactor.util.PersMap
|
|||
|
||||
/**
|
||||
* Abstracts an algorithm for recursive matching of a [Constraint] and a [ConstraintOccurrence]
|
||||
* or a pattern [Term] against a [Term] in a constraint occurrence's arguments.
|
||||
* or a pattern [jetbrains.mps.unification.Term] against a [jetbrains.mps.unification.Term] in a constraint occurrence's arguments.
|
||||
*
|
||||
* @author Fedor Isakov
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -38,16 +38,7 @@ fun ruleBitsOf() = indexMaskOf()
|
|||
*/
|
||||
class RuleIndex(): Iterable<Rule>, RuleLookup
|
||||
{
|
||||
private class IndexedRule {
|
||||
|
||||
constructor(idx: Int, rule: Rule) {
|
||||
this.idx = idx
|
||||
this.rule = rule
|
||||
}
|
||||
|
||||
var idx: Int
|
||||
val rule: Rule
|
||||
}
|
||||
private class IndexedRule(var idx: Int, val rule: Rule)
|
||||
|
||||
// Terminology:
|
||||
// ruleBit - rule's index in the rules list
|
||||
|
|
@ -193,7 +184,7 @@ class RuleIndex(): Iterable<Rule>, RuleLookup
|
|||
* The mask tells whether or not a particular constraint occurrence can match
|
||||
* any of the rule's constraints.
|
||||
*/
|
||||
private class SlotMask() {
|
||||
private class SlotMask {
|
||||
|
||||
val symbol2mask = HashMap<Symbol, BitSet>()
|
||||
|
||||
|
|
@ -259,7 +250,7 @@ class RuleIndex(): Iterable<Rule>, RuleLookup
|
|||
is Term ->
|
||||
termSelectors[argIdx].remove(arg, ruleBit, headPos)
|
||||
is Any ->
|
||||
value2indices.get(arg)?.remove(ruleBit to headPos)
|
||||
value2indices[arg]?.remove(ruleBit to headPos)
|
||||
else ->
|
||||
throw NullPointerException() // never happens
|
||||
}
|
||||
|
|
@ -333,12 +324,12 @@ class RuleIndex(): Iterable<Rule>, RuleLookup
|
|||
}
|
||||
}
|
||||
|
||||
if (!refined) {
|
||||
return if (!refined) {
|
||||
// no arguments or all arguments are wildcards
|
||||
return symbolSelector to slotMasks
|
||||
|
||||
symbolSelector to slotMasks
|
||||
|
||||
} else {
|
||||
return selectedRuleBits to slotMasks
|
||||
selectedRuleBits to slotMasks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ interface RuleMatcher {
|
|||
|
||||
fun probe(): RuleMatchingProbe
|
||||
|
||||
fun setRuleLookup(ruleLookup: RuleLookup): Unit
|
||||
fun setRuleLookup(ruleLookup: RuleLookup)
|
||||
|
||||
fun resetRuleLookup(): Unit
|
||||
fun resetRuleLookup()
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -49,8 +49,6 @@ fun createRuleMatcher(lookup: RuleLookup, tag: Any): RuleMatcher = ReteRuleMatch
|
|||
// Trove stuff
|
||||
typealias Signature = TIntList
|
||||
|
||||
fun noSignature(): Signature = TIntArrayList(0)
|
||||
|
||||
fun Signature.copy() = TIntArrayList(this)
|
||||
|
||||
fun IntArray.toSignature() = TIntArrayList(this)
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@ internal class ControllerImpl (
|
|||
try {
|
||||
block().let {
|
||||
if (!it.isOk()) {
|
||||
failure = EvaluationFailure(it);
|
||||
failure = EvaluationFailure(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,11 +27,6 @@ import java.util.*
|
|||
* @author Fedor Isakov
|
||||
*/
|
||||
|
||||
|
||||
internal typealias OccurrenceStore = Collection<Occurrence>
|
||||
|
||||
internal fun emptyStore(): OccurrenceStore = emptyList()
|
||||
|
||||
/**
|
||||
* Handles creation of the first and following sessions,
|
||||
* properly ending sessions and getting their results.
|
||||
|
|
@ -83,7 +78,7 @@ internal class EvaluationSessionImpl private constructor (
|
|||
val params: Map<ParameterKey<*>, *>?) : EvaluationSession()
|
||||
{
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : Any> parameter(key: ParameterKey<T>): T? = params ?.get(key) as T
|
||||
override fun <T : Any> parameter(key: ParameterKey<T>): T = params ?.get(key) as T
|
||||
|
||||
private fun launch(token: SessionToken?, main: Constraint): EvaluationResult {
|
||||
val sessionProcessing: DefaultProcessingSession = DefaultProcessingSession()
|
||||
|
|
@ -122,7 +117,7 @@ internal class EvaluationSessionImpl private constructor (
|
|||
val status = run(main)
|
||||
controller.shutDown()
|
||||
val newToken = endSession(session)
|
||||
return EvaluationResultImpl(newToken, status, emptySet(), emptyList())
|
||||
return EvaluationResultImpl(newToken, status)
|
||||
}
|
||||
|
||||
protected fun SessionParts.run(main: Constraint): FeedbackStatus = controller.activate(main)
|
||||
|
|
@ -189,11 +184,11 @@ internal class EvaluationSessionImpl private constructor (
|
|||
val ourBackend = Backend()
|
||||
|
||||
fun init() {
|
||||
EvaluationSession.setBackend(ourBackend)
|
||||
setBackend(ourBackend)
|
||||
}
|
||||
|
||||
fun deinit() {
|
||||
EvaluationSession.clearBackend(ourBackend)
|
||||
clearBackend(ourBackend)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -202,14 +197,10 @@ internal class EvaluationSessionImpl private constructor (
|
|||
private class EvaluationResultImpl(
|
||||
val token: SessionToken,
|
||||
val status: FeedbackStatus,
|
||||
val invalidFeedbackKeys: FeedbackKeySet,
|
||||
val invalidRules: Collection<Any>
|
||||
): EvaluationResult {
|
||||
override fun token() = token
|
||||
override fun storeView(): StoreView = token.storeView
|
||||
override fun feedback(): EvaluationFeedback? = if (status is FAILED) status.failure else null
|
||||
override fun invalidFeedbackKeys(): Collection<Any> = invalidFeedbackKeys
|
||||
override fun invalidRules(): Collection<Any> = invalidRules
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package jetbrains.mps.logic.reactor.core.internal
|
||||
|
||||
import jetbrains.mps.logic.reactor.core.LogicalObserver
|
||||
import jetbrains.mps.logic.reactor.logical.LogicalOwner
|
||||
import jetbrains.mps.logic.reactor.logical.MutableLogical
|
||||
import jetbrains.mps.logic.reactor.logical.MetaLogical
|
||||
import java.util.ArrayList
|
||||
|
|
@ -38,26 +37,24 @@ internal class LogicalImpl<T> : MutableLogical<T> {
|
|||
|
||||
var rank = 0
|
||||
|
||||
var usagesCount = 0
|
||||
|
||||
val valueObservers = ArrayList<Pair<LogicalImpl<*>, LogicalObserver>>()
|
||||
|
||||
val parentObservers = ArrayList<Pair<LogicalImpl<*>, LogicalObserver>>()
|
||||
|
||||
constructor(value: T) {
|
||||
this.name = "$${++lastIdx}"
|
||||
this.metaLogical = DefaultMetaLogical<T>(name)
|
||||
this.metaLogical = DefaultMetaLogical(name)
|
||||
this._value = value
|
||||
}
|
||||
|
||||
constructor(name: String) {
|
||||
this.name = "${name}_${++lastIdx}"
|
||||
this.metaLogical = DefaultMetaLogical<T>(name)
|
||||
this.metaLogical = DefaultMetaLogical(name)
|
||||
}
|
||||
|
||||
constructor(name: String, value: T) {
|
||||
this.name = "${name}_${++lastIdx}"
|
||||
this.metaLogical = DefaultMetaLogical<T>(name)
|
||||
this.metaLogical = DefaultMetaLogical(name)
|
||||
this._value = value
|
||||
}
|
||||
|
||||
|
|
@ -122,19 +119,19 @@ internal class LogicalImpl<T> : MutableLogical<T> {
|
|||
// first copy the value
|
||||
if (thisVal == null && otherVal != null) {
|
||||
// var ground
|
||||
thisRepr.setValue(otherVal);
|
||||
thisRepr.setValue(otherVal)
|
||||
// TODO: clear the value in the "other" logical after union
|
||||
|
||||
} else if (thisVal != null && otherVal == null) {
|
||||
// ground var
|
||||
// TODO: no need to copy the value
|
||||
otherRepr.setValue(thisVal);
|
||||
otherRepr.setValue(thisVal)
|
||||
}
|
||||
|
||||
// reconcile the values/merge value observers
|
||||
if (thisVal == null && otherVal == null) {
|
||||
// var var
|
||||
thisRepr.mergeValueObservers(otherRepr);
|
||||
thisRepr.mergeValueObservers(otherRepr)
|
||||
|
||||
} else if (thisVal != null && otherVal != null) {
|
||||
// ground ground
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ import gnu.trove.TIntObjectHashMap
|
|||
import jetbrains.mps.logic.reactor.core.*
|
||||
import jetbrains.mps.logic.reactor.evaluation.*
|
||||
import jetbrains.mps.logic.reactor.program.*
|
||||
import jetbrains.mps.logic.reactor.util.Id
|
||||
import java.util.*
|
||||
|
||||
typealias ChunkIndex = TIntObjectHashMap<MatchJournal.Chunk>
|
||||
|
||||
|
|
|
|||
|
|
@ -167,11 +167,11 @@ internal open class MatchJournalImpl(
|
|||
|
||||
override fun initialChunk(): MatchChunk = initialChunk
|
||||
|
||||
override fun parentChunk(): MatchChunk = ancestorChunksStack.peek()!!
|
||||
override fun parentChunk(): MatchChunk = ancestorChunksStack.peek()
|
||||
|
||||
override fun currentPos(): MatchJournal.Pos = __cursor.currentPos()
|
||||
override fun currentPos(): Pos = __cursor.currentPos()
|
||||
|
||||
override fun reset(pastPos: MatchJournal.Pos) {
|
||||
override fun reset(pastPos: Pos) {
|
||||
__cursor.moveToPastRemoving(pastPos) {
|
||||
popParentChunk()
|
||||
resetOccurrences(it.entries())
|
||||
|
|
@ -189,7 +189,7 @@ internal open class MatchJournalImpl(
|
|||
}
|
||||
|
||||
// Note: returns View for the whole history regardless of current posPtr
|
||||
override fun view() = MatchJournal.View(ArrayList(hist), evidenceSeed)
|
||||
override fun view() = View(ArrayList(hist), evidenceSeed)
|
||||
|
||||
override fun storeView(): StoreView = StoreViewImpl(allOccurrences())
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ internal open class MatchJournalImpl(
|
|||
}
|
||||
}
|
||||
|
||||
internal infix fun ChunkIterator.assertAt(pos: MatchJournal.Pos) {
|
||||
internal infix fun ChunkIterator.assertAt(pos: Pos) {
|
||||
if (!(this at pos))
|
||||
throw IllegalStateException("Position wasn't found in journal: $pos")
|
||||
}
|
||||
|
|
@ -373,7 +373,7 @@ internal open class MatchJournalImpl(
|
|||
|
||||
object EmptyRule : Rule() {
|
||||
override fun kind(): Kind = Kind.PROPAGATION
|
||||
override fun uniqueTag(): Tag = Rule.Tag("__initial_rule__")
|
||||
override fun uniqueTag(): Tag = Tag("__initial_rule__")
|
||||
override fun headKept(): Iterable<Constraint> = emptyList()
|
||||
override fun headReplaced(): Iterable<Constraint> = emptyList()
|
||||
override fun guard(): Iterable<Predicate> = emptyList()
|
||||
|
|
|
|||
|
|
@ -16,12 +16,8 @@
|
|||
|
||||
package jetbrains.mps.logic.reactor.core.internal
|
||||
|
||||
import jetbrains.mps.logic.reactor.core.Controller
|
||||
import jetbrains.mps.logic.reactor.core.ForwardingLogicalObserver
|
||||
import jetbrains.mps.logic.reactor.core.LogicalStateObservable
|
||||
import jetbrains.mps.logic.reactor.core.Occurrence
|
||||
import jetbrains.mps.logic.reactor.logical.Logical
|
||||
import jetbrains.mps.unification.Term
|
||||
|
||||
|
||||
typealias ObserverTriggeredHandler = (Occurrence) -> Boolean
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import kotlin.collections.ArrayList
|
|||
*
|
||||
* Loosely based on "Rete network" algorithm.
|
||||
*
|
||||
* The implementation of [RuleMatchingProbe] returned from [probe] method is not a persistent object, it's rather
|
||||
* The implementation of [RuleMatchingProbe] returned from [ReteRuleMatcherImpl.probe] method is not a persistent object, it's rather
|
||||
* a mutable object which updates its state through usual update methods that all return the same object.
|
||||
*
|
||||
* @author Fedor Isakov
|
||||
|
|
@ -42,8 +42,6 @@ fun trailOf(): Trail = TIntHashSet()
|
|||
|
||||
fun Signature.toTrail() = TIntHashSet(this)
|
||||
|
||||
typealias SignatureIndex = TIntObjectHashMap<List<Signature>>
|
||||
|
||||
fun signatureIndexOf() = TIntObjectHashMap<MutableList<Signature>>()
|
||||
|
||||
internal class ReteRuleMatcherImpl(private var ruleLookup: RuleLookup?,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package jetbrains.mps.logic.reactor.core.internal
|
|||
import jetbrains.mps.logic.reactor.core.Occurrence
|
||||
import jetbrains.mps.logic.reactor.core.RuleMatchEx
|
||||
import jetbrains.mps.logic.reactor.core.Subst
|
||||
import jetbrains.mps.logic.reactor.evaluation.ConstraintOccurrence
|
||||
import jetbrains.mps.logic.reactor.logical.Logical
|
||||
import jetbrains.mps.logic.reactor.logical.LogicalContext
|
||||
import jetbrains.mps.logic.reactor.logical.LogicalOwner
|
||||
|
|
|
|||
|
|
@ -83,8 +83,6 @@ class TermWalker(vararg visitors: TermVisitor<out Term>) {
|
|||
}
|
||||
}
|
||||
|
||||
internal fun Term.unboundLogicals(): Collection<Logical<*>> = logicalsWhere { !it.isBound }
|
||||
|
||||
internal inline fun Term.logicalsWhere(crossinline where: (Logical<*>) -> Boolean): Collection<Logical<*>> {
|
||||
val collected = arrayListOf<Logical<*>>()
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,9 @@
|
|||
package jetbrains.mps.logic.reactor.evaluation;
|
||||
|
||||
|
||||
import gnu.trove.set.TIntSet;
|
||||
import gnu.trove.set.hash.TIntHashSet;
|
||||
import jetbrains.mps.logic.reactor.logical.LogicalContext;
|
||||
import jetbrains.mps.logic.reactor.program.Constraint;
|
||||
import jetbrains.mps.logic.reactor.program.Rule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ package jetbrains.mps.logic.reactor.evaluation;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Used in implementation.
|
||||
*
|
||||
* @author Fedor Isakov
|
||||
*/
|
||||
public interface DataProvider {
|
||||
|
|
|
|||
|
|
@ -16,23 +16,15 @@
|
|||
|
||||
package jetbrains.mps.logic.reactor.evaluation;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Fedor Isakov
|
||||
*/
|
||||
public interface EvaluationResult {
|
||||
|
||||
public SessionToken token();
|
||||
SessionToken token();
|
||||
|
||||
public StoreView storeView();
|
||||
StoreView storeView();
|
||||
|
||||
public EvaluationFeedback feedback();
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public Collection<Object> invalidFeedbackKeys();
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public Collection<Object> invalidRules();
|
||||
EvaluationFeedback feedback();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ package jetbrains.mps.logic.reactor.evaluation;
|
|||
import jetbrains.mps.logic.reactor.program.Program;
|
||||
import jetbrains.mps.logic.reactor.util.Profiler;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* The starting point to evaluate a program.
|
||||
* <p>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package jetbrains.mps.logic.reactor.evaluation;
|
||||
|
||||
|
||||
import jetbrains.mps.logic.reactor.core.EvaluationFailure;
|
||||
import jetbrains.mps.logic.reactor.program.Rule;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package jetbrains.mps.logic.reactor.evaluation;
|
|||
|
||||
import jetbrains.mps.logic.reactor.program.Rule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface SessionToken {
|
||||
@NotNull
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ package jetbrains.mps.logic.reactor.logical;
|
|||
public class MetaLogical<T> implements VarSymbol {
|
||||
|
||||
private static final String WILDCARD = "_";
|
||||
private String name;
|
||||
private Class<T> type;
|
||||
private final String name;
|
||||
private final Class<T> type;
|
||||
private boolean wildcard = false;
|
||||
|
||||
public MetaLogical(String name, Class<T> type) {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public interface MutableLogical<T> extends Logical<T> {
|
|||
void union(MutableLogical<T> other, MutableLogical.ValueReconciler<T> reconciler);
|
||||
|
||||
/**
|
||||
* Calls {@link MutableLogical#union(MutableLogical <T>, MutableLogical.ValueReconciler<T>) } with the default value reconciler.
|
||||
* Calls {@link #union(MutableLogical, MutableLogical.ValueReconciler) } with the default value reconciler.
|
||||
* The default reconciler throws {@link java.lang.IllegalArgumentException } if the two values are not equal.
|
||||
*/
|
||||
void union(MutableLogical<T> other);
|
||||
|
|
|
|||
|
|
@ -63,8 +63,6 @@ public abstract class Rule {
|
|||
/**
|
||||
*
|
||||
* @param groupName template that created this rule
|
||||
* @param tagName
|
||||
* @param uniquePart
|
||||
*/
|
||||
public Tag(String groupName, String tagName, Object uniquePart) {
|
||||
this.group = groupName;
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ package jetbrains.mps.logic.reactor.program;
|
|||
*/
|
||||
public abstract class Symbol {
|
||||
|
||||
private String id;
|
||||
private int arity;
|
||||
private final String id;
|
||||
private final int arity;
|
||||
|
||||
protected Symbol(String id, int arity) {
|
||||
this.id = id;
|
||||
|
|
@ -43,7 +43,7 @@ public abstract class Symbol {
|
|||
@Override
|
||||
public int hashCode() {
|
||||
int result = 17;
|
||||
result = 43 * result + ((id != null ? String.valueOf(id).hashCode() : 0));
|
||||
result = 43 * result + ((id != null ? id.hashCode() : 0));
|
||||
result = 31 * result + 37 * arity;
|
||||
return result;
|
||||
}
|
||||
|
|
@ -61,10 +61,6 @@ public abstract class Symbol {
|
|||
if ((id != null ? !(id.equals(that.id())) : that.id != null)) {
|
||||
return false;
|
||||
}
|
||||
if (arity != that.arity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return arity == that.arity;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,14 +16,13 @@
|
|||
|
||||
package jetbrains.mps.logic.reactor.util
|
||||
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
/**
|
||||
* @author Fedor Isakov
|
||||
*/
|
||||
|
||||
fun <T> ArrayList<T>.push (element: T): Unit { add(element) }
|
||||
fun <T> ArrayList<T>.push (element: T) { add(element) }
|
||||
|
||||
fun <T> ArrayList<T>.pop (): T = removeAt(size - 1)
|
||||
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ fun BitSet.clearBit(bit: Int): BitSet =
|
|||
|
||||
fun BitSet.allSetBits(): TIntIterator = object : TIntIterator {
|
||||
|
||||
var next = nextSetBit(0);
|
||||
var next = nextSetBit(0)
|
||||
|
||||
override fun hasNext(): Boolean = next != -1;
|
||||
override fun hasNext(): Boolean = next != -1
|
||||
|
||||
override fun next(): Int =
|
||||
if (next != -1) {
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ class ClassicIndexedTermTrie<T> : IndexedTermTrie<T> {
|
|||
WILDCARD
|
||||
|
||||
} else {
|
||||
term.symbol() ?: throw NullPointerException("term symbol can't be null")
|
||||
term.symbol()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -419,9 +419,7 @@ class ClassicIndexedTermTrie<T> : IndexedTermTrie<T> {
|
|||
if (existing != null) {
|
||||
return existing
|
||||
} else {
|
||||
val default = default(symbol)
|
||||
next[symbol] = default
|
||||
return default
|
||||
return default(symbol).also { next[symbol] = it }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,8 +46,8 @@ fun <T> Set<T>.put(t: T) = add(t)
|
|||
|
||||
fun <T> Set<T>.without(t: T) = remove(t)
|
||||
|
||||
fun <K,V> Map<K, V>.assoc(k: K, v: V) = put(k, v)
|
||||
fun <K : Any,V> Map<K, V>.assoc(k: K, v: V) = put(k, v)
|
||||
|
||||
fun <K,V> Map<K, V>.without(k: K) = remove(k)
|
||||
fun <K : Any,V> Map<K, V>.without(k: K) = remove(k)
|
||||
|
||||
fun <K,V> Pair<K,V>.getValue(): V = component2()
|
||||
|
|
@ -30,7 +30,7 @@ class Profiler {
|
|||
|
||||
private val tokenStack = LinkedList<Token>()
|
||||
|
||||
constructor() {
|
||||
init {
|
||||
tokenStack.push(Token("_", ++lastTokenId))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import java.util.Collections;
|
|||
*/
|
||||
public class Substitution {
|
||||
|
||||
private boolean mySuccessful;
|
||||
private final boolean mySuccessful;
|
||||
|
||||
private Failure myFailure;
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ public class Substitution {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return myFailure != null ? "[" + String.valueOf(myFailure) + "]" : "[FAILED_SUBSTITUTION]";
|
||||
return myFailure != null ? "[" + myFailure + "]" : "[FAILED_SUBSTITUTION]";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -73,9 +73,9 @@ public class Substitution {
|
|||
*/
|
||||
public static class Binding {
|
||||
|
||||
private Term myVar;
|
||||
private final Term myVar;
|
||||
|
||||
private Term myTerm;
|
||||
private final Term myTerm;
|
||||
|
||||
public Binding(Term myVar, Term myTerm) {
|
||||
this.myVar = myVar;
|
||||
|
|
@ -94,7 +94,7 @@ public class Substitution {
|
|||
|
||||
public static class Failure {
|
||||
|
||||
private FailureCause myCause;
|
||||
private final FailureCause myCause;
|
||||
|
||||
private Object[] myDetails;
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ public class Substitution {
|
|||
SYMBOL_CLASH("symbol clash"),
|
||||
UKNOWN("uknown");
|
||||
|
||||
private String myMessage;
|
||||
private final String myMessage;
|
||||
|
||||
FailureCause(String message) {
|
||||
myMessage = message;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import java.util.Collection;
|
|||
* Represents a node in a term graph. The graph may contain cycles. A node in a term
|
||||
* graph can be of three kinds: a variable, a function (possibly constant) and a reference.
|
||||
* A reference must point to either a function term or a variable.
|
||||
*
|
||||
* A term must implement {@link java.lang.Comparable}, but this is only really used for
|
||||
* comparing the variables.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class TermGraphUnifier(private val wrapper: TermWrapper = TermWrapper.ID,
|
|||
constructor(trivialBindings: Boolean) : this(TermWrapper.ID, trivialBindings) {}
|
||||
|
||||
companion object {
|
||||
val EMPTY_LIST = TIntArrayList.wrap(kotlin.IntArray(0))
|
||||
val EMPTY_LIST = TIntArrayList.wrap(IntArray(0))
|
||||
}
|
||||
|
||||
fun unify(a: Term, b: Term): Substitution {
|
||||
|
|
@ -114,7 +114,7 @@ class TermGraphUnifier(private val wrapper: TermWrapper = TermWrapper.ID,
|
|||
setAcyclic(z)
|
||||
|
||||
// avoid unnecessary instatiation
|
||||
val success = if (subs is SuccessfulSubstitution) subs as SuccessfulSubstitution
|
||||
val success = if (subs is SuccessfulSubstitution) subs
|
||||
else SuccessfulSubstitution(subs)
|
||||
|
||||
if (vars != null) {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package jetbrains.mps.unification;
|
|||
|
||||
/**
|
||||
* Used by the unifier to wrap original terms in order to alter the unification behaviour.
|
||||
*
|
||||
* For example, one might want to represent a (term) variable as a constant in order to avoid unwanted matches.
|
||||
*
|
||||
* @author Fedor Isakov
|
||||
|
|
|
|||
|
|
@ -74,13 +74,9 @@ object Unification {
|
|||
|
||||
class SuccessfulSubstitution(substitution: Substitution) : Substitution(true) {
|
||||
|
||||
private val myBindings: LinkedList<Substitution.Binding>
|
||||
private val myBindings: LinkedList<Binding> = LinkedList(substitution.bindings())
|
||||
|
||||
init {
|
||||
this.myBindings = LinkedList(substitution.bindings())
|
||||
}
|
||||
|
||||
override fun bindings(): Collection<Substitution.Binding> {
|
||||
override fun bindings(): Collection<Binding> {
|
||||
return Collections.unmodifiableCollection(myBindings)
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +92,7 @@ object Unification {
|
|||
}
|
||||
|
||||
fun addBinding(v: Term, n: Term) {
|
||||
myBindings.addFirst(Substitution.Binding(v, n))
|
||||
myBindings.addFirst(Binding(v, n))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue