summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-12-12 08:57:48 -0500
committerGitHub <noreply@github.com>2018-12-12 08:57:48 -0500
commit49ed6b60d662906f290578f802f80b0ead1a2b9d (patch)
treee47050f6508a4b3a4d38b756e9b3c53e0d159507 /source/core
parent62d3e387774255be4d507cca045ac97dabac9970 (diff)
Running tests in slang-test process (#740)
* First pass at having an interface to write text to that can be replaced. Simplifed and made more rigerous the interface used to write formatted strings. * Added AppContext to simplify setting up and parsing around of streams. * Added more simplified way to get the std error/out from AppContext. * Work in progress using dll for tools to speed up testing. * First pass at ISlangWriter interface. * Added support for writing VaArgs. Added NullWriter. * Use ISlangWriter for output. * Use ISlangWriter for output - replacing OutputCallback. Make IRDump go to ISlangWriter * SlangWriterTargetType -> SlangWriterChannel Improvements around AppContext * Shared library working with slang-reflection-test. * Dll testing working for render-test. * Include va_list definintion from header. * Fix errors from clang. * Fix typo for linux. * Added -usexes option * Fix typo. * Fix arguments problem on linux. * Fix typo for linux. * Add windows tool shared library projects. * Fix warning from x86 win build. Fix signed warning from slang-test/main.cpp * First attempt at getting premake to work on travis, and run tests. * Try moving build out into script. * Invoke bash scripts so they don't have to be executable. * Drive configuration/tests from env parameters set by travis * Try using source to run travis tests. * Remove the build.linux directory - but doing so will overwrite Makefile. * Made -fno-delete-null-pointer-checks gcc only. * Try to fix warning from -fno-delete-null-pointer-checks * Turn of warnings for unknown switches. * Try to make premake choose the correct tooling. * Disabled missing braces warning. * Disable -Wundefined-var-template on clang. * -Wunused-function disabled for clang. * Fix typo due to SlangBool. * Remove this nullptr tests. * "-Wno-unused-private-field" for clang. * Added "-Wno-undefined-bool-conversion" * Add DominatorList::end fix. * Split scripts into travis_build.sh travis_test.sh * Fix gcc/clang template pre-declaration issue around QualType. * Fix premake to build such that pthread correctly links with slang-glslang
Diffstat (limited to 'source/core')
-rw-r--r--source/core/core.vcxproj4
-rw-r--r--source/core/core.vcxproj.filters12
-rw-r--r--source/core/slang-app-context.cpp67
-rw-r--r--source/core/slang-app-context.h60
-rw-r--r--source/core/slang-string-util.cpp39
-rw-r--r--source/core/slang-string-util.h9
-rw-r--r--source/core/slang-string.cpp24
-rw-r--r--source/core/slang-string.h8
-rw-r--r--source/core/slang-writer.cpp152
-rw-r--r--source/core/slang-writer.h145
10 files changed, 502 insertions, 18 deletions
diff --git a/source/core/core.vcxproj b/source/core/core.vcxproj
index 97dc19d66..5dad716fb 100644
--- a/source/core/core.vcxproj
+++ b/source/core/core.vcxproj
@@ -182,6 +182,7 @@
<ClInclude Include="list.h" />
<ClInclude Include="platform.h" />
<ClInclude Include="secure-crt.h" />
+ <ClInclude Include="slang-app-context.h" />
<ClInclude Include="slang-byte-encode-util.h" />
<ClInclude Include="slang-cpu-defines.h" />
<ClInclude Include="slang-free-list.h" />
@@ -194,6 +195,7 @@
<ClInclude Include="slang-string-slice-pool.h" />
<ClInclude Include="slang-string-util.h" />
<ClInclude Include="slang-string.h" />
+ <ClInclude Include="slang-writer.h" />
<ClInclude Include="smart-pointer.h" />
<ClInclude Include="stream.h" />
<ClInclude Include="text-io.h" />
@@ -202,6 +204,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="platform.cpp" />
+ <ClCompile Include="slang-app-context.cpp" />
<ClCompile Include="slang-byte-encode-util.cpp" />
<ClCompile Include="slang-free-list.cpp" />
<ClCompile Include="slang-io.cpp" />
@@ -212,6 +215,7 @@
<ClCompile Include="slang-string-slice-pool.cpp" />
<ClCompile Include="slang-string-util.cpp" />
<ClCompile Include="slang-string.cpp" />
+ <ClCompile Include="slang-writer.cpp" />
<ClCompile Include="stream.cpp" />
<ClCompile Include="text-io.cpp" />
<ClCompile Include="token-reader.cpp" />
diff --git a/source/core/core.vcxproj.filters b/source/core/core.vcxproj.filters
index b470f9b43..c5c1fc733 100644
--- a/source/core/core.vcxproj.filters
+++ b/source/core/core.vcxproj.filters
@@ -45,6 +45,9 @@
<ClInclude Include="secure-crt.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="slang-app-context.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="slang-byte-encode-util.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -81,6 +84,9 @@
<ClInclude Include="slang-string.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="slang-writer.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="smart-pointer.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -101,6 +107,9 @@
<ClCompile Include="platform.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="slang-app-context.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="slang-byte-encode-util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -131,6 +140,9 @@
<ClCompile Include="slang-string.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="slang-writer.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="stream.cpp">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/source/core/slang-app-context.cpp b/source/core/slang-app-context.cpp
new file mode 100644
index 000000000..2b3f32cbc
--- /dev/null
+++ b/source/core/slang-app-context.cpp
@@ -0,0 +1,67 @@
+
+#include "slang-app-context.h"
+
+#include "slang-writer.h"
+
+namespace Slang
+{
+
+/* static */AppContext* AppContext::s_singleton = nullptr;
+
+
+/* static */AppContext* AppContext::getDefault()
+{
+ static AppContext* s_context = nullptr;
+
+ if (!s_context)
+ {
+ static FileWriter s_stdError(stderr, WriterFlag::IsStatic | WriterFlag::IsUnowned | WriterFlag::AutoFlush);
+ static FileWriter s_stdOut(stdout, WriterFlag::IsStatic | WriterFlag::IsUnowned | WriterFlag::AutoFlush);
+
+ static AppContext s_contextVar;
+ s_context = &s_contextVar;
+
+ s_context->setWriter(SLANG_WRITER_CHANNEL_STD_ERROR, &s_stdError);
+ s_context->setWriter(SLANG_WRITER_CHANNEL_STD_OUTPUT, &s_stdOut);
+ }
+ return s_context;
+}
+
+/* static */AppContext* AppContext::initDefault()
+{
+ AppContext* context = getDefault();
+ setSingleton(context);
+ return context;
+}
+
+/* static */int AppContext::getReturnCode(SlangResult res)
+{
+ if (SLANG_SUCCEEDED(res))
+ {
+ return 0;
+ }
+ else if (res == SLANG_E_INTERNAL_FAIL)
+ {
+ return -1;
+ }
+ return 1;
+}
+
+void AppContext::setRequestWriters(SlangCompileRequest* request)
+{
+ for (int i = 0; i < SLANG_WRITER_CHANNEL_COUNT_OF; ++i)
+ {
+ if (m_replaceWriterFlags & (1 << i))
+ {
+ spSetWriter(request, SlangWriterChannel(i), m_writers[i]);
+ }
+ }
+}
+
+void AppContext::configureRequest(SlangCompileRequest* request)
+{
+ setRequestWriters(request);
+}
+
+}
+
diff --git a/source/core/slang-app-context.h b/source/core/slang-app-context.h
new file mode 100644
index 000000000..9f1eb306c
--- /dev/null
+++ b/source/core/slang-app-context.h
@@ -0,0 +1,60 @@
+#ifndef SLANG_APP_CONTEXT_H
+#define SLANG_APP_CONTEXT_H
+
+#include "slang-writer.h"
+#include "../../slang-com-ptr.h"
+
+namespace Slang
+{
+
+#ifdef SLANG_SHARED_LIBRARY_TOOL
+# define SLANG_SHARED_LIBRARY_TOOL_API SLANG_EXTERN_C SLANG_DLL_EXPORT
+#else
+# define SLANG_SHARED_LIBRARY_TOOL_API
+#endif
+
+/* A structure to hold general state shared across an application */
+class AppContext
+{
+public:
+
+ ISlangWriter * getWriter(SlangWriterChannel chan) const { return m_writers[chan]; }
+ void setWriter(SlangWriterChannel chan, ISlangWriter* writer) { m_writers[chan] = writer; }
+
+ /// Make modifications to the request
+ void configureRequest(SlangCompileRequest* request);
+
+ void setRequestWriters(SlangCompileRequest* request);
+
+ void setReplaceWriterFlagsAll() { setReplaceWriterFlags((1 << SLANG_WRITER_CHANNEL_COUNT_OF) - 1); }
+ void setReplaceWriterFlags(int flags) { m_replaceWriterFlags = flags; }
+ int getReplaceWriterFlags() const { return m_replaceWriterFlags; }
+
+ /// Ctor
+ AppContext() : m_replaceWriterFlags(0) {}
+
+ /// Initialize a default context
+ static AppContext* initDefault();
+
+ static AppContext* getDefault();
+
+ static AppContext* getSingleton() { return s_singleton; }
+ static void setSingleton(AppContext* context) { s_singleton = context; }
+
+ static WriterHelper getStdError() { return getSingleton()->getWriter(SLANG_WRITER_CHANNEL_STD_ERROR); }
+ static WriterHelper getStdOut() { return getSingleton()->getWriter(SLANG_WRITER_CHANNEL_STD_OUTPUT); }
+ static WriterHelper getDiagnostic() { return getSingleton()->getWriter(SLANG_WRITER_CHANNEL_DIAGNOSTIC); }
+
+ static int getReturnCode(SlangResult res);
+
+protected:
+
+ ComPtr<ISlangWriter> m_writers[SLANG_WRITER_CHANNEL_COUNT_OF];
+ int m_replaceWriterFlags; ///< Bit for each writer
+
+ static AppContext* s_singleton;
+};
+
+}
+
+#endif
diff --git a/source/core/slang-string-util.cpp b/source/core/slang-string-util.cpp
index 6d0d896a1..cb5709759 100644
--- a/source/core/slang-string-util.cpp
+++ b/source/core/slang-string-util.cpp
@@ -39,32 +39,39 @@ static const Guid IID_ISlangBlob = SLANG_UUID_ISlangBlob;
}
}
-
-/* static */void StringUtil::append(const char* format, va_list args, StringBuilder& buf)
+/* static */size_t StringUtil::calcFormattedSize(const char* format, va_list args)
{
- int numChars = 0;
+#if SLANG_WINDOWS_FAMILY
+ return _vscprintf(format, args);
+#else
+ return vsnprintf(nullptr, 0, format, args);
+#endif
+}
+/* static */void StringUtil::calcFormatted(const char* format, va_list args, size_t numChars, char* dst)
+{
#if SLANG_WINDOWS_FAMILY
- numChars = _vscprintf(format, args);
+ vsnprintf_s(dst, numChars + 1, _TRUNCATE, format, args);
#else
+ vsnprintf(dst, numChars + 1, format, args);
+#endif
+}
+
+/* static */void StringUtil::append(const char* format, va_list args, StringBuilder& buf)
+{
+ // Calculate the size
+ size_t numChars;
{
+ // Create a copy of args, as will be consumed by calcFormattedSize
va_list argsCopy;
va_copy(argsCopy, args);
- numChars = vsnprintf(nullptr, 0, format, argsCopy);
+ numChars = calcFormattedSize(format, argsCopy);
va_end(argsCopy);
}
-#endif
-
- List<char> chars;
- chars.SetSize(numChars + 1);
-
-#if SLANG_WINDOWS_FAMILY
- vsnprintf_s(chars.Buffer(), numChars + 1, _TRUNCATE, format, args);
-#else
- vsnprintf(chars.Buffer(), numChars + 1, format, args);
-#endif
- buf.Append(chars.Buffer(), numChars);
+ char* dst = buf.prepareForAppend(numChars + 1);
+ calcFormatted(format, args, numChars, dst);
+ buf.appendInPlace(dst, numChars);
}
/* static */void StringUtil::appendFormat(StringBuilder& buf, const char* format, ...)
diff --git a/source/core/slang-string-util.h b/source/core/slang-string-util.h
index b365b6cf5..0579dd057 100644
--- a/source/core/slang-string-util.h
+++ b/source/core/slang-string-util.h
@@ -41,6 +41,15 @@ struct StringUtil
/// Slices contents will directly address into in, so contents will only stay valid as long as in does.
static void split(const UnownedStringSlice& in, char splitChar, List<UnownedStringSlice>& slicesOut);
+ /// Returns the size in bytes needed to hold the formatted string using the specified args, NOT including a terminating 0
+ /// NOTE! The caller *should* assume this will consume the va_list (use va_copy to make a copy to be consumed)
+ static size_t calcFormattedSize(const char* format, va_list args);
+
+ /// Calculate the formatted string using the specified args.
+ /// NOTE! The caller *should* assume this will consume the va_list
+ /// The buffer should be at least calcFormattedSize + 1 bytes. The +1 is needed because a terminating 0 is written.
+ static void calcFormatted(const char* format, va_list args, size_t numChars, char* dst);
+
/// Appends formatted string with args into buf
static void append(const char* format, va_list args, StringBuilder& buf);
diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp
index b195e12d5..648249b2c 100644
--- a/source/core/slang-string.cpp
+++ b/source/core/slang-string.cpp
@@ -253,7 +253,31 @@ namespace Slang
ensureUniqueStorageWithCapacity(newLength);
return getData() + oldLength;
}
+ void String::appendInPlace(const char* chars, UInt count)
+ {
+ SLANG_UNUSED(chars);
+
+ if (count > 0)
+ {
+ SLANG_ASSERT(buffer && buffer->isUniquelyReferenced());
+
+ auto oldLength = getLength();
+ auto newLength = oldLength + count;
+
+ char* dst = buffer->getData();
+ // Make sure the input buffer is the same one returned from prepareForAppend
+ SLANG_ASSERT(chars == dst + oldLength);
+ // It has to fit within the capacity
+ SLANG_ASSERT(newLength <= buffer->capacity);
+
+ // We just need to modify the length
+ buffer->length = newLength;
+
+ // And mark with a terminating 0
+ dst[newLength] = 0;
+ }
+ }
void String::append(const char* textBegin, char const* textEnd)
{
diff --git a/source/core/slang-string.h b/source/core/slang-string.h
index fb60ef562..435e2b29b 100644
--- a/source/core/slang-string.h
+++ b/source/core/slang-string.h
@@ -329,8 +329,7 @@ namespace Slang
}
void ensureUniqueStorageWithCapacity(UInt capacity);
- char* prepareForAppend(UInt count);
-
+
RefPtr<StringRepresentation> buffer;
public:
@@ -347,6 +346,11 @@ namespace Slang
{
}
+ /// Returns a buffer which can hold at least count chars
+ char* prepareForAppend(UInt count);
+ /// Append data written to buffer output via 'prepareForAppend' directly written 'inplace'
+ void appendInPlace(const char* chars, UInt count);
+
SLANG_FORCE_INLINE StringRepresentation* getStringRepresentation() const { return buffer; }
const char * begin() const
diff --git a/source/core/slang-writer.cpp b/source/core/slang-writer.cpp
new file mode 100644
index 000000000..4c5df0c8a
--- /dev/null
+++ b/source/core/slang-writer.cpp
@@ -0,0 +1,152 @@
+#include "slang-writer.h"
+
+#include "platform.h"
+#include "slang-string-util.h"
+
+// Includes to allow us to control console
+// output when writing assembly dumps.
+#include <fcntl.h>
+#ifdef _WIN32
+# include <io.h>
+#else
+# include <unistd.h>
+#endif
+
+#include <stdarg.h>
+
+namespace Slang
+{
+static const Guid IID_ISlangWriter = SLANG_UUID_ISlangWriter;
+static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown;
+
+/* !!!!!!!!!!!!!!!!!!!!!!!!! WriterHelper !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+
+SlangResult WriterHelper::print(const char* format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ SlangResult res = m_writer->writeVaList(format, args);
+
+ if (res == SLANG_E_NOT_IMPLEMENTED)
+ {
+ StringBuilder builder;
+ StringUtil::append(format, args, builder);
+
+ // Write if there is anything to write
+ res = (builder.Length()) ? m_writer->write(builder.Buffer(), builder.Length()) : SLANG_OK;
+ }
+
+ va_end(args);
+ return res;
+}
+
+SlangResult WriterHelper::put(const char* text)
+{
+ return m_writer->write(text, ::strlen(text));
+}
+
+/* !!!!!!!!!!!!!!!!!!!!!!!!! BaseWriter !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+
+ISlangUnknown* BaseWriter::getInterface(const Guid& guid)
+{
+ return (guid == IID_ISlangUnknown || guid == IID_ISlangWriter) ? static_cast<ISlangWriter*>(this) : nullptr;
+}
+
+/* !!!!!!!!!!!!!!!!!!!!!!!!! CallbackWriter !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+
+SlangResult CallbackWriter::write(const char* chars, size_t numChars)
+{
+ if (numChars > 0)
+ {
+ // Make sure zero terminated
+ StringBuilder builder;
+ builder.Append(chars, numChars);
+
+ m_callback(builder.Buffer(), (void*)m_data);
+ }
+
+ return SLANG_OK;
+}
+
+/* !!!!!!!!!!!!!!!!!!!!!!!!! FileWriter !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+
+FileWriter::~FileWriter()
+{
+ if ((m_flags & WriterFlag::IsUnowned) == 0)
+ {
+ fclose(m_file);
+ }
+}
+
+SlangResult FileWriter::writeVaList(const char* format, va_list args)
+{
+ // http://www.cplusplus.com/reference/cstdio/vfprintf/
+ ::vfprintf(m_file, format, args);
+
+ if (m_flags & WriterFlag::AutoFlush)
+ {
+ ::fflush(m_file);
+ }
+
+ return SLANG_OK;
+}
+
+SlangResult FileWriter::write(const char* text, size_t numChars)
+{
+ const size_t numWritten = ::fwrite(text, sizeof(char), numChars, m_file);
+ if (m_flags & WriterFlag::AutoFlush)
+ {
+ ::fflush(m_file);
+ }
+ return numChars == numWritten ? SLANG_OK : SLANG_FAIL;
+}
+
+void FileWriter::flush()
+{
+ ::fflush(m_file);
+}
+
+/* static */bool FileWriter::isConsole(FILE* file)
+{
+ const int stdoutFileDesc = _fileno(file);
+ return _isatty(stdoutFileDesc) != 0;
+}
+
+SlangResult FileWriter::setMode(SlangWriterMode mode)
+{
+ switch (mode)
+ {
+ case SLANG_WRITER_MODE_BINARY:
+ {
+#ifdef _WIN32
+ int stdoutFileDesc = _fileno(m_file);
+ _setmode(stdoutFileDesc, _O_BINARY);
+ return SLANG_OK;
+#else
+ break;
+#endif
+ }
+ default: break;
+ }
+ return SLANG_FAIL;
+}
+
+/* !!!!!!!!!!!!!!!!!!!!!!!!! StringWriter !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+
+SlangResult StringWriter::writeVaList(const char* format, va_list args)
+{
+ StringUtil::append(format, args, *m_builder);
+ return SLANG_OK;
+}
+
+SlangResult StringWriter::write(const char* chars, size_t numChars)
+{
+ if (numChars > 0)
+ {
+ m_builder->Append(chars, numChars);
+ }
+ return SLANG_OK;
+}
+
+}
+
diff --git a/source/core/slang-writer.h b/source/core/slang-writer.h
new file mode 100644
index 000000000..0fa336d6e
--- /dev/null
+++ b/source/core/slang-writer.h
@@ -0,0 +1,145 @@
+#ifndef SLANG_WRITER_H
+#define SLANG_WRITER_H
+
+#include "slang-string.h"
+
+#include "../../slang-com-helper.h"
+
+namespace Slang
+{
+
+
+class WriterHelper
+{
+public:
+ SlangResult print(const char* format, ...);
+ SlangResult put(const char* text);
+
+ SLANG_FORCE_INLINE void flush() { m_writer->flush(); }
+
+ ISlangWriter* getWriter() const { return m_writer; }
+
+ WriterHelper(ISlangWriter* writer) :m_writer(writer) {}
+
+protected:
+ ISlangWriter* m_writer;
+};
+
+struct WriterFlag
+{
+ enum Enum :uint32_t
+ {
+ IsStatic = 0x1, ///< Means non ref counted
+ IsConsole = 0x2, ///< True if console
+ IsUnowned = 0x4, ///< True if doesn't own contained type
+ AutoFlush = 0x8, ///< Automatically flushes after every call
+ };
+private:
+ WriterFlag() = delete;
+};
+typedef uint32_t WriterFlags;
+
+class BaseWriter : public ISlangWriter, public RefObject
+{
+public:
+ // ISlangUnknown
+ SLANG_REF_OBJECT_IUNKNOWN_QUERY_INTERFACE
+ SLANG_REF_OBJECT_IUNKNOWN_ADD_REF
+ SLANG_NO_THROW uint32_t SLANG_MCALL release() { return (m_flags & WriterFlag::IsStatic) ? 1 : (uint32_t)releaseReference(); }
+
+ // ISlangWriter - default impl
+ SLANG_NO_THROW virtual SlangResult SLANG_MCALL writeVaList(const char* format, va_list args) { SLANG_UNUSED(args); SLANG_UNUSED(format); return SLANG_E_NOT_IMPLEMENTED; }
+ SLANG_NO_THROW virtual void SLANG_MCALL flush() SLANG_OVERRIDE {}
+ SLANG_NO_THROW virtual bool SLANG_MCALL isConsole() SLANG_OVERRIDE { return (m_flags & WriterFlag::IsConsole) != 0; }
+ SLANG_NO_THROW virtual SlangResult SLANG_MCALL setMode(SlangWriterMode mode) SLANG_OVERRIDE { SLANG_UNUSED(mode); return SLANG_FAIL; }
+
+ BaseWriter(WriterFlags flags) :
+ m_flags(flags)
+ {
+ }
+
+protected:
+ ISlangUnknown * getInterface(const Guid& guid);
+ WriterFlags m_flags;
+};
+
+class CallbackWriter : public BaseWriter
+{
+public:
+ typedef BaseWriter Parent;
+ // ISlangWriter
+ SLANG_NO_THROW virtual SlangResult SLANG_MCALL write(const char* chars, size_t numChars) SLANG_OVERRIDE;
+
+ CallbackWriter(SlangDiagnosticCallback callback, const void* data, WriterFlags flags) :
+ Parent(flags),
+ m_callback(callback),
+ m_data(data)
+ {}
+
+protected:
+
+ SlangDiagnosticCallback m_callback;
+ const void* m_data;
+};
+
+class FileWriter : public BaseWriter
+{
+public:
+ typedef BaseWriter Parent;
+ // ISlangWriter
+ SLANG_NO_THROW virtual SlangResult SLANG_MCALL writeVaList(const char* format, va_list args) SLANG_OVERRIDE;
+ SLANG_NO_THROW virtual SlangResult SLANG_MCALL write(const char* chars, size_t numChars) SLANG_OVERRIDE;
+ SLANG_NO_THROW virtual void SLANG_MCALL flush() SLANG_OVERRIDE;
+ SLANG_NO_THROW virtual SlangResult SLANG_MCALL setMode(SlangWriterMode mode) SLANG_OVERRIDE;
+
+ static bool isConsole(FILE* file);
+ static WriterFlags getDefaultFlags(FILE* file) { return isConsole(file) ? WriterFlags(WriterFlag::IsConsole) : 0; }
+
+ /// Ctor
+ FileWriter(FILE* file, WriterFlags flags) :
+ Parent(flags | getDefaultFlags(file)),
+ m_file(file)
+ {}
+
+ /// Dtor
+ ~FileWriter();
+
+protected:
+ FILE* m_file;
+};
+
+class StringWriter : public BaseWriter
+{
+public:
+ typedef BaseWriter Parent;
+ // ISlangWriter
+ SLANG_NO_THROW virtual SlangResult SLANG_MCALL writeVaList(const char* format, va_list args) SLANG_OVERRIDE;
+ SLANG_NO_THROW virtual SlangResult SLANG_MCALL write(const char* chars, size_t numChars) SLANG_OVERRIDE;
+
+ /// Ctor
+ StringWriter(StringBuilder* builder, WriterFlags flags) :
+ Parent(flags),
+ m_builder(builder)
+ {}
+
+protected:
+ StringBuilder* m_builder;
+};
+
+class NullWriter : public BaseWriter
+{
+public:
+ typedef BaseWriter Parent;
+ // ISlangWriter
+ SLANG_NO_THROW virtual SlangResult SLANG_MCALL writeVaList(const char* format, va_list args) SLANG_OVERRIDE { SLANG_UNUSED(format); SLANG_UNUSED(args); return SLANG_OK; }
+ SLANG_NO_THROW virtual SlangResult SLANG_MCALL write(const char* chars, size_t numChars) SLANG_OVERRIDE { SLANG_UNUSED(chars); SLANG_UNUSED(numChars); return SLANG_OK; }
+
+ /// Ctor
+ NullWriter(WriterFlags flags) :
+ Parent(flags)
+ {}
+};
+
+}
+
+#endif // SLANG_TEXT_WRITER_H