clang 23.0.0git
HLSLResource.cpp
Go to the documentation of this file.
1//===--- HLSLResource.cpp - Helper routines for HLSL resources -----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides shared routines to help analyze HLSL resources and
10// their bindings during Sema and CodeGen.
11//
12//===----------------------------------------------------------------------===//
13
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclCXX.h"
17#include "clang/AST/Type.h"
18
19using namespace clang;
20
21namespace clang {
22namespace hlsl {
23
25 pushName(N, FieldDelim);
26 Name.append(BaseClassDelim);
27}
28
29void EmbeddedResourceNameBuilder::pushName(llvm::StringRef N,
30 llvm::StringRef Delim) {
31 Offsets.push_back(Name.size());
32 if (!Name.empty() && !Name.ends_with(BaseClassDelim))
33 Name.append(Delim);
34 Name.append(N);
35}
36
38 llvm::raw_svector_ostream OS(Name);
39 Offsets.push_back(Name.size());
40 OS << ArrayIndexDelim;
41 OS << Index;
42}
43
45 CXXRecordDecl *DerivedRD, CXXRecordDecl *BaseRD) {
46 assert(BaseRD != DerivedRD && DerivedRD->isDerivedFrom(BaseRD));
47 Offsets.push_back(Name.size());
48 Name.append(FieldDelim);
49 while (BaseRD != DerivedRD) {
50 assert(DerivedRD->getNumBases() == 1 &&
51 "HLSL does not support multiple inheritance");
52 DerivedRD = DerivedRD->bases_begin()->getType()->getAsCXXRecordDecl();
53 assert(DerivedRD && "base class not found");
54 Name.append(DerivedRD->getName());
55 Name.append(BaseClassDelim);
56 }
57}
58
59} // namespace hlsl
60} // namespace clang
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
C Language Family Type Representation.
QualType getType() const
Retrieves the type of the base class.
Definition DeclCXX.h:249
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition DeclCXX.h:602
base_class_iterator bases_begin()
Definition DeclCXX.h:615
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
void pushBaseNameHierarchy(CXXRecordDecl *DerivedRD, CXXRecordDecl *BaseRD)
The JSON file list parser is used to communicate input to InstallAPI.