Skip to content

Commit

Permalink
kram - clang-format the projects
Browse files Browse the repository at this point in the history
  • Loading branch information
alecazam committed Oct 13, 2024
1 parent 4201401 commit 839aa51
Show file tree
Hide file tree
Showing 35 changed files with 6,078 additions and 7,001 deletions.
50 changes: 21 additions & 29 deletions hlslparser/src/CodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,65 @@
//
//=============================================================================

#include "Engine.h"

#include "CodeWriter.h"

#include <stdarg.h>

namespace M4
{
#include "Engine.h"

namespace M4 {
CodeWriter::CodeWriter()
{
m_currentLine = 1;
m_currentFileName = NULL;
m_spacesPerIndent = 4;
m_writeFileLine = false;
m_currentLine = 1;
m_currentFileName = NULL;
m_spacesPerIndent = 4;
m_writeFileLine = false;
}

void CodeWriter::BeginLine(int indent, const char* fileName, int lineNumber)
{
// probably missing an EndLine
ASSERT(m_currentIndent == 0);

if (m_writeFileLine)
{

if (m_writeFileLine) {
bool outputLine = false;
bool outputFile = false;

// Output a line number pragma if necessary.
if (fileName != NULL && m_currentFileName != fileName)
{
if (fileName != NULL && m_currentFileName != fileName) {
m_currentFileName = fileName;
fileName = m_currentFileName;
outputFile = true;
}
if (lineNumber != -1 && m_currentLine != lineNumber)
{
if (lineNumber != -1 && m_currentLine != lineNumber) {
m_currentLine = lineNumber;
outputLine = true;
}

// if previous filename is same, only output line
if (outputFile)
{
if (outputFile) {
String_Printf(m_buffer, "#line %d \"%s\"\n", lineNumber, fileName);
}
else if (outputLine)
{
else if (outputLine) {
String_Printf(m_buffer, "#line %d\n", lineNumber);
}
}

// Handle the indentation.
if (indent)
Write("%*s", indent * m_spacesPerIndent, "");

m_currentIndent = indent;

}

int CodeWriter::EndLine(const char* text)
{
if (text != NULL)
{
if (text != NULL) {
m_buffer += text;
}
m_buffer += "\n";
++m_currentLine;

// so can EndLine/BeginLine
int indent = m_currentIndent;
m_currentIndent = 0;
Expand All @@ -93,27 +85,27 @@ void CodeWriter::WriteLine(int indent, const char* format, ...)
{
if (indent)
Write("%*s", indent * m_spacesPerIndent, "");

va_list args;
va_start(args, format);
int result = String_PrintfArgList(m_buffer, format, args);
ASSERT(result != -1);
va_end(args);

EndLine();
}

void CodeWriter::WriteLineTagged(int indent, const char* fileName, int lineNumber, const char* format, ...)
{
// TODO: this should make sure that line isn't already Begu
BeginLine(indent, fileName, lineNumber);

va_list args;
va_start(args, format);
int result = String_PrintfArgList(m_buffer, format, args);
ASSERT(result != -1);
va_end(args);

EndLine();
}

Expand All @@ -127,4 +119,4 @@ void CodeWriter::Reset()
m_buffer.clear();
}

}
} //namespace M4
28 changes: 11 additions & 17 deletions hlslparser/src/CodeWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,37 @@
// stl
#include <string>

namespace M4
{
namespace M4 {

class Allocator;

/**
* This class is used for outputting code. It handles indentation and inserting #line markers
* to match the desired output line numbers.
*/
class CodeWriter
{

class CodeWriter {
public:
CodeWriter();

void SetWriteFileLine(bool enable) { m_writeFileLine = enable; }

void BeginLine(int indent, const char* fileName = NULL, int lineNumber = -1);
void Write(const char* format, ...) M4_PRINTF_ATTR(2, 3);
int EndLine(const char* text = NULL);

void WriteLine(int indent, const char* format, ...) M4_PRINTF_ATTR(3, 4);
void WriteLineTagged(int indent, const char* fileName, int lineNumber, const char* format, ...) M4_PRINTF_ATTR(5, 6) ;
void WriteLineTagged(int indent, const char* fileName, int lineNumber, const char* format, ...) M4_PRINTF_ATTR(5, 6);

const char* GetResult() const;
void Reset();

private:

std::string m_buffer;
int m_currentLine;
const char* m_currentFileName;
int m_spacesPerIndent;
int m_currentIndent;
bool m_writeFileLine;

std::string m_buffer;
int m_currentLine;
const char* m_currentFileName;
int m_spacesPerIndent;
int m_currentIndent;
bool m_writeFileLine;
};

}

} //namespace M4
Loading

0 comments on commit 839aa51

Please sign in to comment.