summaryrefslogtreecommitdiff
path: root/lib/AST
diff options
context:
space:
mode:
authorEd Schouten <ed@FreeBSD.org>2009-06-06 08:21:31 +0000
committerEd Schouten <ed@FreeBSD.org>2009-06-06 08:21:31 +0000
commit37f6c480c696a4a72c1701ee54624cc807aa80ba (patch)
tree06d57bb7679a2140aef96db7105a0bd5f16a4358 /lib/AST
parent2659aeb5e51fe27d24bbffad0d1851b39fed5e43 (diff)
Diffstat (limited to 'lib/AST')
-rw-r--r--lib/AST/ASTContext.cpp74
-rw-r--r--lib/AST/Decl.cpp2
-rw-r--r--lib/AST/DeclCXX.cpp4
-rw-r--r--lib/AST/DeclObjC.cpp22
-rw-r--r--lib/AST/DeclPrinter.cpp46
-rw-r--r--lib/AST/DeclTemplate.cpp46
-rw-r--r--lib/AST/ExprCXX.cpp11
-rw-r--r--lib/AST/ExprConstant.cpp3
-rw-r--r--lib/AST/Type.cpp8
9 files changed, 163 insertions, 53 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index b36d1f3dbfa37..e6dea7cca9551 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -143,7 +143,7 @@ void ASTContext::InitBuiltinTypes() {
// C99 6.2.5p2.
InitBuiltinType(BoolTy, BuiltinType::Bool);
// C99 6.2.5p3.
- if (Target.isCharSigned())
+ if (LangOpts.CharIsSigned)
InitBuiltinType(CharTy, BuiltinType::Char_S);
else
InitBuiltinType(CharTy, BuiltinType::Char_U);
@@ -613,6 +613,20 @@ void ASTContext::CollectObjCIvars(const ObjCInterfaceDecl *OI,
CollectLocalObjCIvars(this, OI, Fields);
}
+/// ShallowCollectObjCIvars -
+/// Collect all ivars, including those synthesized, in the current class.
+///
+void ASTContext::ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI,
+ llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars,
+ bool CollectSynthesized) {
+ for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
+ E = OI->ivar_end(); I != E; ++I) {
+ Ivars.push_back(*I);
+ }
+ if (CollectSynthesized)
+ CollectSynthesizedIvars(OI, Ivars);
+}
+
void ASTContext::CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) {
for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(*this),
@@ -645,6 +659,38 @@ void ASTContext::CollectSynthesizedIvars(const ObjCInterfaceDecl *OI,
}
}
+unsigned ASTContext::CountProtocolSynthesizedIvars(const ObjCProtocolDecl *PD) {
+ unsigned count = 0;
+ for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(*this),
+ E = PD->prop_end(*this); I != E; ++I)
+ if ((*I)->getPropertyIvarDecl())
+ ++count;
+
+ // Also look into nested protocols.
+ for (ObjCProtocolDecl::protocol_iterator P = PD->protocol_begin(),
+ E = PD->protocol_end(); P != E; ++P)
+ count += CountProtocolSynthesizedIvars(*P);
+ return count;
+}
+
+unsigned ASTContext::CountSynthesizedIvars(const ObjCInterfaceDecl *OI)
+{
+ unsigned count = 0;
+ for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(*this),
+ E = OI->prop_end(*this); I != E; ++I) {
+ if ((*I)->getPropertyIvarDecl())
+ ++count;
+ }
+ // Also look into interface's protocol list for properties declared
+ // in the protocol and whose ivars are synthesized.
+ for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(),
+ PE = OI->protocol_end(); P != PE; ++P) {
+ ObjCProtocolDecl *PD = (*P);
+ count += CountProtocolSynthesizedIvars(PD);
+ }
+ return count;
+}
+
/// getInterfaceLayoutImpl - Get or compute information about the
/// layout of the given interface.
///
@@ -664,14 +710,13 @@ ASTContext::getObjCLayout(const ObjCInterfaceDecl *D,
unsigned FieldCount = D->ivar_size();
// Add in synthesized ivar count if laying out an implementation.
if (Impl) {
- llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
- CollectSynthesizedIvars(D, Ivars);
- FieldCount += Ivars.size();
+ unsigned SynthCount = CountSynthesizedIvars(D);
+ FieldCount += SynthCount;
// If there aren't any sythesized ivars then reuse the interface
// entry. Note we can't cache this because we simply free all
// entries later; however we shouldn't look up implementations
// frequently.
- if (FieldCount == D->ivar_size())
+ if (SynthCount == 0)
return getObjCLayout(D, 0);
}
@@ -701,20 +746,11 @@ ASTContext::getObjCLayout(const ObjCInterfaceDecl *D,
// Layout each ivar sequentially.
unsigned i = 0;
- for (ObjCInterfaceDecl::ivar_iterator IVI = D->ivar_begin(),
- IVE = D->ivar_end(); IVI != IVE; ++IVI) {
- const ObjCIvarDecl* Ivar = (*IVI);
- NewEntry->LayoutField(Ivar, i++, false, StructPacking, *this);
- }
- // And synthesized ivars, if this is an implementation.
- if (Impl) {
- // FIXME. Do we need to colltect twice?
- llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
- CollectSynthesizedIvars(D, Ivars);
- for (unsigned k = 0, e = Ivars.size(); k != e; ++k)
- NewEntry->LayoutField(Ivars[k], i++, false, StructPacking, *this);
- }
-
+ llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
+ ShallowCollectObjCIvars(D, Ivars, Impl);
+ for (unsigned k = 0, e = Ivars.size(); k != e; ++k)
+ NewEntry->LayoutField(Ivars[k], i++, false, StructPacking, *this);
+
// Finally, round the size of the total struct up to the alignment of the
// struct itself.
NewEntry->FinalizeLayout();
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index cb3ec1f487da4..dfec1061c25a4 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -489,7 +489,7 @@ void FunctionDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo,
unsigned FunctionDecl::getMinRequiredArguments() const {
unsigned NumRequiredArgs = getNumParams();
while (NumRequiredArgs > 0
- && getParamDecl(NumRequiredArgs-1)->getDefaultArg())
+ && getParamDecl(NumRequiredArgs-1)->hasDefaultArg())
--NumRequiredArgs;
return NumRequiredArgs;
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index 19f89582770e3..94daf484458a3 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -326,7 +326,7 @@ CXXConstructorDecl::isCopyConstructor(ASTContext &Context,
// const volatile X&, and either there are no other parameters
// or else all other parameters have default arguments (8.3.6).
if ((getNumParams() < 1) ||
- (getNumParams() > 1 && getParamDecl(1)->getDefaultArg() == 0))
+ (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()))
return false;
const ParmVarDecl *Param = getParamDecl(0);
@@ -363,7 +363,7 @@ bool CXXConstructorDecl::isConvertingConstructor() const {
return (getNumParams() == 0 &&
getType()->getAsFunctionProtoType()->isVariadic()) ||
(getNumParams() == 1) ||
- (getNumParams() > 1 && getParamDecl(1)->getDefaultArg() != 0);
+ (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg());
}
CXXDestructorDecl *
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index f4bb895730749..21aefdd567bc3 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -42,6 +42,19 @@ void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
// ObjCInterfaceDecl
//===----------------------------------------------------------------------===//
+/// getIvarDecl - This method looks up an ivar in this ContextDecl.
+///
+ObjCIvarDecl *
+ObjCContainerDecl::getIvarDecl(ASTContext &Context, IdentifierInfo *Id) const {
+ lookup_const_iterator Ivar, IvarEnd;
+ for (llvm::tie(Ivar, IvarEnd) = lookup(Context, Id);
+ Ivar != IvarEnd; ++Ivar) {
+ if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar))
+ return ivar;
+ }
+ return 0;
+}
+
// Get the local instance method declared in this interface.
ObjCMethodDecl *
ObjCContainerDecl::getInstanceMethod(ASTContext &Context, Selector Sel) const {
@@ -139,12 +152,9 @@ ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(
ASTContext &Context, IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) {
ObjCInterfaceDecl* ClassDecl = this;
while (ClassDecl != NULL) {
- for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end();
- I != E; ++I) {
- if ((*I)->getIdentifier() == ID) {
- clsDeclared = ClassDecl;
- return *I;
- }
+ if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(Context, ID)) {
+ clsDeclared = ClassDecl;
+ return I;
}
// look into properties.
for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(Context),
diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp
index f29da8b9f4c85..f231abf89e01e 100644
--- a/lib/AST/DeclPrinter.cpp
+++ b/lib/AST/DeclPrinter.cpp
@@ -508,8 +508,50 @@ void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
}
void DeclPrinter::VisitTemplateDecl(TemplateDecl *D) {
- // TODO: Write template parameters.
- Out << "template <...> ";
+ Out << "template <";
+
+ TemplateParameterList *Params = D->getTemplateParameters();
+ for (unsigned i = 0, e = Params->size(); i != e; ++i) {
+ if (i != 0)
+ Out << ", ";
+
+ const Decl *Param = Params->getParam(i);
+ if (const TemplateTypeParmDecl *TTP =
+ dyn_cast<TemplateTypeParmDecl>(Param)) {
+
+ QualType ParamType =
+ Context.getTypeDeclType(const_cast<TemplateTypeParmDecl*>(TTP));
+
+ if (TTP->wasDeclaredWithTypename())
+ Out << "typename ";
+ else
+ Out << "class ";
+
+ Out << ParamType.getAsString(Policy);
+
+ if (TTP->hasDefaultArgument()) {
+ Out << " = ";
+ Out << TTP->getDefaultArgument().getAsString(Policy);
+ };
+ } else if (const NonTypeTemplateParmDecl *NTTP =
+ dyn_cast<NonTypeTemplateParmDecl>(Param)) {
+ Out << NTTP->getType().getAsString(Policy);
+
+ if (IdentifierInfo *Name = NTTP->getIdentifier()) {
+ Out << ' ';
+ Out << Name->getName();
+ }
+
+ if (NTTP->hasDefaultArgument()) {
+ Out << " = ";
+ NTTP->getDefaultArgument()->printPretty(Out, Context, 0, Policy,
+ Indentation);
+ }
+ }
+ }
+
+ Out << "> ";
+
Visit(D->getTemplatedDecl());
}
diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp
index f38ee825106e2..a53416433e03a 100644
--- a/lib/AST/DeclTemplate.cpp
+++ b/lib/AST/DeclTemplate.cpp
@@ -236,28 +236,42 @@ TemplateArgument::TemplateArgument(Expr *E) : Kind(Expression) {
}
//===----------------------------------------------------------------------===//
+// TemplateArgumentListBuilder Implementation
+//===----------------------------------------------------------------------===//
+void TemplateArgumentListBuilder::push_back(const TemplateArgument& Arg) {
+ switch (Arg.getKind()) {
+ default: break;
+ case TemplateArgument::Type:
+ assert(Arg.getAsType()->isCanonical() && "Type must be canonical!");
+ break;
+ }
+
+ Args.push_back(Arg);
+}
+
+//===----------------------------------------------------------------------===//
// TemplateArgumentList Implementation
//===----------------------------------------------------------------------===//
TemplateArgumentList::TemplateArgumentList(ASTContext &Context,
- TemplateArgument *TemplateArgs,
- unsigned NumTemplateArgs,
- bool CopyArgs)
- : NumArguments(NumTemplateArgs) {
+ TemplateArgumentListBuilder &Builder,
+ bool CopyArgs, bool FlattenArgs)
+ : NumArguments(Builder.flatSize()) {
if (!CopyArgs) {
- Arguments.setPointer(TemplateArgs);
+ Arguments.setPointer(Builder.getFlatArgumentList());
Arguments.setInt(1);
return;
}
- unsigned Size = sizeof(TemplateArgument) * NumTemplateArgs;
+
+ unsigned Size = sizeof(TemplateArgument) * Builder.flatSize();
unsigned Align = llvm::AlignOf<TemplateArgument>::Alignment;
void *Mem = Context.Allocate(Size, Align);
Arguments.setPointer((TemplateArgument *)Mem);
Arguments.setInt(0);
TemplateArgument *Args = (TemplateArgument *)Mem;
- for (unsigned I = 0; I != NumTemplateArgs; ++I)
- new (Args + I) TemplateArgument(TemplateArgs[I]);
+ for (unsigned I = 0; I != NumArguments; ++I)
+ new (Args + I) TemplateArgument(Builder.getFlatArgumentList()[I]);
}
TemplateArgumentList::~TemplateArgumentList() {
@@ -271,8 +285,7 @@ ClassTemplateSpecializationDecl::
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK,
DeclContext *DC, SourceLocation L,
ClassTemplateDecl *SpecializedTemplate,
- TemplateArgument *TemplateArgs,
- unsigned NumTemplateArgs)
+ TemplateArgumentListBuilder &Builder)
: CXXRecordDecl(DK,
SpecializedTemplate->getTemplatedDecl()->getTagKind(),
DC, L,
@@ -280,7 +293,7 @@ ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK,
// class template specializations?
SpecializedTemplate->getIdentifier()),
SpecializedTemplate(SpecializedTemplate),
- TemplateArgs(Context, TemplateArgs, NumTemplateArgs, /*CopyArgs=*/true),
+ TemplateArgs(Context, Builder, /*CopyArgs=*/true, /*FlattenArgs=*/true),
SpecializationKind(TSK_Undeclared) {
}
@@ -288,16 +301,14 @@ ClassTemplateSpecializationDecl *
ClassTemplateSpecializationDecl::Create(ASTContext &Context,
DeclContext *DC, SourceLocation L,
ClassTemplateDecl *SpecializedTemplate,
- TemplateArgument *TemplateArgs,
- unsigned NumTemplateArgs,
+ TemplateArgumentListBuilder &Builder,
ClassTemplateSpecializationDecl *PrevDecl) {
ClassTemplateSpecializationDecl *Result
= new (Context)ClassTemplateSpecializationDecl(Context,
ClassTemplateSpecialization,
DC, L,
SpecializedTemplate,
- TemplateArgs,
- NumTemplateArgs);
+ Builder);
Context.getTypeDeclType(Result, PrevDecl);
return Result;
}
@@ -310,14 +321,13 @@ ClassTemplatePartialSpecializationDecl::
Create(ASTContext &Context, DeclContext *DC, SourceLocation L,
TemplateParameterList *Params,
ClassTemplateDecl *SpecializedTemplate,
- TemplateArgument *TemplateArgs, unsigned NumTemplateArgs,
+ TemplateArgumentListBuilder &Builder,
ClassTemplatePartialSpecializationDecl *PrevDecl) {
ClassTemplatePartialSpecializationDecl *Result
= new (Context)ClassTemplatePartialSpecializationDecl(Context,
DC, L, Params,
SpecializedTemplate,
- TemplateArgs,
- NumTemplateArgs);
+ Builder);
Result->setSpecializationKind(TSK_ExplicitSpecialization);
Context.getTypeDeclType(Result, PrevDecl);
return Result;
diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp
index 4a15245591e3b..8fd66a29817d3 100644
--- a/lib/AST/ExprCXX.cpp
+++ b/lib/AST/ExprCXX.cpp
@@ -305,10 +305,11 @@ void CXXConstructExpr::Destroy(ASTContext &C) {
CXXExprWithTemporaries::CXXExprWithTemporaries(Expr *subexpr,
CXXTemporary **temps,
- unsigned numtemps)
+ unsigned numtemps,
+ bool destroytemps)
: Expr(CXXExprWithTemporariesClass, subexpr->getType(),
subexpr->isTypeDependent(), subexpr->isValueDependent()),
- SubExpr(subexpr), Temps(0), NumTemps(numtemps) {
+ SubExpr(subexpr), Temps(0), NumTemps(numtemps), DestroyTemps(destroytemps) {
if (NumTemps > 0) {
Temps = new CXXTemporary*[NumTemps];
for (unsigned i = 0; i < NumTemps; ++i)
@@ -319,8 +320,10 @@ CXXExprWithTemporaries::CXXExprWithTemporaries(Expr *subexpr,
CXXExprWithTemporaries *CXXExprWithTemporaries::Create(ASTContext &C,
Expr *SubExpr,
CXXTemporary **Temps,
- unsigned NumTemps) {
- return new (C) CXXExprWithTemporaries(SubExpr, Temps, NumTemps);
+ unsigned NumTemps,
+ bool DestroyTemps) {
+ return new (C) CXXExprWithTemporaries(SubExpr, Temps, NumTemps,
+ DestroyTemps);
}
void CXXExprWithTemporaries::Destroy(ASTContext &C) {
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 50fdcfd6eb2b6..8e3c3ce2d309e 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -946,7 +946,8 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
const QualType ElementType = Type->getAsPointerType()->getPointeeType();
uint64_t D = LHSValue.getLValueOffset() - RHSValue.getLValueOffset();
- D /= Info.Ctx.getTypeSize(ElementType) / 8;
+ if (!ElementType->isVoidType() && !ElementType->isFunctionType())
+ D /= Info.Ctx.getTypeSize(ElementType) / 8;
return Success(D, E);
}
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index f573744083a40..e304f54226363 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -1049,6 +1049,10 @@ TemplateSpecializationType::
anyDependentTemplateArguments(const TemplateArgument *Args, unsigned NumArgs) {
for (unsigned Idx = 0; Idx < NumArgs; ++Idx) {
switch (Args[Idx].getKind()) {
+ case TemplateArgument::Null:
+ assert(false && "Should not have a NULL template argument");
+ break;
+
case TemplateArgument::Type:
if (Args[Idx].getAsType()->isDependentType())
return true;
@@ -1451,6 +1455,10 @@ TemplateSpecializationType::PrintTemplateArgumentList(
// Print the argument into a string.
std::string ArgString;
switch (Args[Arg].getKind()) {
+ case TemplateArgument::Null:
+ assert(false && "Null template argument");
+ break;
+
case TemplateArgument::Type:
Args[Arg].getAsType().getAsStringInternal(ArgString, Policy);
break;