2010-11-10 12:32:34 +01:00
|
|
|
|
2010-11-30 15:47:03 +01:00
|
|
|
#line 213 "./glsl.g"
|
2010-11-11 12:01:37 +01:00
|
|
|
|
2010-11-10 15:44:59 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-11-10 15:44:59 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** No Commercial Usage
|
2010-11-10 15:44:59 +01:00
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
2010-11-10 15:44:59 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-11-10 15:44:59 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2010-11-10 12:32:34 +01:00
|
|
|
#include "glslparsertable_p.h"
|
|
|
|
|
#include "glsllexer.h"
|
|
|
|
|
#include "glslast.h"
|
2010-11-12 09:53:08 +10:00
|
|
|
#include "glslengine.h"
|
2010-11-10 12:32:34 +01:00
|
|
|
#include <vector>
|
|
|
|
|
#include <stack>
|
|
|
|
|
|
|
|
|
|
namespace GLSL {
|
|
|
|
|
|
2010-11-11 12:01:37 +01:00
|
|
|
class GLSL_EXPORT Parser: public GLSLParserTable
|
2010-11-10 12:32:34 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-11 12:01:37 +01:00
|
|
|
union Value {
|
|
|
|
|
void *ptr;
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *string;
|
2010-11-11 12:01:37 +01:00
|
|
|
AST *ast;
|
|
|
|
|
List<AST *> *ast_list;
|
2010-11-25 12:19:57 +01:00
|
|
|
DeclarationAST *declaration;
|
|
|
|
|
List<DeclarationAST *> *declaration_list;
|
|
|
|
|
ExpressionAST *expression;
|
|
|
|
|
List<ExpressionAST *> *expression_list;
|
|
|
|
|
StatementAST *statement;
|
|
|
|
|
List<StatementAST *> *statement_list;
|
|
|
|
|
TypeAST *type;
|
|
|
|
|
StructTypeAST::Field *field;
|
|
|
|
|
List<StructTypeAST::Field *> *field_list;
|
|
|
|
|
TranslationUnitAST *translation_unit;
|
|
|
|
|
FunctionIdentifierAST *function_identifier;
|
2010-11-12 10:23:46 +10:00
|
|
|
AST::Kind kind;
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST::Precision precision;
|
2010-11-12 10:23:46 +10:00
|
|
|
struct {
|
2010-11-25 12:19:57 +01:00
|
|
|
StatementAST *thenClause;
|
|
|
|
|
StatementAST *elseClause;
|
2010-11-12 10:23:46 +10:00
|
|
|
} ifstmt;
|
|
|
|
|
struct {
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *condition;
|
|
|
|
|
ExpressionAST *increment;
|
2010-11-12 10:23:46 +10:00
|
|
|
} forstmt;
|
|
|
|
|
struct {
|
2010-11-25 12:19:57 +01:00
|
|
|
FunctionIdentifierAST *id;
|
|
|
|
|
List<ExpressionAST *> *arguments;
|
2010-11-12 10:23:46 +10:00
|
|
|
} function;
|
2010-11-15 15:02:21 +10:00
|
|
|
int qualifier;
|
|
|
|
|
LayoutQualifier *layout;
|
|
|
|
|
List<LayoutQualifier *> *layout_list;
|
|
|
|
|
struct {
|
|
|
|
|
int qualifier;
|
|
|
|
|
List<LayoutQualifier *> *layout_list;
|
|
|
|
|
} type_qualifier;
|
2010-11-17 14:46:11 +10:00
|
|
|
struct {
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST *type;
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *name;
|
2010-11-17 14:46:11 +10:00
|
|
|
} param_declarator;
|
2010-11-25 12:19:57 +01:00
|
|
|
ParameterDeclarationAST *param_declaration;
|
|
|
|
|
FunctionDeclarationAST *function_declaration;
|
2010-11-11 12:01:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Parser(Engine *engine, const char *source, unsigned size, int variant);
|
2010-11-10 12:32:34 +01:00
|
|
|
~Parser();
|
|
|
|
|
|
2010-11-29 17:21:47 +01:00
|
|
|
TranslationUnitAST *parse() {
|
|
|
|
|
if (AST *u = parse(T_FEED_GLSL))
|
|
|
|
|
return u->asTranslationUnit();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExpressionAST *parseExpression() {
|
|
|
|
|
if (AST *u = parse(T_FEED_EXPRESSION))
|
|
|
|
|
return u->asExpression();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AST *parse(int startToken);
|
2010-11-10 12:32:34 +01:00
|
|
|
|
|
|
|
|
private:
|
2010-11-11 12:01:37 +01:00
|
|
|
// 1-based
|
2010-11-29 17:21:47 +01:00
|
|
|
int &location(int n) { return _locationStack[_tos + n - 1]; }
|
2010-11-11 12:01:37 +01:00
|
|
|
Value &sym(int n) { return _symStack[_tos + n - 1]; }
|
|
|
|
|
AST *&ast(int n) { return _symStack[_tos + n - 1].ast; }
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *&string(int n) { return _symStack[_tos + n - 1].string; }
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *&expression(int n) { return _symStack[_tos + n - 1].expression; }
|
|
|
|
|
StatementAST *&statement(int n) { return _symStack[_tos + n - 1].statement; }
|
|
|
|
|
TypeAST *&type(int n) { return _symStack[_tos + n - 1].type; }
|
|
|
|
|
FunctionDeclarationAST *&function(int n) { return _symStack[_tos + n - 1].function_declaration; }
|
2010-11-11 12:01:37 +01:00
|
|
|
|
2010-11-29 09:54:27 +01:00
|
|
|
inline int consumeToken() {
|
|
|
|
|
if (_index < int(_tokens.size()))
|
|
|
|
|
return _index++;
|
|
|
|
|
return _tokens.size() - 1;
|
|
|
|
|
}
|
2010-11-29 17:21:47 +01:00
|
|
|
inline const Token &tokenAt(int index) const {
|
|
|
|
|
if (index == 0)
|
|
|
|
|
return _startToken;
|
|
|
|
|
return _tokens.at(index);
|
|
|
|
|
}
|
|
|
|
|
inline int tokenKind(int index) const {
|
|
|
|
|
if (index == 0)
|
|
|
|
|
return _startToken.kind;
|
|
|
|
|
return _tokens.at(index).kind;
|
|
|
|
|
}
|
2010-11-11 12:01:37 +01:00
|
|
|
void reduce(int ruleno);
|
2010-11-10 12:32:34 +01:00
|
|
|
|
2010-11-19 14:59:33 +01:00
|
|
|
void warning(int line, const QString &message)
|
|
|
|
|
{
|
2010-11-26 14:24:03 +01:00
|
|
|
_engine->warning(line, message);
|
2010-11-19 14:59:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void error(int line, const QString &message)
|
|
|
|
|
{
|
2010-11-26 14:24:03 +01:00
|
|
|
_engine->error(line, message);
|
2010-11-19 14:59:33 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-12 09:53:08 +10:00
|
|
|
template <typename T>
|
|
|
|
|
T *makeAstNode()
|
|
|
|
|
{
|
|
|
|
|
T *node = new (_engine->pool()) T ();
|
|
|
|
|
node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T, typename A1>
|
|
|
|
|
T *makeAstNode(A1 a1)
|
|
|
|
|
{
|
|
|
|
|
T *node = new (_engine->pool()) T (a1);
|
|
|
|
|
node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T, typename A1, typename A2>
|
|
|
|
|
T *makeAstNode(A1 a1, A2 a2)
|
|
|
|
|
{
|
|
|
|
|
T *node = new (_engine->pool()) T (a1, a2);
|
|
|
|
|
node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T, typename A1, typename A2, typename A3>
|
|
|
|
|
T *makeAstNode(A1 a1, A2 a2, A3 a3)
|
|
|
|
|
{
|
|
|
|
|
T *node = new (_engine->pool()) T (a1, a2, a3);
|
|
|
|
|
node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T, typename A1, typename A2, typename A3, typename A4>
|
|
|
|
|
T *makeAstNode(A1 a1, A2 a2, A3 a3, A4 a4)
|
|
|
|
|
{
|
|
|
|
|
T *node = new (_engine->pool()) T (a1, a2, a3, a4);
|
|
|
|
|
node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 13:04:54 +10:00
|
|
|
TypeAST *makeBasicType(int token)
|
2010-11-12 10:23:46 +10:00
|
|
|
{
|
2010-11-29 13:04:54 +10:00
|
|
|
TypeAST *type = new (_engine->pool()) BasicTypeAST(token, spell[token]);
|
2010-11-12 10:23:46 +10:00
|
|
|
type->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 12:32:34 +01:00
|
|
|
private:
|
2010-11-11 15:05:42 +01:00
|
|
|
Engine *_engine;
|
2010-11-10 12:32:34 +01:00
|
|
|
int _tos;
|
|
|
|
|
int _index;
|
2010-11-12 09:53:08 +10:00
|
|
|
int yyloc;
|
2010-11-29 09:54:27 +01:00
|
|
|
int yytoken;
|
|
|
|
|
int yyrecovering;
|
|
|
|
|
bool _recovered;
|
2010-11-29 17:21:47 +01:00
|
|
|
Token _startToken;
|
2010-11-10 12:32:34 +01:00
|
|
|
std::vector<int> _stateStack;
|
|
|
|
|
std::vector<int> _locationStack;
|
2010-11-11 12:01:37 +01:00
|
|
|
std::vector<Value> _symStack;
|
2010-11-10 12:32:34 +01:00
|
|
|
std::vector<Token> _tokens;
|
|
|
|
|
};
|
|
|
|
|
|
2011-02-04 09:52:39 +01:00
|
|
|
} // namespace GLSL
|