[clang] [Multilib] Custom flags YAML parsing (PR #110657)
Victor Campos via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 4 07:42:18 PST 2024
================
@@ -259,11 +266,69 @@ template <> struct llvm::yaml::MappingTraits<MultilibSet::FlagMatcher> {
}
};
+template <>
+struct llvm::yaml::MappingContextTraits<custom_flag::CustomFlagValueDetail,
+ llvm::SmallSet<std::string, 32>> {
+ static void mapping(llvm::yaml::IO &io, custom_flag::CustomFlagValueDetail &V,
+ llvm::SmallSet<std::string, 32> &) {
+ io.mapRequired("Name", V.Name);
+ io.mapOptional("ExtraBuildArgs", V.ExtraBuildArgs);
+ }
+ static std::string validate(IO &io, custom_flag::CustomFlagValueDetail &V,
+ llvm::SmallSet<std::string, 32> &NameSet) {
+ if (V.Name.empty())
+ return "custom flag value requires a name";
+ if (!NameSet.insert(V.Name).second)
+ return "duplicate custom flag value name: \"" + V.Name + "\"";
+ return {};
+ }
+};
+
+template <>
+struct llvm::yaml::MappingContextTraits<custom_flag::CustomFlagDeclarationPtr,
+ llvm::SmallSet<std::string, 32>> {
+ static void mapping(llvm::yaml::IO &io,
+ custom_flag::CustomFlagDeclarationPtr &V,
+ llvm::SmallSet<std::string, 32> &NameSet) {
+ assert(!V);
+ V = std::make_shared<custom_flag::CustomFlagDeclaration>();
+ io.mapRequired("Name", V->Name);
+ io.mapRequired("Values", V->ValueList, NameSet);
+ std::string DefaultValueName;
+ io.mapRequired("Default", DefaultValueName);
+
+ for (auto [Idx, Value] : llvm::enumerate(V->ValueList)) {
+ Value.Decl = V;
+ if (Value.Name == DefaultValueName) {
+ assert(V->DefaultValueIdx == ~0UL);
+ V->DefaultValueIdx = Idx;
+ }
+ }
+ }
+ static std::string validate(IO &io, custom_flag::CustomFlagDeclarationPtr &V,
+ llvm::SmallSet<std::string, 32> &) {
+ if (V->Name.empty())
+ return "custom flag requires a name";
+ if (V->ValueList.empty())
+ return "custom flag must have at least one value";
+ if (V->DefaultValueIdx >= V->ValueList.size())
+ return "custom flag must have a default value";
+ if (llvm::any_of(V->ValueList, [&V](const auto &Value) {
+ return !Value.Decl || Value.Decl != V;
+ }))
+ return "custom flag value missing reference to its custom flag "
+ "declaration";
----------------
vhscampos wrote:
Fixed
https://github.com/llvm/llvm-project/pull/110657
More information about the cfe-commits
mailing list