HLSL: Insert return statements into functions that are missing them.

It's allowed to not have all code paths return a value in ESSL but the HLSL
compiler detects this and generates an error.  Work around this by adding
dummy return statements at the end of each function that doesn't have one.

TEST=deqp/data/gles2/shaders/functions.html

BUG=angleproject:1015
BUG=478572

Change-Id: I2913f90f0994d4caf25cc43b16b9fc4e9efb19a5
Reviewed-on: https://chromium-review.googlesource.com/362085
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Commit-Queue: Geoff Lang <geofflang@chromium.org>
diff --git a/src/compiler/translator/util.cpp b/src/compiler/translator/util.cpp
index 84988ae..41276c6 100644
--- a/src/compiler/translator/util.cpp
+++ b/src/compiler/translator/util.cpp
@@ -330,6 +330,134 @@
     }
 }
 
+TOperator TypeToConstructorOperator(const TType &type)
+{
+    switch (type.getBasicType())
+    {
+        case EbtFloat:
+            if (type.isMatrix())
+            {
+                switch (type.getCols())
+                {
+                    case 2:
+                        switch (type.getRows())
+                        {
+                            case 2:
+                                return EOpConstructMat2;
+                            case 3:
+                                return EOpConstructMat2x3;
+                            case 4:
+                                return EOpConstructMat2x4;
+                            default:
+                                break;
+                        }
+                        break;
+
+                    case 3:
+                        switch (type.getRows())
+                        {
+                            case 2:
+                                return EOpConstructMat3x2;
+                            case 3:
+                                return EOpConstructMat3;
+                            case 4:
+                                return EOpConstructMat3x4;
+                            default:
+                                break;
+                        }
+                        break;
+
+                    case 4:
+                        switch (type.getRows())
+                        {
+                            case 2:
+                                return EOpConstructMat4x2;
+                            case 3:
+                                return EOpConstructMat4x3;
+                            case 4:
+                                return EOpConstructMat4;
+                            default:
+                                break;
+                        }
+                        break;
+                }
+            }
+            else
+            {
+                switch (type.getNominalSize())
+                {
+                    case 1:
+                        return EOpConstructFloat;
+                    case 2:
+                        return EOpConstructVec2;
+                    case 3:
+                        return EOpConstructVec3;
+                    case 4:
+                        return EOpConstructVec4;
+                    default:
+                        break;
+                }
+            }
+            break;
+
+        case EbtInt:
+            switch (type.getNominalSize())
+            {
+                case 1:
+                    return EOpConstructInt;
+                case 2:
+                    return EOpConstructIVec2;
+                case 3:
+                    return EOpConstructIVec3;
+                case 4:
+                    return EOpConstructIVec4;
+                default:
+                    break;
+            }
+            break;
+
+        case EbtUInt:
+            switch (type.getNominalSize())
+            {
+                case 1:
+                    return EOpConstructUInt;
+                case 2:
+                    return EOpConstructUVec2;
+                case 3:
+                    return EOpConstructUVec3;
+                case 4:
+                    return EOpConstructUVec4;
+                default:
+                    break;
+            }
+            break;
+
+        case EbtBool:
+            switch (type.getNominalSize())
+            {
+                case 1:
+                    return EOpConstructBool;
+                case 2:
+                    return EOpConstructBVec2;
+                case 3:
+                    return EOpConstructBVec3;
+                case 4:
+                    return EOpConstructBVec4;
+                default:
+                    break;
+            }
+            break;
+
+        case EbtStruct:
+            return EOpConstructStruct;
+
+        default:
+            break;
+    }
+
+    return EOpNull;
+}
+
 GetVariableTraverser::GetVariableTraverser(const TSymbolTable &symbolTable)
     : mSymbolTable(symbolTable)
 {