X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvalidate.cpp;h=4b38c5b755e935f0e3f477c0ecd092202e411c7f;hb=bde40be11da83206f3d33a8225963d47a413662e;hp=8805d41fadf01655f7328b60e501ce8c3a8b73d4;hpb=73d52ab92ce8da522cd2eeb0d7f13c6af3f46e02;p=libs%2Fgl.git diff --git a/source/glsl/validate.cpp b/source/glsl/validate.cpp index 8805d41f..4b38c5b7 100644 --- a/source/glsl/validate.cpp +++ b/source/glsl/validate.cpp @@ -216,7 +216,7 @@ void ReferenceValidator::visit(VariableReference &var) { if(!var.declaration) error(var, format("Use of undeclared variable '%s'", var.name)); - else if(stage->type!=Stage::VERTEX && var.declaration->interface=="in" && !var.declaration->linked_declaration) + else if(stage->type!=Stage::VERTEX && var.declaration->interface=="in" && var.name.compare(0, 3, "gl_") && !var.declaration->linked_declaration) error(var, format("Use of unlinked input variable '%s'", var.name)); } @@ -338,8 +338,14 @@ void ExpressionValidator::visit(UnaryExpression &unary) void ExpressionValidator::visit(BinaryExpression &binary) { if(!binary.type && binary.left->type && binary.right->type) - error(binary, format("No matching operator '%s' found for '%s' and '%s'", - binary.oper->token, binary.left->type->name, binary.right->type->name)); + { + if(binary.oper->token[0]=='[') + error(binary, format("Can't index element of '%s' with '%s'", + binary.left->type->name, binary.right->type->name)); + else + error(binary, format("No matching operator '%s' found for '%s' and '%s'", + binary.oper->token, binary.left->type->name, binary.right->type->name)); + } TraversingVisitor::visit(binary); } @@ -365,6 +371,20 @@ void ExpressionValidator::visit(Assignment &assign) TraversingVisitor::visit(assign); } +void ExpressionValidator::visit(TernaryExpression &ternary) +{ + if(ternary.condition->type) + { + BasicTypeDeclaration *basic_cond = dynamic_cast(ternary.condition->type); + if(!basic_cond || basic_cond->kind!=BasicTypeDeclaration::BOOL) + error(ternary, "Ternary operator condition is not a boolean"); + else if(!ternary.type && ternary.true_expr->type && ternary.false_expr->type) + error(ternary, format("Ternary operator has incompatible types '%s' and '%s'", + ternary.true_expr->type->name, ternary.false_expr->type->name)); + } + TraversingVisitor::visit(ternary); +} + void ExpressionValidator::visit(VariableDeclaration &var) { if(var.init_expression && var.init_expression->type && var.type_declaration && var.init_expression->type!=var.type_declaration)