<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><head></head><div></div><div><br></div><br><div><div>Le 2010-08-26 à 15:57, Tom Care a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi Benoit,<br><br>You can find some coding style guidelines at <a href="http://llvm.org/docs/CodingStandards.html">http://llvm.org/docs/CodingStandards.html</a>.<br><br>We tend to cuddle brackets to the same line, and avoid putting spaces around a condition inside parentheses.<br><br>Tom<br><br>On Aug 26, 2010, at 12:24 PM, Benoit Belley wrote:<br><br><blockquote type="cite">Hi Everyone,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I have modified the RecursiveASTVisitor so that it can now optionally visit every template specialization (class and fucntion templates, implicit and explicit instantiations). <br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">By default this visitor will not recurse in template specializations since the instatiated class isn’t written in the source code anywhere. This behavior can now be changed by calling setVisitingTemplateSpecializations(true) before starting the traversal.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Please feel free to comment on the coding style also. I am new to Clang.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Thanks,<br></blockquote><blockquote type="cite">Benoit<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Index: include/clang/AST/RecursiveASTVisitor.h<br></blockquote><blockquote type="cite">===================================================================<br></blockquote><blockquote type="cite">--- include/clang/AST/RecursiveASTVisitor.h<span class="Apple-tab-span" style="white-space:pre">      </span>(revision 111934)<br></blockquote><blockquote type="cite">+++ include/clang/AST/RecursiveASTVisitor.h<span class="Apple-tab-span" style="white-space:pre">   </span>(working copy)<br></blockquote><blockquote type="cite">@@ -123,12 +123,35 @@<br></blockquote><blockquote type="cite">/// users may override Traverse* and WalkUpFrom* to implement custom<br></blockquote><blockquote type="cite">/// traversal strategies.  Returning false from one of these overridden<br></blockquote><blockquote type="cite">/// functions will abort the entire traversal.<br></blockquote><blockquote type="cite">+///<br></blockquote><blockquote type="cite">+/// By default this visitor will not recurse in template<br></blockquote><blockquote type="cite">+/// specializations ("set<int> x;") since the instatiated class isn't<br></blockquote><blockquote type="cite">+/// written in the source code anywhere. This behavior can be changed<br></blockquote><blockquote type="cite">+/// by calling setVisitingTemplateSpecializations(true) before<br></blockquote><blockquote type="cite">+/// starting the traversal.<br></blockquote><blockquote type="cite">template<typename Derived><br></blockquote><blockquote type="cite">class RecursiveASTVisitor {<br></blockquote><blockquote type="cite">public:<br></blockquote><blockquote type="cite">+  RecursiveASTVisitor() : visitingTemplateSpecializations(false) {}<br></blockquote><blockquote type="cite">+  <br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">  /// \brief Return a reference to the derived class.<br></blockquote><blockquote type="cite">  Derived &getDerived() { return *static_cast<Derived*>(this); }<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">+  /// \brief Control whether this visitor should recurse into<br></blockquote><blockquote type="cite">+  /// template specializations.<br></blockquote><blockquote type="cite">+  void setVisitingTemplateSpecializations(bool flag)<br></blockquote><blockquote type="cite">+  {<br></blockquote><blockquote type="cite">+    visitingTemplateSpecializations = flag;<br></blockquote><blockquote type="cite">+  }<br></blockquote><blockquote type="cite">+  <br></blockquote><blockquote type="cite">+  /// \brief Return whether this visitor should recurse into<br></blockquote><blockquote type="cite">+  /// template specializations.<br></blockquote><blockquote type="cite">+  bool isVisitingTemplateSpecializations() const<br></blockquote><blockquote type="cite">+  {<br></blockquote><blockquote type="cite">+    return visitingTemplateSpecializations;<br></blockquote><blockquote type="cite">+  }<br></blockquote><blockquote type="cite">+  <br></blockquote><blockquote type="cite">  /// \brief Recursively visit a statement or expression, by<br></blockquote><blockquote type="cite">  /// dispatching to Traverse*() based on the argument's dynamic type.<br></blockquote><blockquote type="cite">  ///<br></blockquote><blockquote type="cite">@@ -360,6 +383,10 @@<br></blockquote><blockquote type="cite">  bool TraverseDeclContextHelper(DeclContext *DC);<br></blockquote><blockquote type="cite">  bool TraverseFunctionHelper(FunctionDecl *D);<br></blockquote><blockquote type="cite">  bool TraverseVarHelper(VarDecl *D);<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+  // This flag indicates that the RecursiveASTVisitor should visit<br></blockquote><blockquote type="cite">+  // template specializations.<br></blockquote><blockquote type="cite">+  bool visitingTemplateSpecializations;<br></blockquote><blockquote type="cite">};<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">#define DISPATCH(NAME, CLASS, VAR) \<br></blockquote><blockquote type="cite">@@ -1095,16 +1122,58 @@<br></blockquote><blockquote type="cite">DEF_TRAVERSE_DECL(ClassTemplateDecl, {<br></blockquote><blockquote type="cite">    TRY_TO(TraverseDecl(D->getTemplatedDecl()));<br></blockquote><blockquote type="cite">    TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));<br></blockquote><blockquote type="cite">-    // We should not traverse the specializations/partial<br></blockquote><blockquote type="cite">-    // specializations.  Those will show up in other contexts.<br></blockquote><blockquote type="cite">-    // getInstantiatedFromMemberTemplate() is just a link from a<br></blockquote><blockquote type="cite">-    // template instantiation back to the template from which it was<br></blockquote><blockquote type="cite">-    // instantiated, and thus should not be traversed either.<br></blockquote><blockquote type="cite">+    // By default, we do not traverse the specializations/partial<br></blockquote><blockquote type="cite">+    // specializations. Implicitely instantiated templates do not<br></blockquote><blockquote type="cite">+    // apprear in the user code and explicitely instantiated templates<br></blockquote><blockquote type="cite">+    // show up in other contexts.<br></blockquote><blockquote type="cite">+    //<br></blockquote><blockquote type="cite">+    // Note that getInstantiatedFromMemberTemplate() is just a link<br></blockquote><blockquote type="cite">+    // from a template instantiation back to the template from which<br></blockquote><blockquote type="cite">+    // it was instantiated, and thus should not be traversed.<br></blockquote><blockquote type="cite">+    //<br></blockquote><blockquote type="cite">+    // FIXME: When visiting implicitely instantiated templates, the<br></blockquote><blockquote type="cite">+    // specialization of an explicit instantiation will be visited<br></blockquote><blockquote type="cite">+    // twice, once at the template function declaration and another<br></blockquote><blockquote type="cite">+    // time at the template instantiation site. Is this an issue ? If<br></blockquote><blockquote type="cite">+    // so, when should be visited.<br></blockquote><blockquote type="cite">+    if ( isVisitingTemplateSpecializations() ) {<br></blockquote><blockquote type="cite">+      {<br></blockquote><blockquote type="cite">+        ClassTemplateDecl::spec_iterator end = D->spec_end();<br></blockquote><blockquote type="cite">+        for (ClassTemplateDecl::spec_iterator it = D->spec_begin(); it != end; ++it) {<br></blockquote><blockquote type="cite">+          TRY_TO(TraverseClassTemplateSpecializationDecl(*it));<br></blockquote><blockquote type="cite">+        }<br></blockquote><blockquote type="cite">+      }<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+      {<br></blockquote><blockquote type="cite">+        ClassTemplateDecl::partial_spec_iterator end = D->partial_spec_end();<br></blockquote><blockquote type="cite">+        for (ClassTemplateDecl::partial_spec_iterator it = D->partial_spec_begin(); it != end; ++it) {<br></blockquote><blockquote type="cite">+          TRY_TO(TraverseClassTemplatePartialSpecializationDecl(*it));<br></blockquote><blockquote type="cite">+        }<br></blockquote><blockquote type="cite">+      }<br></blockquote><blockquote type="cite">+    }<br></blockquote><blockquote type="cite">  })<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">DEF_TRAVERSE_DECL(FunctionTemplateDecl, {<br></blockquote><blockquote type="cite">    TRY_TO(TraverseDecl(D->getTemplatedDecl()));<br></blockquote><blockquote type="cite">    TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+    // By default, we do not traverse the function<br></blockquote><blockquote type="cite">+    // specializations. Implicitely instantiated templates do not<br></blockquote><blockquote type="cite">+    // apprear in the user code and explicitely instantiated templates<br></blockquote><blockquote type="cite">+    // show up in other contexts.<br></blockquote><blockquote type="cite">+    //<br></blockquote><blockquote type="cite">+    // FIXME: When visiting implicitely instantiated templates, the<br></blockquote><blockquote type="cite">+    // specialization of an explicit instantiation will be visited<br></blockquote><blockquote type="cite">+    // twice, once at the template function declaration and another<br></blockquote><blockquote type="cite">+    // time at the template instantiation site. Is this an issue ? If<br></blockquote><blockquote type="cite">+    // so, when should be visited.<br></blockquote><blockquote type="cite">+    if ( isVisitingTemplateSpecializations() ) {<br></blockquote><blockquote type="cite">+      FunctionTemplateDecl::spec_iterator end = D->spec_end();<br></blockquote><blockquote type="cite">+      for (FunctionTemplateDecl::spec_iterator it = D->spec_begin(); it != end; ++it) {<br></blockquote><blockquote type="cite">+        TRY_TO(TraverseFunctionDecl(*it));<br></blockquote><blockquote type="cite">+      }<br></blockquote><blockquote type="cite">+    }<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">  })<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {<br></blockquote><blockquote type="cite">@@ -1192,18 +1261,22 @@<br></blockquote><blockquote type="cite">  })<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">DEF_TRAVERSE_DECL(ClassTemplateSpecializationDecl, {<br></blockquote><blockquote type="cite">-    // For implicit instantiations ("set<int> x;"), we don't want to<br></blockquote><blockquote type="cite">-    // recurse at all, since the instatiated class isn't written in<br></blockquote><blockquote type="cite">-    // the source code anywhere.  (Note the instatiated *type* --<br></blockquote><blockquote type="cite">-    // set<int> -- is written, and will still get a callback of<br></blockquote><blockquote type="cite">-    // TemplateSpecializationType).  For explicit instantiations<br></blockquote><blockquote type="cite">-    // ("template set<int>;"), we do need a callback, since this<br></blockquote><blockquote type="cite">-    // is the only callback that's made for this instantiation.<br></blockquote><blockquote type="cite">-    // We use getTypeAsWritten() to distinguish.<br></blockquote><blockquote type="cite">-    // FIXME: see how we want to handle template specializations.<br></blockquote><blockquote type="cite">-    if (TypeSourceInfo *TSI = D->getTypeAsWritten())<br></blockquote><blockquote type="cite">-      TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));<br></blockquote><blockquote type="cite">-    return true;<br></blockquote><blockquote type="cite">+    if ( isVisitingTemplateSpecializations() ) {<br></blockquote><blockquote type="cite">+      TRY_TO(TraverseCXXRecordHelper(D));<br></blockquote><blockquote type="cite">+    }<br></blockquote><blockquote type="cite">+    else {<br></blockquote><blockquote type="cite">+      // For implicit instantiations ("set<int> x;"), we don't want to<br></blockquote><blockquote type="cite">+      // recurse at all, since the instatiated class isn't written in<br></blockquote><blockquote type="cite">+      // the source code anywhere.  (Note the instatiated *type* --<br></blockquote><blockquote type="cite">+      // set<int> -- is written, and will still get a callback of<br></blockquote><blockquote type="cite">+      // TemplateSpecializationType).  For explicit instantiations<br></blockquote><blockquote type="cite">+      // ("template set<int>;"), we do need a callback, since this<br></blockquote><blockquote type="cite">+      // is the only callback that's made for this instantiation.<br></blockquote><blockquote type="cite">+      // We use getTypeAsWritten() to distinguish.<br></blockquote><blockquote type="cite">+      // FIXME: see how we want to handle template specializations.<br></blockquote><blockquote type="cite">+      if (TypeSourceInfo *TSI = D->getTypeAsWritten())<br></blockquote><blockquote type="cite">+        TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));<br></blockquote><blockquote type="cite">+    }<br></blockquote><blockquote type="cite">  })<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">template <typename Derived><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Thanks<br></blockquote><blockquote type="cite">Benoit <br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><RecursiveASTVisitor-TemplSpec.patch><ATT00001..txt><image002.gif><ATT00002..txt>_______________________________________________<br></blockquote><blockquote type="cite">cfe-commits mailing list<br></blockquote><blockquote type="cite"><a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br></blockquote><blockquote type="cite"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br></blockquote><br></div></blockquote></div><br><div apple-content-edited="true">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 11pt; font-family: Calibri, sans-serif; "><b><span style="font-family: Arial, sans-serif; "><o:p> </o:p></span></b></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 1.45pt; font-size: 11pt; font-family: Calibri, sans-serif; "><b><span style="font-family: Arial, sans-serif; "><o:p> </o:p></span></b></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 1.45pt; font-size: 11pt; font-family: Calibri, sans-serif; "><b><span style="font-family: Arial, sans-serif; ">Benoit Belley<o:p></o:p></span></b></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 1.45pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span style="font-size: 8pt; font-family: Arial, sans-serif; color: rgb(131, 131, 131); ">Sr Principal Developer<o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 1.45pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span style="font-size: 8pt; font-family: Arial, sans-serif; color: rgb(131, 131, 131); ">M&E-Product Development Group    <o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 1.45pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span style="font-size: 8pt; font-family: Arial, sans-serif; color: rgb(131, 131, 131); "><o:p> </o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 1.45pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span style="font-size: 8pt; font-family: Arial, sans-serif; color: rgb(131, 131, 131); ">Autodesk Canada Inc.<b> </b></span><span style="font-size: 8pt; font-family: Arial, sans-serif; color: rgb(131, 131, 131); "><br>10 Rue Duke<br>Montreal, Quebec  H3C 2L7 <br>Canada<o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 1.45pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span style="font-size: 8pt; font-family: Arial, sans-serif; color: rgb(131, 131, 131); "><o:p> </o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 1.45pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span style="font-size: 8pt; font-family: Arial, sans-serif; color: rgb(131, 131, 131); ">Direct 514 954-7154<o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 1.45pt; font-size: 11pt; font-family: Calibri, sans-serif; "><span style="font-size: 8pt; font-family: Arial, sans-serif; color: rgb(131, 131, 131); "><o:p> </o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 11pt; font-family: Calibri, sans-serif; "><span style="font-size: 8pt; font-family: Arial, sans-serif; color: rgb(131, 131, 131); "><o:p> </o:p></span></div><br class="Apple-interchange-newline"><span></span></div></div></div></body></html>