Commit 8073a951 by Olli Etuaho Committed by Commit Bot

Enable warning for non-virtual destructors

Virtual functions are removed from TSymbol, so the warning for non-virtual destructor found in a class with virtual functions can be enabled. BUG=angleproject:2417 TEST=angle_unittests Change-Id: Icd0ea2c77ce826739fbe954137f8ee78e6ef5386 Reviewed-on: https://chromium-review.googlesource.com/1051830 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 2fc0806f
...@@ -104,6 +104,7 @@ config("extra_warnings") { ...@@ -104,6 +104,7 @@ config("extra_warnings") {
# Remove when crbug.com/428099 is resolved. # Remove when crbug.com/428099 is resolved.
"-Winconsistent-missing-override", "-Winconsistent-missing-override",
"-Wunneeded-internal-declaration", "-Wunneeded-internal-declaration",
"-Wnon-virtual-dtor",
] ]
} }
} }
......
...@@ -33,11 +33,13 @@ static const char kFunctionMangledNameSeparator = '('; ...@@ -33,11 +33,13 @@ static const char kFunctionMangledNameSeparator = '(';
TSymbol::TSymbol(TSymbolTable *symbolTable, TSymbol::TSymbol(TSymbolTable *symbolTable,
const ImmutableString &name, const ImmutableString &name,
SymbolType symbolType, SymbolType symbolType,
SymbolClass symbolClass,
TExtension extension) TExtension extension)
: mName(name), : mName(name),
mUniqueId(symbolTable->nextUniqueId()), mUniqueId(symbolTable->nextUniqueId()),
mSymbolType(symbolType), mSymbolType(symbolType),
mExtension(extension) mExtension(extension),
mSymbolClass(symbolClass)
{ {
ASSERT(mSymbolType == SymbolType::BuiltIn || mExtension == TExtension::UNDEFINED); ASSERT(mSymbolType == SymbolType::BuiltIn || mExtension == TExtension::UNDEFINED);
ASSERT(mName != "" || mSymbolType == SymbolType::AngleInternal || ASSERT(mName != "" || mSymbolType == SymbolType::AngleInternal ||
...@@ -62,6 +64,12 @@ ImmutableString TSymbol::name() const ...@@ -62,6 +64,12 @@ ImmutableString TSymbol::name() const
ImmutableString TSymbol::getMangledName() const ImmutableString TSymbol::getMangledName() const
{ {
if (mSymbolClass == SymbolClass::Function)
{
// We do this instead of using proper virtual functions so that we can better support
// constexpr symbols.
return static_cast<const TFunction *>(this)->getFunctionMangledName();
}
ASSERT(mSymbolType != SymbolType::Empty); ASSERT(mSymbolType != SymbolType::Empty);
return name(); return name();
} }
...@@ -71,7 +79,9 @@ TVariable::TVariable(TSymbolTable *symbolTable, ...@@ -71,7 +79,9 @@ TVariable::TVariable(TSymbolTable *symbolTable,
const TType *type, const TType *type,
SymbolType symbolType, SymbolType symbolType,
TExtension extension) TExtension extension)
: TSymbol(symbolTable, name, symbolType, extension), mType(type), unionArray(nullptr) : TSymbol(symbolTable, name, symbolType, SymbolClass::Variable, extension),
mType(type),
unionArray(nullptr)
{ {
ASSERT(mType); ASSERT(mType);
} }
...@@ -80,7 +90,7 @@ TStructure::TStructure(TSymbolTable *symbolTable, ...@@ -80,7 +90,7 @@ TStructure::TStructure(TSymbolTable *symbolTable,
const ImmutableString &name, const ImmutableString &name,
const TFieldList *fields, const TFieldList *fields,
SymbolType symbolType) SymbolType symbolType)
: TSymbol(symbolTable, name, symbolType), TFieldListCollection(fields) : TSymbol(symbolTable, name, symbolType, SymbolClass::Struct), TFieldListCollection(fields)
{ {
} }
...@@ -88,7 +98,8 @@ TStructure::TStructure(const TSymbolUniqueId &id, ...@@ -88,7 +98,8 @@ TStructure::TStructure(const TSymbolUniqueId &id,
const ImmutableString &name, const ImmutableString &name,
TExtension extension, TExtension extension,
const TFieldList *fields) const TFieldList *fields)
: TSymbol(id, name, SymbolType::BuiltIn, extension), TFieldListCollection(fields) : TSymbol(id, name, SymbolType::BuiltIn, extension, SymbolClass::Struct),
TFieldListCollection(fields)
{ {
} }
...@@ -126,7 +137,7 @@ TInterfaceBlock::TInterfaceBlock(TSymbolTable *symbolTable, ...@@ -126,7 +137,7 @@ TInterfaceBlock::TInterfaceBlock(TSymbolTable *symbolTable,
const TLayoutQualifier &layoutQualifier, const TLayoutQualifier &layoutQualifier,
SymbolType symbolType, SymbolType symbolType,
TExtension extension) TExtension extension)
: TSymbol(symbolTable, name, symbolType, extension), : TSymbol(symbolTable, name, symbolType, SymbolClass::InterfaceBlock, extension),
TFieldListCollection(fields), TFieldListCollection(fields),
mBlockStorage(layoutQualifier.blockStorage), mBlockStorage(layoutQualifier.blockStorage),
mBinding(layoutQualifier.binding) mBinding(layoutQualifier.binding)
...@@ -138,7 +149,7 @@ TInterfaceBlock::TInterfaceBlock(const TSymbolUniqueId &id, ...@@ -138,7 +149,7 @@ TInterfaceBlock::TInterfaceBlock(const TSymbolUniqueId &id,
const ImmutableString &name, const ImmutableString &name,
TExtension extension, TExtension extension,
const TFieldList *fields) const TFieldList *fields)
: TSymbol(id, name, SymbolType::BuiltIn, extension), : TSymbol(id, name, SymbolType::BuiltIn, extension, SymbolClass::InterfaceBlock),
TFieldListCollection(fields), TFieldListCollection(fields),
mBlockStorage(EbsUnspecified), mBlockStorage(EbsUnspecified),
mBinding(0) mBinding(0)
...@@ -150,7 +161,7 @@ TFunction::TFunction(TSymbolTable *symbolTable, ...@@ -150,7 +161,7 @@ TFunction::TFunction(TSymbolTable *symbolTable,
SymbolType symbolType, SymbolType symbolType,
const TType *retType, const TType *retType,
bool knownToNotHaveSideEffects) bool knownToNotHaveSideEffects)
: TSymbol(symbolTable, name, symbolType, TExtension::UNDEFINED), : TSymbol(symbolTable, name, symbolType, SymbolClass::Function, TExtension::UNDEFINED),
mParametersVector(new TParamVector()), mParametersVector(new TParamVector()),
mParameters(nullptr), mParameters(nullptr),
mParamCount(0u), mParamCount(0u),
......
...@@ -28,6 +28,14 @@ enum class SymbolType ...@@ -28,6 +28,14 @@ enum class SymbolType
Empty // Meaning symbol without a name. Empty // Meaning symbol without a name.
}; };
enum class SymbolClass
{
Function,
Variable,
Struct,
InterfaceBlock
};
// Symbol base class. (Can build functions or variables out of these...) // Symbol base class. (Can build functions or variables out of these...)
class TSymbol : angle::NonCopyable class TSymbol : angle::NonCopyable
{ {
...@@ -36,9 +44,10 @@ class TSymbol : angle::NonCopyable ...@@ -36,9 +44,10 @@ class TSymbol : angle::NonCopyable
TSymbol(TSymbolTable *symbolTable, TSymbol(TSymbolTable *symbolTable,
const ImmutableString &name, const ImmutableString &name,
SymbolType symbolType, SymbolType symbolType,
SymbolClass symbolClass,
TExtension extension = TExtension::UNDEFINED); TExtension extension = TExtension::UNDEFINED);
// Note that we don't have a virtual destructor in order to support constexpr symbols. Data is // Note that we can't have a virtual destructor in order to support constexpr symbols. Data is
// either statically allocated or pool allocated. // either statically allocated or pool allocated.
~TSymbol() = default; ~TSymbol() = default;
...@@ -46,11 +55,11 @@ class TSymbol : angle::NonCopyable ...@@ -46,11 +55,11 @@ class TSymbol : angle::NonCopyable
// as for internal variables. // as for internal variables.
ImmutableString name() const; ImmutableString name() const;
// Don't call getMangledName() for empty symbols (symbolType == SymbolType::Empty). // Don't call getMangledName() for empty symbols (symbolType == SymbolType::Empty).
virtual ImmutableString getMangledName() const; ImmutableString getMangledName() const;
virtual bool isFunction() const { return false; } bool isFunction() const { return mSymbolClass == SymbolClass::Function; }
virtual bool isVariable() const { return false; } bool isVariable() const { return mSymbolClass == SymbolClass::Variable; }
virtual bool isStruct() const { return false; } bool isStruct() const { return mSymbolClass == SymbolClass::Struct; }
const TSymbolUniqueId &uniqueId() const { return mUniqueId; } const TSymbolUniqueId &uniqueId() const { return mUniqueId; }
SymbolType symbolType() const { return mSymbolType; } SymbolType symbolType() const { return mSymbolType; }
...@@ -60,8 +69,13 @@ class TSymbol : angle::NonCopyable ...@@ -60,8 +69,13 @@ class TSymbol : angle::NonCopyable
constexpr TSymbol(const TSymbolUniqueId &id, constexpr TSymbol(const TSymbolUniqueId &id,
const ImmutableString &name, const ImmutableString &name,
SymbolType symbolType, SymbolType symbolType,
TExtension extension) TExtension extension,
: mName(name), mUniqueId(id), mSymbolType(symbolType), mExtension(extension) SymbolClass symbolClass)
: mName(name),
mUniqueId(id),
mSymbolType(symbolType),
mExtension(extension),
mSymbolClass(symbolClass)
{ {
} }
...@@ -71,6 +85,10 @@ class TSymbol : angle::NonCopyable ...@@ -71,6 +85,10 @@ class TSymbol : angle::NonCopyable
const TSymbolUniqueId mUniqueId; const TSymbolUniqueId mUniqueId;
const SymbolType mSymbolType; const SymbolType mSymbolType;
const TExtension mExtension; const TExtension mExtension;
// We use this instead of having virtual functions for querying the class in order to support
// constexpr symbols.
const SymbolClass mSymbolClass;
}; };
// Variable. // Variable.
...@@ -84,7 +102,6 @@ class TVariable : public TSymbol ...@@ -84,7 +102,6 @@ class TVariable : public TSymbol
SymbolType symbolType, SymbolType symbolType,
TExtension ext = TExtension::UNDEFINED); TExtension ext = TExtension::UNDEFINED);
bool isVariable() const override { return true; }
const TType &getType() const { return *mType; } const TType &getType() const { return *mType; }
const TConstantUnion *getConstPointer() const { return unionArray; } const TConstantUnion *getConstPointer() const { return unionArray; }
...@@ -97,7 +114,9 @@ class TVariable : public TSymbol ...@@ -97,7 +114,9 @@ class TVariable : public TSymbol
SymbolType symbolType, SymbolType symbolType,
TExtension extension, TExtension extension,
const TType *type) const TType *type)
: TSymbol(id, name, symbolType, extension), mType(type), unionArray(nullptr) : TSymbol(id, name, symbolType, extension, SymbolClass::Variable),
mType(type),
unionArray(nullptr)
{ {
} }
...@@ -115,8 +134,6 @@ class TStructure : public TSymbol, public TFieldListCollection ...@@ -115,8 +134,6 @@ class TStructure : public TSymbol, public TFieldListCollection
const TFieldList *fields, const TFieldList *fields,
SymbolType symbolType); SymbolType symbolType);
bool isStruct() const override { return true; }
// The char arrays passed in must be pool allocated or static. // The char arrays passed in must be pool allocated or static.
void createSamplerSymbols(const char *namePrefix, void createSamplerSymbols(const char *namePrefix,
const TString &apiNamePrefix, const TString &apiNamePrefix,
...@@ -204,12 +221,10 @@ class TFunction : public TSymbol ...@@ -204,12 +221,10 @@ class TFunction : public TSymbol
const TType *retType, const TType *retType,
bool knownToNotHaveSideEffects); bool knownToNotHaveSideEffects);
bool isFunction() const override { return true; }
void addParameter(const TVariable *p); void addParameter(const TVariable *p);
void shareParameters(const TFunction &parametersSource); void shareParameters(const TFunction &parametersSource);
ImmutableString getMangledName() const override ImmutableString getFunctionMangledName() const
{ {
ASSERT(symbolType() != SymbolType::BuiltIn); ASSERT(symbolType() != SymbolType::BuiltIn);
if (mMangledName.empty()) if (mMangledName.empty())
...@@ -245,7 +260,7 @@ class TFunction : public TSymbol ...@@ -245,7 +260,7 @@ class TFunction : public TSymbol
const TType *retType, const TType *retType,
TOperator op, TOperator op,
bool knownToNotHaveSideEffects) bool knownToNotHaveSideEffects)
: TSymbol(id, name, SymbolType::BuiltIn, extension), : TSymbol(id, name, SymbolType::BuiltIn, extension, SymbolClass::Function),
mParametersVector(nullptr), mParametersVector(nullptr),
mParameters(parameters), mParameters(parameters),
mParamCount(paramCount), mParamCount(paramCount),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment