Files
qt-creator/src/libs/glsl/glslsemantic.cpp

354 lines
6.9 KiB
C++
Raw Normal View History

2010-11-25 10:29:57 +01:00
/**************************************************************************
**
** 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 "glslsemantic.h"
using namespace GLSL;
Semantic::Semantic()
{
}
Semantic::~Semantic()
{
}
void Semantic::expression(ExpressionAST *ast)
2010-11-25 10:29:57 +01:00
{
accept(ast);
}
void Semantic::statement(StatementAST *ast)
2010-11-25 10:29:57 +01:00
{
accept(ast);
}
void Semantic::type(TypeAST *ast)
2010-11-25 10:29:57 +01:00
{
accept(ast);
}
void Semantic::declaration(DeclarationAST *ast)
2010-11-25 10:29:57 +01:00
{
accept(ast);
}
void Semantic::translationUnit(TranslationUnitAST *ast)
2010-11-25 10:29:57 +01:00
{
accept(ast);
}
void Semantic::functionIdentifier(FunctionIdentifierAST *ast)
2010-11-25 10:29:57 +01:00
{
accept(ast);
}
void Semantic::field(StructTypeAST::Field *ast)
2010-11-25 10:29:57 +01:00
{
accept(ast);
}
bool Semantic::visit(TranslationUnitAST *ast)
2010-11-25 10:29:57 +01:00
{
for (List<DeclarationAST *> *it = ast->declarations; it; it = it->next) {
DeclarationAST *decl = it->value;
2010-11-25 10:29:57 +01:00
declaration(decl);
}
return false;
}
bool Semantic::visit(FunctionIdentifierAST *ast)
2010-11-25 10:29:57 +01:00
{
// ast->name
type(ast->type);
return false;
}
bool Semantic::visit(StructTypeAST::Field *ast)
2010-11-25 10:29:57 +01:00
{
// ast->name
type(ast->type);
return false;
}
// expressions
bool Semantic::visit(IdentifierExpressionAST *ast)
2010-11-25 10:29:57 +01:00
{
Q_UNUSED(ast);
return false;
}
bool Semantic::visit(LiteralExpressionAST *ast)
2010-11-25 10:29:57 +01:00
{
Q_UNUSED(ast);
return false;
}
bool Semantic::visit(BinaryExpressionAST *ast)
2010-11-25 10:29:57 +01:00
{
expression(ast->left);
expression(ast->right);
return false;
}
bool Semantic::visit(UnaryExpressionAST *ast)
2010-11-25 10:29:57 +01:00
{
expression(ast->expr);
return false;
}
bool Semantic::visit(TernaryExpressionAST *ast)
2010-11-25 10:29:57 +01:00
{
expression(ast->first);
expression(ast->second);
expression(ast->third);
return false;
}
bool Semantic::visit(AssignmentExpressionAST *ast)
2010-11-25 10:29:57 +01:00
{
expression(ast->variable);
expression(ast->value);
return false;
}
bool Semantic::visit(MemberAccessExpressionAST *ast)
2010-11-25 10:29:57 +01:00
{
expression(ast->expr);
// ast->field
return false;
}
bool Semantic::visit(FunctionCallExpressionAST *ast)
2010-11-25 10:29:57 +01:00
{
expression(ast->expr);
functionIdentifier(ast->id);
for (List<ExpressionAST *> *it = ast->arguments; it; it = it->next) {
ExpressionAST *arg = it->value;
2010-11-25 10:29:57 +01:00
expression(arg);
}
return false;
}
bool Semantic::visit(DeclarationExpressionAST *ast)
2010-11-25 10:29:57 +01:00
{
type(ast->type);
// ast->name
expression(ast->initializer);
return false;
}
// statements
bool Semantic::visit(ExpressionStatementAST *ast)
2010-11-25 10:29:57 +01:00
{
expression(ast->expr);
return false;
}
bool Semantic::visit(CompoundStatementAST *ast)
2010-11-25 10:29:57 +01:00
{
for (List<StatementAST *> *it = ast->statements; it; it = it->next) {
StatementAST *stmt = it->value;
2010-11-25 10:29:57 +01:00
statement(stmt);
}
return false;
}
bool Semantic::visit(IfStatementAST *ast)
2010-11-25 10:29:57 +01:00
{
expression(ast->condition);
statement(ast->thenClause);
statement(ast->elseClause);
return false;
}
bool Semantic::visit(WhileStatementAST *ast)
2010-11-25 10:29:57 +01:00
{
expression(ast->condition);
statement(ast->body);
return false;
}
bool Semantic::visit(DoStatementAST *ast)
2010-11-25 10:29:57 +01:00
{
statement(ast->body);
expression(ast->condition);
return false;
}
bool Semantic::visit(ForStatementAST *ast)
2010-11-25 10:29:57 +01:00
{
statement(ast->init);
expression(ast->condition);
expression(ast->increment);
statement(ast->body);
return false;
}
bool Semantic::visit(JumpStatementAST *ast)
2010-11-25 10:29:57 +01:00
{
Q_UNUSED(ast);
return false;
}
bool Semantic::visit(ReturnStatementAST *ast)
2010-11-25 10:29:57 +01:00
{
expression(ast->expr);
return false;
}
bool Semantic::visit(SwitchStatementAST *ast)
2010-11-25 10:29:57 +01:00
{
expression(ast->expr);
statement(ast->body);
return false;
}
bool Semantic::visit(CaseLabelStatementAST *ast)
2010-11-25 10:29:57 +01:00
{
expression(ast->expr);
return false;
}
bool Semantic::visit(DeclarationStatementAST *ast)
2010-11-25 10:29:57 +01:00
{
for (List<DeclarationAST *> *it = ast->decls; it; it = it->next) {
DeclarationAST *decl = it->value;
2010-11-25 10:29:57 +01:00
declaration(decl);
}
return false;
}
// types
bool Semantic::visit(BasicTypeAST *ast)
2010-11-25 10:29:57 +01:00
{
Q_UNUSED(ast);
return false;
}
bool Semantic::visit(NamedTypeAST *ast)
2010-11-25 10:29:57 +01:00
{
Q_UNUSED(ast);
return false;
}
bool Semantic::visit(ArrayTypeAST *ast)
2010-11-25 10:29:57 +01:00
{
type(ast->elementType);
expression(ast->size);
return false;
}
bool Semantic::visit(StructTypeAST *ast)
2010-11-25 10:29:57 +01:00
{
// ast->name
for (List<StructTypeAST::Field *> *it = ast->fields; it; it = it->next) {
StructTypeAST::Field *f = it->value;
2010-11-25 10:29:57 +01:00
field(f);
}
return false;
}
bool Semantic::visit(QualifiedTypeAST *ast)
2010-11-25 10:29:57 +01:00
{
accept(ast->type);
for (List<LayoutQualifier *> *it = ast->layout_list; it; it = it->next) {
LayoutQualifier *q = it->value;
// q->name;
// q->number;
Q_UNUSED(q);
}
return false;
}
// declarations
bool Semantic::visit(PrecisionDeclarationAST *ast)
2010-11-25 10:29:57 +01:00
{
type(ast->type);
return false;
}
bool Semantic::visit(ParameterDeclarationAST *ast)
2010-11-25 10:29:57 +01:00
{
type(ast->type);
return false;
}
bool Semantic::visit(VariableDeclarationAST *ast)
2010-11-25 10:29:57 +01:00
{
type(ast->type);
expression(ast->initializer);
return false;
}
bool Semantic::visit(TypeDeclarationAST *ast)
2010-11-25 10:29:57 +01:00
{
type(ast->type);
return false;
}
bool Semantic::visit(TypeAndVariableDeclarationAST *ast)
2010-11-25 10:29:57 +01:00
{
declaration(ast->typeDecl);
declaration(ast->varDecl);
return false;
}
bool Semantic::visit(InvariantDeclarationAST *ast)
2010-11-25 10:29:57 +01:00
{
Q_UNUSED(ast);
return false;
}
bool Semantic::visit(InitDeclarationAST *ast)
2010-11-25 10:29:57 +01:00
{
for (List<DeclarationAST *> *it = ast->decls; it; it = it->next) {
DeclarationAST *decl = it->value;
2010-11-25 10:29:57 +01:00
declaration(decl);
}
return false;
}
bool Semantic::visit(FunctionDeclarationAST *ast)
2010-11-25 10:29:57 +01:00
{
type(ast->returnType);
for (List<ParameterDeclarationAST *> *it = ast->params; it; it = it->next) {
ParameterDeclarationAST *decl = it->value;
2010-11-25 10:29:57 +01:00
declaration(decl);
}
statement(ast->body);
return false;
}