forked from qt-creator/qt-creator
Added the suffix AST to the ast nodes and some initial work on the GLSL type system.
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
HEADERS += $$PWD/glsl.h $$PWD/glsllexer.h $$PWD/glslparser.h $$PWD/glslparsertable_p.h $$PWD/glslast.h \
|
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/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 \
|
SOURCES += $$PWD/glslkeywords.cpp $$PWD/glslparser.cpp $$PWD/glslparsertable.cpp \
|
||||||
$$PWD/glsllexer.cpp $$PWD/glslast.cpp \
|
$$PWD/glsllexer.cpp $$PWD/glslast.cpp \
|
||||||
$$PWD/glslastvisitor.cpp $$PWD/glslengine.cpp $$PWD/glslmemorypool.cpp $$PWD/glslastdump.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
|
OTHER_FILES = $$PWD/glsl.g
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -47,6 +47,20 @@ class Engine;
|
|||||||
class Lexer;
|
class Lexer;
|
||||||
class Parser;
|
class Parser;
|
||||||
class MemoryPool;
|
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;
|
class AST;
|
||||||
template <typename T> class List;
|
template <typename T> class List;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ void AST::accept(AST *ast, Visitor *visitor)
|
|||||||
ast->accept(visitor);
|
ast->accept(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TranslationUnit::accept0(Visitor *visitor)
|
void TranslationUnitAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(declarations, visitor);
|
accept(declarations, visitor);
|
||||||
@@ -53,19 +53,19 @@ void TranslationUnit::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IdentifierExpression::accept0(Visitor *visitor)
|
void IdentifierExpressionAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
visitor->visit(this);
|
visitor->visit(this);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiteralExpression::accept0(Visitor *visitor)
|
void LiteralExpressionAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
visitor->visit(this);
|
visitor->visit(this);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryExpression::accept0(Visitor *visitor)
|
void BinaryExpressionAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(left, visitor);
|
accept(left, visitor);
|
||||||
@@ -74,14 +74,14 @@ void BinaryExpression::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnaryExpression::accept0(Visitor *visitor)
|
void UnaryExpressionAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(expr, visitor);
|
accept(expr, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TernaryExpression::accept0(Visitor *visitor)
|
void TernaryExpressionAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(first, visitor);
|
accept(first, visitor);
|
||||||
@@ -91,7 +91,7 @@ void TernaryExpression::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignmentExpression::accept0(Visitor *visitor)
|
void AssignmentExpressionAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(variable, visitor);
|
accept(variable, visitor);
|
||||||
@@ -100,14 +100,14 @@ void AssignmentExpression::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemberAccessExpression::accept0(Visitor *visitor)
|
void MemberAccessExpressionAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(expr, visitor);
|
accept(expr, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunctionCallExpression::accept0(Visitor *visitor)
|
void FunctionCallExpressionAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(expr, visitor);
|
accept(expr, visitor);
|
||||||
@@ -117,14 +117,14 @@ void FunctionCallExpression::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunctionIdentifier::accept0(Visitor *visitor)
|
void FunctionIdentifierAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(type, visitor);
|
accept(type, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclarationExpression::accept0(Visitor *visitor)
|
void DeclarationExpressionAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(type, visitor);
|
accept(type, visitor);
|
||||||
@@ -133,21 +133,21 @@ void DeclarationExpression::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressionStatement::accept0(Visitor *visitor)
|
void ExpressionStatementAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(expr, visitor);
|
accept(expr, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompoundStatement::accept0(Visitor *visitor)
|
void CompoundStatementAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(statements, visitor);
|
accept(statements, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IfStatement::accept0(Visitor *visitor)
|
void IfStatementAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(condition, visitor);
|
accept(condition, visitor);
|
||||||
@@ -157,7 +157,7 @@ void IfStatement::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WhileStatement::accept0(Visitor *visitor)
|
void WhileStatementAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(condition, visitor);
|
accept(condition, visitor);
|
||||||
@@ -166,7 +166,7 @@ void WhileStatement::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoStatement::accept0(Visitor *visitor)
|
void DoStatementAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(body, visitor);
|
accept(body, visitor);
|
||||||
@@ -175,7 +175,7 @@ void DoStatement::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ForStatement::accept0(Visitor *visitor)
|
void ForStatementAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(init, visitor);
|
accept(init, visitor);
|
||||||
@@ -186,20 +186,20 @@ void ForStatement::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JumpStatement::accept0(Visitor *visitor)
|
void JumpStatementAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
visitor->visit(this);
|
visitor->visit(this);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReturnStatement::accept0(Visitor *visitor)
|
void ReturnStatementAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(expr, visitor);
|
accept(expr, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchStatement::accept0(Visitor *visitor)
|
void SwitchStatementAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(expr, visitor);
|
accept(expr, visitor);
|
||||||
@@ -208,22 +208,22 @@ void SwitchStatement::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CaseLabelStatement::accept0(Visitor *visitor)
|
void CaseLabelStatementAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(expr, visitor);
|
accept(expr, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclarationStatement::accept0(Visitor *visitor)
|
void DeclarationStatementAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(decls, visitor);
|
accept(decls, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicType::BasicType(int _token, const char *_name, Category _category)
|
BasicTypeAST::BasicTypeAST(int _token, const char *_name, Category _category)
|
||||||
: Type(Kind_BasicType), token(_token), name(_name), categ(_category)
|
: TypeAST(Kind_BasicType), token(_token), name(_name), categ(_category)
|
||||||
{
|
{
|
||||||
switch (token) {
|
switch (token) {
|
||||||
case GLSLParserTable::T_VOID:
|
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->visit(this);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Type::Precision BasicType::precision() const
|
TypeAST::Precision BasicTypeAST::precision() const
|
||||||
{
|
{
|
||||||
return prec;
|
return prec;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BasicType::setPrecision(Precision precision)
|
bool BasicTypeAST::setPrecision(Precision precision)
|
||||||
{
|
{
|
||||||
if (prec == PrecNotValid)
|
if (prec == PrecNotValid)
|
||||||
return false;
|
return false;
|
||||||
@@ -258,24 +258,24 @@ bool BasicType::setPrecision(Precision precision)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NamedType::accept0(Visitor *visitor)
|
void NamedTypeAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
visitor->visit(this);
|
visitor->visit(this);
|
||||||
visitor->endVisit(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.
|
// Named types are typically structs, which cannot have their precision set.
|
||||||
return PrecNotValid;
|
return PrecNotValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NamedType::setPrecision(Precision)
|
bool NamedTypeAST::setPrecision(Precision)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrayType::accept0(Visitor *visitor)
|
void ArrayTypeAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(elementType, visitor);
|
accept(elementType, visitor);
|
||||||
@@ -284,12 +284,12 @@ void ArrayType::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Type::Precision ArrayType::precision() const
|
TypeAST::Precision ArrayTypeAST::precision() const
|
||||||
{
|
{
|
||||||
return elementType ? elementType->precision() : PrecNotValid;
|
return elementType ? elementType->precision() : PrecNotValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArrayType::setPrecision(Precision precision)
|
bool ArrayTypeAST::setPrecision(Precision precision)
|
||||||
{
|
{
|
||||||
if (elementType)
|
if (elementType)
|
||||||
return elementType->setPrecision(precision);
|
return elementType->setPrecision(precision);
|
||||||
@@ -297,39 +297,39 @@ bool ArrayType::setPrecision(Precision precision)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StructType::accept0(Visitor *visitor)
|
void StructTypeAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(fields, visitor);
|
accept(fields, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Type::Precision StructType::precision() const
|
TypeAST::Precision StructTypeAST::precision() const
|
||||||
{
|
{
|
||||||
return PrecNotValid;
|
return PrecNotValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StructType::setPrecision(Precision)
|
bool StructTypeAST::setPrecision(Precision)
|
||||||
{
|
{
|
||||||
// Structs cannot have a precision set.
|
// Structs cannot have a precision set.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StructType::Field::accept0(Visitor *visitor)
|
void StructTypeAST::Field::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(type, visitor);
|
accept(type, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StructType::Field::setInnerType(Type *innerType)
|
void StructTypeAST::Field::setInnerType(TypeAST *innerType)
|
||||||
{
|
{
|
||||||
if (!innerType)
|
if (!innerType)
|
||||||
return;
|
return;
|
||||||
Type **parent = &type;
|
TypeAST **parent = &type;
|
||||||
Type *inner = type;
|
TypeAST *inner = type;
|
||||||
while (inner != 0) {
|
while (inner != 0) {
|
||||||
ArrayType *array = inner->asArrayType();
|
ArrayTypeAST *array = inner->asArrayType();
|
||||||
if (!array)
|
if (!array)
|
||||||
break;
|
break;
|
||||||
parent = &(array->elementType);
|
parent = &(array->elementType);
|
||||||
@@ -338,7 +338,7 @@ void StructType::Field::setInnerType(Type *innerType)
|
|||||||
*parent = 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)
|
if (!fields)
|
||||||
return fields;
|
return fields;
|
||||||
@@ -351,28 +351,28 @@ List<StructType::Field *> *StructType::fixInnerTypes(Type *innerType, List<Field
|
|||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QualifiedType::accept0(Visitor *visitor)
|
void QualifiedTypeAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(type, visitor);
|
accept(type, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrecisionDeclaration::accept0(Visitor *visitor)
|
void PrecisionDeclarationAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(type, visitor);
|
accept(type, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParameterDeclaration::accept0(Visitor *visitor)
|
void ParameterDeclarationAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(type, visitor);
|
accept(type, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VariableDeclaration::accept0(Visitor *visitor)
|
void VariableDeclarationAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(type, visitor);
|
accept(type, visitor);
|
||||||
@@ -381,20 +381,20 @@ void VariableDeclaration::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
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;
|
return var ? var->type : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TypeDeclaration::accept0(Visitor *visitor)
|
void TypeDeclarationAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(type, visitor);
|
accept(type, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TypeAndVariableDeclaration::accept0(Visitor *visitor)
|
void TypeAndVariableDeclarationAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(typeDecl, visitor);
|
accept(typeDecl, visitor);
|
||||||
@@ -403,20 +403,20 @@ void TypeAndVariableDeclaration::accept0(Visitor *visitor)
|
|||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InvariantDeclaration::accept0(Visitor *visitor)
|
void InvariantDeclarationAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
visitor->visit(this);
|
visitor->visit(this);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitDeclaration::accept0(Visitor *visitor)
|
void InitDeclarationAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this))
|
if (visitor->visit(this))
|
||||||
accept(decls, visitor);
|
accept(decls, visitor);
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunctionDeclaration::accept0(Visitor *visitor)
|
void FunctionDeclarationAST::accept0(Visitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(returnType, visitor);
|
accept(returnType, visitor);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -44,113 +44,113 @@ public:
|
|||||||
virtual bool preVisit(AST *) { return true; }
|
virtual bool preVisit(AST *) { return true; }
|
||||||
virtual void postVisit(AST *) {}
|
virtual void postVisit(AST *) {}
|
||||||
|
|
||||||
virtual bool visit(TranslationUnit *) { return true; }
|
virtual bool visit(TranslationUnitAST *) { return true; }
|
||||||
virtual void endVisit(TranslationUnit *) {}
|
virtual void endVisit(TranslationUnitAST *) {}
|
||||||
|
|
||||||
virtual bool visit(IdentifierExpression *) { return true; }
|
virtual bool visit(IdentifierExpressionAST *) { return true; }
|
||||||
virtual void endVisit(IdentifierExpression *) {}
|
virtual void endVisit(IdentifierExpressionAST *) {}
|
||||||
|
|
||||||
virtual bool visit(LiteralExpression *) { return true; }
|
virtual bool visit(LiteralExpressionAST *) { return true; }
|
||||||
virtual void endVisit(LiteralExpression *) {}
|
virtual void endVisit(LiteralExpressionAST *) {}
|
||||||
|
|
||||||
virtual bool visit(BinaryExpression *) { return true; }
|
virtual bool visit(BinaryExpressionAST *) { return true; }
|
||||||
virtual void endVisit(BinaryExpression *) {}
|
virtual void endVisit(BinaryExpressionAST *) {}
|
||||||
|
|
||||||
virtual bool visit(UnaryExpression *) { return true; }
|
virtual bool visit(UnaryExpressionAST *) { return true; }
|
||||||
virtual void endVisit(UnaryExpression *) {}
|
virtual void endVisit(UnaryExpressionAST *) {}
|
||||||
|
|
||||||
virtual bool visit(TernaryExpression *) { return true; }
|
virtual bool visit(TernaryExpressionAST *) { return true; }
|
||||||
virtual void endVisit(TernaryExpression *) {}
|
virtual void endVisit(TernaryExpressionAST *) {}
|
||||||
|
|
||||||
virtual bool visit(AssignmentExpression *) { return true; }
|
virtual bool visit(AssignmentExpressionAST *) { return true; }
|
||||||
virtual void endVisit(AssignmentExpression *) {}
|
virtual void endVisit(AssignmentExpressionAST *) {}
|
||||||
|
|
||||||
virtual bool visit(MemberAccessExpression *) { return true; }
|
virtual bool visit(MemberAccessExpressionAST *) { return true; }
|
||||||
virtual void endVisit(MemberAccessExpression *) {}
|
virtual void endVisit(MemberAccessExpressionAST *) {}
|
||||||
|
|
||||||
virtual bool visit(FunctionCallExpression *) { return true; }
|
virtual bool visit(FunctionCallExpressionAST *) { return true; }
|
||||||
virtual void endVisit(FunctionCallExpression *) {}
|
virtual void endVisit(FunctionCallExpressionAST *) {}
|
||||||
|
|
||||||
virtual bool visit(FunctionIdentifier *) { return true; }
|
virtual bool visit(FunctionIdentifierAST *) { return true; }
|
||||||
virtual void endVisit(FunctionIdentifier *) {}
|
virtual void endVisit(FunctionIdentifierAST *) {}
|
||||||
|
|
||||||
virtual bool visit(DeclarationExpression *) { return true; }
|
virtual bool visit(DeclarationExpressionAST *) { return true; }
|
||||||
virtual void endVisit(DeclarationExpression *) {}
|
virtual void endVisit(DeclarationExpressionAST *) {}
|
||||||
|
|
||||||
virtual bool visit(ExpressionStatement *) { return true; }
|
virtual bool visit(ExpressionStatementAST *) { return true; }
|
||||||
virtual void endVisit(ExpressionStatement *) {}
|
virtual void endVisit(ExpressionStatementAST *) {}
|
||||||
|
|
||||||
virtual bool visit(CompoundStatement *) { return true; }
|
virtual bool visit(CompoundStatementAST *) { return true; }
|
||||||
virtual void endVisit(CompoundStatement *) {}
|
virtual void endVisit(CompoundStatementAST *) {}
|
||||||
|
|
||||||
virtual bool visit(IfStatement *) { return true; }
|
virtual bool visit(IfStatementAST *) { return true; }
|
||||||
virtual void endVisit(IfStatement *) {}
|
virtual void endVisit(IfStatementAST *) {}
|
||||||
|
|
||||||
virtual bool visit(WhileStatement *) { return true; }
|
virtual bool visit(WhileStatementAST *) { return true; }
|
||||||
virtual void endVisit(WhileStatement *) {}
|
virtual void endVisit(WhileStatementAST *) {}
|
||||||
|
|
||||||
virtual bool visit(DoStatement *) { return true; }
|
virtual bool visit(DoStatementAST *) { return true; }
|
||||||
virtual void endVisit(DoStatement *) {}
|
virtual void endVisit(DoStatementAST *) {}
|
||||||
|
|
||||||
virtual bool visit(ForStatement *) { return true; }
|
virtual bool visit(ForStatementAST *) { return true; }
|
||||||
virtual void endVisit(ForStatement *) {}
|
virtual void endVisit(ForStatementAST *) {}
|
||||||
|
|
||||||
virtual bool visit(JumpStatement *) { return true; }
|
virtual bool visit(JumpStatementAST *) { return true; }
|
||||||
virtual void endVisit(JumpStatement *) {}
|
virtual void endVisit(JumpStatementAST *) {}
|
||||||
|
|
||||||
virtual bool visit(ReturnStatement *) { return true; }
|
virtual bool visit(ReturnStatementAST *) { return true; }
|
||||||
virtual void endVisit(ReturnStatement *) {}
|
virtual void endVisit(ReturnStatementAST *) {}
|
||||||
|
|
||||||
virtual bool visit(SwitchStatement *) { return true; }
|
virtual bool visit(SwitchStatementAST *) { return true; }
|
||||||
virtual void endVisit(SwitchStatement *) {}
|
virtual void endVisit(SwitchStatementAST *) {}
|
||||||
|
|
||||||
virtual bool visit(CaseLabelStatement *) { return true; }
|
virtual bool visit(CaseLabelStatementAST *) { return true; }
|
||||||
virtual void endVisit(CaseLabelStatement *) {}
|
virtual void endVisit(CaseLabelStatementAST *) {}
|
||||||
|
|
||||||
virtual bool visit(DeclarationStatement *) { return true; }
|
virtual bool visit(DeclarationStatementAST *) { return true; }
|
||||||
virtual void endVisit(DeclarationStatement *) {}
|
virtual void endVisit(DeclarationStatementAST *) {}
|
||||||
|
|
||||||
virtual bool visit(BasicType *) { return true; }
|
virtual bool visit(BasicTypeAST *) { return true; }
|
||||||
virtual void endVisit(BasicType *) {}
|
virtual void endVisit(BasicTypeAST *) {}
|
||||||
|
|
||||||
virtual bool visit(NamedType *) { return true; }
|
virtual bool visit(NamedTypeAST *) { return true; }
|
||||||
virtual void endVisit(NamedType *) {}
|
virtual void endVisit(NamedTypeAST *) {}
|
||||||
|
|
||||||
virtual bool visit(ArrayType *) { return true; }
|
virtual bool visit(ArrayTypeAST *) { return true; }
|
||||||
virtual void endVisit(ArrayType *) {}
|
virtual void endVisit(ArrayTypeAST *) {}
|
||||||
|
|
||||||
virtual bool visit(StructType *) { return true; }
|
virtual bool visit(StructTypeAST *) { return true; }
|
||||||
virtual void endVisit(StructType *) {}
|
virtual void endVisit(StructTypeAST *) {}
|
||||||
|
|
||||||
virtual bool visit(StructType::Field *) { return true; }
|
virtual bool visit(StructTypeAST::Field *) { return true; }
|
||||||
virtual void endVisit(StructType::Field *) {}
|
virtual void endVisit(StructTypeAST::Field *) {}
|
||||||
|
|
||||||
virtual bool visit(QualifiedType *) { return true; }
|
virtual bool visit(QualifiedTypeAST *) { return true; }
|
||||||
virtual void endVisit(QualifiedType *) {}
|
virtual void endVisit(QualifiedTypeAST *) {}
|
||||||
|
|
||||||
virtual bool visit(PrecisionDeclaration *) { return true; }
|
virtual bool visit(PrecisionDeclarationAST *) { return true; }
|
||||||
virtual void endVisit(PrecisionDeclaration *) {}
|
virtual void endVisit(PrecisionDeclarationAST *) {}
|
||||||
|
|
||||||
virtual bool visit(ParameterDeclaration *) { return true; }
|
virtual bool visit(ParameterDeclarationAST *) { return true; }
|
||||||
virtual void endVisit(ParameterDeclaration *) {}
|
virtual void endVisit(ParameterDeclarationAST *) {}
|
||||||
|
|
||||||
virtual bool visit(VariableDeclaration *) { return true; }
|
virtual bool visit(VariableDeclarationAST *) { return true; }
|
||||||
virtual void endVisit(VariableDeclaration *) {}
|
virtual void endVisit(VariableDeclarationAST *) {}
|
||||||
|
|
||||||
virtual bool visit(TypeDeclaration *) { return true; }
|
virtual bool visit(TypeDeclarationAST *) { return true; }
|
||||||
virtual void endVisit(TypeDeclaration *) {}
|
virtual void endVisit(TypeDeclarationAST *) {}
|
||||||
|
|
||||||
virtual bool visit(TypeAndVariableDeclaration *) { return true; }
|
virtual bool visit(TypeAndVariableDeclarationAST *) { return true; }
|
||||||
virtual void endVisit(TypeAndVariableDeclaration *) {}
|
virtual void endVisit(TypeAndVariableDeclarationAST *) {}
|
||||||
|
|
||||||
virtual bool visit(InvariantDeclaration *) { return true; }
|
virtual bool visit(InvariantDeclarationAST *) { return true; }
|
||||||
virtual void endVisit(InvariantDeclaration *) {}
|
virtual void endVisit(InvariantDeclarationAST *) {}
|
||||||
|
|
||||||
virtual bool visit(InitDeclaration *) { return true; }
|
virtual bool visit(InitDeclarationAST *) { return true; }
|
||||||
virtual void endVisit(InitDeclaration *) {}
|
virtual void endVisit(InitDeclarationAST *) {}
|
||||||
|
|
||||||
virtual bool visit(FunctionDeclaration *) { return true; }
|
virtual bool visit(FunctionDeclarationAST *) { return true; }
|
||||||
virtual void endVisit(FunctionDeclaration *) {}
|
virtual void endVisit(FunctionDeclarationAST *) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GLSL
|
} // namespace GLSL
|
||||||
|
|||||||
@@ -99,6 +99,59 @@ MemoryPool *Engine::pool()
|
|||||||
return &_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
|
QList<DiagnosticMessage> Engine::diagnosticMessages() const
|
||||||
{
|
{
|
||||||
return _diagnosticMessages;
|
return _diagnosticMessages;
|
||||||
|
|||||||
@@ -32,8 +32,11 @@
|
|||||||
|
|
||||||
#include "glsl.h"
|
#include "glsl.h"
|
||||||
#include "glslmemorypool.h"
|
#include "glslmemorypool.h"
|
||||||
|
#include "glsltypes.h"
|
||||||
#include <QtCore/qstring.h>
|
#include <QtCore/qstring.h>
|
||||||
#include <QtCore/qset.h>
|
#include <QtCore/qset.h>
|
||||||
|
#include <functional>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
namespace GLSL {
|
namespace GLSL {
|
||||||
|
|
||||||
@@ -69,6 +72,21 @@ private:
|
|||||||
int _line;
|
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
|
class GLSL_EXPORT Engine
|
||||||
{
|
{
|
||||||
@@ -80,6 +98,16 @@ public:
|
|||||||
const QString *identifier(const char *s, int n);
|
const QString *identifier(const char *s, int n);
|
||||||
QSet<QString> identifiers() const;
|
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();
|
MemoryPool *pool();
|
||||||
|
|
||||||
QList<DiagnosticMessage> diagnosticMessages() const;
|
QList<DiagnosticMessage> diagnosticMessages() const;
|
||||||
@@ -88,6 +116,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QSet<QString> _identifiers;
|
QSet<QString> _identifiers;
|
||||||
|
TypeTable<VectorType> _vectorTypes;
|
||||||
|
TypeTable<MatrixType> _matrixTypes;
|
||||||
MemoryPool _pool;
|
MemoryPool _pool;
|
||||||
QList<DiagnosticMessage> _diagnosticMessages;
|
QList<DiagnosticMessage> _diagnosticMessages;
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -47,30 +47,30 @@ public:
|
|||||||
const QString *string;
|
const QString *string;
|
||||||
AST *ast;
|
AST *ast;
|
||||||
List<AST *> *ast_list;
|
List<AST *> *ast_list;
|
||||||
Declaration *declaration;
|
DeclarationAST *declaration;
|
||||||
List<Declaration *> *declaration_list;
|
List<DeclarationAST *> *declaration_list;
|
||||||
Expression *expression;
|
ExpressionAST *expression;
|
||||||
List<Expression *> *expression_list;
|
List<ExpressionAST *> *expression_list;
|
||||||
Statement *statement;
|
StatementAST *statement;
|
||||||
List<Statement *> *statement_list;
|
List<StatementAST *> *statement_list;
|
||||||
Type *type;
|
TypeAST *type;
|
||||||
StructType::Field *field;
|
StructTypeAST::Field *field;
|
||||||
List<StructType::Field *> *field_list;
|
List<StructTypeAST::Field *> *field_list;
|
||||||
TranslationUnit *translation_unit;
|
TranslationUnitAST *translation_unit;
|
||||||
FunctionIdentifier *function_identifier;
|
FunctionIdentifierAST *function_identifier;
|
||||||
AST::Kind kind;
|
AST::Kind kind;
|
||||||
Type::Precision precision;
|
TypeAST::Precision precision;
|
||||||
struct {
|
struct {
|
||||||
Statement *thenClause;
|
StatementAST *thenClause;
|
||||||
Statement *elseClause;
|
StatementAST *elseClause;
|
||||||
} ifstmt;
|
} ifstmt;
|
||||||
struct {
|
struct {
|
||||||
Expression *condition;
|
ExpressionAST *condition;
|
||||||
Expression *increment;
|
ExpressionAST *increment;
|
||||||
} forstmt;
|
} forstmt;
|
||||||
struct {
|
struct {
|
||||||
FunctionIdentifier *id;
|
FunctionIdentifierAST *id;
|
||||||
List<Expression *> *arguments;
|
List<ExpressionAST *> *arguments;
|
||||||
} function;
|
} function;
|
||||||
int qualifier;
|
int qualifier;
|
||||||
LayoutQualifier *layout;
|
LayoutQualifier *layout;
|
||||||
@@ -80,27 +80,27 @@ public:
|
|||||||
List<LayoutQualifier *> *layout_list;
|
List<LayoutQualifier *> *layout_list;
|
||||||
} type_qualifier;
|
} type_qualifier;
|
||||||
struct {
|
struct {
|
||||||
Type *type;
|
TypeAST *type;
|
||||||
const QString *name;
|
const QString *name;
|
||||||
} param_declarator;
|
} param_declarator;
|
||||||
ParameterDeclaration *param_declaration;
|
ParameterDeclarationAST *param_declaration;
|
||||||
FunctionDeclaration *function_declaration;
|
FunctionDeclarationAST *function_declaration;
|
||||||
};
|
};
|
||||||
|
|
||||||
Parser(Engine *engine, const char *source, unsigned size, int variant);
|
Parser(Engine *engine, const char *source, unsigned size, int variant);
|
||||||
~Parser();
|
~Parser();
|
||||||
|
|
||||||
TranslationUnit *parse();
|
TranslationUnitAST *parse();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// 1-based
|
// 1-based
|
||||||
Value &sym(int n) { return _symStack[_tos + n - 1]; }
|
Value &sym(int n) { return _symStack[_tos + n - 1]; }
|
||||||
AST *&ast(int n) { return _symStack[_tos + n - 1].ast; }
|
AST *&ast(int n) { return _symStack[_tos + n - 1].ast; }
|
||||||
const QString *&string(int n) { return _symStack[_tos + n - 1].string; }
|
const QString *&string(int n) { return _symStack[_tos + n - 1].string; }
|
||||||
Expression *&expression(int n) { return _symStack[_tos + n - 1].expression; }
|
ExpressionAST *&expression(int n) { return _symStack[_tos + n - 1].expression; }
|
||||||
Statement *&statement(int n) { return _symStack[_tos + n - 1].statement; }
|
StatementAST *&statement(int n) { return _symStack[_tos + n - 1].statement; }
|
||||||
Type *&type(int n) { return _symStack[_tos + n - 1].type; }
|
TypeAST *&type(int n) { return _symStack[_tos + n - 1].type; }
|
||||||
FunctionDeclaration *&function(int n) { return _symStack[_tos + n - 1].function_declaration; }
|
FunctionDeclarationAST *&function(int n) { return _symStack[_tos + n - 1].function_declaration; }
|
||||||
|
|
||||||
inline int consumeToken() { return _index++; }
|
inline int consumeToken() { return _index++; }
|
||||||
inline const Token &tokenAt(int index) const { return _tokens.at(index); }
|
inline const Token &tokenAt(int index) const { return _tokens.at(index); }
|
||||||
@@ -165,9 +165,9 @@ private:
|
|||||||
return node;
|
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;
|
type->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,58 +39,58 @@ Semantic::~Semantic()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Semantic::expression(Expression *ast)
|
void Semantic::expression(ExpressionAST *ast)
|
||||||
{
|
{
|
||||||
accept(ast);
|
accept(ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Semantic::statement(Statement *ast)
|
void Semantic::statement(StatementAST *ast)
|
||||||
{
|
{
|
||||||
accept(ast);
|
accept(ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Semantic::type(Type *ast)
|
void Semantic::type(TypeAST *ast)
|
||||||
{
|
{
|
||||||
accept(ast);
|
accept(ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Semantic::declaration(Declaration *ast)
|
void Semantic::declaration(DeclarationAST *ast)
|
||||||
{
|
{
|
||||||
accept(ast);
|
accept(ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Semantic::translationUnit(TranslationUnit *ast)
|
void Semantic::translationUnit(TranslationUnitAST *ast)
|
||||||
{
|
{
|
||||||
accept(ast);
|
accept(ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Semantic::functionIdentifier(FunctionIdentifier *ast)
|
void Semantic::functionIdentifier(FunctionIdentifierAST *ast)
|
||||||
{
|
{
|
||||||
accept(ast);
|
accept(ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Semantic::field(StructType::Field *ast)
|
void Semantic::field(StructTypeAST::Field *ast)
|
||||||
{
|
{
|
||||||
accept(ast);
|
accept(ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(TranslationUnit *ast)
|
bool Semantic::visit(TranslationUnitAST *ast)
|
||||||
{
|
{
|
||||||
for (List<Declaration *> *it = ast->declarations; it; it = it->next) {
|
for (List<DeclarationAST *> *it = ast->declarations; it; it = it->next) {
|
||||||
Declaration *decl = it->value;
|
DeclarationAST *decl = it->value;
|
||||||
declaration(decl);
|
declaration(decl);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(FunctionIdentifier *ast)
|
bool Semantic::visit(FunctionIdentifierAST *ast)
|
||||||
{
|
{
|
||||||
// ast->name
|
// ast->name
|
||||||
type(ast->type);
|
type(ast->type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(StructType::Field *ast)
|
bool Semantic::visit(StructTypeAST::Field *ast)
|
||||||
{
|
{
|
||||||
// ast->name
|
// ast->name
|
||||||
type(ast->type);
|
type(ast->type);
|
||||||
@@ -99,32 +99,32 @@ bool Semantic::visit(StructType::Field *ast)
|
|||||||
|
|
||||||
|
|
||||||
// expressions
|
// expressions
|
||||||
bool Semantic::visit(IdentifierExpression *ast)
|
bool Semantic::visit(IdentifierExpressionAST *ast)
|
||||||
{
|
{
|
||||||
Q_UNUSED(ast);
|
Q_UNUSED(ast);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(LiteralExpression *ast)
|
bool Semantic::visit(LiteralExpressionAST *ast)
|
||||||
{
|
{
|
||||||
Q_UNUSED(ast);
|
Q_UNUSED(ast);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(BinaryExpression *ast)
|
bool Semantic::visit(BinaryExpressionAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->left);
|
expression(ast->left);
|
||||||
expression(ast->right);
|
expression(ast->right);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(UnaryExpression *ast)
|
bool Semantic::visit(UnaryExpressionAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
expression(ast->expr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(TernaryExpression *ast)
|
bool Semantic::visit(TernaryExpressionAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->first);
|
expression(ast->first);
|
||||||
expression(ast->second);
|
expression(ast->second);
|
||||||
@@ -132,33 +132,33 @@ bool Semantic::visit(TernaryExpression *ast)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(AssignmentExpression *ast)
|
bool Semantic::visit(AssignmentExpressionAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->variable);
|
expression(ast->variable);
|
||||||
expression(ast->value);
|
expression(ast->value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(MemberAccessExpression *ast)
|
bool Semantic::visit(MemberAccessExpressionAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
expression(ast->expr);
|
||||||
// ast->field
|
// ast->field
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(FunctionCallExpression *ast)
|
bool Semantic::visit(FunctionCallExpressionAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
expression(ast->expr);
|
||||||
functionIdentifier(ast->id);
|
functionIdentifier(ast->id);
|
||||||
for (List<Expression *> *it = ast->arguments; it; it = it->next) {
|
for (List<ExpressionAST *> *it = ast->arguments; it; it = it->next) {
|
||||||
Expression *arg = it->value;
|
ExpressionAST *arg = it->value;
|
||||||
expression(arg);
|
expression(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(DeclarationExpression *ast)
|
bool Semantic::visit(DeclarationExpressionAST *ast)
|
||||||
{
|
{
|
||||||
type(ast->type);
|
type(ast->type);
|
||||||
// ast->name
|
// ast->name
|
||||||
@@ -168,22 +168,22 @@ bool Semantic::visit(DeclarationExpression *ast)
|
|||||||
|
|
||||||
|
|
||||||
// statements
|
// statements
|
||||||
bool Semantic::visit(ExpressionStatement *ast)
|
bool Semantic::visit(ExpressionStatementAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
expression(ast->expr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(CompoundStatement *ast)
|
bool Semantic::visit(CompoundStatementAST *ast)
|
||||||
{
|
{
|
||||||
for (List<Statement *> *it = ast->statements; it; it = it->next) {
|
for (List<StatementAST *> *it = ast->statements; it; it = it->next) {
|
||||||
Statement *stmt = it->value;
|
StatementAST *stmt = it->value;
|
||||||
statement(stmt);
|
statement(stmt);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(IfStatement *ast)
|
bool Semantic::visit(IfStatementAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->condition);
|
expression(ast->condition);
|
||||||
statement(ast->thenClause);
|
statement(ast->thenClause);
|
||||||
@@ -191,21 +191,21 @@ bool Semantic::visit(IfStatement *ast)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(WhileStatement *ast)
|
bool Semantic::visit(WhileStatementAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->condition);
|
expression(ast->condition);
|
||||||
statement(ast->body);
|
statement(ast->body);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(DoStatement *ast)
|
bool Semantic::visit(DoStatementAST *ast)
|
||||||
{
|
{
|
||||||
statement(ast->body);
|
statement(ast->body);
|
||||||
expression(ast->condition);
|
expression(ast->condition);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(ForStatement *ast)
|
bool Semantic::visit(ForStatementAST *ast)
|
||||||
{
|
{
|
||||||
statement(ast->init);
|
statement(ast->init);
|
||||||
expression(ast->condition);
|
expression(ast->condition);
|
||||||
@@ -214,35 +214,35 @@ bool Semantic::visit(ForStatement *ast)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(JumpStatement *ast)
|
bool Semantic::visit(JumpStatementAST *ast)
|
||||||
{
|
{
|
||||||
Q_UNUSED(ast);
|
Q_UNUSED(ast);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(ReturnStatement *ast)
|
bool Semantic::visit(ReturnStatementAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
expression(ast->expr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(SwitchStatement *ast)
|
bool Semantic::visit(SwitchStatementAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
expression(ast->expr);
|
||||||
statement(ast->body);
|
statement(ast->body);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(CaseLabelStatement *ast)
|
bool Semantic::visit(CaseLabelStatementAST *ast)
|
||||||
{
|
{
|
||||||
expression(ast->expr);
|
expression(ast->expr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(DeclarationStatement *ast)
|
bool Semantic::visit(DeclarationStatementAST *ast)
|
||||||
{
|
{
|
||||||
for (List<Declaration *> *it = ast->decls; it; it = it->next) {
|
for (List<DeclarationAST *> *it = ast->decls; it; it = it->next) {
|
||||||
Declaration *decl = it->value;
|
DeclarationAST *decl = it->value;
|
||||||
declaration(decl);
|
declaration(decl);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -250,36 +250,36 @@ bool Semantic::visit(DeclarationStatement *ast)
|
|||||||
|
|
||||||
|
|
||||||
// types
|
// types
|
||||||
bool Semantic::visit(BasicType *ast)
|
bool Semantic::visit(BasicTypeAST *ast)
|
||||||
{
|
{
|
||||||
Q_UNUSED(ast);
|
Q_UNUSED(ast);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(NamedType *ast)
|
bool Semantic::visit(NamedTypeAST *ast)
|
||||||
{
|
{
|
||||||
Q_UNUSED(ast);
|
Q_UNUSED(ast);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(ArrayType *ast)
|
bool Semantic::visit(ArrayTypeAST *ast)
|
||||||
{
|
{
|
||||||
type(ast->elementType);
|
type(ast->elementType);
|
||||||
expression(ast->size);
|
expression(ast->size);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(StructType *ast)
|
bool Semantic::visit(StructTypeAST *ast)
|
||||||
{
|
{
|
||||||
// ast->name
|
// ast->name
|
||||||
for (List<StructType::Field *> *it = ast->fields; it; it = it->next) {
|
for (List<StructTypeAST::Field *> *it = ast->fields; it; it = it->next) {
|
||||||
StructType::Field *f = it->value;
|
StructTypeAST::Field *f = it->value;
|
||||||
field(f);
|
field(f);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(QualifiedType *ast)
|
bool Semantic::visit(QualifiedTypeAST *ast)
|
||||||
{
|
{
|
||||||
accept(ast->type);
|
accept(ast->type);
|
||||||
for (List<LayoutQualifier *> *it = ast->layout_list; it; it = it->next) {
|
for (List<LayoutQualifier *> *it = ast->layout_list; it; it = it->next) {
|
||||||
@@ -293,58 +293,58 @@ bool Semantic::visit(QualifiedType *ast)
|
|||||||
|
|
||||||
|
|
||||||
// declarations
|
// declarations
|
||||||
bool Semantic::visit(PrecisionDeclaration *ast)
|
bool Semantic::visit(PrecisionDeclarationAST *ast)
|
||||||
{
|
{
|
||||||
type(ast->type);
|
type(ast->type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(ParameterDeclaration *ast)
|
bool Semantic::visit(ParameterDeclarationAST *ast)
|
||||||
{
|
{
|
||||||
type(ast->type);
|
type(ast->type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(VariableDeclaration *ast)
|
bool Semantic::visit(VariableDeclarationAST *ast)
|
||||||
{
|
{
|
||||||
type(ast->type);
|
type(ast->type);
|
||||||
expression(ast->initializer);
|
expression(ast->initializer);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(TypeDeclaration *ast)
|
bool Semantic::visit(TypeDeclarationAST *ast)
|
||||||
{
|
{
|
||||||
type(ast->type);
|
type(ast->type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(TypeAndVariableDeclaration *ast)
|
bool Semantic::visit(TypeAndVariableDeclarationAST *ast)
|
||||||
{
|
{
|
||||||
declaration(ast->typeDecl);
|
declaration(ast->typeDecl);
|
||||||
declaration(ast->varDecl);
|
declaration(ast->varDecl);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(InvariantDeclaration *ast)
|
bool Semantic::visit(InvariantDeclarationAST *ast)
|
||||||
{
|
{
|
||||||
Q_UNUSED(ast);
|
Q_UNUSED(ast);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(InitDeclaration *ast)
|
bool Semantic::visit(InitDeclarationAST *ast)
|
||||||
{
|
{
|
||||||
for (List<Declaration *> *it = ast->decls; it; it = it->next) {
|
for (List<DeclarationAST *> *it = ast->decls; it; it = it->next) {
|
||||||
Declaration *decl = it->value;
|
DeclarationAST *decl = it->value;
|
||||||
declaration(decl);
|
declaration(decl);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Semantic::visit(FunctionDeclaration *ast)
|
bool Semantic::visit(FunctionDeclarationAST *ast)
|
||||||
{
|
{
|
||||||
type(ast->returnType);
|
type(ast->returnType);
|
||||||
for (List<ParameterDeclaration *> *it = ast->params; it; it = it->next) {
|
for (List<ParameterDeclarationAST *> *it = ast->params; it; it = it->next) {
|
||||||
ParameterDeclaration *decl = it->value;
|
ParameterDeclarationAST *decl = it->value;
|
||||||
declaration(decl);
|
declaration(decl);
|
||||||
}
|
}
|
||||||
statement(ast->body);
|
statement(ast->body);
|
||||||
|
|||||||
@@ -39,59 +39,59 @@ public:
|
|||||||
Semantic();
|
Semantic();
|
||||||
virtual ~Semantic();
|
virtual ~Semantic();
|
||||||
|
|
||||||
void expression(Expression *ast);
|
void expression(ExpressionAST *ast);
|
||||||
void statement(Statement *ast);
|
void statement(StatementAST *ast);
|
||||||
void type(Type *ast);
|
void type(TypeAST *ast);
|
||||||
void declaration(Declaration *ast);
|
void declaration(DeclarationAST *ast);
|
||||||
void translationUnit(TranslationUnit *ast);
|
void translationUnit(TranslationUnitAST *ast);
|
||||||
void functionIdentifier(FunctionIdentifier *ast);
|
void functionIdentifier(FunctionIdentifierAST *ast);
|
||||||
void field(StructType::Field *ast);
|
void field(StructTypeAST::Field *ast);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool visit(TranslationUnit *ast);
|
virtual bool visit(TranslationUnitAST *ast);
|
||||||
virtual bool visit(FunctionIdentifier *ast);
|
virtual bool visit(FunctionIdentifierAST *ast);
|
||||||
virtual bool visit(StructType::Field *ast);
|
virtual bool visit(StructTypeAST::Field *ast);
|
||||||
|
|
||||||
// expressions
|
// expressions
|
||||||
virtual bool visit(IdentifierExpression *ast);
|
virtual bool visit(IdentifierExpressionAST *ast);
|
||||||
virtual bool visit(LiteralExpression *ast);
|
virtual bool visit(LiteralExpressionAST *ast);
|
||||||
virtual bool visit(BinaryExpression *ast);
|
virtual bool visit(BinaryExpressionAST *ast);
|
||||||
virtual bool visit(UnaryExpression *ast);
|
virtual bool visit(UnaryExpressionAST *ast);
|
||||||
virtual bool visit(TernaryExpression *ast);
|
virtual bool visit(TernaryExpressionAST *ast);
|
||||||
virtual bool visit(AssignmentExpression *ast);
|
virtual bool visit(AssignmentExpressionAST *ast);
|
||||||
virtual bool visit(MemberAccessExpression *ast);
|
virtual bool visit(MemberAccessExpressionAST *ast);
|
||||||
virtual bool visit(FunctionCallExpression *ast);
|
virtual bool visit(FunctionCallExpressionAST *ast);
|
||||||
virtual bool visit(DeclarationExpression *ast);
|
virtual bool visit(DeclarationExpressionAST *ast);
|
||||||
|
|
||||||
// statements
|
// statements
|
||||||
virtual bool visit(ExpressionStatement *ast);
|
virtual bool visit(ExpressionStatementAST *ast);
|
||||||
virtual bool visit(CompoundStatement *ast);
|
virtual bool visit(CompoundStatementAST *ast);
|
||||||
virtual bool visit(IfStatement *ast);
|
virtual bool visit(IfStatementAST *ast);
|
||||||
virtual bool visit(WhileStatement *ast);
|
virtual bool visit(WhileStatementAST *ast);
|
||||||
virtual bool visit(DoStatement *ast);
|
virtual bool visit(DoStatementAST *ast);
|
||||||
virtual bool visit(ForStatement *ast);
|
virtual bool visit(ForStatementAST *ast);
|
||||||
virtual bool visit(JumpStatement *ast);
|
virtual bool visit(JumpStatementAST *ast);
|
||||||
virtual bool visit(ReturnStatement *ast);
|
virtual bool visit(ReturnStatementAST *ast);
|
||||||
virtual bool visit(SwitchStatement *ast);
|
virtual bool visit(SwitchStatementAST *ast);
|
||||||
virtual bool visit(CaseLabelStatement *ast);
|
virtual bool visit(CaseLabelStatementAST *ast);
|
||||||
virtual bool visit(DeclarationStatement *ast);
|
virtual bool visit(DeclarationStatementAST *ast);
|
||||||
|
|
||||||
// types
|
// types
|
||||||
virtual bool visit(BasicType *ast);
|
virtual bool visit(BasicTypeAST *ast);
|
||||||
virtual bool visit(NamedType *ast);
|
virtual bool visit(NamedTypeAST *ast);
|
||||||
virtual bool visit(ArrayType *ast);
|
virtual bool visit(ArrayTypeAST *ast);
|
||||||
virtual bool visit(StructType *ast);
|
virtual bool visit(StructTypeAST *ast);
|
||||||
virtual bool visit(QualifiedType *ast);
|
virtual bool visit(QualifiedTypeAST *ast);
|
||||||
|
|
||||||
// declarations
|
// declarations
|
||||||
virtual bool visit(PrecisionDeclaration *ast);
|
virtual bool visit(PrecisionDeclarationAST *ast);
|
||||||
virtual bool visit(ParameterDeclaration *ast);
|
virtual bool visit(ParameterDeclarationAST *ast);
|
||||||
virtual bool visit(VariableDeclaration *ast);
|
virtual bool visit(VariableDeclarationAST *ast);
|
||||||
virtual bool visit(TypeDeclaration *ast);
|
virtual bool visit(TypeDeclarationAST *ast);
|
||||||
virtual bool visit(TypeAndVariableDeclaration *ast);
|
virtual bool visit(TypeAndVariableDeclarationAST *ast);
|
||||||
virtual bool visit(InvariantDeclaration *ast);
|
virtual bool visit(InvariantDeclarationAST *ast);
|
||||||
virtual bool visit(InitDeclaration *ast);
|
virtual bool visit(InitDeclarationAST *ast);
|
||||||
virtual bool visit(FunctionDeclaration *ast);
|
virtual bool visit(FunctionDeclarationAST *ast);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace GLSL
|
} // namespace GLSL
|
||||||
|
|||||||
197
src/libs/glsl/glsltypes.cpp
Normal file
197
src/libs/glsl/glsltypes.cpp
Normal 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
158
src/libs/glsl/glsltypes.h
Normal 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
|
||||||
@@ -75,7 +75,7 @@ int main(int argc, char *argv[])
|
|||||||
variant |= Lexer::Variant_VertexShader | Lexer::Variant_FragmentShader;
|
variant |= Lexer::Variant_VertexShader | Lexer::Variant_FragmentShader;
|
||||||
Engine engine;
|
Engine engine;
|
||||||
Parser parser(&engine, source, size, variant);
|
Parser parser(&engine, source, size, variant);
|
||||||
TranslationUnit *ast = parser.parse();
|
TranslationUnitAST *ast = parser.parse();
|
||||||
std::cout << argv[1] << (ast ? " OK " : " KO ") << std::endl;
|
std::cout << argv[1] << (ast ? " OK " : " KO ") << std::endl;
|
||||||
|
|
||||||
ASTDump dump(qout);
|
ASTDump dump(qout);
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ void GLSLTextEditor::updateDocumentNow()
|
|||||||
|
|
||||||
Engine engine;
|
Engine engine;
|
||||||
Parser parser(&engine, preprocessedCode.constData(), preprocessedCode.size(), variant);
|
Parser parser(&engine, preprocessedCode.constData(), preprocessedCode.size(), variant);
|
||||||
TranslationUnit *ast = parser.parse();
|
TranslationUnitAST *ast = parser.parse();
|
||||||
|
|
||||||
QTextCharFormat errorFormat;
|
QTextCharFormat errorFormat;
|
||||||
errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
|
errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
|
||||||
|
|||||||
Reference in New Issue
Block a user