|
|
Created:
14 years, 6 months ago by wan Modified:
14 years, 6 months ago CC:
csilvers Base URL:
http://llvm.org/svn/llvm-project/cfe/trunk/ Visibility:
Public. |
Patch Set 1 #
Total comments: 66
Patch Set 2 : addresses Doug and Chandler's comments #
MessagesTotal messages: 3
This looks great! I've made a bunch of comments throughout, but feel free to go ahead and commit when you're ready. http://codereview.appspot.com/1607042/diff/1/2 File include/clang/AST/RecursiveASTVisitor.h (right): http://codereview.appspot.com/1607042/diff/1/2#newcode655 include/clang/AST/RecursiveASTVisitor.h:655: I think the parameters of a block will be in the decl_begin()/decl_end() iteration for the BlockDecl, so you don't need to iterate over them here. If not, they should be in the BlockDecl. http://codereview.appspot.com/1607042/diff/1/2#newcode702 include/clang/AST/RecursiveASTVisitor.h:702: Yes. The anonymous namespace will be represented by a NamespaceDecl inside the decl_begin()/decl_end() iteration, so we should not recurse on D->getAnonymousNamespace() here. http://codereview.appspot.com/1607042/diff/1/2#newcode707 include/clang/AST/RecursiveASTVisitor.h:707: We shouldn't traverse the aliased namespace, since it will be defined (and, therefore, traversed) somewhere else. http://codereview.appspot.com/1607042/diff/1/2#newcode715 include/clang/AST/RecursiveASTVisitor.h:715: Same comment as before: the anonymous namespace will show up in decl_begin()/decl_end(), so it shouldn't be traversed here. http://codereview.appspot.com/1607042/diff/1/2#newcode782 include/clang/AST/RecursiveASTVisitor.h:782: This should not iterate over the specializations/partial specializations. Those will show up in other contexts. getInstantiatedFromMemberTemplate() is just a link from a template instantiation back to the template from which it was instantiated. It should not be traversed. http://codereview.appspot.com/1607042/diff/1/2#newcode814 include/clang/AST/RecursiveASTVisitor.h:814: I don't think you should traverse D->getTypeForDecl(); it's a result of declaring the typedef, not something that was written in the source. http://codereview.appspot.com/1607042/diff/1/2#newcode822 include/clang/AST/RecursiveASTVisitor.h:822: Same comment as above: we shouldn't traverse D->getTypeForDecl(). http://codereview.appspot.com/1607042/diff/1/2#newcode834 include/clang/AST/RecursiveASTVisitor.h:834: The enumerators will already be traversed by decl_begin()/decl_end(); you don't want to walk them here. http://codereview.appspot.com/1607042/diff/1/2#newcode842 include/clang/AST/RecursiveASTVisitor.h:842: Don't traverse D->getTypeForDecl(). http://codereview.appspot.com/1607042/diff/1/2#newcode847 include/clang/AST/RecursiveASTVisitor.h:847: The anonymous struct or union object is the variable or field whose type is the anonymous struct or union. We shouldn't walk "up" the tree like this. While it won't actually cause recursion (since we don't visit the Decl behind a RecordType), it's not something that is explicitly written in the source. http://codereview.appspot.com/1607042/diff/1/2#newcode867 include/clang/AST/RecursiveASTVisitor.h:867: } I believe that all of the friends are in decl_begin()/decl_end(). http://codereview.appspot.com/1607042/diff/1/2#newcode873 include/clang/AST/RecursiveASTVisitor.h:873: } The conversion functions are *definitely* in decl_begin()/end(), so this will double-count. http://codereview.appspot.com/1607042/diff/1/2#newcode885 include/clang/AST/RecursiveASTVisitor.h:885: } We probably want to traverse the TemplateArgumentLoc for explicitly-written specializations and instantiations, rather than the computed template arguments. http://codereview.appspot.com/1607042/diff/1/2#newcode966 include/clang/AST/RecursiveASTVisitor.h:966: } The function parameters will already be visited by decl_begin()/decl_end(). http://codereview.appspot.com/1607042/diff/1/2#newcode967 include/clang/AST/RecursiveASTVisitor.h:967: TRY_TO(TraverseType(D->getResultType())); This doesn't seem to be necessary. The result type is part of the TypeSourceInfo for the function declaration. http://codereview.appspot.com/1607042/diff/1/2#newcode1040 include/clang/AST/RecursiveASTVisitor.h:1040: // FIXME: do we need to recurse on getOriginalType()? Recursing on the TypeSourceInfo is far better that recursing on getOriginalType(), since the TypeSourceInfo describes the original type as written. http://codereview.appspot.com/1607042/diff/1/2#newcode1097 include/clang/AST/RecursiveASTVisitor.h:1097: We'll end up visiting the exception object, which already has this type. That's where S->getCaughtType() actually gets the type information from, so it's redundant to visit here. http://codereview.appspot.com/1607042/diff/1/2#newcode1153 include/clang/AST/RecursiveASTVisitor.h:1153: } Perhaps you want to create a TemplateArgumentLoc* traversal helper? There are several loops like this. http://codereview.appspot.com/1607042/diff/1/2#newcode1182 include/clang/AST/RecursiveASTVisitor.h:1182: // FIXME: make a type callback for the cast? IMO, no: the type wasn't written in the source so we shouldn't have a callback for it. http://codereview.appspot.com/1607042/diff/1/2#newcode1208 include/clang/AST/RecursiveASTVisitor.h:1208: In all of these cases, I think the answer is "yes". We should recurse on the TypeSourceInfo* for the type as is was written. http://codereview.appspot.com/1607042/diff/1/2#newcode1289 include/clang/AST/RecursiveASTVisitor.h:1289: // ExplicitCastExpr Definitely worth traversing the TypeSourceInfo* here. http://codereview.appspot.com/1607042/diff/1/2#newcode1290 include/clang/AST/RecursiveASTVisitor.h:1290: // ImplicitCastExpr? IMO, no. http://codereview.appspot.com/1607042/diff/1/2#newcode1294 include/clang/AST/RecursiveASTVisitor.h:1294: // http://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html ? All of these may have TypeSourceInfo*'s that we should recurse on. http://codereview.appspot.com/1607042/diff/1/2#newcode1296 include/clang/AST/RecursiveASTVisitor.h:1296: Yes. Note that we have an open enhancement request to implement proper source-location information for nested-name-specifiers, but we could still walk each of these NestedNameSpecifiers now.
Sign in to reply to this message.
Just a few stylistic comments. Doug hit just about all of the AST stuff I was trying to comment on in previous iterations. =D http://codereview.appspot.com/1607042/diff/1/2 File include/clang/AST/RecursiveASTVisitor.h (right): http://codereview.appspot.com/1607042/diff/1/2#newcode33 include/clang/AST/RecursiveASTVisitor.h:33: // FIXME: reverse the meaning of the bool return value. Maybe attach this FIXME to the class comment where you explain the meaning? http://codereview.appspot.com/1607042/diff/1/2#newcode49 include/clang/AST/RecursiveASTVisitor.h:49: /// methods (except Traverse*()) for declaration, type, statement, s/except/but not/? Otherwise, this sentence doesn't parse for me... http://codereview.appspot.com/1607042/diff/1/2#newcode54 include/clang/AST/RecursiveASTVisitor.h:54: /// Base::Visit* is called. This last sentence no longer seems accurate. http://codereview.appspot.com/1607042/diff/1/2#newcode115 include/clang/AST/RecursiveASTVisitor.h:115: #define STMT(CLASS, PARENT) \ Do we want to braket these defines tightly around the #include of the nodes inc file? I'm a little worried about how much code in this file has STMT defined for it, but not too worried if you think re-defining things will be too annoying. http://codereview.appspot.com/1607042/diff/1/2#newcode209 include/clang/AST/RecursiveASTVisitor.h:209: #define ABSTRACT_TYPE(CLASS, BASE) FYI, unless I missed something, we've still not undef'ed STMT and ABSTRACT_STMT. http://codereview.appspot.com/1607042/diff/1/2#newcode455 include/clang/AST/RecursiveASTVisitor.h:455: // we enforce the following constraint: only the leaf-node visitors In this paragraph and the next you talk about 'visitors' where I think you mean 'Traverse* methods' or something similar given the new design. http://codereview.appspot.com/1607042/diff/1/2#newcode459 include/clang/AST/RecursiveASTVisitor.h:459: // With this constraint, we can design every leaf-node visitor like s/like/as/ http://codereview.appspot.com/1607042/diff/1/2#newcode465 include/clang/AST/RecursiveASTVisitor.h:465: // For types, we iterate, in the macro, iterating over the parent. This sentence doesn't parse for me. Is entire paragraph needed given the comments above? http://codereview.appspot.com/1607042/diff/1/2#newcode626 include/clang/AST/RecursiveASTVisitor.h:626: // if any, then it iterates over its children, if any. I think these two paragraphs, rather than being repeated three times, should go somewher at the top of the file describing the strategy of the overall class. http://codereview.appspot.com/1607042/diff/1/2#newcode885 include/clang/AST/RecursiveASTVisitor.h:885: } On 2010/06/09 00:31:32, DougGregor wrote: > We probably want to traverse the TemplateArgumentLoc for explicitly-written > specializations and instantiations, rather than the computed template arguments. We have a FIXME for that below I think...
Sign in to reply to this message.
Thanks for the excellent comments, Doug and Chandler! I think I've addressed all of them. Would you please take another look (I've uploaded a new patch to the same issue)? Thanks. http://codereview.appspot.com/1607042/diff/1/2 File include/clang/AST/RecursiveASTVisitor.h (right): http://codereview.appspot.com/1607042/diff/1/2#newcode33 include/clang/AST/RecursiveASTVisitor.h:33: // FIXME: reverse the meaning of the bool return value. On 2010/06/09 01:31:23, chandlerc wrote: > Maybe attach this FIXME to the class comment where you explain the meaning? Done. http://codereview.appspot.com/1607042/diff/1/2#newcode49 include/clang/AST/RecursiveASTVisitor.h:49: /// methods (except Traverse*()) for declaration, type, statement, On 2010/06/09 01:31:23, chandlerc wrote: > s/except/but not/? Otherwise, this sentence doesn't parse for me... Reworded. http://codereview.appspot.com/1607042/diff/1/2#newcode54 include/clang/AST/RecursiveASTVisitor.h:54: /// Base::Visit* is called. On 2010/06/09 01:31:23, chandlerc wrote: > This last sentence no longer seems accurate. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode115 include/clang/AST/RecursiveASTVisitor.h:115: #define STMT(CLASS, PARENT) \ On 2010/06/09 01:31:23, chandlerc wrote: > Do we want to braket these defines tightly around the #include of the nodes inc > file? I'm a little worried about how much code in this file has STMT defined for > it, but not too worried if you think re-defining things will be too annoying. The .inc file takes care of #undef-ing the macros. Added a comment to that effect. http://codereview.appspot.com/1607042/diff/1/2#newcode209 include/clang/AST/RecursiveASTVisitor.h:209: #define ABSTRACT_TYPE(CLASS, BASE) On 2010/06/09 01:31:23, chandlerc wrote: > FYI, unless I missed something, we've still not undef'ed STMT and ABSTRACT_STMT. See above. http://codereview.appspot.com/1607042/diff/1/2#newcode455 include/clang/AST/RecursiveASTVisitor.h:455: // we enforce the following constraint: only the leaf-node visitors On 2010/06/09 01:31:23, chandlerc wrote: > In this paragraph and the next you talk about 'visitors' where I think you mean > 'Traverse* methods' or something similar given the new design. Renamed to "traversal". http://codereview.appspot.com/1607042/diff/1/2#newcode459 include/clang/AST/RecursiveASTVisitor.h:459: // With this constraint, we can design every leaf-node visitor like On 2010/06/09 01:31:23, chandlerc wrote: > s/like/as/ Got rid of the entire comment block, as now we have described the design in details at the beginning of the class. http://codereview.appspot.com/1607042/diff/1/2#newcode465 include/clang/AST/RecursiveASTVisitor.h:465: // For types, we iterate, in the macro, iterating over the parent. On 2010/06/09 01:31:23, chandlerc wrote: > This sentence doesn't parse for me. Is entire paragraph needed given the > comments above? Removed. http://codereview.appspot.com/1607042/diff/1/2#newcode626 include/clang/AST/RecursiveASTVisitor.h:626: // if any, then it iterates over its children, if any. On 2010/06/09 01:31:23, chandlerc wrote: > I think these two paragraphs, rather than being repeated three times, should go > somewher at the top of the file describing the strategy of the overall class. Removed. http://codereview.appspot.com/1607042/diff/1/2#newcode655 include/clang/AST/RecursiveASTVisitor.h:655: On 2010/06/09 00:31:32, DougGregor wrote: > I think the parameters of a block will be in the decl_begin()/decl_end() > iteration for the BlockDecl, so you don't need to iterate over them here. If > not, they should be in the BlockDecl. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode702 include/clang/AST/RecursiveASTVisitor.h:702: On 2010/06/09 00:31:32, DougGregor wrote: > Yes. The anonymous namespace will be represented by a NamespaceDecl inside the > decl_begin()/decl_end() iteration, so we should not recurse on > D->getAnonymousNamespace() here. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode707 include/clang/AST/RecursiveASTVisitor.h:707: On 2010/06/09 00:31:32, DougGregor wrote: > We shouldn't traverse the aliased namespace, since it will be defined (and, > therefore, traversed) somewhere else. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode715 include/clang/AST/RecursiveASTVisitor.h:715: On 2010/06/09 00:31:32, DougGregor wrote: > Same comment as before: the anonymous namespace will show up in > decl_begin()/decl_end(), so it shouldn't be traversed here. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode782 include/clang/AST/RecursiveASTVisitor.h:782: On 2010/06/09 00:31:32, DougGregor wrote: > This should not iterate over the specializations/partial specializations. Those > will show up in other contexts. > > getInstantiatedFromMemberTemplate() is just a link from a template instantiation > back to the template from which it was instantiated. It should not be traversed. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode814 include/clang/AST/RecursiveASTVisitor.h:814: On 2010/06/09 00:31:32, DougGregor wrote: > I don't think you should traverse D->getTypeForDecl(); it's a result of > declaring the typedef, not something that was written in the source. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode822 include/clang/AST/RecursiveASTVisitor.h:822: On 2010/06/09 00:31:32, DougGregor wrote: > Same comment as above: we shouldn't traverse D->getTypeForDecl(). Done. http://codereview.appspot.com/1607042/diff/1/2#newcode834 include/clang/AST/RecursiveASTVisitor.h:834: On 2010/06/09 00:31:32, DougGregor wrote: > The enumerators will already be traversed by decl_begin()/decl_end(); you don't > want to walk them here. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode842 include/clang/AST/RecursiveASTVisitor.h:842: On 2010/06/09 00:31:32, DougGregor wrote: > Don't traverse D->getTypeForDecl(). Done. http://codereview.appspot.com/1607042/diff/1/2#newcode847 include/clang/AST/RecursiveASTVisitor.h:847: On 2010/06/09 00:31:32, DougGregor wrote: > The anonymous struct or union object is the variable or field whose type is the > anonymous struct or union. We shouldn't walk "up" the tree like this. While it > won't actually cause recursion (since we don't visit the Decl behind a > RecordType), it's not something that is explicitly written in the source. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode867 include/clang/AST/RecursiveASTVisitor.h:867: } On 2010/06/09 00:31:32, DougGregor wrote: > I believe that all of the friends are in decl_begin()/decl_end(). Done. http://codereview.appspot.com/1607042/diff/1/2#newcode873 include/clang/AST/RecursiveASTVisitor.h:873: } On 2010/06/09 00:31:32, DougGregor wrote: > The conversion functions are *definitely* in decl_begin()/end(), so this will > double-count. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode885 include/clang/AST/RecursiveASTVisitor.h:885: } On 2010/06/09 00:31:32, DougGregor wrote: > We probably want to traverse the TemplateArgumentLoc for explicitly-written > specializations and instantiations, rather than the computed template arguments. Added a FIXME. http://codereview.appspot.com/1607042/diff/1/2#newcode966 include/clang/AST/RecursiveASTVisitor.h:966: } On 2010/06/09 00:31:32, DougGregor wrote: > The function parameters will already be visited by decl_begin()/decl_end(). Done. http://codereview.appspot.com/1607042/diff/1/2#newcode967 include/clang/AST/RecursiveASTVisitor.h:967: TRY_TO(TraverseType(D->getResultType())); On 2010/06/09 00:31:32, DougGregor wrote: > This doesn't seem to be necessary. The result type is part of the TypeSourceInfo > for the function declaration. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode1040 include/clang/AST/RecursiveASTVisitor.h:1040: // FIXME: do we need to recurse on getOriginalType()? On 2010/06/09 00:31:32, DougGregor wrote: > Recursing on the TypeSourceInfo is far better that recursing on > getOriginalType(), since the TypeSourceInfo describes the original type as > written. Adjusted the FIXME. http://codereview.appspot.com/1607042/diff/1/2#newcode1097 include/clang/AST/RecursiveASTVisitor.h:1097: On 2010/06/09 00:31:32, DougGregor wrote: > We'll end up visiting the exception object, which already has this type. That's > where S->getCaughtType() actually gets the type information from, so it's > redundant to visit here. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode1153 include/clang/AST/RecursiveASTVisitor.h:1153: } On 2010/06/09 00:31:32, DougGregor wrote: > Perhaps you want to create a TemplateArgumentLoc* traversal helper? There are > several loops like this. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode1182 include/clang/AST/RecursiveASTVisitor.h:1182: // FIXME: make a type callback for the cast? On 2010/06/09 00:31:32, DougGregor wrote: > IMO, no: the type wasn't written in the source so we shouldn't have a callback > for it. Done. http://codereview.appspot.com/1607042/diff/1/2#newcode1208 include/clang/AST/RecursiveASTVisitor.h:1208: On 2010/06/09 00:31:32, DougGregor wrote: > In all of these cases, I think the answer is "yes". We should recurse on the > TypeSourceInfo* for the type as is was written. Done. I'm traversing the QualType for now. We'll switch from QualType to TypeLoc everywhere later. http://codereview.appspot.com/1607042/diff/1/2#newcode1289 include/clang/AST/RecursiveASTVisitor.h:1289: // ExplicitCastExpr On 2010/06/09 00:31:32, DougGregor wrote: > Definitely worth traversing the TypeSourceInfo* here. Removed the comment as we are already doing it in the concrete subclasses of ExplicitCastExpr. http://codereview.appspot.com/1607042/diff/1/2#newcode1290 include/clang/AST/RecursiveASTVisitor.h:1290: // ImplicitCastExpr? On 2010/06/09 00:31:32, DougGregor wrote: > IMO, no. Removed the comment. http://codereview.appspot.com/1607042/diff/1/2#newcode1296 include/clang/AST/RecursiveASTVisitor.h:1296: On 2010/06/09 00:31:32, DougGregor wrote: > Yes. Note that we have an open enhancement request to implement proper > source-location information for nested-name-specifiers, but we could still walk > each of these NestedNameSpecifiers now. Fixed the comment.
Sign in to reply to this message.
|