コード例 #1
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            //TODO: event expression
            CSharpTextBoolean(writer, expressionContext);
        }
コード例 #2
0
        /// <summary>
        /// Gets the source code of arguments of a feature call.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="featureCall">Details of the call.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        /// <param name="isAgentCall">True if the call is for an agent.</param>
        /// <param name="callText">The string to use for a call upon return.</param>
        /// <param name="outgoingResultList">The list of results.</param>
        public static void CSharpArgumentList(ICSharpWriter writer, ICSharpExpressionContext expressionContext, ICSharpFeatureCall featureCall, int skippedIndex, bool isAgentCall, out string callText, out IList <string> outgoingResultList)
        {
            /*if (featureCall.Count == 0 && expressionContext.DestinationNameList.Count == 0)
             * {
             *  callText = string.Empty;
             *  outgoingResultList = new List<string>();
             * }
             * else*/
            {
                callText           = null;
                outgoingResultList = null;

                switch (featureCall.ArgumentStyle)
                {
                case TypeArgumentStyles.None:
                case TypeArgumentStyles.Positional:
                    CSharpPositionalArgumentList(writer, expressionContext, featureCall, skippedIndex, isAgentCall, out callText, out outgoingResultList);
                    break;

                case TypeArgumentStyles.Assignment:
                    CSharpAssignmentArgumentList(writer, expressionContext, featureCall, skippedIndex, isAgentCall, out callText, out outgoingResultList);
                    break;
                }

                Debug.Assert(callText != null);
                Debug.Assert(outgoingResultList != null);
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            string Result = null;

            switch (Delegated)
            {
            case ICSharpAttributeFeature AsAttributeFeature:
                Result = CSharpTextAttribute(writer, AsAttributeFeature);
                break;

            case ICSharpConstantFeature AsConstantFeature:
                Result = CSharpTextConstant(writer, AsConstantFeature);
                break;

            case ICSharpProcedureFeature AsProcedureFeature:
                Result = CSharpTextProcedure(writer, AsProcedureFeature);
                break;

            case ICSharpFunctionFeature AsFunctionFeature:
                Result = CSharpTextFunction(writer, AsFunctionFeature);
                break;

            case ICSharpPropertyFeature AsPropertyFeature:
                Result = CSharpTextProperty(writer, AsPropertyFeature);
                break;
            }

            Debug.Assert(Result != null);

            expressionContext.SetSingleReturnValue(Result);
        }
コード例 #4
0
        private void WriteCSharpCustomOperator(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            string RightText    = SingleResultExpressionText(writer, RightExpression);
            string OperatorText = Operator.Name;

            expressionContext.SetSingleReturnValue($"{OperatorText} {RightText}");
        }
コード例 #5
0
        private void WriteCSharpDiscreteCall(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(FeatureCall.ParameterList.Count == 0);
            Debug.Assert(FeatureCall.ResultList.Count == 0);

            expressionContext.SetSingleReturnValue(Query.CSharpText(writer, 0));
        }
コード例 #6
0
        private void WriteCSharpAgentCall(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, skippedIndex, true, out string ArgumentListText, out IList <string> OutgoingResultList);
            string QueryText = Query.CSharpText(writer, 0);

            IIdentifier AgentIdentifier     = (IIdentifier)Source.Query.Path[Source.Query.Path.Count - 1];
            string      AgentIdentifierText = CSharpNames.ToCSharpIdentifier(AgentIdentifier.ValidText.Item);

            if (Source.Query.Path.Count > 1)
            {
                QueryText = Query.CSharpText(writer, 1);
            }
            else
            {
                QueryText = "this";
            }

            if (FeatureCall.ArgumentList.Count > 0)
            {
                expressionContext.SetSingleReturnValue($"{AgentIdentifierText}({QueryText}, {ArgumentListText})");
            }
            else
            {
                expressionContext.SetSingleReturnValue($"{AgentIdentifierText}({QueryText})");
            }
        }
コード例 #7
0
        private string CSharpTextEvent(ICSharpWriter writer, ICSharpExpressionContext expressionContext)
        {
            string LeftText  = SingleResultExpressionText(writer, LeftExpression);
            string RightText = SingleResultExpressionText(writer, RightExpression);

            string OperatorName = null;

            switch (Source.Conditional)
            {
            case BaseNode.ConditionalTypes.And:
                OperatorName = "&&";
                break;

            case BaseNode.ConditionalTypes.Or:
                OperatorName = "||";
                break;

            case BaseNode.ConditionalTypes.Xor:
                OperatorName = "^";
                break;

            case BaseNode.ConditionalTypes.Implies:
                OperatorName = "/";
                break;
            }

            Debug.Assert(OperatorName != null);

            return($"{LeftText} {OperatorName} {RightText}");
        }
コード例 #8
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        public void WriteCSharpAsConstant(ICSharpWriter writer, ICSharpExpressionContext expressionContext)
        {
            Debug.Assert(WriteDown);
            Debug.Assert(Class.Source.InitializedObjectList.Contains(Source));

            string ClassNameText = CSharpNames.ToCSharpIdentifier(Class.ValidClassName);

            string AssignmentText = string.Empty;

            foreach (ICSharpAssignmentArgument Assignment in AssignmentList)
            {
                ICSharpExpression SourceExpression = Assignment.SourceExpression;
                string            ExpressionText   = SingleResultExpressionText(writer, SourceExpression);

                foreach (string AssignedField in Assignment.ParameterNameList)
                {
                    if (AssignmentText.Length > 0)
                    {
                        AssignmentText += ", ";
                    }

                    string AssignedFieldText = CSharpNames.ToCSharpIdentifier(AssignedField);
                    AssignmentText += $"{AssignedFieldText} = {ExpressionText}";
                }
            }

            expressionContext.SetSingleReturnValue($"new {ClassNameText}() {{ {AssignmentText} }}");
        }
コード例 #9
0
        private void CSharpTextBoolean(ICSharpWriter writer, ICSharpExpressionContext expressionContext)
        {
            string RightText    = SingleResultExpressionText(writer, RightExpression);
            string OperatorName = "!";

            expressionContext.SetSingleReturnValue($"{OperatorName}{RightText}");
        }
コード例 #10
0
        private void WriteCSharpNumberOperator(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            string OperatorText = null;

            switch (Operator.Name)
            {
            case "≥":
                OperatorText = ">=";
                break;

            case "≤":
                OperatorText = "<=";
                break;

            /* TODO: make up our mind: 'shift right' or '>>' ?!
             *
             * case "shift right":
             *  OperatorText = ">>";
             *  break;
             * case "shift left":
             *  OperatorText = "<<";
             *  break;
             */

            case "modulo":
                OperatorText = "%";
                break;

            case "bitwise and":
                OperatorText = "&";
                break;

            case "bitwise or":
                OperatorText = "|";
                break;

            case "bitwise xor":
                OperatorText = "^";
                break;

            case ">":
            case "<":
            case ">>":
            case "<<":
            case "+":
            case "-":
            case "*":
            case "/":
                OperatorText = Operator.Name;
                break;
            }

            Debug.Assert(OperatorText != null);

            string LeftText  = SingleResultExpressionText(writer, LeftExpression);
            string RightText = SingleResultExpressionText(writer, RightExpression);

            expressionContext.SetSingleReturnValue($"{LeftText} {OperatorText} {RightText}");
        }
コード例 #11
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, skippedIndex, false, out string ArgumentListText, out IList <string> OutgoingResultList);

            expressionContext.SetSingleReturnValue($"base[{ArgumentListText}]");
        }
コード例 #12
0
        private static void CSharpAssignmentArgumentList(ICSharpWriter writer, ICSharpExpressionContext expressionContext, ICSharpFeatureCall featureCall, int skippedIndex, bool isAgentCall, out string callText, out IList <string> outgoingResultList)
        {
            IList <ICSharpParameter> ParameterList = featureCall.ParameterList;
            IList <ICSharpParameter> ResultList    = featureCall.ResultList;
            IList <ICSharpArgument>  ArgumentList  = featureCall.ArgumentList;

            int i;

            callText = string.Empty;

            for (i = 0; i < ParameterList.Count; i++)
            {
                if (callText.Length > 0)
                {
                    callText += ", ";
                }

                ICSharpParameter Parameter     = ParameterList[i];
                string           ParameterName = Parameter.Name;

                ICSharpExpression SourceExpression = null;

                foreach (ICSharpAssignmentArgument Argument in ArgumentList)
                {
                    foreach (string Name in Argument.ParameterNameList)
                    {
                        if (ParameterName == Name)
                        {
                            SourceExpression = Argument.SourceExpression;
                            break;
                        }
                    }
                }

                if (SourceExpression != null)
                {
                    ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();

                    SourceExpression.WriteCSharp(writer, SourceExpressionContext, -1);

                    callText += SourceExpressionContext.ResultListAsArgument;
                }
                else
                {
                    ICSharpScopeAttributeFeature Feature      = Parameter.Feature;
                    ICSharpExpression            DefaultValue = Feature.DefaultValue;

                    Debug.Assert(DefaultValue != null);

                    ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();
                    DefaultValue.WriteCSharp(writer, SourceExpressionContext, -1);

                    callText += SourceExpressionContext.ResultListAsArgument;
                }
            }

            CSharpAssignmentResultList(writer, expressionContext, featureCall, skippedIndex, isAgentCall, ref callText, out outgoingResultList);
        }
コード例 #13
0
        private static void CSharpPositionalArgumentList(ICSharpWriter writer, ICSharpExpressionContext expressionContext, ICSharpFeatureCall featureCall, int skippedIndex, bool isAgentCall, out string callText, out IList <string> outgoingResultList)
        {
            IList <ICSharpParameter> ParameterList = featureCall.ParameterList;
            IList <ICSharpParameter> ResultList    = featureCall.ResultList;
            IList <ICSharpArgument>  ArgumentList  = featureCall.ArgumentList;

            int i, j;

            callText = string.Empty;

            i = 0;
            j = 0;
            for (; i < ArgumentList.Count; i++)
            {
                if (callText.Length > 0)
                {
                    callText += ", ";
                }

                ICSharpPositionalArgument Argument = ArgumentList[i] as ICSharpPositionalArgument;
                Debug.Assert(Argument != null);

                ICSharpExpression        SourceExpression        = Argument.SourceExpression;
                ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();

                SourceExpression.WriteCSharp(writer, SourceExpressionContext, -1);

                callText += SourceExpressionContext.ResultListAsArgument;

                j += SourceExpressionContext.CompleteDestinationNameList.Count;
                if (SourceExpressionContext.ReturnValue != null)
                {
                    j++;
                }
            }

            i = j;
            for (; i < ParameterList.Count; i++)
            {
                if (callText.Length > 0)
                {
                    callText += ", ";
                }

                ICSharpParameter             Parameter    = ParameterList[i];
                ICSharpScopeAttributeFeature Feature      = Parameter.Feature;
                ICSharpExpression            DefaultValue = Feature.DefaultValue;

                Debug.Assert(DefaultValue != null);

                ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();
                DefaultValue.WriteCSharp(writer, SourceExpressionContext, -1);

                callText += SourceExpressionContext.ResultListAsArgument;
            }

            CSharpAssignmentResultList(writer, expressionContext, featureCall, skippedIndex, isAgentCall, ref callText, out outgoingResultList);
        }
コード例 #14
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            Debug.Assert(TypeList.Count > 0);

            string CloneMethod = Source.Type == BaseNode.CloneType.Shallow ? "CloneShallow" : "Clone";

            ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();

            SourceExpression.WriteCSharp(writer, SourceExpressionContext, -1);

            IList <string> ResultList       = new List <string>();
            int            ReturnValueIndex = SourceExpressionContext.ReturnValueIndex;
            string         ReturnValue      = SourceExpressionContext.ReturnValue;

            if (TypeList.Count == 1)
            {
                ICSharpType ClonedType     = TypeList[0];
                string      SourceTypeText = ClonedType.Type2CSharpString(writer, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None);

                string SourceText = SourceExpressionContext.ReturnValue;
                Debug.Assert(SourceText != null);

                expressionContext.SetSingleReturnValue($"({SourceTypeText})({SourceText}).{CloneMethod}()");
            }
            else
            {
                for (int i = 0; i < SourceExpressionContext.CompleteDestinationNameList.Count; i++)
                {
                    if (i == ReturnValueIndex)
                    {
                        Debug.Assert(ReturnValue != null);
                        ResultList.Add(ReturnValue);
                    }
                    else
                    {
                        ResultList.Add(SourceExpressionContext.CompleteDestinationNameList[i]);
                    }
                }

                Debug.Assert(TypeList.Count == ResultList.Count);

                IList <string> OutgoingResultList = new List <string>();

                for (int i = 0; i < TypeList.Count; i++)
                {
                    ICSharpType ClonedType     = TypeList[i];
                    string      SourceTypeText = ClonedType.Type2CSharpString(writer, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None);
                    string      SourceText     = ResultList[i];

                    OutgoingResultList.Add($"({SourceTypeText})({SourceText}).{CloneMethod}()");
                }

                expressionContext.SetMultipleResult(OutgoingResultList, ReturnValueIndex);
            }
        }
コード例 #15
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);
            Debug.Assert(Class.Source.InitializedObjectList.Contains(Source));

            string ClassNameText = CSharpNames.ToCSharpIdentifier(Class.ValidClassName);
            int    Index         = Class.Source.InitializedObjectList.IndexOf(Source);

            expressionContext.SetSingleReturnValue($"{ClassNameText}.InitializedObject{Index}");
        }
コード例 #16
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            if (IsEventExpression)
            {
                expressionContext.SetSingleReturnValue(CSharpTextEvent(writer, expressionContext));
            }
            else
            {
                WriteCSharpBoolean(writer, expressionContext);
            }
        }
コード例 #17
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            if (IsCallingNumberFeature)
            {
                WriteCSharpNumberOperator(writer, expressionContext, skippedIndex);
            }
            else
            {
                WriteCSharpCustomOperator(writer, expressionContext, skippedIndex);
            }
        }
コード例 #18
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            if (IsAgent)
            {
                WriteCSharpAgentCall(writer, expressionContext, skippedIndex);
            }
            else if (Discrete != null)
            {
                WriteCSharpDiscreteCall(writer, expressionContext, skippedIndex);
            }
            else
            {
                WriteCSharpFeatureCall(writer, expressionContext, skippedIndex);
            }

            /*
             * else
             * {
             *  IList<IIdentifier> ValidPath = Query.Source.ValidPath.Item;
             *  IList<IExpressionType> ValidResultTypePath = Query.Source.ValidResultTypePath.Item;
             *
             *  if (ValidResultTypePath.Count >= 2)
             *  {
             *      ExpressionType CallerExpressionType = ValidResultTypePath[ValidResultTypePath.Count - 2];
             *      string CalledFeature = ValidPath[ValidPath.Count - 1].ValidText.Item;
             *      if (CalledFeature == "Has Handler")
             *      {
             *          foreach (KeyValuePair<TypeName, ICompiledType> Entry in CallerExpressionType.ValueType.ConformanceTable)
             *          {
             *              ClassType AsClassType;
             *              if ((AsClassType = Entry.Value as ClassType) != null)
             *              {
             *                  Class BaseClass = (Class)AsClassType.BaseClass;
             *                  if (BaseClass.InheritFromDotNetEvent)
             *                  {
             *                      bool SkipParenthesis = false;
             *                      if (ParentSource is Conditional)
             *                          SkipParenthesis = true;
             *
             *                      return (SkipParenthesis ? "" : "(") + Query.DecoratedCSharpText(Context, 1) + " " + "!=" + " " + "null" + (SkipParenthesis ? "" : ")");
             *                  }
             *              }
             *          }
             *      }
             *  }
             *
             *  return Query.DecoratedCSharpText(cSharpNamespace, 0);
             * }*/
        }
コード例 #19
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            string Result = string.Empty;

            foreach (char c in Source.ValidText.Item)
            {
                switch (c)
                {
                case '\"':
                    Result += "\\\"";
                    break;

                case '\\':
                    Result += "\\\\";
                    break;

                case '\a':
                    Result += "\\a";
                    break;

                case '\b':
                    Result += "\\b";
                    break;

                case '\f':
                    Result += "\\f";
                    break;

                case '\n':
                    Result += "\\n";
                    break;

                case '\r':
                    Result += "\\r";
                    break;

                case '\t':
                    Result += "\\t";
                    break;

                default:
                    Result += c;
                    break;
                }
            }

            expressionContext.SetSingleReturnValue($"\"{Result}\"");
        }
コード例 #20
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();

            IndexedExpression.WriteCSharp(writer, SourceExpressionContext, -1);

            string IndexedText = SourceExpressionContext.ReturnValue;

            CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, -1, false, out string ArgumentListText, out IList <string> OutgoingResultList);

            expressionContext.SetSingleReturnValue($"{IndexedText}[{ArgumentListText}]");
        }
コード例 #21
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            string Result = null;

            //TODO

            switch (Source.Value)
            {
            case BaseNode.Keyword.True:
                Result = "true";
                break;

            case BaseNode.Keyword.False:
                Result = "false";
                break;

            case BaseNode.Keyword.Current:
                Result = "this";
                break;

            case BaseNode.Keyword.Value:
                Result = "value";
                break;

            case BaseNode.Keyword.Result:
                Result = "Result";
                break;

            case BaseNode.Keyword.Retry:
                Result = "Retry";
                break;

            case BaseNode.Keyword.Exception:
                Result = "CaughtException";
                break;

            case BaseNode.Keyword.Indexer:
                Result = "Indexer";
                break;
            }

            Debug.Assert(Result != null);

            expressionContext.SetSingleReturnValue(Result);
        }
コード例 #22
0
        private void WriteCSharpFeatureCall(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Feature.GetOutputFormat(SelectedOverloadType, out int OutgoingParameterCount, out int ReturnValueIndex);

            CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, ReturnValueIndex, false, out string ArgumentListText, out IList <string> OutgoingResultList);
            string QueryText = Query.CSharpText(writer, 0);

            Debug.Assert(OutgoingParameterCount > 0);

            if (OutgoingParameterCount == 1)
            {
                if (ArgumentListText.Length > 0)
                {
                    expressionContext.SetSingleReturnValue($"{QueryText}({ArgumentListText})");
                }
                else if (Feature is ICSharpFunctionFeature)
                {
                    expressionContext.SetSingleReturnValue($"{QueryText}()");
                }
                else
                {
                    if (writer.AttachmentMap.ContainsKey(QueryText))
                    {
                        QueryText = writer.AttachmentMap[QueryText];
                    }

                    expressionContext.SetSingleReturnValue(QueryText);
                }
            }
            else
            {
                if (ReturnValueIndex >= 0)
                {
                    string TemporaryResultName = writer.GetTemporaryName();
                    writer.WriteIndentedLine($"var {TemporaryResultName} = {QueryText}({ArgumentListText});");

                    OutgoingResultList.Insert(ReturnValueIndex, TemporaryResultName);
                }
                else
                {
                    writer.WriteIndentedLine($"{QueryText}({ArgumentListText});");
                }

                expressionContext.SetMultipleResult(OutgoingResultList, ReturnValueIndex);
            }
        }
コード例 #23
0
        private void WriteCSharpBoolean(ICSharpWriter writer, ICSharpExpressionContext expressionContext)
        {
            if (LeftExpression.IsSingleResult && RightExpression.IsSingleResult)
            {
                string LeftText  = SingleResultExpressionText(writer, LeftExpression);
                string RightText = SingleResultExpressionText(writer, RightExpression);

                if (Source.Conditional == BaseNode.ConditionalTypes.Implies)
                {
                    expressionContext.SetSingleReturnValue($"!{LeftText} || {RightText}");
                }
                else
                {
                    string OperatorName = null;

                    switch (Source.Conditional)
                    {
                    case BaseNode.ConditionalTypes.And:
                        OperatorName = "&&";
                        break;

                    case BaseNode.ConditionalTypes.Or:
                        OperatorName = "||";
                        break;

                    case BaseNode.ConditionalTypes.Xor:
                        OperatorName = "^";
                        break;
                    }

                    Debug.Assert(OperatorName != null);

                    expressionContext.SetSingleReturnValue($"{LeftText} {OperatorName} {RightText}");
                }
            }
            else
            {
                //TODO
                expressionContext.SetSingleReturnValue("TODO");
            }
        }
コード例 #24
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            string TypeText;
            string ClassName;
            string ConstantName;

            if (Feature != null)
            {
                TypeText = string.Empty;

                if (Class.ValidSourceName == "Microsoft .NET")
                {
                    ClassName    = CSharpNames.ToDotNetIdentifier(Class.ValidClassName);
                    ConstantName = CSharpNames.ToDotNetIdentifier(Feature.Name);
                }
                else
                {
                    ClassName    = CSharpNames.ToCSharpIdentifier(Class.ValidClassName);
                    ConstantName = CSharpNames.ToCSharpIdentifier(Feature.Name);
                }
            }
            else
            {
                TypeText = "(int)";

                if (Class.HasDiscreteWithUnkownValue)
                {
                    ClassName = CSharpNames.ToCSharpIdentifier(Class.ValidClassName) + "_Enum";
                }
                else
                {
                    ClassName = CSharpNames.ToCSharpIdentifier(Class.ValidClassName);
                }

                ConstantName = CSharpNames.ToCSharpIdentifier(Discrete.Name);
            }

            expressionContext.SetSingleReturnValue($"{TypeText}{ClassName}.{ConstantName}");
        }
コード例 #25
0
        private void WriteCSharpCustomOperator(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            string OperatorText = CSharpNames.ToCSharpIdentifier(Operator.Name);

            if (LeftExpression.IsSingleResult && RightExpression.IsSingleResult)
            {
                string LeftText = SingleResultExpressionText(writer, LeftExpression);

                ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext();
                RightExpression.WriteCSharp(writer, SourceExpressionContext, -1);
                string RightText = SourceExpressionContext.ReturnValue;

                expressionContext.SetSingleReturnValue($"{LeftText}.{OperatorText}({RightText})");
            }
            else
            {
                Operator.GetOutputFormat(SelectedOverloadType, out int OutgoingParameterCount, out int ReturnValueIndex);

                string LeftText = SingleResultExpressionText(writer, LeftExpression);

                CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, ReturnValueIndex, false, out string ArgumentListText, out IList <string> OutgoingResultList);

                if (ReturnValueIndex >= 0)
                {
                    string TemporaryResultName = writer.GetTemporaryName();
                    writer.WriteIndentedLine($"var {TemporaryResultName} = {LeftText}.{OperatorText}({ArgumentListText});");

                    OutgoingResultList.Insert(ReturnValueIndex, TemporaryResultName);
                }
                else
                {
                    writer.WriteIndentedLine($"{LeftText}.{OperatorText}({ArgumentListText});");
                }

                expressionContext.SetMultipleResult(OutgoingResultList, ReturnValueIndex);
            }
        }
コード例 #26
0
 /// <summary>
 /// Writes down the C# instruction.
 /// </summary>
 /// <param name="writer">The stream on which to write.</param>
 /// <param name="expressionContext">The context.</param>
 /// <param name="skippedIndex">Index of a destination to skip.</param>
 public abstract void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex);
コード例 #27
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            string CoexistingPrecursorName     = string.Empty;
            string CoexistingPrecursorRootName = ParentFeature.CoexistingPrecursorName;

            if (!string.IsNullOrEmpty(CoexistingPrecursorRootName))
            {
                CoexistingPrecursorName = CSharpNames.ToCSharpIdentifier(CoexistingPrecursorRootName + " " + "Base");
            }

            PrecursorFeature.GetOutputFormat(SelectedOverloadType, out int OutgoingParameterCount, out int ReturnValueIndex);

            CSharpArgument.CSharpArgumentList(writer, expressionContext, FeatureCall, ReturnValueIndex, false, out string ArgumentListText, out IList <string> OutgoingResultList);
            Debug.Assert(OutgoingParameterCount > 0);

            bool HasArguments = (ParentFeature is ICSharpFunctionFeature) || FeatureCall.ArgumentList.Count > 0;

            if (HasArguments)
            {
                ArgumentListText = $"({ArgumentListText})";
            }

            if (!string.IsNullOrEmpty(CoexistingPrecursorRootName))
            {
                expressionContext.SetSingleReturnValue($"{CoexistingPrecursorName}{ArgumentListText}");
            }
            else
            {
                string FunctionName = CSharpNames.ToCSharpIdentifier(ParentFeature.Name);

                if (OutgoingParameterCount == 1)
                {
                    if (ArgumentListText.Length > 0)
                    {
                        expressionContext.SetSingleReturnValue($"base.{FunctionName}{ArgumentListText}");
                    }
                    else if (SelectedOverloadType != null)
                    {
                        expressionContext.SetSingleReturnValue($"base.{FunctionName}()");
                    }
                    else
                    {
                        expressionContext.SetSingleReturnValue($"base.{FunctionName}");
                    }
                }
                else
                {
                    if (ReturnValueIndex >= 0)
                    {
                        string TemporaryResultName = writer.GetTemporaryName();
                        writer.WriteIndentedLine($"var {TemporaryResultName} = base.{FunctionName}{ArgumentListText};");

                        OutgoingResultList.Insert(ReturnValueIndex, TemporaryResultName);
                    }
                    else
                    {
                        writer.WriteIndentedLine($"base.{FunctionName}{ArgumentListText};");
                    }

                    expressionContext.SetMultipleResult(OutgoingResultList, ReturnValueIndex);
                }
            }
        }
コード例 #28
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            expressionContext.SetSingleReturnValue(string.Empty);//TODO
        }
コード例 #29
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            string QueryText = Query.CSharpText(writer, 0);
            string Result    = null;

            if (Feature != null)
            {
                switch (Feature)
                {
                case ICSharpAttributeFeature AsAttributeFeature:
                    Result = "Entity" + "." + "FromThis" + "(" + "this" + ")" + "." + "Property" + "(" + "\"" + QueryText + "\"" + ")";
                    break;

                case ICSharpConstantFeature AsConstantFeature:
                    Result = "Entity" + "." + "FromThis" + "(" + "this" + ")" + "." + "Property" + "(" + "\"" + QueryText + "\"" + ")";
                    break;

                case ICSharpCreationFeature AsCreationFeature:
                    Result = "Entity" + "." + "FromThis" + "(" + "this" + ")" + "." + "Procedure" + "(" + "\"" + QueryText + "\"" + ")";
                    break;

                case ICSharpFunctionFeature AsFunctionFeature:
                    Result = "Entity" + "." + "FromThis" + "(" + "this" + ")" + "." + "Function" + "(" + "\"" + QueryText + "\"" + ")";
                    break;

                case ICSharpProcedureFeature AsProcedureFeature:
                    Result = "Entity" + "." + "FromThis" + "(" + "this" + ")" + "." + "Procedure" + "(" + "\"" + QueryText + "\"" + ")";
                    break;

                case ICSharpPropertyFeature AsPropertyFeature:
                    Result = "Entity" + "." + "FromThis" + "(" + "this" + ")" + "." + "Property" + "(" + "\"" + QueryText + "\"" + ")";
                    break;

                case ICSharpScopeAttributeFeature AsScopeAttributeFeature:
                    /*
                     * string FeatureString;
                     * IIndexerFeature ThisFeatureAsIndexer;
                     * IFeatureWithName ThisFeatureWithName;
                     *
                     * if ((ThisFeatureAsIndexer = EmbeddingFeature as IIndexerFeature) != null)
                     *  FeatureString = "null";
                     *
                     * else if ((ThisFeatureWithName = EmbeddingFeature as IFeatureWithName) != null)
                     *  FeatureString = "\"" + CSharpRootOutput.ToCSharpIdentifier(ThisFeatureWithName.ValidFeatureName.Item.Name) + "\"";
                     *
                     * else
                     *  throw new InvalidCastException();
                     *
                     * Result = "LocalEntity" + "." + "FromThis" + "(" + "this" + "," + " " + FeatureString + "," + " " + "\"" + QueryText + "\"" + ")";
                     */
                    Result = "Entity" + "." + "FromThis" + "(" + "this" + ")" + "." + "Property" + "(" + "\"" + QueryText + "\"" + ")";
                    break;
                }
            }

            else if (Discrete != null)
            {
                Result = "Entity" + "." + "FromThis" + "(" + "this" + ")" + "." + "Property" + "(" + "\"" + QueryText + "\"" + ")";
            }

            Debug.Assert(Result != null);

            expressionContext.SetSingleReturnValue(Result);
        }
コード例 #30
0
        /// <summary>
        /// Gets the source code corresponding to the expression.
        /// </summary>
        /// <param name="writer">The stream on which to write.</param>
        /// <param name="expressionContext">The context.</param>
        /// <param name="skippedIndex">Index of a destination to skip.</param>
        public override void WriteCSharp(ICSharpWriter writer, ICSharpExpressionContext expressionContext, int skippedIndex)
        {
            Debug.Assert(WriteDown);

            expressionContext.SetSingleReturnValue(Source.ValidText.Item);
        }