diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index d275873651786..4c6966c922cc7 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -410,14 +410,8 @@ class ASTContext : public RefCountedBase { /// The identifier 'NSCopying'. IdentifierInfo *NSCopyingName = nullptr; - /// The identifier '__make_integer_seq'. - mutable IdentifierInfo *MakeIntegerSeqName = nullptr; - - /// The identifier '__type_pack_element'. - mutable IdentifierInfo *TypePackElementName = nullptr; - - /// The identifier '__builtin_common_type'. - mutable IdentifierInfo *BuiltinCommonTypeName = nullptr; +#define BuiltinTemplate(BTName) mutable IdentifierInfo *Name##BTName = nullptr; +#include "clang/Basic/BuiltinTemplates.inc" QualType ObjCConstantStringType; mutable RecordDecl *CFConstantStringTagDecl = nullptr; @@ -629,9 +623,10 @@ class ASTContext : public RefCountedBase { TranslationUnitDecl *TUDecl = nullptr; mutable ExternCContextDecl *ExternCContext = nullptr; - mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr; - mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr; - mutable BuiltinTemplateDecl *BuiltinCommonTypeDecl = nullptr; + +#define BuiltinTemplate(BTName) \ + mutable BuiltinTemplateDecl *Decl##BTName = nullptr; +#include "clang/Basic/BuiltinTemplates.inc" /// The associated SourceManager object. SourceManager &SourceMgr; @@ -1157,9 +1152,9 @@ class ASTContext : public RefCountedBase { } ExternCContextDecl *getExternCContextDecl() const; - BuiltinTemplateDecl *getMakeIntegerSeqDecl() const; - BuiltinTemplateDecl *getTypePackElementDecl() const; - BuiltinTemplateDecl *getBuiltinCommonTypeDecl() const; + +#define BuiltinTemplate(BTName) BuiltinTemplateDecl *get##BTName##Decl() const; +#include "clang/Basic/BuiltinTemplates.inc" // Builtin Types. CanQualType VoidTy; @@ -2107,23 +2102,13 @@ class ASTContext : public RefCountedBase { return BoolName; } - IdentifierInfo *getMakeIntegerSeqName() const { - if (!MakeIntegerSeqName) - MakeIntegerSeqName = &Idents.get("__make_integer_seq"); - return MakeIntegerSeqName; - } - - IdentifierInfo *getTypePackElementName() const { - if (!TypePackElementName) - TypePackElementName = &Idents.get("__type_pack_element"); - return TypePackElementName; - } - - IdentifierInfo *getBuiltinCommonTypeName() const { - if (!BuiltinCommonTypeName) - BuiltinCommonTypeName = &Idents.get("__builtin_common_type"); - return BuiltinCommonTypeName; +#define BuiltinTemplate(BTName) \ + IdentifierInfo *get##BTName##Name() const { \ + if (!Name##BTName) \ + Name##BTName = &Idents.get(#BTName); \ + return Name##BTName; \ } +#include "clang/Basic/BuiltinTemplates.inc" /// Retrieve the Objective-C "instancetype" type, if already known; /// otherwise, returns a NULL type; diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h index 49964b43c7d1d..384f7b031e007 100644 --- a/clang/include/clang/AST/DeclID.h +++ b/clang/include/clang/AST/DeclID.h @@ -71,20 +71,14 @@ enum PredefinedDeclIDs { /// The extern "C" context. PREDEF_DECL_EXTERN_C_CONTEXT_ID, - /// The internal '__make_integer_seq' template. - PREDEF_DECL_MAKE_INTEGER_SEQ_ID, - /// The internal '__NSConstantString' typedef. PREDEF_DECL_CF_CONSTANT_STRING_ID, /// The internal '__NSConstantString' tag type. PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID, - /// The internal '__type_pack_element' template. - PREDEF_DECL_TYPE_PACK_ELEMENT_ID, - - /// The internal '__builtin_common_type' template. - PREDEF_DECL_COMMON_TYPE_ID, +#define BuiltinTemplate(BTName) PREDEF_DECL##BTName##_ID, +#include "clang/Basic/BuiltinTemplates.inc" /// The number of declaration IDs that are predefined. NUM_PREDEF_DECL_IDS diff --git a/clang/include/clang/Basic/BuiltinTemplates.td b/clang/include/clang/Basic/BuiltinTemplates.td new file mode 100644 index 0000000000000..d46ce063d2f7e --- /dev/null +++ b/clang/include/clang/Basic/BuiltinTemplates.td @@ -0,0 +1,52 @@ +//===--- BuiltinTemplates.td - Clang builtin template aliases ---*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +class TemplateArg { + string Name = name; +} + +class Template args, string name> : TemplateArg { + list Args = args; +} + +class Class : TemplateArg { + bit IsVariadic = is_variadic; +} + +class NTTP : TemplateArg { + string TypeName = type_name; + bit IsVariadic = is_variadic; +} + +class BuiltinNTTP : TemplateArg<""> { + string TypeName = type_name; +} + +def SizeT : BuiltinNTTP<"size_t"> {} + +class BuiltinTemplate template_head> { + list TemplateHead = template_head; +} + +// template