Add args() iteartor adapter to Function, for range-for loops.

This patch is in similar vein to what done earlier to Module::globals/aliases
etc. It allows to iterate over function arguments like this:

  for (Argument Arg : F.args()) {
    ...
  }



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204835 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eli Bendersky 2014-03-26 18:04:27 +00:00
parent 489752ddb4
commit cf2de5a970

View File

@ -18,6 +18,7 @@
#ifndef LLVM_IR_FUNCTION_H
#define LLVM_IR_FUNCTION_H
#include "llvm/ADT/iterator_range.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
@ -404,9 +405,9 @@ public:
const BasicBlock &back() const { return BasicBlocks.back(); }
BasicBlock &back() { return BasicBlocks.back(); }
//===--------------------------------------------------------------------===//
// Argument iterator forwarding functions
//
/// @name Function Argument Iteration
/// @{
arg_iterator arg_begin() {
CheckLazyArguments();
return ArgumentList.begin();
@ -424,6 +425,16 @@ public:
return ArgumentList.end();
}
iterator_range<arg_iterator> args() {
return iterator_range<arg_iterator>(arg_begin(), arg_end());
}
iterator_range<const_arg_iterator> args() const {
return iterator_range<const_arg_iterator>(arg_begin(), arg_end());
}
/// @}
size_t arg_size() const;
bool arg_empty() const;