/// <summary>Handles the specified expression.</summary>
    /// <param name="unaryOperatorExpression">The invocation expression.</param>
    /// <param name="scopeParameters">The parameters.</param>
    /// <returns>Returns the string.</returns>
    public ExpressionDescriptor Handle(IUnaryOperatorExpression unaryOperatorExpression, Dictionary<string, string> scopeParameters)
    {
      var left = unaryOperatorExpression.Operand;
      if (left == null)
      {
        return null;
      }

      var statement = ExpressionTemplateBuilder.Handle(left, scopeParameters);
      if (statement == null)
      {
        return null;
      }

      var result = new ExpressionDescriptor
      {
        Template = string.Format("{0}{1}", unaryOperatorExpression.OperatorSign.GetTokenType().TokenRepresentation, statement.Template)
      };

      foreach (var variable in statement.TemplateVariables)
      {
        result.TemplateVariables[variable.Key] = variable.Value;
      }

      return result;
    }
        public override void VisitUnaryOperatorExpression(IUnaryOperatorExpression operation)
        {
            LogString(nameof(IUnaryOperatorExpression));

            var kindStr = $"{nameof(UnaryOperationKind)}.{operation.UnaryOperationKind}";

            LogString($" ({kindStr})");
            LogHasOperatorMethodExpressionCommon(operation);
            LogCommonPropertiesAndNewLine(operation);

            base.VisitUnaryOperatorExpression(operation);
        }
        public static MethodCallPredicateCheck TryCreate(IUnaryOperatorExpression expression)
        {
            Contract.Requires(expression != null);

            // Looking for constructs like !string.IsNullOrEmpty or !string.IsNullOrWhitespace

            // TODO: add test case: (!(!(string.IsNullOrEmpty)))

            var invocationExpression = expression.Operand as IInvocationExpression;
            if (invocationExpression == null)
                return null;

            return TryCreateImpl(invocationExpression, expression.UnaryOperatorType == UnaryOperatorType.EXCL);
        }
        public static MethodCallPredicateCheck TryCreate(IUnaryOperatorExpression expression)
        {
            Contract.Requires(expression != null);

            // Looking for constructs like !string.IsNullOrEmpty or !string.IsNullOrWhitespace

            // TODO: add test case: (!(!(string.IsNullOrEmpty)))

            var invocationExpression = expression.Operand as IInvocationExpression;

            if (invocationExpression == null)
            {
                return(null);
            }

            return(TryCreateImpl(invocationExpression, expression.UnaryOperatorType == UnaryOperatorType.EXCL));
        }
 public static IUnaryOperatorExpression Update(this IUnaryOperatorExpression self, Enum @operatorKind, IOperation @operand, Object @constantValueOpt, IMethodSymbol @methodOpt, Enum @resultKind, ITypeSymbol @type) => self;
 /// <inheritdoc />
 public override IOperation VisitUnaryOperatorExpression(IUnaryOperatorExpression operation, object argument)
 {
     return(base.VisitUnaryOperatorExpression(operation, argument));
 }
Example #7
0
 /// <summary>
 /// Creates a new C# expression.
 /// </summary>
 /// <param name="context">The creation context.</param>
 /// <param name="source">The Easly expression from which the C# expression is created.</param>
 public static ICSharpUnaryOperatorExpression Create(ICSharpContext context, IUnaryOperatorExpression source)
 {
     return(new CSharpUnaryOperatorExpression(context, source));
 }
 public override void VisitUnaryOperatorExpression(IUnaryOperatorExpression expr, IList <IStatement> context)
 {
     expr.Operand.Accept(this, context);
 }
        /// <summary>
        /// Negates the unary expression.
        /// </summary>
        /// <param name="factory">
        /// The factory.
        /// </param>
        /// <param name="unaryOperatorExpression">
        /// The unary operator expression.
        /// </param>
        private static void NegateUnaryExpression(CSharpElementFactory factory, IUnaryOperatorExpression unaryOperatorExpression)
        {
            if (unaryOperatorExpression.OperatorSign.GetText() != "!")
              {
            return;
              }

              var text = unaryOperatorExpression.Operand.GetText().Trim();

              if (text.StartsWith("(") && text.EndsWith(")"))
              {
            text = text.Substring(1, text.Length - 2);
              }

              var expression = factory.CreateExpression(text);

              unaryOperatorExpression.ReplaceBy(expression);
        }
            public override Expression VisitUnaryOperatorExpression(IUnaryOperatorExpression unaryOperatorExpressionParam, IMetadataResolver context)
            {
                Expression operandExpression = unaryOperatorExpressionParam.Operand.Accept(this, context);

                return(new UnaryOperatorExpressionBuilder(unaryOperatorExpressionParam, operandExpression).Build());
            }
 /// <inheritdoc />
 public override Expression VisitUnaryOperatorExpression(IUnaryOperatorExpression operation, LocalBinder argument)
 {
     return(base.VisitUnaryOperatorExpression(operation, argument));
 }
Example #12
0
 public override void VisitUnaryOperatorExpression(IUnaryOperatorExpression operation)
 {
     Visit(operation.Operand);
 }
Example #13
0
 public virtual void VisitUnaryOperatorExpression(IUnaryOperatorExpression operation)
 {
     DefaultVisit(operation);
 }
Example #14
0
 public override IOperation VisitUnaryOperatorExpression(IUnaryOperatorExpression operation, object argument)
 {
     return(new UnaryOperatorExpression(operation.OperatorKind, Visit(operation.Operand), operation.IsLifted, operation.IsChecked, operation.UsesOperatorMethod, operation.OperatorMethod, ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit));
 }
Example #15
0
        public override void VisitUnaryOperatorExpression(IUnaryOperatorExpression operation)
        {
            var usesOperatorMethod = operation.UsesOperatorMethod;
            var operatorMethod = operation.OperatorMethod;
            var unaryOperationKind = operation.UnaryOperationKind;

            base.VisitUnaryOperatorExpression(operation);
        }
        /// <summary>
        /// Finds the matching nodes of a <see cref="IUnaryOperatorExpression"/>.
        /// </summary>
        /// <param name="node">The agent expression to check.</param>
        /// <param name="errorList">The list of errors found.</param>
        /// <param name="resolvedResult">The expression result types upon return.</param>
        /// <param name="resolvedException">Exceptions the expression can throw upon return.</param>
        /// <param name="constantSourceList">Sources of the constant expression upon return, if any.</param>
        /// <param name="expressionConstant">The constant value upon return, if any.</param>
        /// <param name="selectedFeature">The matching feature upon return.</param>
        /// <param name="selectedOverload">The matching overload in <paramref name="selectedFeature"/> upon return.</param>
        /// <param name="selectedOverloadType">The matching overload type upon return.</param>
        public static bool ResolveCompilerReferences(IUnaryOperatorExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant, out IFunctionFeature selectedFeature, out IQueryOverload selectedOverload, out IQueryOverloadType selectedOverloadType)
        {
            resolvedResult       = null;
            resolvedException    = null;
            constantSourceList   = new SealableList <IExpression>();
            expressionConstant   = NeutralLanguageConstant.NotConstant;
            selectedFeature      = null;
            selectedOverload     = null;
            selectedOverloadType = null;

            IIdentifier Operator        = (IIdentifier)node.Operator;
            string      ValidText       = Operator.ValidText.Item;
            IExpression RightExpression = (IExpression)node.RightExpression;
            IResultType RightResult     = RightExpression.ResolvedResult.Item;

            if (!RightResult.TryGetResult(out ICompiledType RightExpressionType))
            {
                errorList.AddError(new ErrorInvalidExpression(RightExpression));
                return(false);
            }

            if (RightExpressionType is IClassType AsClassType)
            {
                ISealableDictionary <IFeatureName, IFeatureInstance> RightFeatureTable = AsClassType.FeatureTable;

                if (!FeatureName.TableContain(RightFeatureTable, ValidText, out IFeatureName Key, out IFeatureInstance Value))
                {
                    errorList.AddError(new ErrorUnknownIdentifier(RightExpression, ValidText));
                    return(false);
                }

                ICompiledFeature OperatorFeature = Value.Feature;
                ICompiledType    OperatorType    = OperatorFeature.ResolvedAgentType.Item;

                if (OperatorFeature is IFunctionFeature AsFunctionFeature && OperatorType is IFunctionType AsFunctionType)
                {
                    IList <IQueryOverloadType> OperatorOverloadList = AsFunctionType.OverloadList;

                    int SelectedOperatorIndex = -1;
                    for (int i = 0; i < OperatorOverloadList.Count; i++)
                    {
                        IQueryOverloadType Overload = OperatorOverloadList[i];
                        if (Overload.ParameterList.Count == 0 && Overload.ResultList.Count == 1)
                        {
                            SelectedOperatorIndex = i;
                            break;
                        }
                    }

                    if (SelectedOperatorIndex < 0)
                    {
                        errorList.AddError(new ErrorInvalidOperator(Operator, ValidText));
                        return(false);
                    }

                    resolvedResult       = Feature.CommonResultType(AsFunctionType.OverloadList);
                    selectedFeature      = AsFunctionFeature;
                    selectedOverload     = AsFunctionFeature.OverloadList[SelectedOperatorIndex];
                    selectedOverloadType = OperatorOverloadList[SelectedOperatorIndex];
                    resolvedException    = new ResultException(selectedOverloadType.ExceptionIdentifierList);

                    constantSourceList.Add(RightExpression);
                }
                else
                {
                    errorList.AddError(new ErrorInvalidOperator(Operator, ValidText));
                    return(false);
                }
            }
 /// <summary>
 /// Get unary operand kind.
 /// </summary>
 public static UnaryOperandKind GetUnaryOperandKind(this IUnaryOperatorExpression unary)
 {
     return(GetUnaryOperandKind(unary.UnaryOperationKind));
 }
 /// <summary>
 /// Get unary operation kind independent of data type.
 /// </summary>
 public static SimpleUnaryOperationKind GetSimpleUnaryOperationKind(this IUnaryOperatorExpression unary)
 {
     return(GetSimpleUnaryOperationKind(unary.UnaryOperationKind));
 }
Example #19
0
 private static bool IsOperatorNot([NotNull] IUnaryOperatorExpression unaryOperator)
 {
     return(unaryOperator.UnaryOperationKind == UnaryOperationKind.BooleanLogicalNot);
 }
 public virtual void VisitUnaryOperatorExpression <TExpression>(IUnaryOperatorExpression <TExpression> unaryOperatorExpression)
     where TExpression : IExpression
 {
     Visit(unaryOperatorExpression);
 }
Example #21
0
 public virtual void VisitUnaryOperatorExpression(IUnaryOperatorExpression operation)
 {
     DefaultVisit(operation);
 }
 public override void VisitUnaryOperatorExpression <TExpression>(IUnaryOperatorExpression <TExpression> unaryOperatorExpression)
 {
     Steps.Add(new WriteUnaryOperatorExpressionType(unaryOperatorExpression.OperatorType));
     Steps.Add(new WriteExpression <TExpression>(unaryOperatorExpression.Operand));
 }