From a32f13fe78982148044f5178b19b770c06fd8428 Mon Sep 17 00:00:00 2001 From: Bill Vaglienti Date: Sun, 26 Feb 2023 15:54:23 -0700 Subject: [PATCH] More fixes to referencing a redefined external structure. --- protocolfield.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++---- protocolfield.h | 3 +++ protocolparser.cpp | 2 +- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/protocolfield.cpp b/protocolfield.cpp index 8f3a0f3..5a6dc4b 100644 --- a/protocolfield.cpp +++ b/protocolfield.cpp @@ -2217,16 +2217,57 @@ void ProtocolField::getPrintIncludeDirectives(std::vector& list) co */ std::string ProtocolField::getEncodeSignature(void) const { + std::string signame = typeName; + + // It is possible that this structure name is a redefined structure, + // in which case we have to lookup the base structure name. + if(inMemoryType.isStruct) + { + const ProtocolStructure* mystruct = parser->lookUpStructure(typeName); + if(mystruct != nullptr) + signame = mystruct->getStructName(); + } + if(isNotEncoded() || isNotInMemory() || isConstant()) return ""; else if(is2dArray()) - return ", const " + typeName + " " + name + "[" + array + "][" + array2d + "]"; + return ", const " + signame + " " + name + "[" + array + "][" + array2d + "]"; else if(isArray()) - return ", const " + typeName + " " + name + "[" + array + "]"; + return ", const " + signame + " " + name + "[" + array + "]"; else if(!inMemoryType.isStruct) - return ", " + typeName + " " + name; + return ", " + signame + " " + name; + else + return ", const " + signame + "* " + name; +} + + +/*! + * Return the signature of this field in a decode function signature. The + * string will start with ", " assuming this field is not the first part of + * the function signature. + * \return the string that provides this fields decode function signature + */ +std::string ProtocolField::getDecodeSignature(void) const +{ + std::string signame = typeName; + + // It is possible that this structure name is a redefined structure, + // in which case we have to lookup the base structure name. + if(inMemoryType.isStruct) + { + const ProtocolStructure* mystruct = parser->lookUpStructure(typeName); + if(mystruct != nullptr) + signame = mystruct->getStructName(); + } + + if(isNotEncoded() || isNotInMemory()) + return ""; + else if(is2dArray()) + return ", " + signame + " " + name + "[" + array + "][" + array2d + "]"; + else if(isArray()) + return ", " + signame + " " + name + "[" + array + "]"; else - return ", const " + typeName + "* " + name; + return ", " + signame + "* " + name; } diff --git a/protocolfield.h b/protocolfield.h index c683d42..782e060 100644 --- a/protocolfield.h +++ b/protocolfield.h @@ -186,6 +186,9 @@ class ProtocolField : public Encodable //! Return the signature of this field in an encode function signature std::string getEncodeSignature(void) const override; + //! Return the signature of this field in an encode function signature + std::string getDecodeSignature(void) const override; + //! Get details needed to produce documentation for this encodable. void getDocumentationDetails(std::vector& outline, std::string& startByte, std::vector& bytes, std::vector& names, std::vector& encodings, std::vector& repeats, std::vector& comments) const override; diff --git a/protocolparser.cpp b/protocolparser.cpp index 080241c..70cee2a 100644 --- a/protocolparser.cpp +++ b/protocolparser.cpp @@ -16,7 +16,7 @@ #include // The version of the protocol generator is set here -const std::string ProtocolParser::genVersion = "3.5.b"; +const std::string ProtocolParser::genVersion = "3.5.c"; /*! * \brief ProtocolParser::ProtocolParser