Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
devops committed Dec 4, 2023
2 parents 549dc1e + d73a7ee commit 23e8f7c
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions kore/src/main/scala/org/kframework/parser/Transformer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

package org.kframework.parser

import java.util

import collection.JavaConverters._
import org.kframework.Collections._

import java.util
import scala.collection.JavaConverters._


class Ignore

Expand Down Expand Up @@ -89,8 +89,6 @@ abstract class ChildrenMapping[E, W] {
* @tparam W container for warnings.
*/
abstract class GeneralTransformer[E, W] extends ChildrenMapping[E, W] {

import collection.mutable
// we expect this data structures to represent a DAG, so we
// use a cache to remember nodes that we already visited.
val cache = new util.IdentityHashMap[Term, (Either[E, Term], W)]()
Expand All @@ -99,7 +97,7 @@ abstract class GeneralTransformer[E, W] extends ChildrenMapping[E, W] {

def apply(t: Term): (Either[E, Term], W) = {
if (cache.containsKey(t)) {
return cache.get(t);
return cache.get(t)
}
val res =
t match {
Expand All @@ -120,34 +118,31 @@ abstract class GeneralTransformer[E, W] extends ChildrenMapping[E, W] {
def apply(c: Constant): (Either[E, Term], W) = simpleResult(c)
}

trait EAsSet[E] {
abstract class SetsGeneralTransformer[E, W]
extends GeneralTransformer[java.util.Set[E], java.util.Set[W]] {
/**
* Merges the set of problematic (i.e., Left) results.
*/
def mergeErrors(a: java.util.Set[E], b: java.util.Set[E]): java.util.Set[E] = {
val c = new java.util.HashSet[E](a);
c.addAll(b);
val c = new java.util.HashSet[E](a)
c.addAll(b)
c
}

val errorUnit: java.util.Set[E] = new java.util.HashSet[E]()
}

trait WAsSet[W] {
val warningUnit: java.util.Set[W] = new java.util.HashSet[W]()

/**
* Merges the set of problematic (i.e., Left) results.
*/
def mergeWarnings(a: java.util.Set[W], b: java.util.Set[W]): java.util.Set[W] = {
val c = new java.util.HashSet[W](a);
c.addAll(b);
val c = new java.util.HashSet[W](a)
c.addAll(b)
c
}
}

abstract class SetsGeneralTransformer[E, W]
extends GeneralTransformer[java.util.Set[E], java.util.Set[W]] with EAsSet[E] with WAsSet[W]

/**
* Visitor pattern for the front end classes.
* Applies the visitor transformation on each node, and returns either a term, or a set of errors. (no warnings)
Expand All @@ -156,15 +151,13 @@ abstract class SetsGeneralTransformer[E, W]
abstract class TransformerWithErrors[E] extends ChildrenMapping[E, Ignore] {

def applyTerm(t: Term): (Either[E, Term], Ignore) = (apply(t), Ignore)

import collection.mutable
// we expect this data structures to represent a DAG, so we
// use a cache to remember nodes that we already visited.
val cache = new util.IdentityHashMap[Term, Either[E, Term]]

def apply(t: Term): Either[E, Term] = {
if (cache.containsKey(t)) {
return cache.get(t);
return cache.get(t)
}
val res =
t match {
Expand All @@ -184,12 +177,23 @@ abstract class TransformerWithErrors[E] extends ChildrenMapping[E, Ignore] {
def apply(tc: TermCons): Either[E, Term] = mapChildrenStrict(tc)._1
def apply(c: Constant): Either[E, Term] = Right(c)

override def mergeWarnings(a: Ignore, b: Ignore) = Ignore
override val warningUnit = Ignore
override def mergeWarnings(a: Ignore, b: Ignore): Ignore = Ignore
override val warningUnit: Ignore = Ignore
}

abstract class SetsTransformerWithErrors[E]
extends TransformerWithErrors[java.util.Set[E]] with EAsSet[E]
extends TransformerWithErrors[java.util.Set[E]] {
/**
* Merges the set of problematic (i.e., Left) results.
*/
def mergeErrors(a: java.util.Set[E], b: java.util.Set[E]): java.util.Set[E] = {
val c = new java.util.HashSet[E](a)
c.addAll(b)
c
}

val errorUnit: java.util.Set[E] = new java.util.HashSet[E]()
}

/**
* Visitor pattern for the front end classes.
Expand All @@ -198,15 +202,13 @@ abstract class SetsTransformerWithErrors[E]
abstract class SafeTransformer extends ChildrenMapping[Ignore, Ignore] {

def applyTerm(t: Term): (Either[Ignore, Term], Ignore) = (Right(apply(t)), Ignore)

import collection.mutable
// we expect this data structures to represent a DAG, so we
// use a cache to remember nodes that we already visited.
val cache = new util.IdentityHashMap[Term, Term]

def apply(t: Term): Term = {
if (cache.containsKey(t)) {
return cache.get(t);
return cache.get(t)
}
val res =
t match {
Expand All @@ -226,8 +228,8 @@ abstract class SafeTransformer extends ChildrenMapping[Ignore, Ignore] {
def apply(tc: TermCons): Term = mapChildrenStrict(tc)._1.right.get
def apply(c: Constant): Term = c

def mergeWarnings(a: Ignore, b: Ignore) = Ignore
val warningUnit = Ignore
def mergeErrors(a: Ignore, b: Ignore) = Ignore
val errorUnit = Ignore
def mergeWarnings(a: Ignore, b: Ignore): Ignore = Ignore
val warningUnit: Ignore = Ignore
def mergeErrors(a: Ignore, b: Ignore): Ignore = Ignore
val errorUnit: Ignore = Ignore
}

0 comments on commit 23e8f7c

Please sign in to comment.