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
21 BlockHierarchyResolver(): r_any_resolved(false) { }
23 bool apply(Stage &s) { r_any_resolved = false; s.content.visit(*this); return r_any_resolved; }
26 virtual void enter(Block &);
29 /** Resolves types of variables and base types of other types. */
30 class TypeResolver: private TraversingVisitor
34 std::map<TypeDeclaration *, TypeDeclaration *> alias_map;
35 std::map<TypeDeclaration *, TypeDeclaration *> array_types;
36 NodeList<Statement>::iterator type_insert_point;
37 InterfaceBlock *iface_block;
46 TypeDeclaration *get_or_create_array_type(TypeDeclaration &);
47 void resolve_type(TypeDeclaration *&, const std::string &, bool);
48 virtual void visit(Block &);
49 virtual void visit(BasicTypeDeclaration &);
50 virtual void visit(ImageTypeDeclaration &);
51 virtual void visit(StructDeclaration &);
52 virtual void visit(VariableDeclaration &);
53 virtual void visit(InterfaceBlock &);
54 virtual void visit(FunctionDeclaration &);
57 /** Resolves variable references. Variable references which match the name
58 of an interface block are turned into interface block references. */
59 class VariableResolver: private TraversingVisitor
63 RefPtr<Expression> r_replacement_expr;
66 bool r_self_referencing;
67 Assignment::Target r_assignment_target;
68 std::vector<VariableDeclaration *> redeclared_builtins;
69 std::set<Node *> nodes_to_remove;
77 virtual void enter(Block &);
78 virtual void visit(RefPtr<Expression> &);
79 void check_assignment_target(Statement *);
80 virtual void visit(VariableReference &);
81 virtual void visit(InterfaceBlockReference &);
82 void add_to_chain(Assignment::Target::ChainType, unsigned);
83 virtual void visit(MemberAccess &);
84 virtual void visit(Swizzle &);
85 virtual void visit(BinaryExpression &);
86 virtual void visit(Assignment &);
87 void merge_layouts(Layout &, const Layout &);
88 virtual void visit(VariableDeclaration &);
89 virtual void visit(InterfaceBlock &);
92 /** Resolves types and lvalueness of expressions. */
93 class ExpressionResolver: private TraversingVisitor
106 BasicTypeDeclaration *type;
107 unsigned component_count;
109 ArgumentInfo(): type(0), component_count(0) { }
113 std::vector<BasicTypeDeclaration *> basic_types;
114 NodeList<Statement>::iterator insert_point;
118 ExpressionResolver();
123 static bool is_scalar(BasicTypeDeclaration &);
124 static bool is_vector_or_matrix(BasicTypeDeclaration &);
125 static BasicTypeDeclaration *get_element_type(BasicTypeDeclaration &);
126 static bool can_convert(BasicTypeDeclaration &, BasicTypeDeclaration &);
127 static Compatibility get_compatibility(BasicTypeDeclaration &, BasicTypeDeclaration &);
128 BasicTypeDeclaration *find_type(BasicTypeDeclaration::Kind, unsigned);
129 BasicTypeDeclaration *find_type(BasicTypeDeclaration &, BasicTypeDeclaration::Kind, unsigned);
130 void convert_to(RefPtr<Expression> &, BasicTypeDeclaration &);
131 bool convert_to_element(RefPtr<Expression> &, BasicTypeDeclaration &);
132 bool truncate_vector(RefPtr<Expression> &, unsigned);
133 void resolve(Expression &, TypeDeclaration *, bool);
135 virtual void visit(Block &);
136 virtual void visit(Literal &);
137 virtual void visit(VariableReference &);
138 virtual void visit(InterfaceBlockReference &);
139 virtual void visit(MemberAccess &);
140 virtual void visit(Swizzle &);
141 virtual void visit(UnaryExpression &);
142 void visit(BinaryExpression &, bool);
143 virtual void visit(BinaryExpression &);
144 virtual void visit(Assignment &);
145 virtual void visit(TernaryExpression &);
146 void visit_constructor(FunctionCall &);
147 virtual void visit(FunctionCall &);
148 virtual void visit(BasicTypeDeclaration &);
149 virtual void visit(VariableDeclaration &);
152 /** Resolves function declarations and calls. */
153 class FunctionResolver: private TraversingVisitor
157 std::map<std::string, std::vector<FunctionDeclaration *> > declarations;
164 virtual void visit(FunctionCall &);
165 virtual void visit(FunctionDeclaration &);