Added support for user-defined structs. And fixed a bug in function return type.
Review URL: http://codereview.appspot.com/849042

git-svn-id: https://angleproject.googlecode.com/svn/trunk@88 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/Intermediate.cpp b/src/compiler/Intermediate.cpp
index c954b63..b0fcd1c 100644
--- a/src/compiler/Intermediate.cpp
+++ b/src/compiler/Intermediate.cpp
@@ -795,9 +795,9 @@
 		// Set array information.
 		//
 		case EOpAssign:
-		case EOpInitialize:
-			getType().setArraySize(left->getType().getArraySize());
-			getType().setArrayInformationType(left->getType().getArrayInformationType());
+                case EOpInitialize:
+                        getTypePointer()->setArraySize(left->getType().getArraySize());
+			getTypePointer()->setArrayInformationType(left->getType().getArrayInformationType());
 			break;
 
 		default:
diff --git a/src/compiler/OutputGLSL.cpp b/src/compiler/OutputGLSL.cpp
index 7831b62..4119459 100644
--- a/src/compiler/OutputGLSL.cpp
+++ b/src/compiler/OutputGLSL.cpp
@@ -56,6 +56,7 @@
 {
 }
 
+// Header declares user-defined structs.
 void TOutputGLSL::header()
 {
     TInfoSinkBase& out = objSink();
@@ -68,11 +69,25 @@
             continue;
 
         const TVariable* variable = static_cast<const TVariable*>(symbol);
-        const TString& name = variable->getName();
-        const TType& type = variable->getType();
-        TQualifier qualifier = type.getQualifier();
+        if (!variable->isUserType())
+            continue;
 
-        //symbol->dump(parseContext.infoSink);
+        const TType& type = variable->getType();
+        ASSERT(type.getQualifier() == EvqTemporary);
+        ASSERT(type.getBasicType() == EbtStruct);
+
+        out << "struct " << variable->getName() << "{\n";
+        const TTypeList* structure = type.getStruct();
+        ASSERT(structure != NULL);
+        incrementDepth();
+        for (size_t i = 0; i < structure->size(); ++i) {
+            const TType* fieldType = (*structure)[i].type;
+            ASSERT(fieldType != NULL);
+            out << getIndentationString(depth);
+            out << getTypeName(*fieldType) << " " << fieldType->getFieldName() << ";\n";
+        }
+        decrementDepth();
+        out << "};\n";
     }
 }
 
@@ -198,7 +213,7 @@
         case EOpEqual: UNIMPLEMENTED(); break;
         case EOpNotEqual: UNIMPLEMENTED(); break;
         case EOpLessThan: writeTriplet(visit, "(", " < ", ")"); break;
-        case EOpGreaterThan: writeTriplet(visit, NULL, " > ", NULL); break;
+        case EOpGreaterThan: writeTriplet(visit, "(", " > ", ")"); break;
         case EOpLessThanEqual: UNIMPLEMENTED(); break;
         case EOpGreaterThanEqual: UNIMPLEMENTED(); break;
 
@@ -338,7 +353,7 @@
         case EOpFunction:
             if (visit == PreVisit)
             {
-                TString returnType = node->getBasicString();
+                TString returnType = getTypeName(node->getType());
                 TString functionName = TFunction::unmangleName(node->getName());
                 out << returnType << " " << functionName;
             }
diff --git a/src/compiler/OutputHLSL.cpp b/src/compiler/OutputHLSL.cpp
index 601a386..5de6c3f 100644
--- a/src/compiler/OutputHLSL.cpp
+++ b/src/compiler/OutputHLSL.cpp
@@ -988,7 +988,7 @@
 {
     TInfoSinkBase &out = context.infoSink.obj;
     
-    TType &type = node->getType();
+    const TType &type = node->getType();
 
     if (type.isField())
     {
diff --git a/src/compiler/intermediate.h b/src/compiler/intermediate.h
index e73335e..22f2397 100644
--- a/src/compiler/intermediate.h
+++ b/src/compiler/intermediate.h
@@ -232,9 +232,9 @@
 	TIntermTyped(const TType& t) : type(t)  { }
 	virtual TIntermTyped* getAsTyped()         { return this; }
 	virtual void setType(const TType& t) { type = t; }
-	virtual TType getType() const { return type; }
+	virtual const TType& getType() const { return type; }
 	virtual TType* getTypePointer() { return &type; }
-	
+
 	virtual TBasicType getBasicType() const { return type.getBasicType(); }
 	virtual TQualifier getQualifier() const { return type.getQualifier(); }
 	virtual int getNominalSize() const { return type.getNominalSize(); }