public object Evaluate(Report rpt, Row row) { try { // Check to see if we're evaluating an expression in a page header or footer; // If that is the case the rows are cached by page. if (row == null && this.UniqueName != null) { Rows rows = rpt.GetPageExpressionRows(UniqueName); if (rows != null && rows.Data != null && rows.Data.Count > 0) { row = rows.Data[0]; } } return(_Expr.Evaluate(rpt, row)); } catch (Exception e) { string err; if (e.InnerException != null) { err = String.Format("Exception evaluating {0}. {1}. {2}", _Source, e.Message, e.InnerException.Message); } else { err = String.Format("Exception evaluating {0}. {1}", _Source, e.Message); } ReportError(rpt, 4, err); return(null); } }
public string EvaluateString(Report rpt, Row row) { object o = _Formatee.Evaluate(rpt, row); if (o == null) { return(null); } string format = _Format.EvaluateString(rpt, row); if (format == null) { return(o.ToString()); // just return string version of object } string result = null; try { result = String.Format("{0:" + format + "}", o); } catch (Exception ex) // invalid format string specified { // treat as a weak error rpt.rl.LogError(2, String.Format("Format string:{1} Value Type:{2} Exception:{0}", ex.Message, format, o.GetType().Name)); result = o.ToString(); } return(result); }
public string EvaluateString(Report rpt, Row row) { object o = _Formatee.Evaluate(rpt, row); if (o == null) { return(null); } string format = _Format.EvaluateString(rpt, row); if (format == null) { return(o.ToString()); // just return string version of object } string result = null; try { result = String.Format("{0:" + format + "}", o); } catch // invalid format string specified { // treat as a weak error result = o.ToString(); } return(result); }
private ScriptResult _EvaluateExpression(IExpr expr, bool createTempScope, bool hardTerminal = false) { if (null == expr) { LogError("Cannot evaluate null expression."); return(null); } StackState stackState = defaultContext.stack.GetState(); if (createTempScope) { if (!defaultContext.stack.PushTerminalScope("<Evaluate>", defaultContext, hardTerminal)) { LogError("_EvaluateExpression: stack overflow"); return(null); } } ScriptResult result = new ScriptResult(); result.value = expr.Evaluate(defaultContext); if (defaultContext.IsRuntimeErrorSet()) { defaultContext.stack.RestoreState(stackState); if (logCompileErrors) { LogError(defaultContext.GetRuntimeErrorString()); } result.runtimeError = defaultContext.control.runtimeError; result.success = false; defaultContext.control.Clear(); } else { result.success = true; if (createTempScope) { defaultContext.stack.RestoreState(stackState); defaultContext.control.Clear(); } } return(result); }
// Evaluate is for interpretation (and is relatively slow) public object Evaluate(Report rpt, Row row) { bool result = _If.EvaluateBoolean(rpt, row); if (result) { return(_IfTrue.Evaluate(rpt, row)); } object o = _IfFalse.Evaluate(rpt, row); // We may need to convert IfFalse to same type as IfTrue if (_IfTrue.GetTypeCode() == _IfFalse.GetTypeCode()) { return(o); } return(Convert.ChangeType(o, _IfTrue.GetTypeCode())); }
public object Evaluate(Report rpt, Row row) { try { return(_Expr.Evaluate(rpt, row)); } catch (Exception e) { string err; if (e.InnerException != null) { err = String.Format("Exception evaluating {0}. {1}. {2}", _Source, e.Message, e.InnerException.Message); } else { err = String.Format("Exception evaluating {0}. {1}", _Source, e.Message); } ReportError(rpt, 4, err); return(null); } }
// Create a new instance of the class. public ClassValue Allocate(ExecContext context) { ClassValue result = childAllocator(); result.classDef = this; result.debugName = name + " Inst"; bool scopePushed = false; for (int ii = 0; ii < _fields.Count; ++ii) { ClassMember member = _fields.Get(ii); object value = null; if (null != member.initializer) { if (!scopePushed) { scopePushed = true; if (!context.stack.PushClassScope(result, context)) { context.SetRuntimeError(RuntimeErrorType.StackOverflow, "ClassValue.Allocate - stack overflow."); return(null); } } value = member.initializer.Evaluate(context); } else if (!member.typeDef.IsReference()) // don't instantiate class refs automatically { value = member.typeDef.GetDefaultValue(context); } Variable newVar = new Variable(member.name, member.typeDef, value); result.fieldVars.Add(newVar); } if (null != constructor) { if (context.IsRuntimeErrorSet()) { return(null); } if (!scopePushed) { scopePushed = true; if (!context.stack.PushClassScope(result, context)) { context.SetRuntimeError(RuntimeErrorType.StackOverflow, "ClassValue.Allocate - stack overflow."); return(null); } } constructor.Evaluate(context); if (context.IsRuntimeErrorSet()) { return(null); } } if (scopePushed) { context.stack.PopScope(); } return(result); }
private object _EvaluateInternal(ExecContext context) { return(expr.Evaluate(context)); }