/// <summary>
        /// Computes the constant value of a nested expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expression">The expression to compute.</param>
        protected static string ComputeNestedExpression(ICSharpWriter writer, ICSharpExpression expression)
        {
            string ValueString;

            ICSharpExpressionAsConstant ExpressionAsConstant = expression as ICSharpExpressionAsConstant;

            Debug.Assert(ExpressionAsConstant != null);

            if (ExpressionAsConstant.IsDirectConstant)
            {
                ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();
                expression.WriteCSharp(writer, SourceExpressionContext, -1);

                ValueString = SourceExpressionContext.ReturnValue;
            }
            else
            {
                ICSharpComputableExpression ComputableExpression = ExpressionAsConstant as ICSharpComputableExpression;
                Debug.Assert(ComputableExpression != null);

                ComputableExpression.Compute(writer);
                ValueString = ComputableExpression.ComputedValue;
            }

            return(ValueString);
        }
Example #2
0
        private void ComputeConstant(ICSharpWriter writer)
        {
            string ValueString;

            ICSharpExpressionAsConstant ExpressionAsConstant = ConstantExpression as ICSharpExpressionAsConstant;

            Debug.Assert(ExpressionAsConstant != null);

            if (ExpressionAsConstant.IsDirectConstant)
            {
                ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();
                ConstantExpression.WriteCSharp(writer, SourceExpressionContext, -1);

                ValueString = SourceExpressionContext.ReturnValue;
            }
            else
            {
                ICSharpComputableExpression ComputableExpression = ExpressionAsConstant as ICSharpComputableExpression;
                Debug.Assert(ComputableExpression != null);

                ComputableExpression.Compute(writer);
                ValueString = ComputableExpression.ComputedValue;
            }

            ComputedValue = ValueString;
        }
Example #3
0
        private Number ComputeSide(ICSharpWriter writer, ICSharpExpression expression)
        {
            string ValueString;

            ICSharpExpressionAsConstant ExpressionAsConstant = expression as ICSharpExpressionAsConstant;

            Debug.Assert(ExpressionAsConstant != null);

            if (ExpressionAsConstant.IsDirectConstant)
            {
                ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();
                expression.WriteCSharp(writer, SourceExpressionContext, -1);

                ValueString = SourceExpressionContext.ReturnValue;
            }
            else
            {
                ICSharpComputableExpression ComputableExpression = ExpressionAsConstant as ICSharpComputableExpression;
                Debug.Assert(ComputableExpression != null);

                ComputableExpression.Compute(writer);
                ValueString = ComputableExpression.ComputedValue;
            }

            FormattedNumber Result = FormattedNumber.Parse(ValueString);

            return(Result.Value);
        }
        private void WriteCSharpImplementation(ICSharpWriter writer, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline)
        {
            writer.WriteDocumentation(Source);

            string TypeString      = Type.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);
            string AttributeString = CSharpNames.ToCSharpIdentifier(Name);

            ICSharpExpressionAsConstant ExpressionAsConstant = ConstantExpression as ICSharpExpressionAsConstant;

            Debug.Assert(ExpressionAsConstant != null);

            string ValueString;

            if (ExpressionAsConstant.IsDirectConstant)
            {
                ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();
                ConstantExpression.WriteCSharp(writer, SourceExpressionContext, -1);

                ValueString = SourceExpressionContext.ReturnValue;
                Debug.Assert(ValueString != null);
            }
            else
            {
                ICSharpComputableExpression CompilableExpression = ConstantExpression as ICSharpComputableExpression;
                Debug.Assert(CompilableExpression != null);

                CompilableExpression.Compute(writer);
                ValueString = CompilableExpression.ComputedValue;
                Debug.Assert(ValueString != null);

                writer.WriteIndentedLine($"// {ValueString} = {ConstantExpression.Source.ExpressionToString}");
            }

            string ExportStatusText = CSharpNames.ComposedExportStatus(false, false, true, exportStatus);

            bool IsReadOnlyObject;

            if (Type is ICSharpClassType AsClassType)
            {
                Guid ClassGuid = AsClassType.Source.BaseClass.ClassGuid;
                IsReadOnlyObject = ClassGuid != LanguageClasses.Number.Guid && ClassGuid != LanguageClasses.Boolean.Guid && ClassGuid != LanguageClasses.String.Guid && ClassGuid != LanguageClasses.Character.Guid;
            }
            else
            {
                IsReadOnlyObject = true;
            }

            string ConstString = IsReadOnlyObject ? "static readonly" : "const";

            writer.WriteIndentedLine($"{ExportStatusText} {ConstString} {TypeString} {AttributeString} = {ValueString};");
        }