ShaderTools.Hlsl.Parser.DirectiveStack.Add C# (CSharp) Method

Add() public method

public Add ( Directive directive ) : DirectiveStack
directive Directive
return DirectiveStack
        public DirectiveStack Add(Directive directive)
        {
            switch (directive.Kind)
            {
                case SyntaxKind.EndIfDirectiveTrivia:
                    var prevIf = GetPreviousIf(_directives);
                    if (prevIf == null || !prevIf.Any())
                    {
                        goto default; // no matching if directive !! leave directive alone
                    }

                    bool tmp;
                    return new DirectiveStack(CompleteIf(_directives, out tmp));
                default:
                    return new DirectiveStack(new ConsList<Directive>(directive, _directives != null ? _directives : ConsList<Directive>.Empty));
            }
        }

Usage Example

Exemplo n.º 1
0
        public HlslLexer(SourceText text, ParserOptions options = null, IIncludeFileSystem fileSystem = null)
        {
            _fileSystem = fileSystem ?? new DummyFileSystem();
            _directives = DirectiveStack.Empty;

            if (options != null)
                foreach (var define in options.PreprocessorDefines)
                {
                    _directives = _directives.Add(new Directive(new ObjectLikeDefineDirectiveTriviaSyntax(
                        null, null, SyntaxFactory.ParseToken(define), new List<SyntaxToken>
                        {
                            SyntaxFactory.ParseToken("1")
                        }, null, true)));
                }

            ExpandMacros = true;

            FileSegments = new List<FileSegment>();
            _includeStack = new Stack<IncludeContext>();
            PushIncludeContext(text);
        }