@@ -152,7 +152,7 @@ class SimpleEvaluator {
152152 public:
153153 virtual ~Expression ();
154154
155- // / Evaluate a Expression.
155+ // / Evaluate an Expression.
156156 virtual bdld::Datum evaluate (EvaluationContext& context) const = 0;
157157 };
158158
@@ -711,30 +711,27 @@ class CompilationContext {
711711// / Contain the inputs of an evaluation.
712712class EvaluationContext {
713713 private:
714- // Where to read properties from.
715- PropertiesReader* d_propertiesReader;
716-
717- // The allocator to use during evaluation.
714+ // / The allocator to use during evaluation.
718715 bslma::Allocator* d_allocator;
719716
720- // Set by `Expression::evaluate` functions when a property does not
721- // have the type deduced during compilation. Stop evaluation and return
722- // `true`.
723- bool d_stop;
717+ // / Where to read properties from.
718+ PropertiesReader* d_propertiesReader;
724719
720+ // / @brief The last encountered error during evaluation or `e_OK` if there
721+ // / is no error. Note that we stop evaluation and return early if
722+ // / an error occurred
725723 ErrorType::Enum d_lastError;
726724
727725 public:
728726 // CREATORS
729- EvaluationContext (PropertiesReader* propertiesReader,
730- bslma::Allocator* allocator);
727+ explicit EvaluationContext (PropertiesReader* propertiesReader,
728+ bslma::Allocator* allocator);
731729
732730 void setPropertiesReader (PropertiesReader* propertiesReader);
733731
734732 void reset ();
735733
736- // / Stop execution.
737- bdld::Datum stop ();
734+ void setError (ErrorType::Enum value);
738735
739736 // / Return `true` if an error occurred and `false` otherwise.
740737 bool hasError () const ;
@@ -844,14 +841,12 @@ bdld::Datum
844841SimpleEvaluator::Comparison<Op>::evaluate(EvaluationContext& context) const
845842{
846843 bdld::Datum left = d_left->evaluate (context);
847-
848- if (context.d_stop ) {
844+ if (context.hasError ()) {
849845 return bdld::Datum::createNull (); // RETURN
850846 }
851847
852848 bdld::Datum right = d_right->evaluate (context);
853-
854- if (context.d_stop ) {
849+ if (context.hasError ()) {
855850 return bdld::Datum::createNull (); // RETURN
856851 }
857852
@@ -862,9 +857,8 @@ SimpleEvaluator::Comparison<Op>::evaluate(EvaluationContext& context) const
862857 // RETURN
863858 }
864859
865- context.d_lastError = ErrorType::e_TYPE;
866-
867- return context.stop (); // RETURN
860+ context.setError (ErrorType::e_TYPE);
861+ return bdld::Datum::createNull (); // RETURN
868862 }
869863
870864 bsls::Types::Int64 a;
@@ -877,9 +871,8 @@ SimpleEvaluator::Comparison<Op>::evaluate(EvaluationContext& context) const
877871 a = left.theInteger ();
878872 }
879873 else {
880- context.d_lastError = ErrorType::e_TYPE;
881-
882- return context.stop (); // RETURN
874+ context.setError (ErrorType::e_TYPE);
875+ return bdld::Datum::createNull (); // RETURN
883876 }
884877
885878 if (right.isInteger64 ()) {
@@ -889,9 +882,8 @@ SimpleEvaluator::Comparison<Op>::evaluate(EvaluationContext& context) const
889882 b = right.theInteger ();
890883 }
891884 else {
892- context.d_lastError = ErrorType::e_TYPE;
893-
894- return context.stop (); // RETURN
885+ context.setError (ErrorType::e_TYPE);
886+ return bdld::Datum::createNull (); // RETURN
895887 }
896888
897889 return bdld::Datum::createBoolean (Op<bsls::Types::Int64>()(a, b));
@@ -935,14 +927,12 @@ bdld::Datum SimpleEvaluator::NumBinaryOperation<Op>::evaluate(
935927 EvaluationContext& context) const
936928{
937929 bdld::Datum left = d_left->evaluate (context);
938-
939- if (context.d_stop ) {
930+ if (context.hasError ()) {
940931 return bdld::Datum::createNull (); // RETURN
941932 }
942933
943934 bdld::Datum right = d_right->evaluate (context);
944-
945- if (context.d_stop ) {
935+ if (context.hasError ()) {
946936 return bdld::Datum::createNull (); // RETURN
947937 }
948938
@@ -956,9 +946,8 @@ bdld::Datum SimpleEvaluator::NumBinaryOperation<Op>::evaluate(
956946 a = left.theInteger ();
957947 }
958948 else {
959- context.d_lastError = ErrorType::e_TYPE;
960-
961- return context.stop (); // RETURN
949+ context.setError (ErrorType::e_TYPE);
950+ return bdld::Datum::createNull (); // RETURN
962951 }
963952
964953 if (right.isInteger64 ()) {
@@ -968,9 +957,8 @@ bdld::Datum SimpleEvaluator::NumBinaryOperation<Op>::evaluate(
968957 b = right.theInteger ();
969958 }
970959 else {
971- context.d_lastError = ErrorType::e_TYPE;
972-
973- return context.stop (); // RETURN
960+ context.setError (ErrorType::e_TYPE);
961+ return bdld::Datum::createNull (); // RETURN
974962 }
975963
976964 bsls::Types::Int64 result = Op<bsls::Types::Int64>()(a, b);
@@ -1170,9 +1158,8 @@ CompilationContext::makeUnaryExpression(ArgType expr)
11701158
11711159inline EvaluationContext::EvaluationContext (PropertiesReader* propertiesReader,
11721160 bslma::Allocator* allocator)
1173- : d_propertiesReader(propertiesReader)
1174- , d_allocator(allocator)
1175- , d_stop(false )
1161+ : d_allocator(allocator)
1162+ , d_propertiesReader(propertiesReader)
11761163, d_lastError(ErrorType::e_OK)
11771164{
11781165}
@@ -1185,20 +1172,18 @@ EvaluationContext::setPropertiesReader(PropertiesReader* propertiesReader)
11851172
11861173inline void EvaluationContext::reset ()
11871174{
1188- d_stop = false ;
11891175 d_lastError = ErrorType::e_OK;
11901176}
11911177
1192- inline bdld::Datum EvaluationContext::stop ( )
1178+ inline void EvaluationContext::setError (ErrorType::Enum value )
11931179{
1194- d_stop = true ;
1195-
1196- return bdld::Datum::createNull ();
1180+ BSLS_ASSERT_SAFE (!hasError ());
1181+ d_lastError = value;
11971182}
11981183
11991184inline bool EvaluationContext::hasError () const
12001185{
1201- return d_lastError != 0 ;
1186+ return d_lastError != ErrorType::e_OK ;
12021187}
12031188
12041189inline ErrorType::Enum EvaluationContext::lastError () const
0 commit comments