| 812 | } |
| 813 | |
| 814 | static RefPtr<Decl> ParseVarDecl( |
| 815 | Parser* parser, |
| 816 | ContainerDecl* containerDecl, |
| 817 | DeclaratorInfo const& declaratorInfo) |
| 818 | { |
| 819 | if (dynamic_cast<ShaderDeclBase*>(containerDecl)) |
| 820 | { |
| 821 | // inside a shader, we create a component decl |
| 822 | RefPtr<ComponentSyntaxNode> decl = new ComponentSyntaxNode(); |
| 823 | parser->FillPosition(decl.Ptr()); |
| 824 | decl->Position = declaratorInfo.nameToken.Position; |
| 825 | |
| 826 | // |
| 827 | decl->Rate = declaratorInfo.rate; |
| 828 | // |
| 829 | |
| 830 | decl->Name = declaratorInfo.nameToken; |
| 831 | decl->TypeNode = declaratorInfo.typeSpec; |
| 832 | |
| 833 | // Note(tfoley): this case is the one place where a component |
| 834 | // declaration differents in any meaningful way from an |
| 835 | // ordinary variable declaration. |
| 836 | if (parser->tokenReader.PeekTokenType() == TokenType::LBrace) |
| 837 | { |
| 838 | decl->BlockStatement = parser->ParseBlockStatement(); |
| 839 | } |
| 840 | else |
| 841 | { |
| 842 | if (AdvanceIf(parser, TokenType::OpAssign)) |
| 843 | { |
| 844 | decl->Expression = parser->ParseExpression(); |
| 845 | } |
| 846 | // TODO(tfoley): support the block case here |
| 847 | parser->ReadToken(TokenType::Semicolon); |
| 848 | } |
| 849 | |
| 850 | return decl; |
| 851 | } |
| 852 | else |
| 853 | { |
| 854 | // everywhere else, we create an ordinary `VarDeclBase` |
| 855 | RefPtr<VarDeclBase> decl = CreateVarDeclForContext(containerDecl); |
| 856 | parser->FillPosition(decl.Ptr()); |
| 857 | decl->Position = declaratorInfo.nameToken.Position; |
| 858 | |
| 859 | decl->Name = declaratorInfo.nameToken; |
| 860 | decl->TypeNode = declaratorInfo.typeSpec; |
| 861 | |
| 862 | if (AdvanceIf(parser, TokenType::OpAssign)) |
| 863 | { |
| 864 | decl->Expr = parser->ParseExpression(); |
| 865 | } |
| 866 | parser->ReadToken(TokenType::Semicolon); |
| 867 | |
| 868 | return decl; |
| 869 | } |
| 870 | } |
| 871 |
no test coverage detected