コード例 #1
0
        internal override void FinalPass()
        {
            // optimization: avoid expression overhead if this isn't really an expression
            if (_Source == null)
            {
                _Expr = new Constant("");
                return;
            }
            else if (_Source == "" ||			// empty expression
                _Source[0] != '=')	// if 1st char not '='
            {
                _Expr = new Constant(_Source);	//   this is a constant value
                return;
            }

            Parser p = new Parser(OwnerReport.DataCache);

            // find the fields that are part of the DataRegion (if there is one)
            IDictionary fields=null;
            ReportLink dr = Parent;
            Grouping grp= null;		// remember if in a table group or detail group or list group
            Matrix m=null;
            ReportLink phpf=null;
            while (dr != null)
            {
                if (dr is Grouping)
                    p.NoAggregateFunctions = true;
                else if (dr is TableGroup)
                    grp = ((TableGroup) dr).Grouping;
                else if (dr is Matrix)
                {
                    m = (Matrix) dr;		// if matrix we need to pass special
                    break;
                }
                else if (dr is Details)
                {
                    grp = ((Details) dr).Grouping;
                }
                else if (dr is List)
                {
                    grp = ((List) dr).Grouping;
                    break;
                }
                else if (dr is PageHeader || dr is PageFooter)
                {
                    phpf = dr;
                }
                else if (dr is DataRegion || dr is DataSetDefn)
                    break;
                dr = dr.Parent;
            }
            if (dr != null)
            {
                if (dr is DataSetDefn)
                {
                    DataSetDefn d = (DataSetDefn) dr;
                    if (d.Fields != null)
                        fields = d.Fields.Items;
                }
                else	// must be a DataRegion
                {
                    DataRegion d = (DataRegion) dr;
                    if (d.DataSetDefn != null &&
                        d.DataSetDefn.Fields != null)
                        fields = d.DataSetDefn.Fields.Items;
                }
            }

            NameLookup lu = new NameLookup(fields, OwnerReport.LUReportParameters,
                OwnerReport.LUReportItems,OwnerReport.LUGlobals,
                OwnerReport.LUUser, OwnerReport.LUAggrScope,
                grp, m, OwnerReport.CodeModules, OwnerReport.Classes, OwnerReport.DataSetsDefn,
                OwnerReport.CodeType);

            if (phpf != null)
            {
                // Non-null when expression is in PageHeader or PageFooter;
                //   Expression name needed for dynamic lookup of ReportItems on a page.
                lu.PageFooterHeader = phpf;
                lu.ExpressionName = _UniqueName = "xn_" + Interlocked.Increment(ref Parser.Counter).ToString();
            }

            try
            {
                _Expr = p.Parse(lu, _Source);
            }
            catch (Exception e)
            {
                _Expr = new ConstantError(e.Message);
                // Invalid expression
                OwnerReport.rl.LogError(8, ErrorText(e.Message));
            }

            // Optimize removing any expression that always result in a constant
            try
            {
                _Expr = _Expr.ConstantOptimization();
            }
            catch(Exception ex)
            {
                OwnerReport.rl.LogError(4, "Expression:" + _Source + "\r\nConstant Optimization exception:\r\n" + ex.Message + "\r\nStack trace:\r\n" + ex.StackTrace );
            }
            _Type = _Expr.GetTypeCode();

            return;
        }
コード例 #2
0
        internal TypeCode DoParse(Report rpt)
        {
            // optimization: avoid expression overhead if this isn't really an expression
            if (_Source == null)
            {
                _Expr = new Constant("");
                return _Expr.GetTypeCode();
            }
            else if (_Source == string.Empty ||			// empty expression
                _Source[0] != '=')	// if 1st char not '='
            {
                _Expr = new Constant(_Source);	//   this is a constant value
                return _Expr.GetTypeCode();
            }

            Parser p = new Parser(new System.Collections.Generic.List<ICacheData>());

            // find the fields that are part of the DataRegion (if there is one)
            IDictionary fields=null;
            ReportLink dr = _rl.Parent;
            Grouping grp= null;		// remember if in a table group or detail group or list group
            Matrix m=null;

            while (dr != null)
            {
                if (dr is Grouping)
                    p.NoAggregateFunctions = true;
                else if (dr is TableGroup)
                    grp = ((TableGroup) dr).Grouping;
                else if (dr is Matrix)
                {
                    m = (Matrix) dr;		// if matrix we need to pass special
                    break;
                }
                else if (dr is Details)
                {
                    grp = ((Details) dr).Grouping;
                }
                else if (dr is List)
                {
                    grp = ((List) dr).Grouping;
                    break;
                }
                else if (dr is DataRegion || dr is DataSetDefn)
                    break;
                dr = dr.Parent;
            }
            if (dr != null)
            {
                if (dr is DataSetDefn)
                {
                    DataSetDefn d = (DataSetDefn) dr;
                    if (d.Fields != null)
                        fields = d.Fields.Items;
                }
                else	// must be a DataRegion
                {
                    DataRegion d = (DataRegion) dr;
                    if (d.DataSetDefn != null &&
                        d.DataSetDefn.Fields != null)
                        fields = d.DataSetDefn.Fields.Items;
                }
            }

            NameLookup lu = new NameLookup(fields, rpt.ReportDefinition.LUReportParameters,
                rpt.ReportDefinition.LUReportItems, rpt.ReportDefinition.LUGlobals,
                rpt.ReportDefinition.LUUser, rpt.ReportDefinition.LUAggrScope,
                grp, m, rpt.ReportDefinition.CodeModules, rpt.ReportDefinition.Classes, rpt.ReportDefinition.DataSetsDefn,
                rpt.ReportDefinition.CodeType);

            try
            {
                _Expr = p.Parse(lu, _Source);
            }
            catch (Exception e)
            {
                _Expr = new ConstantError(e.Message);
                // Invalid expression
                rpt.rl.LogError(8, ErrorText(e.Message));
            }

            // Optimize removing any expression that always result in a constant
            try
            {
                _Expr = _Expr.ConstantOptimization();
            }
            catch(Exception ex)
            {
                rpt.rl.LogError(4, "Expression:" + _Source + "\r\nConstant Optimization exception:\r\n" + ex.Message + "\r\nStack trace:\r\n" + ex.StackTrace );
            }

            return _Expr.GetTypeCode();
        }