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_TRANSLATORMETALDIRECT_NAME_H_ 8 #define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_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 explicit 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 explicit 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 }; 63 64 ANGLE_NO_DISCARD bool ExpressionContainsName(const Name &name, TIntermTyped &node); 65 66 } // namespace sh 67 68 #endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_NAME_H_ 69