void HLSLGenerator::OutputStatements(int indent, HLSLStatement* statement) { while (statement != NULL) { if (statement->nodeType == HLSLNodeType_Declaration) { HLSLDeclaration* declaration = static_cast<HLSLDeclaration*>(statement); m_writer.BeginLine(indent, declaration->fileName, declaration->line); OutputDeclaration(declaration); m_writer.EndLine(";"); } else if (statement->nodeType == HLSLNodeType_Struct) { HLSLStruct* structure = static_cast<HLSLStruct*>(statement); m_writer.WriteLine(indent, "struct %s {", structure->name); HLSLStructField* field = structure->field; while (field != NULL) { m_writer.BeginLine(indent + 1, field->fileName, field->line); OutputDeclaration(field->type, field->name, field->semantic); m_writer.Write(";"); m_writer.EndLine(); field = field->nextField; } m_writer.WriteLine(indent, "};"); } else if (statement->nodeType == HLSLNodeType_Buffer) { HLSLBuffer* buffer = static_cast<HLSLBuffer*>(statement); HLSLBufferField* field = buffer->field; if (!m_legacy) { m_writer.BeginLine(indent, buffer->fileName, buffer->line); m_writer.Write("cbuffer %s", buffer->name); if (buffer->registerName != NULL) { m_writer.Write(" : register(%s)", buffer->registerName); } m_writer.EndLine(" {"); } while (field != NULL) { m_writer.BeginLine(indent + 1, field->fileName, field->line); OutputDeclaration(field->type, field->name); m_writer.Write(";"); m_writer.EndLine(); field = field->nextField; } if (!m_legacy) { m_writer.WriteLine(indent, "};"); } } else if (statement->nodeType == HLSLNodeType_Function) { HLSLFunction* function = static_cast<HLSLFunction*>(statement); // Use an alternate name for the function which is supposed to be entry point // so that we can supply our own function which will be the actual entry point. const char* functionName = function->name; const char* returnTypeName = GetTypeName(function->returnType); m_writer.BeginLine(indent, function->fileName, function->line); m_writer.Write("%s %s(", returnTypeName, functionName); OutputArguments(function->argument); if (function->semantic != NULL) { m_writer.Write(") : %s {", function->semantic); } else { m_writer.Write(") {"); } m_writer.EndLine(); OutputStatements(indent + 1, function->statement); m_writer.WriteLine(indent, "};"); } else if (statement->nodeType == HLSLNodeType_ExpressionStatement) { HLSLExpressionStatement* expressionStatement = static_cast<HLSLExpressionStatement*>(statement); m_writer.BeginLine(indent, statement->fileName, statement->line); OutputExpression(expressionStatement->expression); m_writer.EndLine(";"); } else if (statement->nodeType == HLSLNodeType_ReturnStatement) { HLSLReturnStatement* returnStatement = static_cast<HLSLReturnStatement*>(statement); if (returnStatement->expression != NULL) { m_writer.BeginLine(indent, returnStatement->fileName, returnStatement->line); m_writer.Write("return "); OutputExpression(returnStatement->expression); m_writer.EndLine(";"); } else { m_writer.WriteLine(indent, returnStatement->fileName, returnStatement->line, "return;"); } } else if (statement->nodeType == HLSLNodeType_DiscardStatement) { HLSLDiscardStatement* discardStatement = static_cast<HLSLDiscardStatement*>(statement); m_writer.WriteLine(indent, discardStatement->fileName, discardStatement->line, "discard;"); } else if (statement->nodeType == HLSLNodeType_BreakStatement) { HLSLBreakStatement* breakStatement = static_cast<HLSLBreakStatement*>(statement); m_writer.WriteLine(indent, breakStatement->fileName, breakStatement->line, "break;"); } else if (statement->nodeType == HLSLNodeType_ContinueStatement) { HLSLContinueStatement* continueStatement = static_cast<HLSLContinueStatement*>(statement); m_writer.WriteLine(indent, continueStatement->fileName, continueStatement->line, "continue;"); } else if (statement->nodeType == HLSLNodeType_IfStatement) { HLSLIfStatement* ifStatement = static_cast<HLSLIfStatement*>(statement); m_writer.BeginLine(indent, ifStatement->fileName, ifStatement->line); m_writer.Write("if ("); OutputExpression(ifStatement->condition); m_writer.Write(") {"); m_writer.EndLine(); OutputStatements(indent + 1, ifStatement->statement); m_writer.WriteLine(indent, "}"); if (ifStatement->elseStatement != NULL) { m_writer.WriteLine(indent, "else {"); OutputStatements(indent + 1, ifStatement->elseStatement); m_writer.WriteLine(indent, "}"); } } else if (statement->nodeType == HLSLNodeType_ForStatement) { HLSLForStatement* forStatement = static_cast<HLSLForStatement*>(statement); m_writer.BeginLine(indent, forStatement->fileName, forStatement->line); m_writer.Write("for ("); OutputDeclaration(forStatement->initialization); m_writer.Write("; "); OutputExpression(forStatement->condition); m_writer.Write("; "); OutputExpression(forStatement->increment); m_writer.Write(") {"); m_writer.EndLine(); OutputStatements(indent + 1, forStatement->statement); m_writer.WriteLine(indent, "}"); } else { // Unhanded statement type. ASSERT(0); } statement = statement->nextStatement; } }
//================================================================ // Name: OutputEvent // Class: DocFileOutput // // Description: This function is normally overriden by a subclass. // The subclass's OutputEvent will call this function // when its done with its own version. // // Parameters: Event *ev -- The event to output // // Returns: None // //================================================================ void DocFileOutput::OutputEvent(Event *ev) { OutputArguments(ev); eventCount++; }