diff options
author | Chris Lattner <sabre@nondot.org> | 2007-12-28 05:25:02 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-12-28 05:25:02 +0000 |
commit | e4407ede20b9a8525d79ef07f65d23fefe6a237d (patch) | |
tree | 6ce8bd8e8813daf4d2054910ebfb211f9604ca66 | |
parent | 180f0e904437fbb3fe3472523b15b20c03bac2a0 (diff) | |
download | bcm5719-llvm-e4407ede20b9a8525d79ef07f65d23fefe6a237d.tar.gz bcm5719-llvm-e4407ede20b9a8525d79ef07f65d23fefe6a237d.zip |
Add accessors + iterator interface.
llvm-svn: 45378
-rw-r--r-- | clang/AST/Expr.cpp | 30 | ||||
-rw-r--r-- | clang/include/clang/AST/Expr.h | 15 |
2 files changed, 45 insertions, 0 deletions
diff --git a/clang/AST/Expr.cpp b/clang/AST/Expr.cpp index e814d58328a..94d99ab4bd5 100644 --- a/clang/AST/Expr.cpp +++ b/clang/AST/Expr.cpp @@ -88,6 +88,36 @@ CallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t, RParenLoc = rparenloc; } +/// 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 CallExpr::setNumArgs(unsigned NumArgs) { + // No change, just return. + if (NumArgs == getNumArgs()) return; + + // If shrinking # arguments, just delete the extras and forgot them. + if (NumArgs < getNumArgs()) { + for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i) + delete getArg(i); + this->NumArgs = NumArgs; + return; + } + + // Otherwise, we are growing the # arguments. New an bigger argument array. + Expr **NewSubExprs = new Expr*[NumArgs+1]; + // Copy over args. + for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i) + NewSubExprs[i] = SubExprs[i]; + // Null out new args. + for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i) + NewSubExprs[i] = 0; + + delete[] SubExprs; + SubExprs = NewSubExprs; + this->NumArgs = NumArgs; +} + + bool CallExpr::isBuiltinClassifyType(llvm::APSInt &Result) const { // The following enum mimics gcc's internal "typeclass.h" file. enum gcc_type_class { diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index b82db0e0ff9..aba11ea9adb 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -585,12 +585,27 @@ public: assert(Arg < NumArgs && "Arg access out of range!"); SubExprs[Arg+ARGS_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(unsigned NumArgs); + + typedef Expr **arg_iterator; + typedef Expr * const *arg_const_iterator; + arg_iterator arg_begin() { return SubExprs+ARGS_START; } + arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); } + arg_const_iterator arg_begin() const { return SubExprs+ARGS_START; } + arg_const_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs(); } + + /// getNumCommas - Return the number of commas that must have been present in /// this function call. unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } bool isBuiltinClassifyType(llvm::APSInt &Result) const; + SourceLocation getRParenLoc() const { return RParenLoc; } SourceRange getSourceRange() const { return SourceRange(getCallee()->getLocStart(), RParenLoc); } |