2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-11-25 10:29:57 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-11-25 10:29:57 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-11-25 10:29:57 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-11-25 10:29:57 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 17:14:20 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-04-13 08:42:33 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2010-11-25 10:29:57 +01:00
|
|
|
|
|
|
|
|
#include "glslastvisitor.h"
|
2010-12-02 16:30:19 +01:00
|
|
|
#include "glsltype.h"
|
2010-11-25 10:29:57 +01:00
|
|
|
|
|
|
|
|
namespace GLSL {
|
|
|
|
|
|
|
|
|
|
class GLSL_EXPORT Semantic: protected Visitor
|
|
|
|
|
{
|
|
|
|
|
public:
|
2010-11-26 15:00:46 +01:00
|
|
|
Semantic();
|
2018-05-07 15:10:01 +02:00
|
|
|
~Semantic() override;
|
2010-11-25 10:29:57 +01:00
|
|
|
|
2010-11-26 12:08:43 +01:00
|
|
|
struct ExprResult {
|
2019-07-31 17:21:41 +02:00
|
|
|
ExprResult(const Type *type = nullptr, bool isConstant = false)
|
2010-11-26 12:08:43 +01:00
|
|
|
: type(type), isConstant(isConstant) {}
|
|
|
|
|
|
2011-06-24 13:42:19 +02:00
|
|
|
~ExprResult() { }
|
|
|
|
|
|
2010-12-02 16:30:19 +01:00
|
|
|
bool isValid() const {
|
|
|
|
|
if (! type)
|
|
|
|
|
return false;
|
2019-07-31 17:21:41 +02:00
|
|
|
else if (type->asUndefinedType() != nullptr)
|
2010-12-02 16:30:19 +01:00
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 13:23:04 +02:00
|
|
|
explicit operator bool() const { return isValid(); }
|
2010-11-26 12:08:43 +01:00
|
|
|
|
|
|
|
|
const Type *type;
|
|
|
|
|
bool isConstant;
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-26 15:00:46 +01:00
|
|
|
void translationUnit(TranslationUnitAST *ast, Scope *globalScope, Engine *engine);
|
2010-11-29 17:21:47 +01:00
|
|
|
ExprResult expression(ExpressionAST *ast, Scope *scope, Engine *engine);
|
2010-11-26 15:00:46 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
Engine *switchEngine(Engine *engine);
|
|
|
|
|
Scope *switchScope(Scope *scope);
|
|
|
|
|
|
2010-11-30 16:10:07 +01:00
|
|
|
bool implicitCast(const Type *type, const Type *target) const;
|
|
|
|
|
|
2010-11-26 12:08:43 +01:00
|
|
|
ExprResult expression(ExpressionAST *ast);
|
2010-11-25 12:19:57 +01:00
|
|
|
void statement(StatementAST *ast);
|
2010-11-25 13:06:41 +01:00
|
|
|
const Type *type(TypeAST *ast);
|
2010-11-25 12:19:57 +01:00
|
|
|
void declaration(DeclarationAST *ast);
|
2010-11-26 12:55:24 +01:00
|
|
|
ExprResult functionIdentifier(FunctionIdentifierAST *ast);
|
2010-11-25 14:55:43 +01:00
|
|
|
Symbol *field(StructTypeAST::Field *ast);
|
|
|
|
|
void parameterDeclaration(ParameterDeclarationAST *ast, Function *fun);
|
2010-11-25 10:29:57 +01:00
|
|
|
|
2018-05-07 15:10:01 +02:00
|
|
|
bool visit(TranslationUnitAST *ast) override;
|
|
|
|
|
bool visit(FunctionIdentifierAST *ast) override;
|
|
|
|
|
bool visit(StructTypeAST::Field *ast) override;
|
2010-11-25 10:29:57 +01:00
|
|
|
|
|
|
|
|
// expressions
|
2018-05-07 15:10:01 +02:00
|
|
|
bool visit(IdentifierExpressionAST *ast) override;
|
|
|
|
|
bool visit(LiteralExpressionAST *ast) override;
|
|
|
|
|
bool visit(BinaryExpressionAST *ast) override;
|
|
|
|
|
bool visit(UnaryExpressionAST *ast) override;
|
|
|
|
|
bool visit(TernaryExpressionAST *ast) override;
|
|
|
|
|
bool visit(AssignmentExpressionAST *ast) override;
|
|
|
|
|
bool visit(MemberAccessExpressionAST *ast) override;
|
|
|
|
|
bool visit(FunctionCallExpressionAST *ast) override;
|
|
|
|
|
bool visit(DeclarationExpressionAST *ast) override;
|
2010-11-25 10:29:57 +01:00
|
|
|
|
|
|
|
|
// statements
|
2018-05-07 15:10:01 +02:00
|
|
|
bool visit(ExpressionStatementAST *ast) override;
|
|
|
|
|
bool visit(CompoundStatementAST *ast) override;
|
|
|
|
|
bool visit(IfStatementAST *ast) override;
|
|
|
|
|
bool visit(WhileStatementAST *ast) override;
|
|
|
|
|
bool visit(DoStatementAST *ast) override;
|
|
|
|
|
bool visit(ForStatementAST *ast) override;
|
|
|
|
|
bool visit(JumpStatementAST *ast) override;
|
|
|
|
|
bool visit(ReturnStatementAST *ast) override;
|
|
|
|
|
bool visit(SwitchStatementAST *ast) override;
|
|
|
|
|
bool visit(CaseLabelStatementAST *ast) override;
|
|
|
|
|
bool visit(DeclarationStatementAST *ast) override;
|
2010-11-25 10:29:57 +01:00
|
|
|
|
|
|
|
|
// types
|
2018-05-07 15:10:01 +02:00
|
|
|
bool visit(BasicTypeAST *ast) override;
|
|
|
|
|
bool visit(NamedTypeAST *ast) override;
|
|
|
|
|
bool visit(ArrayTypeAST *ast) override;
|
|
|
|
|
bool visit(StructTypeAST *ast) override;
|
|
|
|
|
bool visit(QualifiedTypeAST *ast) override;
|
2010-11-25 10:29:57 +01:00
|
|
|
|
|
|
|
|
// declarations
|
2018-05-07 15:10:01 +02:00
|
|
|
bool visit(PrecisionDeclarationAST *ast) override;
|
|
|
|
|
bool visit(ParameterDeclarationAST *ast) override;
|
|
|
|
|
bool visit(VariableDeclarationAST *ast) override;
|
|
|
|
|
bool visit(TypeDeclarationAST *ast) override;
|
|
|
|
|
bool visit(TypeAndVariableDeclarationAST *ast) override;
|
|
|
|
|
bool visit(InvariantDeclarationAST *ast) override;
|
|
|
|
|
bool visit(InitDeclarationAST *ast) override;
|
|
|
|
|
bool visit(FunctionDeclarationAST *ast) override;
|
2010-11-25 13:06:41 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Engine *_engine;
|
2010-11-25 14:55:43 +01:00
|
|
|
Scope *_scope;
|
2010-11-26 12:08:43 +01:00
|
|
|
const Type *_type;
|
|
|
|
|
ExprResult _expr;
|
2010-11-25 10:29:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace GLSL
|