From e1dd6c14367126d9795946ac61c1162f4c34bc40 Mon Sep 17 00:00:00 2001 From: Fabian Peller-Konrad <fabian.peller-konrad@kit.edu> Date: Tue, 19 Jul 2022 15:39:33 +0200 Subject: [PATCH] added filepath to read methods --- .../codegeneration/typereader/xml/Reader.cpp | 47 +++++++++---------- .../codegeneration/typereader/xml/Reader.h | 10 ++-- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.cpp b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.cpp index be81be7ea..f820853e4 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.cpp @@ -130,7 +130,7 @@ namespace armarx::aron::typereader::xml { for (const auto& include : (*codeincludes).nodes()) { - auto i = readCodeInclude(include, includePaths); + auto i = readCodeInclude(include, filePath.parent_path(), includePaths); if (not i.empty()) this->systemIncludes.push_back(i); } } @@ -140,7 +140,7 @@ namespace armarx::aron::typereader::xml { for (const auto& include : (*aronincludes).nodes()) { - auto i = readAronInclude(include, includePaths); + auto i = readAronInclude(include, filePath.parent_path(), includePaths); if (not i.empty()) this->aronIncludes.push_back(i); } } @@ -152,7 +152,7 @@ namespace armarx::aron::typereader::xml { if (util::HasTagName(include, constantes::SYSTEM_INCLUDE_TAG)) // if its a system include tag then we know that it must be a code include { - auto i = readCodeInclude(include, includePaths); + auto i = readCodeInclude(include, filePath.parent_path(), includePaths); if (not i.empty()) this->systemIncludes.push_back(i); } else @@ -174,12 +174,12 @@ namespace armarx::aron::typereader::xml { if (what.ends_with(ARON_FILE_SUFFIX)) { - auto i = readAronInclude(include, includePaths); + auto i = readAronInclude(include, filePath.parent_path(), includePaths); if (not i.empty()) this->aronIncludes.push_back(i); } else // we believe that this is a code include since it is not an xml file { - auto i = readCodeInclude(include, includePaths); + auto i = readCodeInclude(include, filePath.parent_path(), includePaths); if (not i.empty()) this->systemIncludes.push_back(i); } } @@ -194,15 +194,14 @@ namespace armarx::aron::typereader::xml { if (util::HasTagName(generateType, constantes::OBJECT_TAG)) { - for (const auto& additionalInclude : getAdditionalIncludesFromReplacements(generateType, filePath)) + for (const auto& additionalInclude : getAdditionalIncludesFromReplacements(generateType, filePath.parent_path())) { RapidXmlReaderPtr reader = RapidXmlReader::FromXmlString("<PackagePath package=\""+additionalInclude.first+"\" path=\""+additionalInclude.second+"\"/>"); auto node = reader->getRoot(); - auto i = this->readAronInclude(node, includePaths); + auto i = this->readAronInclude(node, filePath, includePaths); if (not i.empty() && std::find(this->aronIncludes.begin(), this->aronIncludes.end(), i) == this->aronIncludes.end()) { - std::cout << "OUT IS: " << i << std::endl; this->aronIncludes.push_back(i); } } @@ -237,7 +236,7 @@ namespace armarx::aron::typereader::xml } } - std::pair<std::string, std::string> Reader::readPackagePathInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths) + std::pair<std::string, std::string> Reader::readPackagePathInclude(const RapidXmlReaderNode& node, const std::filesystem::path&, const std::vector<std::filesystem::path>& includePaths) { util::EnforceTagName(node, constantes::PACKAGE_PATH_TAG); std::string package = util::GetAttribute(node, constantes::PACKAGE_ATTRIBUTE_NAME); @@ -258,7 +257,7 @@ namespace armarx::aron::typereader::xml throw error::AronException(__PRETTY_FUNCTION__, "Could not find an file `" + includepath.string() + "`. Search paths are: " + simox::alg::to_string(includePaths)); } - std::pair<std::string, std::string> Reader::readInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths) + std::pair<std::string, std::string> Reader::readInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filepath, const std::vector<std::filesystem::path>& includePaths) { util::EnforceTagName(node, constantes::INCLUDE_TAG); std::string value = util::GetAttribute(node, constantes::INCLUDE_ATTRIBUTE_NAME); @@ -267,10 +266,10 @@ namespace armarx::aron::typereader::xml value = simox::alg::replace_all(value, "<", ""); value = simox::alg::replace_all(value, ">", ""); - return {value, "\"" + value + "\""}; + return {value, "<" + value + ">"}; } - std::pair<std::string, std::string> Reader::readSystemInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths) + std::pair<std::string, std::string> Reader::readSystemInclude(const RapidXmlReaderNode& node, const std::filesystem::path&, const std::vector<std::filesystem::path>& includePaths) { util::EnforceTagName(node, constantes::SYSTEM_INCLUDE_TAG); std::string value = util::GetAttribute(node, constantes::INCLUDE_ATTRIBUTE_NAME); @@ -279,41 +278,41 @@ namespace armarx::aron::typereader::xml value = simox::alg::replace_all(value, "<", ""); value = simox::alg::replace_all(value, ">", ""); - return {value, "<" + value + ">"}; + return {"", "<" + value + ">"}; } - std::string Reader::readCodeInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths) + std::string Reader::readCodeInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filepath, const std::vector<std::filesystem::path>& includePaths) { if (util::HasTagName(node, constantes::PACKAGE_PATH_TAG)) { - return readPackagePathInclude(node, includePaths).second; + return readPackagePathInclude(node, filepath, includePaths).second; } if (util::HasTagName(node, constantes::INCLUDE_TAG)) { - return readInclude(node, includePaths).second; + return readInclude(node, filepath, includePaths).second; } if (util::HasTagName(node, constantes::SYSTEM_INCLUDE_TAG)) { - return readSystemInclude(node, includePaths).second; + return readSystemInclude(node, filepath, includePaths).second; } throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Could not parse a code include. The tag is wrong.", node.name()); } - std::string Reader::readAronInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths) + std::string Reader::readAronInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filepath, const std::vector<std::filesystem::path>& includePaths) { std::string include; - std::string orig_include; + std::string include_unescaped; if (util::HasTagName(node, constantes::PACKAGE_PATH_TAG)) { - auto p = readPackagePathInclude(node, includePaths); - orig_include = p.first; + auto p = readPackagePathInclude(node, filepath, includePaths); + include_unescaped = p.first; include = p.second; } if (util::HasTagName(node, constantes::INCLUDE_TAG)) { - auto p = readInclude(node, includePaths); - orig_include = p.first; + auto p = readInclude(node, filepath, includePaths); + include_unescaped = p.first; include = p.second; } @@ -325,7 +324,7 @@ namespace armarx::aron::typereader::xml // parse parent xml file and add objects to alreday known Reader anotherReader; - anotherReader.parseFile(orig_include, includePaths); + anotherReader.parseFile(include_unescaped, includePaths); for (const auto& previouslyKnown : anotherReader.factory.allPreviouslyKnownPublicTypes) { factory.allPreviouslyKnownPublicTypes.push_back(previouslyKnown); diff --git a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.h b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.h index 293f4c290..4cc71341c 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.h +++ b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.h @@ -60,12 +60,12 @@ namespace armarx::aron::typereader::xml std::vector<std::pair<std::string, std::string>> getAdditionalIncludesFromReplacements(const RapidXmlReaderNode& node, const std::filesystem::path& filePath); // parse includes - std::pair<std::string, std::string> readPackagePathInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths); - std::pair<std::string, std::string> readInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths); - std::pair<std::string, std::string> readSystemInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths); + std::pair<std::string, std::string> readPackagePathInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filename, const std::vector<std::filesystem::path>& includePaths); + std::pair<std::string, std::string> readInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filename, const std::vector<std::filesystem::path>& includePaths); + std::pair<std::string, std::string> readSystemInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filename, const std::vector<std::filesystem::path>& includePaths); - std::string readCodeInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths); - std::string readAronInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths); + std::string readCodeInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filename, const std::vector<std::filesystem::path>& includePaths); + std::string readAronInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filename, const std::vector<std::filesystem::path>& includePaths); // parse top-level objects type::ObjectPtr readGenerateObject(const RapidXmlReaderNode& node); -- GitLab