From 6967da8ffafe094507b153a93c607b95f2ab22a6 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 23 Apr 2019 18:46:53 +0000 Subject: [PATCH] llvm-cvtres: Split addChild(ID) into two functions Before, there was an IsData parameter. Now, there are two different functions for data nodes and ID nodes. No behavior change, needed for a follow-up change to make two data nodes (but not two ID nodes) with the same ID an error. For consistency, rename another addChild() overload to addNameChild(). llvm-svn: 359024 --- llvm/include/llvm/Object/WindowsResource.h | 8 +++---- llvm/lib/Object/WindowsResource.cpp | 36 +++++++++++++++++++----------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/llvm/include/llvm/Object/WindowsResource.h b/llvm/include/llvm/Object/WindowsResource.h index fd04e60..d241da8 100644 --- a/llvm/include/llvm/Object/WindowsResource.h +++ b/llvm/include/llvm/Object/WindowsResource.h @@ -195,10 +195,10 @@ public: TreeNode &addTypeNode(const ResourceEntryRef &Entry, bool &IsNewTypeString); TreeNode &addNameNode(const ResourceEntryRef &Entry, bool &IsNewNameString); TreeNode &addLanguageNode(const ResourceEntryRef &Entry); - TreeNode &addChild(uint32_t ID, bool IsDataNode = false, - uint16_t MajorVersion = 0, uint16_t MinorVersion = 0, - uint32_t Characteristics = 0); - TreeNode &addChild(ArrayRef NameRef, bool &IsNewString); + TreeNode &addDataChild(uint32_t ID, uint16_t MajorVersion, + uint16_t MinorVersion, uint32_t Characteristics); + TreeNode &addIDChild(uint32_t ID); + TreeNode &addNameChild(ArrayRef NameRef, bool &IsNewString); bool IsDataNode = false; uint32_t StringIndex; diff --git a/llvm/lib/Object/WindowsResource.cpp b/llvm/lib/Object/WindowsResource.cpp index 53fe4d5..2195a61 100644 --- a/llvm/lib/Object/WindowsResource.cpp +++ b/llvm/lib/Object/WindowsResource.cpp @@ -214,35 +214,45 @@ WindowsResourceParser::TreeNode & WindowsResourceParser::TreeNode::addTypeNode(const ResourceEntryRef &Entry, bool &IsNewTypeString) { if (Entry.checkTypeString()) - return addChild(Entry.getTypeString(), IsNewTypeString); + return addNameChild(Entry.getTypeString(), IsNewTypeString); else - return addChild(Entry.getTypeID()); + return addIDChild(Entry.getTypeID()); } WindowsResourceParser::TreeNode & WindowsResourceParser::TreeNode::addNameNode(const ResourceEntryRef &Entry, bool &IsNewNameString) { if (Entry.checkNameString()) - return addChild(Entry.getNameString(), IsNewNameString); + return addNameChild(Entry.getNameString(), IsNewNameString); else - return addChild(Entry.getNameID()); + return addIDChild(Entry.getNameID()); } WindowsResourceParser::TreeNode & WindowsResourceParser::TreeNode::addLanguageNode( const ResourceEntryRef &Entry) { - return addChild(Entry.getLanguage(), true, Entry.getMajorVersion(), - Entry.getMinorVersion(), Entry.getCharacteristics()); + return addDataChild(Entry.getLanguage(), Entry.getMajorVersion(), + Entry.getMinorVersion(), Entry.getCharacteristics()); } -WindowsResourceParser::TreeNode &WindowsResourceParser::TreeNode::addChild( - uint32_t ID, bool IsDataNode, uint16_t MajorVersion, uint16_t MinorVersion, +WindowsResourceParser::TreeNode &WindowsResourceParser::TreeNode::addDataChild( + uint32_t ID, uint16_t MajorVersion, uint16_t MinorVersion, uint32_t Characteristics) { auto Child = IDChildren.find(ID); if (Child == IDChildren.end()) { - auto NewChild = - IsDataNode ? createDataNode(MajorVersion, MinorVersion, Characteristics) - : createIDNode(); + auto NewChild = createDataNode(MajorVersion, MinorVersion, Characteristics); + WindowsResourceParser::TreeNode &Node = *NewChild; + IDChildren.emplace(ID, std::move(NewChild)); + return Node; + } else + return *(Child->second); +} + +WindowsResourceParser::TreeNode &WindowsResourceParser::TreeNode::addIDChild( + uint32_t ID) { + auto Child = IDChildren.find(ID); + if (Child == IDChildren.end()) { + auto NewChild = createIDNode(); WindowsResourceParser::TreeNode &Node = *NewChild; IDChildren.emplace(ID, std::move(NewChild)); return Node; @@ -251,8 +261,8 @@ WindowsResourceParser::TreeNode &WindowsResourceParser::TreeNode::addChild( } WindowsResourceParser::TreeNode & -WindowsResourceParser::TreeNode::addChild(ArrayRef NameRef, - bool &IsNewString) { +WindowsResourceParser::TreeNode::addNameChild(ArrayRef NameRef, + bool &IsNewString) { std::string NameString; ArrayRef CorrectedName; std::vector EndianCorrectedName; -- 2.7.4