summaryrefslogtreecommitdiff
path: root/source/core/slang-writer.h
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/slang-writer.h
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/slang-writer.h')
-rw-r--r--source/core/slang-writer.h145
1 files changed, 145 insertions, 0 deletions
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