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