diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-06-04 15:10:26 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-04 15:10:26 -0400 |
| commit | 0d9071bd1511ee2cb7d6ba6ce9e250d25613ddca (patch) | |
| tree | 410558e5bae917d027209f5807f8633db8291069 /source/slang/slang-source-stream.h | |
| parent | 0a8f7ae6b899718150f359a378e53bfedd090090 (diff) | |
Review improvements on #971: WIP: Support for other source target languages (#974)
* * Added SourceStyle to CLikeSourceEmitter, to limit cases to actual target types.
* Made Impl methods _ prefixed
* Small tidyup
* * SourceStream -> SourceWriter
* use slang-emit- prefix on SourceWriter file
* * Remove EmitContext -> merge into CLikeSourceEmitter
* slang-c-like-source-emitter -> slang-emit-source.cpp
* ExtensionUsageTracker -> GLSLExtensionTracker
slang-extension-usage-tracker.cpp/.h -> slang-emit-glsl-extension-tracker.cpp/.h
* emit-source.cpp.h -> emit-c-like.cpp/.h
* Small fix to move where some _ prefixed functions are declared in CLikeSourceEmitter.
Diffstat (limited to 'source/slang/slang-source-stream.h')
| -rw-r--r-- | source/slang/slang-source-stream.h | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/source/slang/slang-source-stream.h b/source/slang/slang-source-stream.h deleted file mode 100644 index e6b7507c0..000000000 --- a/source/slang/slang-source-stream.h +++ /dev/null @@ -1,113 +0,0 @@ -// slang-source-stream.h -#ifndef SLANG_SOURCE_STREAM_H_INCLUDED -#define SLANG_SOURCE_STREAM_H_INCLUDED - -#include "../core/slang-basic.h" - -#include "slang-compiler.h" - -namespace Slang -{ - -/* Class that encapsulates a stream of source. Facilities provided... - -* Management of the buffer that holds the source content as it is constructed -* output line directives - + Supports GLSL as well as C/CPP/HLSL style directives -* Support for line indention */ -class SourceStream -{ -public: - /// Emits without span without any extra processing - void emitRawTextSpan(char const* textBegin, char const* textEnd); - void emitRawText(char const* text); - - /// Emit different types into the stream - void emit(char const* textBegin, char const* textEnd); - void emit(char const* text); - void emit(const String& text); - void emit(const UnownedStringSlice& text); - void emit(Name* name); - void emit(const NameLoc& nameAndLoc); - void emit(IntegerLiteralValue value); - void emit(UInt value); - void emit(int value); - void emit(double value); - - /// Emit names (doing so can also advance to a new source location) - void emitName(const NameLoc& nameAndLoc); - void emitName(Name* name, const SourceLoc& loc); - void emitName(Name* name); - - /// Indent the text - void indent(); - /// Dedent (the opposite of indenting) the text - void dedent(); - - /// Move the current source location to that specified - void advanceToSourceLocation(const SourceLoc& sourceLocation); - void advanceToSourceLocation(const HumaneSourceLoc& sourceLocation); - - /// Get the content as a string - String getContent() { return m_builder.ProduceString(); } - /// Clear the content - void clearContent() { m_builder.Clear(); } - /// Get the content as a string and clear the internal representation - String getContentAndClear(); - - /// Get the line directive mode used - LineDirectiveMode getLineDirectiveMode() const { return m_lineDirectiveMode; } - /// Get the source manager user - SourceManager* getSourceManager() const { return m_sourceManager; } - - /// Ctor - SourceStream(SourceManager* sourceManager, LineDirectiveMode lineDirectiveMode); - -protected: - void _emitTextSpan(char const* textBegin, char const* textEnd); - void _flushSourceLocationChange(); - - // Emit a `#line` directive to the output, and also - // ensure that source location tracking information - // is correct based on the directive we just output. - void _emitLineDirectiveAndUpdateSourceLocation(const HumaneSourceLoc& sourceLocation); - - void _emitLineDirectiveIfNeeded(const HumaneSourceLoc& sourceLocation); - - // Emit a `#line` directive to the output. - // Doesn't update state of source-location tracking. - void _emitLineDirective(const HumaneSourceLoc& sourceLocation); - - // The string of code we've built so far. - // TODO(JS): We could store the text in chunks, and then only sew together into one buffer - // when we are done. Doing so would not require copies/reallocs until the full buffer has been - // produced. A downside to doing this is that it won't be so simple to debug by trying to - // look at the current contents of the buffer - StringBuilder m_builder; - - // Current source position for tracking purposes... - HumaneSourceLoc m_loc; - HumaneSourceLoc m_nextSourceLocation; - bool m_needToUpdateSourceLocation = false; - - // Are we at the start of a line, so that we should indent - // before writing any other text? - bool m_isAtStartOfLine = true; - - // How far are we indented? - Int m_indentLevel = 0; - - SourceManager* m_sourceManager = nullptr; - - // For GLSL output, we can't emit traditional `#line` directives - // with a file path in them, so we maintain a map that associates - // each path with a unique integer, and then we output those - // instead. - Dictionary<String, int> m_mapGLSLSourcePathToID; - int m_glslSourceIDCount = 0; - - LineDirectiveMode m_lineDirectiveMode; -}; - -} -#endif |
