================ @@ -0,0 +1,236 @@ +//==--- Traits.td - Generate expression and type traits -------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "TableGenBackends.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/TableGen/Record.h" +#include "llvm/TableGen/TableGenBackend.h" + +using namespace llvm; + +namespace { + +std::vector<const Record *> +getAllDerivedDefsInDeclOrder(const RecordKeeper &Records, StringRef ClassName) { + std::vector<const Record *> Defs = + Records.getAllDerivedDefinitions(ClassName); + llvm::sort(Defs, [](const Record *A, const Record *B) { + return A->getID() < B->getID(); + }); + return Defs; +} + +void emitKeyFlags(ArrayRef<const Record *> KeyFlags, raw_ostream &OS) { + assert(!KeyFlags.empty() && "KeyFlags should never be empty"); + interleave( + KeyFlags, OS, [&](const Record *KeyFlag) { OS << KeyFlag->getName(); }, + " | "); +} + +StringRef recordKindToMacro(const Record *R) { + if (R->isSubClassOf("UnaryTrait")) + return "TYPE_TRAIT_1"; + if (R->isSubClassOf("BinaryTrait")) + return "TYPE_TRAIT_2"; + if (R->isSubClassOf("VariadicTrait")) + return "TYPE_TRAIT_N"; + if (R->isSubClassOf("ArrayTrait")) + return "ARRAY_TYPE_TRAIT"; + if (R->isSubClassOf("ExpressionTrait")) + return "EXPRESSION_TRAIT"; + if (R->isSubClassOf("UnaryExprOrTypeTrait")) + return "UNARY_EXPR_OR_TYPE_TRAIT"; + if (R->isSubClassOf("CXX11UnaryExprOrTypeTrait")) + return "CXX11_UNARY_EXPR_OR_TYPE_TRAIT"; + if (R->isSubClassOf("TransformTypeTrait")) + return "TRANSFORM_TYPE_TRAIT_DEF"; + if (R->isSubClassOf("Alias")) + return "ALIAS"; + llvm_unreachable("unexpected Trait subclass"); ---------------- erichkeane wrote:
Probably not, though I wonder if these `kind` macro names should be a member of the `TypeTrait` or `Trait` thing, and added in the tablegen rather than looking it up like this. https://github.com/llvm/llvm-project/pull/201491 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
