Skip to content

Commit 5c91ac3

Browse files
authored
Merge pull request #669 from nasa/tumbar-remove-builtin
Remove builtin types
2 parents f5932ef + 8e457e5 commit 5c91ac3

File tree

256 files changed

+476
-1649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+476
-1649
lines changed

compiler/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ test-output.txt
55
*.o
66
native-fpp-*
77
*.class
8+
# Version is not checked in during typical development
9+
lib/src/main/scala/util/Version.scala

compiler/lib/src/main/scala/analysis/Analyzers/UseAnalyzer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ trait UseAnalyzer extends TypeExpressionAnalyzer {
9090
case direct : Ast.SpecConnectionGraph.Direct => visitList(a, direct.connections, connection)
9191
case pattern : Ast.SpecConnectionGraph.Pattern => for {
9292
a <- qualIdentNode (componentInstanceUse) (a, pattern.source)
93-
a <- visitList(a, pattern.targets, qualIdentNode (componentInstanceUse) _)
93+
a <- visitList(a, pattern.targets, qualIdentNode(componentInstanceUse))
9494
} yield a
9595
}
9696
}

compiler/lib/src/main/scala/codegen/CppWriter/AliasCppWriter.scala

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -120,39 +120,34 @@ case class AliasCppWriter (
120120
return linesMember(List())
121121
}
122122

123-
val systemHHeaders = List(
124-
"FpConfig.h"
125-
).map(CppWriter.systemHeaderString).map(line)
126-
123+
// Include Fw/Types/BasicTypes.h here
124+
// To avoid an include cycle, don't depend on Fw/FPrimeBasicTypes.hpp
125+
// If the alias refers to one of those types, the header will appear
126+
// in symbolHeaders
127127
val standardHeaders = List(
128128
"Fw/Types/BasicTypes.h",
129129
).map(CppWriter.headerString)
130130

131131
val symbolHeaders = writeHIncludeDirectives(s, aNode)
132132
val headers = (standardHeaders ++ symbolHeaders).distinct.sorted.map(line)
133-
linesMember(List.concat(
134-
addBlankPrefix(systemHHeaders),
135-
addBlankPrefix(headers)
136-
))
133+
linesMember(addBlankPrefix(headers))
137134
}
138135

139136
private def getHppIncludes: CppDoc.Member.Lines = {
140-
val systemHppHeaders = List(
141-
"FpConfig.hpp"
142-
).map(CppWriter.systemHeaderString).map(line)
143-
144137
val standardHeaders = List(
138+
// Include BasicTypes.h or Fw/Types/String.hpp here
139+
// Fw/Types/String.hpp includes Fw/Types/BasicTypes.h
140+
// To avoid an include cycle, don't depend on Fw/FPrimeBasicTypes.hpp
141+
// If the alias refers to one of those types, the header will appear
142+
// in symbolHeaders
145143
aliasType.aliasType match {
146144
case Type.String(_) => "Fw/Types/String.hpp"
147-
case _ => "Fw/Types/BasicTypes.h"
145+
case _ => "Fw/Types/BasicTypes.hpp"
148146
},
149147
).map(CppWriter.headerString)
150148
val symbolHeaders = writeHppIncludeDirectives(s, aNode)
151149
val headers = standardHeaders ++ symbolHeaders
152-
linesMember(List.concat(
153-
addBlankPrefix(systemHppHeaders),
154-
addBlankPrefix(headers.distinct.sorted.map(line))
155-
))
150+
linesMember(addBlankPrefix(headers.distinct.sorted.map(line)))
156151
}
157152

158153
private def getHppDefinition: CppDoc.Member.Lines = {
@@ -178,20 +173,24 @@ case class AliasCppWriter (
178173

179174
private def getHDefinition: CppDoc.Member.Lines = {
180175
val name = s.getName(symbol)
181-
def getTypePRI(ty: Type): String = {
182-
ty match {
183-
case Type.Float(f) => aliasType.aliasType.toString().toLowerCase()
184-
case Type.PrimitiveInt(i) => aliasType.aliasType.toString().toLowerCase()
185-
case _ => typeCppWriter.write(ty)
186-
}
187-
}
188176

189-
val fmtSpec = getTypePRI(aliasType.aliasType)
177+
val fmtSpecList = aliasType.aliasType match {
178+
// C-style floating-poing format strings (f, g) are platform-independent
179+
// In F Prime code, we just use them
180+
case Type.Float(f) => Nil
181+
// C-style integer format strings (d, u, ld, lu, etc.) are platform-specific
182+
// In F Prime code we don't use them. Instead we use a platform-independent macro.
183+
// Write out the macro here
184+
case _ => List("_" + typeCppWriter.write(aliasType.aliasType))
185+
}
190186

191-
linesMember(addBlankPrefix(
192-
AnnotationCppWriter.writePreComment(aNode) ++ lines(
193-
s"""|typedef ${typeCppWriter.write(aliasType.aliasType)} $name;
194-
|#define PRI_$name PRI_${fmtSpec}""")
195-
))
187+
linesMember(
188+
addBlankPrefix(
189+
AnnotationCppWriter.writePreComment(aNode) ++ (
190+
s"typedef ${typeCppWriter.write(aliasType.aliasType)} $name;" ::
191+
fmtSpecList.map(s => s"#define PRI_$name PRI$s")
192+
).map(line)
193+
)
194+
)
196195
}
197196
}

compiler/lib/src/main/scala/codegen/CppWriter/ArrayCppWriter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ case class ArrayCppWriter (
8787

8888
private def getHppIncludes: CppDoc.Member = {
8989
val standardHeaders = List(
90-
"FpConfig.hpp",
90+
"Fw/FPrimeBasicTypes.hpp",
9191
"Fw/Types/ExternalString.hpp",
9292
"Fw/Types/Serializable.hpp",
9393
"Fw/Types/String.hpp"

compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentCppWriter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,13 @@ case class ComponentCppWriter (
9898
val internalStrHeaders =
9999
guardedList (hasInternalPorts) (List("Fw/Types/InternalInterfaceString.hpp"))
100100
val systemHeaders =
101-
("FpConfig.hpp" :: guardedList (hasEvents) (
101+
(guardedList (hasEvents) (
102102
List("atomic")
103103
)).map(CppWriter.systemHeaderString).sortBy(_.toLowerCase()).map(line)
104104
val userHeaders = {
105105
val standardHeaders = List.concat(
106106
List(
107+
"Fw/FPrimeBasicTypes.hpp",
107108
"Fw/Port/InputSerializePort.hpp",
108109
"Fw/Port/OutputSerializePort.hpp",
109110
"Fw/Comp/ActiveComponentBase.hpp"

compiler/lib/src/main/scala/codegen/CppWriter/ConstantCppWriter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object ConstantCppWriter extends CppWriterUtils {
1515
case constantMembers =>
1616
val fileName = ComputeCppFiles.FileNames.getConstants
1717
val hppHeaderLines = {
18-
val headers = List("FpConfig.hpp")
18+
val headers = List("Fw/FPrimeBasicTypes.hpp")
1919
Line.blank :: headers.map(CppWriter.headerLine)
2020
}
2121
val cppHeaderLines = {

compiler/lib/src/main/scala/codegen/CppWriter/CppWriterState.scala

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package fpp.compiler.codegen
33
import fpp.compiler.analysis._
44
import fpp.compiler.ast._
55
import fpp.compiler.util._
6-
import fpp.compiler.codegen.CppWriterState.builtInTypes
76

87
/** C++ Writer state */
98
case class CppWriterState(
@@ -137,8 +136,7 @@ case class CppWriterState(
137136
val name = getName(sym)
138137
for {
139138
fileName <- sym match {
140-
case _: Symbol.AbsType =>
141-
if isBuiltInType(name) then None else Some(name)
139+
case _: Symbol.AbsType => Some(name)
142140
case _: Symbol.AliasType => Some(
143141
ComputeCppFiles.FileNames.getAliasType(name)
144142
)
@@ -172,9 +170,6 @@ case class CppWriterState(
172170
usedSymbols.map(getIncludeFiles).filter(_.isDefined).map(_.get).map(CppWriterState.headerString).toList
173171
}
174172

175-
/** Is t a built-in type? */
176-
def isBuiltInType(typeName: String): Boolean = builtInTypes.contains(typeName)
177-
178173
def isTypeSupportedInC(t: Type): Boolean = {
179174
t match {
180175
case Type.AliasType(node, aliasType) =>
@@ -184,20 +179,14 @@ case class CppWriterState(
184179
// Make sure all types in the alias chain meet the C requirements
185180
case None => isTypeSupportedInC(aliasType)
186181
}
187-
case Type.AbsType(node) => isBuiltInType(getName(Symbol.AbsType(node)))
188182
case Type.PrimitiveInt(_) => true
189183
case Type.Float(_) => true
190184
case _ => false
191185
}
192186
}
193187

194188
/** Is t a primitive type (not serializable)? */
195-
def isPrimitive(t: Type, typeName: String): Boolean = (
196-
isBuiltInType(typeName) ||
197-
t.getUnderlyingType.isPrimitive ||
198-
// See if this an alias of a builtin type
199-
isBuiltInType(t.getUnderlyingType.toString())
200-
)
189+
def isPrimitive(t: Type, typeName: String): Boolean = t.getUnderlyingType.isPrimitive
201190

202191
/** Is t a string type? */
203192
def isStringType(t: Type) = t.getUnderlyingType match {
@@ -212,28 +201,6 @@ object CppWriterState {
212201
/** The default default string size */
213202
val defaultDefaultStringSize = 80
214203

215-
/** A mapping from special built-in types to their
216-
* default values */
217-
val zero: Value.Integer = Value.Integer(0)
218-
val builtInTypes: Map[String,Value.Integer] = Map(
219-
"FwChanIdType" -> zero,
220-
"FwDpIdType" -> zero,
221-
"FwDpPriorityType" -> zero,
222-
"FwEnumStoreType" -> zero,
223-
"FwEventIdType" -> zero,
224-
"FwIndexType" -> zero,
225-
"FwOpcodeType" -> zero,
226-
"FwPacketDescriptorType" -> zero,
227-
"FwPrmIdType" -> zero,
228-
"FwSignedSizeType" -> zero,
229-
"FwSizeStoreType" -> zero,
230-
"FwSizeType" -> zero,
231-
"FwTimeBaseStoreType" -> zero,
232-
"FwTimeContextStoreType" -> zero,
233-
"FwTlmPacketizeIdType" -> zero,
234-
"FwTraceIdType" -> zero,
235-
)
236-
237204
/** Construct a header string */
238205
def headerString(s: String): String = {
239206
val q = "\""

compiler/lib/src/main/scala/codegen/CppWriter/CppWriterUtils.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ import fpp.compiler.analysis._
66
trait CppWriterUtils extends LineUtils {
77

88
/** Standard system hpp headers */
9-
val standardSystemHppHeaders = List(
10-
"FpConfig.hpp"
11-
).map(CppWriter.systemHeaderString)
9+
val standardSystemHppHeaders = Nil.map(CppWriter.systemHeaderString)
1210

1311
/** Standard user hpp headers */
1412
val standardUserHppHeaders = List(
13+
"Fw/FPrimeBasicTypes.hpp",
1514
"Fw/Types/ExternalString.hpp",
1615
"Fw/Types/Serializable.hpp",
1716
"Fw/Types/String.hpp"
1817
).map(CppWriter.headerString)
1918

2019
/** Standard system cpp headers */
21-
val standardSystemCppHeaders = Nil
20+
val standardSystemCppHeaders = Nil.map(CppWriter.systemHeaderString)
2221

2322
/** Standard user cpp headers */
2423
val standardUserCppHeaders = List(

compiler/lib/src/main/scala/codegen/CppWriter/EnumCppWriter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ case class EnumCppWriter(
8383

8484
private def getHppIncludes: CppDoc.Member = {
8585
val strings = List(
86-
"FpConfig.hpp",
86+
"Fw/FPrimeBasicTypes.hpp",
8787
"Fw/Types/Serializable.hpp",
8888
"Fw/Types/String.hpp"
8989
)

compiler/lib/src/main/scala/codegen/CppWriter/PortCppWriter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ case class PortCppWriter (
122122
private def getHppIncludes: CppDoc.Member = {
123123
val systemHeaders = List(
124124
"cstdio",
125-
"cstring",
126-
"FpConfig.hpp"
125+
"cstring"
127126
).map(CppWriter.systemHeaderString).map(line)
128127
val serializableHeader = data.returnType match {
129128
case Some(_) => Nil
130129
case None => List("Fw/Types/Serializable.hpp")
131130
}
132131
val standardHeaders = (
133132
List(
133+
"Fw/FPrimeBasicTypes.hpp",
134134
"Fw/Comp/PassiveComponentBase.hpp",
135135
"Fw/Port/InputPortBase.hpp",
136136
"Fw/Port/OutputPortBase.hpp",

compiler/lib/src/main/scala/codegen/CppWriter/StructCppWriter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ case class StructCppWriter(
100100

101101
private def getHppIncludes: CppDoc.Member = {
102102
val userHeaders = List(
103-
"FpConfig.hpp",
103+
"Fw/FPrimeBasicTypes.hpp",
104104
"Fw/Types/ExternalString.hpp",
105105
"Fw/Types/Serializable.hpp",
106106
"Fw/Types/String.hpp"

compiler/lib/src/main/scala/codegen/CppWriter/ValueCppWriter.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ object ValueCppWriter {
1515

1616
override def absType(s: CppWriterState, v: Value.AbsType) = {
1717
val aNode = v.t.node
18-
val cppName = s.writeSymbol(Symbol.AbsType(aNode))
19-
CppWriterState.builtInTypes.get(cppName) match {
20-
case Some(v) => write(s, v)
21-
case None => TypeCppWriter.getName(s, v.getType) ++ "()"
22-
}
18+
TypeCppWriter.getName(s, v.getType) ++ "()"
2319
}
2420

2521
override def array(s: CppWriterState, v: Value.Array) = {

compiler/lib/src/main/scala/codegen/XmlWriter/XmlWriterState.scala

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,8 @@ case class XmlWriterState(
3131
tagFileName <- sym match {
3232
case Symbol.AbsType(aNode) =>
3333
val symbol = Symbol.AbsType(aNode)
34-
// Don't import headers for built-in types
35-
val cppName = writeSymbol(symbol)
36-
if (CppWriterState.builtInTypes.contains(cppName)) None
37-
else {
38-
val name = getName(symbol)
39-
Some("include_header", s"${name}.hpp")
40-
}
34+
val name = getName(symbol)
35+
Some("include_header", s"${name}.hpp")
4136
case Symbol.Array(aNode) => Some(
4237
"import_array_type",
4338
XmlWriterState.getArrayFileName(getName(Symbol.Array(aNode)))

compiler/scripts/fprime-gcc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,13 @@ case "$os" in
4343
;;
4444
esac
4545

46-
g++ --std=c++11 $flags $os_flags -DTGT_OS_TYPE_$os_type -I $FPRIME -I $FPRIME/config -I $FPRIME/cmake/platform/types -I . $FPRIME_GCC_FLAGS $@
46+
g++ --std=c++11 \
47+
$flags \
48+
$os_flags \
49+
-DTGT_OS_TYPE_$os_type \
50+
-I $FPRIME \
51+
-I $FPRIME/config \
52+
-I $FPRIME/cmake/platform/types \
53+
-I . \
54+
$FPRIME_GCC_FLAGS \
55+
$@

compiler/tools/fpp-depend/test/filenames_auto_generated_output.ref.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ EEnumAc.hpp
1818
EEnumAi.xml
1919
FppConstantsAc.cpp
2020
FppConstantsAc.hpp
21+
FwOpcodeTypeAliasAc.hpp
2122
PPortAc.cpp
2223
PPortAc.hpp
2324
PPortAi.xml

compiler/tools/fpp-depend/test/filenames_generated_output.ref.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ EEnumAc.hpp
1818
EEnumAi.xml
1919
FppConstantsAc.cpp
2020
FppConstantsAc.hpp
21+
FwOpcodeTypeAliasAc.hpp
2122
PPortAc.cpp
2223
PPortAc.hpp
2324
PPortAi.xml

compiler/tools/fpp-depend/test/filenames_include_auto_generated_output.ref.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ EEnumAc.hpp
1818
EEnumAi.xml
1919
FppConstantsAc.cpp
2020
FppConstantsAc.hpp
21+
FwOpcodeTypeAliasAc.hpp
2122
PPortAc.cpp
2223
PPortAc.hpp
2324
PPortAi.xml

compiler/tools/fpp-depend/test/filenames_include_generated_output.ref.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ EEnumAc.hpp
1818
EEnumAi.xml
1919
FppConstantsAc.cpp
2020
FppConstantsAc.hpp
21+
FwOpcodeTypeAliasAc.hpp
2122
PPortAc.cpp
2223
PPortAc.hpp
2324
PPortAi.xml

compiler/tools/fpp-filenames/test/include.ref.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ EEnumAc.hpp
1818
EEnumAi.xml
1919
FppConstantsAc.cpp
2020
FppConstantsAc.hpp
21+
FwOpcodeTypeAliasAc.hpp
2122
PPortAc.cpp
2223
PPortAc.hpp
2324
PPortAi.xml

compiler/tools/fpp-filenames/test/ok.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ state machine SM2 {
1010
state S
1111
}
1212

13-
type FwOpcodeType
13+
type FwOpcodeType = U32
1414
type WithCDefinition = U32
1515
type WithCDefinitionBuiltin = FwOpcodeType
1616
type WithoutCDefinition = A

compiler/tools/fpp-filenames/test/ok.ref.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ EEnumAc.hpp
1818
EEnumAi.xml
1919
FppConstantsAc.cpp
2020
FppConstantsAc.hpp
21+
FwOpcodeTypeAliasAc.hpp
2122
PPortAc.cpp
2223
PPortAc.hpp
2324
PPortAi.xml

compiler/tools/fpp-to-cpp/test/alias/AbsSerializableAc.ref.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define AbsSerializableAc_HPP
99

1010
#include "AbsTypeAliasAc.hpp"
11-
#include "FpConfig.hpp"
11+
#include "Fw/FPrimeBasicTypes.hpp"
1212
#include "Fw/Types/ExternalString.hpp"
1313
#include "Fw/Types/Serializable.hpp"
1414
#include "Fw/Types/String.hpp"

compiler/tools/fpp-to-cpp/test/alias/AbsTypeAliasAc.ref.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#ifndef AbsTypeAliasAc_HPP
88
#define AbsTypeAliasAc_HPP
99

10-
#include <FpConfig.hpp>
11-
12-
#include "Fw/Types/BasicTypes.h"
10+
#include "Fw/Types/BasicTypes.hpp"
1311
#include "T.hpp"
1412

1513
//! An alias of abstract type

0 commit comments

Comments
 (0)