Added the suffix AST to the ast nodes and some initial work on the GLSL type system.

This commit is contained in:
Roberto Raggi
2010-11-25 12:19:57 +01:00
parent 6c74dbbac0
commit 864c3bfc98
16 changed files with 1596 additions and 1144 deletions

View File

@@ -1,9 +1,9 @@
HEADERS += $$PWD/glsl.h $$PWD/glsllexer.h $$PWD/glslparser.h $$PWD/glslparsertable_p.h $$PWD/glslast.h \
$$PWD/glslastvisitor.h $$PWD/glslengine.h $$PWD/glslmemorypool.h $$PWD/glslastdump.h \
$$PWD/glslsemantic.h
$$PWD/glslsemantic.h $$PWD/glsltypes.h
SOURCES += $$PWD/glslkeywords.cpp $$PWD/glslparser.cpp $$PWD/glslparsertable.cpp \
$$PWD/glsllexer.cpp $$PWD/glslast.cpp \
$$PWD/glslastvisitor.cpp $$PWD/glslengine.cpp $$PWD/glslmemorypool.cpp $$PWD/glslastdump.cpp \
$$PWD/glslsemantic.cpp
$$PWD/glslsemantic.cpp $$PWD/glsltypes.cpp
OTHER_FILES = $$PWD/glsl.g

File diff suppressed because it is too large Load Diff

View File

@@ -47,6 +47,20 @@ class Engine;
class Lexer;
class Parser;
class MemoryPool;
// types
class Type;
class UndefinedType;
class VoidType;
class BoolType;
class IntType;
class UIntType;
class FloatType;
class DoubleType;
class OpaqueType;
class VectorType;
class MatrixType;
class AST;
template <typename T> class List;
}

View File

@@ -45,7 +45,7 @@ void AST::accept(AST *ast, Visitor *visitor)
ast->accept(visitor);
}
void TranslationUnit::accept0(Visitor *visitor)
void TranslationUnitAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(declarations, visitor);
@@ -53,19 +53,19 @@ void TranslationUnit::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void IdentifierExpression::accept0(Visitor *visitor)
void IdentifierExpressionAST::accept0(Visitor *visitor)
{
visitor->visit(this);
visitor->endVisit(this);
}
void LiteralExpression::accept0(Visitor *visitor)
void LiteralExpressionAST::accept0(Visitor *visitor)
{
visitor->visit(this);
visitor->endVisit(this);
}
void BinaryExpression::accept0(Visitor *visitor)
void BinaryExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(left, visitor);
@@ -74,14 +74,14 @@ void BinaryExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void UnaryExpression::accept0(Visitor *visitor)
void UnaryExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(expr, visitor);
visitor->endVisit(this);
}
void TernaryExpression::accept0(Visitor *visitor)
void TernaryExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(first, visitor);
@@ -91,7 +91,7 @@ void TernaryExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void AssignmentExpression::accept0(Visitor *visitor)
void AssignmentExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(variable, visitor);
@@ -100,14 +100,14 @@ void AssignmentExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void MemberAccessExpression::accept0(Visitor *visitor)
void MemberAccessExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(expr, visitor);
visitor->endVisit(this);
}
void FunctionCallExpression::accept0(Visitor *visitor)
void FunctionCallExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(expr, visitor);
@@ -117,14 +117,14 @@ void FunctionCallExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void FunctionIdentifier::accept0(Visitor *visitor)
void FunctionIdentifierAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(type, visitor);
visitor->endVisit(this);
}
void DeclarationExpression::accept0(Visitor *visitor)
void DeclarationExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(type, visitor);
@@ -133,21 +133,21 @@ void DeclarationExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void ExpressionStatement::accept0(Visitor *visitor)
void ExpressionStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(expr, visitor);
visitor->endVisit(this);
}
void CompoundStatement::accept0(Visitor *visitor)
void CompoundStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(statements, visitor);
visitor->endVisit(this);
}
void IfStatement::accept0(Visitor *visitor)
void IfStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(condition, visitor);
@@ -157,7 +157,7 @@ void IfStatement::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void WhileStatement::accept0(Visitor *visitor)
void WhileStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(condition, visitor);
@@ -166,7 +166,7 @@ void WhileStatement::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void DoStatement::accept0(Visitor *visitor)
void DoStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(body, visitor);
@@ -175,7 +175,7 @@ void DoStatement::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void ForStatement::accept0(Visitor *visitor)
void ForStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(init, visitor);
@@ -186,20 +186,20 @@ void ForStatement::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void JumpStatement::accept0(Visitor *visitor)
void JumpStatementAST::accept0(Visitor *visitor)
{
visitor->visit(this);
visitor->endVisit(this);
}
void ReturnStatement::accept0(Visitor *visitor)
void ReturnStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(expr, visitor);
visitor->endVisit(this);
}
void SwitchStatement::accept0(Visitor *visitor)
void SwitchStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(expr, visitor);
@@ -208,22 +208,22 @@ void SwitchStatement::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void CaseLabelStatement::accept0(Visitor *visitor)
void CaseLabelStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(expr, visitor);
visitor->endVisit(this);
}
void DeclarationStatement::accept0(Visitor *visitor)
void DeclarationStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(decls, visitor);
visitor->endVisit(this);
}
BasicType::BasicType(int _token, const char *_name, Category _category)
: Type(Kind_BasicType), token(_token), name(_name), categ(_category)
BasicTypeAST::BasicTypeAST(int _token, const char *_name, Category _category)
: TypeAST(Kind_BasicType), token(_token), name(_name), categ(_category)
{
switch (token) {
case GLSLParserTable::T_VOID:
@@ -239,18 +239,18 @@ BasicType::BasicType(int _token, const char *_name, Category _category)
}
}
void BasicType::accept0(Visitor *visitor)
void BasicTypeAST::accept0(Visitor *visitor)
{
visitor->visit(this);
visitor->endVisit(this);
}
Type::Precision BasicType::precision() const
TypeAST::Precision BasicTypeAST::precision() const
{
return prec;
}
bool BasicType::setPrecision(Precision precision)
bool BasicTypeAST::setPrecision(Precision precision)
{
if (prec == PrecNotValid)
return false;
@@ -258,24 +258,24 @@ bool BasicType::setPrecision(Precision precision)
return true;
}
void NamedType::accept0(Visitor *visitor)
void NamedTypeAST::accept0(Visitor *visitor)
{
visitor->visit(this);
visitor->endVisit(this);
}
Type::Precision NamedType::precision() const
TypeAST::Precision NamedTypeAST::precision() const
{
// Named types are typically structs, which cannot have their precision set.
return PrecNotValid;
}
bool NamedType::setPrecision(Precision)
bool NamedTypeAST::setPrecision(Precision)
{
return false;
}
void ArrayType::accept0(Visitor *visitor)
void ArrayTypeAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(elementType, visitor);
@@ -284,12 +284,12 @@ void ArrayType::accept0(Visitor *visitor)
visitor->endVisit(this);
}
Type::Precision ArrayType::precision() const
TypeAST::Precision ArrayTypeAST::precision() const
{
return elementType ? elementType->precision() : PrecNotValid;
}
bool ArrayType::setPrecision(Precision precision)
bool ArrayTypeAST::setPrecision(Precision precision)
{
if (elementType)
return elementType->setPrecision(precision);
@@ -297,39 +297,39 @@ bool ArrayType::setPrecision(Precision precision)
return false;
}
void StructType::accept0(Visitor *visitor)
void StructTypeAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(fields, visitor);
visitor->endVisit(this);
}
Type::Precision StructType::precision() const
TypeAST::Precision StructTypeAST::precision() const
{
return PrecNotValid;
}
bool StructType::setPrecision(Precision)
bool StructTypeAST::setPrecision(Precision)
{
// Structs cannot have a precision set.
return false;
}
void StructType::Field::accept0(Visitor *visitor)
void StructTypeAST::Field::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(type, visitor);
visitor->endVisit(this);
}
void StructType::Field::setInnerType(Type *innerType)
void StructTypeAST::Field::setInnerType(TypeAST *innerType)
{
if (!innerType)
return;
Type **parent = &type;
Type *inner = type;
TypeAST **parent = &type;
TypeAST *inner = type;
while (inner != 0) {
ArrayType *array = inner->asArrayType();
ArrayTypeAST *array = inner->asArrayType();
if (!array)
break;
parent = &(array->elementType);
@@ -338,7 +338,7 @@ void StructType::Field::setInnerType(Type *innerType)
*parent = innerType;
}
List<StructType::Field *> *StructType::fixInnerTypes(Type *innerType, List<Field *> *fields)
List<StructTypeAST::Field *> *StructTypeAST::fixInnerTypes(TypeAST *innerType, List<Field *> *fields)
{
if (!fields)
return fields;
@@ -351,28 +351,28 @@ List<StructType::Field *> *StructType::fixInnerTypes(Type *innerType, List<Field
return fields;
}
void QualifiedType::accept0(Visitor *visitor)
void QualifiedTypeAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(type, visitor);
visitor->endVisit(this);
}
void PrecisionDeclaration::accept0(Visitor *visitor)
void PrecisionDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(type, visitor);
visitor->endVisit(this);
}
void ParameterDeclaration::accept0(Visitor *visitor)
void ParameterDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(type, visitor);
visitor->endVisit(this);
}
void VariableDeclaration::accept0(Visitor *visitor)
void VariableDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(type, visitor);
@@ -381,20 +381,20 @@ void VariableDeclaration::accept0(Visitor *visitor)
visitor->endVisit(this);
}
Type *VariableDeclaration::declarationType(List<Declaration *> *decls)
TypeAST *VariableDeclarationAST::declarationType(List<DeclarationAST *> *decls)
{
VariableDeclaration *var = decls->value->asVariableDeclaration();
VariableDeclarationAST *var = decls->value->asVariableDeclaration();
return var ? var->type : 0;
}
void TypeDeclaration::accept0(Visitor *visitor)
void TypeDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(type, visitor);
visitor->endVisit(this);
}
void TypeAndVariableDeclaration::accept0(Visitor *visitor)
void TypeAndVariableDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(typeDecl, visitor);
@@ -403,20 +403,20 @@ void TypeAndVariableDeclaration::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void InvariantDeclaration::accept0(Visitor *visitor)
void InvariantDeclarationAST::accept0(Visitor *visitor)
{
visitor->visit(this);
visitor->endVisit(this);
}
void InitDeclaration::accept0(Visitor *visitor)
void InitDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(decls, visitor);
visitor->endVisit(this);
}
void FunctionDeclaration::accept0(Visitor *visitor)
void FunctionDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(returnType, visitor);

File diff suppressed because it is too large Load Diff

View File

@@ -44,113 +44,113 @@ public:
virtual bool preVisit(AST *) { return true; }
virtual void postVisit(AST *) {}
virtual bool visit(TranslationUnit *) { return true; }
virtual void endVisit(TranslationUnit *) {}
virtual bool visit(TranslationUnitAST *) { return true; }
virtual void endVisit(TranslationUnitAST *) {}
virtual bool visit(IdentifierExpression *) { return true; }
virtual void endVisit(IdentifierExpression *) {}
virtual bool visit(IdentifierExpressionAST *) { return true; }
virtual void endVisit(IdentifierExpressionAST *) {}
virtual bool visit(LiteralExpression *) { return true; }
virtual void endVisit(LiteralExpression *) {}
virtual bool visit(LiteralExpressionAST *) { return true; }
virtual void endVisit(LiteralExpressionAST *) {}
virtual bool visit(BinaryExpression *) { return true; }
virtual void endVisit(BinaryExpression *) {}
virtual bool visit(BinaryExpressionAST *) { return true; }
virtual void endVisit(BinaryExpressionAST *) {}
virtual bool visit(UnaryExpression *) { return true; }
virtual void endVisit(UnaryExpression *) {}
virtual bool visit(UnaryExpressionAST *) { return true; }
virtual void endVisit(UnaryExpressionAST *) {}
virtual bool visit(TernaryExpression *) { return true; }
virtual void endVisit(TernaryExpression *) {}
virtual bool visit(TernaryExpressionAST *) { return true; }
virtual void endVisit(TernaryExpressionAST *) {}
virtual bool visit(AssignmentExpression *) { return true; }
virtual void endVisit(AssignmentExpression *) {}
virtual bool visit(AssignmentExpressionAST *) { return true; }
virtual void endVisit(AssignmentExpressionAST *) {}
virtual bool visit(MemberAccessExpression *) { return true; }
virtual void endVisit(MemberAccessExpression *) {}
virtual bool visit(MemberAccessExpressionAST *) { return true; }
virtual void endVisit(MemberAccessExpressionAST *) {}
virtual bool visit(FunctionCallExpression *) { return true; }
virtual void endVisit(FunctionCallExpression *) {}
virtual bool visit(FunctionCallExpressionAST *) { return true; }
virtual void endVisit(FunctionCallExpressionAST *) {}
virtual bool visit(FunctionIdentifier *) { return true; }
virtual void endVisit(FunctionIdentifier *) {}
virtual bool visit(FunctionIdentifierAST *) { return true; }
virtual void endVisit(FunctionIdentifierAST *) {}
virtual bool visit(DeclarationExpression *) { return true; }
virtual void endVisit(DeclarationExpression *) {}
virtual bool visit(DeclarationExpressionAST *) { return true; }
virtual void endVisit(DeclarationExpressionAST *) {}
virtual bool visit(ExpressionStatement *) { return true; }
virtual void endVisit(ExpressionStatement *) {}
virtual bool visit(ExpressionStatementAST *) { return true; }
virtual void endVisit(ExpressionStatementAST *) {}
virtual bool visit(CompoundStatement *) { return true; }
virtual void endVisit(CompoundStatement *) {}
virtual bool visit(CompoundStatementAST *) { return true; }
virtual void endVisit(CompoundStatementAST *) {}
virtual bool visit(IfStatement *) { return true; }
virtual void endVisit(IfStatement *) {}
virtual bool visit(IfStatementAST *) { return true; }
virtual void endVisit(IfStatementAST *) {}
virtual bool visit(WhileStatement *) { return true; }
virtual void endVisit(WhileStatement *) {}
virtual bool visit(WhileStatementAST *) { return true; }
virtual void endVisit(WhileStatementAST *) {}
virtual bool visit(DoStatement *) { return true; }
virtual void endVisit(DoStatement *) {}
virtual bool visit(DoStatementAST *) { return true; }
virtual void endVisit(DoStatementAST *) {}
virtual bool visit(ForStatement *) { return true; }
virtual void endVisit(ForStatement *) {}
virtual bool visit(ForStatementAST *) { return true; }
virtual void endVisit(ForStatementAST *) {}
virtual bool visit(JumpStatement *) { return true; }
virtual void endVisit(JumpStatement *) {}
virtual bool visit(JumpStatementAST *) { return true; }
virtual void endVisit(JumpStatementAST *) {}
virtual bool visit(ReturnStatement *) { return true; }
virtual void endVisit(ReturnStatement *) {}
virtual bool visit(ReturnStatementAST *) { return true; }
virtual void endVisit(ReturnStatementAST *) {}
virtual bool visit(SwitchStatement *) { return true; }
virtual void endVisit(SwitchStatement *) {}
virtual bool visit(SwitchStatementAST *) { return true; }
virtual void endVisit(SwitchStatementAST *) {}
virtual bool visit(CaseLabelStatement *) { return true; }
virtual void endVisit(CaseLabelStatement *) {}
virtual bool visit(CaseLabelStatementAST *) { return true; }
virtual void endVisit(CaseLabelStatementAST *) {}
virtual bool visit(DeclarationStatement *) { return true; }
virtual void endVisit(DeclarationStatement *) {}
virtual bool visit(DeclarationStatementAST *) { return true; }
virtual void endVisit(DeclarationStatementAST *) {}
virtual bool visit(BasicType *) { return true; }
virtual void endVisit(BasicType *) {}
virtual bool visit(BasicTypeAST *) { return true; }
virtual void endVisit(BasicTypeAST *) {}
virtual bool visit(NamedType *) { return true; }
virtual void endVisit(NamedType *) {}
virtual bool visit(NamedTypeAST *) { return true; }
virtual void endVisit(NamedTypeAST *) {}
virtual bool visit(ArrayType *) { return true; }
virtual void endVisit(ArrayType *) {}
virtual bool visit(ArrayTypeAST *) { return true; }
virtual void endVisit(ArrayTypeAST *) {}
virtual bool visit(StructType *) { return true; }
virtual void endVisit(StructType *) {}
virtual bool visit(StructTypeAST *) { return true; }
virtual void endVisit(StructTypeAST *) {}
virtual bool visit(StructType::Field *) { return true; }
virtual void endVisit(StructType::Field *) {}
virtual bool visit(StructTypeAST::Field *) { return true; }
virtual void endVisit(StructTypeAST::Field *) {}
virtual bool visit(QualifiedType *) { return true; }
virtual void endVisit(QualifiedType *) {}
virtual bool visit(QualifiedTypeAST *) { return true; }
virtual void endVisit(QualifiedTypeAST *) {}
virtual bool visit(PrecisionDeclaration *) { return true; }
virtual void endVisit(PrecisionDeclaration *) {}
virtual bool visit(PrecisionDeclarationAST *) { return true; }
virtual void endVisit(PrecisionDeclarationAST *) {}
virtual bool visit(ParameterDeclaration *) { return true; }
virtual void endVisit(ParameterDeclaration *) {}
virtual bool visit(ParameterDeclarationAST *) { return true; }
virtual void endVisit(ParameterDeclarationAST *) {}
virtual bool visit(VariableDeclaration *) { return true; }
virtual void endVisit(VariableDeclaration *) {}
virtual bool visit(VariableDeclarationAST *) { return true; }
virtual void endVisit(VariableDeclarationAST *) {}
virtual bool visit(TypeDeclaration *) { return true; }
virtual void endVisit(TypeDeclaration *) {}
virtual bool visit(TypeDeclarationAST *) { return true; }
virtual void endVisit(TypeDeclarationAST *) {}
virtual bool visit(TypeAndVariableDeclaration *) { return true; }
virtual void endVisit(TypeAndVariableDeclaration *) {}
virtual bool visit(TypeAndVariableDeclarationAST *) { return true; }
virtual void endVisit(TypeAndVariableDeclarationAST *) {}
virtual bool visit(InvariantDeclaration *) { return true; }
virtual void endVisit(InvariantDeclaration *) {}
virtual bool visit(InvariantDeclarationAST *) { return true; }
virtual void endVisit(InvariantDeclarationAST *) {}
virtual bool visit(InitDeclaration *) { return true; }
virtual void endVisit(InitDeclaration *) {}
virtual bool visit(InitDeclarationAST *) { return true; }
virtual void endVisit(InitDeclarationAST *) {}
virtual bool visit(FunctionDeclaration *) { return true; }
virtual void endVisit(FunctionDeclaration *) {}
virtual bool visit(FunctionDeclarationAST *) { return true; }
virtual void endVisit(FunctionDeclarationAST *) {}
};
} // namespace GLSL

View File

@@ -99,6 +99,59 @@ MemoryPool *Engine::pool()
return &_pool;
}
const UndefinedType *Engine::undefinedType()
{
static UndefinedType t;
return &t;
}
const VoidType *Engine::voidType()
{
static VoidType t;
return &t;
}
const BoolType *Engine::boolType()
{
static BoolType t;
return &t;
}
const IntType *Engine::intType()
{
static IntType t;
return &t;
}
const UIntType *Engine::uintType()
{
static UIntType t;
return &t;
}
const FloatType *Engine::floatType()
{
static FloatType t;
return &t;
}
const DoubleType *Engine::doubleType()
{
static DoubleType t;
return &t;
}
const VectorType *Engine::vectorType(const Type *elementType, int dimension)
{
return _vectorTypes.intern(VectorType(elementType, dimension));
}
const MatrixType *Engine::matrixType(const Type *elementType, int columns, int rows)
{
return _matrixTypes.intern(MatrixType(elementType, columns, rows));
}
QList<DiagnosticMessage> Engine::diagnosticMessages() const
{
return _diagnosticMessages;

View File

@@ -32,8 +32,11 @@
#include "glsl.h"
#include "glslmemorypool.h"
#include "glsltypes.h"
#include <QtCore/qstring.h>
#include <QtCore/qset.h>
#include <functional>
#include <set>
namespace GLSL {
@@ -69,6 +72,21 @@ private:
int _line;
};
template <typename _Type>
class TypeTable
{
public:
struct Compare: std::binary_function<_Type, _Type, bool> {
bool operator()(const _Type &value, const _Type &other) const {
return value.isLessThan(&other);
}
};
const _Type *intern(const _Type &ty) { return &*_entries.insert(ty).first; }
private:
std::set<_Type, Compare> _entries;
};
class GLSL_EXPORT Engine
{
@@ -80,6 +98,16 @@ public:
const QString *identifier(const char *s, int n);
QSet<QString> identifiers() const;
const UndefinedType *undefinedType();
const VoidType *voidType();
const BoolType *boolType();
const IntType *intType();
const UIntType *uintType();
const FloatType *floatType();
const DoubleType *doubleType();
const VectorType *vectorType(const Type *elementType, int dimension);
const MatrixType *matrixType(const Type *elementType, int columns, int rows);
MemoryPool *pool();
QList<DiagnosticMessage> diagnosticMessages() const;
@@ -88,6 +116,8 @@ public:
private:
QSet<QString> _identifiers;
TypeTable<VectorType> _vectorTypes;
TypeTable<MatrixType> _matrixTypes;
MemoryPool _pool;
QList<DiagnosticMessage> _diagnosticMessages;
};

File diff suppressed because it is too large Load Diff

View File

@@ -47,30 +47,30 @@ public:
const QString *string;
AST *ast;
List<AST *> *ast_list;
Declaration *declaration;
List<Declaration *> *declaration_list;
Expression *expression;
List<Expression *> *expression_list;
Statement *statement;
List<Statement *> *statement_list;
Type *type;
StructType::Field *field;
List<StructType::Field *> *field_list;
TranslationUnit *translation_unit;
FunctionIdentifier *function_identifier;
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;
AST::Kind kind;
Type::Precision precision;
TypeAST::Precision precision;
struct {
Statement *thenClause;
Statement *elseClause;
StatementAST *thenClause;
StatementAST *elseClause;
} ifstmt;
struct {
Expression *condition;
Expression *increment;
ExpressionAST *condition;
ExpressionAST *increment;
} forstmt;
struct {
FunctionIdentifier *id;
List<Expression *> *arguments;
FunctionIdentifierAST *id;
List<ExpressionAST *> *arguments;
} function;
int qualifier;
LayoutQualifier *layout;
@@ -80,27 +80,27 @@ public:
List<LayoutQualifier *> *layout_list;
} type_qualifier;
struct {
Type *type;
TypeAST *type;
const QString *name;
} param_declarator;
ParameterDeclaration *param_declaration;
FunctionDeclaration *function_declaration;
ParameterDeclarationAST *param_declaration;
FunctionDeclarationAST *function_declaration;
};
Parser(Engine *engine, const char *source, unsigned size, int variant);
~Parser();
TranslationUnit *parse();
TranslationUnitAST *parse();
private:
// 1-based
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; }
Expression *&expression(int n) { return _symStack[_tos + n - 1].expression; }
Statement *&statement(int n) { return _symStack[_tos + n - 1].statement; }
Type *&type(int n) { return _symStack[_tos + n - 1].type; }
FunctionDeclaration *&function(int n) { return _symStack[_tos + n - 1].function_declaration; }
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; }
inline int consumeToken() { return _index++; }
inline const Token &tokenAt(int index) const { return _tokens.at(index); }
@@ -165,9 +165,9 @@ private:
return node;
}
Type *makeBasicType(int token, BasicType::Category category)
TypeAST *makeBasicType(int token, BasicTypeAST::Category category)
{
Type *type = new (_engine->pool()) BasicType(token, spell[token], category);
TypeAST *type = new (_engine->pool()) BasicTypeAST(token, spell[token], category);
type->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
return type;
}

View File

@@ -39,58 +39,58 @@ Semantic::~Semantic()
{
}
void Semantic::expression(Expression *ast)
void Semantic::expression(ExpressionAST *ast)
{
accept(ast);
}
void Semantic::statement(Statement *ast)
void Semantic::statement(StatementAST *ast)
{
accept(ast);
}
void Semantic::type(Type *ast)
void Semantic::type(TypeAST *ast)
{
accept(ast);
}
void Semantic::declaration(Declaration *ast)
void Semantic::declaration(DeclarationAST *ast)
{
accept(ast);
}
void Semantic::translationUnit(TranslationUnit *ast)
void Semantic::translationUnit(TranslationUnitAST *ast)
{
accept(ast);
}
void Semantic::functionIdentifier(FunctionIdentifier *ast)
void Semantic::functionIdentifier(FunctionIdentifierAST *ast)
{
accept(ast);
}
void Semantic::field(StructType::Field *ast)
void Semantic::field(StructTypeAST::Field *ast)
{
accept(ast);
}
bool Semantic::visit(TranslationUnit *ast)
bool Semantic::visit(TranslationUnitAST *ast)
{
for (List<Declaration *> *it = ast->declarations; it; it = it->next) {
Declaration *decl = it->value;
for (List<DeclarationAST *> *it = ast->declarations; it; it = it->next) {
DeclarationAST *decl = it->value;
declaration(decl);
}
return false;
}
bool Semantic::visit(FunctionIdentifier *ast)
bool Semantic::visit(FunctionIdentifierAST *ast)
{
// ast->name
type(ast->type);
return false;
}
bool Semantic::visit(StructType::Field *ast)
bool Semantic::visit(StructTypeAST::Field *ast)
{
// ast->name
type(ast->type);
@@ -99,32 +99,32 @@ bool Semantic::visit(StructType::Field *ast)
// expressions
bool Semantic::visit(IdentifierExpression *ast)
bool Semantic::visit(IdentifierExpressionAST *ast)
{
Q_UNUSED(ast);
return false;
}
bool Semantic::visit(LiteralExpression *ast)
bool Semantic::visit(LiteralExpressionAST *ast)
{
Q_UNUSED(ast);
return false;
}
bool Semantic::visit(BinaryExpression *ast)
bool Semantic::visit(BinaryExpressionAST *ast)
{
expression(ast->left);
expression(ast->right);
return false;
}
bool Semantic::visit(UnaryExpression *ast)
bool Semantic::visit(UnaryExpressionAST *ast)
{
expression(ast->expr);
return false;
}
bool Semantic::visit(TernaryExpression *ast)
bool Semantic::visit(TernaryExpressionAST *ast)
{
expression(ast->first);
expression(ast->second);
@@ -132,33 +132,33 @@ bool Semantic::visit(TernaryExpression *ast)
return false;
}
bool Semantic::visit(AssignmentExpression *ast)
bool Semantic::visit(AssignmentExpressionAST *ast)
{
expression(ast->variable);
expression(ast->value);
return false;
}
bool Semantic::visit(MemberAccessExpression *ast)
bool Semantic::visit(MemberAccessExpressionAST *ast)
{
expression(ast->expr);
// ast->field
return false;
}
bool Semantic::visit(FunctionCallExpression *ast)
bool Semantic::visit(FunctionCallExpressionAST *ast)
{
expression(ast->expr);
functionIdentifier(ast->id);
for (List<Expression *> *it = ast->arguments; it; it = it->next) {
Expression *arg = it->value;
for (List<ExpressionAST *> *it = ast->arguments; it; it = it->next) {
ExpressionAST *arg = it->value;
expression(arg);
}
return false;
}
bool Semantic::visit(DeclarationExpression *ast)
bool Semantic::visit(DeclarationExpressionAST *ast)
{
type(ast->type);
// ast->name
@@ -168,22 +168,22 @@ bool Semantic::visit(DeclarationExpression *ast)
// statements
bool Semantic::visit(ExpressionStatement *ast)
bool Semantic::visit(ExpressionStatementAST *ast)
{
expression(ast->expr);
return false;
}
bool Semantic::visit(CompoundStatement *ast)
bool Semantic::visit(CompoundStatementAST *ast)
{
for (List<Statement *> *it = ast->statements; it; it = it->next) {
Statement *stmt = it->value;
for (List<StatementAST *> *it = ast->statements; it; it = it->next) {
StatementAST *stmt = it->value;
statement(stmt);
}
return false;
}
bool Semantic::visit(IfStatement *ast)
bool Semantic::visit(IfStatementAST *ast)
{
expression(ast->condition);
statement(ast->thenClause);
@@ -191,21 +191,21 @@ bool Semantic::visit(IfStatement *ast)
return false;
}
bool Semantic::visit(WhileStatement *ast)
bool Semantic::visit(WhileStatementAST *ast)
{
expression(ast->condition);
statement(ast->body);
return false;
}
bool Semantic::visit(DoStatement *ast)
bool Semantic::visit(DoStatementAST *ast)
{
statement(ast->body);
expression(ast->condition);
return false;
}
bool Semantic::visit(ForStatement *ast)
bool Semantic::visit(ForStatementAST *ast)
{
statement(ast->init);
expression(ast->condition);
@@ -214,35 +214,35 @@ bool Semantic::visit(ForStatement *ast)
return false;
}
bool Semantic::visit(JumpStatement *ast)
bool Semantic::visit(JumpStatementAST *ast)
{
Q_UNUSED(ast);
return false;
}
bool Semantic::visit(ReturnStatement *ast)
bool Semantic::visit(ReturnStatementAST *ast)
{
expression(ast->expr);
return false;
}
bool Semantic::visit(SwitchStatement *ast)
bool Semantic::visit(SwitchStatementAST *ast)
{
expression(ast->expr);
statement(ast->body);
return false;
}
bool Semantic::visit(CaseLabelStatement *ast)
bool Semantic::visit(CaseLabelStatementAST *ast)
{
expression(ast->expr);
return false;
}
bool Semantic::visit(DeclarationStatement *ast)
bool Semantic::visit(DeclarationStatementAST *ast)
{
for (List<Declaration *> *it = ast->decls; it; it = it->next) {
Declaration *decl = it->value;
for (List<DeclarationAST *> *it = ast->decls; it; it = it->next) {
DeclarationAST *decl = it->value;
declaration(decl);
}
return false;
@@ -250,36 +250,36 @@ bool Semantic::visit(DeclarationStatement *ast)
// types
bool Semantic::visit(BasicType *ast)
bool Semantic::visit(BasicTypeAST *ast)
{
Q_UNUSED(ast);
return false;
}
bool Semantic::visit(NamedType *ast)
bool Semantic::visit(NamedTypeAST *ast)
{
Q_UNUSED(ast);
return false;
}
bool Semantic::visit(ArrayType *ast)
bool Semantic::visit(ArrayTypeAST *ast)
{
type(ast->elementType);
expression(ast->size);
return false;
}
bool Semantic::visit(StructType *ast)
bool Semantic::visit(StructTypeAST *ast)
{
// ast->name
for (List<StructType::Field *> *it = ast->fields; it; it = it->next) {
StructType::Field *f = it->value;
for (List<StructTypeAST::Field *> *it = ast->fields; it; it = it->next) {
StructTypeAST::Field *f = it->value;
field(f);
}
return false;
}
bool Semantic::visit(QualifiedType *ast)
bool Semantic::visit(QualifiedTypeAST *ast)
{
accept(ast->type);
for (List<LayoutQualifier *> *it = ast->layout_list; it; it = it->next) {
@@ -293,58 +293,58 @@ bool Semantic::visit(QualifiedType *ast)
// declarations
bool Semantic::visit(PrecisionDeclaration *ast)
bool Semantic::visit(PrecisionDeclarationAST *ast)
{
type(ast->type);
return false;
}
bool Semantic::visit(ParameterDeclaration *ast)
bool Semantic::visit(ParameterDeclarationAST *ast)
{
type(ast->type);
return false;
}
bool Semantic::visit(VariableDeclaration *ast)
bool Semantic::visit(VariableDeclarationAST *ast)
{
type(ast->type);
expression(ast->initializer);
return false;
}
bool Semantic::visit(TypeDeclaration *ast)
bool Semantic::visit(TypeDeclarationAST *ast)
{
type(ast->type);
return false;
}
bool Semantic::visit(TypeAndVariableDeclaration *ast)
bool Semantic::visit(TypeAndVariableDeclarationAST *ast)
{
declaration(ast->typeDecl);
declaration(ast->varDecl);
return false;
}
bool Semantic::visit(InvariantDeclaration *ast)
bool Semantic::visit(InvariantDeclarationAST *ast)
{
Q_UNUSED(ast);
return false;
}
bool Semantic::visit(InitDeclaration *ast)
bool Semantic::visit(InitDeclarationAST *ast)
{
for (List<Declaration *> *it = ast->decls; it; it = it->next) {
Declaration *decl = it->value;
for (List<DeclarationAST *> *it = ast->decls; it; it = it->next) {
DeclarationAST *decl = it->value;
declaration(decl);
}
return false;
}
bool Semantic::visit(FunctionDeclaration *ast)
bool Semantic::visit(FunctionDeclarationAST *ast)
{
type(ast->returnType);
for (List<ParameterDeclaration *> *it = ast->params; it; it = it->next) {
ParameterDeclaration *decl = it->value;
for (List<ParameterDeclarationAST *> *it = ast->params; it; it = it->next) {
ParameterDeclarationAST *decl = it->value;
declaration(decl);
}
statement(ast->body);

View File

@@ -39,59 +39,59 @@ public:
Semantic();
virtual ~Semantic();
void expression(Expression *ast);
void statement(Statement *ast);
void type(Type *ast);
void declaration(Declaration *ast);
void translationUnit(TranslationUnit *ast);
void functionIdentifier(FunctionIdentifier *ast);
void field(StructType::Field *ast);
void expression(ExpressionAST *ast);
void statement(StatementAST *ast);
void type(TypeAST *ast);
void declaration(DeclarationAST *ast);
void translationUnit(TranslationUnitAST *ast);
void functionIdentifier(FunctionIdentifierAST *ast);
void field(StructTypeAST::Field *ast);
protected:
virtual bool visit(TranslationUnit *ast);
virtual bool visit(FunctionIdentifier *ast);
virtual bool visit(StructType::Field *ast);
virtual bool visit(TranslationUnitAST *ast);
virtual bool visit(FunctionIdentifierAST *ast);
virtual bool visit(StructTypeAST::Field *ast);
// expressions
virtual bool visit(IdentifierExpression *ast);
virtual bool visit(LiteralExpression *ast);
virtual bool visit(BinaryExpression *ast);
virtual bool visit(UnaryExpression *ast);
virtual bool visit(TernaryExpression *ast);
virtual bool visit(AssignmentExpression *ast);
virtual bool visit(MemberAccessExpression *ast);
virtual bool visit(FunctionCallExpression *ast);
virtual bool visit(DeclarationExpression *ast);
virtual bool visit(IdentifierExpressionAST *ast);
virtual bool visit(LiteralExpressionAST *ast);
virtual bool visit(BinaryExpressionAST *ast);
virtual bool visit(UnaryExpressionAST *ast);
virtual bool visit(TernaryExpressionAST *ast);
virtual bool visit(AssignmentExpressionAST *ast);
virtual bool visit(MemberAccessExpressionAST *ast);
virtual bool visit(FunctionCallExpressionAST *ast);
virtual bool visit(DeclarationExpressionAST *ast);
// statements
virtual bool visit(ExpressionStatement *ast);
virtual bool visit(CompoundStatement *ast);
virtual bool visit(IfStatement *ast);
virtual bool visit(WhileStatement *ast);
virtual bool visit(DoStatement *ast);
virtual bool visit(ForStatement *ast);
virtual bool visit(JumpStatement *ast);
virtual bool visit(ReturnStatement *ast);
virtual bool visit(SwitchStatement *ast);
virtual bool visit(CaseLabelStatement *ast);
virtual bool visit(DeclarationStatement *ast);
virtual bool visit(ExpressionStatementAST *ast);
virtual bool visit(CompoundStatementAST *ast);
virtual bool visit(IfStatementAST *ast);
virtual bool visit(WhileStatementAST *ast);
virtual bool visit(DoStatementAST *ast);
virtual bool visit(ForStatementAST *ast);
virtual bool visit(JumpStatementAST *ast);
virtual bool visit(ReturnStatementAST *ast);
virtual bool visit(SwitchStatementAST *ast);
virtual bool visit(CaseLabelStatementAST *ast);
virtual bool visit(DeclarationStatementAST *ast);
// types
virtual bool visit(BasicType *ast);
virtual bool visit(NamedType *ast);
virtual bool visit(ArrayType *ast);
virtual bool visit(StructType *ast);
virtual bool visit(QualifiedType *ast);
virtual bool visit(BasicTypeAST *ast);
virtual bool visit(NamedTypeAST *ast);
virtual bool visit(ArrayTypeAST *ast);
virtual bool visit(StructTypeAST *ast);
virtual bool visit(QualifiedTypeAST *ast);
// declarations
virtual bool visit(PrecisionDeclaration *ast);
virtual bool visit(ParameterDeclaration *ast);
virtual bool visit(VariableDeclaration *ast);
virtual bool visit(TypeDeclaration *ast);
virtual bool visit(TypeAndVariableDeclaration *ast);
virtual bool visit(InvariantDeclaration *ast);
virtual bool visit(InitDeclaration *ast);
virtual bool visit(FunctionDeclaration *ast);
virtual bool visit(PrecisionDeclarationAST *ast);
virtual bool visit(ParameterDeclarationAST *ast);
virtual bool visit(VariableDeclarationAST *ast);
virtual bool visit(TypeDeclarationAST *ast);
virtual bool visit(TypeAndVariableDeclarationAST *ast);
virtual bool visit(InvariantDeclarationAST *ast);
virtual bool visit(InitDeclarationAST *ast);
virtual bool visit(FunctionDeclarationAST *ast);
};
} // namespace GLSL

197
src/libs/glsl/glsltypes.cpp Normal file
View File

@@ -0,0 +1,197 @@
/**************************************************************************
**
** 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.
**
**************************************************************************/
#include "glsltypes.h"
#include <QtCore/qglobal.h>
using namespace GLSL;
bool UndefinedType::isEqualTo(const Type *other) const
{
if (other && other->asUndefinedType() != 0)
return true;
return false;
}
bool UndefinedType::isLessThan(const Type *other) const
{
Q_UNUSED(other);
Q_ASSERT(other != 0);
Q_ASSERT(other->asUndefinedType() != 0);
return false;
}
bool VoidType::isEqualTo(const Type *other) const
{
if (other && other->asVoidType() != 0)
return true;
return false;
}
bool VoidType::isLessThan(const Type *other) const
{
Q_UNUSED(other);
Q_ASSERT(other != 0);
Q_ASSERT(other->asVoidType() != 0);
return false;
}
bool BoolType::isEqualTo(const Type *other) const
{
if (other && other->asBoolType() != 0)
return true;
return false;
}
bool BoolType::isLessThan(const Type *other) const
{
Q_UNUSED(other);
Q_ASSERT(other != 0);
Q_ASSERT(other->asBoolType() != 0);
return false;
}
bool IntType::isEqualTo(const Type *other) const
{
if (other && other->asIntType() != 0)
return true;
return false;
}
bool IntType::isLessThan(const Type *other) const
{
Q_UNUSED(other);
Q_ASSERT(other != 0);
Q_ASSERT(other->asIntType() != 0);
return false;
}
bool UIntType::isEqualTo(const Type *other) const
{
if (other && other->asUIntType() != 0)
return true;
return false;
}
bool UIntType::isLessThan(const Type *other) const
{
Q_UNUSED(other);
Q_ASSERT(other != 0);
Q_ASSERT(other->asUIntType() != 0);
return false;
}
bool FloatType::isEqualTo(const Type *other) const
{
if (other && other->asFloatType() != 0)
return true;
return false;
}
bool FloatType::isLessThan(const Type *other) const
{
Q_UNUSED(other);
Q_ASSERT(other != 0);
Q_ASSERT(other->asFloatType() != 0);
return false;
}
bool DoubleType::isEqualTo(const Type *other) const
{
if (other && other->asDoubleType() != 0)
return true;
return false;
}
bool DoubleType::isLessThan(const Type *other) const
{
Q_UNUSED(other);
Q_ASSERT(other != 0);
Q_ASSERT(other->asDoubleType() != 0);
return false;
}
bool VectorType::isEqualTo(const Type *other) const
{
if (other) {
if (const VectorType *v = other->asVectorType()) {
if (_dimension != v->dimension())
return false;
else if (_elementType != v->elementType())
return false;
return true;
}
}
return false;
}
bool VectorType::isLessThan(const Type *other) const
{
Q_ASSERT(other != 0);
const VectorType *vec = other->asVectorType();
Q_ASSERT(vec != 0);
if (_dimension < vec->dimension())
return true;
else if (_dimension == vec->dimension() && _elementType < vec->elementType())
return true;
return false;
}
bool MatrixType::isEqualTo(const Type *other) const
{
if (other) {
if (const MatrixType *v = other->asMatrixType()) {
if (_columns != v->columns())
return false;
else if (_rows != v->rows())
return false;
else if (_elementType != v->elementType())
return false;
return true;
}
}
return false;
}
bool MatrixType::isLessThan(const Type *other) const
{
Q_ASSERT(other != 0);
const MatrixType *mat = other->asMatrixType();
Q_ASSERT(mat != 0);
if (_columns < mat->columns())
return true;
else if (_columns == mat->columns()) {
if (_rows < mat->rows())
return true;
else if (_rows == mat->rows() && _elementType < mat->elementType())
return true;
}
return false;
}

158
src/libs/glsl/glsltypes.h Normal file
View File

@@ -0,0 +1,158 @@
/**************************************************************************
**
** 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.
**
**************************************************************************/
#ifndef GLSLTYPES_H
#define GLSLTYPES_H
#include "glsl.h"
namespace GLSL {
class GLSL_EXPORT Type
{
public:
virtual ~Type() {}
virtual const UndefinedType *asUndefinedType() const { return 0; }
virtual const VoidType *asVoidType() const { return 0; }
virtual const BoolType *asBoolType() const { return 0; }
virtual const IntType *asIntType() const { return 0; }
virtual const UIntType *asUIntType() const { return 0; }
virtual const FloatType *asFloatType() const { return 0; }
virtual const DoubleType *asDoubleType() const { return 0; }
virtual const OpaqueType *asOpaqueType() const { return 0; }
virtual const VectorType *asVectorType() const { return 0; }
virtual const MatrixType *asMatrixType() const { return 0; }
virtual bool isEqualTo(const Type *other) const = 0;
virtual bool isLessThan(const Type *other) const = 0;
};
class GLSL_EXPORT OpaqueType: public Type
{
public:
virtual const OpaqueType *asOpaqueType() const { return this; }
};
class GLSL_EXPORT UndefinedType: public Type
{
public:
virtual const UndefinedType *asUndefinedType() const { return this; }
virtual bool isEqualTo(const Type *other) const;
virtual bool isLessThan(const Type *other) const;
};
class GLSL_EXPORT VoidType: public Type
{
public:
virtual const VoidType *asVoidType() const { return this; }
virtual bool isEqualTo(const Type *other) const;
virtual bool isLessThan(const Type *other) const;
};
class GLSL_EXPORT BoolType: public Type
{
public:
virtual const BoolType *asBoolType() const { return this; }
virtual bool isEqualTo(const Type *other) const;
virtual bool isLessThan(const Type *other) const;
};
class GLSL_EXPORT IntType: public Type
{
public:
virtual const IntType *asIntType() const { return this; }
virtual bool isEqualTo(const Type *other) const;
virtual bool isLessThan(const Type *other) const;
};
class GLSL_EXPORT UIntType: public Type
{
public:
virtual const UIntType *asUIntType() const { return this; }
virtual bool isEqualTo(const Type *other) const;
virtual bool isLessThan(const Type *other) const;
};
class GLSL_EXPORT FloatType: public Type
{
public:
virtual const FloatType *asFloatType() const { return this; }
virtual bool isEqualTo(const Type *other) const;
virtual bool isLessThan(const Type *other) const;
};
class GLSL_EXPORT DoubleType: public Type
{
public:
virtual const DoubleType *asDoubleType() const { return this; }
virtual bool isEqualTo(const Type *other) const;
virtual bool isLessThan(const Type *other) const;
};
class GLSL_EXPORT VectorType: public Type
{
public:
VectorType(const Type *elementType, int dimension)
: _elementType(elementType), _dimension(dimension) {}
const Type *elementType() const { return _elementType; }
int dimension() const { return _dimension; }
virtual const VectorType *asVectorType() const { return this; }
virtual bool isEqualTo(const Type *other) const;
virtual bool isLessThan(const Type *other) const;
private:
const Type *_elementType;
int _dimension;
};
class GLSL_EXPORT MatrixType: public Type
{
public:
MatrixType(const Type *elementType, int columns, int rows)
: _elementType(elementType), _columns(columns), _rows(rows) {}
const Type *elementType() const { return _elementType; }
int columns() const { return _columns; }
int rows() const { return _rows; }
virtual const MatrixType *asMatrixType() const { return this; }
virtual bool isEqualTo(const Type *other) const;
virtual bool isLessThan(const Type *other) const;
private:
const Type *_elementType;
int _columns;
int _rows;
};
} // end of namespace GLSL
#endif // GLSLTYPES_H

View File

@@ -75,7 +75,7 @@ int main(int argc, char *argv[])
variant |= Lexer::Variant_VertexShader | Lexer::Variant_FragmentShader;
Engine engine;
Parser parser(&engine, source, size, variant);
TranslationUnit *ast = parser.parse();
TranslationUnitAST *ast = parser.parse();
std::cout << argv[1] << (ast ? " OK " : " KO ") << std::endl;
ASTDump dump(qout);

View File

@@ -264,7 +264,7 @@ void GLSLTextEditor::updateDocumentNow()
Engine engine;
Parser parser(&engine, preprocessedCode.constData(), preprocessedCode.size(), variant);
TranslationUnit *ast = parser.parse();
TranslationUnitAST *ast = parser.parse();
QTextCharFormat errorFormat;
errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);