From: Sean Hunt Date: Sun, 30 May 2010 07:21:58 +0000 (+0000) Subject: Convert DeclNodes to use TableGen. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a55591af3e5506b95a9718e15380129fbfc5ebc;p=clang Convert DeclNodes to use TableGen. The macros required for DeclNodes use have changed to match the use of StmtNodes. The FooFirst enumerator constants have been named firstFoo to match usage elsewhere. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105165 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/CMakeLists.txt b/include/clang/AST/CMakeLists.txt index c24ea06aa0..4359de3cc4 100644 --- a/include/clang/AST/CMakeLists.txt +++ b/include/clang/AST/CMakeLists.txt @@ -3,3 +3,9 @@ tablegen(StmtNodes.inc -gen-clang-stmt-nodes) add_custom_target(ClangStmtNodes DEPENDS StmtNodes.inc) + +set(LLVM_TARGET_DEFINITIONS DeclNodes.td) +tablegen(DeclNodes.inc + -gen-clang-decl-nodes) +add_custom_target(ClangDeclNodes + DEPENDS DeclNodes.inc) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 7d5b66e02a..61447295ce 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -216,7 +216,7 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const NamedDecl *D) { return true; } - static bool classofKind(Kind K) { return K >= NamedFirst && K <= NamedLast; } + static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; } }; inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, @@ -361,7 +361,7 @@ public: // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const ValueDecl *D) { return true; } - static bool classofKind(Kind K) { return K >= ValueFirst && K <= ValueLast; } + static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; } }; /// \brief Represents a ValueDecl that came out of a declarator. @@ -417,7 +417,7 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const DeclaratorDecl *D) { return true; } static bool classofKind(Kind K) { - return K >= DeclaratorFirst && K <= DeclaratorLast; + return K >= firstDeclarator && K <= lastDeclarator; } }; @@ -908,7 +908,7 @@ public: // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const VarDecl *D) { return true; } - static bool classofKind(Kind K) { return K >= VarFirst && K <= VarLast; } + static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; } }; class ImplicitParamDecl : public VarDecl { @@ -1493,7 +1493,7 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const FunctionDecl *D) { return true; } static bool classofKind(Kind K) { - return K >= FunctionFirst && K <= FunctionLast; + return K >= firstFunction && K <= lastFunction; } static DeclContext *castToDeclContext(const FunctionDecl *D) { return static_cast(const_cast(D)); @@ -1556,7 +1556,7 @@ public: // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const FieldDecl *D) { return true; } - static bool classofKind(Kind K) { return K >= FieldFirst && K <= FieldLast; } + static bool classofKind(Kind K) { return K >= firstField && K <= lastField; } }; /// EnumConstantDecl - An instance of this object exists for each enum constant @@ -1625,7 +1625,7 @@ public: // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const TypeDecl *D) { return true; } - static bool classofKind(Kind K) { return K >= TypeFirst && K <= TypeLast; } + static bool classofKind(Kind K) { return K >= firstType && K <= lastType; } }; @@ -1847,7 +1847,7 @@ public: // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const TagDecl *D) { return true; } - static bool classofKind(Kind K) { return K >= TagFirst && K <= TagLast; } + static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; } static DeclContext *castToDeclContext(const TagDecl *D) { return static_cast(const_cast(D)); @@ -2092,7 +2092,7 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const RecordDecl *D) { return true; } static bool classofKind(Kind K) { - return K >= RecordFirst && K <= RecordLast; + return K >= firstRecord && K <= lastRecord; } }; diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index c15aeef14b..453c8597bf 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -68,12 +68,13 @@ class Decl { public: /// \brief Lists the kind of concrete classes of Decl. enum Kind { -#define DECL(Derived, Base) Derived, -#define DECL_RANGE(CommonBase, Start, End) \ - CommonBase##First = Start, CommonBase##Last = End, -#define LAST_DECL_RANGE(CommonBase, Start, End) \ - CommonBase##First = Start, CommonBase##Last = End -#include "clang/AST/DeclNodes.def" +#define DECL(DERIVED, BASE) DERIVED, +#define ABSTRACT_DECL(DECL) +#define DECL_RANGE(BASE, START, END) \ + first##BASE = START, last##BASE = END, +#define LAST_DECL_RANGE(BASE, START, END) \ + first##BASE = START, last##BASE = END +#include "clang/AST/DeclNodes.inc" }; /// \brief A placeholder type used to construct an empty shell of a @@ -244,7 +245,7 @@ protected: HasAttrs(false), Implicit(false), Used(false), Access(AS_none), PCHLevel(0), IdentifierNamespace(getIdentifierNamespaceForKind(DK)) { - if (Decl::CollectingStats()) addDeclKind(DK); + if (Decl::CollectingStats()) add(DK); } virtual ~Decl(); @@ -482,7 +483,7 @@ public: SourceLocation getBodyRBrace() const; // global temp stats (until we have a per-module visitor) - static void addDeclKind(Kind k); + static void add(Kind k); static bool CollectingStats(bool Enable = false); static void PrintStats(); @@ -687,7 +688,7 @@ public: case Decl::ObjCMethod: return true; default: - return DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast; + return DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction; } } @@ -700,7 +701,7 @@ public: } bool isRecord() const { - return DeclKind >= Decl::RecordFirst && DeclKind <= Decl::RecordLast; + return DeclKind >= Decl::firstRecord && DeclKind <= Decl::lastRecord; } bool isNamespace() const { @@ -1083,9 +1084,10 @@ public: static bool classof(const Decl *D); static bool classof(const DeclContext *D) { return true; } -#define DECL_CONTEXT(Name) \ - static bool classof(const Name##Decl *D) { return true; } -#include "clang/AST/DeclNodes.def" +#define DECL(NAME, BASE) +#define DECL_CONTEXT(NAME) \ + static bool classof(const NAME##Decl *D) { return true; } +#include "clang/AST/DeclNodes.inc" void dumpDeclContext() const; diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index c19c200f26..f672433c89 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -920,9 +920,7 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { - return K == CXXRecord || - K == ClassTemplateSpecialization || - K == ClassTemplatePartialSpecialization; + return K >= firstCXXRecord && K <= lastCXXRecord; } static bool classof(const CXXRecordDecl *D) { return true; } static bool classof(const ClassTemplateSpecializationDecl *D) { @@ -1012,7 +1010,7 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const CXXMethodDecl *D) { return true; } static bool classofKind(Kind K) { - return K >= CXXMethod && K <= CXXConversion; + return K >= firstCXXMethod && K <= lastCXXMethod; } }; @@ -1607,7 +1605,7 @@ class UsingDirectiveDecl : public NamedDecl { SourceLocation IdentLoc, NamedDecl *Nominated, DeclContext *CommonAncestor) - : NamedDecl(Decl::UsingDirective, DC, L, getName()), + : NamedDecl(UsingDirective, DC, L, getName()), NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange), Qualifier(Qualifier), IdentLoc(IdentLoc), NominatedNamespace(Nominated), @@ -1680,7 +1678,7 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const UsingDirectiveDecl *D) { return true; } - static bool classofKind(Kind K) { return K == Decl::UsingDirective; } + static bool classofKind(Kind K) { return K == UsingDirective; } // Friend for getUsingDirectiveName. friend class DeclContext; @@ -1714,7 +1712,7 @@ class NamespaceAliasDecl : public NamedDecl { SourceRange QualifierRange, NestedNameSpecifier *Qualifier, SourceLocation IdentLoc, NamedDecl *Namespace) - : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc), + : NamedDecl(NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc), QualifierRange(QualifierRange), Qualifier(Qualifier), IdentLoc(IdentLoc), Namespace(Namespace) { } @@ -1786,7 +1784,7 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const NamespaceAliasDecl *D) { return true; } - static bool classofKind(Kind K) { return K == Decl::NamespaceAlias; } + static bool classofKind(Kind K) { return K == NamespaceAlias; } }; /// UsingShadowDecl - Represents a shadow declaration introduced into @@ -1866,7 +1864,7 @@ class UsingDecl : public NamedDecl { UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR, SourceLocation UL, NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg) - : NamedDecl(Decl::Using, DC, L, Name), + : NamedDecl(Using, DC, L, Name), NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS), IsTypeName(IsTypeNameArg) { } @@ -1934,7 +1932,7 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const UsingDecl *D) { return true; } - static bool classofKind(Kind K) { return K == Decl::Using; } + static bool classofKind(Kind K) { return K == Using; } }; /// UnresolvedUsingValueDecl - Represents a dependent using @@ -1960,7 +1958,7 @@ class UnresolvedUsingValueDecl : public ValueDecl { NestedNameSpecifier *TargetNNS, SourceLocation TargetNameLoc, DeclarationName TargetName) - : ValueDecl(Decl::UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty), + : ValueDecl(UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty), TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc), TargetNestedNameSpecifier(TargetNNS) { } @@ -1997,7 +1995,7 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const UnresolvedUsingValueDecl *D) { return true; } - static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingValue; } + static bool classofKind(Kind K) { return K == UnresolvedUsingValue; } }; /// UnresolvedUsingTypenameDecl - Represents a dependent using @@ -2026,7 +2024,7 @@ class UnresolvedUsingTypenameDecl : public TypeDecl { SourceLocation TypenameLoc, SourceRange TargetNNR, NestedNameSpecifier *TargetNNS, SourceLocation TargetNameLoc, IdentifierInfo *TargetName) - : TypeDecl(Decl::UnresolvedUsingTypename, DC, TargetNameLoc, TargetName), + : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName), TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc), TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS) { } @@ -2070,7 +2068,7 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; } - static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingTypename; } + static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } }; /// StaticAssertDecl - Represents a C++0x static_assert declaration. @@ -2098,7 +2096,7 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(StaticAssertDecl *D) { return true; } - static bool classofKind(Kind K) { return K == Decl::StaticAssert; } + static bool classofKind(Kind K) { return K == StaticAssert; } }; /// Insertion operator for diagnostics. This allows sending AccessSpecifier's diff --git a/include/clang/AST/DeclNodes.def b/include/clang/AST/DeclNodes.def deleted file mode 100644 index 5b03ff8d91..0000000000 --- a/include/clang/AST/DeclNodes.def +++ /dev/null @@ -1,165 +0,0 @@ -//===-- DeclNodes.def - Metadata about Decl AST nodes -----------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines the declaration nodes within the AST. The -// description of the declaration nodes uses six macros: -// -// DECL(Derived, Base) describes a normal declaration type Derived -// and specifies its base class. Note that Derived should not have -// the Decl suffix on it, while Base should. -// -// LAST_DECL(Derived, Base) is like DECL, but is used for the last -// declaration in the list. -// -// ABSTRACT_DECL(Derived, Base) describes an abstract class that is -// used to specify a classification of declarations. For example, -// TagDecl is an abstract class used to describe the various kinds of -// "tag" declarations (unions, structs, classes, enums). -// -// DECL_CONTEXT(Decl) specifies that Decl is a kind of declaration -// that is also a DeclContext. -// -// LAST_DECL_CONTEXT(Decl) is like DECL_CONTEXT, but is used for the -// last declaration context. -// -// DECL_RANGE(CommonBase, Start, End) specifies a range of -// declaration values that have a common (potentially indirect) base -// class. -// -// LAST_DECL_RANGE(CommonBase, Start, End) is like DECL_RANGE, but is -// used for the last declaration range. -// -// Note that, due to the use of ranges, the order of the these -// declarations is significant. A declaration should be listed under -// its base class. -// ===----------------------------------------------------------------------===// - -#ifndef DECL -# define DECL(Derived, Base) -#endif - -#ifndef LAST_DECL -# define LAST_DECL(Derived, Base) DECL(Derived, Base) -#endif - -#ifndef ABSTRACT_DECL -# define ABSTRACT_DECL(Derived, Base) -#endif - -#ifndef DECL_CONTEXT -# define DECL_CONTEXT(Decl) -#endif - -#ifndef DECL_CONTEXT_BASE -# define DECL_CONTEXT_BASE(Decl) DECL_CONTEXT(Decl) -#endif - -#ifndef LAST_DECL_CONTEXT -# define LAST_DECL_CONTEXT(Decl) DECL_CONTEXT(Decl) -#endif - -#ifndef DECL_RANGE -# define DECL_RANGE(CommonBase, Start, End) -#endif - -#ifndef LAST_DECL_RANGE -# define LAST_DECL_RANGE(CommonBase, Start, End) \ - DECL_RANGE(CommonBase, Start, End) -#endif - -DECL(TranslationUnit, Decl) -ABSTRACT_DECL(Named, Decl) - DECL(Namespace, NamedDecl) - DECL(UsingDirective, NamedDecl) - DECL(NamespaceAlias, NamedDecl) - ABSTRACT_DECL(Type, NamedDecl) - DECL(Typedef, TypeDecl) - DECL(UnresolvedUsingTypename, TypeDecl) - ABSTRACT_DECL(Tag, TypeDecl) - DECL(Enum, TagDecl) - DECL(Record, TagDecl) - DECL(CXXRecord, RecordDecl) - DECL(ClassTemplateSpecialization, CXXRecordDecl) - DECL(ClassTemplatePartialSpecialization, - ClassTemplateSpecializationDecl) - DECL(TemplateTypeParm, TypeDecl) - ABSTRACT_DECL(Value, NamedDecl) - DECL(EnumConstant, ValueDecl) - DECL(UnresolvedUsingValue, ValueDecl) - ABSTRACT_DECL(Declarator, ValueDecl) - DECL(Function, DeclaratorDecl) - DECL(CXXMethod, FunctionDecl) - DECL(CXXConstructor, CXXMethodDecl) - DECL(CXXDestructor, CXXMethodDecl) - DECL(CXXConversion, CXXMethodDecl) - DECL(Field, DeclaratorDecl) - DECL(ObjCIvar, FieldDecl) - DECL(ObjCAtDefsField, FieldDecl) - DECL(Var, DeclaratorDecl) - DECL(ImplicitParam, VarDecl) - DECL(ParmVar, VarDecl) - DECL(NonTypeTemplateParm, VarDecl) - ABSTRACT_DECL(Template, NamedDecl) - DECL(FunctionTemplate, TemplateDecl) - DECL(ClassTemplate, TemplateDecl) - DECL(TemplateTemplateParm, TemplateDecl) - DECL(Using, NamedDecl) - DECL(UsingShadow, NamedDecl) - DECL(ObjCMethod, NamedDecl) - ABSTRACT_DECL(ObjCContainer, NamedDecl) - DECL(ObjCCategory, ObjCContainerDecl) - DECL(ObjCProtocol, ObjCContainerDecl) - DECL(ObjCInterface, ObjCContainerDecl) - ABSTRACT_DECL(ObjCImpl, ObjCContainerDecl) - DECL(ObjCCategoryImpl, ObjCImplDecl) - DECL(ObjCImplementation, ObjCImplDecl) - DECL(ObjCProperty, NamedDecl) - DECL(ObjCCompatibleAlias, NamedDecl) -DECL(LinkageSpec, Decl) -DECL(ObjCPropertyImpl, Decl) -DECL(ObjCForwardProtocol, Decl) -DECL(ObjCClass, Decl) -DECL(FileScopeAsm, Decl) -DECL(Friend, Decl) -DECL(FriendTemplate, Decl) -DECL(StaticAssert, Decl) -LAST_DECL(Block, Decl) - -// Declaration contexts. DECL_CONTEXT_BASE indicates that it has subclasses. -DECL_CONTEXT(TranslationUnit) -DECL_CONTEXT(Namespace) -DECL_CONTEXT(LinkageSpec) -DECL_CONTEXT(ObjCMethod) -DECL_CONTEXT_BASE(Tag) -DECL_CONTEXT_BASE(Function) -DECL_CONTEXT_BASE(ObjCContainer) -LAST_DECL_CONTEXT(Block) - -// Declaration ranges -DECL_RANGE(Named, Namespace, ObjCCompatibleAlias) -DECL_RANGE(ObjCContainer, ObjCCategory, ObjCImplementation) -DECL_RANGE(Field, Field, ObjCAtDefsField) -DECL_RANGE(Type, Typedef, TemplateTypeParm) -DECL_RANGE(Tag, Enum, ClassTemplatePartialSpecialization) -DECL_RANGE(Record, Record, ClassTemplatePartialSpecialization) -DECL_RANGE(Value, EnumConstant, NonTypeTemplateParm) -DECL_RANGE(Declarator, Function, NonTypeTemplateParm) -DECL_RANGE(Function, Function, CXXConversion) -DECL_RANGE(Template, FunctionTemplate, TemplateTemplateParm) -DECL_RANGE(ObjCImpl, ObjCCategoryImpl, ObjCImplementation) -LAST_DECL_RANGE(Var, Var, NonTypeTemplateParm) - -#undef LAST_DECL_RANGE -#undef DECL_RANGE -#undef LAST_DECL_CONTEXT -#undef DECL_CONTEXT_BASE -#undef DECL_CONTEXT -#undef ABSTRACT_DECL -#undef LAST_DECL -#undef DECL diff --git a/include/clang/AST/DeclNodes.td b/include/clang/AST/DeclNodes.td new file mode 100644 index 0000000000..8025394f3c --- /dev/null +++ b/include/clang/AST/DeclNodes.td @@ -0,0 +1,67 @@ +class Decl { + bit Abstract = abstract; +} + +class DDecl : Decl { + Decl Base = base; +} + +class DeclContext { } + +def TranslationUnit : Decl, DeclContext; +def Named : Decl<1>; + def Namespace : DDecl, DeclContext; + def UsingDirective : DDecl; + def NamespaceAlias : DDecl; + def Type : DDecl; + def Typedef : DDecl; + def UnresolvedUsingTypename : DDecl; + def Tag : DDecl, DeclContext; + def Enum : DDecl; + def Record : DDecl; + def CXXRecord : DDecl; + def ClassTemplateSpecialization : DDecl; + def ClassTemplatePartialSpecialization + : DDecl; + def TemplateTypeParm : DDecl; + def Value : DDecl; + def EnumConstant : DDecl; + def UnresolvedUsingValue : DDecl; + def Declarator : DDecl; + def Function : DDecl, DeclContext; + def CXXMethod : DDecl; + def CXXConstructor : DDecl; + def CXXDestructor : DDecl; + def CXXConversion : DDecl; + def Field : DDecl; + def ObjCIvar : DDecl; + def ObjCAtDefsField : DDecl; + def Var : DDecl; + def ImplicitParam : DDecl; + def ParmVar : DDecl; + def NonTypeTemplateParm : DDecl; + def Template : DDecl; + def FunctionTemplate : DDecl