blob: 7e8cea9ae070c3031ce39784afa3e24e1f9e9be4 [file] [log] [blame]
Chris Lattnera11999d2006-10-15 22:34:45 +00001//===--- Decl.cpp - Declaration AST Node Implementation -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Decl class and subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/Decl.h"
Chris Lattner17ed4872006-11-20 04:58:19 +000015#include "clang/Lex/IdentifierTable.h"
Chris Lattner6d9a6852006-10-25 05:11:20 +000016using namespace llvm;
17using namespace clang;
Chris Lattnera11999d2006-10-15 22:34:45 +000018
Chris Lattner6d9a6852006-10-25 05:11:20 +000019// Out-of-line virtual method providing a home for Decl.
20Decl::~Decl() {
21}
Chris Lattner17ed4872006-11-20 04:58:19 +000022
23const char *Decl::getName() const {
Chris Lattnerec040b12007-01-21 23:09:50 +000024 if (const IdentifierInfo *II = getIdentifier())
25 return II->getName();
26 return "";
Chris Lattner17ed4872006-11-20 04:58:19 +000027}
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +000028
29
30FunctionDecl::~FunctionDecl() {
31 delete[] ParamInfo;
32}
33
34unsigned FunctionDecl::getNumParams() const {
35 return cast<FunctionTypeProto>(getType().getTypePtr())->getNumArgs();
36}
37
38void FunctionDecl::setParams(VarDecl **NewParamInfo, unsigned NumParams) {
39 assert(ParamInfo == 0 && "Already has param info!");
40 assert(NumParams == getNumParams() && "Parameter count mismatch!");
41
Chris Lattner8f5bf2f2007-01-21 19:04:10 +000042 // Zero params -> null pointer.
43 if (NumParams) {
44 ParamInfo = new VarDecl*[NumParams];
45 memcpy(ParamInfo, NewParamInfo, sizeof(VarDecl*)*NumParams);
46 }
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +000047}
Chris Lattner41943152007-01-25 04:52:46 +000048
49
Chris Lattnerc1915e22007-01-25 07:29:02 +000050/// defineElements - When created, EnumDecl correspond to a forward declared
51/// enum. This method is used to mark the decl as being defined, with the
52/// specified contents.
53void EnumDecl::defineElements(EnumConstantDecl **Elts, unsigned NumElts) {
54 assert(!isDefinition() && "Cannot redefine enums!");
55 setDefinition(true);
56 NumElements = NumElts;
57 if (NumElts) {
58 Elements = new EnumConstantDecl*[NumElts];
59 memcpy(Elements, Elts, NumElts*sizeof(Decl*));
60 }
61}
62
63
64
Chris Lattner41943152007-01-25 04:52:46 +000065/// defineBody - When created, RecordDecl's correspond to a forward declared
66/// record. This method is used to mark the decl as being defined, with the
67/// specified contents.
Chris Lattner5f521502007-01-25 06:27:24 +000068void RecordDecl::defineBody(Decl **members, unsigned numMembers) {
Chris Lattner41943152007-01-25 04:52:46 +000069 assert(!isDefinition() && "Cannot redefine record!");
70 setDefinition(true);
Chris Lattner5f521502007-01-25 06:27:24 +000071 NumMembers = numMembers;
72 if (numMembers) {
73 Members = new Decl*[numMembers];
74 memcpy(Members, members, numMembers*sizeof(Decl*));
Chris Lattner41943152007-01-25 04:52:46 +000075 }
76}