John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 1 | // |
| 2 | //Copyright (C) 2016 Google, Inc. |
| 3 | // |
| 4 | //All rights reserved. |
| 5 | // |
| 6 | //Redistribution and use in source and binary forms, with or without |
| 7 | //modification, are permitted provided that the following conditions |
| 8 | //are met: |
| 9 | // |
| 10 | // Redistributions of source code must retain the above copyright |
| 11 | // notice, this list of conditions and the following disclaimer. |
| 12 | // |
| 13 | // Redistributions in binary form must reproduce the above |
| 14 | // copyright notice, this list of conditions and the following |
| 15 | // disclaimer in the documentation and/or other materials provided |
| 16 | // with the distribution. |
| 17 | // |
| 18 | // Neither the name of Google, Inc., nor the names of its |
| 19 | // contributors may be used to endorse or promote products derived |
| 20 | // from this software without specific prior written permission. |
| 21 | // |
| 22 | //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 | //"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 | //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 25 | //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 26 | //COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 27 | //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 28 | //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 29 | //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 30 | //CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 31 | //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 32 | //ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 33 | //POSSIBILITY OF SUCH DAMAGE. |
| 34 | // |
| 35 | |
| 36 | #ifndef HLSLGRAMMAR_H_ |
| 37 | #define HLSLGRAMMAR_H_ |
| 38 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 39 | #include "hlslParseHelper.h" |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 40 | #include "hlslOpMap.h" |
John Kessenich | 9c86c6a | 2016-05-03 22:49:24 -0600 | [diff] [blame] | 41 | #include "hlslTokenStream.h" |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 42 | |
| 43 | namespace glslang { |
| 44 | |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 45 | // Should just be the grammar aspect of HLSL. |
| 46 | // Described in more detail in hlslGrammar.cpp. |
| 47 | |
John Kessenich | 9c86c6a | 2016-05-03 22:49:24 -0600 | [diff] [blame] | 48 | class HlslGrammar : public HlslTokenStream { |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 49 | public: |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 50 | HlslGrammar(HlslScanContext& scanner, HlslParseContext& parseContext) |
John Kessenich | 9c86c6a | 2016-05-03 22:49:24 -0600 | [diff] [blame] | 51 | : HlslTokenStream(scanner), parseContext(parseContext), intermediate(parseContext.intermediate) { } |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 52 | virtual ~HlslGrammar() { } |
| 53 | |
| 54 | bool parse(); |
| 55 | |
| 56 | protected: |
| 57 | void expected(const char*); |
John Kessenich | aecd497 | 2016-03-14 10:46:34 -0600 | [diff] [blame] | 58 | bool acceptIdentifier(HlslToken&); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 59 | bool acceptCompilationUnit(); |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 60 | bool acceptDeclaration(TIntermNode*& node); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 61 | bool acceptFullySpecifiedType(TType&); |
| 62 | void acceptQualifier(TQualifier&); |
| 63 | bool acceptType(TType&); |
John Kessenich | e6e7494 | 2016-06-11 16:43:14 -0600 | [diff] [blame] | 64 | bool acceptStruct(TType&); |
| 65 | bool acceptStructDeclarationList(TTypeList*&); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 66 | bool acceptFunctionParameters(TFunction&); |
| 67 | bool acceptParameterDeclaration(TFunction&); |
| 68 | bool acceptFunctionDefinition(TFunction&, TIntermNode*&); |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 69 | bool acceptParenExpression(TIntermTyped*&); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 70 | bool acceptExpression(TIntermTyped*&); |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 71 | bool acceptAssignmentExpression(TIntermTyped*&); |
| 72 | bool acceptBinaryExpression(TIntermTyped*&, PrecedenceLevel); |
| 73 | bool acceptUnaryExpression(TIntermTyped*&); |
| 74 | bool acceptPostfixExpression(TIntermTyped*&); |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 75 | bool acceptConstructor(TIntermTyped*&); |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 76 | bool acceptFunctionCall(HlslToken, TIntermTyped*&); |
John Kessenich | 4678ca9 | 2016-05-13 09:33:42 -0600 | [diff] [blame] | 77 | bool acceptArguments(TFunction*, TIntermTyped*&); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 78 | bool acceptLiteral(TIntermTyped*&); |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 79 | bool acceptCompoundStatement(TIntermNode*&); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 80 | bool acceptStatement(TIntermNode*&); |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 81 | bool acceptScopedStatement(TIntermNode*&); |
John Kessenich | 077e052 | 2016-06-09 02:02:17 -0600 | [diff] [blame] | 82 | bool acceptScopedCompoundStatement(TIntermNode*&); |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 83 | bool acceptNestedStatement(TIntermNode*&); |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 84 | void acceptAttributes(); |
| 85 | bool acceptSelectionStatement(TIntermNode*&); |
| 86 | bool acceptSwitchStatement(TIntermNode*&); |
| 87 | bool acceptIterationStatement(TIntermNode*&); |
| 88 | bool acceptJumpStatement(TIntermNode*&); |
| 89 | bool acceptCaseLabel(TIntermNode*&); |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 90 | void acceptArraySpecifier(TArraySizes*&); |
John Kessenich | 630dd7d | 2016-06-12 23:52:12 -0600 | [diff] [blame] | 91 | void acceptPostDecls(TType&); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 92 | |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 93 | HlslParseContext& parseContext; // state of parsing and helper functions for building the intermediate |
| 94 | TIntermediate& intermediate; // the final product, the intermediate representation, includes the AST |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | } // end namespace glslang |
| 98 | |
| 99 | #endif // HLSLGRAMMAR_H_ |