From d80750e7c20ea061f210b756196cc844b762b852 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 5 Mar 2021 13:22:47 +0200 Subject: [PATCH] Resolve the return types of functions --- source/glsl/generate.cpp | 7 +++++++ source/glsl/generate.h | 1 + source/glsl/syntax.cpp | 6 ++++-- source/glsl/syntax.h | 1 + source/glsl/validate.cpp | 7 +++++++ source/glsl/validate.h | 1 + 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index 8626cac6..433d506e 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -162,6 +162,13 @@ void TypeResolver::visit(VariableDeclaration &var) var.type_declaration = i->second; } +void TypeResolver::visit(FunctionDeclaration &func) +{ + map::iterator i = stage->types.find(func.return_type); + func.return_type_declaration = (i!=stage->types.end() ? i->second : 0); + TraversingVisitor::visit(func); +} + VariableResolver::VariableResolver(): stage(0), diff --git a/source/glsl/generate.h b/source/glsl/generate.h index d303af36..d4e570ab 100644 --- a/source/glsl/generate.h +++ b/source/glsl/generate.h @@ -71,6 +71,7 @@ private: virtual void visit(ImageTypeDeclaration &); virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); + virtual void visit(FunctionDeclaration &); }; /** Resolves variable references. Variable references which match the name diff --git a/source/glsl/syntax.cpp b/source/glsl/syntax.cpp index e20d6c26..c8058c4f 100644 --- a/source/glsl/syntax.cpp +++ b/source/glsl/syntax.cpp @@ -347,7 +347,8 @@ void InterfaceBlock::visit(NodeVisitor &visitor) FunctionDeclaration::FunctionDeclaration(): - definition(0) + definition(0), + return_type_declaration(0) { } FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other): @@ -356,7 +357,8 @@ FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other): name(other.name), parameters(other.parameters), body(other.body), - definition(other.definition==&other ? this : 0) + definition(other.definition==&other ? this : 0), + return_type_declaration(0) { } void FunctionDeclaration::visit(NodeVisitor &visitor) diff --git a/source/glsl/syntax.h b/source/glsl/syntax.h index 62c289d9..0379a911 100644 --- a/source/glsl/syntax.h +++ b/source/glsl/syntax.h @@ -404,6 +404,7 @@ struct FunctionDeclaration: Statement Block body; FunctionDeclaration *definition; + TypeDeclaration *return_type_declaration; FunctionDeclaration(); FunctionDeclaration(const FunctionDeclaration &); diff --git a/source/glsl/validate.cpp b/source/glsl/validate.cpp index 8e5e996c..e6f0c653 100644 --- a/source/glsl/validate.cpp +++ b/source/glsl/validate.cpp @@ -201,6 +201,13 @@ void ReferenceValidator::visit(VariableDeclaration &var) TraversingVisitor::visit(var); } +void ReferenceValidator::visit(FunctionDeclaration &func) +{ + if(!func.return_type_declaration) + error(func, format("Use of undeclared type '%s'", func.return_type)); + TraversingVisitor::visit(func); +} + } // namespace SL } // namespace GL } // namespace Msp diff --git a/source/glsl/validate.h b/source/glsl/validate.h index e4b9edae..3efa5141 100644 --- a/source/glsl/validate.h +++ b/source/glsl/validate.h @@ -78,6 +78,7 @@ private: virtual void visit(VariableReference &); virtual void visit(InterfaceBlockReference &); virtual void visit(VariableDeclaration &); + virtual void visit(FunctionDeclaration &); }; } // namespace SL -- 2.43.0