[yaml2obj][ELF] - Simplify the code that performs sections validation.
authorGeorgii Rymar <grimar@accesssoftek.com>
Thu, 15 Oct 2020 09:44:42 +0000 (12:44 +0300)
committerGeorgii Rymar <grimar@accesssoftek.com>
Tue, 20 Oct 2020 08:28:23 +0000 (11:28 +0300)
commitb9e2b59680ad1bbfd2b9110b3ebf3d2b22cad51b
tree5375e80d76603054b1fa07fa72f318fce1e2b2b3
parent6aabbeadae2024f468990e256706148a2c05f644
[yaml2obj][ELF] - Simplify the code that performs sections validation.

This:
1) Changes the return type of `MappingTraits<T>>::validate` to `std::string`
instead of `StringRef`. It allows to create more complex error messages.

2) It introduces std::vector<std::pair<StringRef, bool>> getEntries():
a new virtual method of Section, which is the base class for all sections.
It returns names of special section specific keys (e.g. "Entries") and flags that
says if them exist in a YAML. The code in validate() uses this list of entries
descriptions to generalize validation.
This approach was discussed in the D89039 thread.

Differential revision: https://reviews.llvm.org/D89463
12 files changed:
lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
llvm/include/llvm/ObjectYAML/DWARFYAML.h
llvm/include/llvm/ObjectYAML/ELFYAML.h
llvm/include/llvm/ObjectYAML/MachOYAML.h
llvm/include/llvm/ObjectYAML/MinidumpYAML.h
llvm/include/llvm/Support/YAMLTraits.h
llvm/lib/ObjectYAML/DWARFYAML.cpp
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/lib/ObjectYAML/MachOYAML.cpp
llvm/lib/ObjectYAML/MinidumpYAML.cpp
llvm/test/tools/yaml2obj/ELF/gnu-hash-section.yaml
llvm/unittests/Support/YAMLIOTest.cpp