diff options
author | Bruno Ricci <riccibrun@gmail.com> | 2018-12-03 14:54:03 +0000 |
---|---|---|
committer | Bruno Ricci <riccibrun@gmail.com> | 2018-12-03 14:54:03 +0000 |
commit | 67a4e110d5e6f802a0ae7644ddead2aa904b0e49 (patch) | |
tree | ecae51c5aa6eaa7e1b071027220443c9c841efb7 /include/clang/AST/Expr.h | |
parent | 74a1e19dc9d9b5f1e4275745a384f594922c4ac9 (diff) |
[AST][Sema] Remove CallExpr::setNumArgs
CallExpr::setNumArgs is the only thing that prevents storing the arguments
in a trailing array. There is only 3 places in Sema where setNumArgs is called.
D54900 dealt with one of them.
This patch remove the other two calls to setNumArgs in ConvertArgumentsForCall.
To do this we do the following changes:
1.) Replace the first call to setNumArgs by an assertion since we are moving the
responsability to allocate enough space for the arguments from
Sema::ConvertArgumentsForCall to its callers
(which are Sema::BuildCallToMemberFunction, and Sema::BuildResolvedCallExpr).
2.) Add a new member function CallExpr::shrinkNumArgs, which can only be used
to drop arguments and then replace the second call to setNumArgs by
shrinkNumArgs.
3.) Add a new defaulted parameter MinNumArgs to CallExpr and its derived
classes which specifies a minimum number of argument slots to allocate.
The actual number of arguments slots allocated will be
max(number of args, MinNumArgs) with the extra args nulled. Note that
after the creation of the call expression all of the arguments will be
non-null. It is just during the creation of the call expression that some of
the last arguments can be temporarily null, until filled by default arguments.
4.) Update Sema::BuildCallToMemberFunction by passing the number of parameters
in the function prototype to the constructor of CXXMemberCallExpr. Here the
change is pretty straightforward.
5.) Update Sema::BuildResolvedCallExpr. Here the change is more complicated
since the type-checking for the function type was done after the creation of
the call expression. We need to move this before the creation of the call
expression, and then pass the number of parameters in the function prototype
(if any) to the constructor of the call expression.
6.) Update the deserialization of CallExpr and its derived classes.
Differential Revision: https://reviews.llvm.org/D54902
Reviewed By: aaron.ballman
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348145 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/AST/Expr.h')
-rw-r--r-- | include/clang/AST/Expr.h | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 7df7b56ca1..d082fdd1cc 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -2416,11 +2416,12 @@ protected: // These versions of the constructor are for derived classes. CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, ArrayRef<Expr *> preargs, ArrayRef<Expr *> args, QualType t, - ExprValueKind VK, SourceLocation rparenloc); + ExprValueKind VK, SourceLocation rparenloc, unsigned MinNumArgs = 0); CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, ArrayRef<Expr *> args, - QualType t, ExprValueKind VK, SourceLocation rparenloc); + QualType t, ExprValueKind VK, SourceLocation rparenloc, + unsigned MinNumArgs = 0); CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs, - EmptyShell Empty); + unsigned NumArgs, EmptyShell Empty); Stmt *getPreArg(unsigned i) { assert(i < getNumPreArgs() && "Prearg access out of range!"); @@ -2438,11 +2439,14 @@ protected: unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } public: - CallExpr(const ASTContext& C, Expr *fn, ArrayRef<Expr*> args, QualType t, - ExprValueKind VK, SourceLocation rparenloc); + /// Build a call expression. MinNumArgs specifies the minimum number of + /// arguments. The actual number of arguments will be the greater of + /// args.size() and MinNumArgs. + CallExpr(const ASTContext &C, Expr *fn, ArrayRef<Expr *> args, QualType t, + ExprValueKind VK, SourceLocation rparenloc, unsigned MinNumArgs = 0); /// Build an empty call expression. - CallExpr(const ASTContext &C, StmtClass SC, EmptyShell Empty); + CallExpr(const ASTContext &C, unsigned NumArgs, EmptyShell Empty); const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } @@ -2488,10 +2492,18 @@ public: SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; } - /// setNumArgs - This changes the number of arguments present in this call. - /// Any orphaned expressions are deleted by this, and any new operands are set - /// to null. - void setNumArgs(const ASTContext& C, unsigned NumArgs); + /// Reduce the number of arguments in this call expression. This is used for + /// example during error recovery to drop extra arguments. There is no way + /// to perform the opposite because: 1.) We don't track how much storage + /// we have for the argument array 2.) This would potentially require growing + /// the argument array, something we cannot support since the arguments will + /// be stored in a trailing array in the future. + /// (TODO: update this comment when this is done). + void shrinkNumArgs(unsigned NewNumArgs) { + assert((NewNumArgs <= NumArgs) && + "shrinkNumArgs cannot increase the number of arguments!"); + NumArgs = NewNumArgs; + } typedef ExprIterator arg_iterator; typedef ConstExprIterator const_arg_iterator; |