Hash :
8e9dc1a6
Author :
Date :
2024-11-19T11:08:31
Validate anonymous struct names with namespace
Consider GLSL:
struct { vec4 e; } g;
struct sbbf { vec4 f; };
The struct name validation would fail if user chosen struct name would
clash with a symbol name that ANGLE internally gave to an anonymous
struct.
Fix by importing Name abstraction from MSL backend. A symbol name is
a pair (namespace, string).
Move operator<<(std::ostream &os, const ImmutableString &str)
to sh namespace because that is more natural for operator overloading
name resolution. MSVC works with this.
Bug: angleproject:379758201
Change-Id: Icc9b02aa8cb532e1d925e2fba4c45468f01b9144
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6035029
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Commit-Queue: Kimmo Kinnunen <kkinnunen@apple.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_TRANSLATOR_NAME_H_
#define COMPILER_TRANSLATOR_NAME_H_
#include "compiler/translator/ImmutableString.h"
#include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/Symbol.h"
#include "compiler/translator/Types.h"
namespace sh
{
constexpr char kAngleInternalPrefix[] = "ANGLE";
// Represents the name of a symbol.
class Name
{
public:
constexpr Name(const Name &) = default;
constexpr Name() : Name(kEmptyImmutableString, SymbolType::Empty) {}
constexpr Name(ImmutableString rawName, SymbolType symbolType)
: mRawName(rawName), mSymbolType(symbolType)
{
ASSERT(rawName.empty() == (symbolType == SymbolType::Empty));
}
explicit constexpr Name(const char *rawName, SymbolType symbolType = SymbolType::AngleInternal)
: Name(ImmutableString(rawName), symbolType)
{}
Name(const std::string &rawName, SymbolType symbolType)
: Name(ImmutableString(rawName), symbolType)
{}
explicit Name(const TField &field);
explicit Name(const TSymbol &symbol);
Name &operator=(const Name &) = default;
bool operator==(const Name &other) const;
bool operator!=(const Name &other) const;
bool operator<(const Name &other) const;
constexpr const ImmutableString &rawName() const { return mRawName; }
constexpr SymbolType symbolType() const { return mSymbolType; }
bool empty() const;
bool beginsWith(const Name &prefix) const;
void emit(TInfoSinkBase &out) const;
private:
ImmutableString mRawName;
SymbolType mSymbolType;
template <typename T>
void emitImpl(T &out) const;
friend std::ostream &operator<<(std::ostream &os, const sh::Name &name);
};
constexpr Name kBaseInstanceName = Name("baseInstance");
[[nodiscard]] bool ExpressionContainsName(const Name &name, TIntermTyped &node);
} // namespace sh
#endif // COMPILER_TRANSLATOR_MSL_NAME_H_