Skip to content

Commit

Permalink
Refactor EncodeChoreography to use scopes in a smart way instead of o…
Browse files Browse the repository at this point in the history
…bfuscating logic with a state machine
  • Loading branch information
bobismijnnaam committed Mar 4, 2025
1 parent f82ebb2 commit b977a93
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 210 deletions.
5 changes: 4 additions & 1 deletion src/col/vct/col/ast/declaration/singular/EndpointImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ trait EndpointImpl[G]
extends EndpointOps[G] with DeclarationImpl[G] with EndpointFamilyOps[G] {
this: Endpoint[G] =>
override def layout(implicit ctx: Ctx): Doc =
Group(Text("endpoint") <+> ctx.name(this) <+> "=" <+> init)
Group(
Text("endpoint") <+> ctx.name(this) <> range.map(_.show)
.getOrElse(Empty) <+> "=" <+> init <> ";"
)

def singleType: TClass[G] = cls.decl.classType(typeArgs)
def rangeType: TSeq[G] = TSeq(singleType)
Expand Down
12 changes: 12 additions & 0 deletions src/col/vct/col/util/Scopes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ case class Scopes[Pre, Post, PreDecl <: Declaration[
succeedOnly(pre, post)
}

def get(decl: PreDecl): Option[PostDecl] = {
for (succ <- successors) {
succ.get(decl) match {
case Some(postDecl) => return Some(postDecl)
case None =>
}
}
None
}

def apply(decl: PreDecl): PostDecl = get(decl).get

def dispatch(
decl: PreDecl
)(implicit rw: AbstractRewriter[Pre, Post]): PostDecl = {
Expand Down
Loading

0 comments on commit b977a93

Please sign in to comment.