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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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