Exemple #1
0
        VarDeclaration Parse(Queue <LexerNode> lexers, CBufferNode parent)
        {
            var variable = VarDeclarationParse(lexers);

            variable.Parent = parent;
            return(variable);
        }
Exemple #2
0
 public void Visit(CBufferNode cbuff)
 {
     cbuff.VarDeclaration.Handle(this);
     cbuff.Register.Handle(this);
     cbuff.Children.ForEach(x => x.Handle(this));
 }
Exemple #3
0
        void Parse(Queue <LexerNode> lexers, DefinitionObjectNode parent)
        {
            var next = lexers.Peek();

            switch (next.Token)
            {
            case LexerTokens.Operator:
                switch (next.Value)
                {
                case ShaderSyntaxInfo.Semicolon:
                    lexers.Dequeue();        //skip lex
                    return;
                }
                break;

            case LexerTokens.Comment:
                parent.Children.Add(new CommentsNode()
                {
                    Lex = lexers.Dequeue()
                });
                return;

            case LexerTokens.Punctuation:
                switch (next.Value)
                {
                case "#":
                    // ==== examples ==== //
                    // #include "./Shaders/Common.fx"
                    // ==== ++++++++ ==== //
                    lexers.Dequeue();            //for '#'
                    var id = new IncludeDeclaration {
                        Name = lexers.Dequeue(), //get key
                        Path = new StringNode {
                            NameLex = lexers.Dequeue()
                        }
                    };
                    parent.Children.Add(id);
                    return;

                case "[":        //attrinuter: [maxvertexcount(18)]
                    var body = new ListNode();
                    DelimitedBy(lexers, DelimeterParams.Attribute, body, lex => { while (lex.Any())
                                                                                  {
                                                                                      lex.Dequeue();
                                                                                  }
                                                                                  return(null); });
                    return;
                }
                break;
            }
            //specific keys to parse first
            switch (next.Value)
            {
            case ShaderSyntaxInfo.StructKey:
                var var  = VarDeclarationParse(lexers);
                var strn = new StructNode {
                    VarDeclaration = var, Parent = parent
                };
                using (semantic.RegisterStruct(var.DeclarationName.NameLex, strn)) {
                    parent.Children.Add(strn);

                    DelimitedBy(lexers, DelimeterParams.Sequences, strn.Children, lex => VarDeclarationWithSemanticNamesParse(lex, strn));
                    if (lexers.Peek().Value == ShaderSyntaxInfo.Semicolon)
                    {
                        //in some cases ';' is end of declaration
                        lexers.Dequeue();
                    }
                }
                return;

            case ShaderSyntaxInfo.CbufferKey:
                var cbn = new CBufferNode {
                    VarDeclaration = VarDeclarationParse(lexers), Parent = parent
                };
                lexers.Dequeue().ThrowIfNot(ShaderSyntaxInfo.Colon);
                parent.Children.Add(cbn);
                cbn.Register = Parse(lexers, new FunctionCallNode {
                    Parent = cbn, Name = new SystemName {
                        NameLex = lexers.Dequeue()
                    }
                });
                DelimitedBy(lexers, DelimeterParams.Sequences, cbn.Children, lex => Parse(lex, cbn));
                return;
            }
            //parse any variable
            var variable = VarDeclarationParse(lexers);

            if (lexers.Peek().Value == ShaderSyntaxInfo.Semicolon) //end of declaration or definition
                                                                   //float4 illumDiffuse;
            {
                lexers.Dequeue();                                  //skip Semicolon
                variable.Parent = parent;
                parent.Children.Add(variable);
                return;
            }

            //
            next = lexers.Peek();
            switch (next.Token)
            {
            case LexerTokens.Punctuation:
                // ==== examples ==== //
                //int foo(InputT input, ...) { }
                var fdn = new FunctionDeclarationNode {
                    Parent         = parent,
                    VarDeclaration = variable
                };

                parent.Children.Add(fdn);

                DelimitedBy(lexers, DelimeterParams.Function, fdn.Vars,
                            lex => {
                    //var v = VarDeclarationParse(lex);
                    var v = VarDeclarationWithSemanticNamesParse(lex, parent);
                    lex.ThrowIfAny();
                    return(v);
                });
                using (semantic.RegisterFunction(variable.DeclarationName.NameLex, fdn)) {
                    //maybe have semantic name
                    var semanticNameMaybe = lexers.Peek();
                    if (semanticNameMaybe.Token == LexerTokens.Operator && semanticNameMaybe.Value == ":")
                    {
                        lexers.Dequeue();    //skip operator
                        fdn.SemanticNameLex = lexers.Dequeue();
                    }
                    var boundary = DelimitedBy(lexers, DelimeterParams.Sequences, fdn.Children,
                                               lex => FunctionParse(lex, fdn));
                    fdn.Boundary = boundary;
                }

                return;

            case LexerTokens.Operator:
                parent.Children.Add(AssignmentParse(lexers, new AssignmentVariableDefinition()
                {
                    Left = variable
                }));
                break;
            }
        }
Exemple #4
0
 public void Visit(CBufferNode definitionObjectNode)
 {
 }