Exemple #1
0
 void ILSLSyntaxErrorListener.TypeMismatchInVariableDeclaration(LSLSourceCodeRange location, LSLType variableType,
                                                                ILSLReadOnlyExprNode assignedExpression)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.TypeMismatchInVariableDeclaration(location, variableType, assignedExpression));
 }
Exemple #2
0
 void ILSLSyntaxErrorListener.InvalidTupleComponentAccessOperation(LSLSourceCodeRange location,
                                                                   ILSLReadOnlyExprNode exprLvalue,
                                                                   string memberAccessed)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () => SyntaxErrorListener.InvalidTupleComponentAccessOperation(location, exprLvalue, memberAccessed));
 }
Exemple #3
0
 void ILSLSyntaxErrorListener.InvalidBinaryOperation(LSLSourceCodeRange location, ILSLReadOnlyExprNode left,
                                                     string operation,
                                                     ILSLReadOnlyExprNode right)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () => SyntaxErrorListener.InvalidBinaryOperation(location, left, operation, right));
 }
Exemple #4
0
        /// <summary>
        ///     Validates that an expression can be passed into the parameter slot of a function.
        ///     IE: That the passed expression matches up with or can be converted to the parameter type.
        /// </summary>
        /// <param name="parameterSignature">The parameter definition.</param>
        /// <param name="parameterExpressionPassed">The expression the user has attempting to pass into the parameter.</param>
        /// <returns><c>true</c> if <paramref name="parameterExpressionPassed"/> can be passed to the given parameter signature.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="parameterSignature"/> or <paramref name="parameterExpressionPassed"/> is <c>null</c>.</exception>
        public bool ValidateFunctionParameter(
            LSLParameterSignature parameterSignature,
            ILSLReadOnlyExprNode parameterExpressionPassed)
        {
            if (parameterSignature == null)
            {
                throw new ArgumentNullException("parameterSignature");
            }
            if (parameterExpressionPassed == null)
            {
                throw new ArgumentNullException("parameterExpressionPassed");
            }

            if (parameterExpressionPassed.HasErrors)
            {
                return(false);
            }

            if (parameterSignature.Variadic && parameterSignature.Type == LSLType.Void)
            {
                return(true);
            }


            var left = new LSLDummyExpr
            {
                Type           = parameterSignature.Type,
                ExpressionType = LSLExpressionType.ParameterVariable
            };


            return
                (ValidateBinaryOperation(left, LSLBinaryOperationType.Assign,
                                         parameterExpressionPassed).IsValid);
        }
        public static bool IsNegated(this ILSLReadOnlyExprNode node)
        {
            var parentAsPrefixOperator = node.Parent as ILSLPrefixOperationNode;

            return(parentAsPrefixOperator != null &&
                   parentAsPrefixOperator.Operation == LSLPrefixOperationType.Negate);
        }
 /// <summary>
 ///     Occurs when a return value inside of an event handler returns an expression instead of nothing.  <para/>
 ///     The return value of the expression is simply discarded in this case.
 /// </summary>
 /// <param name="location">The location.</param>
 /// <param name="eventSignature">The signature of the event handler this warning occurred in.</param>
 /// <param name="returnExpression">The return expression.</param>
 public virtual void ReturnedValueFromEventHandler(LSLSourceCodeRange location, ILSLEventSignature eventSignature,
                                                   ILSLReadOnlyExprNode returnExpression)
 {
     OnWarning(location,
               string.Format(
                   "Return statement in event handler \"{0}\" returns a value that will be discarded.",
                   eventSignature.Name));
 }
Exemple #7
0
 void ILSLSyntaxWarningListener.ConditionalExpressionIsConstant(LSLSourceCodeRange location,
                                                                ILSLReadOnlyExprNode expression,
                                                                LSLConditionalStatementType conditionalStatementType)
 {
     _warningActionQueue.Enqueue(location.StartIndex,
                                 () =>
                                 SyntaxWarningListener.ConditionalExpressionIsConstant(location, expression, conditionalStatementType));
 }
Exemple #8
0
 void ILSLSyntaxWarningListener.ForLoopInitExpressionHasNoEffect(LSLSourceCodeRange location,
                                                                 ILSLReadOnlyExprNode expression, int expressionIndex,
                                                                 int expressionCountTotal)
 {
     _warningActionQueue.Enqueue(location.StartIndex,
                                 () =>
                                 SyntaxWarningListener.ForLoopInitExpressionHasNoEffect(location, expression, expressionIndex,
                                                                                        expressionCountTotal));
 }
        /// <summary>
        ///     Determines if an expression node represents a function call to a user defined function.
        /// </summary>
        /// <param name="node">The expression node to test.</param>
        /// <returns>True if the expression node represents a function call to a user defined function.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="node"/> is <c>null</c>.</exception>
        public static bool IsUserFunctionCall(this ILSLReadOnlyExprNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            return(node.ExpressionType == LSLExpressionType.UserFunction);
        }
Exemple #10
0
        /// <summary>
        ///     Determines if an expression can be used to initialize a rotation literal
        /// </summary>
        /// <param name="type">The type of expression that is attempting to be used.</param>
        /// <returns>True if the expression can be inside of a rotation literal.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="type"/> is <c>null</c>.</exception>
        public bool ValidateRotationContent(ILSLReadOnlyExprNode type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            return(!type.HasErrors && (type.Type == LSLType.Float || type.Type == LSLType.Integer));
        }
Exemple #11
0
 void ILSLSyntaxErrorListener.TypeMismatchInReturnValue(LSLSourceCodeRange location,
                                                        ILSLFunctionSignature functionSignature,
                                                        ILSLReadOnlyExprNode attemptedReturnExpression)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.TypeMismatchInReturnValue(location, functionSignature,
                                                                             attemptedReturnExpression));
 }
        /// <summary>
        ///     Determines if the expression node represents a code literal.  Such as a string, vector, rotation or list literal.
        /// </summary>
        /// <param name="node">The expression node to test.</param>
        /// <returns>True if the expression node represents a code literal.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="node"/> is <c>null</c>.</exception>
        public static bool IsLiteral(this ILSLReadOnlyExprNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            return(node.ExpressionType == LSLExpressionType.Literal);
        }
        /// <summary>
        ///     Determines if an expression node represents a reference to a global variable.
        /// </summary>
        /// <param name="node">The expression node to test.</param>
        /// <returns>True if the expression node represents a reference to a global variable.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="node"/> is <c>null</c>.</exception>
        public static bool IsGlobalVariable(this ILSLReadOnlyExprNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            return
                (node.ExpressionType == LSLExpressionType.GlobalVariable);
        }
Exemple #14
0
        /// <summary>
        ///     Determines if an expression can be used to initialize a list literal
        /// </summary>
        /// <param name="type">The type of expression that is attempting to be used.</param>
        /// <returns>True if the expression can be inside of a list literal.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="type"/> is <c>null</c>.</exception>
        public bool ValidateListContent(ILSLReadOnlyExprNode type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            //check for void required, we do not want functions returning void in a list
            return(!type.HasErrors && type.Type != LSLType.List && type.Type != LSLType.Void);
        }
        /// <summary>
        ///     Determines whether the expression is a reference to a vector or rotation component, using the dot operator.
        /// </summary>
        /// <param name="node">The expression node to test.</param>
        /// <returns>
        ///     True if the expression node represents a reference to a vector or rotation variable component via the dot
        ///     operator.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="node"/> is <c>null</c>.</exception>
        public static bool IsVectorOrRotationComponent(this ILSLReadOnlyExprNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            return(node.ExpressionType == LSLExpressionType.VectorComponentAccess ||
                   node.ExpressionType == LSLExpressionType.RotationComponentAccess);
        }
        /// <summary>
        ///     Determines if an expression node represents a reference to a local parameter.
        /// </summary>
        /// <param name="node">The expression node to test.</param>
        /// <returns>True if the expression node represents a reference to a local parameter.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="node"/> is <c>null</c>.</exception>
        public static bool IsLocalParameter(this ILSLReadOnlyExprNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            return
                (node.ExpressionType == LSLExpressionType.ParameterVariable);
        }
Exemple #17
0
        /// <summary>
        ///     Validates and returns the type resulting from a binary operation.
        /// </summary>
        /// <param name="left">The expression to on the left of the binary operation.</param>
        /// <param name="operation">The binary operation to preform.</param>
        /// <param name="right">The expression to on the right of the binary operation.</param>
        /// <returns>An <see cref="LSLExpressionValidatorResult" /> object</returns>
        /// <exception cref="ArgumentNullException"><paramref name="left"/> or <paramref name="right"/> is <c>null</c>.</exception>
        public LSLExpressionValidatorResult ValidateBinaryOperation(ILSLReadOnlyExprNode left, LSLBinaryOperationType operation,
                                                                    ILSLReadOnlyExprNode right)
        {
            if (left == null)
            {
                throw new ArgumentNullException("left");
            }
            if (right == null)
            {
                throw new ArgumentNullException("right");
            }

            if (left.HasErrors || right.HasErrors)
            {
                return(LSLExpressionValidatorResult.Error);
            }


            if (left.Type == LSLType.List && operation == LSLBinaryOperationType.AddAssign)
            {
                return(LSLExpressionValidatorResult.List);
            }


            if (left.Type == LSLType.List || right.Type == LSLType.List)
            {
                if (operation == LSLBinaryOperationType.Add)
                {
                    return(LSLExpressionValidatorResult.List);
                }
            }


            if (left.Type == LSLType.List && right.Type == LSLType.List)
            {
                if (operation == LSLBinaryOperationType.Equals || operation == LSLBinaryOperationType.NotEquals)
                {
                    return(LSLExpressionValidatorResult.Integer);
                }
                if (operation == LSLBinaryOperationType.Assign)
                {
                    return(LSLExpressionValidatorResult.List);
                }
            }


            LSLType t;

            if (_operations.TryGetValue(left.Type + operation.ToOperatorString() + right.Type, out t))
            {
                return(new LSLExpressionValidatorResult(t, true));
            }

            return(new LSLExpressionValidatorResult(t, false));
        }
Exemple #18
0
        /// <summary>
        ///     Validates that an expression of some type can be returned from a function given the
        ///     functions return type.
        /// </summary>
        /// <param name="returnType">The return type of the function the expression is being returned from.</param>
        /// <param name="returnedExpression">The expression attempting to be returned.</param>
        /// <returns>True if the expression is allowed to be returned from the function given the expression type and return type.</returns>
        public bool ValidateReturnTypeMatch(LSLType returnType, ILSLReadOnlyExprNode returnedExpression)
        {
            var left = new LSLDummyExpr
            {
                Type           = returnType,
                ExpressionType = LSLExpressionType.LocalVariable
            };

            return
                (ValidateBinaryOperation(left, LSLBinaryOperationType.Assign, returnedExpression).IsValid);
        }
        /// <summary>
        ///     Determines if the expression node represents a compound expression.
        ///     Compound expressions are:
        ///     Binary Expressions
        ///     Parenthesized Expressions
        ///     Postfix Expressions
        ///     Prefix Expressions
        ///     Typecast Expressions
        /// </summary>
        /// <param name="node">The expression node to test.</param>
        /// <returns>True if the expression node represents a compound expression.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="node"/> is <c>null</c>.</exception>
        public static bool IsCompoundExpression(this ILSLReadOnlyExprNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            return(node.ExpressionType == LSLExpressionType.BinaryExpression ||
                   node.ExpressionType == LSLExpressionType.ParenthesizedExpression ||
                   node.ExpressionType == LSLExpressionType.PostfixExpression ||
                   node.ExpressionType == LSLExpressionType.PrefixExpression ||
                   node.ExpressionType == LSLExpressionType.TypecastExpression);
        }
Exemple #20
0
        /// <summary>
        ///     Determines if an expression is valid inside of a boolean condition area, such as an if statement
        ///     or other control statement including loops.
        /// </summary>
        /// <param name="type">The type of expression that is attempting to be used.</param>
        /// <returns>True if the expression can be used inside of boolean condition area.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="type"/> is <c>null</c>.</exception>
        public bool ValidBooleanConditional(ILSLReadOnlyExprNode type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            return
                ((type.Type == LSLType.Key) ||
                 (type.Type == LSLType.Integer) ||
                 (type.Type == LSLType.Vector) ||
                 (type.Type == LSLType.Rotation) ||
                 (type.Type == LSLType.List) ||
                 (type.Type == LSLType.String) ||
                 (type.Type == LSLType.Float));
        }
Exemple #21
0
        /// <summary>
        ///     Validates and returns the type resulting from a cast operation.
        /// </summary>
        /// <param name="castedExpression">The expression to preform the cast on.</param>
        /// <param name="castTo">The type that is being casted to.</param>
        /// <returns>An <see cref="LSLExpressionValidatorResult" /> object</returns>
        /// <exception cref="ArgumentNullException"><paramref name="castedExpression"/> is <c>null</c>.</exception>
        public LSLExpressionValidatorResult ValidateCastOperation(LSLType castTo, ILSLReadOnlyExprNode castedExpression)
        {
            if (castedExpression == null)
            {
                throw new ArgumentNullException("castedExpression");
            }

            if (castedExpression.HasErrors)
            {
                return(LSLExpressionValidatorResult.Error);
            }


            LSLType t;

            if (_operations.TryGetValue("(" + castTo + ")" + castedExpression.Type, out t))
            {
                return(new LSLExpressionValidatorResult(t, true));
            }

            return(LSLExpressionValidatorResult.Error);
        }
Exemple #22
0
        /// <summary>
        ///     Validates and returns the type resulting from a postfix operation.
        /// </summary>
        /// <param name="left">The expression to preform the postfix operation on.</param>
        /// <param name="operation">The postfix operation preformed.</param>
        /// <returns>An <see cref="LSLExpressionValidatorResult" /> object</returns>
        /// <exception cref="ArgumentNullException"><paramref name="left"/> is <c>null</c>.</exception>
        public LSLExpressionValidatorResult ValidatePostfixOperation(ILSLReadOnlyExprNode left,
                                                                     LSLPostfixOperationType operation)
        {
            if (left == null)
            {
                throw new ArgumentNullException("left");
            }

            if (left.HasErrors)
            {
                return(LSLExpressionValidatorResult.Error);
            }

            LSLType t;

            if (_operations.TryGetValue(left.Type + operation.ToOperatorString(), out t))
            {
                return(new LSLExpressionValidatorResult(t, true));
            }

            return(LSLExpressionValidatorResult.Error);
        }
Exemple #23
0
 void ILSLSyntaxWarningListener.ReturnedValueFromEventHandler(LSLSourceCodeRange location,
                                                              ILSLEventSignature eventSignature, ILSLReadOnlyExprNode returnExpression)
 {
     _warningActionQueue.Enqueue(location.StartIndex,
                                 () =>
                                 SyntaxWarningListener.ReturnedValueFromEventHandler(location, eventSignature, returnExpression));
 }
Exemple #24
0
        /// <summary>
        ///     Validates and returns the type resulting from a prefix operation.
        /// </summary>
        /// <param name="right">The expression to preform the prefix operation on.</param>
        /// <param name="operation">The prefix operation preformed.</param>
        /// <returns>An <see cref="LSLExpressionValidatorResult" /> object</returns>
        /// <exception cref="ArgumentNullException"><paramref name="right"/> is <c>null</c>.</exception>
        public LSLExpressionValidatorResult ValidatePrefixOperation(LSLPrefixOperationType operation, ILSLReadOnlyExprNode right)
        {
            if (right == null)
            {
                throw new ArgumentNullException("right");
            }

            if (right.HasErrors)
            {
                return(LSLExpressionValidatorResult.Error);
            }

            LSLType t;

            if (_operations.TryGetValue(operation.ToOperatorString() + right.Type, out t))
            {
                return(new LSLExpressionValidatorResult(t, true));
            }

            return(LSLExpressionValidatorResult.Error);
        }
Exemple #25
0
 void ILSLSyntaxErrorListener.ForLoopConditionNotValidType(LSLSourceCodeRange location,
                                                           ILSLReadOnlyExprNode attemptedConditionExpression)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () => SyntaxErrorListener.ForLoopConditionNotValidType(location, attemptedConditionExpression));
 }
 /// <summary>
 ///     Determines whether the given expression is a modifiable L-Value.
 ///     This is true if its a global variable, local variable, local parameter or a reference to a vector component via the
 ///     dot operator.
 /// </summary>
 /// <param name="node">The expression node to test.</param>
 /// <returns>True if the expression is a modifiable L-Value.</returns>
 public static bool IsModifiableLeftValue(this ILSLReadOnlyExprNode node)
 {
     return(node.IsVariableOrParameter() || node.IsVectorOrRotationComponent());
 }
Exemple #27
0
 void ILSLSyntaxErrorListener.CastOnCastExpression(LSLSourceCodeRange location,
                                                   ILSLReadOnlyExprNode castedExpression)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () => SyntaxErrorListener.CastOnCastExpression(location, castedExpression));
 }
Exemple #28
0
 void ILSLSyntaxWarningListener.ExpressionStatementHasNoEffect(LSLSourceCodeRange location,
                                                               ILSLReadOnlyExprNode statementExpression)
 {
     _warningActionQueue.Enqueue(location.StartIndex,
                                 () => SyntaxWarningListener.ExpressionStatementHasNoEffect(location, statementExpression));
 }
Exemple #29
0
 void ILSLSyntaxErrorListener.InvalidRotationContent(LSLSourceCodeRange location, LSLRotationComponent component,
                                                     ILSLReadOnlyExprNode invalidExpressionContent)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () => SyntaxErrorListener.InvalidRotationContent(location, component, invalidExpressionContent));
 }
Exemple #30
0
 void ILSLSyntaxErrorListener.InvalidCastOperation(LSLSourceCodeRange location, LSLType castTo,
                                                   ILSLReadOnlyExprNode fromExpression)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () => SyntaxErrorListener.InvalidCastOperation(location, castTo, fromExpression));
 }