diff --git a/compiler/lib/src/main/scala/analysis/Analyzers/BasicUseAnalyzer.scala b/compiler/lib/src/main/scala/analysis/Analyzers/BasicUseAnalyzer.scala index 4c9077596..d58e37bbf 100644 --- a/compiler/lib/src/main/scala/analysis/Analyzers/BasicUseAnalyzer.scala +++ b/compiler/lib/src/main/scala/analysis/Analyzers/BasicUseAnalyzer.scala @@ -157,7 +157,7 @@ trait BasicUseAnalyzer extends TypeExpressionAnalyzer { val (_, node1, _) = node val data = node1.data data match { - case direct : Ast.SpecConnectionGraph.Direct => visitList(a, direct.connections, connection) + case direct : Ast.SpecConnectionGraph.Direct => visitList(a, direct.connections.map(_._2), connection) case pattern : Ast.SpecConnectionGraph.Pattern => for { a <- qualIdentNode (interfaceInstanceUse) (a, pattern.source) a <- visitList(a, pattern.targets, qualIdentNode(interfaceInstanceUse)) diff --git a/compiler/lib/src/main/scala/analysis/Analyzers/TypeExpressionAnalyzer.scala b/compiler/lib/src/main/scala/analysis/Analyzers/TypeExpressionAnalyzer.scala index 40766c794..d07975386 100644 --- a/compiler/lib/src/main/scala/analysis/Analyzers/TypeExpressionAnalyzer.scala +++ b/compiler/lib/src/main/scala/analysis/Analyzers/TypeExpressionAnalyzer.scala @@ -178,7 +178,7 @@ trait TypeExpressionAnalyzer val (_, node1, _) = node val data = node1.data data match { - case direct : Ast.SpecConnectionGraph.Direct => visitList(a, direct.connections, connection) + case direct : Ast.SpecConnectionGraph.Direct => visitList(a, direct.connections.map(_._2), connection) case pattern => Right(a) } } diff --git a/compiler/lib/src/main/scala/analysis/Semantics/Connection.scala b/compiler/lib/src/main/scala/analysis/Semantics/Connection.scala index de5dd2479..e92e449b4 100644 --- a/compiler/lib/src/main/scala/analysis/Semantics/Connection.scala +++ b/compiler/lib/src/main/scala/analysis/Semantics/Connection.scala @@ -9,7 +9,9 @@ case class Connection( from: Connection.Endpoint, /** The to endpoint */ to: Connection.Endpoint, - isUnmatched: Boolean = false + isUnmatched: Boolean = false, + /** The AST connection, with its annotations, if there is one */ + astOpt: Option[Ast.Annotated[Ast.SpecConnectionGraph.Connection]] = None ) extends Ordered[Connection] { override def toString = s"${from.toString} -> ${to.toString}" @@ -158,17 +160,23 @@ case class Connection( object Connection { /** Constructs a connection from an AST connection */ - def fromAst(a: Analysis, connection: Ast.SpecConnectionGraph.Connection): - Result.Result[Connection] = - for { - from <- Endpoint.fromAst(a, connection.fromPort, connection.fromIndex) - to <- Endpoint.fromAst(a, connection.toPort, connection.toIndex) - connection <- Right(Connection(from, to, connection.isUnmatched)) - _ <- connection.checkDirections - _ <- connection.checkTypes(a) - _ <- connection.checkSerialWithTypedInput(a) - } - yield connection + def fromAst( + a: Analysis, + aConnection: Ast.Annotated[Ast.SpecConnectionGraph.Connection] + ): Result.Result[Connection] = { + val connection = aConnection._2 + for { + from <- Endpoint.fromAst(a, connection.fromPort, connection.fromIndex) + to <- Endpoint.fromAst(a, connection.toPort, connection.toIndex) + connection <- Right( + Connection(from, to, connection.isUnmatched, Some(aConnection)) + ) + _ <- connection.checkDirections + _ <- connection.checkTypes(a) + _ <- connection.checkSerialWithTypedInput(a) + } + yield connection + } /** A connection endpoint */ case class Endpoint( diff --git a/compiler/lib/src/main/scala/ast/Ast.scala b/compiler/lib/src/main/scala/ast/Ast.scala index df0a9be3f..3fb2880b4 100644 --- a/compiler/lib/src/main/scala/ast/Ast.scala +++ b/compiler/lib/src/main/scala/ast/Ast.scala @@ -563,7 +563,7 @@ object Ast { final case class Direct( name: Ident, - connections: List[Connection] + connections: List[Annotated[Connection]] ) extends SpecConnectionGraph object Pattern { diff --git a/compiler/lib/src/main/scala/codegen/AstWriter.scala b/compiler/lib/src/main/scala/codegen/AstWriter.scala index a03e01c92..91786d557 100644 --- a/compiler/lib/src/main/scala/codegen/AstWriter.scala +++ b/compiler/lib/src/main/scala/codegen/AstWriter.scala @@ -443,7 +443,7 @@ object AstWriter extends AstVisitor with LineUtils { } lines("spec connection graph direct") ++ ( ident(g.name) ++ - g.connections.flatMap(connection) + g.connections.flatMap { case (pre, c, post) => annotate(pre, connection(c), post) } ).map(indentIn) } def pattern(g: Ast.SpecConnectionGraph.Pattern) = { diff --git a/compiler/lib/src/main/scala/codegen/FppWriter.scala b/compiler/lib/src/main/scala/codegen/FppWriter.scala index 502b50c39..5c026cc36 100644 --- a/compiler/lib/src/main/scala/codegen/FppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/FppWriter.scala @@ -515,7 +515,11 @@ class FppWriter(a: Analysis = Analysis()) extends AstVisitor with LineUtils { def direct(scg: Ast.SpecConnectionGraph.Direct) = lines(s"connections ${ident(scg.name)}"). joinNoIndent (" ") ( - addBraces(scg.connections.flatMap(connection)) + addBraces( + scg.connections.flatMap { case (pre, c, post) => + annotate(pre, connection(c), post) + } + ) ) def pattern(scg: Ast.SpecConnectionGraph.Pattern) = { Line.addPrefix( diff --git a/compiler/lib/src/main/scala/codegen/XmlFppWriter/TopologyXmlFppWriter.scala b/compiler/lib/src/main/scala/codegen/XmlFppWriter/TopologyXmlFppWriter.scala index 8be30baf6..8a6e6904b 100644 --- a/compiler/lib/src/main/scala/codegen/XmlFppWriter/TopologyXmlFppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/XmlFppWriter/TopologyXmlFppWriter.scala @@ -151,7 +151,7 @@ object TopologyXmlFppWriter extends LineUtils { for (connections <- connectionList(file)) yield ( Nil, - Ast.SpecConnectionGraph.Direct("XML", connections), + Ast.SpecConnectionGraph.Direct("XML", connections.map(c => (Nil, c, Nil))), Nil ) diff --git a/compiler/lib/src/main/scala/syntax/Parser.scala b/compiler/lib/src/main/scala/syntax/Parser.scala index 3d721b582..c6d791468 100644 --- a/compiler/lib/src/main/scala/syntax/Parser.scala +++ b/compiler/lib/src/main/scala/syntax/Parser.scala @@ -582,9 +582,10 @@ object Parser extends Parsers { def specConnectionGraph: Parser[Ast.SpecConnectionGraph] = { def directGraph = { - (connections ~> ident) ~! (lbrace ~>! elementSequence( + (connections ~> ident) ~! (lbrace ~>! annotatedElementSequence( connection, - comma + comma, + { case x => x } ) <~! rbrace) ^^ { case ident ~ connections => Ast.SpecConnectionGraph.Direct(ident, connections) } diff --git a/compiler/lib/src/main/scala/transform/ExpandTemplates.scala b/compiler/lib/src/main/scala/transform/ExpandTemplates.scala index e04b68dd3..93b5f1018 100644 --- a/compiler/lib/src/main/scala/transform/ExpandTemplates.scala +++ b/compiler/lib/src/main/scala/transform/ExpandTemplates.scala @@ -475,7 +475,14 @@ object ExpandTemplates extends AstUnitTransformer data match { case data @ Ast.SpecConnectionGraph.Direct(_, connections) => - for (connections <- transformList(a, connections, connection)) + def annotatedConnection( + a: Analysis, + aConnection: Ast.Annotated[Ast.SpecConnectionGraph.Connection] + ) = { + val (pre, c, post) = aConnection + for (pair <- connection(a, c)) yield ((), (pre, pair._2, post)) + } + for (connections <- transformList(a, connections, annotatedConnection)) yield { val dataCopy = data.copy(connections = connections) val node = cloneAnnotatedNode(a, aNode, dataCopy) diff --git a/compiler/tools/fpp-syntax/test/syntax-ast.ref.txt b/compiler/tools/fpp-syntax/test/syntax-ast.ref.txt index e389ac735..86787184d 100644 --- a/compiler/tools/fpp-syntax/test/syntax-ast.ref.txt +++ b/compiler/tools/fpp-syntax/test/syntax-ast.ref.txt @@ -397,11 +397,13 @@ def module @ Direct connection graph specifier spec connection graph direct ident C + @ Connection connection from port qual ident i1.p index literal int 0 to port qual ident i2.p index literal int 1 + @< Connection unmatched connection from port qual ident i1.p1 index literal int 0 diff --git a/compiler/tools/fpp-syntax/test/syntax-include-ast.ref.txt b/compiler/tools/fpp-syntax/test/syntax-include-ast.ref.txt index 23c24dc68..5c8468c82 100644 --- a/compiler/tools/fpp-syntax/test/syntax-include-ast.ref.txt +++ b/compiler/tools/fpp-syntax/test/syntax-include-ast.ref.txt @@ -401,11 +401,13 @@ def module @ Direct connection graph specifier spec connection graph direct ident C + @ Connection connection from port qual ident i1.p index literal int 0 to port qual ident i2.p index literal int 1 + @< Connection unmatched connection from port qual ident i1.p1 index literal int 0 diff --git a/compiler/tools/fpp-syntax/test/syntax-stdin.ref.txt b/compiler/tools/fpp-syntax/test/syntax-stdin.ref.txt index 23c24dc68..5c8468c82 100644 --- a/compiler/tools/fpp-syntax/test/syntax-stdin.ref.txt +++ b/compiler/tools/fpp-syntax/test/syntax-stdin.ref.txt @@ -401,11 +401,13 @@ def module @ Direct connection graph specifier spec connection graph direct ident C + @ Connection connection from port qual ident i1.p index literal int 0 to port qual ident i2.p index literal int 1 + @< Connection unmatched connection from port qual ident i1.p1 index literal int 0 diff --git a/compiler/tools/fpp-syntax/test/syntax.fpp b/compiler/tools/fpp-syntax/test/syntax.fpp index bca7a615a..e6f7b3334 100644 --- a/compiler/tools/fpp-syntax/test/syntax.fpp +++ b/compiler/tools/fpp-syntax/test/syntax.fpp @@ -220,7 +220,9 @@ module DefinitionsAndSpecifiers { @ Direct connection graph specifier connections C { + @ Connection i1.p[0] -> i2.p[1] + @< Connection unmatched i1.p1[0] -> i2.p2[0] unmatched i1.p1 -> i2.p2 .i1.p3 -> .i2.p3 diff --git a/compiler/tools/fpp-to-fpp/test/include.ref.txt b/compiler/tools/fpp-to-fpp/test/include.ref.txt index db244390b..e1aa43b61 100644 --- a/compiler/tools/fpp-to-fpp/test/include.ref.txt +++ b/compiler/tools/fpp-to-fpp/test/include.ref.txt @@ -259,7 +259,8 @@ module DefinitionsAndSpecifiers { @ Direct connection graph specifier connections C { - i1.p[0] -> i2.p[1] + @ Connection + i1.p[0] -> i2.p[1] @< Connection unmatched i1.p1[0] -> i2.p2[0] unmatched i1.p1 -> i2.p2 .i1.p3 -> .i2.p3 diff --git a/compiler/tools/fpp-to-fpp/test/no_include.ref.txt b/compiler/tools/fpp-to-fpp/test/no_include.ref.txt index f6b80c7a4..b10ec63d6 100644 --- a/compiler/tools/fpp-to-fpp/test/no_include.ref.txt +++ b/compiler/tools/fpp-to-fpp/test/no_include.ref.txt @@ -255,7 +255,8 @@ module DefinitionsAndSpecifiers { @ Direct connection graph specifier connections C { - i1.p[0] -> i2.p[1] + @ Connection + i1.p[0] -> i2.p[1] @< Connection unmatched i1.p1[0] -> i2.p2[0] unmatched i1.p1 -> i2.p2 .i1.p3 -> .i2.p3 diff --git a/compiler/tools/fpp-to-fpp/test/topology.fpp b/compiler/tools/fpp-to-fpp/test/topology.fpp index 5e15fcd4e..5ebc55b99 100644 --- a/compiler/tools/fpp-to-fpp/test/topology.fpp +++ b/compiler/tools/fpp-to-fpp/test/topology.fpp @@ -7,5 +7,9 @@ topology T implements I1,I2{ port p2 = i1.p2 - connections Conn { i1.pOut -> i2.pIn } + connections Conn { + @ Connection + i1.pOut -> i2.pIn @< Connection + i2.pOut -> i1.pIn + } } diff --git a/compiler/tools/fpp-to-fpp/test/topology.ref.txt b/compiler/tools/fpp-to-fpp/test/topology.ref.txt index 70e95e7a1..8377a9618 100644 --- a/compiler/tools/fpp-to-fpp/test/topology.ref.txt +++ b/compiler/tools/fpp-to-fpp/test/topology.ref.txt @@ -13,7 +13,9 @@ topology T implements \ port p2 = i1.p2 connections Conn { - i1.pOut -> i2.pIn + @ Connection + i1.pOut -> i2.pIn @< Connection + i2.pOut -> i1.pIn } } diff --git a/docs/fpp-spec.html b/docs/fpp-spec.html index 95f0e988a..97df39e69 100644 --- a/docs/fpp-spec.html +++ b/docs/fpp-spec.html @@ -11091,6 +11091,9 @@

14.2.1

A specifier.

  • +

    A connection in a direct graph specifier.

    +
  • +
  • A state definition member.

  • @@ -14610,7 +14613,7 @@

    25.4. Translation Tools

    diff --git a/docs/fpp-users-guide.html b/docs/fpp-users-guide.html index 5cededc01..51dee6061 100644 --- a/docs/fpp-users-guide.html +++ b/docs/fpp-users-guide.html @@ -11291,6 +11291,19 @@

    14.2.1. D
    +

    The connections in a direct graph specifier are +annotatable elements. +For example, you can write this:

    +
    +
    +
    +
    connections C {
    +  @ This is a pre-annotation
    +  a.p -> b.p @< This is a post-annotation
    +}
    +
    +
    +

    The connections appearing in direct graph specifiers must obey the following rules:

    @@ -18420,7 +18433,7 @@

    19.4. S diff --git a/docs/index.html b/docs/index.html index 033d2808c..2d3a13616 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4,7 +4,7 @@ - + F Prime Prime (FPP)