// Copyright (C) 2020 Jérôme Leclercq // This file is part of the "Nazara Engine - Shader generator" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include namespace Nz::ShaderBuilder { inline std::unique_ptr Impl::AccessMember::operator()(ShaderAst::ExpressionPtr structExpr, std::vector memberIdentifiers) const { auto accessMemberNode = std::make_unique(); accessMemberNode->structExpr = std::move(structExpr); accessMemberNode->memberIdentifiers = std::move(memberIdentifiers); return accessMemberNode; } inline std::unique_ptr Impl::Assign::operator()(ShaderAst::AssignType op, ShaderAst::ExpressionPtr left, ShaderAst::ExpressionPtr right) const { auto assignNode = std::make_unique(); assignNode->op = op; assignNode->left = std::move(left); assignNode->right = std::move(right); return assignNode; } inline std::unique_ptr Impl::Binary::operator()(ShaderAst::BinaryType op, ShaderAst::ExpressionPtr left, ShaderAst::ExpressionPtr right) const { auto binaryNode = std::make_unique(); binaryNode->op = op; binaryNode->left = std::move(left); binaryNode->right = std::move(right); return binaryNode; } inline std::unique_ptr Impl::Branch::operator()(ShaderAst::ExpressionPtr condition, ShaderAst::StatementPtr truePath, ShaderAst::StatementPtr falsePath) const { auto branchNode = std::make_unique(); auto& condStatement = branchNode->condStatements.emplace_back(); condStatement.condition = std::move(condition); condStatement.statement = std::move(truePath); branchNode->elseStatement = std::move(falsePath); return branchNode; } inline std::unique_ptr Impl::Branch::operator()(std::vector condStatements, ShaderAst::StatementPtr elseStatement) const { auto branchNode = std::make_unique(); branchNode->condStatements = std::move(condStatements); branchNode->elseStatement = std::move(elseStatement); return branchNode; } inline std::unique_ptr Impl::Cast::operator()(ShaderAst::ExpressionType targetType, std::vector expressions) const { auto castNode = std::make_unique(); castNode->targetType = std::move(targetType); assert(expressions.size() <= castNode->expressions.size()); for (std::size_t i = 0; i < expressions.size(); ++i) castNode->expressions[i] = std::move(expressions[i]); return castNode; } inline std::unique_ptr Impl::ConditionalExpression::operator()(std::string conditionName, ShaderAst::ExpressionPtr truePath, ShaderAst::ExpressionPtr falsePath) const { auto condExprNode = std::make_unique(); condExprNode->conditionName = std::move(conditionName); condExprNode->falsePath = std::move(falsePath); condExprNode->truePath = std::move(truePath); return condExprNode; } inline std::unique_ptr Impl::ConditionalStatement::operator()(std::string conditionName, ShaderAst::StatementPtr statement) const { auto condStatementNode = std::make_unique(); condStatementNode->conditionName = std::move(conditionName); condStatementNode->statement = std::move(statement); return condStatementNode; } inline std::unique_ptr Impl::Constant::operator()(ShaderAst::ConstantValue value) const { auto constantNode = std::make_unique(); constantNode->value = std::move(value); return constantNode; } inline std::unique_ptr Impl::DeclareFunction::operator()(std::string name, std::vector parameters, std::vector statements, ShaderAst::ExpressionType returnType) const { auto declareFunctionNode = std::make_unique(); declareFunctionNode->name = std::move(name); declareFunctionNode->parameters = std::move(parameters); declareFunctionNode->returnType = std::move(returnType); declareFunctionNode->statements = std::move(statements); return declareFunctionNode; } inline std::unique_ptr Impl::DeclareFunction::operator()(std::vector attributes, std::string name, std::vector parameters, std::vector statements, ShaderAst::ExpressionType returnType) const { auto declareFunctionNode = std::make_unique(); declareFunctionNode->attributes = std::move(attributes); declareFunctionNode->name = std::move(name); declareFunctionNode->parameters = std::move(parameters); declareFunctionNode->returnType = std::move(returnType); declareFunctionNode->statements = std::move(statements); return declareFunctionNode; } inline std::unique_ptr Impl::DeclareStruct::operator()(ShaderAst::StructDescription description) const { auto declareStructNode = std::make_unique(); declareStructNode->description = std::move(description); return declareStructNode; } inline std::unique_ptr Impl::DeclareStruct::operator()(std::vector attributes, ShaderAst::StructDescription description) const { auto declareStructNode = std::make_unique(); declareStructNode->attributes = std::move(attributes); declareStructNode->description = std::move(description); return declareStructNode; } inline std::unique_ptr Nz::ShaderBuilder::Impl::DeclareVariable::operator()(std::string name, ShaderAst::ExpressionType type, ShaderAst::ExpressionPtr initialValue) const { auto declareVariableNode = std::make_unique(); declareVariableNode->varName = std::move(name); declareVariableNode->varType = std::move(type); declareVariableNode->initialExpression = std::move(initialValue); return declareVariableNode; } inline std::unique_ptr Impl::ExpressionStatement::operator()(ShaderAst::ExpressionPtr expression) const { auto expressionStatementNode = std::make_unique(); expressionStatementNode->expression = std::move(expression); return expressionStatementNode; } inline std::unique_ptr Impl::Identifier::operator()(std::string name) const { auto identifierNode = std::make_unique(); identifierNode->identifier = std::move(name); return identifierNode; } inline std::unique_ptr Impl::Intrinsic::operator()(ShaderAst::IntrinsicType intrinsicType, std::vector parameters) const { auto intrinsicExpression = std::make_unique(); intrinsicExpression->intrinsic = intrinsicType; intrinsicExpression->parameters = std::move(parameters); return intrinsicExpression; } inline std::unique_ptr Impl::Return::operator()(ShaderAst::ExpressionPtr expr) const { auto returnNode = std::make_unique(); returnNode->returnExpr = std::move(expr); return returnNode; } template std::unique_ptr Impl::NoParam::operator()() const { return std::make_unique(); } inline std::unique_ptr Impl::Swizzle::operator()(ShaderAst::ExpressionPtr expression, std::vector swizzleComponents) const { auto swizzleNode = std::make_unique(); swizzleNode->expression = std::move(expression); assert(swizzleComponents.size() <= swizzleNode->components.size()); for (std::size_t i = 0; i < swizzleComponents.size(); ++i) swizzleNode->components[i] = swizzleComponents[i]; return swizzleNode; } } #include