Exemplo n.º 1
0
        private static void InitializeGlobalOperators(SimpleScope scope)
        {
            // Initialize numeric types
            foreach (var type in new[] { BuiltinType.Byte, BuiltinType.Integer, BuiltinType.UnsignedInteger, BuiltinType.Real })
            {
                scope.AddOperator(PsiOperator.Plus, FunctionType.CreateUnaryOperator(type));
                scope.AddOperator(PsiOperator.Minus, FunctionType.CreateUnaryOperator(type));

                scope.AddOperator(PsiOperator.Plus, FunctionType.CreateBinaryOperator(type));
                scope.AddOperator(PsiOperator.Minus, FunctionType.CreateBinaryOperator(type));
                scope.AddOperator(PsiOperator.Multiply, FunctionType.CreateBinaryOperator(type));
                scope.AddOperator(PsiOperator.Divide, FunctionType.CreateBinaryOperator(type));
                scope.AddOperator(PsiOperator.Modulo, FunctionType.CreateBinaryOperator(type));

                scope.AddOperator(PsiOperator.Equals, FunctionType.CreateBinaryOperator(BuiltinType.Boolean, type));
                scope.AddOperator(PsiOperator.NotEquals, FunctionType.CreateBinaryOperator(BuiltinType.Boolean, type));
                scope.AddOperator(PsiOperator.Less, FunctionType.CreateBinaryOperator(BuiltinType.Boolean, type));
                scope.AddOperator(PsiOperator.LessOrEqual, FunctionType.CreateBinaryOperator(BuiltinType.Boolean, type));
                scope.AddOperator(PsiOperator.More, FunctionType.CreateBinaryOperator(BuiltinType.Boolean, type));
                scope.AddOperator(PsiOperator.MoreOrEqual, FunctionType.CreateBinaryOperator(BuiltinType.Boolean, type));
            }

            // Initialize integral types
            foreach (var type in new[] { BuiltinType.Byte, BuiltinType.Integer, BuiltinType.UnsignedInteger })
            {
                scope.AddOperator(PsiOperator.Invert, FunctionType.CreateUnaryOperator(type));

                scope.AddOperator(PsiOperator.And, FunctionType.CreateBinaryOperator(type));
                scope.AddOperator(PsiOperator.Or, FunctionType.CreateBinaryOperator(type));
                scope.AddOperator(PsiOperator.Xor, FunctionType.CreateBinaryOperator(type));
                scope.AddOperator(PsiOperator.ShiftRight, FunctionType.CreateBinaryOperator(type));
                scope.AddOperator(PsiOperator.ArithmeticShiftRight, FunctionType.CreateBinaryOperator(type));
            }

            // Initialize real type
            {
                scope.AddOperator(PsiOperator.Exponentiate, FunctionType.CreateBinaryOperator(BuiltinType.Real));
            }

            // Initialize boolean type
            {
                scope.AddOperator(PsiOperator.Invert, FunctionType.CreateUnaryOperator(BuiltinType.Boolean));
                scope.AddOperator(PsiOperator.And, FunctionType.CreateBinaryOperator(BuiltinType.Boolean));
                scope.AddOperator(PsiOperator.Or, FunctionType.CreateBinaryOperator(BuiltinType.Boolean));
                scope.AddOperator(PsiOperator.Xor, FunctionType.CreateBinaryOperator(BuiltinType.Boolean));
            }
        }