Commit 55234b9d authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Implemented some basic code completion.

parent 31ff319f
......@@ -36,6 +36,9 @@
%token_prefix T_
%expect 1
%token FEED_GLSL "feed GLSL"
%token FEED_EXPRESSION "feed expression"
%token ADD_ASSIGN "+="
%token AMPERSAND "&"
%token AND_ASSIGN "&="
......@@ -209,7 +212,7 @@
%token ERROR "error"
%token RESERVED "reserved word"
%start translation_unit
%start toplevel
/:
/**************************************************************************
......@@ -301,10 +304,23 @@ public:
Parser(Engine *engine, const char *source, unsigned size, int variant);
~Parser();
TranslationUnitAST *parse();
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);
private:
// 1-based
int &location(int n) { return _locationStack[_tos + n - 1]; }
Value &sym(int n) { return _symStack[_tos + n - 1]; }
AST *&ast(int n) { return _symStack[_tos + n - 1].ast; }
const QString *&string(int n) { return _symStack[_tos + n - 1].string; }
......@@ -318,8 +334,16 @@ private:
return _index++;
return _tokens.size() - 1;
}
inline const Token &tokenAt(int index) const { return _tokens.at(index); }
inline int tokenKind(int index) const { return _tokens.at(index).kind; }
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;
}
void reduce(int ruleno);
void warning(int line, const QString &message)
......@@ -387,6 +411,7 @@ private:
int yytoken;
int yyrecovering;
bool _recovered;
Token _startToken;
std::vector<int> _stateStack;
std::vector<int> _locationStack;
std::vector<Value> _symStack;
......@@ -492,14 +517,14 @@ Parser::Parser(Engine *engine, const char *source, unsigned size, int variant)
_tokens.push_back(tk);
} while (tk.isNot(EOF_SYMBOL));
_index = 1;
_index = 0;
}
Parser::~Parser()
{
}
TranslationUnitAST *Parser::parse()
AST *Parser::parse(int startToken)
{
int action = 0;
yytoken = -1;
......@@ -508,6 +533,7 @@ TranslationUnitAST *Parser::parse()
_recovered = false;
_tos = -1;
_startToken.kind = startToken;
do {
again:
......@@ -2641,14 +2667,20 @@ case $rule_number: {
compound_statement ::= LEFT_BRACE RIGHT_BRACE ;
/.
case $rule_number: {
ast(1) = makeAstNode<CompoundStatementAST>();
CompoundStatementAST *stmt = makeAstNode<CompoundStatementAST>();
stmt->start = tokenAt(location(1)).begin();
stmt->end = tokenAt(location(2)).end();
ast(1) = stmt;
} break;
./
compound_statement ::= LEFT_BRACE statement_list RIGHT_BRACE ;
/.
case $rule_number: {
ast(1) = makeAstNode<CompoundStatementAST>(sym(2).statement_list);
CompoundStatementAST *stmt = makeAstNode<CompoundStatementAST>(sym(2).statement_list);
stmt->start = tokenAt(location(1)).begin();
stmt->end = tokenAt(location(3)).end();
ast(1) = stmt;
} break;
./
......@@ -2669,14 +2701,20 @@ case $rule_number: {
compound_statement_no_new_scope ::= LEFT_BRACE RIGHT_BRACE ;
/.
case $rule_number: {
ast(1) = makeAstNode<CompoundStatementAST>();
CompoundStatementAST *stmt = makeAstNode<CompoundStatementAST>();
stmt->start = tokenAt(location(1)).begin();
stmt->end = tokenAt(location(2)).end();
ast(1) = stmt;
} break;
./
compound_statement_no_new_scope ::= LEFT_BRACE statement_list RIGHT_BRACE ;
/.
case $rule_number: {
ast(1) = makeAstNode<CompoundStatementAST>(sym(2).statement_list);
CompoundStatementAST *stmt = makeAstNode<CompoundStatementAST>(sym(2).statement_list);
stmt->start = tokenAt(location(1)).begin();
stmt->end = tokenAt(location(3)).end();
ast(1) = stmt;
} break;
./
......@@ -2953,6 +2991,19 @@ case $rule_number: {
./
toplevel ::= FEED_GLSL translation_unit ;
/.
case $rule_number: {
ast(1) = ast(2);
} break;
./
toplevel ::= FEED_EXPRESSION expression ;
/.
case $rule_number: {
ast(1) = ast(2);
} break;
./
/.
} // end switch
......
......@@ -508,9 +508,11 @@ class GLSL_EXPORT CompoundStatementAST: public StatementAST
{
public:
CompoundStatementAST()
: StatementAST(Kind_CompoundStatement), statements(0) {}
: StatementAST(Kind_CompoundStatement), statements(0)
, start(0), end(0), symbol(0) {}
CompoundStatementAST(List<StatementAST *> *_statements)
: StatementAST(Kind_CompoundStatement), statements(finish(_statements)) {}
: StatementAST(Kind_CompoundStatement), statements(finish(_statements))
, start(0), end(0), symbol(0) {}
virtual CompoundStatementAST *asCompoundStatement() { return this; }
......@@ -518,6 +520,9 @@ public:
public: // attributes
List<StatementAST *> *statements;
int start;
int end;
Block *symbol; // decoration
};
class GLSL_EXPORT IfStatementAST: public StatementAST
......
This diff is collapsed.
#line 214 "glsl.g"
#line 217 "./glsl.g"
/**************************************************************************
**
......@@ -90,10 +90,23 @@ public:
Parser(Engine *engine, const char *source, unsigned size, int variant);
~Parser();
TranslationUnitAST *parse();
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);
private:
// 1-based
int &location(int n) { return _locationStack[_tos + n - 1]; }
Value &sym(int n) { return _symStack[_tos + n - 1]; }
AST *&ast(int n) { return _symStack[_tos + n - 1].ast; }
const QString *&string(int n) { return _symStack[_tos + n - 1].string; }
......@@ -107,8 +120,16 @@ private:
return _index++;
return _tokens.size() - 1;
}
inline const Token &tokenAt(int index) const { return _tokens.at(index); }
inline int tokenKind(int index) const { return _tokens.at(index).kind; }
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;
}
void reduce(int ruleno);
void warning(int line, const QString &message)
......@@ -176,6 +197,7 @@ private:
int yytoken;
int yyrecovering;
bool _recovered;
Token _startToken;
std::vector<int> _stateStack;
std::vector<int> _locationStack;
std::vector<Value> _symStack;
......
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** 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.
**
** 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.
**
** 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.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of other Qt classes. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
// This file was generated by qlalr - DO NOT EDIT!
#ifndef GLSLPARSERTABLE_P_H
#define GLSLPARSERTABLE_P_H
#include <QtCore/qglobal.h>
QT_BEGIN_NAMESPACE
class GLSLParserTable
{
public:
enum VariousConstants {
EOF_SYMBOL = 0,
T_ADD_ASSIGN = 1,
T_AMPERSAND = 2,
T_AND_ASSIGN = 3,
T_AND_OP = 4,
T_ATTRIBUTE = 5,
T_BANG = 6,
T_BOOL = 7,
T_BREAK = 8,
T_BVEC2 = 9,
T_BVEC3 = 10,
T_BVEC4 = 11,
T_CARET = 12,
T_CASE = 13,
T_CENTROID = 14,
T_COLON = 15,
T_COMMA = 16,
T_COMMENT = 170,
T_CONST = 17,
T_CONTINUE = 18,
T_DASH = 19,
T_DEC_OP = 20,
T_DEFAULT = 21,
T_DISCARD = 22,
T_DIV_ASSIGN = 23,
T_DMAT2 = 24,
T_DMAT2X2 = 25,
T_DMAT2X3 = 26,
T_DMAT2X4 = 27,
T_DMAT3 = 28,
T_DMAT3X2 = 29,
T_DMAT3X3 = 30,
T_DMAT3X4 = 31,
T_DMAT4 = 32,
T_DMAT4X2 = 33,
T_DMAT4X3 = 34,
T_DMAT4X4 = 35,
T_DO = 36,
T_DOT = 37,
T_DOUBLE = 38,
T_DVEC2 = 39,
T_DVEC3 = 40,
T_DVEC4 = 41,
T_ELSE = 42,
T_EQUAL = 43,
T_EQ_OP = 44,
T_ERROR = 171,
T_FALSE = 168,
T_FLAT = 45,
T_FLOAT = 46,
T_FOR = 47,
T_GE_OP = 48,
T_HIGHP = 49,
T_IDENTIFIER = 50,
T_IF = 51,
T_IN = 52,
T_INC_OP = 53,
T_INOUT = 54,
T_INT = 55,
T_INVARIANT = 56,
T_ISAMPLER1D = 57,
T_ISAMPLER1DARRAY = 58,
T_ISAMPLER2D = 59,
T_ISAMPLER2DARRAY = 60,
T_ISAMPLER2DMS = 61,
T_ISAMPLER2DMSARRAY = 62,
T_ISAMPLER2DRECT = 63,
T_ISAMPLER3D = 64,
T_ISAMPLERBUFFER = 65,
T_ISAMPLERCUBE = 66,
T_ISAMPLERCUBEARRAY = 67,
T_IVEC2 = 68,
T_IVEC3 = 69,
T_IVEC4 = 70,
T_LAYOUT = 71,
T_LEFT_ANGLE = 72,
T_LEFT_ASSIGN = 73,
T_LEFT_BRACE = 74,
T_LEFT_BRACKET = 75,
T_LEFT_OP = 76,
T_LEFT_PAREN = 77,
T_LE_OP = 78,
T_LOWP = 79,
T_MAT2 = 80,
T_MAT2X2 = 81,
T_MAT2X3 = 82,
T_MAT2X4 = 83,
T_MAT3 = 84,
T_MAT3X2 = 85,
T_MAT3X3 = 86,
T_MAT3X4 = 87,
T_MAT4 = 88,
T_MAT4X2 = 89,
T_MAT4X3 = 90,
T_MAT4X4 = 91,
T_MEDIUMP = 92,
T_MOD_ASSIGN = 93,
T_MUL_ASSIGN = 94,
T_NE_OP = 95,
T_NOPERSPECTIVE = 96,
T_NUMBER = 97,
T_OR_ASSIGN = 98,
T_OR_OP = 99,
T_OUT = 100,
T_PATCH = 101,
T_PERCENT = 102,
T_PLUS = 103,
T_PRECISION = 104,
T_PREPROC = 169,
T_QUESTION = 105,
T_RESERVED = 172,
T_RETURN = 106,
T_RIGHT_ANGLE = 107,
T_RIGHT_ASSIGN = 108,
T_RIGHT_BRACE = 109,
T_RIGHT_BRACKET = 110,
T_RIGHT_OP = 111,
T_RIGHT_PAREN = 112,
T_SAMPLE = 113,
T_SAMPLER1D = 114,
T_SAMPLER1DARRAY = 115,
T_SAMPLER1DARRAYSHADOW = 116,
T_SAMPLER1DSHADOW = 117,
T_SAMPLER2D = 118,
T_SAMPLER2DARRAY = 119,
T_SAMPLER2DARRAYSHADOW = 120,
T_SAMPLER2DMS = 121,
T_SAMPLER2DMSARRAY = 122,
T_SAMPLER2DRECT = 123,
T_SAMPLER2DRECTSHADOW = 124,
T_SAMPLER2DSHADOW = 125,
T_SAMPLER3D = 126,
T_SAMPLERBUFFER = 127,
T_SAMPLERCUBE = 128,
T_SAMPLERCUBEARRAY = 129,
T_SAMPLERCUBEARRAYSHADOW = 130,
T_SAMPLERCUBESHADOW = 131,
T_SEMICOLON = 132,
T_SLASH = 133,
T_SMOOTH = 134,
T_STAR = 135,
T_STRUCT = 136,
T_SUBROUTINE = 137,
T_SUB_ASSIGN = 138,
T_SWITCH = 139,
T_TILDE = 140,
T_TRUE = 167,
T_TYPE_NAME = 141,
T_UINT = 142,
T_UNIFORM = 143,
T_USAMPLER1D = 144,
T_USAMPLER1DARRAY = 145,
T_USAMPLER2D = 146,
T_USAMPLER2DARRAY = 147,
T_USAMPLER2DMS = 148,
T_USAMPLER2DMSARRAY = 149,
T_USAMPLER2DRECT = 150,
T_USAMPLER3D = 151,
T_USAMPLERBUFFER = 152,
T_USAMPLERCUBE = 153,
T_USAMPLERCUBEARRAY = 154,
T_UVEC2 = 155,
T_UVEC3 = 156,
T_UVEC4 = 157,
T_VARYING = 158,
T_VEC2 = 159,
T_VEC3 = 160,
T_VEC4 = 161,
T_VERTICAL_BAR = 162,
T_VOID = 163,
T_WHILE = 164,
T_XOR_ASSIGN = 165,
T_XOR_OP = 166,
ACCEPT_STATE = 440,
RULE_COUNT = 314,
STATE_COUNT = 459,
TERMINAL_COUNT = 173,
NON_TERMINAL_COUNT = 84,
GOTO_INDEX_OFFSET = 459,
GOTO_INFO_OFFSET = 4757,
GOTO_CHECK_OFFSET = 4757
T_ADD_ASSIGN = 3,
T_AMPERSAND = 4,
T_AND_ASSIGN = 5,
T_AND_OP = 6,
T_ATTRIBUTE = 7,
T_BANG = 8,
T_BOOL = 9,
T_BREAK = 10,
T_BVEC2 = 11,
T_BVEC3 = 12,
T_BVEC4 = 13,
T_CARET = 14,
T_CASE = 15,
T_CENTROID = 16,
T_COLON = 17,
T_COMMA = 18,
T_COMMENT = 172,
T_CONST = 19,
T_CONTINUE = 20,
T_DASH = 21,
T_DEC_OP = 22,
T_DEFAULT = 23,
T_DISCARD = 24,
T_DIV_ASSIGN = 25,
T_DMAT2 = 26,
T_DMAT2X2 = 27,
T_DMAT2X3 = 28,
T_DMAT2X4 = 29,
T_DMAT3 = 30,
T_DMAT3X2 = 31,
T_DMAT3X3 = 32,
T_DMAT3X4 = 33,
T_DMAT4 = 34,
T_DMAT4X2 = 35,
T_DMAT4X3 = 36,
T_DMAT4X4 = 37,
T_DO = 38,
T_DOT = 39,
T_DOUBLE = 40,
T_DVEC2 = 41,
T_DVEC3 = 42,
T_DVEC4 = 43,
T_ELSE = 44,
T_EQUAL = 45,
T_EQ_OP = 46,
T_ERROR = 173,
T_FALSE = 170,
T_FEED_EXPRESSION = 2,
T_FEED_GLSL = 1,
T_FLAT = 47,
T_FLOAT = 48,
T_FOR = 49,
T_GE_OP = 50,
T_HIGHP = 51,
T_IDENTIFIER = 52,
T_IF = 53,
T_IN = 54,
T_INC_OP = 55,
T_INOUT = 56,
T_INT = 57,
T_INVARIANT = 58,
T_ISAMPLER1D = 59,
T_ISAMPLER1DARRAY = 60,
T_ISAMPLER2D = 61,
T_ISAMPLER2DARRAY = 62,
T_ISAMPLER2DMS = 63,
T_ISAMPLER2DMSARRAY = 64,
T_ISAMPLER2DRECT = 65,
T_ISAMPLER3D = 66,
T_ISAMPLERBUFFER = 67,
T_ISAMPLERCUBE = 68,
T_ISAMPLERCUBEARRAY = 69,
T_IVEC2 = 70,
T_IVEC3 = 71,
T_IVEC4 = 72,
T_LAYOUT = 73,
T_LEFT_ANGLE = 74,
T_LEFT_ASSIGN = 75,
T_LEFT_BRACE = 76,
T_LEFT_BRACKET = 77,
T_LEFT_OP = 78,
T_LEFT_PAREN = 79,
T_LE_OP = 80,
T_LOWP = 81,
T_MAT2 = 82,
T_MAT2X2 = 83,
T_MAT2X3 = 84,
T_MAT2X4 = 85,
T_MAT3 = 86,
T_MAT3X2 = 87,
T_MAT3X3 = 88,
T_MAT3X4 = 89,
T_MAT4 = 90,
T_MAT4X2 = 91,
T_MAT4X3 = 92,
T_MAT4X4 = 93,
T_MEDIUMP = 94,
T_MOD_ASSIGN = 95,
T_MUL_ASSIGN = 96,
T_NE_OP = 97,
T_NOPERSPECTIVE = 98,
T_NUMBER = 99,
T_OR_ASSIGN = 100,
T_OR_OP = 101,
T_OUT = 102,
T_PATCH = 103,
T_PERCENT = 104,
T_PLUS = 105,
T_PRECISION = 106,
T_PREPROC = 171,
T_QUESTION = 107,
T_RESERVED = 174,
T_RETURN = 108,
T_RIGHT_ANGLE = 109,
T_RIGHT_ASSIGN = 110,
T_RIGHT_BRACE = 111,
T_RIGHT_BRACKET = 112,
T_RIGHT_OP = 113,
T_RIGHT_PAREN = 114,
T_SAMPLE = 115,
T_SAMPLER1D = 116,
T_SAMPLER1DARRAY = 117,
T_SAMPLER1DARRAYSHADOW = 118,
T_SAMPLER1DSHADOW = 119,
T_SAMPLER2D = 120,
T_SAMPLER2DARRAY = 121,
T_SAMPLER2DARRAYSHADOW = 122,
T_SAMPLER2DMS = 123,
T_SAMPLER2DMSARRAY = 124,
T_SAMPLER2DRECT = 125,
T_SAMPLER2DRECTSHADOW = 126,
T_SAMPLER2DSHADOW = 127,
T_SAMPLER3D = 128,
T_SAMPLERBUFFER = 129,
T_SAMPLERCUBE = 130,
T_SAMPLERCUBEARRAY = 131,
T_SAMPLERCUBEARRAYSHADOW = 132,
T_SAMPLERCUBESHADOW = 133,