2010-11-10 12:32:34 +01:00
|
|
|
|
2010-11-11 12:01:37 +01:00
|
|
|
#line 212 "./glsl.g"
|
|
|
|
|
|
2010-11-10 15:44:59 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
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;
|
|
|
|
|
const std::string *string;
|
|
|
|
|
AST *ast;
|
|
|
|
|
List<AST *> *ast_list;
|
|
|
|
|
Declaration *declaration;
|
|
|
|
|
List<Declaration *> *declaration_list;
|
2010-11-11 15:25:19 +01:00
|
|
|
Expression *expression;
|
|
|
|
|
List<Expression *> *expression_list;
|
2010-11-11 12:01:37 +01:00
|
|
|
TranslationUnit *translation_unit;
|
2010-11-11 15:25:19 +01:00
|
|
|
// ### ast nodes...
|
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-11 12:01:37 +01:00
|
|
|
TranslationUnit *parse();
|
2010-11-10 12:32:34 +01:00
|
|
|
|
|
|
|
|
private:
|
2010-11-11 12:01:37 +01:00
|
|
|
// 1-based
|
|
|
|
|
Value &sym(int n) { return _symStack[_tos + n - 1]; }
|
|
|
|
|
AST *&ast(int n) { return _symStack[_tos + n - 1].ast; }
|
|
|
|
|
const std::string *&string(int n) { return _symStack[_tos + n - 1].string; }
|
|
|
|
|
|
2010-11-10 12:32:34 +01:00
|
|
|
inline int consumeToken() { return _index++; }
|
|
|
|
|
inline const Token &tokenAt(int index) const { return _tokens.at(index); }
|
|
|
|
|
inline int tokenKind(int index) const { 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-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-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-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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end of namespace GLSL
|