Merge the two routines.
This commit is contained in:
parent
56829dd334
commit
f9a0b72594
@ -48,8 +48,9 @@ namespace cling {
|
||||
return false;
|
||||
}
|
||||
|
||||
Expr* ASTNullDerefProtection::InsertThrow(SourceLocation* Loc, Expr* Arg) {
|
||||
ASTContext* Context = &m_Sema->getASTContext();
|
||||
|
||||
Stmt* ASTNullDerefProtection::SynthesizeCheck(SourceLocation Loc, Expr* Arg ){
|
||||
ASTContext& Context = m_Sema->getASTContext();
|
||||
Scope* S = m_Sema->getScopeForContext(m_Sema->CurContext);
|
||||
//copied from DynamicLookup.cpp
|
||||
NamespaceDecl* NSD = utils::Lookup::Namespace(m_Sema, "cling");
|
||||
@ -58,7 +59,7 @@ namespace cling {
|
||||
|
||||
// Find and set up "NullDerefException"
|
||||
DeclarationName Name
|
||||
= &Context->Idents.get("NullDerefException");
|
||||
= &Context.Idents.get("NullDerefException");
|
||||
|
||||
LookupResult R(*m_Sema, Name, SourceLocation(),
|
||||
Sema::LookupOrdinaryName, Sema::ForRedeclaration);
|
||||
@ -71,7 +72,7 @@ namespace cling {
|
||||
= dyn_cast<CXXRecordDecl>(utils::Lookup::Named(m_Sema, "Sema",
|
||||
utils::Lookup::Namespace(m_Sema, "clang")));
|
||||
|
||||
QualType SemaRDTy = Context->getTypeDeclType(SemaRD);
|
||||
QualType SemaRDTy = Context.getTypeDeclType(SemaRD);
|
||||
Expr* VoidSemaArg = utils::Synthesize::CStyleCastPtrExpr(m_Sema, SemaRDTy,
|
||||
(uint64_t)m_Sema);
|
||||
|
||||
@ -80,25 +81,19 @@ namespace cling {
|
||||
= dyn_cast<CXXRecordDecl>(utils::Lookup::Named(m_Sema, "Expr",
|
||||
utils::Lookup::Namespace(m_Sema, "clang")));
|
||||
|
||||
QualType ExprRDTy = Context->getTypeDeclType(ExprRD);
|
||||
QualType ExprRDTy = Context.getTypeDeclType(ExprRD);
|
||||
Expr* VoidExprArg = utils::Synthesize::CStyleCastPtrExpr(m_Sema, ExprRDTy,
|
||||
(uint64_t)Arg);
|
||||
|
||||
Expr *args[] = {VoidSemaArg, VoidExprArg};
|
||||
QualType NullDerefDeclTy = Context->getTypeDeclType(NullDerefDecl);
|
||||
TypeSourceInfo* TSI = Context->getTrivialTypeSourceInfo(NullDerefDeclTy,
|
||||
SourceLocation());
|
||||
QualType NullDerefDeclTy = Context.getTypeDeclType(NullDerefDecl);
|
||||
TypeSourceInfo* TSI = Context.getTrivialTypeSourceInfo(NullDerefDeclTy,
|
||||
SourceLocation());
|
||||
ExprResult ConstructorCall
|
||||
= m_Sema->BuildCXXTypeConstructExpr(TSI,*Loc, MultiExprArg(args, 2),*Loc);
|
||||
= m_Sema->BuildCXXTypeConstructExpr(TSI,Loc, MultiExprArg(args, 2),Loc);
|
||||
|
||||
ExprResult Throw = m_Sema->ActOnCXXThrow(S, *Loc, ConstructorCall.take());
|
||||
return Throw.get();
|
||||
}
|
||||
Expr* Throw = m_Sema->ActOnCXXThrow(S, Loc, ConstructorCall.take()).take();
|
||||
|
||||
|
||||
Stmt* ASTNullDerefProtection::SynthesizeCheck(SourceLocation Loc, Expr* Arg ){
|
||||
Expr* Throw = InsertThrow(&Loc, Arg);
|
||||
ASTContext& Context = m_Sema->getASTContext();
|
||||
// Check whether we can get the argument'value. If the argument is
|
||||
// null, throw an exception direclty. If the argument is not null
|
||||
// then ignore this argument and continue to deal with the next
|
||||
@ -114,7 +109,6 @@ namespace cling {
|
||||
// operation to check its value at runtime.
|
||||
DeclRefExpr* DRE = dyn_cast<DeclRefExpr>(Arg->IgnoreImpCasts());
|
||||
assert(DRE && "No declref expr?");
|
||||
Scope* S = m_Sema->getScopeForContext(m_Sema->CurContext);
|
||||
ExprResult ER = m_Sema->ActOnUnaryOp(S, Loc, tok::exclaim, DRE);
|
||||
|
||||
Decl* varDecl = 0;
|
||||
@ -181,17 +175,7 @@ namespace cling {
|
||||
}
|
||||
}
|
||||
else {
|
||||
Expr* Throw = InsertThrow(&SL, Op);
|
||||
ExprResult ER
|
||||
= m_Sema->Sema::ActOnUnaryOp(S, SL, tok::exclaim, Op);
|
||||
|
||||
Decl* varDecl = 0;
|
||||
Stmt* varStmt = 0;
|
||||
|
||||
Sema::FullExprArg FullCond(m_Sema->MakeFullExpr(ER.take()));
|
||||
StmtResult IfStmt = m_Sema->ActOnIfStmt(SL, FullCond, varDecl,
|
||||
Throw, SL, varStmt);
|
||||
Stmts.push_back(IfStmt.get());
|
||||
Stmts.push_back(SynthesizeCheck(SL, Op));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,8 +43,6 @@ namespace cling {
|
||||
ASTNullDerefProtection(clang::Sema* S);
|
||||
|
||||
virtual ~ASTNullDerefProtection();
|
||||
clang::Expr* InsertThrow(clang::SourceLocation* Loc,
|
||||
clang::Expr* Arg);
|
||||
clang::Stmt* SynthesizeCheck(clang::SourceLocation Loc,
|
||||
clang::Expr* Arg);
|
||||
virtual void Transform();
|
||||
|
Loading…
x
Reference in New Issue
Block a user