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 | |
| 47 | //===----------------------------------------------------------------------===// |
| 48 | // TemplateDecl Implementation |
| 49 | //===----------------------------------------------------------------------===// |
| 50 | |
| 51 | TemplateDecl::~TemplateDecl() { |
| 52 | } |
| 53 | |
| 54 | //===----------------------------------------------------------------------===// |
| 55 | // FunctionTemplateDecl Implementation |
| 56 | //===----------------------------------------------------------------------===// |
| 57 | |
| 58 | FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, |
| 59 | DeclContext *DC, |
| 60 | SourceLocation L, |
| 61 | DeclarationName Name, |
| 62 | TemplateParameterList *Params, |
| 63 | NamedDecl *Decl) { |
| 64 | return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl); |
| 65 | } |
| 66 | |
| 67 | //===----------------------------------------------------------------------===// |
| 68 | // ClassTemplateDecl Implementation |
| 69 | //===----------------------------------------------------------------------===// |
| 70 | |
| 71 | ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, |
| 72 | DeclContext *DC, |
| 73 | SourceLocation L, |
| 74 | DeclarationName Name, |
| 75 | TemplateParameterList *Params, |
| 76 | NamedDecl *Decl) { |
| 77 | return new (C) ClassTemplateDecl(DC, L, Name, Params, Decl); |
| 78 | } |
| 79 | |
| 80 | //===----------------------------------------------------------------------===// |
| 81 | // TemplateTypeParm Allocation/Deallocation Method Implementations |
| 82 | //===----------------------------------------------------------------------===// |
| 83 | |
| 84 | TemplateTypeParmDecl * |
| 85 | TemplateTypeParmDecl::Create(ASTContext &C, DeclContext *DC, |
| 86 | SourceLocation L, unsigned D, unsigned P, |
| 87 | IdentifierInfo *Id, bool Typename) { |
Douglas Gregor | fab9d67 | 2009-02-05 23:33:38 +0000 | [diff] [blame] | 88 | QualType Type = C.getTemplateTypeParmType(D, P, Id); |
| 89 | return new (C) TemplateTypeParmDecl(DC, L, Id, Typename, Type); |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | //===----------------------------------------------------------------------===// |
| 93 | // NonTypeTemplateParmDecl Method Implementations |
| 94 | //===----------------------------------------------------------------------===// |
| 95 | |
| 96 | NonTypeTemplateParmDecl * |
| 97 | NonTypeTemplateParmDecl::Create(ASTContext &C, DeclContext *DC, |
| 98 | SourceLocation L, unsigned D, unsigned P, |
| 99 | IdentifierInfo *Id, QualType T, |
| 100 | SourceLocation TypeSpecStartLoc) { |
| 101 | return new (C) NonTypeTemplateParmDecl(DC, L, D, P, Id, T, |
| 102 | TypeSpecStartLoc); |
| 103 | } |
| 104 | |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame^] | 105 | SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const { |
| 106 | return DefaultArgument? DefaultArgument->getSourceRange().getBegin() |
| 107 | : SourceLocation(); |
| 108 | } |
| 109 | |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 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 | |
Douglas Gregor | d684b00 | 2009-02-10 19:49:53 +0000 | [diff] [blame^] | 122 | SourceLocation TemplateTemplateParmDecl::getDefaultArgumentLoc() const { |
| 123 | return DefaultArgument? DefaultArgument->getSourceRange().getBegin() |
| 124 | : SourceLocation(); |
| 125 | } |