HLSL: Add template style constructors for vector & matrix types
diff --git a/hlsl/hlslGrammar.cpp b/hlsl/hlslGrammar.cpp
index 417e4cb..d269f0b 100755
--- a/hlsl/hlslGrammar.cpp
+++ b/hlsl/hlslGrammar.cpp
@@ -1,5 +1,6 @@
 //
 //Copyright (C) 2016 Google, Inc.
+//Copyright (C) 2016 LunarG, Inc.
 //
 //All rights reserved.
 //
@@ -291,12 +292,176 @@
     } while (true);
 }
 
+// template_type
+//      : FLOAT
+//      | DOUBLE
+//      | INT
+//      | DWORD
+//      | UINT
+//      | BOOL
+//
+bool HlslGrammar::acceptTemplateType(TBasicType& basicType)
+{
+    switch (peek()) {
+    case EHTokFloat:
+        basicType = EbtFloat;
+        break;
+    case EHTokDouble:
+        basicType = EbtDouble;
+        break;
+    case EHTokInt:
+    case EHTokDword:
+        basicType = EbtInt;
+        break;
+    case EHTokUint:
+        basicType = EbtUint;
+        break;
+    case EHTokBool:
+        basicType = EbtBool;
+        break;
+    default:
+        return false;
+    }
+
+    advanceToken();
+
+    return true;
+}
+
+// vector_template_type
+//      : VECTOR
+//      | VECTOR LEFT_ANGLE template_type COMMA integer_literal RIGHT_ANGLE
+//
+bool HlslGrammar::acceptVectorTemplateType(TType& type)
+{
+    if (! acceptTokenClass(EHTokVector))
+        return false;
+
+    if (! acceptTokenClass(EHTokLeftAngle)) {
+        // in HLSL, 'vector' alone means float4.
+        new(&type) TType(EbtFloat, EvqTemporary, 4);
+        return true;
+    }
+
+    TBasicType basicType;
+    if (! acceptTemplateType(basicType)) {
+        expected("scalar type");
+        return false;
+    }
+
+    // COMMA
+    if (! acceptTokenClass(EHTokComma)) {
+        expected(",");
+        return false;
+    }
+
+    // integer
+    if (! peekTokenClass(EHTokIntConstant)) {
+        expected("literal integer");
+        return false;
+    }
+
+    TIntermTyped* vecSize;
+    if (! acceptLiteral(vecSize))
+        return false;
+
+    const int vecSizeI = vecSize->getAsConstantUnion()->getConstArray()[0].getIConst();
+
+    new(&type) TType(basicType, EvqTemporary, vecSizeI);
+
+    if (vecSizeI == 1)
+        type.makeVector();
+
+    if (!acceptTokenClass(EHTokRightAngle)) {
+        expected("right angle bracket");
+        return false;
+    }
+
+    return true;
+}
+
+// matrix_template_type
+//      : MATRIX
+//      | MATRIX LEFT_ANGLE template_type COMMA integer_literal COMMA integer_literal RIGHT_ANGLE
+//
+bool HlslGrammar::acceptMatrixTemplateType(TType& type)
+{
+    if (! acceptTokenClass(EHTokMatrix))
+        return false;
+
+    if (! acceptTokenClass(EHTokLeftAngle)) {
+        // in HLSL, 'matrix' alone means float4x4.
+        new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 4);
+        return true;
+    }
+
+    TBasicType basicType;
+    if (! acceptTemplateType(basicType)) {
+        expected("scalar type");
+        return false;
+    }
+
+    // COMMA
+    if (! acceptTokenClass(EHTokComma)) {
+        expected(",");
+        return false;
+    }
+
+    // integer rows
+    if (! peekTokenClass(EHTokIntConstant)) {
+        expected("literal integer");
+        return false;
+    }
+
+    TIntermTyped* rows;
+    if (! acceptLiteral(rows))
+        return false;
+
+    // COMMA
+    if (! acceptTokenClass(EHTokComma)) {
+        expected(",");
+        return false;
+    }
+    
+    // integer cols
+    if (! peekTokenClass(EHTokIntConstant)) {
+        expected("literal integer");
+        return false;
+    }
+
+    TIntermTyped* cols;
+    if (! acceptLiteral(cols))
+        return false;
+
+    new(&type) TType(basicType, EvqTemporary, 0,
+                     cols->getAsConstantUnion()->getConstArray()[0].getIConst(),
+                     rows->getAsConstantUnion()->getConstArray()[0].getIConst());
+
+    if (!acceptTokenClass(EHTokRightAngle)) {
+        expected("right angle bracket");
+        return false;
+    }
+
+    return true;
+}
+
+
 // If token is for a type, update 'type' with the type information,
 // and return true and advance.
 // Otherwise, return false, and don't advance
 bool HlslGrammar::acceptType(TType& type)
 {
+    TBasicType basicType;
+
     switch (peek()) {
+    case EHTokVector:
+        return acceptVectorTemplateType(type);
+        break;
+
+    case EHTokMatrix:
+        return acceptMatrixTemplateType(type);
+        break;
+
     case EHTokStruct:
         return acceptStruct(type);
         break;
@@ -386,6 +551,7 @@
         new(&type) TType(EbtUint, EvqTemporary, 4);
         break;
 
+
     case EHTokBool:
         new(&type) TType(EbtBool);
         break;