internal IDisposable RegisterStruct(LexerNode lexer, StructNode node) { if (!CanRegisterGlobalFunction()) { throw new SemanticException($"Unavailable struct declaration '{lexer.Value}' inside another function '{currentRegistration.Name}'"); } var str = new StructGloalObject { Name = lexer, Node = node }; global.Add(lexer.Value, str); currentRegistration = new ScopeRegistration(lexer.Value, str); return(currentRegistration); }
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; } }
public void Visit(StructNode str) { str.VarDeclaration.Handle(this); str.Children.ForEach(x => x.Handle(this)); }
public void Visit(StructNode definitionObjectNode) { }