blob: ded8e96692bf67bee84da8accc8bd915d43562c5 [file] [log] [blame]
John Kesseniche01a9bc2016-03-12 20:11:22 -07001//
John Kessenich927608b2017-01-06 12:34:14 -07002// Copyright (C) 2016 Google, Inc.
3// Copyright (C) 2016 LunarG, Inc.
John Kesseniche01a9bc2016-03-12 20:11:22 -07004//
John Kessenich927608b2017-01-06 12:34:14 -07005// All rights reserved.
John Kesseniche01a9bc2016-03-12 20:11:22 -07006//
John Kessenich927608b2017-01-06 12:34:14 -07007// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
John Kesseniche01a9bc2016-03-12 20:11:22 -070010//
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 Kessenich927608b2017-01-06 12:34:14 -070023// 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 Kesseniche01a9bc2016-03-12 20:11:22 -070035//
36
37#ifndef HLSLGRAMMAR_H_
38#define HLSLGRAMMAR_H_
39
John Kesseniche01a9bc2016-03-12 20:11:22 -070040#include "hlslParseHelper.h"
John Kessenich34fb0362016-05-03 23:17:20 -060041#include "hlslOpMap.h"
John Kessenich9c86c6a2016-05-03 22:49:24 -060042#include "hlslTokenStream.h"
John Kesseniche01a9bc2016-03-12 20:11:22 -070043
44namespace glslang {
45
John Kessenich088d52b2017-03-11 17:55:28 -070046 class TAttributeMap;
47 class TFunctionDeclarator;
John Kessenichecba76f2017-01-06 00:34:48 -070048
John Kessenich078d7f22016-03-14 10:02:11 -060049 // Should just be the grammar aspect of HLSL.
50 // Described in more detail in hlslGrammar.cpp.
51
John Kessenich9c86c6a2016-05-03 22:49:24 -060052 class HlslGrammar : public HlslTokenStream {
John Kesseniche01a9bc2016-03-12 20:11:22 -070053 public:
John Kessenich078d7f22016-03-14 10:02:11 -060054 HlslGrammar(HlslScanContext& scanner, HlslParseContext& parseContext)
John Kessenich0320d092017-06-13 22:22:52 -060055 : HlslTokenStream(scanner), parseContext(parseContext), intermediate(parseContext.intermediate),
56 typeIdentifiers(false) { }
John Kesseniche01a9bc2016-03-12 20:11:22 -070057 virtual ~HlslGrammar() { }
58
59 bool parse();
60
61 protected:
John Kessenich7f349c72016-07-08 22:09:10 -060062 HlslGrammar();
63 HlslGrammar& operator=(const HlslGrammar&);
64
John Kesseniche01a9bc2016-03-12 20:11:22 -070065 void expected(const char*);
LoopDawg4886f692016-06-29 10:58:58 -060066 void unimplemented(const char*);
John Kessenichaecd4972016-03-14 10:46:34 -060067 bool acceptIdentifier(HlslToken&);
John Kesseniche01a9bc2016-03-12 20:11:22 -070068 bool acceptCompilationUnit();
John Kessenich8f9fdc92017-03-30 16:22:26 -060069 bool acceptDeclarationList(TIntermNode*&);
John Kessenich02467d82017-01-19 15:41:47 -070070 bool acceptDeclaration(TIntermNode*&);
John Kessenich5bc4d9a2016-06-20 01:22:38 -060071 bool acceptControlDeclaration(TIntermNode*& node);
LoopDawg4886f692016-06-29 10:58:58 -060072 bool acceptSamplerDeclarationDX9(TType&);
73 bool acceptSamplerState();
John Kessenich87142c72016-03-12 20:24:24 -070074 bool acceptFullySpecifiedType(TType&);
John Kessenich54ee28f2017-03-11 14:13:00 -070075 bool acceptFullySpecifiedType(TType&, TIntermNode*& nodeList);
John Kessenichb9e39122016-08-17 10:22:08 -060076 bool acceptQualifier(TQualifier&);
77 bool acceptLayoutQualifierList(TQualifier&);
John Kessenich87142c72016-03-12 20:24:24 -070078 bool acceptType(TType&);
John Kessenich54ee28f2017-03-11 14:13:00 -070079 bool acceptType(TType&, TIntermNode*& nodeList);
steve-lunargf49cdf42016-11-17 15:04:20 -070080 bool acceptTemplateVecMatBasicType(TBasicType&);
LoopDawg6daaa4f2016-06-23 19:13:48 -060081 bool acceptVectorTemplateType(TType&);
82 bool acceptMatrixTemplateType(TType&);
steve-lunarg067eb9b2017-04-01 15:34:48 -060083 bool acceptTessellationDeclType(TBuiltInVariable&);
steve-lunarg858c9282017-01-07 08:54:10 -070084 bool acceptTessellationPatchTemplateType(TType&);
steve-lunargf49cdf42016-11-17 15:04:20 -070085 bool acceptStreamOutTemplateType(TType&, TLayoutGeometry&);
86 bool acceptOutputPrimitiveGeometry(TLayoutGeometry&);
John Kessenicha1e2d492016-09-20 13:22:58 -060087 bool acceptAnnotations(TQualifier&);
LoopDawg4886f692016-06-29 10:58:58 -060088 bool acceptSamplerType(TType&);
89 bool acceptTextureType(TType&);
steve-lunarg5da1f032017-02-12 17:50:28 -070090 bool acceptStructBufferType(TType&);
steve-lunarga766b832017-04-25 09:30:28 -060091 bool acceptConstantBufferType(TType&);
John Kessenich54ee28f2017-03-11 14:13:00 -070092 bool acceptStruct(TType&, TIntermNode*& nodeList);
John Kessenichaa3c64c2017-03-28 09:52:38 -060093 bool acceptStructDeclarationList(TTypeList*&, TIntermNode*& nodeList, TVector<TFunctionDeclarator>&);
John Kessenichf3d88bd2017-03-19 12:24:29 -060094 bool acceptMemberFunctionDefinition(TIntermNode*& nodeList, const TType&, const TString& memberName,
95 TFunctionDeclarator&);
John Kessenich5f934b02016-03-13 17:58:25 -060096 bool acceptFunctionParameters(TFunction&);
97 bool acceptParameterDeclaration(TFunction&);
John Kessenichb16f7e62017-03-11 19:32:47 -070098 bool acceptFunctionDefinition(TFunctionDeclarator&, TIntermNode*& nodeList, TVector<HlslToken>* deferredTokens);
John Kessenich088d52b2017-03-11 17:55:28 -070099 bool acceptFunctionBody(TFunctionDeclarator& declarator, TIntermNode*& nodeList);
John Kessenich0d2b6de2016-06-05 11:23:11 -0600100 bool acceptParenExpression(TIntermTyped*&);
John Kessenich87142c72016-03-12 20:24:24 -0700101 bool acceptExpression(TIntermTyped*&);
John Kessenich07354242016-07-01 19:58:06 -0600102 bool acceptInitializer(TIntermTyped*&);
John Kessenich34fb0362016-05-03 23:17:20 -0600103 bool acceptAssignmentExpression(TIntermTyped*&);
John Kessenich00957f82016-07-27 10:39:57 -0600104 bool acceptConditionalExpression(TIntermTyped*&);
John Kessenich34fb0362016-05-03 23:17:20 -0600105 bool acceptBinaryExpression(TIntermTyped*&, PrecedenceLevel);
106 bool acceptUnaryExpression(TIntermTyped*&);
107 bool acceptPostfixExpression(TIntermTyped*&);
John Kessenichd016be12016-03-13 11:24:20 -0600108 bool acceptConstructor(TIntermTyped*&);
John Kessenich8f9fdc92017-03-30 16:22:26 -0600109 bool acceptFunctionCall(const TSourceLoc&, TString& name, TIntermTyped*&, TIntermTyped* objectBase);
John Kessenich4678ca92016-05-13 09:33:42 -0600110 bool acceptArguments(TFunction*, TIntermTyped*&);
John Kessenich87142c72016-03-12 20:24:24 -0700111 bool acceptLiteral(TIntermTyped*&);
John Kessenich0e071192017-06-06 11:37:33 -0600112 bool acceptSimpleStatement(TIntermNode*&);
John Kessenich21472ae2016-06-04 11:46:33 -0600113 bool acceptCompoundStatement(TIntermNode*&);
John Kessenich0d2b6de2016-06-05 11:23:11 -0600114 bool acceptScopedStatement(TIntermNode*&);
John Kessenich077e0522016-06-09 02:02:17 -0600115 bool acceptScopedCompoundStatement(TIntermNode*&);
John Kessenich0e071192017-06-06 11:37:33 -0600116 bool acceptStatement(TIntermNode*&);
John Kessenich0d2b6de2016-06-05 11:23:11 -0600117 bool acceptNestedStatement(TIntermNode*&);
steve-lunarg1868b142016-10-20 13:07:10 -0600118 void acceptAttributes(TAttributeMap&);
Rex Xu57e65922017-07-04 23:23:40 +0800119 bool acceptSelectionStatement(TIntermNode*&, const TAttributeMap&);
120 bool acceptSwitchStatement(TIntermNode*&, const TAttributeMap&);
steve-lunargf1709e72017-05-02 20:14:50 -0600121 bool acceptIterationStatement(TIntermNode*&, const TAttributeMap&);
John Kessenich21472ae2016-06-04 11:46:33 -0600122 bool acceptJumpStatement(TIntermNode*&);
123 bool acceptCaseLabel(TIntermNode*&);
John Kessenichd02dc5d2016-07-01 00:04:11 -0600124 bool acceptDefaultLabel(TIntermNode*&);
John Kessenich19b92ff2016-06-19 11:50:34 -0600125 void acceptArraySpecifier(TArraySizes*&);
John Kessenich854fe242017-03-02 14:30:59 -0700126 bool acceptPostDecls(TQualifier&);
steve-lunarg26d31452016-12-23 18:56:57 -0700127 bool acceptDefaultParameterDeclaration(const TType&, TIntermTyped*&);
John Kesseniche01a9bc2016-03-12 20:11:22 -0700128
John Kessenichb16f7e62017-03-11 19:32:47 -0700129 bool captureBlockTokens(TVector<HlslToken>& tokens);
John Kessenich0320d092017-06-13 22:22:52 -0600130 const char* getTypeString(EHlslTokenClass tokenClass) const;
John Kessenichb16f7e62017-03-11 19:32:47 -0700131
John Kessenich078d7f22016-03-14 10:02:11 -0600132 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 Kessenich0320d092017-06-13 22:22:52 -0600134 bool typeIdentifiers; // shader uses some types as identifiers
John Kesseniche01a9bc2016-03-12 20:11:22 -0700135 };
136
137} // end namespace glslang
138
139#endif // HLSLGRAMMAR_H_