Revise header files in generated C++

This commit is contained in:
bocchino 2022-07-08 13:48:01 -07:00
parent c88938b938
commit cceec03f05
21 changed files with 12 additions and 56 deletions

View File

@ -8,11 +8,7 @@ import fpp.compiler.util._
case class ArrayCppWriter ( case class ArrayCppWriter (
s: CppWriterState, s: CppWriterState,
aNode: Ast.Annotated[AstNode[Ast.DefArray]] aNode: Ast.Annotated[AstNode[Ast.DefArray]]
) extends AstVisitor with CppWriterLineUtils { ) extends CppWriterLineUtils {
type In = CppWriterState
type Out = List[Line]
private val node = aNode._2 private val node = aNode._2
@ -46,12 +42,10 @@ case class ArrayCppWriter (
data.eltType data.eltType
) )
override def default(s: CppWriterState): List[Line] = Nil private def writeIncludeDirectives(
override def defArrayAnnotatedNode(
s: CppWriterState, s: CppWriterState,
aNode: Ast.Annotated[AstNode[Ast.DefArray]] aNode: Ast.Annotated[AstNode[Ast.DefArray]]
): List[Line] = { ): List[String] = {
val Right(a) = UsedSymbols.defArrayAnnotatedNode(s.a, aNode) val Right(a) = UsedSymbols.defArrayAnnotatedNode(s.a, aNode)
s.writeIncludeDirectives(a.usedSymbolSet) s.writeIncludeDirectives(a.usedSymbolSet)
} }
@ -93,19 +87,14 @@ case class ArrayCppWriter (
} }
private def getHppIncludes: CppDoc.Member = { private def getHppIncludes: CppDoc.Member = {
val strings = List( val standardHeaders = List(
"Fw/Types/BasicTypes.hpp", "Fw/Types/BasicTypes.hpp",
"Fw/Types/Serializable.hpp", "Fw/Types/Serializable.hpp",
"Fw/Types/String.hpp" "Fw/Types/String.hpp"
) ).map(CppWriter.headerString)
CppWriter.linesMember( val symbolHeaders = writeIncludeDirectives(s, aNode)
List( val headers = standardHeaders ++ symbolHeaders
Line.blank :: CppWriter.linesMember(addBlankPrefix(headers.sorted.map(line)))
strings.map(CppWriter.headerString).map(line),
Line.blank ::
defArrayAnnotatedNode(s, aNode),
).flatten
)
} }
private def getCppIncludes: CppDoc.Member = { private def getCppIncludes: CppDoc.Member = {

View File

@ -129,7 +129,7 @@ case class CppWriterState(
} }
/** Write include directives as lines */ /** Write include directives as lines */
def writeIncludeDirectives(usedSymbols: Iterable[Symbol]): List[Line] = { def writeIncludeDirectives(usedSymbols: Iterable[Symbol]): List[String] = {
def getHeaderStr(file: File.JavaPath) = def getHeaderStr(file: File.JavaPath) =
CppWriter.headerString(s"${file.toString}.hpp") CppWriter.headerString(s"${file.toString}.hpp")
def getDirectiveforSymbol(sym: Symbol): Option[String] = sym match { def getDirectiveforSymbol(sym: Symbol): Option[String] = sym match {
@ -143,9 +143,6 @@ case class CppWriterState(
case Symbol.Component(node) => Some( case Symbol.Component(node) => Some(
getHeaderStr(getRelativePath(ComputeCppFiles.FileNames.getComponent(getName(Symbol.Component(node))))) getHeaderStr(getRelativePath(ComputeCppFiles.FileNames.getComponent(getName(Symbol.Component(node)))))
) )
case Symbol.Constant(_) => Some(
getHeaderStr(getRelativePath(ComputeCppFiles.FileNames.getConstants))
)
case Symbol.Enum(node) => Some( case Symbol.Enum(node) => Some(
getHeaderStr(getRelativePath(ComputeCppFiles.FileNames.getEnum(getName(Symbol.Enum(node))))) getHeaderStr(getRelativePath(ComputeCppFiles.FileNames.getEnum(getName(Symbol.Enum(node)))))
) )
@ -161,10 +158,7 @@ case class CppWriterState(
case _ => None case _ => None
} }
usedSymbols.map(getDirectiveforSymbol).filter(_.isDefined).map(_.get).toList match { usedSymbols.map(getDirectiveforSymbol).filter(_.isDefined).map(_.get).toList
case Nil => Nil
case strings => strings.map(Line(_))
}
} }
/** Is this a built-in type? */ /** Is this a built-in type? */

View File

@ -10,7 +10,6 @@
#include "Fw/Types/BasicTypes.hpp" #include "Fw/Types/BasicTypes.hpp"
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "T.hpp" #include "T.hpp"
//! An array of abstract type //! An array of abstract type

View File

@ -11,7 +11,6 @@
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
//! An array of a built-in type //! An array of a built-in type
class BuiltInType : class BuiltInType :
public Fw::Serializable public Fw::Serializable

View File

@ -7,12 +7,11 @@
#ifndef Enum1ArrayAc_HPP #ifndef Enum1ArrayAc_HPP
#define Enum1ArrayAc_HPP #define Enum1ArrayAc_HPP
#include "E1EnumAc.hpp"
#include "Fw/Types/BasicTypes.hpp" #include "Fw/Types/BasicTypes.hpp"
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "E1EnumAc.hpp"
//! Array with enum argument //! Array with enum argument
class Enum1 : class Enum1 :
public Fw::Serializable public Fw::Serializable

View File

@ -7,12 +7,11 @@
#ifndef Enum2ArrayAc_HPP #ifndef Enum2ArrayAc_HPP
#define Enum2ArrayAc_HPP #define Enum2ArrayAc_HPP
#include "E2EnumAc.hpp"
#include "Fw/Types/BasicTypes.hpp" #include "Fw/Types/BasicTypes.hpp"
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "E2EnumAc.hpp"
class Enum2 : class Enum2 :
public Fw::Serializable public Fw::Serializable
{ {

View File

@ -10,7 +10,6 @@
#include "Fw/Types/BasicTypes.hpp" #include "Fw/Types/BasicTypes.hpp"
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "PrimitiveF64ArrayAc.hpp" #include "PrimitiveF64ArrayAc.hpp"
//! An array of arrays //! An array of arrays

View File

@ -11,8 +11,6 @@
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "FppConstantsAc.hpp"
namespace M { namespace M {
class PrimitiveBool : class PrimitiveBool :

View File

@ -11,8 +11,6 @@
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "FppConstantsAc.hpp"
namespace M { namespace M {
//! An array of F32 with default value and format string //! An array of F32 with default value and format string

View File

@ -11,8 +11,6 @@
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "FppConstantsAc.hpp"
namespace M { namespace M {
//! An array of F32 with format string //! An array of F32 with format string

View File

@ -11,8 +11,6 @@
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "FppConstantsAc.hpp"
namespace M { namespace M {
//! An array of F64 with default value and format string //! An array of F64 with default value and format string

View File

@ -11,8 +11,6 @@
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "FppConstantsAc.hpp"
namespace M { namespace M {
//! An array of I32 with format string //! An array of I32 with format string

View File

@ -11,8 +11,6 @@
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "FppConstantsAc.hpp"
namespace M { namespace M {
//! An array of I64 with format string //! An array of I64 with format string

View File

@ -11,8 +11,6 @@
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "FppConstantsAc.hpp"
namespace M { namespace M {
class PrimitiveU16 : class PrimitiveU16 :

View File

@ -11,8 +11,6 @@
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "FppConstantsAc.hpp"
namespace M { namespace M {
class PrimitiveU8 : class PrimitiveU8 :

View File

@ -11,7 +11,6 @@
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
//! An array of strings //! An array of strings
class String1 : class String1 :
public Fw::Serializable public Fw::Serializable

View File

@ -11,7 +11,6 @@
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
//! An array of strings with specified default value and format string //! An array of strings with specified default value and format string
class String2 : class String2 :
public Fw::Serializable public Fw::Serializable

View File

@ -10,7 +10,6 @@
#include "Fw/Types/BasicTypes.hpp" #include "Fw/Types/BasicTypes.hpp"
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "String2ArrayAc.hpp" #include "String2ArrayAc.hpp"
//! An array of arrays of strings //! An array of arrays of strings

View File

@ -10,7 +10,6 @@
#include "Fw/Types/BasicTypes.hpp" #include "Fw/Types/BasicTypes.hpp"
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "S1SerializableAc.hpp" #include "S1SerializableAc.hpp"
//! An array of structs //! An array of structs

View File

@ -10,7 +10,6 @@
#include "Fw/Types/BasicTypes.hpp" #include "Fw/Types/BasicTypes.hpp"
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "S2SerializableAc.hpp" #include "S2SerializableAc.hpp"
//! Array of structs with struct member //! Array of structs with struct member

View File

@ -10,7 +10,6 @@
#include "Fw/Types/BasicTypes.hpp" #include "Fw/Types/BasicTypes.hpp"
#include "Fw/Types/Serializable.hpp" #include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp" #include "Fw/Types/String.hpp"
#include "S3SerializableAc.hpp" #include "S3SerializableAc.hpp"
//! An array of structs with array member //! An array of structs with array member