internal AssignmentExpression GenAssignmentExpression(IScope scope, Variable v, int maxDepth) { AssignmentOperator op = _options.AssignmentOperators.ChooseRandom(_rand); AssignmentExpression ae = new AssignmentExpression() { Operator = op }; if (op.Has(OperatorRequirement.NumericOnly)) { scope.Require(GlobalFunction.CALC); ae.DefaultValue = GenNumericLiteral(); } if (!op.Has(OperatorRequirement.WithoutRhs)) { Expression expr = GenExpression(scope, maxDepth); if (op.Has(OperatorRequirement.NumericOnly) && !expr.IsNumeric) { expr = new NumericExpression(scope, expr, GenNumericLiteral()); } if (op.Has(OperatorRequirement.RhsNonzero)) { expr = new NonZeroExpression(scope, expr); } ae.Rhs = expr; } ae.Variable = v; return(ae); }
/// <summary> /// Constructor to use when creating a RoslynDom from scratch /// </summary> /// <param name="left"> /// Expression to assign to /// </param> /// <param name="expression"> /// Expression to assign /// </param> /// <param name="op"> /// Assignment operator /// </param> public RDomAssignmentStatement(IExpression left, IExpression expression, AssignmentOperator op = AssignmentOperator.Equals) : base() { _left = left; _expression = expression; _operator = op; }
public static string JsText(this AssignmentOperator op) { switch (op) { case AssignmentOperator.Assign: return("="); case AssignmentOperator.PlusAssign: return("+="); case AssignmentOperator.MinusAssign: return("-="); case AssignmentOperator.TimesAssign: return("*="); case AssignmentOperator.DivideAssign: return("/="); case AssignmentOperator.ModuloAssign: return("%="); case AssignmentOperator.BitwiseAndAssign: return("&="); case AssignmentOperator.BitwiseOrAssign: return("|="); case AssignmentOperator.BitwiseXOrAssign: return("^="); case AssignmentOperator.LeftShiftAssign: return("<<="); case AssignmentOperator.RightShiftAssign: return(">>="); case AssignmentOperator.UnsignedRightShiftAssign: return(">>>="); default: throw new NotSupportedException(); } }
/// <summary> /// Creates a new assignment. /// /// <param name="left">left hand side</param> /// <param name="operator">assignment operator</param> /// <param name="right">right hand side</param> /// <param name="source_reference">reference to source code</param> /// <returns>newly created assignment</returns> /// </summary> public Assignment(Expression left, Expression right, AssignmentOperator Operator = AssignmentOperator.SIMPLE, SourceReference source_reference = null) { this.right = right; this.Operator = Operator; this.source_reference = source_reference; this.left = left; }
/// <summary> /// Builds a new <see cref="CodeNamespaceImport"/> object based /// on the settings of the current object. /// </summary> /// <param name="ns"> /// The namespace to build the new <see cref="CodeNamespaceImport"/> /// object. /// </param> /// <param name="alias"> /// The alias name to use when building the new <see cref="CodeNamespaceImport"/> /// object. /// </param> /// <returns> /// A new <see cref="CodeNamespaceImport"/> object. /// </returns> public virtual CodeNamespaceImport BuildNamespaceImport(string ns, string alias) { if (String.IsNullOrWhiteSpace(alias) || Order == NamespaceAliasOrder.None) { return(new CodeNamespaceImport(ns)); } const string assignment = "{0} {1} {2}"; string name = String.Empty; switch (Order) { case NamespaceAliasOrder.NamespaceFirst: name = String.Format(assignment, ns.Trim(), AssignmentOperator.Trim(), alias.Trim()); break; case NamespaceAliasOrder.AliasFirst: name = String.Format(assignment, alias.Trim(), AssignmentOperator.Trim(), ns.Trim()); break; } return(new CodeNamespaceImport(name)); }
public AssignmentExpression(string op, INode left, Expression right) { Type = Nodes.AssignmentExpression; Operator = AssignmentExpression.ParseAssignmentOperator(op); Left = left; Right = right; }
public AssignmentExpressionExecuter(AssignmentExpression expr) : base(expr) { identifier = expr.Left; identifierName = expr.Left.Name; right = Build(expr.Right); op = expr.Operator; }
public static string ToStatementString(this AssignmentOperator Operator) { switch (Operator) { case AssignmentOperator.Equals: return("="); case AssignmentOperator.PlusEquals: return("+="); case AssignmentOperator.MinusEquals: return("-="); case AssignmentOperator.MultEquals: return("*="); case AssignmentOperator.DivEquals: return("/="); case AssignmentOperator.none: return(""); default: throw new ApplicationException("unsupported enum " + Operator.ToString()); } }
public static string ConvertAssignmentOperatorToString(AssignmentOperator assignmentOperator) { if (!Enum.IsDefined(typeof(AssignmentOperator), assignmentOperator)) { throw new ArgumentException("Unsupported AssignmentOperator.", nameof(assignmentOperator)); } return(assignmentOperator.GetDescription()); }
public static SyntaxKind SyntaxTokenKindFromAssignmentOperator(AssignmentOperator op) { foreach (var tuple in assignmentOpMap) { if (tuple.Item3 == op) { return tuple.Item2; } } throw new InvalidOperationException(); }
/// <summary> /// Costructor of the assignment operation. /// </summary> /// <param name="rightOperand">TypeExpression to be assigned to the stored firstOperand operand.</param> /// <param name="op">Kind o</param> /// <param name="methodAnalyzed">The Actual Method Being Analysed</param> /// <param name="unification">Kind of unification to use: Equivalent, Incremental and Override.</param> /// <param name="actualImplicitObject">The actual "this" objet we are visiting.</param> /// <param name="location">The location (file, line, column) of text being analyzed.</param> public AssignmentOperation(TypeExpression rightOperand, AssignmentOperator op, MethodType methodAnalyzed, SortOfUnification unification, TypeExpression actualImplicitObject, Location location) { this.rightOperand = rightOperand; this.op = op; this.methodAnalyzed = methodAnalyzed; this.unification = unification; this.actualImplicitObject = actualImplicitObject; this.location = location; }
public AssignmentExpressionSyntax( ExpressionSyntax leftOperand, AssignmentOperator @operator, ExpressionSyntax rightOperand) : base(TextSpan.Covering(leftOperand.Span, rightOperand.Span)) { LeftOperand = leftOperand; RightOperand = rightOperand; Operator = @operator; }
public AssignmentExpression( string op, Expression left, Expression right) : base(Nodes.AssignmentExpression) { Operator = ParseAssignmentOperator(op); Left = left; Right = right; }
public AssignmentExpressionSyntax( IAssignableExpressionSyntax leftOperand, AssignmentOperator @operator, IExpressionSyntax rightOperand) : base(TextSpan.Covering(leftOperand.Span, rightOperand.Span)) { this.leftOperand = leftOperand; this.rightOperand = rightOperand; Operator = @operator; }
public static string ToSymbolString(this AssignmentOperator @operator) { return(@operator switch { AssignmentOperator.Simple => "=", AssignmentOperator.Plus => "+=", AssignmentOperator.Minus => "-=", AssignmentOperator.Asterisk => "*=", AssignmentOperator.Slash => "/=", _ => throw ExhaustiveMatch.Failed(@operator) });
/// <nodoc /> public AssignmentExpression(SymbolAtom leftExpression, int index, AssignmentOperator operatorKind, [NotNull] Expression rightExpression, LineInfo location) : base(location) { Contract.Requires(index >= 0); Contract.Requires(rightExpression != null); LeftExpression = leftExpression; OperatorKind = operatorKind; RightExpression = rightExpression; Index = index; }
public static string OperatorString(this AssignmentOperator op) { return(op switch { AssignmentOperator.Equals => "=", AssignmentOperator.Add => "+=", AssignmentOperator.Subtract => "-=", AssignmentOperator.Multiply => "*=", AssignmentOperator.Divide => "/=", _ => throw new NotImplementedException($"{op} not implemented") });
public static SyntaxKind SyntaxTokenKindFromAssignmentOperator(AssignmentOperator op) { foreach (var tuple in assignmentOpMap) { if (tuple.Item3 == op) { return(tuple.Item2); } } throw new InvalidOperationException(); }
public AssignmentExpression( TextSpan span, DataType dataType, ExpressionSemantics semantics, IAssignableExpression leftOperand, AssignmentOperator @operator, IExpression rightOperand) : base(span, dataType, semantics) { LeftOperand = leftOperand; Operator = @operator; RightOperand = rightOperand; }
/// <summary> /// Gets string representation. /// </summary> public static string ToDisplayString(this AssignmentOperator @operator) { switch (@operator) { case AssignmentOperator.Assignment: return("="); case AssignmentOperator.AdditionAssignment: return("+="); case AssignmentOperator.SubtractionAssignment: return("-="); case AssignmentOperator.MultiplicationAssignment: return("*="); case AssignmentOperator.RemainderAssignment: return("%="); case AssignmentOperator.ExponentiationAssignment: return("**="); case AssignmentOperator.LeftShiftAssignment: return("<<="); case AssignmentOperator.RightShiftAssignment: return(">>="); case AssignmentOperator.UnsignedRightShiftAssignment: return(">>>="); case AssignmentOperator.BitwiseAndAssignment: return("&="); case AssignmentOperator.BitwiseXorAssignment: return("^="); case AssignmentOperator.BitwiseOrAssignment: return("|="); default: Contract.Assert(false); throw new ArgumentOutOfRangeException(nameof(@operator), @operator, null); } }
public AssignmentExpression(AssignmentOperator op, Expression left, Expression right, Location location = null) : base(SyntaxNodeType.AssignmentExpression, location) { if (!FastEnumValidator <AssignmentOperator> .IsDefined((int)op)) { throw new ArgumentOutOfRangeException("op"); } if (left == null) { throw new ArgumentNullException("left"); } if (right == null) { throw new ArgumentNullException("right"); } Operator = op; Left = left; Right = right; }
/// <summary> /// Performs a calculation following the <paramref name="assignment"/> of the two specified values. /// </summary> /// <typeparam name="T">The type of the values for the operand operation.</typeparam> /// <param name="x">The value to calculate with <paramref name="y"/>.</param> /// <param name="assignment">One of the enumeration values that specifies the rules to apply for the assignment operator of <paramref name="x"/> and <paramref name="y"/>.</param> /// <param name="y">The value to calculate with <paramref name="x"/>.</param> /// <returns>The result of the <paramref name="assignment"/> for <paramref name="x"/> and <paramref name="y"/>.</returns> /// <exception cref="TypeArgumentException"> /// <typeparamref name="T"/> is outside the range of allowed types.<br/> /// Allowed types are: <see cref="Byte"/>, <see cref="Decimal"/>, <see cref="Double"/>, <see cref="Int16"/>, <see cref="Int32"/>, <see cref="Int64"/>, <see cref="SByte"/>, <see cref="Single"/>, <see cref="UInt16"/>, <see cref="UInt32"/> or <see cref="UInt64"/>. /// </exception> public static T Calculate <T>(T x, AssignmentOperator assignment, T y) where T : struct, IConvertible { switch (assignment) { case AssignmentOperator.Addition: return(Add(x, y)); case AssignmentOperator.And: return(And(x, y)); case AssignmentOperator.Assign: return(Assign(x, y)); case AssignmentOperator.Division: return(Divide(x, y)); case AssignmentOperator.ExclusiveOr: return(ExclusiveOr(x, y)); case AssignmentOperator.LeftShift: return(LeftShift(x, y)); case AssignmentOperator.Multiplication: return(Multiply(x, y)); case AssignmentOperator.Or: return(Or(x, y)); case AssignmentOperator.Remainder: return(Remainder(x, y)); case AssignmentOperator.RightShift: return(RightShift(x, y)); case AssignmentOperator.Subtraction: return(Subtract(x, y)); default: throw new ArgumentOutOfRangeException(nameof(assignment)); } }
/// <summary>Gets an assignment operation.</summary> public virtual IAssignmentOperation GetOperation(AssignmentOperator op, CodeType value) { CodeType current = _type; while (current != null) { if (current.Operations != null) { foreach (IAssignmentOperation operation in current.Operations._assignmentOperations) { if (operation.Operator == op && value != null && value.Implements(operation.ValueType)) { return(operation); } } } current = current.Extends; } return(null); }
public override void ExitVarAssign([NotNull] PigeonParser.VarAssignContext context) { var varName = context.ID().GetText(); var varType = Types.Get(context.expr()); if (scope.TryGetVariable(varName, out var variable)) { if (variable.ReadOnly) { errorBag.ReportRedefiningReadOnlyVariable(context.GetTextSpan(), varName); } if (!AssignmentOperator.IsAssignable(context.op.Text, variable.Type, varType)) { errorBag.ReportInvalidTypeAssignment(context.GetTextSpan(), varName, variable.Type, varType); } } else { errorBag.ReportUndeclaredVariable(context.GetTextSpan(), varName); } }
/// <summary> /// Converts from operator to string /// </summary> /// <param name="assignmentOperator"> /// The assignment operator. /// </param> /// <returns> /// A string representation of an assignment operator /// </returns> public static string ConvertToString(this AssignmentOperator assignmentOperator) { switch (assignmentOperator) { case AssignmentOperator.Default: return("="); case AssignmentOperator.Addition: return("+="); case AssignmentOperator.Subtraction: return("-="); case AssignmentOperator.Multiplication: return("*="); case AssignmentOperator.Division: return("/="); case AssignmentOperator.Modulo: return("%="); case AssignmentOperator.BitwiseAnd: return("&="); case AssignmentOperator.BitwiseOr: return("|="); case AssignmentOperator.BitwiseXor: return("^="); case AssignmentOperator.BitwiseShiftLeft: return("<<="); case AssignmentOperator.BitwiseShiftRight: return(">>="); } return(string.Empty); }
public static string ToSymbolString(this AssignmentOperator @operator) { switch (@operator) { case AssignmentOperator.Direct: return("="); case AssignmentOperator.Plus: return("+="); case AssignmentOperator.Minus: return("-="); case AssignmentOperator.Asterisk: return("*="); case AssignmentOperator.Slash: return("/="); default: throw NonExhaustiveMatchException.For(@operator); } }
private static BinaryExpressionOperator AssignmentToBinary(AssignmentOperator pOp) { switch (pOp) { case AssignmentOperator.AdditionEquals: return(BinaryExpressionOperator.Addition); case AssignmentOperator.ConcatEquals: throw new NotSupportedException(); case AssignmentOperator.DivisionEquals: return(BinaryExpressionOperator.Division); case AssignmentOperator.MultiplyEquals: return(BinaryExpressionOperator.Multiplication); case AssignmentOperator.SubtractionEquals: return(BinaryExpressionOperator.Subtraction); default: throw new NotSupportedException("Assignment operator does not map to binary operator " + pOp.ToString()); } }
public SetVariableAction(ParseInfo parseInfo, Scope scope, Assignment assignmentContext) { // Get the variable expression. IExpression variableExpression = parseInfo.GetExpression(scope, assignmentContext.VariableExpression); // Extract the variable data. _variableResolve = new VariableResolve(parseInfo, new VariableResolveOptions() { ShouldBeSettable = true }, variableExpression, assignmentContext.VariableExpression.Range); // Get the value. _value = parseInfo.SetExpectType(_variableResolve.SetVariable?.Type()).GetExpression(scope, assignmentContext.Value); // Get the operation. Token assignmentToken = assignmentContext.AssignmentToken; CodeType variableType = variableExpression.Type(), valueType = _value.Type(); AssignmentOperator op = AssignmentOperation.OperatorFromTokenType(assignmentToken.TokenType); _operation = variableType.Operations.GetOperation(op, valueType); // No operators exist for the variable and value pair. if (_operation == null) { // If the variable type is any, use default operation. if (assignmentToken.TokenType == TokenType.Equal && variableType.Operations.DefaultAssignment && TypeComparison.IsAny(parseInfo.Types, variableType)) { _operation = new AssignmentOperation(op, parseInfo.Types.Any()); } // Otherwise, add an error. else { parseInfo.Script.Diagnostics.Error("Operator '" + assignmentToken.Text + "' cannot be applied to the types '" + variableType.GetNameOrAny() + "' and '" + valueType.GetNameOrAny() + "'.", assignmentToken.Range); } } }
public static bool Match(this AssignmentOperator a, AssignmentOperator b) { return a == AssignmentOperator.Any || b == AssignmentOperator.Any || a == b; }
private string TranslateAssignmentOperator(AssignmentOperator op) { switch (op) { case AssignmentOperator.Assign: return "="; case AssignmentOperator.PlusAssign: return "+="; case AssignmentOperator.MinusAssign: return "-="; case AssignmentOperator.BitwiseOrAssign: return "|="; case AssignmentOperator.BitwiseAndAssign: return "&="; case AssignmentOperator.BitwiseXOrAssign: return "^="; case AssignmentOperator.UnsignedRightShiftAssign: return ">>>="; case AssignmentOperator.LeftShiftAssign: return "<<="; case AssignmentOperator.RightShiftAssign: return ">>="; case AssignmentOperator.ModuloAssign: return "%="; default: throw new NotImplementedException("TODO: operator " + op + " is not supported."); } }
public IExpression MakeAssignmentExpression(IExpression left, IExpression right, AssignmentOperator operation) { return MakeAssignmentExpressionInternal((Expression)left, (Expression)right, operation); }
public bool IsAssignmentOperator(AssignmentOperator op) => _assignmentOperations.Any(assignmentOp => op == assignmentOp.Operator);
public override INode VisitAssignmentOperator(AssignmentOperator assignmentOperator) { return(new AssignmentOperator(assignmentOperator.Context, assignmentOperator.Value)); }
public AssignmentSyntax BuildAssignment(AssignmentOperator operation, ExpressionSyntax left, ExpressionSyntax right) { return new AssignmentSyntax(operation, left, right); }
private Expression MakeAssignmentExpressionInternal(Expression left, Expression right, AssignmentOperator operation) { Expression value = null; switch (operation) { case AssignmentOperator.Equal: value = right; break; case AssignmentOperator.Multiply: value = MakeMultiplyExpressionInternal(left, right); break; case AssignmentOperator.Divide: value = MakeDivideExpressionInternal(left, right); break; case AssignmentOperator.Remainder: value = MakeRemainderExpressionInternal(left, right); break; case AssignmentOperator.Addition: value = MakeAdditionExpressionInternal(left, right); break; case AssignmentOperator.Subtraction: value = MakeSubtractionExpressionInternal(left, right); break; case AssignmentOperator.LeftShift: value = MakeLeftShiftExpressionInternal(left, right); break; case AssignmentOperator.RightShift: value = MakeRightShiftExpressionInternal(left, right); break; case AssignmentOperator.UnsignedRightShift: value = MakeUnsignedRightShiftExpressionInternal(left, right); break; case AssignmentOperator.BitwiseAnd: value = MakeBitwiseAndExpressionInternal(left, right); break; case AssignmentOperator.BitwiseXor: value = MakeBitwiseXorExpressionInternal(left, right); break; case AssignmentOperator.BitwiseOr: value = MakeBitwiseOrExpressionInternal(left, right); break; } Expression targetExp = GetEquivalent(left); var id = targetExp as ReadIdentifierExpression; Expression result; if (id != null) { result = MakeWriteIdentifierExpression(id.Symbol, value); } else { var indexer = targetExp as ReadIndexerExpression; if (indexer != null) { var container = indexer.Container; var index = indexer.Index; if (indexer.User == null) { //we are going to throw this away soon! container.RemoveUser(indexer); index.RemoveUser(indexer); } result = MakeWriteIndexerExpression(container, index, value); } else { //this is a runtime error! result = MakeCommaOperatorExpression(new List<Expression> { left, right, MakeInternalCall(CodeGen.Types.Operations.Error.ReferenceError, null)}); } } return result; }
public static string OperatorToString(AssignmentOperator @operator) { string operatorString; if (!AssignmentOperatorMapping.TryGetValue(@operator, out operatorString)) throw new ArgumentException("Operator does not exist in the Visual Basic language."); return operatorString; }
/// <summary> /// Initializes a new instance of the <see cref="AssignmentExpression"/> class. /// </summary> /// <param name="operator">The @operator.</param> /// <param name="target">The target.</param> /// <param name="value">The value.</param> public AssignmentExpression(AssignmentOperator @operator, Expression target, Expression value) { Operator = @operator; Target = target; Value = value; }
public static Value EvaluateArthmeticAssignment(Value varValue, Value exprValue, AssignmentOperator assignment) { string operation; if ((operation = assignment.GetOperation()) is null) { return(null); } else { return(EvaluateByString(varValue, exprValue, operation)); } }