xref: /aosp_15_r20/external/angle/src/compiler/translator/Name.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2020 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #ifndef COMPILER_TRANSLATOR_NAME_H_
8 #define COMPILER_TRANSLATOR_NAME_H_
9 
10 #include "compiler/translator/ImmutableString.h"
11 #include "compiler/translator/InfoSink.h"
12 #include "compiler/translator/IntermNode.h"
13 #include "compiler/translator/Symbol.h"
14 #include "compiler/translator/Types.h"
15 
16 namespace sh
17 {
18 
19 constexpr char kAngleInternalPrefix[] = "ANGLE";
20 
21 // Represents the name of a symbol.
22 class Name
23 {
24   public:
25     constexpr Name(const Name &) = default;
26 
Name()27     constexpr Name() : Name(kEmptyImmutableString, SymbolType::Empty) {}
28 
Name(ImmutableString rawName,SymbolType symbolType)29     constexpr Name(ImmutableString rawName, SymbolType symbolType)
30         : mRawName(rawName), mSymbolType(symbolType)
31     {
32         ASSERT(rawName.empty() == (symbolType == SymbolType::Empty));
33     }
34 
35     explicit constexpr Name(const char *rawName, SymbolType symbolType = SymbolType::AngleInternal)
Name(ImmutableString (rawName),symbolType)36         : Name(ImmutableString(rawName), symbolType)
37     {}
38 
Name(const std::string & rawName,SymbolType symbolType)39     Name(const std::string &rawName, SymbolType symbolType)
40         : Name(ImmutableString(rawName), symbolType)
41     {}
42 
43     explicit Name(const TField &field);
44     explicit Name(const TSymbol &symbol);
45 
46     Name &operator=(const Name &) = default;
47     bool operator==(const Name &other) const;
48     bool operator!=(const Name &other) const;
49     bool operator<(const Name &other) const;
50 
rawName()51     constexpr const ImmutableString &rawName() const { return mRawName; }
symbolType()52     constexpr SymbolType symbolType() const { return mSymbolType; }
53 
54     bool empty() const;
55     bool beginsWith(const Name &prefix) const;
56 
57     void emit(TInfoSinkBase &out) const;
58 
59   private:
60     ImmutableString mRawName;
61     SymbolType mSymbolType;
62     template <typename T>
63     void emitImpl(T &out) const;
64     friend std::ostream &operator<<(std::ostream &os, const sh::Name &name);
65 };
66 
67 constexpr Name kBaseInstanceName = Name("baseInstance");
68 
69 [[nodiscard]] bool ExpressionContainsName(const Name &name, TIntermTyped &node);
70 
71 }  // namespace sh
72 
73 #endif  // COMPILER_TRANSLATOR_MSL_NAME_H_
74