2006-10-16 06:34:45 +08:00
|
|
|
//===--- Decl.cpp - Declaration AST Node Implementation -------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Chris Lattner and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Decl class and subclasses.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/Decl.h"
|
2006-11-20 12:58:19 +08:00
|
|
|
#include "clang/Lex/IdentifierTable.h"
|
2006-10-25 13:11:20 +08:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace clang;
|
2006-10-16 06:34:45 +08:00
|
|
|
|
2006-10-25 13:11:20 +08:00
|
|
|
// Out-of-line virtual method providing a home for Decl.
|
|
|
|
Decl::~Decl() {
|
|
|
|
}
|
2006-11-20 12:58:19 +08:00
|
|
|
|
|
|
|
const char *Decl::getName() const {
|
2007-01-22 07:09:50 +08:00
|
|
|
if (const IdentifierInfo *II = getIdentifier())
|
|
|
|
return II->getName();
|
|
|
|
return "";
|
2006-11-20 12:58:19 +08:00
|
|
|
}
|
2007-01-21 15:42:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
FunctionDecl::~FunctionDecl() {
|
|
|
|
delete[] ParamInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned FunctionDecl::getNumParams() const {
|
|
|
|
return cast<FunctionTypeProto>(getType().getTypePtr())->getNumArgs();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FunctionDecl::setParams(VarDecl **NewParamInfo, unsigned NumParams) {
|
|
|
|
assert(ParamInfo == 0 && "Already has param info!");
|
|
|
|
assert(NumParams == getNumParams() && "Parameter count mismatch!");
|
|
|
|
|
2007-01-22 03:04:10 +08:00
|
|
|
// Zero params -> null pointer.
|
|
|
|
if (NumParams) {
|
|
|
|
ParamInfo = new VarDecl*[NumParams];
|
|
|
|
memcpy(ParamInfo, NewParamInfo, sizeof(VarDecl*)*NumParams);
|
|
|
|
}
|
2007-01-21 15:42:07 +08:00
|
|
|
}
|
2007-01-25 12:52:46 +08:00
|
|
|
|
|
|
|
|
2007-01-25 15:29:02 +08:00
|
|
|
/// defineElements - When created, EnumDecl correspond to a forward declared
|
|
|
|
/// enum. This method is used to mark the decl as being defined, with the
|
|
|
|
/// specified contents.
|
|
|
|
void EnumDecl::defineElements(EnumConstantDecl **Elts, unsigned NumElts) {
|
|
|
|
assert(!isDefinition() && "Cannot redefine enums!");
|
|
|
|
setDefinition(true);
|
|
|
|
NumElements = NumElts;
|
|
|
|
if (NumElts) {
|
|
|
|
Elements = new EnumConstantDecl*[NumElts];
|
|
|
|
memcpy(Elements, Elts, NumElts*sizeof(Decl*));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-01-25 12:52:46 +08:00
|
|
|
/// defineBody - When created, RecordDecl's correspond to a forward declared
|
|
|
|
/// record. This method is used to mark the decl as being defined, with the
|
|
|
|
/// specified contents.
|
2007-01-25 14:27:24 +08:00
|
|
|
void RecordDecl::defineBody(Decl **members, unsigned numMembers) {
|
2007-01-25 12:52:46 +08:00
|
|
|
assert(!isDefinition() && "Cannot redefine record!");
|
|
|
|
setDefinition(true);
|
2007-01-25 14:27:24 +08:00
|
|
|
NumMembers = numMembers;
|
|
|
|
if (numMembers) {
|
|
|
|
Members = new Decl*[numMembers];
|
|
|
|
memcpy(Members, members, numMembers*sizeof(Decl*));
|
2007-01-25 12:52:46 +08:00
|
|
|
}
|
|
|
|
}
|