diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-11-18 13:01:27 +1000 |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-11-18 13:36:50 +1000 |
commit | 2fab4ba8ad56f229cf3a41975bb5be9b39c949fd (patch) | |
tree | 26a452510b0d09288ad94454a0d475d9ecdbc0ed /src/libs | |
parent | 0fa980028ea74c7ba7afa610a4572b6513c45cfb (diff) | |
download | qt-creator-2fab4ba8ad56f229cf3a41975bb5be9b39c949fd.tar.gz |
GLSL AST nodes for function and struct decls
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/glsl/glsl.g | 79 | ||||
-rw-r--r-- | src/libs/glsl/glslast.cpp | 19 | ||||
-rw-r--r-- | src/libs/glsl/glslast.h | 47 | ||||
-rw-r--r-- | src/libs/glsl/glslastvisitor.h | 6 | ||||
-rw-r--r-- | src/libs/glsl/glslparser.cpp | 707 | ||||
-rw-r--r-- | src/libs/glsl/glslparser.h | 4 |
6 files changed, 515 insertions, 347 deletions
diff --git a/src/libs/glsl/glsl.g b/src/libs/glsl/glsl.g index b3295e96e1..2d795b9a6e 100644 --- a/src/libs/glsl/glsl.g +++ b/src/libs/glsl/glsl.g @@ -292,7 +292,8 @@ public: Type *type; const std::string *name; } param_declarator; - // ### ast nodes... + ParameterDeclaration *param_declaration; + FunctionDeclaration *function_declaration; }; Parser(Engine *engine, const char *source, unsigned size, int variant); @@ -308,6 +309,7 @@ private: Expression *&expression(int n) { return _symStack[_tos + n - 1].expression; } Statement *&statement(int n) { return _symStack[_tos + n - 1].statement; } Type *&type(int n) { return _symStack[_tos + n - 1].type; } + FunctionDeclaration *&function(int n) { return _symStack[_tos + n - 1].function_declaration; } inline int consumeToken() { return _index++; } inline const Token &tokenAt(int index) const { return _tokens.at(index); } @@ -1123,7 +1125,7 @@ case $rule_number: { declaration ::= function_prototype SEMICOLON ; /. case $rule_number: { - // ast(1) = new ...AST(...); + // nothing to do. } break; ./ @@ -1144,77 +1146,124 @@ case $rule_number: { declaration ::= type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE SEMICOLON ; /. case $rule_number: { - // ast(1) = new ...AST(...); + if (sym(1).type_qualifier.qualifier != QualifiedType::Struct) { + // TODO: issue an error if the qualifier is not "struct". + } + Type *type = makeAstNode<StructType>(string(2), sym(4).field_list); + ast(1) = makeAstNode<TypeDeclaration>(type); } break; ./ declaration ::= type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE IDENTIFIER SEMICOLON ; /. case $rule_number: { - // ast(1) = new ...AST(...); + if ((sym(1).type_qualifier.qualifier & QualifiedType::Struct) == 0) { + // TODO: issue an error if the qualifier does not contain "struct". + } + Type *type = makeAstNode<StructType>(string(2), sym(4).field_list); + Type *qualtype = type; + if (sym(1).type_qualifier.qualifier != QualifiedType::Struct) { + qualtype = makeAstNode<QualifiedType> + (sym(1).type_qualifier.qualifier & ~QualifiedType::Struct, qualtype, + sym(1).type_qualifier.layout_list); + } + ast(1) = makeAstNode<TypeAndVariableDeclaration> + (makeAstNode<TypeDeclaration>(type), + makeAstNode<VariableDeclaration>(qualtype, string(6))); } break; ./ declaration ::= type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE IDENTIFIER LEFT_BRACKET RIGHT_BRACKET SEMICOLON ; /. case $rule_number: { - // ast(1) = new ...AST(...); + if ((sym(1).type_qualifier.qualifier & QualifiedType::Struct) == 0) { + // TODO: issue an error if the qualifier does not contain "struct". + } + Type *type = makeAstNode<StructType>(string(2), sym(4).field_list); + Type *qualtype = type; + if (sym(1).type_qualifier.qualifier != QualifiedType::Struct) { + qualtype = makeAstNode<QualifiedType> + (sym(1).type_qualifier.qualifier & ~QualifiedType::Struct, qualtype, + sym(1).type_qualifier.layout_list); + } + ast(1) = makeAstNode<TypeAndVariableDeclaration> + (makeAstNode<TypeDeclaration>(type), + makeAstNode<VariableDeclaration> + (makeAstNode<ArrayType>(qualtype), string(6))); } break; ./ declaration ::= type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET SEMICOLON ; /. case $rule_number: { - // ast(1) = new ...AST(...); + if ((sym(1).type_qualifier.qualifier & QualifiedType::Struct) == 0) { + // TODO: issue an error if the qualifier does not contain "struct". + } + Type *type = makeAstNode<StructType>(string(2), sym(4).field_list); + Type *qualtype = type; + if (sym(1).type_qualifier.qualifier != QualifiedType::Struct) { + qualtype = makeAstNode<QualifiedType> + (sym(1).type_qualifier.qualifier & ~QualifiedType::Struct, qualtype, + sym(1).type_qualifier.layout_list); + } + ast(1) = makeAstNode<TypeAndVariableDeclaration> + (makeAstNode<TypeDeclaration>(type), + makeAstNode<VariableDeclaration> + (makeAstNode<ArrayType>(qualtype, expression(8)), string(6))); } break; ./ declaration ::= type_qualifier SEMICOLON ; /. case $rule_number: { - // ast(1) = new ...AST(...); + Type *type = makeAstNode<QualifiedType> + (sym(1).type_qualifier.qualifier, (Type *)0, + sym(1).type_qualifier.layout_list); + ast(1) = makeAstNode<TypeDeclaration>(type); } break; ./ function_prototype ::= function_declarator RIGHT_PAREN ; /. case $rule_number: { - // ast(1) = new ...AST(...); + function(1)->finishParams(); } break; ./ function_declarator ::= function_header ; /. case $rule_number: { - // ast(1) = new ...AST(...); + // nothing to do. } break; ./ function_declarator ::= function_header_with_parameters ; /. case $rule_number: { - // ast(1) = new ...AST(...); + // nothing to do. } break; ./ function_header_with_parameters ::= function_header parameter_declaration ; /. case $rule_number: { - // ast(1) = new ...AST(...); + function(1)->params = makeAstNode< List<ParameterDeclaration *> > + (sym(2).param_declaration); } break; ./ function_header_with_parameters ::= function_header_with_parameters COMMA parameter_declaration ; /. case $rule_number: { - // ast(1) = new ...AST(...); + function(1)->params = makeAstNode< List<ParameterDeclaration *> > + (function(1)->params, sym(3).param_declaration); } break; ./ function_header ::= fully_specified_type IDENTIFIER LEFT_PAREN ; /. case $rule_number: { - // ast(1) = new ...AST(...); + function(1) = makeAstNode<FunctionDeclaration>(type(1), string(2)); } break; ./ @@ -2801,7 +2850,7 @@ case $rule_number: { external_declaration ::= function_definition ; /. case $rule_number: { - // ast(1) = new ...AST(...); + // nothing to do. } break; ./ @@ -2822,7 +2871,7 @@ case $rule_number: { function_definition ::= function_prototype compound_statement_no_new_scope ; /. case $rule_number: { - // ast(1) = new ...AST(...); + function(1)->body = statement(2); } break; ./ diff --git a/src/libs/glsl/glslast.cpp b/src/libs/glsl/glslast.cpp index 28c8c97f28..7f81e59f28 100644 --- a/src/libs/glsl/glslast.cpp +++ b/src/libs/glsl/glslast.cpp @@ -394,6 +394,15 @@ void TypeDeclaration::accept0(Visitor *visitor) visitor->endVisit(this); } +void TypeAndVariableDeclaration::accept0(Visitor *visitor) +{ + if (visitor->visit(this)) { + accept(typeDecl, visitor); + accept(varDecl, visitor); + } + visitor->endVisit(this); +} + void InvariantDeclaration::accept0(Visitor *visitor) { visitor->visit(this); @@ -406,3 +415,13 @@ void InitDeclaration::accept0(Visitor *visitor) accept(decls, visitor); visitor->endVisit(this); } + +void FunctionDeclaration::accept0(Visitor *visitor) +{ + if (visitor->visit(this)) { + accept(returnType, visitor); + accept(params, visitor); + accept(body, visitor); + } + visitor->endVisit(this); +} diff --git a/src/libs/glsl/glslast.h b/src/libs/glsl/glslast.h index 7e4493eeb8..3c5ce980dc 100644 --- a/src/libs/glsl/glslast.h +++ b/src/libs/glsl/glslast.h @@ -71,8 +71,10 @@ class PrecisionDeclaration; class ParameterDeclaration; class VariableDeclaration; class TypeDeclaration; +class TypeAndVariableDeclaration; class InvariantDeclaration; class InitDeclaration; +class FunctionDeclaration; class Visitor; template <typename T> @@ -215,8 +217,10 @@ public: Kind_ParameterDeclaration, Kind_VariableDeclaration, Kind_TypeDeclaration, + Kind_TypeAndVariableDeclaration, Kind_InvariantDeclaration, - Kind_InitDeclaration + Kind_InitDeclaration, + Kind_FunctionDeclaration }; virtual TranslationUnit *asTranslationUnit() { return 0; } @@ -258,8 +262,10 @@ public: virtual ParameterDeclaration *asParameterDeclaration() { return 0; } virtual VariableDeclaration *asVariableDeclaration() { return 0; } virtual TypeDeclaration *asTypeDeclaration() { return 0; } + virtual TypeAndVariableDeclaration *asTypeAndVariableDeclaration() { return 0; } virtual InvariantDeclaration *asInvariantDeclaration() { return 0; } virtual InitDeclaration *asInitDeclaration() { return 0; } + virtual FunctionDeclaration *asFunctionDeclaration() { return 0; } void accept(Visitor *visitor); static void accept(AST *ast, Visitor *visitor); @@ -953,6 +959,23 @@ public: // attributes Type *type; }; +class TypeAndVariableDeclaration: public Declaration +{ +public: + TypeAndVariableDeclaration(TypeDeclaration *_typeDecl, + VariableDeclaration *_varDecl) + : Declaration(Kind_TypeAndVariableDeclaration) + , typeDecl(_typeDecl), varDecl(_varDecl) {} + + virtual TypeAndVariableDeclaration *asTypeAndVariableDeclaration() { return this; } + + virtual void accept0(Visitor *visitor); + +public: // attributes + TypeDeclaration *typeDecl; + VariableDeclaration *varDecl; +}; + class InvariantDeclaration: public Declaration { public: @@ -981,6 +1004,28 @@ public: // attributes List<Declaration *> *decls; }; +class FunctionDeclaration : public Declaration +{ +public: + FunctionDeclaration(Type *_returnType, const std::string *_name) + : Declaration(Kind_FunctionDeclaration), returnType(_returnType) + , name(_name), params(0), body(0) {} + + virtual FunctionDeclaration *asFunctionDeclaration() { return this; } + + virtual void accept0(Visitor *visitor); + + void finishParams() { params = finish(params); } + + bool isPrototype() const { return body == 0; } + +public: // attributes + Type *returnType; + const std::string *name; + List<ParameterDeclaration *> *params; + Statement *body; +}; + } // namespace GLSL #endif // GLSLAST_H diff --git a/src/libs/glsl/glslastvisitor.h b/src/libs/glsl/glslastvisitor.h index 045eeb7539..1214ce1920 100644 --- a/src/libs/glsl/glslastvisitor.h +++ b/src/libs/glsl/glslastvisitor.h @@ -138,11 +138,17 @@ public: virtual bool visit(TypeDeclaration *) { return true; } virtual void endVisit(TypeDeclaration *) {} + virtual bool visit(TypeAndVariableDeclaration *) { return true; } + virtual void endVisit(TypeAndVariableDeclaration *) {} + virtual bool visit(InvariantDeclaration *) { return true; } virtual void endVisit(InvariantDeclaration *) {} virtual bool visit(InitDeclaration *) { return true; } virtual void endVisit(InitDeclaration *) {} + + virtual bool visit(FunctionDeclaration *) { return true; } + virtual void endVisit(FunctionDeclaration *) {} }; } // namespace GLSL diff --git a/src/libs/glsl/glslparser.cpp b/src/libs/glsl/glslparser.cpp index c9940d7510..b58118b148 100644 --- a/src/libs/glsl/glslparser.cpp +++ b/src/libs/glsl/glslparser.cpp @@ -1,5 +1,5 @@ -#line 378 "./glsl.g" +#line 380 "./glsl.g" /************************************************************************** ** @@ -159,137 +159,137 @@ TranslationUnit *Parser::parse() return 0; } -#line 540 "./glsl.g" +#line 542 "./glsl.g" void Parser::reduce(int ruleno) { switch(ruleno) { -#line 549 "./glsl.g" +#line 551 "./glsl.g" case 0: { ast(1) = makeAstNode<IdentifierExpression>(string(1)); } break; -#line 556 "./glsl.g" +#line 558 "./glsl.g" case 1: { ast(1) = makeAstNode<LiteralExpression>(string(1)); } break; -#line 563 "./glsl.g" +#line 565 "./glsl.g" case 2: { ast(1) = makeAstNode<LiteralExpression>(_engine->identifier("true", 4)); } break; -#line 570 "./glsl.g" +#line 572 "./glsl.g" case 3: { ast(1) = makeAstNode<LiteralExpression>(_engine->identifier("false", 5)); } break; -#line 577 "./glsl.g" +#line 579 "./glsl.g" case 4: { // nothing to do. } break; -#line 584 "./glsl.g" +#line 586 "./glsl.g" case 5: { ast(1) = ast(2); } break; -#line 591 "./glsl.g" +#line 593 "./glsl.g" case 6: { // nothing to do. } break; -#line 598 "./glsl.g" +#line 600 "./glsl.g" case 7: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_ArrayAccess, expression(1), expression(3)); } break; -#line 605 "./glsl.g" +#line 607 "./glsl.g" case 8: { // nothing to do. } break; -#line 612 "./glsl.g" +#line 614 "./glsl.g" case 9: { ast(1) = makeAstNode<MemberAccessExpression>(expression(1), string(3)); } break; -#line 619 "./glsl.g" +#line 621 "./glsl.g" case 10: { ast(1) = makeAstNode<UnaryExpression>(AST::Kind_PostIncrement, expression(1)); } break; -#line 626 "./glsl.g" +#line 628 "./glsl.g" case 11: { ast(1) = makeAstNode<UnaryExpression>(AST::Kind_PostDecrement, expression(1)); } break; -#line 633 "./glsl.g" +#line 635 "./glsl.g" case 12: { // nothing to do. } break; -#line 640 "./glsl.g" +#line 642 "./glsl.g" case 13: { // nothing to do. } break; -#line 647 "./glsl.g" +#line 649 "./glsl.g" case 14: { ast(1) = makeAstNode<FunctionCallExpression> (sym(1).function.id, sym(1).function.arguments); } break; -#line 655 "./glsl.g" +#line 657 "./glsl.g" case 15: { ast(1) = makeAstNode<FunctionCallExpression> (expression(1), sym(3).function.id, sym(3).function.arguments); } break; -#line 663 "./glsl.g" +#line 665 "./glsl.g" case 16: { // nothing to do. } break; -#line 670 "./glsl.g" +#line 672 "./glsl.g" case 17: { // nothing to do. } break; -#line 677 "./glsl.g" +#line 679 "./glsl.g" case 18: { sym(1).function.id = sym(1).function_identifier; sym(1).function.arguments = 0; } break; -#line 685 "./glsl.g" +#line 687 "./glsl.g" case 19: { sym(1).function.id = sym(1).function_identifier; sym(1).function.arguments = 0; } break; -#line 693 "./glsl.g" +#line 695 "./glsl.g" case 20: { sym(1).function.id = sym(1).function_identifier; @@ -297,7 +297,7 @@ case 20: { makeAstNode< List<Expression *> >(expression(2)); } break; -#line 702 "./glsl.g" +#line 704 "./glsl.g" case 21: { sym(1).function.arguments = @@ -305,459 +305,506 @@ case 21: { (sym(1).function.arguments, expression(3)); } break; -#line 711 "./glsl.g" +#line 713 "./glsl.g" case 22: { // nothing to do. } break; -#line 718 "./glsl.g" +#line 720 "./glsl.g" case 23: { ast(1) = makeAstNode<FunctionIdentifier>(type(1)); } break; -#line 725 "./glsl.g" +#line 727 "./glsl.g" case 24: { ast(1) = makeAstNode<FunctionIdentifier>(string(1)); } break; -#line 732 "./glsl.g" +#line 734 "./glsl.g" case 25: { // nothing to do. } break; -#line 739 "./glsl.g" +#line 741 "./glsl.g" case 26: { ast(1) = makeAstNode<UnaryExpression>(AST::Kind_PreIncrement, expression(1)); } break; -#line 746 "./glsl.g" +#line 748 "./glsl.g" case 27: { ast(1) = makeAstNode<UnaryExpression>(AST::Kind_PreDecrement, expression(1)); } break; -#line 753 "./glsl.g" +#line 755 "./glsl.g" case 28: { ast(1) = makeAstNode<UnaryExpression>(sym(1).kind, expression(2)); } break; -#line 760 "./glsl.g" +#line 762 "./glsl.g" case 29: { sym(1).kind = AST::Kind_UnaryPlus; } break; -#line 767 "./glsl.g" +#line 769 "./glsl.g" case 30: { sym(1).kind = AST::Kind_UnaryMinus; } break; -#line 774 "./glsl.g" +#line 776 "./glsl.g" case 31: { sym(1).kind = AST::Kind_LogicalNot; } break; -#line 781 "./glsl.g" +#line 783 "./glsl.g" case 32: { sym(1).kind = AST::Kind_BitwiseNot; } break; -#line 788 "./glsl.g" +#line 790 "./glsl.g" case 33: { // nothing to do. } break; -#line 795 "./glsl.g" +#line 797 "./glsl.g" case 34: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_Multiply, expression(1), expression(3)); } break; -#line 802 "./glsl.g" +#line 804 "./glsl.g" case 35: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_Divide, expression(1), expression(3)); } break; -#line 809 "./glsl.g" +#line 811 "./glsl.g" case 36: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_Modulus, expression(1), expression(3)); } break; -#line 816 "./glsl.g" +#line 818 "./glsl.g" case 37: { // nothing to do. } break; -#line 823 "./glsl.g" +#line 825 "./glsl.g" case 38: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_Plus, expression(1), expression(3)); } break; -#line 830 "./glsl.g" +#line 832 "./glsl.g" case 39: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_Minus, expression(1), expression(3)); } break; -#line 837 "./glsl.g" +#line 839 "./glsl.g" case 40: { // nothing to do. } break; -#line 844 "./glsl.g" +#line 846 "./glsl.g" case 41: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_ShiftLeft, expression(1), expression(3)); } break; -#line 851 "./glsl.g" +#line 853 "./glsl.g" case 42: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_ShiftRight, expression(1), expression(3)); } break; -#line 858 "./glsl.g" +#line 860 "./glsl.g" case 43: { // nothing to do. } break; -#line 865 "./glsl.g" +#line 867 "./glsl.g" case 44: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_LessThan, expression(1), expression(3)); } break; -#line 872 "./glsl.g" +#line 874 "./glsl.g" case 45: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_GreaterThan, expression(1), expression(3)); } break; -#line 879 "./glsl.g" +#line 881 "./glsl.g" case 46: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_LessEqual, expression(1), expression(3)); } break; -#line 886 "./glsl.g" +#line 888 "./glsl.g" case 47: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_GreaterEqual, expression(1), expression(3)); } break; -#line 893 "./glsl.g" +#line 895 "./glsl.g" case 48: { // nothing to do. } break; -#line 900 "./glsl.g" +#line 902 "./glsl.g" case 49: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_Equal, expression(1), expression(3)); } break; -#line 907 "./glsl.g" +#line 909 "./glsl.g" case 50: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_NotEqual, expression(1), expression(3)); } break; -#line 914 "./glsl.g" +#line 916 "./glsl.g" case 51: { // nothing to do. } break; -#line 921 "./glsl.g" +#line 923 "./glsl.g" case 52: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_BitwiseAnd, expression(1), expression(3)); } break; -#line 928 "./glsl.g" +#line 930 "./glsl.g" case 53: { // nothing to do. } break; -#line 935 "./glsl.g" +#line 937 "./glsl.g" case 54: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_BitwiseOr, expression(1), expression(3)); } break; -#line 942 "./glsl.g" +#line 944 "./glsl.g" case 55: { // nothing to do. } break; -#line 949 "./glsl.g" +#line 951 "./glsl.g" case 56: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_BitwiseXor, expression(1), expression(3)); } break; -#line 956 "./glsl.g" +#line 958 "./glsl.g" case 57: { // nothing to do. } break; -#line 963 "./glsl.g" +#line 965 "./glsl.g" case 58: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_LogicalAnd, expression(1), expression(3)); } break; -#line 970 "./glsl.g" +#line 972 "./glsl.g" case 59: { // nothing to do. } break; -#line 977 "./glsl.g" +#line 979 "./glsl.g" case 60: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_LogicalXor, expression(1), expression(3)); } break; -#line 984 "./glsl.g" +#line 986 "./glsl.g" case 61: { // nothing to do. } break; -#line 991 "./glsl.g" +#line 993 "./glsl.g" case 62: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_LogicalOr, expression(1), expression(3)); } break; -#line 998 "./glsl.g" +#line 1000 "./glsl.g" case 63: { // nothing to do. } break; -#line 1005 "./glsl.g" +#line 1007 "./glsl.g" case 64: { ast(1) = makeAstNode<TernaryExpression>(AST::Kind_Conditional, expression(1), expression(3), expression(5)); } break; -#line 1012 "./glsl.g" +#line 1014 "./glsl.g" case 65: { // nothing to do. } break; -#line 1019 "./glsl.g" +#line 1021 "./glsl.g" case 66: { ast(1) = makeAstNode<AssignmentExpression>(sym(2).kind, expression(1), expression(3)); } break; -#line 1026 "./glsl.g" +#line 1028 "./glsl.g" case 67: { sym(1).kind = AST::Kind_Assign; } break; -#line 1033 "./glsl.g" +#line 1035 "./glsl.g" case 68: { sym(1).kind = AST::Kind_AssignMultiply; } break; -#line 1040 "./glsl.g" +#line 1042 "./glsl.g" case 69: { sym(1).kind = AST::Kind_AssignDivide; } break; -#line 1047 "./glsl.g" +#line 1049 "./glsl.g" case 70: { sym(1).kind = AST::Kind_AssignModulus; } break; -#line 1054 "./glsl.g" +#line 1056 "./glsl.g" case 71: { sym(1).kind = AST::Kind_AssignPlus; } break; -#line 1061 "./glsl.g" +#line 1063 "./glsl.g" case 72: { sym(1).kind = AST::Kind_AssignMinus; } break; -#line 1068 "./glsl.g" +#line 1070 "./glsl.g" case 73: { sym(1).kind = AST::Kind_AssignShiftLeft; } break; -#line 1075 "./glsl.g" +#line 1077 "./glsl.g" case 74: { sym(1).kind = AST::Kind_AssignShiftRight; } break; -#line 1082 "./glsl.g" +#line 1084 "./glsl.g" case 75: { sym(1).kind = AST::Kind_AssignAnd; } break; -#line 1089 "./glsl.g" +#line 1091 "./glsl.g" case 76: { sym(1).kind = AST::Kind_AssignXor; } break; -#line 1096 "./glsl.g" +#line 1098 "./glsl.g" case 77: { sym(1).kind = AST::Kind_AssignOr; } break; -#line 1103 "./glsl.g" +#line 1105 "./glsl.g" case 78: { // nothing to do. } break; -#line 1110 "./glsl.g" +#line 1112 "./glsl.g" case 79: { ast(1) = makeAstNode<BinaryExpression>(AST::Kind_Comma, expression(1), expression(3)); } break; -#line 1117 "./glsl.g" +#line 1119 "./glsl.g" case 80: { // nothing to do. } break; -#line 1124 "./glsl.g" +#line 1126 "./glsl.g" case 81: { - // ast(1) = new ...AST(...); + // nothing to do. } break; -#line 1131 "./glsl.g" +#line 1133 "./glsl.g" case 82: { ast(1) = makeAstNode<InitDeclaration>(sym(1).declaration_list); } break; -#line 1138 "./glsl.g" +#line 1140 "./glsl.g" case 83: { ast(1) = makeAstNode<PrecisionDeclaration>(sym(2).precision, type(3)); } break; -#line 1145 "./glsl.g" +#line 1147 "./glsl.g" case 84: { - // ast(1) = new ...AST(...); + if (sym(1).type_qualifier.qualifier != QualifiedType::Struct) { + // TODO: issue an error if the qualifier is not "struct". + } + Type *type = makeAstNode<StructType>(string(2), sym(4).field_list); + ast(1) = makeAstNode<TypeDeclaration>(type); } break; -#line 1152 "./glsl.g" +#line 1158 "./glsl.g" case 85: { - // ast(1) = new ...AST(...); + if ((sym(1).type_qualifier.qualifier & QualifiedType::Struct) == 0) { + // TODO: issue an error if the qualifier does not contain "struct". + } + Type *type = makeAstNode<StructType>(string(2), sym(4).field_list); + Type *qualtype = type; + if (sym(1).type_qualifier.qualifier != QualifiedType::Struct) { + qualtype = makeAstNode<QualifiedType> + (sym(1).type_qualifier.qualifier & ~QualifiedType::Struct, qualtype, + sym(1).type_qualifier.layout_list); + } + ast(1) = makeAstNode<TypeAndVariableDeclaration> + (makeAstNode<TypeDeclaration>(type), + makeAstNode<VariableDeclaration>(qualtype, string(6))); } break; -#line 1159 "./glsl.g" +#line 1177 "./glsl.g" case 86: { - // ast(1) = new ...AST(...); + if ((sym(1).type_qualifier.qualifier & QualifiedType::Struct) == 0) { + // TODO: issue an error if the qualifier does not contain "struct". + } + Type *type = makeAstNode<StructType>(string(2), sym(4).field_list); + Type *qualtype = type; + if (sym(1).type_qualifier.qualifier != QualifiedType::Struct) { + qualtype = makeAstNode<QualifiedType> + (sym(1).type_qualifier.qualifier & ~QualifiedType::Struct, qualtype, + sym(1).type_qualifier.layout_list); + } + ast(1) = makeAstNode<TypeAndVariableDeclaration> + (makeAstNode<TypeDeclaration>(type), + makeAstNode<VariableDeclaration> + (makeAstNode<ArrayType>(qualtype), string(6))); } break; -#line 1166 "./glsl.g" +#line 1197 "./glsl.g" case 87: { - // ast(1) = new ...AST(...); + if ((sym(1).type_qualifier.qualifier & QualifiedType::Struct) == 0) { + // TODO: issue an error if the qualifier does not contain "struct". + } + Type *type = makeAstNode<StructType>(string(2), sym(4).field_list); + Type *qualtype = type; + if (sym(1).type_qualifier.qualifier != QualifiedType::Struct) { + qualtype = makeAstNode<QualifiedType> + (sym(1).type_qualifier.qualifier & ~QualifiedType::Struct, qualtype, + sym(1).type_qualifier.layout_list); + } + ast(1) = makeAstNode<TypeAndVariableDeclaration> + (makeAstNode<TypeDeclaration>(type), + makeAstNode<VariableDeclaration> + (makeAstNode<ArrayType>(qualtype, expression(8)), string(6))); } break; -#line 1173 "./glsl.g" +#line 1217 "./glsl.g" case 88: { - // ast(1) = new ...AST(...); + Type *type = makeAstNode<QualifiedType> + (sym(1).type_qualifier.qualifier, (Type *)0, + sym(1).type_qualifier.layout_list); + ast(1) = makeAstNode<TypeDeclaration>(type); } break; -#line 1180 "./glsl.g" +#line 1227 "./glsl.g" case 89: { - // ast(1) = new ...AST(...); + function(1)->finishParams(); } break; -#line 1187 "./glsl.g" +#line 1234 "./glsl.g" case 90: { - // ast(1) = new ...AST(...); + // nothing to do. } break; -#line 1194 "./glsl.g" +#line 1241 "./glsl.g" case 91: { - // ast(1) = new ...AST(...); + // nothing to do. } break; -#line 1201 "./glsl.g" +#line 1248 "./glsl.g" case 92: { - // ast(1) = new ...AST(...); + function(1)->params = makeAstNode< List<ParameterDeclaration *> > + (sym(2).param_declaration); } break; -#line 1208 "./glsl.g" +#line 1256 "./glsl.g" case 93: { - // ast(1) = new ...AST(...); + function(1)->params = makeAstNode< List<ParameterDeclaration *> > + (function(1)->params, sym(3).param_declaration); } break; -#line 1215 "./glsl.g" +#line 1264 "./glsl.g" case 94: { - // ast(1) = new ...AST(...); + function(1) = makeAstNode<FunctionDeclaration>(type(1), string(2)); } break; -#line 1222 "./glsl.g" +#line 1271 "./glsl.g" case 95: { sym(1).param_declarator.type = type(1); sym(1).param_declarator.name = string(2); } break; -#line 1230 "./glsl.g" +#line 1279 "./glsl.g" case 96: { sym(1).param_declarator.type = makeAstNode<ArrayType>(type(1), expression(4)); sym(1).param_declarator.name = string(2); } break; -#line 1238 "./glsl.g" +#line 1287 "./glsl.g" case 97: { ast(1) = makeAstNode<ParameterDeclaration> @@ -768,7 +815,7 @@ case 97: { sym(3).param_declarator.name); } break; -#line 1250 "./glsl.g" +#line 1299 "./glsl.g" case 98: { ast(1) = makeAstNode<ParameterDeclaration> @@ -777,7 +824,7 @@ case 98: { sym(2).param_declarator.name); } break; -#line 1260 "./glsl.g" +#line 1309 "./glsl.g" case 99: { ast(1) = makeAstNode<ParameterDeclaration> @@ -787,7 +834,7 @@ case 99: { (const std::string *)0); } break; -#line 1271 "./glsl.g" +#line 1320 "./glsl.g" case 100: { ast(1) = makeAstNode<ParameterDeclaration> @@ -795,44 +842,44 @@ case 100: { (const std::string *)0); } break; -#line 1280 "./glsl.g" +#line 1329 "./glsl.g" case 101: { sym(1).qualifier = ParameterDeclaration::In; } break; -#line 1287 "./glsl.g" +#line 1336 "./glsl.g" case 102: { sym(1).qualifier = ParameterDeclaration::In; } break; -#line 1294 "./glsl.g" +#line 1343 "./glsl.g" case 103: { sym(1).qualifier = ParameterDeclaration::Out; } break; -#line 1301 "./glsl.g" +#line 1350 "./glsl.g" case 104: { sym(1).qualifier = ParameterDeclaration::InOut; } break; -#line 1308 "./glsl.g" +#line 1357 "./glsl.g" case 105: { // nothing to do. } break; -#line 1315 "./glsl.g" +#line 1364 "./glsl.g" case 106: { sym(1).declaration_list = makeAstNode< List<Declaration *> > (sym(1).declaration); } break; -#line 1323 "./glsl.g" +#line 1372 "./glsl.g" case 107: { Type *type = VariableDeclaration::declarationType(sym(1).declaration_list); @@ -841,7 +888,7 @@ case 107: { (sym(1).declaration_list, decl); } break; -#line 1333 "./glsl.g" +#line 1382 "./glsl.g" case 108: { Type *type = VariableDeclaration::declarationType(sym(1).declaration_list); @@ -851,7 +898,7 @@ case 108: { (sym(1).declaration_list, decl); } break; -#line 1344 "./glsl.g" +#line 1393 "./glsl.g" case 109: { Type *type = VariableDeclaration::declarationType(sym(1).declaration_list); @@ -861,7 +908,7 @@ case 109: { (sym(1).declaration_list, decl); } break; -#line 1355 "./glsl.g" +#line 1404 "./glsl.g" case 110: { Type *type = VariableDeclaration::declarationType(sym(1).declaration_list); @@ -872,7 +919,7 @@ case 110: { (sym(1).declaration_list, decl); } break; -#line 1367 "./glsl.g" +#line 1416 "./glsl.g" case 111: { Type *type = VariableDeclaration::declarationType(sym(1).declaration_list); @@ -883,7 +930,7 @@ case 111: { (sym(1).declaration_list, decl); } break; -#line 1379 "./glsl.g" +#line 1428 "./glsl.g" case 112: { Type *type = VariableDeclaration::declarationType(sym(1).declaration_list); @@ -893,40 +940,40 @@ case 112: { (sym(1).declaration_list, decl); } break; -#line 1390 "./glsl.g" +#line 1439 "./glsl.g" case 113: { ast(1) = makeAstNode<TypeDeclaration>(type(1)); } break; -#line 1397 "./glsl.g" +#line 1446 "./glsl.g" case 114: { ast(1) = makeAstNode<VariableDeclaration>(type(1), string(2)); } break; -#line 1404 "./glsl.g" +#line 1453 "./glsl.g" case 115: { ast(1) = makeAstNode<VariableDeclaration> (makeAstNode<ArrayType>(type(1)), string(2)); } break; -#line 1412 "./glsl.g" +#line 1461 "./glsl.g" case 116: { ast(1) = makeAstNode<VariableDeclaration> (makeAstNode<ArrayType>(type(1), expression(4)), string(2)); } break; -#line 1420 "./glsl.g" +#line 1469 "./glsl.g" case 117: { ast(1) = makeAstNode<VariableDeclaration> (makeAstNode<ArrayType>(type(1)), string(2), expression(6)); } break; -#line 1428 "./glsl.g" +#line 1477 "./glsl.g" case 118: { ast(1) = makeAstNode<VariableDeclaration> @@ -934,26 +981,26 @@ case 118: { string(2), expression(7)); } break; -#line 1437 "./glsl.g" +#line 1486 "./glsl.g" case 119: { ast(1) = makeAstNode<VariableDeclaration> (type(1), string(2), expression(4)); } break; -#line 1445 "./glsl.g" +#line 1494 "./glsl.g" case 120: { ast(1) = makeAstNode<InvariantDeclaration>(string(2)); } break; -#line 1452 "./glsl.g" +#line 1501 "./glsl.g" case 121: { ast(1) = makeAstNode<QualifiedType>(0, type(1), (List<LayoutQualifier *> *)0); } break; -#line 1459 "./glsl.g" +#line 1508 "./glsl.g" case 122: { ast(1) = makeAstNode<QualifiedType> @@ -961,207 +1008,207 @@ case 122: { sym(1).type_qualifier.layout_list); } break; -#line 1468 "./glsl.g" +#line 1517 "./glsl.g" case 123: { sym(1).qualifier = QualifiedType::Invariant; } break; -#line 1475 "./glsl.g" +#line 1524 "./glsl.g" case 124: { sym(1).qualifier = QualifiedType::Smooth; } break; -#line 1482 "./glsl.g" +#line 1531 "./glsl.g" case 125: { sym(1).qualifier = QualifiedType::Flat; } break; -#line 1489 "./glsl.g" +#line 1538 "./glsl.g" case 126: { sym(1).qualifier = QualifiedType::NoPerspective; } break; -#line 1496 "./glsl.g" +#line 1545 "./glsl.g" case 127: { sym(1) = sym(3); } break; -#line 1503 "./glsl.g" +#line 1552 "./glsl.g" case 128: { sym(1).layout_list = makeAstNode< List<LayoutQualifier *> >(sym(1).layout); } break; -#line 1510 "./glsl.g" +#line 1559 "./glsl.g" case 129: { sym(1).layout_list = makeAstNode< List<LayoutQualifier *> >(sym(1).layout_list, sym(3).layout); } break; -#line 1517 "./glsl.g" +#line 1566 "./glsl.g" case 130: { sym(1).layout = makeAstNode<LayoutQualifier>(string(1), (const std::string *)0); } break; -#line 1524 "./glsl.g" +#line 1573 "./glsl.g" case 131: { sym(1).layout = makeAstNode<LayoutQualifier>(string(1), string(3)); } break; -#line 1531 "./glsl.g" +#line 1580 "./glsl.g" case 132: { sym(1).qualifier = QualifiedType::Const; } break; -#line 1538 "./glsl.g" +#line 1587 "./glsl.g" case 133: { sym(1).type_qualifier.qualifier = sym(1).qualifier; sym(1).type_qualifier.layout_list = 0; } break; -#line 1546 "./glsl.g" +#line 1595 "./glsl.g" case 134: { sym(1).type_qualifier.layout_list = sym(1).layout_list; sym(1).type_qualifier.qualifier = 0; } break; -#line 1554 "./glsl.g" +#line 1603 "./glsl.g" case 135: { sym(1).type_qualifier.layout_list = sym(1).layout_list; sym(1).type_qualifier.qualifier = sym(2).qualifier; } break; -#line 1562 "./glsl.g" +#line 1611 "./glsl.g" case 136: { sym(1).type_qualifier.qualifier = sym(1).qualifier | sym(2).qualifier; sym(1).type_qualifier.layout_list = 0; } break; -#line 1570 "./glsl.g" +#line 1619 "./glsl.g" case 137: { sym(1).type_qualifier.qualifier = sym(1).qualifier; sym(1).type_qualifier.layout_list = 0; } break; -#line 1578 "./glsl.g" +#line 1627 "./glsl.g" case 138: { sym(1).type_qualifier.qualifier = sym(1).qualifier | sym(2).qualifier; sym(1).type_qualifier.layout_list = 0; } break; -#line 1586 "./glsl.g" +#line 1635 "./glsl.g" case 139: { sym(1).type_qualifier.qualifier = sym(1).qualifier | sym(2).qualifier | sym(3).qualifier; sym(1).type_qualifier.layout_list = 0; } break; -#line 1594 "./glsl.g" +#line 1643 "./glsl.g" case 140: { sym(1).type_qualifier.qualifier = QualifiedType::Invariant; sym(1).type_qualifier.layout_list = 0; } break; -#line 1602 "./glsl.g" +#line 1651 "./glsl.g" case 141: { sym(1).qualifier = QualifiedType::Const; } break; -#line 1609 "./glsl.g" +#line 1658 "./glsl.g" case 142: { sym(1).qualifier = QualifiedType::Attribute; } break; -#line 1616 "./glsl.g" +#line 1665 "./glsl.g" case 143: { sym(1).qualifier = QualifiedType::Varying; } break; -#line 1623 "./glsl.g" +#line 1672 "./glsl.g" case 144: { sym(1).qualifier = QualifiedType::CentroidVarying; } break; -#line 1630 "./glsl.g" +#line 1679 "./glsl.g" case 145: { sym(1).qualifier = QualifiedType::In; } break; -#line 1637 "./glsl.g" +#line 1686 "./glsl.g" case 146: { sym(1).qualifier = QualifiedType::Out; } break; -#line 1644 "./glsl.g" +#line 1693 "./glsl.g" case 147: { sym(1).qualifier = QualifiedType::CentroidIn; } break; -#line 1651 "./glsl.g" +#line 1700 "./glsl.g" case 148: { sym(1).qualifier = QualifiedType::CentroidOut; } break; -#line 1658 "./glsl.g" +#line 1707 "./glsl.g" case 149: { sym(1).qualifier = QualifiedType::PatchIn; } break; -#line 1665 "./glsl.g" +#line 1714 "./glsl.g" case 150: { sym(1).qualifier = QualifiedType::PatchOut; } break; -#line 1672 "./glsl.g" +#line 1721 "./glsl.g" case 151: { sym(1).qualifier = QualifiedType::SampleIn; } break; -#line 1679 "./glsl.g" +#line 1728 "./glsl.g" case 152: { sym(1).qualifier = QualifiedType::SampleOut; } break; -#line 1686 "./glsl.g" +#line 1735 "./glsl.g" case 153: { sym(1).qualifier = QualifiedType::Uniform; } break; -#line 1693 "./glsl.g" +#line 1742 "./glsl.g" case 154: { // nothing to do. } break; -#line 1700 "./glsl.g" +#line 1749 "./glsl.g" case 155: { if (!type(2)->setPrecision(sym(1).precision)) { @@ -1170,595 +1217,595 @@ case 155: { ast(1) = type(2); } break; -#line 1710 "./glsl.g" +#line 1759 "./glsl.g" case 156: { // nothing to do. } break; -#line 1717 "./glsl.g" +#line 1766 "./glsl.g" case 157: { ast(1) = makeAstNode<ArrayType>(type(1)); } break; -#line 1724 "./glsl.g" +#line 1773 "./glsl.g" case 158: { ast(1) = makeAstNode<ArrayType>(type(1), expression(3)); } break; -#line 1731 "./glsl.g" +#line 1780 "./glsl.g" case 159: { ast(1) = makeBasicType(T_VOID, Type::Void); } break; -#line 1738 "./glsl.g" +#line 1787 "./glsl.g" case 160: { ast(1) = makeBasicType(T_FLOAT, Type::Primitive); } break; -#line 1745 "./glsl.g" +#line 1794 "./glsl.g" case 161: { ast(1) = makeBasicType(T_DOUBLE, Type::Primitive); } break; -#line 1752 "./glsl.g" +#line 1801 "./glsl.g" case 162: { ast(1) = makeBasicType(T_INT, Type::Primitive); } break; -#line 1759 "./glsl.g" +#line 1808 "./glsl.g" case 163: { ast(1) = makeBasicType(T_UINT, Type::Primitive); } break; -#line 1766 "./glsl.g" +#line 1815 "./glsl.g" case 164: { ast(1) = makeBasicType(T_BOOL, Type::Primitive); } break; -#line 1773 "./glsl.g" +#line 1822 "./glsl.g" case 165: { ast(1) = makeBasicType(T_VEC2, Type::Vector2); } break; -#line 1780 "./glsl.g" +#line 1829 "./glsl.g" case 166: { ast(1) = makeBasicType(T_VEC3, Type::Vector3); } break; -#line 1787 "./glsl.g" +#line 1836 "./glsl.g" case 167: { ast(1) = makeBasicType(T_VEC4, Type::Vector4); } break; -#line 1794 "./glsl.g" +#line 1843 "./glsl.g" case 168: { ast(1) = makeBasicType(T_DVEC2, Type::Vector2); } break; -#line 1801 "./glsl.g" +#line 1850 "./glsl.g" case 169: { ast(1) = makeBasicType(T_DVEC3, Type::Vector3); } break; -#line 1808 "./glsl.g" +#line 1857 "./glsl.g" case 170: { ast(1) = makeBasicType(T_DVEC4, Type::Vector4); } break; -#line 1815 "./glsl.g" +#line 1864 "./glsl.g" case 171: { ast(1) = makeBasicType(T_BVEC2, Type::Vector2); } break; -#line 1822 "./glsl.g" +#line 1871 "./glsl.g" case 172: { ast(1) = makeBasicType(T_BVEC3, Type::Vector3); } break; -#line 1829 "./glsl.g" +#line 1878 "./glsl.g" case 173: { ast(1) = makeBasicType(T_BVEC4, Type::Vector4); } break; -#line 1836 "./glsl.g" +#line 1885 "./glsl.g" case 174: { ast(1) = makeBasicType(T_IVEC2, Type::Vector2); } break; -#line 1843 "./glsl.g" +#line 1892 "./glsl.g" case 175: { ast(1) = makeBasicType(T_IVEC3, Type::Vector3); } break; -#line 1850 "./glsl.g" +#line 1899 "./glsl.g" case 176: { ast(1) = makeBasicType(T_IVEC4, Type::Vector4); } break; -#line 1857 "./glsl.g" +#line 1906 "./glsl.g" case 177: { ast(1) = makeBasicType(T_UVEC2, Type::Vector2); } break; -#line 1864 "./glsl.g" +#line 1913 "./glsl.g" case 178: { ast(1) = makeBasicType(T_UVEC3, Type::Vector3); } break; -#line 1871 "./glsl.g" +#line 1920 "./glsl.g" case 179: { ast(1) = makeBasicType(T_UVEC4, Type::Vector4); } break; -#line 1878 "./glsl.g" +#line 1927 "./glsl.g" case 180: { ast(1) = makeBasicType(T_MAT2, Type::Matrix); } break; -#line 1885 "./glsl.g" +#line 1934 "./glsl.g" case 181: { ast(1) = makeBasicType(T_MAT3, Type::Matrix); } break; -#line 1892 "./glsl.g" +#line 1941 "./glsl.g" case 182: { ast(1) = makeBasicType(T_MAT4, Type::Matrix); } break; -#line 1899 "./glsl.g" +#line 1948 "./glsl.g" case 183: { ast(1) = makeBasicType(T_MAT2X2, Type::Matrix); } break; -#line 1906 "./glsl.g" +#line 1955 "./glsl.g" case 184: { ast(1) = makeBasicType(T_MAT2X3, Type::Matrix); } break; -#line 1913 "./glsl.g" +#line 1962 "./glsl.g" case 185: { ast(1) = makeBasicType(T_MAT2X4, Type::Matrix); } break; -#line 1920 "./glsl.g" +#line 1969 "./glsl.g" case 186: { ast(1) = makeBasicType(T_MAT3X2, Type::Matrix); } break; -#line 1927 "./glsl.g" +#line 1976 "./glsl.g" case 187: { ast(1) = makeBasicType(T_MAT3X3, Type::Matrix); } break; -#line 1934 "./glsl.g" +#line 1983 "./glsl.g" case 188: { ast(1) = makeBasicType(T_MAT3X4, Type::Matrix); } break; -#line 1941 "./glsl.g" +#line 1990 "./glsl.g" case 189: { ast(1) = makeBasicType(T_MAT4X2, Type::Matrix); } break; -#line 1948 "./glsl.g" +#line 1997 "./glsl.g" case 190: { ast(1) = makeBasicType(T_MAT4X3, Type::Matrix); } break; -#line 1955 "./glsl.g" +#line 2004 "./glsl.g" case 191: { ast(1) = makeBasicType(T_MAT4X4, Type::Matrix); } break; -#line 1962 "./glsl.g" +#line 2011 "./glsl.g" case 192: { ast(1) = makeBasicType(T_DMAT2, Type::Matrix); } break; -#line 1969 "./glsl.g" +#line 2018 "./glsl.g" case 193: { ast(1) = makeBasicType(T_DMAT3, Type::Matrix); } break; -#line 1976 "./glsl.g" +#line 2025 "./glsl.g" case 194: { ast(1) = makeBasicType(T_DMAT4, Type::Matrix); } break; -#line 1983 "./glsl.g" +#line 2032 "./glsl.g" case 195: { ast(1) = makeBasicType(T_DMAT2X2, Type::Matrix); } break; -#line 1990 "./glsl.g" +#line 2039 "./glsl.g" case 196: { ast(1) = makeBasicType(T_DMAT2X3, Type::Matrix); } break; -#line 1997 "./glsl.g" +#line 2046 "./glsl.g" case 197: { ast(1) = makeBasicType(T_DMAT2X4, Type::Matrix); } break; -#line 2004 "./glsl.g" +#line 2053 "./glsl.g" case 198: { ast(1) = makeBasicType(T_DMAT3X2, Type::Matrix); } break; -#line 2011 "./glsl.g" +#line 2060 "./glsl.g" case 199: { ast(1) = makeBasicType(T_DMAT3X3, Type::Matrix); } break; -#line 2018 "./glsl.g" +#line 2067 "./glsl.g" case 200: { ast(1) = makeBasicType(T_DMAT3X4, Type::Matrix); } break; -#line 2025 "./glsl.g" +#line 2074 "./glsl.g" case 201: { ast(1) = makeBasicType(T_DMAT4X2, Type::Matrix); } break; -#line 2032 "./glsl.g" +#line 2081 "./glsl.g" case 202: { ast(1) = makeBasicType(T_DMAT4X3, Type::Matrix); } break; -#line 2039 "./glsl.g" +#line 2088 "./glsl.g" case 203: { ast(1) = makeBasicType(T_DMAT4X4, Type::Matrix); } break; -#line 2046 "./glsl.g" +#line 2095 "./glsl.g" case 204: { ast(1) = makeBasicType(T_SAMPLER1D, Type::Sampler1D); } break; -#line 2053 "./glsl.g" +#line 2102 "./glsl.g" case 205: { ast(1) = makeBasicType(T_SAMPLER2D, Type::Sampler2D); } break; -#line 2060 "./glsl.g" +#line 2109 "./glsl.g" case 206: { ast(1) = makeBasicType(T_SAMPLER3D, Type::Sampler3D); } break; -#line 2067 "./glsl.g" +#line 2116 "./glsl.g" case 207: { ast(1) = makeBasicType(T_SAMPLERCUBE, Type::SamplerCube); } break; -#line 2074 "./glsl.g" +#line 2123 "./glsl.g" case 208: { ast(1) = makeBasicType(T_SAMPLER1DSHADOW, Type::Sampler1DShadow); } break; -#line 2081 "./glsl.g" +#line 2130 "./glsl.g" case 209: { ast(1) = makeBasicType(T_SAMPLER2DSHADOW, Type::Sampler2DShadow); } break; -#line 2088 "./glsl.g" +#line 2137 "./glsl.g" case 210: { ast(1) = makeBasicType(T_SAMPLERCUBESHADOW, Type::SamplerCubeShadow); } break; -#line 2095 "./glsl.g" +#line 2144 "./glsl.g" case 211: { ast(1) = makeBasicType(T_SAMPLER1DARRAY, Type::Sampler1DArray); } break; -#line 2102 "./glsl.g" +#line 2151 "./glsl.g" case 212: { ast(1) = makeBasicType(T_SAMPLER2DARRAY, Type::Sampler2DArray); } break; -#line 2109 "./glsl.g" +#line 2158 "./glsl.g" case 213: { ast(1) = makeBasicType(T_SAMPLER1DARRAYSHADOW, Type::Sampler1DArrayShadow); } break; -#line 2116 "./glsl.g" +#line 2165 "./glsl.g" case 214: { ast(1) = makeBasicType(T_SAMPLER2DARRAYSHADOW, Type::Sampler2DArrayShadow); } break; -#line 2123 "./glsl.g" +#line 2172 "./glsl.g" case 215: { ast(1) = makeBasicType(T_SAMPLERCUBEARRAY, Type::SamplerCubeShadow); } break; -#line 2130 "./glsl.g" +#line 2179 "./glsl.g" case 216: { ast(1) = makeBasicType(T_SAMPLERCUBEARRAYSHADOW, Type::SamplerCubeArrayShadow); } break; -#line 2137 "./glsl.g" +#line 2186 "./glsl.g" case 217: { ast(1) = makeBasicType(T_ISAMPLER1D, Type::Sampler1D); } break; -#line 2144 "./glsl.g" +#line 2193 "./glsl.g" case 218: { ast(1) = makeBasicType(T_ISAMPLER2D, Type::Sampler2D); } break; -#line 2151 "./glsl.g" +#line 2200 "./glsl.g" case 219: { ast(1) = makeBasicType(T_ISAMPLER3D, Type::Sampler3D); } break; -#line 2158 "./glsl.g" +#line 2207 "./glsl.g" case 220: { ast(1) = makeBasicType(T_ISAMPLERCUBE, Type::SamplerCube); } break; -#line 2165 "./glsl.g" +#line 2214 "./glsl.g" case 221: { ast(1) = makeBasicType(T_ISAMPLER1DARRAY, Type::Sampler1DArray); } break; -#line 2172 "./glsl.g" +#line 2221 "./glsl.g" case 222: { ast(1) = makeBasicType(T_ISAMPLER2DARRAY, Type::Sampler2DArray); } break; -#line 2179 "./glsl.g" +#line 2228 "./glsl.g" case 223: { ast(1) = makeBasicType(T_ISAMPLERCUBEARRAY, Type::SamplerCubeArray); } break; -#line 2186 "./glsl.g" +#line 2235 "./glsl.g" case 224: { ast(1) = makeBasicType(T_USAMPLER1D, Type::Sampler1D); } break; -#line 2193 "./glsl.g" +#line 2242 "./glsl.g" case 225: { ast(1) = makeBasicType(T_USAMPLER2D, Type::Sampler2D); } break; -#line 2200 "./glsl.g" +#line 2249 "./glsl.g" case 226: { ast(1) = makeBasicType(T_USAMPLER3D, Type::Sampler3D); } break; -#line 2207 "./glsl.g" +#line 2256 "./glsl.g" case 227: { ast(1) = makeBasicType(T_USAMPLERCUBE, Type::SamplerCube); } break; -#line 2214 "./glsl.g" +#line 2263 "./glsl.g" case 228: { ast(1) = makeBasicType(T_USAMPLER1DARRAY, Type::Sampler1DArray); } break; -#line 2221 "./glsl.g" +#line 2270 "./glsl.g" case 229: { ast(1) = makeBasicType(T_USAMPLER2DARRAY, Type::Sampler2DArray); } break; -#line 2228 "./glsl.g" +#line 2277 "./glsl.g" case 230: { ast(1) = makeBasicType(T_USAMPLERCUBEARRAY, Type::SamplerCubeArray); } break; -#line 2235 "./glsl.g" +#line 2284 "./glsl.g" case 231: { ast(1) = makeBasicType(T_SAMPLER2DRECT, Type::Sampler2DRect); } break; -#line 2242 "./glsl.g" +#line 2291 "./glsl.g" case 232: { ast(1) = makeBasicType(T_SAMPLER2DRECTSHADOW, Type::Sampler2DRectShadow); } break; -#line 2249 "./glsl.g" +#line 2298 "./glsl.g" case 233: { ast(1) = makeBasicType(T_ISAMPLER2DRECT, Type::Sampler2DRect); } break; -#line 2256 "./glsl.g" +#line 2305 "./glsl.g" case 234: { ast(1) = makeBasicType(T_USAMPLER2DRECT, Type::Sampler2DRect); } break; -#line 2263 "./glsl.g" +#line 2312 "./glsl.g" case 235: { ast(1) = makeBasicType(T_SAMPLERBUFFER, Type::SamplerBuffer); } break; -#line 2270 "./glsl.g" +#line 2319 "./glsl.g" case 236: { ast(1) = makeBasicType(T_ISAMPLERBUFFER, Type::SamplerBuffer); } break; -#line 2277 "./glsl.g" +#line 2326 "./glsl.g" case 237: { ast(1) = makeBasicType(T_USAMPLERBUFFER, Type::SamplerBuffer); } break; -#line 2284 "./glsl.g" +#line 2333 "./glsl.g" case 238: { ast(1) = makeBasicType(T_SAMPLER2DMS, Type::Sampler2DMS); } break; -#line 2291 "./glsl.g" +#line 2340 "./glsl.g" case 239: { ast(1) = makeBasicType(T_ISAMPLER2DMS, Type::Sampler2DMS); } break; -#line 2298 "./glsl.g" +#line 2347 "./glsl.g" case 240: { ast(1) = makeBasicType(T_USAMPLER2DMS, Type::Sampler2DMS); } break; -#line 2305 "./glsl.g" +#line 2354 "./glsl.g" case 241: { ast(1) = makeBasicType(T_SAMPLER2DMSARRAY, Type::Sampler2DMSArray); } break; -#line 2312 "./glsl.g" +#line 2361 "./glsl.g" case 242: { ast(1) = makeBasicType(T_ISAMPLER2DMSARRAY, Type::Sampler2DMSArray); } break; -#line 2319 "./glsl.g" +#line 2368 "./glsl.g" case 243: { ast(1) = makeBasicType(T_USAMPLER2DMSARRAY, Type::Sampler2DMSArray); } break; -#line 2326 "./glsl.g" +#line 2375 "./glsl.g" case 244: { // nothing to do. } break; -#line 2333 "./glsl.g" +#line 2382 "./glsl.g" case 245: { ast(1) = makeAstNode<NamedType>(string(1)); } break; -#line 2340 "./glsl.g" +#line 2389 "./glsl.g" case 246: { sym(1).precision = Type::Highp; } break; -#line 2347 "./glsl.g" +#line 2396 "./glsl.g" case 247: { sym(1).precision = Type::Mediump; } break; -#line 2354 "./glsl.g" +#line 2403 "./glsl.g" case 248: { sym(1).precision = Type::Lowp; } break; -#line 2361 "./glsl.g" +#line 2410 "./glsl.g" case 249: { ast(1) = makeAstNode<StructType>(string(2), sym(4).field_list); } break; -#line 2368 "./glsl.g" +#line 2417 "./glsl.g" case 250: { ast(1) = makeAstNode<StructType>(sym(3).field_list); } break; -#line 2375 "./glsl.g" +#line 2424 "./glsl.g" case 251: { // nothing to do. } break; -#line 2382 "./glsl.g" +#line 2431 "./glsl.g" case 252: { sym(1).field_list = appendLists(sym(1).field_list, sym(2).field_list); } break; -#line 2389 "./glsl.g" +#line 2438 "./glsl.g" case 253: { sym(1).field_list = StructType::fixInnerTypes(type(1), sym(2).field_list); } break; -#line 2396 "./glsl.g" +#line 2445 "./glsl.g" case 254: { sym(1).field_list = StructType::fixInnerTypes @@ -1767,321 +1814,321 @@ case 254: { sym(1).type_qualifier.layout_list), sym(3).field_list); } break; -#line 2406 "./glsl.g" +#line 2455 "./glsl.g" case 255: { // nothing to do. sym(1).field_list = makeAstNode< List<StructType::Field *> >(sym(1).field); } break; -#line 2414 "./glsl.g" +#line 2463 "./glsl.g" case 256: { sym(1).field_list = makeAstNode< List<StructType::Field *> >(sym(1).field_list, sym(3).field); } break; -#line 2421 "./glsl.g" +#line 2470 "./glsl.g" case 257: { sym(1).field = makeAstNode<StructType::Field>(string(1)); } break; -#line 2428 "./glsl.g" +#line 2477 "./glsl.g" case 258: { sym(1).field = makeAstNode<StructType::Field> (string(1), makeAstNode<ArrayType>((Type *)0)); } break; -#line 2436 "./glsl.g" +#line 2485 "./glsl.g" case 259: { sym(1).field = makeAstNode<StructType::Field> (string(1), makeAstNode<ArrayType>((Type *)0, expression(3))); } break; -#line 2444 "./glsl.g" +#line 2493 "./glsl.g" case 260: { // nothing to do. } break; -#line 2451 "./glsl.g" +#line 2500 "./glsl.g" case 261: { ast(1) = makeAstNode<DeclarationStatement>(sym(1).declaration_list); } break; -#line 2458 "./glsl.g" +#line 2507 "./glsl.g" case 262: { // nothing to do. } break; -#line 2465 "./glsl.g" +#line 2514 "./glsl.g" case 263: { // nothing to do. } break; -#line 2472 "./glsl.g" +#line 2521 "./glsl.g" case 264: { // nothing to do. } break; -#line 2479 "./glsl.g" +#line 2528 "./glsl.g" case 265: { // nothing to do. } break; -#line 2486 "./glsl.g" +#line 2535 "./glsl.g" case 266: { // nothing to do. } break; -#line 2493 "./glsl.g" +#line 2542 "./glsl.g" case 267: { // nothing to do. } break; -#line 2500 "./glsl.g" +#line 2549 "./glsl.g" case 268: { // nothing to do. } break; -#line 2507 "./glsl.g" +#line 2556 "./glsl.g" case 269: { // nothing to do. } break; -#line 2514 "./glsl.g" +#line 2563 "./glsl.g" case 270: { // nothing to do. } break; -#line 2521 "./glsl.g" +#line 2570 "./glsl.g" case 271: { ast(1) = makeAstNode<CompoundStatement>(); } break; -#line 2528 "./glsl.g" +#line 2577 "./glsl.g" case 272: { ast(1) = makeAstNode<CompoundStatement>(sym(2).statement_list); } break; -#line 2535 "./glsl.g" +#line 2584 "./glsl.g" case 273: { // nothing to do. } break; -#line 2542 "./glsl.g" +#line 2591 "./glsl.g" case 274: { // nothing to do. } break; -#line 2549 "./glsl.g" +#line 2598 "./glsl.g" case 275: { ast(1) = makeAstNode<CompoundStatement>(); } break; -#line 2556 "./glsl.g" +#line 2605 "./glsl.g" case 276: { ast(1) = makeAstNode<CompoundStatement>(sym(2).statement_list); } break; -#line 2563 "./glsl.g" +#line 2612 "./glsl.g" case 277: { sym(1).statement_list = makeAstNode< List<Statement *> >(sym(1).statement); } break; -#line 2570 "./glsl.g" +#line 2619 "./glsl.g" case 278: { sym(1).statement_list = makeAstNode< List<Statement *> >(sym(1).statement_list, sym(2).statement); } break; -#line 2577 "./glsl.g" +#line 2626 "./glsl.g" case 279: { ast(1) = makeAstNode<CompoundStatement>(); // Empty statement } break; -#line 2584 "./glsl.g" +#line 2633 "./glsl.g" case 280: { ast(1) = makeAstNode<ExpressionStatement>(expression(1)); } break; -#line 2591 "./glsl.g" +#line 2640 "./glsl.g" case 281: { ast(1) = makeAstNode<IfStatement>(expression(3), sym(5).ifstmt.thenClause, sym(5).ifstmt.elseClause); } break; -#line 2598 "./glsl.g" +#line 2647 "./glsl.g" case 282: { sym(1).ifstmt.thenClause = statement(1); sym(1).ifstmt.elseClause = statement(3); } break; -#line 2606 "./glsl.g" +#line 2655 "./glsl.g" case 283: { sym(1).ifstmt.thenClause = statement(1); sym(1).ifstmt.elseClause = 0; } break; -#line 2614 "./glsl.g" +#line 2663 "./glsl.g" case 284: { // nothing to do. } break; -#line 2621 "./glsl.g" +#line 2670 "./glsl.g" case 285: { ast(1) = makeAstNode<DeclarationExpression> (type(1), string(2), expression(4)); } break; -#line 2629 "./glsl.g" +#line 2678 "./glsl.g" case 286: { ast(1) = makeAstNode<SwitchStatement>(expression(3), statement(6)); } break; -#line 2636 "./glsl.g" +#line 2685 "./glsl.g" case 287: { ast(1) = makeAstNode<CompoundStatement>(); } break; -#line 2643 "./glsl.g" +#line 2692 "./glsl.g" case 288: { ast(1) = makeAstNode<CompoundStatement>(sym(1).statement_list); } break; -#line 2650 "./glsl.g" +#line 2699 "./glsl.g" case 289: { ast(1) = makeAstNode<CaseLabelStatement>(expression(2)); } break; -#line 2657 "./glsl.g" +#line 2706 "./glsl.g" case 290: { ast(1) = makeAstNode<CaseLabelStatement>(); } break; -#line 2664 "./glsl.g" +#line 2713 "./glsl.g" case 291: { ast(1) = makeAstNode<WhileStatement>(expression(3), statement(5)); } break; -#line 2671 "./glsl.g" +#line 2720 "./glsl.g" case 292: { ast(1) = makeAstNode<DoStatement>(statement(2), expression(5)); } break; -#line 2678 "./glsl.g" +#line 2727 "./glsl.g" case 293: { ast(1) = makeAstNode<ForStatement>(statement(3), sym(4).forstmt.condition, sym(4).forstmt.increment, statement(6)); } break; -#line 2685 "./glsl.g" +#line 2734 "./glsl.g" case 294: { // nothing to do. } break; -#line 2692 "./glsl.g" +#line 2741 "./glsl.g" case 295: { // nothing to do. } break; -#line 2699 "./glsl.g" +#line 2748 "./glsl.g" case 296: { // nothing to do. } break; -#line 2706 "./glsl.g" +#line 2755 "./glsl.g" case 297: { // nothing to do. } break; -#line 2713 "./glsl.g" +#line 2762 "./glsl.g" case 298: { sym(1).forstmt.condition = expression(1); sym(1).forstmt.increment = 0; } break; -#line 2721 "./glsl.g" +#line 2770 "./glsl.g" case 299: { sym(1).forstmt.condition = expression(1); sym(1).forstmt.increment = expression(3); } break; -#line 2729 "./glsl.g" +#line 2778 "./glsl.g" case 300: { ast(1) = makeAstNode<JumpStatement>(AST::Kind_Continue); } break; -#line 2736 "./glsl.g" +#line 2785 "./glsl.g" case 301: { ast(1) = makeAstNode<JumpStatement>(AST::Kind_Break); } break; -#line 2743 "./glsl.g" +#line 2792 "./glsl.g" case 302: { ast(1) = makeAstNode<ReturnStatement>(); } break; -#line 2750 "./glsl.g" +#line 2799 "./glsl.g" case 303: { ast(1) = makeAstNode<ReturnStatement>(expression(2)); } break; -#line 2757 "./glsl.g" +#line 2806 "./glsl.g" case 304: { ast(1) = makeAstNode<JumpStatement>(AST::Kind_Discard); } break; -#line 2764 "./glsl.g" +#line 2813 "./glsl.g" case 305: { ast(1) = makeAstNode<TranslationUnit>(sym(1).declaration_list); } break; -#line 2771 "./glsl.g" +#line 2820 "./glsl.g" case 306: { if (sym(1).declaration) { @@ -2092,7 +2139,7 @@ case 306: { } } break; -#line 2783 "./glsl.g" +#line 2832 "./glsl.g" case 307: { if (sym(1).declaration_list && sym(2).declaration) { @@ -2110,37 +2157,37 @@ case 307: { } } break; -#line 2802 "./glsl.g" +#line 2851 "./glsl.g" case 308: { - // ast(1) = new ...AST(...); + // nothing to do. } break; -#line 2809 "./glsl.g" +#line 2858 "./glsl.g" case 309: { // nothing to do. } break; -#line 2816 "./glsl.g" +#line 2865 "./glsl.g" case 310: { ast(1) = 0; } break; -#line 2823 "./glsl.g" +#line 2872 "./glsl.g" case 311: { - // ast(1) = new ...AST(...); + function(1)->body = statement(2); } break; -#line 2830 "./glsl.g" +#line 2879 "./glsl.g" case 312: { ast(1) = 0; } break; -#line 2838 "./glsl.g" +#line 2887 "./glsl.g" } // end switch } // end Parser::reduce() diff --git a/src/libs/glsl/glslparser.h b/src/libs/glsl/glslparser.h index 1e93ba50e7..772a96ae5a 100644 --- a/src/libs/glsl/glslparser.h +++ b/src/libs/glsl/glslparser.h @@ -83,7 +83,8 @@ public: Type *type; const std::string *name; } param_declarator; - // ### ast nodes... + ParameterDeclaration *param_declaration; + FunctionDeclaration *function_declaration; }; Parser(Engine *engine, const char *source, unsigned size, int variant); @@ -99,6 +100,7 @@ private: Expression *&expression(int n) { return _symStack[_tos + n - 1].expression; } Statement *&statement(int n) { return _symStack[_tos + n - 1].statement; } Type *&type(int n) { return _symStack[_tos + n - 1].type; } + FunctionDeclaration *&function(int n) { return _symStack[_tos + n - 1].function_declaration; } inline int consumeToken() { return _index++; } inline const Token &tokenAt(int index) const { return _tokens.at(index); } |