Esempio n. 1
0
        public ForStatement(IStatement[] preLoopAssignment, EvaluationStatement condition, IStatement[] afterLoopEvaluations, IStatement statement, StatementInfo info)
            : base(condition, statement, info)
        {
            PreLoopAssignment    = preLoopAssignment;
            AfterLoopEvaluations = afterLoopEvaluations;

            var children = new List <IStatement>();

            if (preLoopAssignment != null)
            {
                children.AddRange(preLoopAssignment);
            }
            if (condition != null)
            {
                children.Add(condition);
            }
            if (afterLoopEvaluations != null)
            {
                children.AddRange(afterLoopEvaluations);
            }
            if (statement != null)
            {
                children.Add(statement);
            }

            TraversableChildren = children.ToArray();
        }
Esempio n. 2
0
 public ArrayStatement(TypeDescriptor type, EvaluationStatement length, EvaluationStatement[] elements, StatementInfo info)
 {
     Info     = info;
     Type     = type;
     Length   = length;
     Elements = elements;
 }
 public static BitwiseEvaluationStatement CreateNot(BitwiseNotOperator op, EvaluationStatement operand,
                                                    StatementInfo info, IStatement parentStatement = null)
 {
     return(new BitwiseEvaluationStatement(null, op, operand, info)
     {
         ParentStatement = parentStatement
     });
 }
Esempio n. 4
0
 public static ArithmeticEvaluationStatement CreatePrefixDecrement(DecrementOperator op,
                                                                   EvaluationStatement operand, StatementInfo info, IStatement parentStatement = null)
 {
     return(new ArithmeticEvaluationStatement(true, null, op, operand, info)
     {
         ParentStatement = parentStatement
     });
 }
Esempio n. 5
0
 public static ArithmeticEvaluationStatement CreateNegate(NegativeNumberOperator op,
                                                          EvaluationStatement operand, StatementInfo info, IStatement parentStatement = null)
 {
     return(new ArithmeticEvaluationStatement(null, op, operand, info)
     {
         ParentStatement = parentStatement
     });
 }
Esempio n. 6
0
 public static ArithmeticEvaluationStatement CreatePostfix(ArithmeticOperator op,
                                                           EvaluationStatement operand, StatementInfo info, IStatement parentStatement = null)
 {
     return(new ArithmeticEvaluationStatement(operand, op, null, info)
     {
         ParentStatement = parentStatement
     });
 }
Esempio n. 7
0
        public TypeCastStatement(TypeDescriptor typeDescriptor, EvaluationStatement target, StatementInfo info, IStatement parentStatement)
        {
            TypeDescriptor = typeDescriptor;
            Target         = target;
            Info           = info;

            ParentStatement = parentStatement;
        }
        public SwitchCaseStatement(EvaluationStatement switchTarget, ConditionalBlockStatement[] cases, StatementInfo info)
        {
            SwitchTarget = switchTarget;
            Cases        = cases;
            Info         = info;

            TraversableChildren = StatementHelpers.CreateChildren(new IStatement[] { switchTarget }.Union(cases).ToArray());
            Branches            = cases.Select(x => x.Statement).ToArray();
        }
Esempio n. 9
0
 public VariableDefinitionStatement(
     TypeDescriptor typeDescriptor,
     string name,
     bool isConstant,
     EvaluationStatement value,
     StatementInfo info)
     : base(typeDescriptor, name, value, value != null, info)
 {
     IsConstant = isConstant;
 }
Esempio n. 10
0
        public DefinitionStatement(TypeDescriptor typeDescriptor, string name, EvaluationStatement defaultValue,
                                   bool hasDefaultValue, StatementInfo info)
        {
            TypeDescriptor  = typeDescriptor;
            Name            = name;
            DefaultValue    = defaultValue;
            HasDefaultValue = hasDefaultValue;
            Info            = info;

            TraversableChildren = StatementHelpers.CreateChildren(defaultValue);
        }
        public BitwiseEvaluationStatement(EvaluationStatement left, BitwiseOperator @operator,
                                          EvaluationStatement right, StatementInfo info, IStatement parentStatement = null)
        {
            Left            = left;
            Operator        = @operator;
            Right           = right;
            Info            = info;
            ParentStatement = parentStatement;

            TraversableChildren = StatementHelpers.CreateChildren(left, @operator, right);
        }
Esempio n. 12
0
        public ArithmeticEvaluationStatement(EvaluationStatement left, ArithmeticOperator @operator,
                                             EvaluationStatement right, StatementInfo info, IStatement parentStatement = null)
        {
            CanBeEmbedded   = false;
            Left            = left;
            Operator        = @operator;
            Right           = right;
            Info            = info;
            ParentStatement = parentStatement;

            TraversableChildren = StatementHelpers.CreateChildren(left, @operator, right);
        }
Esempio n. 13
0
        public static TypeDescriptor GetDataType(this EvaluationStatement evaluationStatement, Context context,
                                                 Scope scope)
        {
            switch (evaluationStatement)
            {
            case ConstantValueStatement constantValueStatement:
            {
                return(constantValueStatement.TypeDescriptor);
            }

            case VariableAccessStatement variableAccessStatement:
            {
                if (scope.TryGetVariableInfo(variableAccessStatement, out var variableInfo))
                {
                    return(variableInfo.TypeDescriptor);
                }

                if (scope.TryGetConstantInfo(variableAccessStatement, out var constantInfo))
                {
                    return(constantInfo.TypeDescriptor);
                }

                if (scope.TryGetPrototypeInfo(variableAccessStatement, out var functionInfo) ||
                    scope.TryGetFunctionInfo(variableAccessStatement, out functionInfo))
                {
                    return(new TypeDescriptor(DataTypes.Delegate,
                                              new TypeDescriptor.LookupInfo(functionInfo.ClassName, functionInfo.Name)));
                }

                throw new IdentifierNotFoundCompilerException(variableAccessStatement.VariableName,
                                                              variableAccessStatement.Info);
            }

            case FunctionCallStatement functionCallStatement:
            {
                var funcInfo = FunctionStatementTranspilerBase.GetFunctionInfoFromFunctionCall(context, scope,
                                                                                               functionCallStatement, out var sourceObjectInfo);

                if (funcInfo == null)
                {
                    throw new IdentifierNotFoundCompilerException(functionCallStatement.FunctionName,
                                                                  functionCallStatement.Info);
                }

                return(funcInfo.TypeDescriptor);
            }

            case BitwiseEvaluationStatement bitwiseEvaluationStatement:
            {
                switch (bitwiseEvaluationStatement.Operator)
                {
                case BitwiseNotOperator _:
                {
                    return(bitwiseEvaluationStatement.Right.GetDataType(context, scope));
                }

                case BitwiseAndOperator _:
                case BitwiseOrOperator _:
                case XorOperator _:
                {
                    return(OperateDataTypes(
                               bitwiseEvaluationStatement.Operator,
                               bitwiseEvaluationStatement.Left.GetDataType(context, scope),
                               bitwiseEvaluationStatement.Right.GetDataType(context, scope)
                               ));
                }
                }

                return(TypeDescriptor.Numeric);
            }

            case LogicalEvaluationStatement _:     //logicalEvaluationStatement
            {
                return(TypeDescriptor.Boolean);
            }

            case ArithmeticEvaluationStatement arithmeticEvaluationStatement:
            {
                switch (arithmeticEvaluationStatement.Operator)
                {
                case IncrementOperator _:
                case DecrementOperator _:
                case NegativeNumberOperator _:
                {
                    return((arithmeticEvaluationStatement.Right ?? arithmeticEvaluationStatement.Left)
                           .GetDataType(context, scope));
                }

                case AdditionOperator _:
                case SubtractionOperator _:
                case MultiplicationOperator _:
                case DivisionOperator _:
                //case ReminderOperator _:
                case ModulusOperator _:
                {
                    return(OperateDataTypes(
                               arithmeticEvaluationStatement.Operator,
                               arithmeticEvaluationStatement.Left.GetDataType(context, scope),
                               arithmeticEvaluationStatement.Right.GetDataType(context, scope)
                               ));
                }
                }

                return(TypeDescriptor.Numeric);
            }

            case AssignmentStatement assignmentStatement:
            {
                return(assignmentStatement.LeftSide.GetDataType(context, scope));
            }

            case TypeCastStatement typeCastStatement:
            {
                return(typeCastStatement.TypeDescriptor);
            }

            case IndexerAccessStatement indexerAccessStatement:
            {
                var type = indexerAccessStatement.Source.GetDataType(context, scope);
                if (!type.IsArray())
                {
                    throw new InvalidStatementStructureCompilerException(indexerAccessStatement,
                                                                         indexerAccessStatement.Info);
                }

                //NOTE: multi-dimensional arrays is not supported.
                return(type ^ DataTypes.Array);
            }

            case ArrayStatement arrayStatement:
            {
                return(arrayStatement.Type);
            }

            default:
                throw new InvalidOperationException();
            }
        }
Esempio n. 14
0
 public TypeCastStatement(TypeDescriptor typeDescriptor, EvaluationStatement target, StatementInfo info)
 {
     TypeDescriptor = typeDescriptor;
     Target         = target;
     Info           = info;
 }