Make ParsedAttrInfo and subclasses use constexpr construction

This removes a 30 kB global initializer. NFCI.
This commit is contained in:
Benjamin Kramer 2022-03-05 20:32:37 +01:00
parent 1fbdb03b1d
commit e44bbedb32
2 changed files with 49 additions and 28 deletions

View File

@ -74,12 +74,29 @@ struct ParsedAttrInfo {
// The names of the known arguments of this attribute.
ArrayRef<const char *> ArgNames;
ParsedAttrInfo(AttributeCommonInfo::Kind AttrKind =
AttributeCommonInfo::NoSemaHandlerAttribute)
: AttrKind(AttrKind), NumArgs(0), OptArgs(0), HasCustomParsing(0),
IsTargetSpecific(0), IsType(0), IsStmt(0), IsKnownToGCC(0),
IsSupportedByPragmaAttribute(0) {}
protected:
constexpr ParsedAttrInfo(AttributeCommonInfo::Kind AttrKind =
AttributeCommonInfo::NoSemaHandlerAttribute)
: AttrKind(AttrKind), NumArgs(0), OptArgs(0), NumArgMembers(0),
HasCustomParsing(0), AcceptsExprPack(0), IsTargetSpecific(0), IsType(0),
IsStmt(0), IsKnownToGCC(0), IsSupportedByPragmaAttribute(0) {}
constexpr ParsedAttrInfo(AttributeCommonInfo::Kind AttrKind, unsigned NumArgs,
unsigned OptArgs, unsigned NumArgMembers,
unsigned HasCustomParsing, unsigned AcceptsExprPack,
unsigned IsTargetSpecific, unsigned IsType,
unsigned IsStmt, unsigned IsKnownToGCC,
unsigned IsSupportedByPragmaAttribute,
ArrayRef<Spelling> Spellings,
ArrayRef<const char *> ArgNames)
: AttrKind(AttrKind), NumArgs(NumArgs), OptArgs(OptArgs),
NumArgMembers(NumArgMembers), HasCustomParsing(HasCustomParsing),
AcceptsExprPack(AcceptsExprPack), IsTargetSpecific(IsTargetSpecific),
IsType(IsType), IsStmt(IsStmt), IsKnownToGCC(IsKnownToGCC),
IsSupportedByPragmaAttribute(IsSupportedByPragmaAttribute),
Spellings(Spellings), ArgNames(ArgNames) {}
public:
virtual ~ParsedAttrInfo() = default;
/// Check if this attribute appertains to D, and issue a diagnostic if not.

View File

@ -3577,9 +3577,9 @@ static void emitArgInfo(const Record &R, raw_ostream &OS) {
// If there is a variadic argument, we will set the optional argument count
// to its largest value. Since it's currently a 4-bit number, we set it to 15.
OS << " NumArgs = " << ArgCount << ";\n";
OS << " OptArgs = " << (HasVariadic ? 15 : OptCount) << ";\n";
OS << " NumArgMembers = " << ArgMemberCount << ";\n";
OS << " /*NumArgs=*/" << ArgCount << ",\n";
OS << " /*OptArgs=*/" << (HasVariadic ? 15 : OptCount) << ",\n";
OS << " /*NumArgMembers=*/" << ArgMemberCount << ",\n";
}
static std::string GetDiagnosticSpelling(const Record &R) {
@ -4205,30 +4205,34 @@ void EmitClangAttrParsedAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
OS << "struct ParsedAttrInfo" << I->first
<< " final : public ParsedAttrInfo {\n";
OS << " ParsedAttrInfo" << I->first << "() {\n";
OS << " AttrKind = ParsedAttr::AT_" << AttrName << ";\n";
OS << " constexpr ParsedAttrInfo" << I->first << "() : ParsedAttrInfo(\n";
OS << " /*AttrKind=*/ParsedAttr::AT_" << AttrName << ",\n";
emitArgInfo(Attr, OS);
OS << " HasCustomParsing = ";
OS << Attr.getValueAsBit("HasCustomParsing") << ";\n";
OS << " AcceptsExprPack = ";
OS << Attr.getValueAsBit("AcceptsExprPack") << ";\n";
OS << " IsTargetSpecific = ";
OS << Attr.isSubClassOf("TargetSpecificAttr") << ";\n";
OS << " IsType = ";
OS << (Attr.isSubClassOf("TypeAttr") ||
Attr.isSubClassOf("DeclOrTypeAttr")) << ";\n";
OS << " IsStmt = ";
OS << " /*HasCustomParsing=*/";
OS << Attr.getValueAsBit("HasCustomParsing") << ",\n";
OS << " /*AcceptsExprPack=*/";
OS << Attr.getValueAsBit("AcceptsExprPack") << ",\n";
OS << " /*IsTargetSpecific=*/";
OS << Attr.isSubClassOf("TargetSpecificAttr") << ",\n";
OS << " /*IsType=*/";
OS << (Attr.isSubClassOf("TypeAttr") || Attr.isSubClassOf("DeclOrTypeAttr"))
<< ",\n";
OS << " /*IsStmt=*/";
OS << (Attr.isSubClassOf("StmtAttr") || Attr.isSubClassOf("DeclOrStmtAttr"))
<< ";\n";
OS << " IsKnownToGCC = ";
OS << IsKnownToGCC(Attr) << ";\n";
OS << " IsSupportedByPragmaAttribute = ";
OS << PragmaAttributeSupport.isAttributedSupported(*I->second) << ";\n";
<< ",\n";
OS << " /*IsKnownToGCC=*/";
OS << IsKnownToGCC(Attr) << ",\n";
OS << " /*IsSupportedByPragmaAttribute=*/";
OS << PragmaAttributeSupport.isAttributedSupported(*I->second) << ",\n";
if (!Spellings.empty())
OS << " Spellings = " << I->first << "Spellings;\n";
OS << " /*Spellings=*/" << I->first << "Spellings,\n";
else
OS << " /*Spellings=*/{},\n";
if (!ArgNames.empty())
OS << " ArgNames = " << I->first << "ArgNames;\n";
OS << " }\n";
OS << " /*ArgNames=*/" << I->first << "ArgNames";
else
OS << " /*ArgNames=*/{}";
OS << ") {}\n";
GenerateAppertainsTo(Attr, OS);
GenerateMutualExclusionsChecks(Attr, Records, OS, MergeDeclOS, MergeStmtOS);
GenerateLangOptRequirements(Attr, OS);