================
@@ -96,24 +96,119 @@ void addRootSignatureMD(llvm::dxbc::RootSignatureVersion
RootSigVer,
RootSignatureValMD->addOperand(MDVals);
}
+// Gived a MemberExpr of a resource or resource array type, find the parent
+// VarDecl of the struct or class instance that contains this resource and
+// build the full resource name based on the member access path.
+//
+// For example, for a member access like "myStructArray[0].memberA",
+// this function will find the VarDecl of "myStructArray" and use the
+// EmbeddedResourceNameBuilder to build the resource name
+// "myStructArray.0.memberA".
+static const VarDecl *findStructResourceParentDeclAndBuildName(
+ const MemberExpr *ME, EmbeddedResourceNameBuilder &NameBuilder) {
+
+ SmallVector<const Expr *> WorkList;
+ const VarDecl *VD = nullptr;
+ const Expr *E = ME;
+
+ for (;;) {
+ if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
+ assert(isa<VarDecl>(DRE->getDecl()) &&
+ "member expr base is not a var decl");
+ VD = cast<VarDecl>(DRE->getDecl());
+ NameBuilder.pushName(VD->getName());
+ break;
+ }
+
+ WorkList.push_back(E);
+ if (const auto *ME = dyn_cast<MemberExpr>(E))
+ E = ME->getBase();
+ else if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E))
+ E = ICE->getSubExpr();
+ else if (const auto *ASE = dyn_cast<ArraySubscriptExpr>(E))
+ E = ASE->getBase();
+ else if (isa<CXXThisExpr>(E))
+ // Resource member access on "this" pointer not yet implemented
+ // (llvm/llvm-project#190299)
+ return nullptr;
+ else
+ llvm_unreachable("unexpected expr type in resource member access");
+ }
+
+ while (!WorkList.empty()) {
+ E = WorkList.pop_back_val();
+ if (const auto *ME = dyn_cast<MemberExpr>(E)) {
+ NameBuilder.pushName(
+ ME->getMemberNameInfo().getName().getAsIdentifierInfo()->getName());
----------------
bob80905 wrote:
Maybe this case is handled elsewhere, or doesn't exist, but I wonder how this
would work for members that are implicit, with no actual source location.
Specifically, what `getAsIdentifierInfo()` would return.
https://github.com/llvm/llvm-project/pull/187127
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits