+ resolve(stage, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS);
+ }
+}
+
+template<typename T>
+bool Compiler::resolve(Stage &stage, unsigned &flags, unsigned bit)
+{
+ if(!(flags&bit))
+ return false;
+
+ flags &= ~bit;
+ return T().apply(stage);
+}
+
+void Compiler::resolve(Stage &stage, unsigned flags)
+{
+ while(flags)
+ {
+ if(resolve<BlockHierarchyResolver>(stage, flags, RESOLVE_BLOCKS))
+ ;
+ else if(resolve<TypeResolver>(stage, flags, RESOLVE_TYPES))
+ flags |= RESOLVE_BLOCKS|RESOLVE_VARIABLES|RESOLVE_EXPRESSIONS;
+ else if(resolve<VariableResolver>(stage, flags, RESOLVE_VARIABLES))
+ flags |= RESOLVE_EXPRESSIONS;
+ else if(resolve<FunctionResolver>(stage, flags, RESOLVE_FUNCTIONS))
+ flags |= RESOLVE_EXPRESSIONS;
+ else if(resolve<ExpressionResolver>(stage, flags, RESOLVE_EXPRESSIONS))
+ flags |= RESOLVE_VARIABLES;
+ }
+}
+
+bool Compiler::validate(Stage &stage)
+{
+ TypeValidator().apply(stage);
+ DeclarationValidator().apply(stage);
+ ReferenceValidator().apply(stage);
+ ExpressionValidator().apply(stage);
+
+ for(vector<Diagnostic>::const_iterator i=stage.diagnostics.begin(); i!=stage.diagnostics.end(); ++i)
+ if(i->severity==Diagnostic::ERR)
+ return false;
+
+ return true;