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
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-11-10 15:44:59 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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-11-10 15:44:59 +01:00
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 17:14:20 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** 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
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
2011-04-13 08:42:33 +02:00
|
|
|
|
2010-11-10 12:32:34 +01:00
|
|
|
#ifndef GLSLAST_H
|
|
|
|
|
#define GLSLAST_H
|
|
|
|
|
|
2010-11-11 11:29:29 +10:00
|
|
|
#include "glsl.h"
|
2010-11-11 15:05:42 +01:00
|
|
|
#include "glslmemorypool.h"
|
2010-11-18 15:57:44 +10:00
|
|
|
#include <QtCore/qstring.h>
|
2010-11-10 12:32:34 +01:00
|
|
|
|
|
|
|
|
namespace GLSL {
|
|
|
|
|
|
|
|
|
|
class AST;
|
2010-11-25 12:19:57 +01:00
|
|
|
class TranslationUnitAST;
|
|
|
|
|
class ExpressionAST;
|
|
|
|
|
class IdentifierExpressionAST;
|
|
|
|
|
class LiteralExpressionAST;
|
|
|
|
|
class BinaryExpressionAST;
|
|
|
|
|
class UnaryExpressionAST;
|
|
|
|
|
class TernaryExpressionAST;
|
|
|
|
|
class AssignmentExpressionAST;
|
|
|
|
|
class MemberAccessExpressionAST;
|
|
|
|
|
class FunctionCallExpressionAST;
|
|
|
|
|
class FunctionIdentifierAST;
|
|
|
|
|
class DeclarationExpressionAST;
|
|
|
|
|
class StatementAST;
|
|
|
|
|
class ExpressionStatementAST;
|
|
|
|
|
class CompoundStatementAST;
|
|
|
|
|
class IfStatementAST;
|
|
|
|
|
class WhileStatementAST;
|
|
|
|
|
class DoStatementAST;
|
|
|
|
|
class ForStatementAST;
|
|
|
|
|
class JumpStatementAST;
|
|
|
|
|
class ReturnStatementAST;
|
|
|
|
|
class SwitchStatementAST;
|
|
|
|
|
class CaseLabelStatementAST;
|
|
|
|
|
class DeclarationStatementAST;
|
|
|
|
|
class TypeAST;
|
|
|
|
|
class BasicTypeAST;
|
|
|
|
|
class NamedTypeAST;
|
|
|
|
|
class ArrayTypeAST;
|
|
|
|
|
class StructTypeAST;
|
|
|
|
|
class QualifiedTypeAST;
|
|
|
|
|
class DeclarationAST;
|
|
|
|
|
class PrecisionDeclarationAST;
|
|
|
|
|
class ParameterDeclarationAST;
|
|
|
|
|
class VariableDeclarationAST;
|
|
|
|
|
class TypeDeclarationAST;
|
|
|
|
|
class TypeAndVariableDeclarationAST;
|
|
|
|
|
class InvariantDeclarationAST;
|
|
|
|
|
class InitDeclarationAST;
|
|
|
|
|
class FunctionDeclarationAST;
|
2010-11-11 11:29:29 +10:00
|
|
|
class Visitor;
|
2010-11-10 12:32:34 +01:00
|
|
|
|
2010-11-11 12:01:37 +01:00
|
|
|
template <typename T>
|
2010-11-11 15:05:42 +01:00
|
|
|
class GLSL_EXPORT List: public Managed
|
2010-11-11 12:01:37 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
List(const T &value)
|
2010-11-12 09:53:08 +10:00
|
|
|
: value(value), next(this), lineno(0) {}
|
2010-11-11 12:01:37 +01:00
|
|
|
|
|
|
|
|
List(List *previous, const T &value)
|
2010-11-12 09:53:08 +10:00
|
|
|
: value(value), lineno(0)
|
2010-11-11 12:01:37 +01:00
|
|
|
{
|
|
|
|
|
next = previous->next;
|
|
|
|
|
previous->next = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List *finish()
|
|
|
|
|
{
|
|
|
|
|
List *head = next;
|
|
|
|
|
next = 0;
|
|
|
|
|
return head;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
T value;
|
|
|
|
|
List *next;
|
2010-11-12 09:53:08 +10:00
|
|
|
int lineno;
|
2010-11-11 12:01:37 +01:00
|
|
|
};
|
|
|
|
|
|
2010-11-12 09:05:48 +10:00
|
|
|
// Append two lists, which are assumed to still be circular, pre-finish.
|
|
|
|
|
template <typename T>
|
|
|
|
|
List<T> *appendLists(List<T> *first, List<T> *second)
|
|
|
|
|
{
|
|
|
|
|
if (!first)
|
|
|
|
|
return second;
|
|
|
|
|
else if (!second)
|
|
|
|
|
return first;
|
|
|
|
|
List<T> *firstHead = first->next;
|
|
|
|
|
List<T> *secondHead = second->next;
|
|
|
|
|
first->next = secondHead;
|
|
|
|
|
second->next = firstHead;
|
|
|
|
|
return second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class GLSL_EXPORT AST: public Managed
|
2010-11-10 12:32:34 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-11 11:29:29 +10:00
|
|
|
enum Kind {
|
|
|
|
|
Kind_Undefined,
|
|
|
|
|
|
2010-11-11 12:01:37 +01:00
|
|
|
// Translation unit
|
|
|
|
|
Kind_TranslationUnit,
|
|
|
|
|
|
2010-11-11 11:29:29 +10:00
|
|
|
// Primary expressions
|
|
|
|
|
Kind_Identifier,
|
|
|
|
|
Kind_Literal,
|
|
|
|
|
|
|
|
|
|
// Unary expressions
|
|
|
|
|
Kind_PreIncrement,
|
|
|
|
|
Kind_PostIncrement,
|
|
|
|
|
Kind_PreDecrement,
|
|
|
|
|
Kind_PostDecrement,
|
|
|
|
|
Kind_UnaryPlus,
|
|
|
|
|
Kind_UnaryMinus,
|
|
|
|
|
Kind_LogicalNot,
|
|
|
|
|
Kind_BitwiseNot,
|
|
|
|
|
|
|
|
|
|
// Binary expressions
|
|
|
|
|
Kind_Plus,
|
|
|
|
|
Kind_Minus,
|
|
|
|
|
Kind_Multiply,
|
|
|
|
|
Kind_Divide,
|
|
|
|
|
Kind_Modulus,
|
|
|
|
|
Kind_ShiftLeft,
|
|
|
|
|
Kind_ShiftRight,
|
|
|
|
|
Kind_Equal,
|
|
|
|
|
Kind_NotEqual,
|
|
|
|
|
Kind_LessThan,
|
|
|
|
|
Kind_LessEqual,
|
|
|
|
|
Kind_GreaterThan,
|
|
|
|
|
Kind_GreaterEqual,
|
|
|
|
|
Kind_LogicalAnd,
|
|
|
|
|
Kind_LogicalOr,
|
2010-11-12 10:23:46 +10:00
|
|
|
Kind_LogicalXor,
|
2010-11-11 11:29:29 +10:00
|
|
|
Kind_BitwiseAnd,
|
|
|
|
|
Kind_BitwiseOr,
|
|
|
|
|
Kind_BitwiseXor,
|
|
|
|
|
Kind_Comma,
|
|
|
|
|
Kind_ArrayAccess,
|
|
|
|
|
|
|
|
|
|
// Other expressions
|
|
|
|
|
Kind_Conditional,
|
|
|
|
|
Kind_MemberAccess,
|
|
|
|
|
Kind_FunctionCall,
|
|
|
|
|
Kind_MemberFunctionCall,
|
2010-11-12 10:23:46 +10:00
|
|
|
Kind_FunctionIdentifier,
|
2010-11-17 14:46:11 +10:00
|
|
|
Kind_DeclarationExpression,
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
// Assignment expressions
|
|
|
|
|
Kind_Assign,
|
|
|
|
|
Kind_AssignPlus,
|
|
|
|
|
Kind_AssignMinus,
|
|
|
|
|
Kind_AssignMultiply,
|
|
|
|
|
Kind_AssignDivide,
|
|
|
|
|
Kind_AssignModulus,
|
|
|
|
|
Kind_AssignShiftLeft,
|
|
|
|
|
Kind_AssignShiftRight,
|
|
|
|
|
Kind_AssignAnd,
|
|
|
|
|
Kind_AssignOr,
|
|
|
|
|
Kind_AssignXor,
|
|
|
|
|
|
|
|
|
|
// Statements
|
|
|
|
|
Kind_ExpressionStatement,
|
|
|
|
|
Kind_CompoundStatement,
|
|
|
|
|
Kind_If,
|
|
|
|
|
Kind_While,
|
|
|
|
|
Kind_Do,
|
|
|
|
|
Kind_For,
|
|
|
|
|
Kind_Break,
|
|
|
|
|
Kind_Continue,
|
|
|
|
|
Kind_Discard,
|
|
|
|
|
Kind_Return,
|
|
|
|
|
Kind_ReturnExpression,
|
|
|
|
|
Kind_Switch,
|
|
|
|
|
Kind_CaseLabel,
|
|
|
|
|
Kind_DefaultLabel,
|
2010-11-17 14:46:11 +10:00
|
|
|
Kind_DeclarationStatement,
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
// Types
|
|
|
|
|
Kind_BasicType,
|
|
|
|
|
Kind_NamedType,
|
|
|
|
|
Kind_ArrayType,
|
|
|
|
|
Kind_OpenArrayType,
|
|
|
|
|
Kind_StructType,
|
|
|
|
|
Kind_AnonymousStructType,
|
2010-11-12 10:23:46 +10:00
|
|
|
Kind_StructField,
|
2010-11-15 15:02:21 +10:00
|
|
|
Kind_QualifiedType,
|
2010-11-12 10:23:46 +10:00
|
|
|
|
|
|
|
|
// Declarations
|
2010-11-17 14:46:11 +10:00
|
|
|
Kind_PrecisionDeclaration,
|
|
|
|
|
Kind_ParameterDeclaration,
|
|
|
|
|
Kind_VariableDeclaration,
|
|
|
|
|
Kind_TypeDeclaration,
|
2010-11-18 13:01:27 +10:00
|
|
|
Kind_TypeAndVariableDeclaration,
|
2010-11-17 14:46:11 +10:00
|
|
|
Kind_InvariantDeclaration,
|
2010-11-18 13:01:27 +10:00
|
|
|
Kind_InitDeclaration,
|
|
|
|
|
Kind_FunctionDeclaration
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual TranslationUnitAST *asTranslationUnit() { return 0; }
|
|
|
|
|
|
|
|
|
|
virtual ExpressionAST *asExpression() { return 0; }
|
|
|
|
|
virtual IdentifierExpressionAST *asIdentifierExpression() { return 0; }
|
|
|
|
|
virtual LiteralExpressionAST *asLiteralExpression() { return 0; }
|
|
|
|
|
virtual BinaryExpressionAST *asBinaryExpression() { return 0; }
|
|
|
|
|
virtual UnaryExpressionAST *asUnaryExpression() { return 0; }
|
|
|
|
|
virtual TernaryExpressionAST *asTernaryExpression() { return 0; }
|
|
|
|
|
virtual AssignmentExpressionAST *asAssignmentExpression() { return 0; }
|
|
|
|
|
virtual MemberAccessExpressionAST *asMemberAccessExpression() { return 0; }
|
|
|
|
|
virtual FunctionCallExpressionAST *asFunctionCallExpression() { return 0; }
|
|
|
|
|
virtual FunctionIdentifierAST *asFunctionIdentifier() { return 0; }
|
|
|
|
|
virtual DeclarationExpressionAST *asDeclarationExpression() { return 0; }
|
|
|
|
|
|
|
|
|
|
virtual StatementAST *asStatement() { return 0; }
|
|
|
|
|
virtual ExpressionStatementAST *asExpressionStatement() { return 0; }
|
|
|
|
|
virtual CompoundStatementAST *asCompoundStatement() { return 0; }
|
|
|
|
|
virtual IfStatementAST *asIfStatement() { return 0; }
|
|
|
|
|
virtual WhileStatementAST *asWhileStatement() { return 0; }
|
|
|
|
|
virtual DoStatementAST *asDoStatement() { return 0; }
|
|
|
|
|
virtual ForStatementAST *asForStatement() { return 0; }
|
|
|
|
|
virtual JumpStatementAST *asJumpStatement() { return 0; }
|
|
|
|
|
virtual ReturnStatementAST *asReturnStatement() { return 0; }
|
|
|
|
|
virtual SwitchStatementAST *asSwitchStatement() { return 0; }
|
|
|
|
|
virtual CaseLabelStatementAST *asCaseLabelStatement() { return 0; }
|
|
|
|
|
virtual DeclarationStatementAST *asDeclarationStatement() { return 0; }
|
|
|
|
|
|
|
|
|
|
virtual TypeAST *asType() { return 0; }
|
|
|
|
|
virtual BasicTypeAST *asBasicType() { return 0; }
|
|
|
|
|
virtual NamedTypeAST *asNamedType() { return 0; }
|
|
|
|
|
virtual ArrayTypeAST *asArrayType() { return 0; }
|
|
|
|
|
virtual StructTypeAST *asStructType() { return 0; }
|
|
|
|
|
virtual QualifiedTypeAST *asQualifiedType() { return 0; }
|
|
|
|
|
|
|
|
|
|
virtual DeclarationAST *asDeclaration() { return 0; }
|
|
|
|
|
virtual PrecisionDeclarationAST *asPrecisionDeclaration() { return 0; }
|
|
|
|
|
virtual ParameterDeclarationAST *asParameterDeclaration() { return 0; }
|
|
|
|
|
virtual VariableDeclarationAST *asVariableDeclaration() { return 0; }
|
|
|
|
|
virtual TypeDeclarationAST *asTypeDeclaration() { return 0; }
|
|
|
|
|
virtual TypeAndVariableDeclarationAST *asTypeAndVariableDeclaration() { return 0; }
|
|
|
|
|
virtual InvariantDeclarationAST *asInvariantDeclaration() { return 0; }
|
|
|
|
|
virtual InitDeclarationAST *asInitDeclaration() { return 0; }
|
|
|
|
|
virtual FunctionDeclarationAST *asFunctionDeclaration() { return 0; }
|
2010-11-12 10:23:46 +10:00
|
|
|
|
2010-11-11 11:29:29 +10:00
|
|
|
void accept(Visitor *visitor);
|
|
|
|
|
static void accept(AST *ast, Visitor *visitor);
|
|
|
|
|
|
2010-11-11 12:01:37 +01:00
|
|
|
template <typename T>
|
|
|
|
|
static void accept(List<T> *it, Visitor *visitor)
|
|
|
|
|
{
|
|
|
|
|
for (; it; it = it->next)
|
|
|
|
|
accept(it->value, visitor);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-11 11:29:29 +10:00
|
|
|
virtual void accept0(Visitor *visitor) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
AST(Kind _kind) : kind(_kind), lineno(0) {}
|
|
|
|
|
|
2010-11-11 12:01:37 +01:00
|
|
|
template <typename T>
|
|
|
|
|
static List<T> *finish(List<T> *list)
|
|
|
|
|
{
|
|
|
|
|
if (! list)
|
|
|
|
|
return 0;
|
|
|
|
|
return list->finish(); // convert the circular list with a linked list.
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-11 11:29:29 +10:00
|
|
|
public: // attributes
|
|
|
|
|
int kind;
|
|
|
|
|
int lineno;
|
2010-11-12 09:05:48 +10:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
~AST() {} // Managed types cannot be deleted.
|
2010-11-10 12:32:34 +01:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT TranslationUnitAST: public AST
|
2010-11-10 12:32:34 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
TranslationUnitAST(List<DeclarationAST *> *declarations)
|
2010-11-12 09:05:48 +10:00
|
|
|
: AST(Kind_TranslationUnit), declarations(finish(declarations)) {}
|
2010-11-10 12:32:34 +01:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual TranslationUnitAST *asTranslationUnit() { return this; }
|
2010-11-10 12:32:34 +01:00
|
|
|
|
2010-11-11 11:29:29 +10:00
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
2010-11-10 12:32:34 +01:00
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
List<DeclarationAST *> *declarations;
|
2010-11-10 12:32:34 +01:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT ExpressionAST: public AST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
protected:
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST(Kind _kind) : AST(_kind) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual ExpressionAST *asExpression() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT IdentifierExpressionAST: public ExpressionAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
IdentifierExpressionAST(const QString *_name)
|
|
|
|
|
: ExpressionAST(Kind_Identifier), name(_name) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual IdentifierExpressionAST *asIdentifierExpression() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *name;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT LiteralExpressionAST: public ExpressionAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
LiteralExpressionAST(const QString *_value)
|
|
|
|
|
: ExpressionAST(Kind_Literal), value(_value) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual LiteralExpressionAST *asLiteralExpression() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *value;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT BinaryExpressionAST: public ExpressionAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
BinaryExpressionAST(Kind _kind, ExpressionAST *_left, ExpressionAST *_right)
|
|
|
|
|
: ExpressionAST(_kind), left(_left), right(_right) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual BinaryExpressionAST *asBinaryExpression() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *left;
|
|
|
|
|
ExpressionAST *right;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT UnaryExpressionAST: public ExpressionAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
UnaryExpressionAST(Kind _kind, ExpressionAST *_expr)
|
|
|
|
|
: ExpressionAST(_kind), expr(_expr) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual UnaryExpressionAST *asUnaryExpression() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *expr;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT TernaryExpressionAST: public ExpressionAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
TernaryExpressionAST(Kind _kind, ExpressionAST *_first, ExpressionAST *_second, ExpressionAST *_third)
|
|
|
|
|
: ExpressionAST(_kind), first(_first), second(_second), third(_third) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual TernaryExpressionAST *asTernaryExpression() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *first;
|
|
|
|
|
ExpressionAST *second;
|
|
|
|
|
ExpressionAST *third;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT AssignmentExpressionAST: public ExpressionAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
AssignmentExpressionAST(Kind _kind, ExpressionAST *_variable, ExpressionAST *_value)
|
|
|
|
|
: ExpressionAST(_kind), variable(_variable), value(_value) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual AssignmentExpressionAST *asAssignmentExpression() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *variable;
|
|
|
|
|
ExpressionAST *value;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT MemberAccessExpressionAST: public ExpressionAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
MemberAccessExpressionAST(ExpressionAST *_expr, const QString *_field)
|
|
|
|
|
: ExpressionAST(Kind_MemberAccess), expr(_expr), field(_field) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual MemberAccessExpressionAST *asMemberAccessExpression() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *expr;
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *field;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT FunctionCallExpressionAST: public ExpressionAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
FunctionCallExpressionAST(FunctionIdentifierAST *_id,
|
|
|
|
|
List<ExpressionAST *> *_arguments)
|
|
|
|
|
: ExpressionAST(Kind_FunctionCall), expr(0), id(_id)
|
2010-11-12 09:05:48 +10:00
|
|
|
, arguments(finish(_arguments)) {}
|
2010-11-25 12:19:57 +01:00
|
|
|
FunctionCallExpressionAST(ExpressionAST *_expr, FunctionIdentifierAST *_id,
|
|
|
|
|
List<ExpressionAST *> *_arguments)
|
|
|
|
|
: ExpressionAST(Kind_MemberFunctionCall), expr(_expr), id(_id)
|
2010-11-12 09:05:48 +10:00
|
|
|
, arguments(finish(_arguments)) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual FunctionCallExpressionAST *asFunctionCallExpression() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *expr;
|
|
|
|
|
FunctionIdentifierAST *id;
|
|
|
|
|
List<ExpressionAST *> *arguments;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT FunctionIdentifierAST: public AST
|
2010-11-12 10:23:46 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
FunctionIdentifierAST(const QString *_name)
|
2010-11-12 10:23:46 +10:00
|
|
|
: AST(Kind_FunctionIdentifier), name(_name), type(0) {}
|
2010-11-25 12:19:57 +01:00
|
|
|
FunctionIdentifierAST(TypeAST *_type)
|
2010-11-12 10:23:46 +10:00
|
|
|
: AST(Kind_FunctionIdentifier), name(0), type(_type) {}
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual FunctionIdentifierAST *asFunctionIdentifier() { return this; }
|
2010-11-12 10:23:46 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *name;
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST *type;
|
2010-11-12 10:23:46 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT DeclarationExpressionAST: public ExpressionAST
|
2010-11-17 14:46:11 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
DeclarationExpressionAST(TypeAST *_type, const QString *_name,
|
|
|
|
|
ExpressionAST *_initializer)
|
|
|
|
|
: ExpressionAST(Kind_DeclarationExpression), type(_type)
|
2010-11-17 14:46:11 +10:00
|
|
|
, name(_name), initializer(_initializer) {}
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual DeclarationExpressionAST *asDeclarationExpression() { return this; }
|
2010-11-17 14:46:11 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST *type;
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *name;
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *initializer;
|
2010-11-17 14:46:11 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT StatementAST: public AST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
protected:
|
2010-11-25 12:19:57 +01:00
|
|
|
StatementAST(Kind _kind) : AST(_kind) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual StatementAST *asStatement() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT ExpressionStatementAST: public StatementAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionStatementAST(ExpressionAST *_expr)
|
|
|
|
|
: StatementAST(Kind_ExpressionStatement), expr(_expr) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual ExpressionStatementAST *asExpressionStatement() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *expr;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT CompoundStatementAST: public StatementAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
CompoundStatementAST()
|
2010-11-29 17:21:47 +01:00
|
|
|
: StatementAST(Kind_CompoundStatement), statements(0)
|
|
|
|
|
, start(0), end(0), symbol(0) {}
|
2010-11-25 12:19:57 +01:00
|
|
|
CompoundStatementAST(List<StatementAST *> *_statements)
|
2010-11-29 17:21:47 +01:00
|
|
|
: StatementAST(Kind_CompoundStatement), statements(finish(_statements))
|
|
|
|
|
, start(0), end(0), symbol(0) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual CompoundStatementAST *asCompoundStatement() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
List<StatementAST *> *statements;
|
2010-11-29 17:21:47 +01:00
|
|
|
int start;
|
|
|
|
|
int end;
|
|
|
|
|
Block *symbol; // decoration
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT IfStatementAST: public StatementAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
IfStatementAST(ExpressionAST *_condition, StatementAST *_thenClause, StatementAST *_elseClause)
|
|
|
|
|
: StatementAST(Kind_If), condition(_condition)
|
2010-11-11 11:29:29 +10:00
|
|
|
, thenClause(_thenClause), elseClause(_elseClause) {}
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual IfStatementAST *asIfStatement() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *condition;
|
|
|
|
|
StatementAST *thenClause;
|
|
|
|
|
StatementAST *elseClause;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT WhileStatementAST: public StatementAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
WhileStatementAST(ExpressionAST *_condition, StatementAST *_body)
|
|
|
|
|
: StatementAST(Kind_While), condition(_condition), body(_body) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual WhileStatementAST *asWhileStatement() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *condition;
|
|
|
|
|
StatementAST *body;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT DoStatementAST: public StatementAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
DoStatementAST(StatementAST *_body, ExpressionAST *_condition)
|
|
|
|
|
: StatementAST(Kind_Do), body(_body), condition(_condition) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual DoStatementAST *asDoStatement() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
StatementAST *body;
|
|
|
|
|
ExpressionAST *condition;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT ForStatementAST: public StatementAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
ForStatementAST(StatementAST *_init, ExpressionAST *_condition, ExpressionAST *_increment, StatementAST *_body)
|
|
|
|
|
: StatementAST(Kind_For), init(_init), condition(_condition), increment(_increment), body(_body) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual ForStatementAST *asForStatement() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
StatementAST *init;
|
|
|
|
|
ExpressionAST *condition;
|
|
|
|
|
ExpressionAST *increment;
|
|
|
|
|
StatementAST *body;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT JumpStatementAST: public StatementAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
JumpStatementAST(Kind _kind) : StatementAST(_kind) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual JumpStatementAST *asJumpStatement() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT ReturnStatementAST: public StatementAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
ReturnStatementAST() : StatementAST(Kind_Return), expr(0) {}
|
|
|
|
|
ReturnStatementAST(ExpressionAST *_expr)
|
|
|
|
|
: StatementAST(Kind_ReturnExpression), expr(_expr) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual ReturnStatementAST *asReturnStatement() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *expr;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT SwitchStatementAST: public StatementAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
SwitchStatementAST(ExpressionAST *_expr, StatementAST *_body)
|
|
|
|
|
: StatementAST(Kind_Switch), expr(_expr), body(_body) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual SwitchStatementAST *asSwitchStatement() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *expr;
|
|
|
|
|
StatementAST *body;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT CaseLabelStatementAST: public StatementAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
CaseLabelStatementAST() : StatementAST(Kind_DefaultLabel), expr(0) {}
|
|
|
|
|
CaseLabelStatementAST(ExpressionAST *_expr)
|
|
|
|
|
: StatementAST(Kind_CaseLabel), expr(_expr) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual CaseLabelStatementAST *asCaseLabelStatement() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *expr;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT DeclarationStatementAST: public StatementAST
|
2010-11-17 14:46:11 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-26 10:06:05 +10:00
|
|
|
DeclarationStatementAST(DeclarationAST *_decl)
|
|
|
|
|
: StatementAST(Kind_DeclarationStatement), decl(_decl) {}
|
2010-11-17 14:46:11 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual DeclarationStatementAST *asDeclarationStatement() { return this; }
|
2010-11-17 14:46:11 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-26 10:06:05 +10:00
|
|
|
DeclarationAST *decl;
|
2010-11-17 14:46:11 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT TypeAST: public AST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
protected:
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST(Kind _kind) : AST(_kind) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
enum Precision
|
|
|
|
|
{
|
2010-11-12 10:23:46 +10:00
|
|
|
PrecNotValid, // Precision not valid (e.g. structs).
|
2010-11-11 11:29:29 +10:00
|
|
|
PrecUnspecified, // Precision not known, but can be validly set.
|
|
|
|
|
Lowp,
|
|
|
|
|
Mediump,
|
|
|
|
|
Highp
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual TypeAST *asType() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual Precision precision() const = 0;
|
|
|
|
|
|
|
|
|
|
// Set the precision for the innermost basic type. Returns false if it
|
2010-11-12 10:23:46 +10:00
|
|
|
// is not valid to set a precision (e.g. structs).
|
2010-11-11 11:29:29 +10:00
|
|
|
virtual bool setPrecision(Precision precision) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT BasicTypeAST: public TypeAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
// Pass the parser's token code: T_VOID, T_VEC4, etc.
|
2010-11-29 13:04:54 +10:00
|
|
|
BasicTypeAST(int _token, const char *_name);
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual BasicTypeAST *asBasicType() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
virtual Precision precision() const;
|
|
|
|
|
virtual bool setPrecision(Precision precision);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
|
|
|
|
Precision prec;
|
|
|
|
|
int token;
|
2010-11-12 10:23:46 +10:00
|
|
|
const char *name;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT NamedTypeAST: public TypeAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
NamedTypeAST(const QString *_name) : TypeAST(Kind_NamedType), name(_name) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual NamedTypeAST *asNamedType() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
virtual Precision precision() const;
|
|
|
|
|
virtual bool setPrecision(Precision precision);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *name;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT ArrayTypeAST: public TypeAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
ArrayTypeAST(TypeAST *_elementType)
|
|
|
|
|
: TypeAST(Kind_OpenArrayType), elementType(_elementType), size(0) {}
|
|
|
|
|
ArrayTypeAST(TypeAST *_elementType, ExpressionAST *_size)
|
|
|
|
|
: TypeAST(Kind_ArrayType), elementType(_elementType), size(_size) {}
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual ArrayTypeAST *asArrayType() { return this; }
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
virtual Precision precision() const;
|
|
|
|
|
virtual bool setPrecision(Precision precision);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST *elementType;
|
|
|
|
|
ExpressionAST *size;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT StructTypeAST: public TypeAST
|
2010-11-11 11:29:29 +10:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
class Field: public AST
|
|
|
|
|
{
|
|
|
|
|
public:
|
2010-11-18 15:57:44 +10:00
|
|
|
Field(const QString *_name)
|
2010-11-11 11:29:29 +10:00
|
|
|
: AST(Kind_StructField), name(_name), type(0) {}
|
|
|
|
|
|
|
|
|
|
// Takes the outer shell of an array type with the innermost
|
|
|
|
|
// element type set to null. The fixInnerTypes() method will
|
|
|
|
|
// set the innermost element type to a meaningful value.
|
2010-11-25 12:19:57 +01:00
|
|
|
Field(const QString *_name, TypeAST *_type)
|
2010-11-11 11:29:29 +10:00
|
|
|
: AST(Kind_StructField), name(_name), type(_type) {}
|
|
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
void setInnerType(TypeAST *innerType);
|
2010-11-11 11:29:29 +10:00
|
|
|
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *name;
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST *type;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
StructTypeAST(List<Field *> *_fields)
|
|
|
|
|
: TypeAST(Kind_AnonymousStructType), fields(finish(_fields)) {}
|
|
|
|
|
StructTypeAST(const QString *_name, List<Field *> *_fields)
|
|
|
|
|
: TypeAST(Kind_StructType), name(_name), fields(finish(_fields)) {}
|
2010-11-12 09:05:48 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual StructTypeAST *asStructType() { return this; }
|
2010-11-12 09:05:48 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
virtual Precision precision() const;
|
|
|
|
|
virtual bool setPrecision(Precision precision);
|
|
|
|
|
|
2010-11-11 11:29:29 +10:00
|
|
|
// Fix the inner types of a field list. The "innerType" will
|
2010-11-12 09:05:48 +10:00
|
|
|
// be copied into the "array holes" of all fields.
|
2010-11-25 12:19:57 +01:00
|
|
|
static List<Field *> *fixInnerTypes(TypeAST *innerType, List<Field *> *fields);
|
2010-11-11 11:29:29 +10:00
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *name;
|
2010-11-12 09:05:48 +10:00
|
|
|
List<Field *> *fields;
|
2010-11-11 11:29:29 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-15 15:02:21 +10:00
|
|
|
class GLSL_EXPORT LayoutQualifier
|
|
|
|
|
{
|
|
|
|
|
public:
|
2010-11-18 15:57:44 +10:00
|
|
|
LayoutQualifier(const QString *_name, const QString *_number)
|
2010-11-15 15:02:21 +10:00
|
|
|
: name(_name), number(_number), lineno(0) {}
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *name;
|
|
|
|
|
const QString *number;
|
2010-11-15 15:02:21 +10:00
|
|
|
int lineno;
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT QualifiedTypeAST: public TypeAST
|
2010-11-15 15:02:21 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
QualifiedTypeAST(int _qualifiers, TypeAST *_type, List<LayoutQualifier *> *_layout_list)
|
|
|
|
|
: TypeAST(Kind_QualifiedType), qualifiers(_qualifiers), type(_type)
|
2010-11-17 14:46:11 +10:00
|
|
|
, layout_list(finish(_layout_list)) {}
|
2010-11-15 15:02:21 +10:00
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
StorageMask = 0x000000FF,
|
|
|
|
|
NoStorage = 0x00000000,
|
|
|
|
|
Const = 0x00000001,
|
|
|
|
|
Attribute = 0x00000002,
|
|
|
|
|
Varying = 0x00000003,
|
|
|
|
|
CentroidVarying = 0x00000004,
|
|
|
|
|
In = 0x00000005,
|
|
|
|
|
Out = 0x00000006,
|
|
|
|
|
CentroidIn = 0x00000007,
|
|
|
|
|
CentroidOut = 0x00000008,
|
|
|
|
|
PatchIn = 0x00000009,
|
|
|
|
|
PatchOut = 0x0000000A,
|
|
|
|
|
SampleIn = 0x0000000B,
|
|
|
|
|
SampleOut = 0x0000000C,
|
|
|
|
|
Uniform = 0x0000000D,
|
|
|
|
|
InterpolationMask = 0x00000F00,
|
|
|
|
|
NoInterpolation = 0x00000000,
|
|
|
|
|
Smooth = 0x00000100,
|
|
|
|
|
Flat = 0x00000200,
|
|
|
|
|
NoPerspective = 0x00000300,
|
2010-11-29 13:04:54 +10:00
|
|
|
Invariant = 0x00010000,
|
|
|
|
|
Struct = 0x00020000
|
2010-11-15 15:02:21 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual QualifiedTypeAST *asQualifiedType() { return this; }
|
2010-11-15 15:02:21 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
virtual Precision precision() const { return type->precision(); }
|
|
|
|
|
virtual bool setPrecision(Precision precision) { return type->setPrecision(precision); }
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
|
|
|
|
int qualifiers;
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST *type;
|
2010-11-15 15:02:21 +10:00
|
|
|
List<LayoutQualifier *> *layout_list;
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT DeclarationAST: public AST
|
2010-11-12 10:23:46 +10:00
|
|
|
{
|
|
|
|
|
protected:
|
2010-11-25 12:19:57 +01:00
|
|
|
DeclarationAST(Kind _kind) : AST(_kind) {}
|
2010-11-12 10:23:46 +10:00
|
|
|
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual DeclarationAST *asDeclaration() { return this; }
|
2010-11-12 10:23:46 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT PrecisionDeclarationAST: public DeclarationAST
|
2010-11-12 10:23:46 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
PrecisionDeclarationAST(TypeAST::Precision _precision, TypeAST *_type)
|
|
|
|
|
: DeclarationAST(Kind_PrecisionDeclaration)
|
2010-11-12 10:23:46 +10:00
|
|
|
, precision(_precision), type(_type) {}
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual PrecisionDeclarationAST *asPrecisionDeclaration() { return this; }
|
2010-11-12 10:23:46 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST::Precision precision;
|
|
|
|
|
TypeAST *type;
|
2010-11-12 10:23:46 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT ParameterDeclarationAST: public DeclarationAST
|
2010-11-17 14:46:11 +10:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
enum Qualifier
|
|
|
|
|
{
|
|
|
|
|
In,
|
|
|
|
|
Out,
|
|
|
|
|
InOut
|
|
|
|
|
};
|
2010-11-25 12:19:57 +01:00
|
|
|
ParameterDeclarationAST(TypeAST *_type, Qualifier _qualifier,
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *_name)
|
2010-11-25 12:19:57 +01:00
|
|
|
: DeclarationAST(Kind_ParameterDeclaration), type(_type)
|
2010-11-17 14:46:11 +10:00
|
|
|
, qualifier(_qualifier), name(_name) {}
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual ParameterDeclarationAST *asParameterDeclaration() { return this; }
|
2010-11-17 14:46:11 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST *type;
|
2010-11-17 14:46:11 +10:00
|
|
|
Qualifier qualifier;
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *name;
|
2010-11-17 14:46:11 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT VariableDeclarationAST: public DeclarationAST
|
2010-11-17 14:46:11 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
VariableDeclarationAST(TypeAST *_type, const QString *_name,
|
|
|
|
|
ExpressionAST *_initializer = 0)
|
|
|
|
|
: DeclarationAST(Kind_VariableDeclaration), type(_type)
|
2010-11-17 14:46:11 +10:00
|
|
|
, name(_name), initializer(_initializer) {}
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual VariableDeclarationAST *asVariableDeclaration() { return this; }
|
2010-11-17 14:46:11 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
static TypeAST *declarationType(List<DeclarationAST *> *decls);
|
2010-11-17 14:46:11 +10:00
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST *type;
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *name;
|
2010-11-25 12:19:57 +01:00
|
|
|
ExpressionAST *initializer;
|
2010-11-17 14:46:11 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT TypeDeclarationAST: public DeclarationAST
|
2010-11-17 14:46:11 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeDeclarationAST(TypeAST *_type)
|
|
|
|
|
: DeclarationAST(Kind_TypeDeclaration), type(_type) {}
|
2010-11-17 14:46:11 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual TypeDeclarationAST *asTypeDeclaration() { return this; }
|
2010-11-17 14:46:11 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST *type;
|
2010-11-17 14:46:11 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT TypeAndVariableDeclarationAST: public DeclarationAST
|
2010-11-18 13:01:27 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAndVariableDeclarationAST(TypeDeclarationAST *_typeDecl,
|
|
|
|
|
VariableDeclarationAST *_varDecl)
|
|
|
|
|
: DeclarationAST(Kind_TypeAndVariableDeclaration)
|
2010-11-18 13:01:27 +10:00
|
|
|
, typeDecl(_typeDecl), varDecl(_varDecl) {}
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual TypeAndVariableDeclarationAST *asTypeAndVariableDeclaration() { return this; }
|
2010-11-18 13:01:27 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeDeclarationAST *typeDecl;
|
|
|
|
|
VariableDeclarationAST *varDecl;
|
2010-11-18 13:01:27 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT InvariantDeclarationAST: public DeclarationAST
|
2010-11-17 14:46:11 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
InvariantDeclarationAST(const QString *_name)
|
|
|
|
|
: DeclarationAST(Kind_InvariantDeclaration), name(_name) {}
|
2010-11-17 14:46:11 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual InvariantDeclarationAST *asInvariantDeclaration() { return this; }
|
2010-11-17 14:46:11 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *name;
|
2010-11-17 14:46:11 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT InitDeclarationAST: public DeclarationAST
|
2010-11-17 14:46:11 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
InitDeclarationAST(List<DeclarationAST *> *_decls)
|
|
|
|
|
: DeclarationAST(Kind_InitDeclaration), decls(finish(_decls)) {}
|
2010-11-17 14:46:11 +10:00
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual InitDeclarationAST *asInitDeclaration() { return this; }
|
2010-11-17 14:46:11 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
List<DeclarationAST *> *decls;
|
2010-11-17 14:46:11 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
class GLSL_EXPORT FunctionDeclarationAST : public DeclarationAST
|
2010-11-18 13:01:27 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2010-11-25 12:19:57 +01:00
|
|
|
FunctionDeclarationAST(TypeAST *_returnType, const QString *_name)
|
|
|
|
|
: DeclarationAST(Kind_FunctionDeclaration), returnType(_returnType)
|
2010-11-18 13:01:27 +10:00
|
|
|
, name(_name), params(0), body(0) {}
|
|
|
|
|
|
2010-11-25 12:19:57 +01:00
|
|
|
virtual FunctionDeclarationAST *asFunctionDeclaration() { return this; }
|
2010-11-18 13:01:27 +10:00
|
|
|
|
|
|
|
|
virtual void accept0(Visitor *visitor);
|
|
|
|
|
|
|
|
|
|
void finishParams() { params = finish(params); }
|
|
|
|
|
|
|
|
|
|
bool isPrototype() const { return body == 0; }
|
|
|
|
|
|
|
|
|
|
public: // attributes
|
2010-11-25 12:19:57 +01:00
|
|
|
TypeAST *returnType;
|
2010-11-18 15:57:44 +10:00
|
|
|
const QString *name;
|
2010-11-25 12:19:57 +01:00
|
|
|
List<ParameterDeclarationAST *> *params;
|
|
|
|
|
StatementAST *body;
|
2010-11-18 13:01:27 +10:00
|
|
|
};
|
|
|
|
|
|
2010-11-10 12:32:34 +01:00
|
|
|
} // namespace GLSL
|
|
|
|
|
|
|
|
|
|
#endif // GLSLAST_H
|