Example #1
0
        // AssignOperator

        /// <summary>
        /// Creates a compiler warning if the specified assignment operator cannot be used with the specified data type.
        /// </summary>
        /// <param name="operator">The assignment operator.</param>
        /// <param name="type">The target data type.</param>
        /// <param name="context">The translation context.</param>
        /// <param name="filename">The current file name.</param>
        /// <param name="errorToken">The token to report errors at.</param>
        public static void TestCompatible(this AssignOperator @operator, DataType type, TranslationContext context, string filename, IToken errorToken)
        {
            switch (@operator)
            {
            case AssignOperator.Equals:
                return;

            case AssignOperator.AddEquals:
            case AssignOperator.MinusEquals:
            case AssignOperator.PlusPlus:
            case AssignOperator.MinusMinus:

                if (!DataType.Number.IsCompatible(type))
                {
                    context.ErrorList.Add(new CompilerError(
                                              $"Cannot use operator '{@operator}' on a value of type '{type}'",
                                              ErrorType.TypeMismatch, errorToken, filename));
                }
                return;

            case AssignOperator.DotEquals:

                if (!DataType.String.IsCompatible(type))
                {
                    context.ErrorList.Add(new CompilerError(
                                              $"Cannot use operator '{@operator}' on a value of type '{type}'",
                                              ErrorType.TypeMismatch, errorToken, filename));
                }
                return;

            default:
                throw new ArgumentOutOfRangeException(nameof(@operator), @operator, null);
            }
        }
 static String getDisplayName(AssignOperator operator) {
     switch (operator) {
     case Add:
         return "+=";
     case And:
         return "&=";
     case Divide:
         return "/=";
     case LeftShift:
         return "<<=";
     case Modulo:
         return "%=";
     case Multiply:
         return "*=";
     case Or:
         return "|=";
     case RightShift:
         return ">>=";
     case Subtract:
         return "-=";
     case UnsignedRightShift:
         return ">>>=";
     case Xor:
         return "^=";
     default:
         throw new IllegalStateException();
     }
 }
Example #3
0
 /// <summary>
 /// Creates a new instance of the <see cref="VarAssignStmt"/> class.
 /// </summary>
 /// <param name="variableName">The name of the variable being assigned.</param>
 /// <param name="operator">The operator to use for the assignment.</param>
 /// <param name="value">The input to the assignment operator.</param>
 /// <param name="fileName">The name of the file.</param>
 /// <param name="errorToken">The token to report any compiler errors to.</param>
 public VarAssignStmt(string variableName, AssignOperator @operator, string fileName, IToken errorToken,
                      IExpression value = null)
 {
     Operator     = @operator;
     FileName     = fileName;
     ErrorToken   = errorToken;
     VariableName = variableName;
     Value        = value;
 }
Example #4
0
 /// <summary>
 /// Creates a new instance of the <see cref="ArrayAssignStmt"/> class.
 /// </summary>
 /// <param name="arrayName">The name of the array of the element being assigned.</param>
 /// <param name="index">The index of the element being assigned.</param>
 /// <param name="operator">The operator to use for the assignment.</param>
 /// <param name="value">The input to the assignment operator.</param>
 /// <param name="fileName">The name of the file.</param>
 /// <param name="errorToken">The token to report any compiler errors to.</param>
 public ArrayAssignStmt(string arrayName, IExpression index, AssignOperator @operator, IExpression value,
                        string fileName, IToken errorToken)
 {
     Operator   = @operator;
     Index      = index;
     ArrayName  = arrayName;
     Value      = value;
     FileName   = fileName;
     ErrorToken = errorToken;
 }
Example #5
0
 public AssignConstantCompiler(Compiler compiler, AssignOperator operatorCompiler)
     : base(compiler, operatorCompiler)
 {
 }
Example #6
0
 public ValueDefineCommand(int index, IExpr expr)
 {
     this.expr = new AssignOperator(new Value(index), expr);
 }
Example #7
0
 protected AssignCompiler(Compiler compiler, AssignOperator operatorCompiler) : base(compiler)
 {
     this.operatorCompiler = operatorCompiler;
 }
 public AssignInstanceVariableCompiler(Compiler compiler, AssignOperator operatorCompiler)
     : base(compiler, operatorCompiler)
 {
 }