================
@@ -0,0 +1,140 @@
+//===---------- SubobjectVisitor.h - Subobject Visitor ----------*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines the SubobjectVisitor interface, which recursively
+//  traverses subobjects within a type.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_SUBOBJECTVISITOR_H
+#define LLVM_CLANG_AST_SUBOBJECTVISITOR_H
+
+#include "clang/AST/Type.h"
+
+namespace clang {
+template <typename Derived> class SubobjectVisitor {
+  ASTContext &Ctx;
+
+  public:
+  SubobjectVisitor(ASTContext &Ctx) : Ctx(Ctx) {}
+  /// Return a reference to the derived class.
+  Derived &getDerived() { return *static_cast<Derived *>(this); }
+
----------------
Fznamznon wrote:

Hi @tahonermann , thanks. I've updated the PR to reflect the changes. 

> If we later find that it would be useful to provide more specific visitors 
> for different kinds of records or types, then we can implement the fallback 
> approach used in CommentVisitor.h, DeclVisitor.h, StmtVisitor.h, and 
> TemplateArgumentVisitor.h; they provide specialized visitors (e.g., 
> VisitNullTemplateArgument()) that, if not implemented by the derived class, 
> fall back to a generic visitor (e.g., VisitTemplateArgument()). 

Well I had to do that already for the basic kernel argument checking visitor 
I'm adding in this PR. Otherwise I don't see how it would find a reference type 
for me. If you think I would need to move all this dispatching to the derived 
class, please let me know. I don't think that, for example, a visitor that will 
find special types and build a chain of member accesses for decomposition 
support will need to know how to visit a specific type.

Also, note that in DPC++ we added possibility to visit each element of the 
array for decomposition support, since we had to call `__init` for each element 
of the array of accessors (if it appears within kernel arguments). I suppose it 
might be needed here in the future as well.

> Most visitors allow the node pointer/reference type to be customized to 
> support non-const and const visitation. I think that is a useful feature to 
> provide.

This is slightly problematic. 1. I don't know an example where it would be 
useful. 2. I added visitation for different kinds of records or types and since 
visit interface accepts a `QualType`, I only could do `getTypePtr` to dispatch 
to different types and `getTypePtr` only returns `const Type*` . So there is no 
non-const visitation for all kinds of types which I find weird.

I also had to apply a few tweaks here because `getAsArrayType` only returns 
const qualified `ArrayType*` and `CXXRecordDecl::bases` returns an array of 
`CXXBaseQualifier` objects, not array of pointers.

Please let me know if this is moving in the right direction.

https://github.com/llvm/llvm-project/pull/192957
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to