[cfe-commits] r93120 - in /cfe/trunk: include/clang/AST/Attr.h lib/AST/AttrImpl.cpp lib/AST/CMakeLists.txt

Anton Korobeynikov asl at math.spbu.ru
Sun Jan 10 06:38:14 PST 2010


Author: asl
Date: Sun Jan 10 08:38:13 2010
New Revision: 93120

URL: http://llvm.org/viewvc/llvm-project?rev=93120&view=rev
Log:
Make clone() method out-of-line for Attr classes.

Added:
    cfe/trunk/lib/AST/AttrImpl.cpp
Modified:
    cfe/trunk/include/clang/AST/Attr.h
    cfe/trunk/lib/AST/CMakeLists.txt

Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=93120&r1=93119&r2=93120&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Sun Jan 10 08:38:13 2010
@@ -161,7 +161,7 @@
 class ATTR##Attr : public Attr {                                        \
 public:                                                                 \
   ATTR##Attr() : Attr(ATTR) {}                                          \
-  virtual Attr *clone(ASTContext &C) const { return ::new (C) ATTR##Attr; }\
+  virtual Attr *clone(ASTContext &C) const;                             \
   static bool classof(const Attr *A) { return A->getKind() == ATTR; }   \
   static bool classof(const ATTR##Attr *A) { return true; }             \
 }
@@ -177,9 +177,7 @@
   /// getAlignment - The specified alignment in bits.
   unsigned getAlignment() const { return Alignment; }
 
-  virtual Attr* clone(ASTContext &C) const {
-    return ::new (C) PragmaPackAttr(Alignment);
-  }
+  virtual Attr* clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) {
@@ -206,9 +204,7 @@
       return Alignment;
   }
 
-  virtual Attr* clone(ASTContext &C) const {
-    return ::new (C) AlignedAttr(Alignment);
-  }
+  virtual Attr* clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) {
@@ -224,7 +220,7 @@
 
   const std::string& getAnnotation() const { return Annotation; }
 
-  virtual Attr* clone(ASTContext &C) const { return ::new (C) AnnotateAttr(Annotation); }
+  virtual Attr* clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) {
@@ -240,7 +236,7 @@
 
   const std::string& getLabel() const { return Label; }
 
-  virtual Attr* clone(ASTContext &C) const { return ::new (C) AsmLabelAttr(Label); }
+  virtual Attr* clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) {
@@ -258,7 +254,7 @@
 
   const std::string& getAliasee() const { return Aliasee; }
 
-  virtual Attr *clone(ASTContext &C) const { return ::new (C) AliasAttr(Aliasee); }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) { return A->getKind() == Alias; }
@@ -272,7 +268,7 @@
 
   int getPriority() const { return priority; }
 
-  virtual Attr *clone(ASTContext &C) const { return ::new (C) ConstructorAttr(priority); }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) { return A->getKind() == Constructor; }
@@ -286,7 +282,7 @@
 
   int getPriority() const { return priority; }
 
-  virtual Attr *clone(ASTContext &C) const { return ::new (C) DestructorAttr(priority); }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) { return A->getKind() == Destructor; }
@@ -297,7 +293,7 @@
 public:
   GNUInlineAttr() : Attr(GNUInline) {}
 
-  virtual Attr *clone(ASTContext &C) const { return ::new (C) GNUInlineAttr; }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) {
@@ -310,7 +306,7 @@
 public:
   IBOutletAttr() : Attr(IBOutletKind) {}
 
-  virtual Attr *clone(ASTContext &C) const { return ::new (C) IBOutletAttr; }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) {
@@ -332,7 +328,7 @@
 
   const std::string& getName() const { return Name; }
 
-  virtual Attr *clone(ASTContext &C) const { return ::new (C) SectionAttr(Name); }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) {
@@ -377,7 +373,7 @@
     return ArgNums ? std::binary_search(ArgNums, ArgNums+Size, arg) : true;
   }
 
-  virtual Attr *clone(ASTContext &C) const { return ::new (C) NonNullAttr(ArgNums, Size); }
+  virtual Attr *clone(ASTContext &C) const;
 
   static bool classof(const Attr *A) { return A->getKind() == NonNull; }
   static bool classof(const NonNullAttr *A) { return true; }
@@ -395,9 +391,7 @@
   int getFormatIdx() const { return formatIdx; }
   int getFirstArg() const { return firstArg; }
 
-  virtual Attr *clone(ASTContext &C) const {
-    return ::new (C) FormatAttr(Type, formatIdx, firstArg);
-  }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) { return A->getKind() == Format; }
@@ -410,9 +404,7 @@
   FormatArgAttr(int idx) : Attr(FormatArg), formatIdx(idx) {}
   int getFormatIdx() const { return formatIdx; }
 
-  virtual Attr *clone(ASTContext &C) const {
-    return ::new (C) FormatArgAttr(formatIdx);
-  }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) { return A->getKind() == FormatArg; }
@@ -427,9 +419,7 @@
   int getSentinel() const { return sentinel; }
   int getNullPos() const { return NullPos; }
 
-  virtual Attr *clone(ASTContext &C) const {
-    return ::new (C) SentinelAttr(sentinel, NullPos);
-  }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) { return A->getKind() == Sentinel; }
@@ -452,7 +442,7 @@
 
   VisibilityTypes getVisibility() const { return VisibilityType; }
 
-  virtual Attr *clone(ASTContext &C) const { return ::new (C) VisibilityAttr(VisibilityType); }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) { return A->getKind() == Visibility; }
@@ -472,9 +462,7 @@
 
   virtual bool isMerged() const { return false; }
 
-  virtual Attr *clone(ASTContext &C) const {
-    return ::new (C) OverloadableAttr;
-  }
+  virtual Attr *clone(ASTContext &C) const;
 
   static bool classof(const Attr *A) { return A->getKind() == Overloadable; }
   static bool classof(const OverloadableAttr *) { return true; }
@@ -492,7 +480,7 @@
 
   BlocksAttrTypes getType() const { return BlocksAttrType; }
 
-  virtual Attr *clone(ASTContext &C) const { return ::new (C) BlocksAttr(BlocksAttrType); }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) { return A->getKind() == Blocks; }
@@ -509,7 +497,7 @@
 
   const FunctionDecl *getFunctionDecl() const { return FD; }
 
-  virtual Attr *clone(ASTContext &C) const { return ::new (C) CleanupAttr(FD); }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) { return A->getKind() == Cleanup; }
@@ -528,9 +516,7 @@
 
   unsigned getNumParams() const { return NumParams; }
 
-  virtual Attr *clone(ASTContext &C) const {
-    return ::new (C) RegparmAttr(NumParams);
-  }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) { return A->getKind() == Regparm; }
@@ -547,9 +533,7 @@
   unsigned getYDim() const { return Y; }
   unsigned getZDim() const { return Z; }
 
-  virtual Attr *clone(ASTContext &C) const {
-    return ::new (C) ReqdWorkGroupSizeAttr(X, Y, Z);
-  }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) {
@@ -579,9 +563,7 @@
 
   unsigned getNumber() const { return Number; }
 
-  virtual Attr *clone(ASTContext &C) const {
-    return ::new (C) MSP430InterruptAttr(Number);
-  }
+  virtual Attr *clone(ASTContext &C) const;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *A) { return A->getKind() == MSP430Interrupt; }

Added: cfe/trunk/lib/AST/AttrImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/AttrImpl.cpp?rev=93120&view=auto

==============================================================================
--- cfe/trunk/lib/AST/AttrImpl.cpp (added)
+++ cfe/trunk/lib/AST/AttrImpl.cpp Sun Jan 10 08:38:13 2010
@@ -0,0 +1,143 @@
+//===--- AttrImpl.cpp - Classes for representing attributes -----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file contains out-of-line virtual methods for Attr classes.
+//
+//===----------------------------------------------------------------------===//
+
+
+#include "clang/AST/Attr.h"
+#include "clang/AST/ASTContext.h"
+using namespace clang;
+
+#define DEF_SIMPLE_ATTR_CLONE(ATTR)                                     \
+  Attr *ATTR##Attr::clone(ASTContext &C) const {                        \
+    return ::new (C) ATTR##Attr;                                        \
+  }
+
+// FIXME: Can we use variadic macro to define DEF_SIMPLE_ATTR_CLONE for
+// "non-simple" classes?
+
+DEF_SIMPLE_ATTR_CLONE(Packed)
+DEF_SIMPLE_ATTR_CLONE(AlwaysInline)
+DEF_SIMPLE_ATTR_CLONE(Malloc)
+DEF_SIMPLE_ATTR_CLONE(NoReturn)
+DEF_SIMPLE_ATTR_CLONE(AnalyzerNoReturn)
+DEF_SIMPLE_ATTR_CLONE(Deprecated)
+DEF_SIMPLE_ATTR_CLONE(Final)
+DEF_SIMPLE_ATTR_CLONE(Unavailable)
+DEF_SIMPLE_ATTR_CLONE(Unused)
+DEF_SIMPLE_ATTR_CLONE(Used)
+DEF_SIMPLE_ATTR_CLONE(Weak)
+DEF_SIMPLE_ATTR_CLONE(WeakImport)
+DEF_SIMPLE_ATTR_CLONE(NoThrow)
+DEF_SIMPLE_ATTR_CLONE(Const)
+DEF_SIMPLE_ATTR_CLONE(Pure)
+DEF_SIMPLE_ATTR_CLONE(FastCall)
+DEF_SIMPLE_ATTR_CLONE(StdCall)
+DEF_SIMPLE_ATTR_CLONE(CDecl)
+DEF_SIMPLE_ATTR_CLONE(TransparentUnion)
+DEF_SIMPLE_ATTR_CLONE(ObjCNSObject)
+DEF_SIMPLE_ATTR_CLONE(ObjCException)
+DEF_SIMPLE_ATTR_CLONE(NoDebug)
+DEF_SIMPLE_ATTR_CLONE(WarnUnusedResult)
+DEF_SIMPLE_ATTR_CLONE(NoInline)
+DEF_SIMPLE_ATTR_CLONE(CFReturnsRetained)
+DEF_SIMPLE_ATTR_CLONE(NSReturnsRetained)
+DEF_SIMPLE_ATTR_CLONE(BaseCheck)
+DEF_SIMPLE_ATTR_CLONE(Hiding)
+DEF_SIMPLE_ATTR_CLONE(Override)
+DEF_SIMPLE_ATTR_CLONE(DLLImport)
+DEF_SIMPLE_ATTR_CLONE(DLLExport)
+
+Attr* PragmaPackAttr::clone(ASTContext &C) const {
+  return ::new (C) PragmaPackAttr(Alignment);
+}
+
+Attr* AlignedAttr::clone(ASTContext &C) const {
+  return ::new (C) AlignedAttr(Alignment);
+}
+
+Attr* AnnotateAttr::clone(ASTContext &C) const {
+  return ::new (C) AnnotateAttr(Annotation);
+}
+
+Attr *AsmLabelAttr::clone(ASTContext &C) const {
+  return ::new (C) AsmLabelAttr(Label);
+}
+
+Attr *AliasAttr::clone(ASTContext &C) const {
+  return ::new (C) AliasAttr(Aliasee);
+}
+
+Attr *ConstructorAttr::clone(ASTContext &C) const {
+  return ::new (C) ConstructorAttr(priority);
+}
+
+Attr *DestructorAttr::clone(ASTContext &C) const {
+  return ::new (C) DestructorAttr(priority);
+}
+
+Attr *IBOutletAttr::clone(ASTContext &C) const {
+  return ::new (C) IBOutletAttr;
+}
+
+Attr *GNUInlineAttr::clone(ASTContext &C) const {
+  return ::new (C) GNUInlineAttr;
+}
+
+Attr *SectionAttr::clone(ASTContext &C) const {
+  return ::new (C) SectionAttr(Name);
+}
+
+Attr *NonNullAttr::clone(ASTContext &C) const {
+  return ::new (C) NonNullAttr(ArgNums, Size);
+}
+
+Attr *FormatAttr::clone(ASTContext &C) const {
+  return ::new (C) FormatAttr(Type, formatIdx, firstArg);
+}
+
+Attr *FormatArgAttr::clone(ASTContext &C) const {
+  return ::new (C) FormatArgAttr(formatIdx);
+}
+
+Attr *SentinelAttr::clone(ASTContext &C) const {
+  return ::new (C) SentinelAttr(sentinel, NullPos);
+}
+
+Attr *VisibilityAttr::clone(ASTContext &C) const {
+  return ::new (C) VisibilityAttr(VisibilityType);
+}
+
+Attr *OverloadableAttr::clone(ASTContext &C) const {
+  return ::new (C) OverloadableAttr;
+}
+
+Attr *BlocksAttr::clone(ASTContext &C) const {
+  return ::new (C) BlocksAttr(BlocksAttrType);
+}
+
+Attr *CleanupAttr::clone(ASTContext &C) const {
+  return ::new (C) CleanupAttr(FD);
+}
+
+Attr *RegparmAttr::clone(ASTContext &C) const {
+  return ::new (C) RegparmAttr(NumParams);
+}
+
+Attr *ReqdWorkGroupSizeAttr::clone(ASTContext &C) const {
+  return ::new (C) ReqdWorkGroupSizeAttr(X, Y, Z);
+}
+
+Attr *MSP430InterruptAttr::clone(ASTContext &C) const {
+  return ::new (C) MSP430InterruptAttr(Number);
+}
+
+

Modified: cfe/trunk/lib/AST/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CMakeLists.txt?rev=93120&r1=93119&r2=93120&view=diff

==============================================================================
--- cfe/trunk/lib/AST/CMakeLists.txt (original)
+++ cfe/trunk/lib/AST/CMakeLists.txt Sun Jan 10 08:38:13 2010
@@ -4,6 +4,7 @@
   APValue.cpp
   ASTConsumer.cpp
   ASTContext.cpp
+  AttrImpl.cpp
   CXXInheritance.cpp
   Decl.cpp
   DeclBase.cpp





More information about the cfe-commits mailing list