Commit dd037b2a by alokp@chromium.org

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
parent d25ab251
......@@ -795,9 +795,9 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
// 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:
......
......@@ -56,6 +56,7 @@ TOutputGLSL::TOutputGLSL(TParseContext &context)
{
}
// Header declares user-defined structs.
void TOutputGLSL::header()
{
TInfoSinkBase& out = objSink();
......@@ -68,11 +69,25 @@ void TOutputGLSL::header()
continue;
const TVariable* variable = static_cast<const TVariable*>(symbol);
const TString& name = variable->getName();
if (!variable->isUserType())
continue;
const TType& type = variable->getType();
TQualifier qualifier = type.getQualifier();
ASSERT(type.getQualifier() == EvqTemporary);
ASSERT(type.getBasicType() == EbtStruct);
//symbol->dump(parseContext.infoSink);
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 @@ bool TOutputGLSL::visitBinary(Visit visit, TIntermBinary* node)
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 @@ bool TOutputGLSL::visitAggregate(Visit visit, TIntermAggregate* node)
case EOpFunction:
if (visit == PreVisit)
{
TString returnType = node->getBasicString();
TString returnType = getTypeName(node->getType());
TString functionName = TFunction::unmangleName(node->getName());
out << returnType << " " << functionName;
}
......
......@@ -988,7 +988,7 @@ void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node)
{
TInfoSinkBase &out = context.infoSink.obj;
TType &type = node->getType();
const TType &type = node->getType();
if (type.isField())
{
......
......@@ -232,9 +232,9 @@ public:
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(); }
......
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