Shader: Add support for function attributes (entry)
This commit is contained in:
@@ -37,6 +37,7 @@ namespace Nz::ShaderAst
|
||||
inline std::size_t GetScopeId(const Node* node) const;
|
||||
|
||||
ShaderStageType stageType = ShaderStageType::Undefined;
|
||||
std::array<DeclareFunctionStatement*, ShaderStageTypeCount> entryFunctions = {};
|
||||
std::unordered_map<const Expression*, ShaderExpressionType> nodeExpressionType;
|
||||
std::unordered_map<const Node*, std::size_t> scopeIdByNode;
|
||||
std::vector<Scope> scopes;
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace Nz::ShaderBuilder
|
||||
struct DeclareFunction
|
||||
{
|
||||
inline std::unique_ptr<ShaderAst::DeclareFunctionStatement> operator()(std::string name, std::vector<ShaderAst::DeclareFunctionStatement::Parameter> parameters, std::vector<ShaderAst::StatementPtr> statements, ShaderAst::ShaderExpressionType returnType = ShaderAst::BasicType::Void) const;
|
||||
inline std::unique_ptr<ShaderAst::DeclareFunctionStatement> operator()(std::vector<ShaderAst::Attribute> attributes, std::string name, std::vector<ShaderAst::DeclareFunctionStatement::Parameter> parameters, std::vector<ShaderAst::StatementPtr> statements, ShaderAst::ShaderExpressionType returnType = ShaderAst::BasicType::Void) const;
|
||||
};
|
||||
|
||||
struct DeclareVariable
|
||||
|
||||
@@ -58,6 +58,18 @@ namespace Nz::ShaderBuilder
|
||||
return declareFunctionNode;
|
||||
}
|
||||
|
||||
inline std::unique_ptr<ShaderAst::DeclareFunctionStatement> Impl::DeclareFunction::operator()(std::vector<ShaderAst::Attribute> attributes, std::string name, std::vector<ShaderAst::DeclareFunctionStatement::Parameter> parameters, std::vector<ShaderAst::StatementPtr> statements, ShaderAst::ShaderExpressionType returnType) const
|
||||
{
|
||||
auto declareFunctionNode = std::make_unique<ShaderAst::DeclareFunctionStatement>();
|
||||
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<ShaderAst::DeclareVariableStatement> Nz::ShaderBuilder::Impl::DeclareVariable::operator()(std::string name, ShaderAst::ShaderExpressionType type, ShaderAst::ExpressionPtr initialValue) const
|
||||
{
|
||||
auto declareVariableNode = std::make_unique<ShaderAst::DeclareVariableStatement>();
|
||||
|
||||
@@ -57,14 +57,15 @@ namespace Nz::ShaderLang
|
||||
const Token& Advance();
|
||||
void Consume(std::size_t count = 1);
|
||||
const Token& Expect(const Token& token, TokenType type);
|
||||
const Token& ExpectNot(const Token& token, TokenType type);
|
||||
const Token& Expect(TokenType type);
|
||||
const Token& Peek(std::size_t advance = 0);
|
||||
|
||||
std::vector<ShaderAst::Attribute> ParseAttributes();
|
||||
void HandleAttributes();
|
||||
|
||||
// Statements
|
||||
std::vector<ShaderAst::StatementPtr> ParseFunctionBody();
|
||||
ShaderAst::StatementPtr ParseFunctionDeclaration();
|
||||
ShaderAst::StatementPtr ParseFunctionDeclaration(std::vector<ShaderAst::Attribute> attributes = {});
|
||||
ShaderAst::DeclareFunctionStatement::Parameter ParseFunctionParameter();
|
||||
ShaderAst::StatementPtr ParseReturnStatement();
|
||||
ShaderAst::StatementPtr ParseStatement();
|
||||
@@ -87,7 +88,6 @@ namespace Nz::ShaderLang
|
||||
|
||||
struct Context
|
||||
{
|
||||
std::vector<ShaderAst::Attribute> pendingAttributes;
|
||||
std::unique_ptr<ShaderAst::MultiStatement> root;
|
||||
std::size_t tokenCount;
|
||||
std::size_t tokenIndex = 0;
|
||||
|
||||
@@ -201,6 +201,7 @@ namespace Nz::ShaderAst
|
||||
};
|
||||
|
||||
std::string name;
|
||||
std::vector<Attribute> attributes;
|
||||
std::vector<Parameter> parameters;
|
||||
std::vector<StatementPtr> statements;
|
||||
ShaderExpressionType returnType = BasicType::Void;
|
||||
|
||||
Reference in New Issue
Block a user