Files
llvm/clang/AST/Decl.cpp
Chris Lattner c1915e2052 Create EnumConstantDecl objects for each enum value, and fill them into
the EnumDecl when the enum type is complete.  This allows us to detect
redefinitions of enums.

llvm-svn: 39300
2007-01-25 07:29:02 +00:00

77 lines
2.3 KiB
C++

//===--- 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"
#include "clang/Lex/IdentifierTable.h"
using namespace llvm;
using namespace clang;
// Out-of-line virtual method providing a home for Decl.
Decl::~Decl() {
}
const char *Decl::getName() const {
if (const IdentifierInfo *II = getIdentifier())
return II->getName();
return "";
}
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!");
// Zero params -> null pointer.
if (NumParams) {
ParamInfo = new VarDecl*[NumParams];
memcpy(ParamInfo, NewParamInfo, sizeof(VarDecl*)*NumParams);
}
}
/// 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*));
}
}
/// 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.
void RecordDecl::defineBody(Decl **members, unsigned numMembers) {
assert(!isDefinition() && "Cannot redefine record!");
setDefinition(true);
NumMembers = numMembers;
if (numMembers) {
Members = new Decl*[numMembers];
memcpy(Members, members, numMembers*sizeof(Decl*));
}
}