1 #ifndef MSP_GL_SL_RESOLVE_H_
2 #define MSP_GL_SL_RESOLVE_H_
14 /** Forms links between nested blocks in the syntax tree. */
15 class BlockHierarchyResolver: private TraversingVisitor
18 bool r_any_resolved = false;
21 bool apply(Stage &s) { r_any_resolved = false; s.content.visit(*this); return r_any_resolved; }
24 virtual void enter(Block &);
27 /** Resolves types of variables and base types of other types. */
28 class TypeResolver: private TraversingVisitor
32 std::map<TypeDeclaration *, TypeDeclaration *> alias_map;
33 std::map<std::pair<TypeDeclaration *, bool>, TypeDeclaration *> array_types;
34 NodeList<Statement>::iterator type_insert_point;
35 NodeList<Statement>::iterator block_member_type_ins_pt;
36 VariableDeclaration *iface_block = 0;
37 bool r_any_resolved = false;
43 TypeDeclaration *get_or_create_array_type(TypeDeclaration &);
44 void resolve_type(TypeDeclaration *&, const std::string &, bool);
45 virtual void visit(Block &);
46 virtual void visit(BasicTypeDeclaration &);
47 virtual void visit(ImageTypeDeclaration &);
48 virtual void visit(StructDeclaration &);
49 virtual void visit(VariableDeclaration &);
50 virtual void visit(FunctionDeclaration &);
53 /** Resolves variable references. */
54 class VariableResolver: private TraversingVisitor
58 RefPtr<Expression> r_replacement_expr;
59 bool r_any_resolved = false;
60 bool record_target = false;
61 bool r_self_referencing = false;
62 Assignment::Target r_assignment_target;
63 std::vector<Statement *> redeclared_builtins;
64 std::set<Node *> nodes_to_remove;
70 virtual void enter(Block &);
71 virtual void visit(RefPtr<Expression> &);
72 void check_assignment_target(Statement *);
73 virtual void visit(VariableReference &);
74 virtual void visit(MemberAccess &);
75 virtual void visit(Swizzle &);
76 virtual void visit(BinaryExpression &);
77 virtual void visit(Assignment &);
78 void merge_layouts(Layout &, const Layout &);
79 void redeclare_builtin(VariableDeclaration &, VariableDeclaration &);
80 virtual void visit(VariableDeclaration &);
83 /** Resolves types and lvalueness of expressions. */
84 class ExpressionResolver: private TraversingVisitor
97 BasicTypeDeclaration *type = 0;
98 unsigned component_count = 0;
102 const FunctionDeclaration *current_function = 0;
103 std::vector<BasicTypeDeclaration *> basic_types;
104 NodeList<Statement>::iterator insert_point;
105 bool r_any_resolved = false;
111 static Compatibility get_compatibility(BasicTypeDeclaration &, BasicTypeDeclaration &);
112 BasicTypeDeclaration *find_type(BasicTypeDeclaration::Kind, unsigned, bool = true);
113 BasicTypeDeclaration *find_type(BasicTypeDeclaration &, BasicTypeDeclaration::Kind, unsigned);
114 void convert_to(RefPtr<Expression> &, BasicTypeDeclaration &);
115 bool convert_to_element(RefPtr<Expression> &, BasicTypeDeclaration &);
116 bool truncate_vector(RefPtr<Expression> &, unsigned);
117 void resolve(Expression &, TypeDeclaration *, bool);
119 virtual void visit(Block &);
120 virtual void visit(Literal &);
121 virtual void visit(VariableReference &);
122 virtual void visit(MemberAccess &);
123 virtual void visit(Swizzle &);
124 virtual void visit(UnaryExpression &);
125 void visit(BinaryExpression &, bool);
126 virtual void visit(BinaryExpression &);
127 virtual void visit(Assignment &);
128 virtual void visit(TernaryExpression &);
129 void visit_constructor(FunctionCall &);
130 virtual void visit(FunctionCall &);
131 virtual void visit(BasicTypeDeclaration &);
132 virtual void visit(VariableDeclaration &);
133 virtual void visit(FunctionDeclaration &);
134 virtual void visit(Return &);
137 /** Resolves function declarations and calls. */
138 class FunctionResolver: private TraversingVisitor
142 std::map<std::string, std::vector<FunctionDeclaration *> > declarations;
143 bool r_any_resolved = false;
149 static bool can_convert_arguments(const FunctionCall &, const FunctionDeclaration &);
151 virtual void visit(FunctionCall &);
152 virtual void visit(FunctionDeclaration &);