Remove the ASTContext parameter from the getBody() methods of Decl and subclasses.

Timings showed no significant difference before and after the commit.

llvm-svn: 74504
This commit is contained in:
Argyrios Kyrtzidis 2009-06-30 02:35:26 +00:00
parent 8a803cc351
commit ddcd132a5b
26 changed files with 50 additions and 55 deletions

View File

@ -724,11 +724,11 @@ public:
/// function. The variant that accepts a FunctionDecl pointer will
/// set that function declaration to the actual declaration
/// containing the body (if there is one).
Stmt *getBody(ASTContext &Context, const FunctionDecl *&Definition) const;
Stmt *getBody(const FunctionDecl *&Definition) const;
virtual Stmt *getBody(ASTContext &Context) const {
virtual Stmt *getBody() const {
const FunctionDecl* Definition;
return getBody(Context, Definition);
return getBody(Definition);
}
/// \brief If the function has a body that is immediately available,
@ -1442,8 +1442,8 @@ public:
bool IsVariadic() const { return isVariadic; }
void setIsVariadic(bool value) { isVariadic = value; }
CompoundStmt *getBody() const { return (CompoundStmt*) Body; }
Stmt *getBody(ASTContext &C) const { return (Stmt*) Body; }
CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
Stmt *getBody() const { return (Stmt*) Body; }
void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
// Iterator access to formal parameters.

View File

@ -314,14 +314,14 @@ public:
/// getBody - If this Decl represents a declaration for a body of code,
/// such as a function or method definition, this method returns the
/// top-level Stmt* of that body. Otherwise this method returns null.
virtual Stmt* getBody(ASTContext &Context) const { return 0; }
virtual Stmt* getBody() const { return 0; }
/// getCompoundBody - Returns getBody(), dyn_casted to a CompoundStmt.
CompoundStmt* getCompoundBody(ASTContext &Context) const;
CompoundStmt* getCompoundBody() const;
/// getBodyRBrace - Gets the right brace of the body, if a body exists.
/// This works whether the body is a CompoundStmt or a CXXTryStmt.
SourceLocation getBodyRBrace(ASTContext &Context) const;
SourceLocation getBodyRBrace() const;
// global temp stats (until we have a per-module visitor)
static void addDeclKind(Kind k);

View File

@ -242,10 +242,10 @@ public:
return ImplementationControl(DeclImplementation);
}
virtual Stmt *getBody(ASTContext &C) const {
virtual Stmt *getBody() const {
return (Stmt*) Body;
}
CompoundStmt *getBody() { return (CompoundStmt*)Body; }
CompoundStmt *getCompoundBody() { return (CompoundStmt*)Body; }
void setBody(Stmt *B) { Body = B; }
// Implement isa/cast/dyncast/etc.

View File

@ -2433,9 +2433,6 @@ public:
const Stmt *getBody() const;
Stmt *getBody();
const Stmt *getBody(ASTContext &C) const { return getBody(); }
Stmt *getBody(ASTContext &C) { return getBody(); }
virtual SourceRange getSourceRange() const {
return SourceRange(getCaretLocation(), getBody()->getLocEnd());
}

View File

@ -375,12 +375,11 @@ void FunctionDecl::Destroy(ASTContext& C) {
}
Stmt *FunctionDecl::getBody(ASTContext &Context,
const FunctionDecl *&Definition) const {
Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) {
if (FD->Body) {
Definition = FD;
return FD->Body.get(Context.getExternalSource());
return FD->Body.get(getASTContext().getExternalSource());
}
}

View File

@ -360,12 +360,12 @@ DeclContext *Decl::castToDeclContext(const Decl *D) {
}
}
CompoundStmt* Decl::getCompoundBody(ASTContext &Context) const {
return dyn_cast_or_null<CompoundStmt>(getBody(Context));
CompoundStmt* Decl::getCompoundBody() const {
return dyn_cast_or_null<CompoundStmt>(getBody());
}
SourceLocation Decl::getBodyRBrace(ASTContext &Context) const {
Stmt *Body = getBody(Context);
SourceLocation Decl::getBodyRBrace() const {
Stmt *Body = getBody();
if (!Body)
return SourceLocation();
if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Body))

View File

@ -361,7 +361,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
} else
Out << ' ';
D->getBody(Context)->printPretty(Out, Context, 0, SubPolicy, Indentation);
D->getBody()->printPretty(Out, Context, 0, SubPolicy, Indentation);
Out << '\n';
}
}

View File

@ -517,7 +517,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(getContext()), PD, St);
St = scanForIvars(MD->getBody(), PD, St);
}
}
}

View File

@ -146,7 +146,7 @@ public:
ParentMap& getParentMap() {
if (PM.get() == 0)
PM.reset(new ParentMap(getCodeDecl().getBody(getASTContext())));
PM.reset(new ParentMap(getCodeDecl().getBody()));
return *PM.get();
}
@ -182,8 +182,7 @@ PathDiagnosticBuilder::ExecutionContinues(const ExplodedNode<GRState>* N) {
if (Stmt *S = GetNextStmt(N))
return PathDiagnosticLocation(S, getSourceManager());
return FullSourceLoc(getCodeDecl().getBodyRBrace(getASTContext()),
getSourceManager());
return FullSourceLoc(getCodeDecl().getBodyRBrace(), getSourceManager());
}
PathDiagnosticLocation
@ -893,7 +892,7 @@ public:
// statement (if it doesn't already exist).
// FIXME: Should handle CXXTryStmt if analyser starts supporting C++.
if (const CompoundStmt *CS =
PDB.getCodeDecl().getCompoundBody(PDB.getASTContext()))
PDB.getCodeDecl().getCompoundBody())
if (!CS->body_empty()) {
SourceLocation Loc = (*CS->body_begin())->getLocStart();
rawAddEdge(PathDiagnosticLocation(Loc, PDB.getSourceManager()));

View File

@ -2632,7 +2632,7 @@ CFRefLeakReport::getEndPath(BugReporterContext& BRC,
if (!L.isValid()) {
const Decl &D = BRC.getCodeDecl();
L = PathDiagnosticLocation(D.getBodyRBrace(BRC.getASTContext()), SMgr);
L = PathDiagnosticLocation(D.getBodyRBrace(), SMgr);
}
std::string sbuf;

View File

@ -172,7 +172,7 @@ void clang::CheckObjCDealloc(ObjCImplementationDecl* D,
}
// dealloc found. Scan for missing [super dealloc].
if (MD->getBody(Ctx) && !scan_dealloc(MD->getBody(Ctx), S)) {
if (MD->getBody() && !scan_dealloc(MD->getBody(), 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(Ctx), ID, PD, RS, SelfII, Ctx)
if(scan_ivar_release(MD->getBody(), ID, PD, RS, SelfII, Ctx)
!= requiresRelease) {
const char *name;
const char* category = "Memory (Core Foundation/Objective-C)";

View File

@ -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(Ctx),
E = D->instmeth_end(Ctx); I!=E; ++I)
Scan(M, (*I)->getBody(Ctx));
Scan(M, (*I)->getBody());
// Scan for @synthesized property methods that act as setters/getters
// to an ivar.

View File

@ -129,8 +129,8 @@ void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) {
if (CGM.getDebugInfo() && !OMD->hasAttr<NodebugAttr>())
DebugInfo = CGM.getDebugInfo();
StartObjCMethod(OMD, OMD->getClassInterface());
EmitStmt(OMD->getBody(getContext()));
FinishFunction(OMD->getBodyRBrace(getContext()));
EmitStmt(OMD->getBody());
FinishFunction(OMD->getBodyRBrace());
}
// FIXME: I wasn't sure about the synthesis approach. If we end up generating an

View File

@ -226,7 +226,7 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD,
}
// FIXME: Support CXXTryStmt here, too.
if (const CompoundStmt *S = FD->getCompoundBody(getContext())) {
if (const CompoundStmt *S = FD->getCompoundBody()) {
StartFunction(FD, FD->getResultType(), Fn, Args, S->getLBracLoc());
EmitStmt(S);
FinishFunction(S->getRBracLoc());

View File

@ -1102,7 +1102,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(getContext()))
if (FD->getBody())
GA->setLinkage(llvm::Function::DLLExportLinkage);
} else {
GA->setLinkage(llvm::Function::DLLExportLinkage);
@ -1550,7 +1550,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(getContext()))
if (OMD->getBody())
CodeGenFunction(*this).GenerateObjCMethod(OMD);
break;
}

View File

@ -307,7 +307,7 @@ void AnalysisConsumer::HandleTopLevelSingleDecl(Decl *D) {
Opts.AnalyzeSpecificFunction != FD->getIdentifier()->getName())
break;
Stmt* Body = FD->getBody(*Ctx);
Stmt* Body = FD->getBody();
if (Body) HandleCode(FD, Body, FunctionActions);
break;
}

View File

@ -147,7 +147,7 @@ void DocumentXML::writeDeclToXML(Decl *D)
DeclPrinter(*this).Visit(D);
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
{
if (Stmt *Body = FD->getBody(*Ctx)) {
if (Stmt *Body = FD->getBody()) {
addSubNode("Body");
PrintStmt(Body);
toParent();

View File

@ -146,7 +146,7 @@ void PCHDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
VisitValueDecl(D);
Record.push_back(D->isThisDeclarationADefinition());
if (D->isThisDeclarationADefinition())
Writer.AddStmt(D->getBody(Context));
Writer.AddStmt(D->getBody());
Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
Record.push_back(D->getStorageClass()); // FIXME: stable encoding
Record.push_back(D->isInline());
@ -172,7 +172,7 @@ void PCHDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
// Unlike C/C++, method bodies will never be in header files.
Record.push_back(D->getBody() != 0);
if (D->getBody() != 0) {
Writer.AddStmt(D->getBody(Context));
Writer.AddStmt(D->getBody());
Writer.AddDeclRef(D->getSelfDecl(), Record);
Writer.AddDeclRef(D->getCmdDecl(), Record);
}

View File

@ -211,7 +211,7 @@ void DeclLocResolver::VisitFunctionDecl(FunctionDecl *D) {
// Finally, search through the body of the function.
if (D->isThisDeclarationADefinition()) {
StmtLocResolver SLR(Ctx, Loc);
SLR.Visit(D->getBody(Ctx));
SLR.Visit(D->getBody());
if (SLR.FoundIt()) {
llvm::tie(Dcl, Stm) = SLR.getResult();
// If we didn't find a more immediate 'parent' declaration for the

View File

@ -1089,7 +1089,7 @@ void RewriteBlocks::HandleDeclInMainFile(Decl *D) {
RewriteFunctionProtoType(FD->getType(), FD);
// FIXME: Handle CXXTryStmt
if (CompoundStmt *Body = FD->getCompoundBody(*Context)) {
if (CompoundStmt *Body = FD->getCompoundBody()) {
CurFunctionDef = FD;
FD->setBody(cast_or_null<CompoundStmt>(RewriteFunctionBody(Body)));
// This synthesizes and inserts the block "impl" struct, invoke function,
@ -1101,7 +1101,7 @@ void RewriteBlocks::HandleDeclInMainFile(Decl *D) {
}
if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
RewriteMethodDecl(MD);
if (Stmt *Body = MD->getBody(*Context)) {
if (Stmt *Body = MD->getBody()) {
CurMethodDef = MD;
RewriteFunctionBody(Body);
InsertBlockLiteralsWithinMethod(MD);
@ -1113,7 +1113,7 @@ void RewriteBlocks::HandleDeclInMainFile(Decl *D) {
RewriteBlockPointerDecl(VD);
if (VD->getInit()) {
if (BlockExpr *CBE = dyn_cast<BlockExpr>(VD->getInit())) {
RewriteFunctionBody(CBE->getBody(*Context));
RewriteFunctionBody(CBE->getBody());
// We've just rewritten the block body in place.
// Now we snarf the rewritten text and stash it away for later use.

View File

@ -993,7 +993,7 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) {
ObjCMethodDecl *OMD = *I;
RewriteObjCMethodDecl(OMD, ResultStr);
SourceLocation LocStart = OMD->getLocStart();
SourceLocation LocEnd = OMD->getCompoundBody(*Context)->getLocStart();
SourceLocation LocEnd = OMD->getCompoundBody()->getLocStart();
const char *startBuf = SM->getCharacterData(LocStart);
const char *endBuf = SM->getCharacterData(LocEnd);
@ -1009,7 +1009,7 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) {
ObjCMethodDecl *OMD = *I;
RewriteObjCMethodDecl(OMD, ResultStr);
SourceLocation LocStart = OMD->getLocStart();
SourceLocation LocEnd = OMD->getCompoundBody(*Context)->getLocStart();
SourceLocation LocEnd = OMD->getCompoundBody()->getLocStart();
const char *startBuf = SM->getCharacterData(LocStart);
const char *endBuf = SM->getCharacterData(LocEnd);
@ -4554,7 +4554,7 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
RewriteBlocksInFunctionProtoType(FD->getType(), FD);
// FIXME: If this should support Obj-C++, support CXXTryStmt
if (CompoundStmt *Body = FD->getCompoundBody(*Context)) {
if (CompoundStmt *Body = FD->getCompoundBody()) {
CurFunctionDef = FD;
CollectPropertySetters(Body);
CurrentBody = Body;
@ -4574,7 +4574,7 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
return;
}
if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
if (CompoundStmt *Body = MD->getBody()) {
if (CompoundStmt *Body = MD->getCompoundBody()) {
CurMethodDef = MD;
CollectPropertySetters(Body);
CurrentBody = Body;

View File

@ -3063,7 +3063,7 @@ Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) {
// See if this is a redefinition.
const FunctionDecl *Definition;
if (FD->getBody(Context, Definition)) {
if (FD->getBody(Definition)) {
Diag(FD->getLocation(), diag::err_redefinition) << FD->getDeclName();
Diag(Definition->getLocation(), diag::note_previous_definition);
}

View File

@ -818,7 +818,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(S.Context);
isDef = FD->getBody();
} else if (isa<ObjCPropertyDecl>(D) || isa<ObjCMethodDecl>(D)) {
// We ignore weak import on properties and methods
return;

View File

@ -2750,7 +2750,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(Context, Def) && NumArgs != Def->param_size()) {
if (FDecl->getBody(Def) && NumArgs != Def->param_size()) {
const FunctionProtoType *Proto =
Def->getType()->getAsFunctionProtoType();
if (!Proto || !(Proto->isVariadic() && NumArgs >= Def->param_size())) {
@ -5607,7 +5607,7 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) {
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
// Implicit instantiation of function templates and member functions of
// class templates.
if (!Function->getBody(Context)) {
if (!Function->getBody()) {
// FIXME: distinguish between implicit instantiations of function
// templates and explicit specializations (the latter don't get
// instantiated, naturally).

View File

@ -1000,7 +1000,7 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
DEnd = Instantiation->decls_end(Context);
D != DEnd; ++D) {
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(*D)) {
if (!Function->getBody(Context))
if (!Function->getBody())
InstantiateFunctionDefinition(PointOfInstantiation, Function);
} else if (VarDecl *Var = dyn_cast<VarDecl>(*D)) {
const VarDecl *Def = 0;

View File

@ -670,7 +670,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
if (Function->isInvalidDecl())
return;
assert(!Function->getBody(Context) && "Already instantiated!");
assert(!Function->getBody() && "Already instantiated!");
// Find the function body that we'll be substituting.
const FunctionDecl *PatternDecl = 0;
@ -680,7 +680,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
PatternDecl = Function->getInstantiatedFromMemberFunction();
Stmt *Pattern = 0;
if (PatternDecl)
Pattern = PatternDecl->getBody(Context, PatternDecl);
Pattern = PatternDecl->getBody(PatternDecl);
if (!Pattern)
return;
@ -863,7 +863,7 @@ void Sema::PerformPendingImplicitInstantiations() {
PendingImplicitInstantiations.pop();
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Inst.first))
if (!Function->getBody(Context))
if (!Function->getBody())
InstantiateFunctionDefinition(/*FIXME:*/Inst.second, Function);
// FIXME: instantiation static member variables