Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 1 | //===--- DeclCXX.cpp - C++ Declaration AST Node Implementation ------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the C++ related Decl classes for templates. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/DeclCXX.h" |
| 15 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame^] | 16 | #include "clang/AST/Expr.h" |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
| 18 | #include "clang/Basic/IdentifierTable.h" |
| 19 | #include "llvm/ADT/STLExtras.h" |
| 20 | using namespace clang; |
| 21 | |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | // TemplateParameterList Implementation |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 26 | TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc, |
| 27 | SourceLocation LAngleLoc, |
| 28 | Decl **Params, unsigned NumParams, |
| 29 | SourceLocation RAngleLoc) |
| 30 | : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc), |
| 31 | NumParams(NumParams) { |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 32 | for (unsigned Idx = 0; Idx < NumParams; ++Idx) |
| 33 | begin()[Idx] = Params[Idx]; |
| 34 | } |
| 35 | |
| 36 | TemplateParameterList * |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 37 | TemplateParameterList::Create(ASTContext &C, SourceLocation TemplateLoc, |
| 38 | SourceLocation LAngleLoc, Decl **Params, |
| 39 | unsigned NumParams, SourceLocation RAngleLoc) { |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 40 | unsigned Size = sizeof(TemplateParameterList) + sizeof(Decl *) * NumParams; |
| 41 | unsigned Align = llvm::AlignOf<TemplateParameterList>::Alignment; |
| 42 | void *Mem = C.Allocate(Size, Align); |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 43 | return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params, |
| 44 | NumParams, RAngleLoc); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame^] | 47 | void TemplateArg::Destroy(ASTContext &C) { |
| 48 | if (Kind == ExprArg) |
| 49 | getAsExpr()->Destroy(C); |
| 50 | } |
| 51 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 52 | //===----------------------------------------------------------------------===// |
| 53 | // TemplateDecl Implementation |
| 54 | //===----------------------------------------------------------------------===// |
| 55 | |
| 56 | TemplateDecl::~TemplateDecl() { |
| 57 | } |
| 58 | |
| 59 | //===----------------------------------------------------------------------===// |
| 60 | // FunctionTemplateDecl Implementation |
| 61 | //===----------------------------------------------------------------------===// |
| 62 | |
| 63 | FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, |
| 64 | DeclContext *DC, |
| 65 | SourceLocation L, |
| 66 | DeclarationName Name, |
| 67 | TemplateParameterList *Params, |
| 68 | NamedDecl *Decl) { |
| 69 | return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl); |
| 70 | } |
| 71 | |
| 72 | //===----------------------------------------------------------------------===// |
| 73 | // ClassTemplateDecl Implementation |
| 74 | //===----------------------------------------------------------------------===// |
| 75 | |
| 76 | ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, |
| 77 | DeclContext *DC, |
| 78 | SourceLocation L, |
| 79 | DeclarationName Name, |
| 80 | TemplateParameterList *Params, |
| 81 | NamedDecl *Decl) { |
| 82 | return new (C) ClassTemplateDecl(DC, L, Name, Params, Decl); |
| 83 | } |
| 84 | |
| 85 | //===----------------------------------------------------------------------===// |
| 86 | // TemplateTypeParm Allocation/Deallocation Method Implementations |
| 87 | //===----------------------------------------------------------------------===// |
| 88 | |
| 89 | TemplateTypeParmDecl * |
| 90 | TemplateTypeParmDecl::Create(ASTContext &C, DeclContext *DC, |
| 91 | SourceLocation L, unsigned D, unsigned P, |
| 92 | IdentifierInfo *Id, bool Typename) { |
Douglas Gregor | fab9d67 | 2009-02-05 23:33:38 +0000 | [diff] [blame] | 93 | QualType Type = C.getTemplateTypeParmType(D, P, Id); |
| 94 | return new (C) TemplateTypeParmDecl(DC, L, Id, Typename, Type); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | //===----------------------------------------------------------------------===// |
| 98 | // NonTypeTemplateParmDecl Method Implementations |
| 99 | //===----------------------------------------------------------------------===// |
| 100 | |
| 101 | NonTypeTemplateParmDecl * |
| 102 | NonTypeTemplateParmDecl::Create(ASTContext &C, DeclContext *DC, |
| 103 | SourceLocation L, unsigned D, unsigned P, |
| 104 | IdentifierInfo *Id, QualType T, |
| 105 | SourceLocation TypeSpecStartLoc) { |
| 106 | return new (C) NonTypeTemplateParmDecl(DC, L, D, P, Id, T, |
| 107 | TypeSpecStartLoc); |
| 108 | } |
| 109 | |
| 110 | //===----------------------------------------------------------------------===// |
| 111 | // TemplateTemplateParmDecl Method Implementations |
| 112 | //===----------------------------------------------------------------------===// |
| 113 | |
| 114 | TemplateTemplateParmDecl * |
| 115 | TemplateTemplateParmDecl::Create(ASTContext &C, DeclContext *DC, |
| 116 | SourceLocation L, unsigned D, unsigned P, |
| 117 | IdentifierInfo *Id, |
| 118 | TemplateParameterList *Params) { |
| 119 | return new (C) TemplateTemplateParmDecl(DC, L, D, P, Id, Params); |
| 120 | } |
| 121 | |