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" |
| 16 | #include "clang/AST/ASTContext.h" |
| 17 | #include "clang/Basic/IdentifierTable.h" |
| 18 | #include "llvm/ADT/STLExtras.h" |
| 19 | using namespace clang; |
| 20 | |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | // TemplateParameterList Implementation |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame^] | 25 | TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc, |
| 26 | SourceLocation LAngleLoc, |
| 27 | Decl **Params, unsigned NumParams, |
| 28 | SourceLocation RAngleLoc) |
| 29 | : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc), |
| 30 | NumParams(NumParams) { |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 31 | for (unsigned Idx = 0; Idx < NumParams; ++Idx) |
| 32 | begin()[Idx] = Params[Idx]; |
| 33 | } |
| 34 | |
| 35 | TemplateParameterList * |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame^] | 36 | TemplateParameterList::Create(ASTContext &C, SourceLocation TemplateLoc, |
| 37 | SourceLocation LAngleLoc, Decl **Params, |
| 38 | unsigned NumParams, SourceLocation RAngleLoc) { |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 39 | unsigned Size = sizeof(TemplateParameterList) + sizeof(Decl *) * NumParams; |
| 40 | unsigned Align = llvm::AlignOf<TemplateParameterList>::Alignment; |
| 41 | void *Mem = C.Allocate(Size, Align); |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame^] | 42 | return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params, |
| 43 | NumParams, RAngleLoc); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | //===----------------------------------------------------------------------===// |
| 47 | // TemplateDecl Implementation |
| 48 | //===----------------------------------------------------------------------===// |
| 49 | |
| 50 | TemplateDecl::~TemplateDecl() { |
| 51 | } |
| 52 | |
| 53 | //===----------------------------------------------------------------------===// |
| 54 | // FunctionTemplateDecl Implementation |
| 55 | //===----------------------------------------------------------------------===// |
| 56 | |
| 57 | FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, |
| 58 | DeclContext *DC, |
| 59 | SourceLocation L, |
| 60 | DeclarationName Name, |
| 61 | TemplateParameterList *Params, |
| 62 | NamedDecl *Decl) { |
| 63 | return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl); |
| 64 | } |
| 65 | |
| 66 | //===----------------------------------------------------------------------===// |
| 67 | // ClassTemplateDecl Implementation |
| 68 | //===----------------------------------------------------------------------===// |
| 69 | |
| 70 | ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, |
| 71 | DeclContext *DC, |
| 72 | SourceLocation L, |
| 73 | DeclarationName Name, |
| 74 | TemplateParameterList *Params, |
| 75 | NamedDecl *Decl) { |
| 76 | return new (C) ClassTemplateDecl(DC, L, Name, Params, Decl); |
| 77 | } |
| 78 | |
| 79 | //===----------------------------------------------------------------------===// |
| 80 | // TemplateTypeParm Allocation/Deallocation Method Implementations |
| 81 | //===----------------------------------------------------------------------===// |
| 82 | |
| 83 | TemplateTypeParmDecl * |
| 84 | TemplateTypeParmDecl::Create(ASTContext &C, DeclContext *DC, |
| 85 | SourceLocation L, unsigned D, unsigned P, |
| 86 | IdentifierInfo *Id, bool Typename) { |
Douglas Gregor | fab9d67 | 2009-02-05 23:33:38 +0000 | [diff] [blame] | 87 | QualType Type = C.getTemplateTypeParmType(D, P, Id); |
| 88 | return new (C) TemplateTypeParmDecl(DC, L, Id, Typename, Type); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | //===----------------------------------------------------------------------===// |
| 92 | // NonTypeTemplateParmDecl Method Implementations |
| 93 | //===----------------------------------------------------------------------===// |
| 94 | |
| 95 | NonTypeTemplateParmDecl * |
| 96 | NonTypeTemplateParmDecl::Create(ASTContext &C, DeclContext *DC, |
| 97 | SourceLocation L, unsigned D, unsigned P, |
| 98 | IdentifierInfo *Id, QualType T, |
| 99 | SourceLocation TypeSpecStartLoc) { |
| 100 | return new (C) NonTypeTemplateParmDecl(DC, L, D, P, Id, T, |
| 101 | TypeSpecStartLoc); |
| 102 | } |
| 103 | |
| 104 | //===----------------------------------------------------------------------===// |
| 105 | // TemplateTemplateParmDecl Method Implementations |
| 106 | //===----------------------------------------------------------------------===// |
| 107 | |
| 108 | TemplateTemplateParmDecl * |
| 109 | TemplateTemplateParmDecl::Create(ASTContext &C, DeclContext *DC, |
| 110 | SourceLocation L, unsigned D, unsigned P, |
| 111 | IdentifierInfo *Id, |
| 112 | TemplateParameterList *Params) { |
| 113 | return new (C) TemplateTemplateParmDecl(DC, L, D, P, Id, Params); |
| 114 | } |
| 115 | |