Skip to content

Commit cf148f9

Browse files
authored
Merge pull request #944 from nasa/issue-935-string-types
Revise string types
2 parents 62a8f2c + 8d26300 commit cf148f9

File tree

6 files changed

+40
-46
lines changed

6 files changed

+40
-46
lines changed

compiler/lib/src/main/scala/analysis/Semantics/Type.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,18 +384,12 @@ object Type {
384384
case (Boolean -> Boolean) => true
385385
case _ => false
386386
}
387-
def string = pair match {
388-
case (String(None) -> String(None)) => true
389-
case (String(Some(e1)) -> String(Some(e2))) => e1 == e2
390-
case _ => false
391-
}
392387
def sameDef = (t1.getDefNodeId, t2.getDefNodeId) match {
393388
case (Some(id1), Some(id2)) => id1 == id2
394389
case _ => false
395390
}
396391
numeric ||
397392
boolean ||
398-
string ||
399393
sameDef
400394
}
401395

compiler/lib/src/test/scala/semantics/TypeSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class TypeSpec extends AnyWordSpec {
2525
duplicate(I64),
2626
duplicate(I8),
2727
duplicate(Integer),
28-
duplicate(String(None)),
2928
duplicate(U16),
3029
duplicate(U32),
3130
duplicate(U64),
@@ -40,6 +39,7 @@ class TypeSpec extends AnyWordSpec {
4039
(defaultAbsType, defaultEnum),
4140
(defaultArray, defaultStruct),
4241
(Boolean,String(None)),
42+
duplicate(String(None)),
4343
(F32,F64),
4444
(I8,U32),
4545
duplicate(AnonArray(None, I32)),

docs/fpp-spec.html

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10884,14 +10884,28 @@ <h3 id="Types_String-Types">17.6. String Types</h3>
1088410884
A string type is written <code>string</code> or <code>string size</code> <em>n</em>,
1088510885
where <em>n</em> is an integer value in the range [1,2^31-1].
1088610886
There is one string type <code>string</code> and one string type <code>string size</code> <em>n</em>
10887-
for each legal value of <em>n</em>.</p>
10887+
for each legal value of <em>n</em>.
10888+
The string type names map to the string types in the following way:</p>
10889+
</div>
10890+
<div class="ulist">
10891+
<ul>
10892+
<li>
10893+
<p>The type name <code>string</code> maps to the type <code>string</code>.</p>
10894+
</li>
10895+
<li>
10896+
<p>The type name <code>string</code> <code>size</code> <em>e</em> maps to the type <code>string</code> <code>size</code> <em>n</em>,
10897+
after evaluating the expression <em>e</em> to the value <em>n</em>.</p>
10898+
</li>
10899+
</ul>
1088810900
</div>
1088910901
<div class="paragraph">
1089010902
<p>The value <em>n</em>, if present, is called the <strong>size</strong> associated with the string
1089110903
type.
10892-
The size provides a maximum string length that the code generator can use
10904+
The size provides a maximum string length that the code generator uses
1089310905
for allocating memory and serializing data.
10894-
If no explicit size is present, then the code generator uses a default size.</p>
10906+
If no size is present, then the code generator uses
10907+
the <a href="#Definitions_Framework-Definitions_Constant-Definitions">framework definition</a> <code>FW_FIXED_LENGTH_STRING_SIZE</code> as the
10908+
maximum string length.</p>
1089510909
</div>
1089610910
</div>
1089710911
<div class="sect2">
@@ -11560,11 +11574,6 @@ <h3 id="Type-Checking_Identical-Types">18.13. Identical Types</h3>
1156011574
<a href="#Types_The-Boolean-Type">the Boolean type</a>.</p>
1156111575
</li>
1156211576
<li>
11563-
<p>\$T_1\$ and \$T_2\$
11564-
are both the same
11565-
<a href="#Types_String-Types">string type</a>.</p>
11566-
</li>
11567-
<li>
1156811577
<p>Each of \$T_1\$ and \$T_2\$
1156911578
is an
1157011579
<a href="#Types_Abstract-Types">abstract type</a>,
@@ -11576,6 +11585,9 @@ <h3 id="Type-Checking_Identical-Types">18.13. Identical Types</h3>
1157611585
</li>
1157711586
</ol>
1157811587
</div>
11588+
<div class="paragraph">
11589+
<p>Note that string types are never identical.</p>
11590+
</div>
1157911591
</div>
1158011592
<div class="sect2">
1158111593
<h3 id="Type-Checking_Type-Conversion">18.14. Type Conversion</h3>
@@ -12040,8 +12052,7 @@ <h2 id="Values">20. Values</h2>
1204012052
<div class="paragraph">
1204112053
<p>Every value <em>v</em> belongs to exactly one <a href="#Types_Canonical-Types">canonical type</a>
1204212054
<em>T</em>, except that
12043-
every string value belongs to the type <code>string</code> and to
12044-
all types <code>string size</code> <em>n</em>, for any <em>n</em>.</p>
12055+
every string value belongs to every string type.</p>
1204512056
</div>
1204612057
<div class="paragraph">
1204712058
<p>Every value that belongs to type <em>T</em> also belongs to every
@@ -12137,20 +12148,8 @@ <h3 id="Values_String-Values">20.5. String Values</h3>
1213712148
characters in the sequence.</p>
1213812149
</div>
1213912150
<div class="paragraph">
12140-
<p>A string value <em>v</em> belongs to the following canonical types:</p>
12141-
</div>
12142-
<div class="ulist">
12143-
<ul>
12144-
<li>
12145-
<p><code>string</code></p>
12146-
</li>
12147-
<li>
12148-
<p><code>string size</code> <em>n</em> for any <em>n</em>.</p>
12149-
</li>
12150-
</ul>
12151-
</div>
12152-
<div class="paragraph">
12153-
<p>Note that <em>v</em> may have length <em>m</em> and type <code>string size</code> <em>n</em>,
12151+
<p>A string value <em>v</em> belongs to every string type.
12152+
Note that <em>v</em> may have length <em>m</em> and type <code>string size</code> <em>n</em>,
1215412153
with \$m &gt; n\$.
1215512154
In this case, the behavior is defined by the code generation strategy.
1215612155
In particular, when code is generated for the F Prime framework,
@@ -12861,7 +12860,7 @@ <h3 id="Analysis-and-Translation_Translation-Tools">23.4. Translation Tools</h3>
1286112860
</div>
1286212861
<div id="footer">
1286312862
<div id="footer-text">
12864-
Last updated 2026-03-09 15:31:20 -0700
12863+
Last updated 2026-03-09 16:24:44 -0700
1286512864
</div>
1286612865
</div>
1286712866
<script src="code-prettify/run_prettify.js"></script>

docs/spec/Type-Checking.adoc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,6 @@ the type.
269269
are both
270270
<<Types_The-Boolean-Type,the Boolean type>>.
271271

272-
. stem:[T_1] and stem:[T_2]
273-
are both the same
274-
<<Types_String-Types,string type>>.
275-
276272
. Each of stem:[T_1] and stem:[T_2]
277273
is an
278274
<<Types_Abstract-Types,abstract type>>,
@@ -282,6 +278,8 @@ is an
282278
<<Types_Struct-Types,struct type>>,
283279
and both types refer to the same definition.
284280

281+
Note that string types are never identical.
282+
285283
=== Type Conversion
286284

287285
We say that a type stem:[T_1] *may be converted to* another type stem:[T_2] if

docs/spec/Types.adoc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,21 @@ A string type is written `string` or `string size` _n_,
4343
where _n_ is an integer value in the range [1,2^31-1].
4444
There is one string type `string` and one string type `string size` _n_
4545
for each legal value of _n_.
46+
The string type names map to the string types in the following way:
47+
48+
* The type name `string` maps to the type `string`.
49+
50+
* The type name `string` `size` _e_ maps to the type `string` `size` _n_,
51+
after evaluating the expression _e_ to the value _n_.
4652

4753
The value _n_, if present, is called the *size* associated with the string
4854
type.
49-
The size provides a maximum string length that the code generator can use
55+
The size provides a maximum string length that the code generator uses
5056
for allocating memory and serializing data.
51-
If no explicit size is present, then the code generator uses a default size.
57+
If no size is present, then the code generator uses
58+
the <<Definitions_Framework-Definitions_Constant-Definitions,
59+
framework definition>> `FW_FIXED_LENGTH_STRING_SIZE` as the
60+
maximum string length.
5261

5362
=== Array Types
5463

docs/spec/Values.adoc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ A *value* is one of the following:
2626
2727
Every value _v_ belongs to exactly one <<Types_Canonical-Types,canonical type>>
2828
_T_, except that
29-
every string value belongs to the type `string` and to
30-
all types `string size` _n_, for any _n_.
29+
every string value belongs to every string type.
3130

3231
Every value that belongs to type _T_ also belongs to every
3332
<<Types_Alias-Types,alias type>> whose
@@ -96,12 +95,7 @@ e.g., `"abc"`.
9695
Every string value _v_ has a *length*, which is the number of
9796
characters in the sequence.
9897

99-
A string value _v_ belongs to the following canonical types:
100-
101-
* `string`
102-
103-
* `string size` _n_ for any _n_.
104-
98+
A string value _v_ belongs to every string type.
10599
Note that _v_ may have length _m_ and type `string size` _n_,
106100
with stem:[m > n].
107101
In this case, the behavior is defined by the code generation strategy.

0 commit comments

Comments
 (0)