Add a constexpr constructor for TVariable

BUG=angleproject:2267
TEST=angle_unittests

Change-Id: I9b7e01801caa7235ac5e2d4212ea92e38c1f774d
Reviewed-on: https://chromium-review.googlesource.com/908752
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/common/angleutils.h b/src/common/angleutils.h
index db95173..829897c 100644
--- a/src/common/angleutils.h
+++ b/src/common/angleutils.h
@@ -30,7 +30,7 @@
 class NonCopyable
 {
   protected:
-    NonCopyable() = default;
+    constexpr NonCopyable() = default;
     ~NonCopyable() = default;
 
   private:
diff --git a/src/compiler/translator/ImmutableString.h b/src/compiler/translator/ImmutableString.h
index 2caef8d..e077377 100644
--- a/src/compiler/translator/ImmutableString.h
+++ b/src/compiler/translator/ImmutableString.h
@@ -54,7 +54,8 @@
     {
     }
 
-    ImmutableString(const ImmutableString &) = default;
+    constexpr ImmutableString(const ImmutableString &) = default;
+
     ImmutableString &operator=(const ImmutableString &) = default;
 
     constexpr const char *data() const { return mData ? mData : ""; }
diff --git a/src/compiler/translator/Symbol.cpp b/src/compiler/translator/Symbol.cpp
index 1332798..daaa33f 100644
--- a/src/compiler/translator/Symbol.cpp
+++ b/src/compiler/translator/Symbol.cpp
@@ -144,11 +144,6 @@
     ASSERT(name != nullptr || symbolType == SymbolType::AngleInternal || tOp != EOpNull);
 }
 
-TFunction::~TFunction()
-{
-    // Just here to discourage the compiler from inlining it.
-}
-
 void TFunction::clearParameters()
 {
     parameters.clear();
diff --git a/src/compiler/translator/Symbol.h b/src/compiler/translator/Symbol.h
index 3675d4f..0322cbe 100644
--- a/src/compiler/translator/Symbol.h
+++ b/src/compiler/translator/Symbol.h
@@ -38,10 +38,9 @@
             SymbolType symbolType,
             TExtension extension = TExtension::UNDEFINED);
 
-    virtual ~TSymbol()
-    {
-        // don't delete name, it's from the pool
-    }
+    // Note that we don't have a virtual destructor in order to support constexpr symbols. Data is
+    // either statically allocated or pool allocated.
+    ~TSymbol() = default;
 
     // Don't call name() or getMangledName() for empty symbols (symbolType == SymbolType::Empty).
     ImmutableString name() const;
@@ -56,6 +55,14 @@
     TExtension extension() const { return mExtension; }
 
   protected:
+    constexpr TSymbol(const TSymbolUniqueId &id,
+                      const ImmutableString &name,
+                      SymbolType symbolType,
+                      TExtension extension)
+        : mName(name), mUniqueId(id), mSymbolType(symbolType), mExtension(extension)
+    {
+    }
+
     const ImmutableString mName;
 
   private:
@@ -75,7 +82,6 @@
               SymbolType symbolType,
               TExtension ext = TExtension::UNDEFINED);
 
-    ~TVariable() override {}
     bool isVariable() const override { return true; }
     const TType &getType() const { return *mType; }
 
@@ -84,6 +90,15 @@
     void shareConstPointer(const TConstantUnion *constArray) { unionArray = constArray; }
 
   private:
+    constexpr TVariable(const TSymbolUniqueId &id,
+                        const ImmutableString &name,
+                        SymbolType symbolType,
+                        TExtension extension,
+                        const TType *type)
+        : TSymbol(id, name, symbolType, extension), mType(type), unionArray(nullptr)
+    {
+    }
+
     const TType *mType;
     const TConstantUnion *unionArray;
 };
@@ -190,8 +205,6 @@
               TOperator tOp        = EOpNull,
               TExtension extension = TExtension::UNDEFINED);
 
-    virtual ~TFunction();
-
     bool isFunction() const override { return true; }
 
     void addParameter(const TConstParameter &p)
diff --git a/src/compiler/translator/SymbolUniqueId.cpp b/src/compiler/translator/SymbolUniqueId.cpp
index e5dc15c..0812a87 100644
--- a/src/compiler/translator/SymbolUniqueId.cpp
+++ b/src/compiler/translator/SymbolUniqueId.cpp
@@ -20,7 +20,6 @@
 {
 }
 
-TSymbolUniqueId::TSymbolUniqueId(const TSymbolUniqueId &) = default;
 TSymbolUniqueId &TSymbolUniqueId::operator=(const TSymbolUniqueId &) = default;
 
 int TSymbolUniqueId::get() const
diff --git a/src/compiler/translator/SymbolUniqueId.h b/src/compiler/translator/SymbolUniqueId.h
index b00728c..a01f771 100644
--- a/src/compiler/translator/SymbolUniqueId.h
+++ b/src/compiler/translator/SymbolUniqueId.h
@@ -22,13 +22,15 @@
     POOL_ALLOCATOR_NEW_DELETE();
     explicit TSymbolUniqueId(TSymbolTable *symbolTable);
     explicit TSymbolUniqueId(const TSymbol &symbol);
-    TSymbolUniqueId(const TSymbolUniqueId &);
+    constexpr TSymbolUniqueId(const TSymbolUniqueId &) = default;
     TSymbolUniqueId &operator=(const TSymbolUniqueId &);
     bool operator==(const TSymbolUniqueId &) const;
 
     int get() const;
 
   private:
+    constexpr TSymbolUniqueId(int staticId) : mId(staticId) {}
+
     int mId;
 };