Hi Sam,
really cool stuff! I've changed the subject so we can keep a review
thread per patch.
High-level comment:
- I personally prefer to put the public stuff first in the class
definition, as that's what I'm interested in as a user of the class;
it is also the most important thing about the class; if nobody
objects, I'd vote that we make that a rule in the tools/extra
repository.
- I would like to see a few more negative tests; I've added comments
inline for which parts of the code I'd want to see more tests; my
general guide-line is that there should be at least one test that
breaks when you change lines of code in an "easy to get wrong" way...
+ if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(T)) { // meow
meow what?
+ // The array's size will always be an APInt representing the length as an
+ // unsigned value, and ConditionExpr may evaluate to a signed value.
+ // To avoid precision loss, we extend each to be one bit larger than the
+ // largest size, convert ConditionExpr to an unsigned value, and compare
+ // the two unsigned values.
I'd add tests that verify the corner cases here...
Or, can you just call APSInt::isSameValue() and get rid of the comment
and the complex code?
+bool ForLoopASTVisitor::TraverseArraySubscriptExpr(ArraySubscriptExpr *ASE) {
+ Expr *Arr = ASE->getBase();
+ if (isValidSubscriptExpr(ASE->getIdx(), TargetVar, Arr)) {
+ const Expr *ArrReduced = Arr->IgnoreParenCasts();
+ if (!containsExpr(Context, &ContainersIndexed, ArrReduced))
+ ContainersIndexed.insert(ArrReduced);
+ Usages.push_back(ASE);
+ return true;
Why's this only a Usage when isValidSubscriptExpr? (comment might help)
+//////////////////// ForLoopASTVisitor functions
I have a strong dislike of ascii art in source code, as I think it's
not helpful (ForLoopASTVisitor methods are easy to detect by the
ForLoopASTVisitor:: prefix
+ if (!FS || !Context->getSourceManager().isFromMainFile(FS->getForLoc()))
FS cannot be NULL. If you don't trust me, use assert() and report a
bug if it ever fails
Is the isFromMainFile part tested anywhere?
+ if (!areSameVariable(LoopVar, CondVar) || !areSameVariable(LoopVar, InitVar))
+ return;
I'd add negative tests for those...
+ if (!BoundExpr)
+ return;
Again, cannot happen - assert() if you want.
+ const ForLoopASTVisitor::ContainerResult &ContainersIndexed =
+ Finder.getContainersIndexed();
+ if (ContainersIndexed.size() != 1)
+ return;
I'd add a negative test for that.
+//===-- llvm/Instruction.h - Instruction class definition -------*-
C++ -*-===//
Wrong name
+// This file contains matchers and callbacks for use in migrating C++
for loops.
+//
+//
+//===----------------------------------------------------------------------===//
Remove unnecessary vertical space.
+class ForLoopASTVisitor : public RecursiveASTVisitor<ForLoopASTVisitor> {
+ public :
Why's this in the header? Isn't this an implementation detail of LoopFixer?
+ // Accessor for OnlyUsedAsIndex
+ bool isOnlyUsedAsIndex() const { return OnlyUsedAsIndex; }
Unused (outside of the class). Remove?
+using std::vector;
+using std::string;
I'd generally prefer to just spell them out - seems like this is more
noise than the view extra std::.
Cheers,
/Manuel