blob: b4a948f295adbef3d163415fe8249314557b50db [file] [log] [blame]
John Kesseniche01a9bc2016-03-12 20:11:22 -07001//
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 Kesseniche01a9bc2016-03-12 20:11:22 -070039#include "hlslParseHelper.h"
John Kessenich34fb0362016-05-03 23:17:20 -060040#include "hlslOpMap.h"
John Kessenich9c86c6a2016-05-03 22:49:24 -060041#include "hlslTokenStream.h"
John Kesseniche01a9bc2016-03-12 20:11:22 -070042
43namespace glslang {
44
John Kessenich078d7f22016-03-14 10:02:11 -060045 // Should just be the grammar aspect of HLSL.
46 // Described in more detail in hlslGrammar.cpp.
47
John Kessenich9c86c6a2016-05-03 22:49:24 -060048 class HlslGrammar : public HlslTokenStream {
John Kesseniche01a9bc2016-03-12 20:11:22 -070049 public:
John Kessenich078d7f22016-03-14 10:02:11 -060050 HlslGrammar(HlslScanContext& scanner, HlslParseContext& parseContext)
John Kessenich9c86c6a2016-05-03 22:49:24 -060051 : HlslTokenStream(scanner), parseContext(parseContext), intermediate(parseContext.intermediate) { }
John Kesseniche01a9bc2016-03-12 20:11:22 -070052 virtual ~HlslGrammar() { }
53
54 bool parse();
55
56 protected:
57 void expected(const char*);
John Kessenichaecd4972016-03-14 10:46:34 -060058 bool acceptIdentifier(HlslToken&);
John Kesseniche01a9bc2016-03-12 20:11:22 -070059 bool acceptCompilationUnit();
John Kessenichd016be12016-03-13 11:24:20 -060060 bool acceptDeclaration(TIntermNode*& node);
John Kessenich87142c72016-03-12 20:24:24 -070061 bool acceptFullySpecifiedType(TType&);
62 void acceptQualifier(TQualifier&);
63 bool acceptType(TType&);
John Kesseniche6e74942016-06-11 16:43:14 -060064 bool acceptStruct(TType&);
65 bool acceptStructDeclarationList(TTypeList*&);
John Kessenich5f934b02016-03-13 17:58:25 -060066 bool acceptFunctionParameters(TFunction&);
67 bool acceptParameterDeclaration(TFunction&);
68 bool acceptFunctionDefinition(TFunction&, TIntermNode*&);
John Kessenich0d2b6de2016-06-05 11:23:11 -060069 bool acceptParenExpression(TIntermTyped*&);
John Kessenich87142c72016-03-12 20:24:24 -070070 bool acceptExpression(TIntermTyped*&);
John Kessenich34fb0362016-05-03 23:17:20 -060071 bool acceptAssignmentExpression(TIntermTyped*&);
72 bool acceptBinaryExpression(TIntermTyped*&, PrecedenceLevel);
73 bool acceptUnaryExpression(TIntermTyped*&);
74 bool acceptPostfixExpression(TIntermTyped*&);
John Kessenichd016be12016-03-13 11:24:20 -060075 bool acceptConstructor(TIntermTyped*&);
John Kessenich34fb0362016-05-03 23:17:20 -060076 bool acceptFunctionCall(HlslToken, TIntermTyped*&);
John Kessenich4678ca92016-05-13 09:33:42 -060077 bool acceptArguments(TFunction*, TIntermTyped*&);
John Kessenich87142c72016-03-12 20:24:24 -070078 bool acceptLiteral(TIntermTyped*&);
John Kessenich21472ae2016-06-04 11:46:33 -060079 bool acceptCompoundStatement(TIntermNode*&);
John Kessenich5f934b02016-03-13 17:58:25 -060080 bool acceptStatement(TIntermNode*&);
John Kessenich0d2b6de2016-06-05 11:23:11 -060081 bool acceptScopedStatement(TIntermNode*&);
John Kessenich077e0522016-06-09 02:02:17 -060082 bool acceptScopedCompoundStatement(TIntermNode*&);
John Kessenich0d2b6de2016-06-05 11:23:11 -060083 bool acceptNestedStatement(TIntermNode*&);
John Kessenich21472ae2016-06-04 11:46:33 -060084 void acceptAttributes();
85 bool acceptSelectionStatement(TIntermNode*&);
86 bool acceptSwitchStatement(TIntermNode*&);
87 bool acceptIterationStatement(TIntermNode*&);
88 bool acceptJumpStatement(TIntermNode*&);
89 bool acceptCaseLabel(TIntermNode*&);
John Kessenich19b92ff2016-06-19 11:50:34 -060090 void acceptArraySpecifier(TArraySizes*&);
John Kessenich630dd7d2016-06-12 23:52:12 -060091 void acceptPostDecls(TType&);
John Kesseniche01a9bc2016-03-12 20:11:22 -070092
John Kessenich078d7f22016-03-14 10:02:11 -060093 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 Kesseniche01a9bc2016-03-12 20:11:22 -070095 };
96
97} // end namespace glslang
98
99#endif // HLSLGRAMMAR_H_