X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fresolve.h;h=d592e4efd5a60ddaea72b0533db48474abfe8df8;hb=08d3b5a55fad7439b47fc93d8ba604cbeb7e19ca;hp=69c877fc6e542e24a5fd9edaf382662e2a83243d;hpb=001cdc10d0e0b7e006a4dce5363a5c593e35b7ae;p=libs%2Fgl.git diff --git a/source/glsl/resolve.h b/source/glsl/resolve.h index 69c877fc..d592e4ef 100644 --- a/source/glsl/resolve.h +++ b/source/glsl/resolve.h @@ -15,11 +15,9 @@ namespace SL { class BlockHierarchyResolver: private TraversingVisitor { private: - bool r_any_resolved; + bool r_any_resolved = false; public: - BlockHierarchyResolver(): r_any_resolved(false) { } - bool apply(Stage &s) { r_any_resolved = false; s.content.visit(*this); return r_any_resolved; } private: @@ -30,62 +28,58 @@ private: class TypeResolver: private TraversingVisitor { private: - Stage *stage; + Stage *stage = 0; std::map alias_map; - std::map array_types; + std::map, TypeDeclaration *> array_types; + std::map, ImageTypeDeclaration *> image_types; NodeList::iterator type_insert_point; - InterfaceBlock *iface_block; - bool r_any_resolved; + NodeList::iterator block_member_type_ins_pt; + VariableDeclaration *iface_block = 0; + bool r_any_resolved = false; public: - TypeResolver(); - bool apply(Stage &); private: TypeDeclaration *get_or_create_array_type(TypeDeclaration &); - void resolve_type(TypeDeclaration *&, const std::string &, bool); + TypeDeclaration *get_or_create_image_type(ImageTypeDeclaration &, const std::string &); + void resolve_type(TypeDeclaration *&, const std::string &, bool, const Layout * = 0); virtual void visit(Block &); virtual void visit(BasicTypeDeclaration &); virtual void visit(ImageTypeDeclaration &); virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); - virtual void visit(InterfaceBlock &); virtual void visit(FunctionDeclaration &); }; -/** Resolves variable references. Variable references which match the name -of an interface block are turned into interface block references. */ +/** Resolves variable references. */ class VariableResolver: private TraversingVisitor { private: - Stage *stage; + Stage *stage = 0; RefPtr r_replacement_expr; - bool r_any_resolved; - bool record_target; - bool r_self_referencing; + bool r_any_resolved = false; + bool record_target = false; + bool r_self_referencing = false; Assignment::Target r_assignment_target; - std::vector redeclared_builtins; + std::vector redeclared_builtins; std::set nodes_to_remove; public: - VariableResolver(); - bool apply(Stage &); private: virtual void enter(Block &); virtual void visit(RefPtr &); - void check_assignment_target(Statement *); + void check_assignment_target(VariableDeclaration *); virtual void visit(VariableReference &); - virtual void visit(InterfaceBlockReference &); virtual void visit(MemberAccess &); virtual void visit(Swizzle &); virtual void visit(BinaryExpression &); virtual void visit(Assignment &); void merge_layouts(Layout &, const Layout &); + void redeclare_builtin(VariableDeclaration &, VariableDeclaration &); virtual void visit(VariableDeclaration &); - virtual void visit(InterfaceBlock &); }; /** Resolves types and lvalueness of expressions. */ @@ -102,25 +96,22 @@ private: struct ArgumentInfo { - BasicTypeDeclaration *type; - unsigned component_count; - - ArgumentInfo(): type(0), component_count(0) { } + BasicTypeDeclaration *type = 0; + unsigned component_count = 0; }; - Stage *stage; + Stage *stage = 0; + const FunctionDeclaration *current_function = 0; std::vector basic_types; NodeList::iterator insert_point; - bool r_any_resolved; + bool r_any_resolved = false; public: - ExpressionResolver(); - bool apply(Stage &); private: static Compatibility get_compatibility(BasicTypeDeclaration &, BasicTypeDeclaration &); - BasicTypeDeclaration *find_type(BasicTypeDeclaration::Kind, unsigned); + BasicTypeDeclaration *find_type(BasicTypeDeclaration::Kind, unsigned, bool = true); BasicTypeDeclaration *find_type(BasicTypeDeclaration &, BasicTypeDeclaration::Kind, unsigned); void convert_to(RefPtr &, BasicTypeDeclaration &); bool convert_to_element(RefPtr &, BasicTypeDeclaration &); @@ -130,7 +121,6 @@ private: virtual void visit(Block &); virtual void visit(Literal &); virtual void visit(VariableReference &); - virtual void visit(InterfaceBlockReference &); virtual void visit(MemberAccess &); virtual void visit(Swizzle &); virtual void visit(UnaryExpression &); @@ -142,15 +132,17 @@ private: virtual void visit(FunctionCall &); virtual void visit(BasicTypeDeclaration &); virtual void visit(VariableDeclaration &); + virtual void visit(FunctionDeclaration &); + virtual void visit(Return &); }; /** Resolves function declarations and calls. */ class FunctionResolver: private TraversingVisitor { private: - Stage *stage; + Stage *stage = 0; std::map > declarations; - bool r_any_resolved; + bool r_any_resolved = false; public: bool apply(Stage &);