John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 1 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 2 | // Copyright (C) 2016 Google, Inc. |
| 3 | // Copyright (C) 2016 LunarG, Inc. |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 4 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 5 | // All rights reserved. |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 6 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 7 | // Redistribution and use in source and binary forms, with or without |
| 8 | // modification, are permitted provided that the following conditions |
| 9 | // are met: |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 10 | // |
| 11 | // Redistributions of source code must retain the above copyright |
| 12 | // notice, this list of conditions and the following disclaimer. |
| 13 | // |
| 14 | // Redistributions in binary form must reproduce the above |
| 15 | // copyright notice, this list of conditions and the following |
| 16 | // disclaimer in the documentation and/or other materials provided |
| 17 | // with the distribution. |
| 18 | // |
| 19 | // Neither the name of Google, Inc., nor the names of its |
| 20 | // contributors may be used to endorse or promote products derived |
| 21 | // from this software without specific prior written permission. |
| 22 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 26 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 27 | // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 28 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 29 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 30 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 31 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 32 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 33 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 34 | // POSSIBILITY OF SUCH DAMAGE. |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 35 | // |
| 36 | |
| 37 | #ifndef HLSLGRAMMAR_H_ |
| 38 | #define HLSLGRAMMAR_H_ |
| 39 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 40 | #include "hlslParseHelper.h" |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 41 | #include "hlslOpMap.h" |
John Kessenich | 9c86c6a | 2016-05-03 22:49:24 -0600 | [diff] [blame] | 42 | #include "hlslTokenStream.h" |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 43 | |
| 44 | namespace glslang { |
| 45 | |
John Kessenich | 088d52b | 2017-03-11 17:55:28 -0700 | [diff] [blame] | 46 | class TAttributeMap; |
| 47 | class TFunctionDeclarator; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 48 | |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 49 | // Should just be the grammar aspect of HLSL. |
| 50 | // Described in more detail in hlslGrammar.cpp. |
| 51 | |
John Kessenich | 9c86c6a | 2016-05-03 22:49:24 -0600 | [diff] [blame] | 52 | class HlslGrammar : public HlslTokenStream { |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 53 | public: |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 54 | HlslGrammar(HlslScanContext& scanner, HlslParseContext& parseContext) |
John Kessenich | 0320d09 | 2017-06-13 22:22:52 -0600 | [diff] [blame] | 55 | : HlslTokenStream(scanner), parseContext(parseContext), intermediate(parseContext.intermediate), |
| 56 | typeIdentifiers(false) { } |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 57 | virtual ~HlslGrammar() { } |
| 58 | |
| 59 | bool parse(); |
| 60 | |
| 61 | protected: |
John Kessenich | 7f349c7 | 2016-07-08 22:09:10 -0600 | [diff] [blame] | 62 | HlslGrammar(); |
| 63 | HlslGrammar& operator=(const HlslGrammar&); |
| 64 | |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 65 | void expected(const char*); |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 66 | void unimplemented(const char*); |
John Kessenich | aecd497 | 2016-03-14 10:46:34 -0600 | [diff] [blame] | 67 | bool acceptIdentifier(HlslToken&); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 68 | bool acceptCompilationUnit(); |
John Kessenich | 8f9fdc9 | 2017-03-30 16:22:26 -0600 | [diff] [blame] | 69 | bool acceptDeclarationList(TIntermNode*&); |
John Kessenich | 02467d8 | 2017-01-19 15:41:47 -0700 | [diff] [blame] | 70 | bool acceptDeclaration(TIntermNode*&); |
John Kessenich | 5bc4d9a | 2016-06-20 01:22:38 -0600 | [diff] [blame] | 71 | bool acceptControlDeclaration(TIntermNode*& node); |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 72 | bool acceptSamplerDeclarationDX9(TType&); |
| 73 | bool acceptSamplerState(); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 74 | bool acceptFullySpecifiedType(TType&); |
John Kessenich | 54ee28f | 2017-03-11 14:13:00 -0700 | [diff] [blame] | 75 | bool acceptFullySpecifiedType(TType&, TIntermNode*& nodeList); |
John Kessenich | b9e3912 | 2016-08-17 10:22:08 -0600 | [diff] [blame] | 76 | bool acceptQualifier(TQualifier&); |
| 77 | bool acceptLayoutQualifierList(TQualifier&); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 78 | bool acceptType(TType&); |
John Kessenich | 54ee28f | 2017-03-11 14:13:00 -0700 | [diff] [blame] | 79 | bool acceptType(TType&, TIntermNode*& nodeList); |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 80 | bool acceptTemplateVecMatBasicType(TBasicType&); |
LoopDawg | 6daaa4f | 2016-06-23 19:13:48 -0600 | [diff] [blame] | 81 | bool acceptVectorTemplateType(TType&); |
| 82 | bool acceptMatrixTemplateType(TType&); |
steve-lunarg | 067eb9b | 2017-04-01 15:34:48 -0600 | [diff] [blame] | 83 | bool acceptTessellationDeclType(TBuiltInVariable&); |
steve-lunarg | 858c928 | 2017-01-07 08:54:10 -0700 | [diff] [blame] | 84 | bool acceptTessellationPatchTemplateType(TType&); |
steve-lunarg | f49cdf4 | 2016-11-17 15:04:20 -0700 | [diff] [blame] | 85 | bool acceptStreamOutTemplateType(TType&, TLayoutGeometry&); |
| 86 | bool acceptOutputPrimitiveGeometry(TLayoutGeometry&); |
John Kessenich | a1e2d49 | 2016-09-20 13:22:58 -0600 | [diff] [blame] | 87 | bool acceptAnnotations(TQualifier&); |
LoopDawg | 4886f69 | 2016-06-29 10:58:58 -0600 | [diff] [blame] | 88 | bool acceptSamplerType(TType&); |
| 89 | bool acceptTextureType(TType&); |
steve-lunarg | 5da1f03 | 2017-02-12 17:50:28 -0700 | [diff] [blame] | 90 | bool acceptStructBufferType(TType&); |
steve-lunarg | a766b83 | 2017-04-25 09:30:28 -0600 | [diff] [blame] | 91 | bool acceptConstantBufferType(TType&); |
John Kessenich | 54ee28f | 2017-03-11 14:13:00 -0700 | [diff] [blame] | 92 | bool acceptStruct(TType&, TIntermNode*& nodeList); |
John Kessenich | aa3c64c | 2017-03-28 09:52:38 -0600 | [diff] [blame] | 93 | bool acceptStructDeclarationList(TTypeList*&, TIntermNode*& nodeList, TVector<TFunctionDeclarator>&); |
John Kessenich | f3d88bd | 2017-03-19 12:24:29 -0600 | [diff] [blame] | 94 | bool acceptMemberFunctionDefinition(TIntermNode*& nodeList, const TType&, const TString& memberName, |
| 95 | TFunctionDeclarator&); |
John Kessenich | 5f934b0 | 2016-03-13 17:58:25 -0600 | [diff] [blame] | 96 | bool acceptFunctionParameters(TFunction&); |
| 97 | bool acceptParameterDeclaration(TFunction&); |
John Kessenich | b16f7e6 | 2017-03-11 19:32:47 -0700 | [diff] [blame] | 98 | bool acceptFunctionDefinition(TFunctionDeclarator&, TIntermNode*& nodeList, TVector<HlslToken>* deferredTokens); |
John Kessenich | 088d52b | 2017-03-11 17:55:28 -0700 | [diff] [blame] | 99 | bool acceptFunctionBody(TFunctionDeclarator& declarator, TIntermNode*& nodeList); |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 100 | bool acceptParenExpression(TIntermTyped*&); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 101 | bool acceptExpression(TIntermTyped*&); |
John Kessenich | 0735424 | 2016-07-01 19:58:06 -0600 | [diff] [blame] | 102 | bool acceptInitializer(TIntermTyped*&); |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 103 | bool acceptAssignmentExpression(TIntermTyped*&); |
John Kessenich | 00957f8 | 2016-07-27 10:39:57 -0600 | [diff] [blame] | 104 | bool acceptConditionalExpression(TIntermTyped*&); |
John Kessenich | 34fb036 | 2016-05-03 23:17:20 -0600 | [diff] [blame] | 105 | bool acceptBinaryExpression(TIntermTyped*&, PrecedenceLevel); |
| 106 | bool acceptUnaryExpression(TIntermTyped*&); |
| 107 | bool acceptPostfixExpression(TIntermTyped*&); |
John Kessenich | d016be1 | 2016-03-13 11:24:20 -0600 | [diff] [blame] | 108 | bool acceptConstructor(TIntermTyped*&); |
John Kessenich | 8f9fdc9 | 2017-03-30 16:22:26 -0600 | [diff] [blame] | 109 | bool acceptFunctionCall(const TSourceLoc&, TString& name, TIntermTyped*&, TIntermTyped* objectBase); |
John Kessenich | 4678ca9 | 2016-05-13 09:33:42 -0600 | [diff] [blame] | 110 | bool acceptArguments(TFunction*, TIntermTyped*&); |
John Kessenich | 87142c7 | 2016-03-12 20:24:24 -0700 | [diff] [blame] | 111 | bool acceptLiteral(TIntermTyped*&); |
John Kessenich | 0e07119 | 2017-06-06 11:37:33 -0600 | [diff] [blame] | 112 | bool acceptSimpleStatement(TIntermNode*&); |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 113 | bool acceptCompoundStatement(TIntermNode*&); |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 114 | bool acceptScopedStatement(TIntermNode*&); |
John Kessenich | 077e052 | 2016-06-09 02:02:17 -0600 | [diff] [blame] | 115 | bool acceptScopedCompoundStatement(TIntermNode*&); |
John Kessenich | 0e07119 | 2017-06-06 11:37:33 -0600 | [diff] [blame] | 116 | bool acceptStatement(TIntermNode*&); |
John Kessenich | 0d2b6de | 2016-06-05 11:23:11 -0600 | [diff] [blame] | 117 | bool acceptNestedStatement(TIntermNode*&); |
steve-lunarg | 1868b14 | 2016-10-20 13:07:10 -0600 | [diff] [blame] | 118 | void acceptAttributes(TAttributeMap&); |
Rex Xu | 57e6592 | 2017-07-04 23:23:40 +0800 | [diff] [blame] | 119 | bool acceptSelectionStatement(TIntermNode*&, const TAttributeMap&); |
| 120 | bool acceptSwitchStatement(TIntermNode*&, const TAttributeMap&); |
steve-lunarg | f1709e7 | 2017-05-02 20:14:50 -0600 | [diff] [blame] | 121 | bool acceptIterationStatement(TIntermNode*&, const TAttributeMap&); |
John Kessenich | 21472ae | 2016-06-04 11:46:33 -0600 | [diff] [blame] | 122 | bool acceptJumpStatement(TIntermNode*&); |
| 123 | bool acceptCaseLabel(TIntermNode*&); |
John Kessenich | d02dc5d | 2016-07-01 00:04:11 -0600 | [diff] [blame] | 124 | bool acceptDefaultLabel(TIntermNode*&); |
John Kessenich | 19b92ff | 2016-06-19 11:50:34 -0600 | [diff] [blame] | 125 | void acceptArraySpecifier(TArraySizes*&); |
John Kessenich | 854fe24 | 2017-03-02 14:30:59 -0700 | [diff] [blame] | 126 | bool acceptPostDecls(TQualifier&); |
steve-lunarg | 26d3145 | 2016-12-23 18:56:57 -0700 | [diff] [blame] | 127 | bool acceptDefaultParameterDeclaration(const TType&, TIntermTyped*&); |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 128 | |
John Kessenich | b16f7e6 | 2017-03-11 19:32:47 -0700 | [diff] [blame] | 129 | bool captureBlockTokens(TVector<HlslToken>& tokens); |
John Kessenich | 0320d09 | 2017-06-13 22:22:52 -0600 | [diff] [blame] | 130 | const char* getTypeString(EHlslTokenClass tokenClass) const; |
John Kessenich | b16f7e6 | 2017-03-11 19:32:47 -0700 | [diff] [blame] | 131 | |
John Kessenich | 078d7f2 | 2016-03-14 10:02:11 -0600 | [diff] [blame] | 132 | HlslParseContext& parseContext; // state of parsing and helper functions for building the intermediate |
| 133 | TIntermediate& intermediate; // the final product, the intermediate representation, includes the AST |
John Kessenich | 0320d09 | 2017-06-13 22:22:52 -0600 | [diff] [blame] | 134 | bool typeIdentifiers; // shader uses some types as identifiers |
John Kessenich | e01a9bc | 2016-03-12 20:11:22 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | } // end namespace glslang |
| 138 | |
| 139 | #endif // HLSLGRAMMAR_H_ |