summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-18 00:02:19 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-18 00:02:19 +0000
commite3dcb2ddd11d76b5b0a394f8c33437a38810bcb7 (patch)
tree775d32110ec52aac4047847f3a5fa36977e597da /clang/lib
parent7d59a92b457ed8e9a6749e08ab06a0486494699c (diff)
downloadbcm5719-llvm-e3dcb2ddd11d76b5b0a394f8c33437a38810bcb7.tar.gz
bcm5719-llvm-e3dcb2ddd11d76b5b0a394f8c33437a38810bcb7.zip
FunctionDecl::getBody() is getting an ASTContext argument for use in
lazy PCH deserialization. Propagate that argument wherever it needs to be. No functionality change, except that I've tightened up a few PCH tests in preparation. llvm-svn: 69406
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/Decl.cpp12
-rw-r--r--clang/lib/AST/DeclSerialization.cpp6
-rw-r--r--clang/lib/AST/Expr.cpp8
-rw-r--r--clang/lib/Analysis/BasicStore.cpp2
-rw-r--r--clang/lib/Analysis/BugReporter.cpp6
-rw-r--r--clang/lib/Analysis/CFRefCount.cpp3
-rw-r--r--clang/lib/Analysis/CheckObjCDealloc.cpp4
-rw-r--r--clang/lib/Analysis/CheckObjCUnusedIVars.cpp2
-rw-r--r--clang/lib/Analysis/PathDiagnostic.cpp9
-rw-r--r--clang/lib/CodeGen/CGObjC.cpp4
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp2
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp4
-rw-r--r--clang/lib/Frontend/PCHWriter.cpp10
-rw-r--r--clang/lib/Sema/SemaDecl.cpp2
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp2
-rw-r--r--clang/lib/Sema/SemaExpr.cpp2
16 files changed, 50 insertions, 28 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index d733c8c929f..5d49d706d7e 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -320,7 +320,8 @@ void FunctionDecl::Destroy(ASTContext& C) {
}
-CompoundStmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
+CompoundStmt *FunctionDecl::getBody(ASTContext &Context,
+ const FunctionDecl *&Definition) const {
for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) {
if (FD->Body) {
Definition = FD;
@@ -331,6 +332,15 @@ CompoundStmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
return 0;
}
+CompoundStmt *FunctionDecl::getBodyIfAvailable() const {
+ for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) {
+ if (FD->Body)
+ return cast<CompoundStmt>(FD->Body);
+ }
+
+ return 0;
+}
+
bool FunctionDecl::isMain() const {
return getDeclContext()->getLookupContext()->isTranslationUnit() &&
getIdentifier() && getIdentifier()->isStr("main");
diff --git a/clang/lib/AST/DeclSerialization.cpp b/clang/lib/AST/DeclSerialization.cpp
index 3ffcc49c363..81fdae2edc7 100644
--- a/clang/lib/AST/DeclSerialization.cpp
+++ b/clang/lib/AST/DeclSerialization.cpp
@@ -477,11 +477,11 @@ void FunctionDecl::EmitImpl(Serializer& S) const {
if (ParamInfo != NULL) {
S.EmitBool(true);
S.EmitInt(getNumParams());
- S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body);
+ // FIXME: S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body);
}
else {
S.EmitBool(false);
- S.EmitOwnedPtr(Body);
+ // FIXME: S.EmitOwnedPtr(Body);
}
}
@@ -508,7 +508,7 @@ FunctionDecl* FunctionDecl::CreateImpl(Deserializer& D, ASTContext& C) {
if (hasParamDecls)
D.BatchReadOwnedPtrs(numParams,
reinterpret_cast<Decl**>(&decl->ParamInfo[0]),
- decl->Body, C);
+ /*FIXME: decl->Body,*/ C);
else
decl->Body = D.ReadOwnedPtr<Stmt>(C);
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 523615491d5..46dce59d3e9 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -399,8 +399,12 @@ const FunctionType *BlockExpr::getFunctionType() const {
SourceLocation BlockExpr::getCaretLocation() const {
return TheBlock->getCaretLocation();
}
-const Stmt *BlockExpr::getBody() const { return TheBlock->getBody(); }
-Stmt *BlockExpr::getBody() { return TheBlock->getBody(); }
+const Stmt *BlockExpr::getBody() const {
+ return TheBlock->getBody();
+}
+Stmt *BlockExpr::getBody() {
+ return TheBlock->getBody();
+}
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Analysis/BasicStore.cpp b/clang/lib/Analysis/BasicStore.cpp
index 566c1971b7d..9047d9d8a95 100644
--- a/clang/lib/Analysis/BasicStore.cpp
+++ b/clang/lib/Analysis/BasicStore.cpp
@@ -525,7 +525,7 @@ Store BasicStoreManager::getInitialStore() {
// Scan the method for ivar references. While this requires an
// entire AST scan, the cost should not be high in practice.
- St = scanForIvars(MD->getBody(), PD, St);
+ St = scanForIvars(MD->getBody(getContext()), PD, St);
}
}
}
diff --git a/clang/lib/Analysis/BugReporter.cpp b/clang/lib/Analysis/BugReporter.cpp
index 01f5e81bf58..7e7132aaab7 100644
--- a/clang/lib/Analysis/BugReporter.cpp
+++ b/clang/lib/Analysis/BugReporter.cpp
@@ -140,7 +140,7 @@ public:
const ExplodedNode<GRState>* N);
ParentMap& getParentMap() {
- if (PM.get() == 0) PM.reset(new ParentMap(CodeDecl.getBody()));
+ if (PM.get() == 0) PM.reset(new ParentMap(CodeDecl.getBody(getContext())));
return *PM.get();
}
@@ -163,7 +163,7 @@ public:
BugReport& getReport() { return *R; }
GRBugReporter& getBugReporter() { return BR; }
GRStateManager& getStateManager() { return BR.getStateManager(); }
-
+
PathDiagnosticLocation getEnclosingStmtLocation(const Stmt *S);
PathDiagnosticLocation
@@ -189,7 +189,7 @@ PathDiagnosticBuilder::ExecutionContinues(const ExplodedNode<GRState>* N) {
if (Stmt *S = GetNextStmt(N))
return PathDiagnosticLocation(S, SMgr);
- return FullSourceLoc(CodeDecl.getBody()->getRBracLoc(), SMgr);
+ return FullSourceLoc(CodeDecl.getBody(getContext())->getRBracLoc(), SMgr);
}
PathDiagnosticLocation
diff --git a/clang/lib/Analysis/CFRefCount.cpp b/clang/lib/Analysis/CFRefCount.cpp
index cfeabd0cb1b..7443c521b3b 100644
--- a/clang/lib/Analysis/CFRefCount.cpp
+++ b/clang/lib/Analysis/CFRefCount.cpp
@@ -2903,7 +2903,8 @@ CFRefLeakReport::getEndPath(BugReporter& br, const ExplodedNode<GRState>* EndN){
}
if (!L.isValid()) {
- CompoundStmt *CS = BR.getStateManager().getCodeDecl().getBody();
+ CompoundStmt *CS
+ = BR.getStateManager().getCodeDecl().getBody(BR.getContext());
L = PathDiagnosticLocation(CS->getRBracLoc(), SMgr);
}
diff --git a/clang/lib/Analysis/CheckObjCDealloc.cpp b/clang/lib/Analysis/CheckObjCDealloc.cpp
index a14ae265128..0d6e7e46a0b 100644
--- a/clang/lib/Analysis/CheckObjCDealloc.cpp
+++ b/clang/lib/Analysis/CheckObjCDealloc.cpp
@@ -172,7 +172,7 @@ void clang::CheckObjCDealloc(ObjCImplementationDecl* D,
}
// dealloc found. Scan for missing [super dealloc].
- if (MD->getBody() && !scan_dealloc(MD->getBody(), S)) {
+ if (MD->getBody(Ctx) && !scan_dealloc(MD->getBody(Ctx), S)) {
const char* name = LOpts.getGCMode() == LangOptions::NonGC
? "missing [super dealloc]"
@@ -223,7 +223,7 @@ void clang::CheckObjCDealloc(ObjCImplementationDecl* D,
// ivar must be released if and only if the kind of setter was not 'assign'
bool requiresRelease = PD->getSetterKind() != ObjCPropertyDecl::Assign;
- if(scan_ivar_release(MD->getBody(), ID, PD, RS, SelfII, Ctx)
+ if(scan_ivar_release(MD->getBody(Ctx), ID, PD, RS, SelfII, Ctx)
!= requiresRelease) {
const char *name;
const char* category = "Memory (Core Foundation/Objective-C)";
diff --git a/clang/lib/Analysis/CheckObjCUnusedIVars.cpp b/clang/lib/Analysis/CheckObjCUnusedIVars.cpp
index 658a6b189aa..57fad8d86b6 100644
--- a/clang/lib/Analysis/CheckObjCUnusedIVars.cpp
+++ b/clang/lib/Analysis/CheckObjCUnusedIVars.cpp
@@ -85,7 +85,7 @@ void clang::CheckObjCUnusedIvar(ObjCImplementationDecl* D, BugReporter& BR) {
// Now scan the methods for accesses.
for (ObjCImplementationDecl::instmeth_iterator I = D->instmeth_begin(),
E = D->instmeth_end(); I!=E; ++I)
- Scan(M, (*I)->getBody());
+ Scan(M, (*I)->getBody(BR.getContext()));
// Scan for @synthesized property methods that act as setters/getters
// to an ivar.
diff --git a/clang/lib/Analysis/PathDiagnostic.cpp b/clang/lib/Analysis/PathDiagnostic.cpp
index da007c16ec4..1d00727d0a2 100644
--- a/clang/lib/Analysis/PathDiagnostic.cpp
+++ b/clang/lib/Analysis/PathDiagnostic.cpp
@@ -171,8 +171,13 @@ SourceRange PathDiagnosticLocation::asRange() const {
case DeclK:
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
return MD->getSourceRange();
- if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
- return FD->getBody()->getSourceRange();
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+ // FIXME: We would like to always get the function body, even
+ // when it needs to be de-serialized, but getting the
+ // ASTContext here requires significant changes.
+ if (CompoundStmt *Body = FD->getBodyIfAvailable())
+ return Body->getSourceRange();
+ }
else {
SourceLocation L = D->getLocation();
return SourceRange(L, L);
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 808add74f76..147155ea1ac 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -131,8 +131,8 @@ void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) {
if (CGM.getDebugInfo() && !OMD->hasAttr<NodebugAttr>())
DebugInfo = CGM.getDebugInfo();
StartObjCMethod(OMD, OMD->getClassInterface());
- EmitStmt(OMD->getBody());
- FinishFunction(cast<CompoundStmt>(OMD->getBody())->getRBracLoc());
+ EmitStmt(OMD->getBody(getContext()));
+ FinishFunction(cast<CompoundStmt>(OMD->getBody(getContext()))->getRBracLoc());
}
// FIXME: I wasn't sure about the synthesis approach. If we end up
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 4bdebfe4315..45c7d0aa27a 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -225,7 +225,7 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD,
FProto->getArgType(i)));
}
- const CompoundStmt *S = FD->getBody();
+ const CompoundStmt *S = FD->getBody(getContext());
StartFunction(FD, FD->getResultType(), Fn, Args, S->getLBracLoc());
EmitStmt(S);
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 4cb1b43ba53..df62f0e918b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -971,7 +971,7 @@ void CodeGenModule::EmitAliasDefinition(const ValueDecl *D) {
if (D->hasAttr<DLLExportAttr>()) {
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
// The dllexport attribute is ignored for undefined symbols.
- if (FD->getBody())
+ if (FD->getBody(getContext()))
GA->setLinkage(llvm::Function::DLLExportLinkage);
} else {
GA->setLinkage(llvm::Function::DLLExportLinkage);
@@ -1403,7 +1403,7 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
case Decl::ObjCMethod: {
ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(D);
// If this is not a prototype, emit the body.
- if (OMD->getBody())
+ if (OMD->getBody(getContext()))
CodeGenFunction(*this).GenerateObjCMethod(OMD);
break;
}
diff --git a/clang/lib/Frontend/PCHWriter.cpp b/clang/lib/Frontend/PCHWriter.cpp
index 64bf3833b4f..d7f0cd3497f 100644
--- a/clang/lib/Frontend/PCHWriter.cpp
+++ b/clang/lib/Frontend/PCHWriter.cpp
@@ -241,13 +241,15 @@ namespace {
: public DeclVisitor<PCHDeclWriter, void> {
PCHWriter &Writer;
+ ASTContext &Context;
PCHWriter::RecordData &Record;
public:
pch::DeclCode Code;
- PCHDeclWriter(PCHWriter &Writer, PCHWriter::RecordData &Record)
- : Writer(Writer), Record(Record) { }
+ PCHDeclWriter(PCHWriter &Writer, ASTContext &Context,
+ PCHWriter::RecordData &Record)
+ : Writer(Writer), Context(Context), Record(Record) { }
void VisitDecl(Decl *D);
void VisitTranslationUnitDecl(TranslationUnitDecl *D);
@@ -340,7 +342,7 @@ void PCHDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
VisitValueDecl(D);
Record.push_back(D->isThisDeclarationADefinition());
if (D->isThisDeclarationADefinition())
- Writer.AddStmt(D->getBody());
+ Writer.AddStmt(D->getBody(Context));
Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
Record.push_back(D->getStorageClass()); // FIXME: stable encoding
Record.push_back(D->isInline());
@@ -1474,7 +1476,7 @@ void PCHWriter::WriteDeclsBlock(ASTContext &Context) {
// Emit all of the declarations.
RecordData Record;
- PCHDeclWriter W(*this, Record);
+ PCHDeclWriter W(*this, Context, Record);
while (!DeclsToEmit.empty()) {
// Pull the next declaration off the queue
Decl *D = DeclsToEmit.front();
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3a264d4449e..619d08c7580 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2824,7 +2824,7 @@ Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) {
// See if this is a redefinition.
const FunctionDecl *Definition;
- if (FD->getBody(Definition)) {
+ if (FD->getBody(Context, Definition)) {
Diag(FD->getLocation(), diag::err_redefinition) << FD->getDeclName();
Diag(Definition->getLocation(), diag::note_previous_definition);
}
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index cafa67fde75..f16d343dd04 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -771,7 +771,7 @@ static void HandleWeakImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
isDef = (!VD->hasExternalStorage() || VD->getInit());
} else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
- isDef = FD->getBody();
+ isDef = FD->getBody(S.Context);
} else if (isa<ObjCPropertyDecl>(D)) {
// We ignore weak import on properties
return;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e0d28fa140e..20a150fad60 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2417,7 +2417,7 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc,
// Check if we have too few/too many template arguments, based
// on our knowledge of the function definition.
const FunctionDecl *Def = 0;
- if (FDecl->getBody(Def) && NumArgs != Def->param_size())
+ if (FDecl->getBody(Context, Def) && NumArgs != Def->param_size())
Diag(RParenLoc, diag::warn_call_wrong_number_of_arguments)
<< (NumArgs > Def->param_size()) << FDecl << Fn->getSourceRange();
}
OpenPOWER on IntegriCloud