blob: b297dd25cbe42c5dcd841b8435d4bd1d54a3ad2f [file] [log] [blame]
Douglas Gregoraaba5e32009-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"
Douglas Gregor55f6b142009-02-09 18:46:07 +000016#include "clang/AST/Expr.h"
Douglas Gregoraaba5e32009-02-04 19:02:06 +000017#include "clang/AST/ASTContext.h"
18#include "clang/Basic/IdentifierTable.h"
19#include "llvm/ADT/STLExtras.h"
20using namespace clang;
21
22//===----------------------------------------------------------------------===//
23// TemplateParameterList Implementation
24//===----------------------------------------------------------------------===//
25
Douglas Gregorddc29e12009-02-06 22:42:48 +000026TemplateParameterList::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 Gregoraaba5e32009-02-04 19:02:06 +000032 for (unsigned Idx = 0; Idx < NumParams; ++Idx)
33 begin()[Idx] = Params[Idx];
34}
35
36TemplateParameterList *
Douglas Gregorddc29e12009-02-06 22:42:48 +000037TemplateParameterList::Create(ASTContext &C, SourceLocation TemplateLoc,
38 SourceLocation LAngleLoc, Decl **Params,
39 unsigned NumParams, SourceLocation RAngleLoc) {
Douglas Gregoraaba5e32009-02-04 19:02:06 +000040 unsigned Size = sizeof(TemplateParameterList) + sizeof(Decl *) * NumParams;
41 unsigned Align = llvm::AlignOf<TemplateParameterList>::Alignment;
42 void *Mem = C.Allocate(Size, Align);
Douglas Gregorddc29e12009-02-06 22:42:48 +000043 return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
44 NumParams, RAngleLoc);
Douglas Gregoraaba5e32009-02-04 19:02:06 +000045}
46
47//===----------------------------------------------------------------------===//
48// TemplateDecl Implementation
49//===----------------------------------------------------------------------===//
50
51TemplateDecl::~TemplateDecl() {
52}
53
54//===----------------------------------------------------------------------===//
55// FunctionTemplateDecl Implementation
56//===----------------------------------------------------------------------===//
57
58FunctionTemplateDecl *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
71ClassTemplateDecl *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
84TemplateTypeParmDecl *
85TemplateTypeParmDecl::Create(ASTContext &C, DeclContext *DC,
86 SourceLocation L, unsigned D, unsigned P,
87 IdentifierInfo *Id, bool Typename) {
Douglas Gregorfab9d672009-02-05 23:33:38 +000088 QualType Type = C.getTemplateTypeParmType(D, P, Id);
89 return new (C) TemplateTypeParmDecl(DC, L, Id, Typename, Type);
Douglas Gregoraaba5e32009-02-04 19:02:06 +000090}
91
92//===----------------------------------------------------------------------===//
93// NonTypeTemplateParmDecl Method Implementations
94//===----------------------------------------------------------------------===//
95
96NonTypeTemplateParmDecl *
97NonTypeTemplateParmDecl::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 Gregord684b002009-02-10 19:49:53 +0000105SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const {
106 return DefaultArgument? DefaultArgument->getSourceRange().getBegin()
107 : SourceLocation();
108}
109
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000110//===----------------------------------------------------------------------===//
111// TemplateTemplateParmDecl Method Implementations
112//===----------------------------------------------------------------------===//
113
114TemplateTemplateParmDecl *
115TemplateTemplateParmDecl::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 Gregord684b002009-02-10 19:49:53 +0000122SourceLocation TemplateTemplateParmDecl::getDefaultArgumentLoc() const {
123 return DefaultArgument? DefaultArgument->getSourceRange().getBegin()
124 : SourceLocation();
125}