Add support for alternative forms to precision tests
authorPyry Haulos <phaulos@google.com>
Fri, 29 May 2015 21:04:15 +0000 (14:04 -0700)
committerPyry Haulos <phaulos@google.com>
Fri, 29 May 2015 21:04:15 +0000 (14:04 -0700)
This adds alternative(a, b) that can be used to allow two alternative
forms of sub-expression. Alternative forms will be printed to the test
log output as "{a | b}".

Bug: 19408572
Bug: 21110253
Change-Id: Id6a7508e041be2bc3a42ec44dd318b49ad7fb841

modules/glshared/glsBuiltinPrecisionTests.cpp

index 0032fce..b954cad 100644 (file)
@@ -1302,6 +1302,31 @@ protected:
        ArgExprs                        m_args;
 };
 
+template<typename T>
+class Alternatives : public Func<Signature<T, T, T> >
+{
+public:
+       typedef typename        Alternatives::Sig               Sig;
+
+protected:
+       typedef typename        Alternatives::IRet              IRet;
+       typedef typename        Alternatives::IArgs             IArgs;
+
+       virtual string          getName                         (void) const                    { return "alternatives"; }
+       virtual void            doPrintDefinition       (std::ostream&) const   {}
+       void                            doGetUsedFuncs          (FuncSet&) const                {}
+
+       virtual IRet            doApply                         (const EvalContext&, const IArgs& args) const
+       {
+               return unionIVal<T>(args.a, args.b);
+       }
+
+       virtual void            doPrint                         (ostream& os, const BaseArgExprs& args) const
+       {
+               os << "{" << *args[0] << " | " << *args[1] << "}";
+       }
+};
+
 template <typename Sig>
 ExprP<typename Sig::Ret> createApply (const Func<Sig>&                                         func,
                                                                          const typename Func<Sig>::ArgExprs&   args)
@@ -1348,6 +1373,13 @@ typename F::IRet call (const EvalContext&                        ctx,
        return instance<F>().apply(ctx, arg0, arg1, arg2, arg3);
 }
 
+template <typename T>
+ExprP<T> alternatives (const ExprP<T>& arg0,
+                                          const ExprP<T>& arg1)
+{
+       return createApply<typename Alternatives<T>::Sig>(instance<Alternatives<T> >(), arg0, arg1);
+}
+
 template <typename Sig>
 class ApplyVar : public Apply<Sig>
 {