Skip to content

Commit

Permalink
Merge pull request #580 from jwest115/fpp-576
Browse files Browse the repository at this point in the history
Require displayable types in records
  • Loading branch information
bocchino authored Jan 25, 2025
2 parents 275a026 + 0ace648 commit 5762c34
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ object CheckComponentDefs
aNode: Ast.Annotated[AstNode[Ast.SpecRecord]]
) = {
val data = aNode._2.data
val record = Record.fromSpecRecord(a, aNode)
for {
idOpt <- a.getNonnegativeBigIntValueOpt(data.id)
record <- Record.fromSpecRecord(a, aNode)
component <- a.component.get.addRecord(idOpt, record)
}
yield a.copy(component = Some(component))
Expand Down
7 changes: 5 additions & 2 deletions compiler/lib/src/main/scala/analysis/Semantics/Record.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ object Record {

/** Creates a record from a record specifier */
def fromSpecRecord(a: Analysis, aNode: Ast.Annotated[AstNode[Ast.SpecRecord]]):
Record = {
Result.Result[Record] = {
val node = aNode._2
val data = node.data
val recordType = a.typeMap(data.recordType.id)
Record(aNode, recordType, data.isArray)
for {
_ <- a.checkDisplayableType(data.recordType.id, "type of record is not displayable")
}
yield Record(aNode, recordType, data.isArray)
}

}
21 changes: 21 additions & 0 deletions compiler/tools/fpp-check/test/record/not_displayable.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Fw {

port DpRequest
port DpResponse
port DpSend
port Time

}

passive component C {

product request port productRequestOut
sync product recv port productRecvIn
product send port productSendOut
time get port timeGetOut

type A
product container Container
product record R: A id 0x100

}
10 changes: 10 additions & 0 deletions compiler/tools/fpp-check/test/record/not_displayable.ref.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fpp-check
[ local path prefix ]/compiler/tools/fpp-check/test/record/not_displayable.fpp:19.21
product record R: A id 0x100
^
error: type of record is not displayable

[ local path prefix ]/compiler/tools/fpp-check/test/record/not_displayable.fpp:17.3
type A
^
Type is defined here
1 change: 1 addition & 0 deletions compiler/tools/fpp-check/test/record/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ missing_container
missing_ports
missing_product_recv_port
missing_product_send_port
not_displayable
ok
"
2 changes: 1 addition & 1 deletion compiler/tools/fpp-locate-uses/test/defs.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ constant queue_size_def = 10
constant stack_size_def = 10
constant priority_def = 10
constant cpu_def = 0
type RecordType
constant record_id = 0
array RecordType = [3] U32
constant container_id = 0
constant container_priority = 0
constant product_recv_priority = 0
Expand Down
4 changes: 2 additions & 2 deletions docs/fpp-spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -6762,7 +6762,7 @@ <h4 id="Specifiers_Record-Specifiers_Semantics">7.13.2. Semantics</h4>
</li>
<li>
<p>The type name <em>T</em> following the identifier specifies the type of the data stored
in the record.</p>
in the record. <em>T</em> must be a <a href="#Types_Displayable-Types">displayable type</a>.</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
Expand Down Expand Up @@ -10582,7 +10582,7 @@ <h3 id="Analysis-and-Translation_Translation-Tools">22.4. Translation Tools</h3>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2024-12-11 16:51:10 -0800
Last updated 2025-01-24 15:53:17 -0800
</div>
</div>
<script src="code-prettify/run_prettify.js"></script>
Expand Down
6 changes: 4 additions & 2 deletions docs/fpp-users-guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -8161,7 +8161,9 @@ <h4 id="Defining-Components_Data-Products_Basic-Data-Products">10.9.1. Basic Dat
The simplest record specification consists of the keywords <code>product</code> <code>record</code>,
a name, and a data type.
The name is the name of the record.
The data type is the type of the data that the record holds.</p>
The data type is the type of the data that the record holds.
The data type must be a
<a href="#Defining-Components_Commands_Formal-Parameters">displayable type</a>.</p>
</div>
<div class="paragraph">
<p>As an example, here is a component called <code>BasicDataProducts</code> that specifies
Expand Down Expand Up @@ -14817,7 +14819,7 @@ <h4 id="Writing-C-Plus-Plus-Implementations_Implementing-Deployments_Public-Symb
</div>
<div id="footer">
<div id="footer-text">
Last updated 2024-12-11 16:51:28 -0800
Last updated 2025-01-24 15:52:51 -0800
</div>
</div>
<script src="code-prettify/run_prettify.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ <h1>F Prime Prime (FPP)</h1>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2024-07-20 12:45:03 -0700
Last updated 2025-01-24 15:43:35 -0800
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/Specifiers/Record-Specifiers.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _]_
. The identifier names the record.

. The type name _T_ following the identifier specifies the type of the data stored
in the record.
in the record. _T_ must be a <<Types_Displayable-Types,displayable type>>.

.. If the keyword `array` appears after the type name, then the record stores
a variable number of elements of type _T_.
Expand Down
2 changes: 2 additions & 0 deletions docs/users-guide/Defining-Components.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,8 @@ The simplest record specification consists of the keywords `product` `record`,
a name, and a data type.
The name is the name of the record.
The data type is the type of the data that the record holds.
The data type must be a
<<Defining-Components_Commands_Formal-Parameters,displayable type>>.

As an example, here is a component called `BasicDataProducts` that specifies
two records and two containers.
Expand Down

0 comments on commit 5762c34

Please sign in to comment.