blob: ba92c92246a56db5f6fd574d789970b21360b39e [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 Kessenich5f934b02016-03-13 17:58:25 -060064 bool acceptFunctionParameters(TFunction&);
65 bool acceptParameterDeclaration(TFunction&);
66 bool acceptFunctionDefinition(TFunction&, TIntermNode*&);
John Kessenich0d2b6de2016-06-05 11:23:11 -060067 bool acceptParenExpression(TIntermTyped*&);
John Kessenich87142c72016-03-12 20:24:24 -070068 bool acceptExpression(TIntermTyped*&);
John Kessenich34fb0362016-05-03 23:17:20 -060069 bool acceptAssignmentExpression(TIntermTyped*&);
70 bool acceptBinaryExpression(TIntermTyped*&, PrecedenceLevel);
71 bool acceptUnaryExpression(TIntermTyped*&);
72 bool acceptPostfixExpression(TIntermTyped*&);
John Kessenichd016be12016-03-13 11:24:20 -060073 bool acceptConstructor(TIntermTyped*&);
John Kessenich34fb0362016-05-03 23:17:20 -060074 bool acceptFunctionCall(HlslToken, TIntermTyped*&);
John Kessenich4678ca92016-05-13 09:33:42 -060075 bool acceptArguments(TFunction*, TIntermTyped*&);
John Kessenich87142c72016-03-12 20:24:24 -070076 bool acceptLiteral(TIntermTyped*&);
John Kessenich21472ae2016-06-04 11:46:33 -060077 bool acceptCompoundStatement(TIntermNode*&);
John Kessenich5f934b02016-03-13 17:58:25 -060078 bool acceptStatement(TIntermNode*&);
John Kessenich0d2b6de2016-06-05 11:23:11 -060079 bool acceptScopedStatement(TIntermNode*&);
John Kessenich077e0522016-06-09 02:02:17 -060080 bool acceptScopedCompoundStatement(TIntermNode*&);
John Kessenich0d2b6de2016-06-05 11:23:11 -060081 bool acceptNestedStatement(TIntermNode*&);
John Kessenich21472ae2016-06-04 11:46:33 -060082 void acceptAttributes();
83 bool acceptSelectionStatement(TIntermNode*&);
84 bool acceptSwitchStatement(TIntermNode*&);
85 bool acceptIterationStatement(TIntermNode*&);
86 bool acceptJumpStatement(TIntermNode*&);
87 bool acceptCaseLabel(TIntermNode*&);
88
John Kessenich078d7f22016-03-14 10:02:11 -060089 bool acceptSemantic();
John Kesseniche01a9bc2016-03-12 20:11:22 -070090
John Kessenich078d7f22016-03-14 10:02:11 -060091 HlslParseContext& parseContext; // state of parsing and helper functions for building the intermediate
92 TIntermediate& intermediate; // the final product, the intermediate representation, includes the AST
John Kesseniche01a9bc2016-03-12 20:11:22 -070093 };
94
95} // end namespace glslang
96
97#endif // HLSLGRAMMAR_H_