Example #1
0
 void ILSLSyntaxWarningListener.FunctionParameterNeverUsed(LSLSourceCodeRange location,
                                                           ILSLVariableDeclarationNode parameter,
                                                           ILSLFunctionSignature inFunction)
 {
     _warningActionQueue.Enqueue(location.StartIndex,
                                 () => SyntaxWarningListener.FunctionParameterNeverUsed(location, parameter, inFunction));
 }
Example #2
0
        /// <summary>
        ///     Construct an <see cref="LSLVariableNode" /> that references a local variable declaration node.
        /// </summary>
        /// <param name="declarationNode">A variable declaration node.</param>
        /// <param name="variableName">The name of the local variable.</param>
        /// <param name="type">The type of the local variable.</param>
        /// <param name="sourceRange">Optional source range for the area the reference exists in.</param>
        /// <returns>A new variable node representing a reference to <paramref name="declarationNode" />.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="declarationNode" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="type" /> is <see cref="LSLType.Void" /> or
        /// </exception>
        /// <exception cref="LSLInvalidSymbolNameException"><paramref name="variableName" /> contains characters that are not valid in an LSL ID token.</exception>
        internal static LSLVariableNode CreateLocalVarReference(LSLType type, string variableName,
                                                                ILSLVariableDeclarationNode declarationNode, LSLSourceCodeRange sourceRange = null)
        {
            if (declarationNode == null)
            {
                throw new ArgumentNullException("declarationNode");
            }

            if (type == LSLType.Void)
            {
                throw new ArgumentException("local variable type cannot be LSLType.Void", "type");
            }

            if (!LSLTokenTools.IDRegexAnchored.IsMatch(variableName))
            {
                throw new LSLInvalidSymbolNameException(
                          "variableName provided contained characters not allowed in an LSL ID token.");
            }

            return(new LSLVariableNode
            {
                Name = variableName,
                TypeName = type.ToLSLTypeName(),
                Type = type,
                IsConstant = false,
                Declaration = declarationNode,
                ExpressionType = LSLExpressionType.LocalVariable,
                SourceRange = sourceRange
            });
        }
        /// <summary>
        ///     A user defined local variable was never referenced.
        /// </summary>
        /// <param name="location">The location in the source code of the local variable that was never referenced.</param>
        /// <param name="variable">The variable declaration node of the un-referenced local variable.</param>
        /// <param name="inEvent">The signature of the event handler in which the local variable exists.</param>
        public virtual void LocalVariableNeverUsed(LSLSourceCodeRange location, ILSLVariableDeclarationNode variable,
                                                   ILSLEventSignature inEvent)
        {
            const string msg = "Local variable \"{0}\" was never used in event \"{1}\".";

            OnWarning(location, string.Format(msg, variable.Name, inEvent.Name));
        }
Example #4
0
 void ILSLSyntaxWarningListener.LocalVariableNeverUsed(LSLSourceCodeRange location,
                                                       ILSLVariableDeclarationNode variable,
                                                       ILSLEventSignature inEvent)
 {
     _warningActionQueue.Enqueue(location.StartIndex,
                                 () => SyntaxWarningListener.LocalVariableNeverUsed(location, variable, inEvent));
 }
 /// <summary>
 ///     A local variable name inside of a user defined function hides the definition of one of the functions parameters.
 /// </summary>
 /// <param name="location">The location in source code of the local variable that hides the function parameter.</param>
 /// <param name="functionSignature">The signature of the function in which the local variable is defined.</param>
 /// <param name="localVariable">The variable declaration node of the local variable that hides the parameter.</param>
 /// <param name="parameter">The parameter node of the parameter that was hidden.</param>
 public virtual void LocalVariableHidesParameter(LSLSourceCodeRange location,
                                                 ILSLFunctionSignature functionSignature,
                                                 ILSLVariableDeclarationNode localVariable, ILSLParameterNode parameter)
 {
     OnWarning(location, string.Format("Local variable \"{0}\" in function \"{1}\" hides parameter \"{2}\".",
                                       localVariable.Name, functionSignature.Name, parameter.Name));
 }
 /// <summary>
 ///     A user defined function parameter was never referenced.
 /// </summary>
 /// <param name="location">The location in the source code of the parameter that was never referenced.</param>
 /// <param name="parameter">The variable declaration node of the un-referenced function parameter.</param>
 /// <param name="inFunction">The signature of the function in which the parameter exists.</param>
 public virtual void FunctionParameterNeverUsed(LSLSourceCodeRange location,
                                                ILSLVariableDeclarationNode parameter,
                                                ILSLFunctionSignature inFunction)
 {
     OnWarning(location,
               string.Format("Parameter \"{0}\" was never used in function \"{1}\".", parameter.Name, inFunction.Name));
 }
        /// <summary>
        ///     A user defined global variable was never referenced.
        /// </summary>
        /// <param name="location">The location in the source code of the global variable that was never referenced.</param>
        /// <param name="variable">The variable declaration node of the un-referenced global variable.</param>
        public virtual void GlobalVariableNeverUsed(LSLSourceCodeRange location, ILSLVariableDeclarationNode variable)
        {
            const string msg = "Global variable \"{0}\" was never used.";


            OnWarning(location, string.Format(msg, variable.Name));
        }
Example #8
0
 void ILSLSyntaxWarningListener.LocalVariableHidesGlobalVariable(LSLSourceCodeRange location,
                                                                 ILSLEventSignature eventHandlerSignature,
                                                                 ILSLVariableDeclarationNode localVariable, ILSLVariableDeclarationNode globalVariable)
 {
     _warningActionQueue.Enqueue(location.StartIndex,
                                 () =>
                                 SyntaxWarningListener.LocalVariableHidesGlobalVariable(location, eventHandlerSignature,
                                                                                        localVariable, globalVariable));
 }
Example #9
0
 void ILSLSyntaxWarningListener.LocalVariableHidesParameter(LSLSourceCodeRange location,
                                                            ILSLFunctionSignature functionSignature,
                                                            ILSLVariableDeclarationNode localVariable, ILSLParameterNode parameter)
 {
     _warningActionQueue.Enqueue(location.StartIndex,
                                 () =>
                                 SyntaxWarningListener.LocalVariableHidesParameter(location, functionSignature, localVariable,
                                                                                   parameter));
 }
Example #10
0
        /// <summary>
        ///     Visit a variable declaration node during a syntax tree traversal.
        /// </summary>
        /// <param name="node">The Syntax Tree Node.</param>
        /// <seealso cref="LSLValidatorNodeVisitor{T}.VisitGlobalVariableDeclaration">
        ///     VisitGlobalVariableDeclaration calls this
        ///     method.
        /// </seealso>
        /// <seealso cref="LSLValidatorNodeVisitor{T}.VisitLocalVariableDeclaration">
        ///     VisitLocalVariableDeclaration calls this
        ///     method.
        /// </seealso>
        /// <returns>An object of type (T) from the visitor implementation of this function.</returns>
        public virtual T VisitVariableDeclaration(ILSLVariableDeclarationNode node)
        {
            if (node.HasDeclarationExpression)
            {
                Visit(node.DeclarationExpression);
            }

            return(default(T));
        }
Example #11
0
 void ILSLSyntaxWarningListener.VariableRedeclaredInInnerScope(LSLSourceCodeRange location,
                                                               ILSLEventSignature currentEventBodySignature,
                                                               ILSLVariableDeclarationNode newDeclarationNode, ILSLVariableDeclarationNode previousDeclarationNode)
 {
     _warningActionQueue.Enqueue(location.StartIndex,
                                 () =>
                                 SyntaxWarningListener.VariableRedeclaredInInnerScope(location, currentEventBodySignature,
                                                                                      newDeclarationNode, previousDeclarationNode));
 }
 /// <summary>
 ///     A local variable was re-declared inside of a nested scope, such as an if statement or for loop, ect... <para/>
 ///     This is not an error, but bad practice.  This function handles the warning case inside event handlers.
 /// </summary>
 /// <param name="location">The source code range of the new variable declaration.</param>
 /// <param name="currentEventBodySignature">The signature of the event handler the new variable was declared in.</param>
 /// <param name="newDeclarationNode">The tree node of the new declaration that has not been added to the tree yet.</param>
 /// <param name="previousDeclarationNode">
 ///     The previous variable declaration node which already exist in the syntax tree, in
 ///     an outer scope.
 /// </param>
 public virtual void VariableRedeclaredInInnerScope(LSLSourceCodeRange location,
                                                    ILSLEventSignature currentEventBodySignature,
                                                    ILSLVariableDeclarationNode newDeclarationNode, ILSLVariableDeclarationNode previousDeclarationNode)
 {
     OnWarning(location,
               string.Format(
                   "Local variable \"{0}\" in event handler \"{1}\" hides a previous declaration in an outer scope (on line {2}).",
                   newDeclarationNode.Name, currentEventBodySignature.Name,
                   MapLineNumber(previousDeclarationNode.SourceRange.LineStart)));
 }
 /// <summary>
 ///     A local variable inside of a library defined event handler hides the definition of a user defined global variable.
 /// </summary>
 /// <param name="location">The location in source code of the local variable that hides the global variable.</param>
 /// <param name="eventHandlerSignature">The parsed signature of the event handler in which the local variable is defined.</param>
 /// <param name="localVariable">The variable declaration node of the local variable that hides the global variable.</param>
 /// <param name="globalVariable">The variable declaration node of the user defined global variable that was hidden.</param>
 public virtual void LocalVariableHidesGlobalVariable(LSLSourceCodeRange location,
                                                      ILSLEventSignature eventHandlerSignature,
                                                      ILSLVariableDeclarationNode localVariable, ILSLVariableDeclarationNode globalVariable)
 {
     OnWarning(location,
               string.Format(
                   "Local variable \"{0}\" in event handler \"{1}\" hides global variable \"{2}\" defined on line {3}.",
                   localVariable.Name, eventHandlerSignature.Name, globalVariable.Name,
                   MapLineNumber(globalVariable.SourceRange.LineStart)));
 }
Example #14
0
        /// <exception cref="ArgumentNullException"><paramref name="context" /> or <paramref name="declaration" /> is <c>null</c>.</exception>
        internal static LSLVariableNode CreateVarReference(LSLParser.LocalVariableDeclarationContext context,
                                                           ILSLVariableDeclarationNode declaration)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (declaration == null)
            {
                throw new ArgumentNullException("declaration");
            }

            return(new LSLVariableNode
            {
                Name = context.variable_name.Text,
                TypeName = context.variable_type.Text,
                Type = LSLTypeTools.FromLSLTypeName(context.variable_type.Text),
                ExpressionType = LSLExpressionType.LocalVariable,
                IsConstant = false,
                SourceRange = new LSLSourceCodeRange(context),
                Declaration = declaration
            });
        }
 /// <summary>
 ///     A parameter name of a user defined function hides the definition of a global variable.
 /// </summary>
 /// <param name="location">The location in source code of the parameter that hides the global variable.</param>
 /// <param name="functionSignature">The function signature to which the parameter definition belongs to.</param>
 /// <param name="parameter">The signature of the parameter that hides the global variable.</param>
 /// <param name="globalVariable">The variable declaration node of the global variable that was hidden.</param>
 public virtual void ParameterHidesGlobalVariable(LSLSourceCodeRange location,
                                                  ILSLFunctionSignature functionSignature,
                                                  ILSLParameterNode parameter, ILSLVariableDeclarationNode globalVariable)
 {
     OnWarning(location,
               string.Format(
                   "Parameter \"{0}\" of function \"{1}\" hides global variable \"{2}\" defined on line {3}.",
                   parameter.Name, functionSignature.Name, globalVariable.Name,
                   MapLineNumber(globalVariable.SourceRange.LineStart)));
 }
Example #16
0
 void ILSLSyntaxWarningListener.GlobalVariableNeverUsed(LSLSourceCodeRange location,
                                                        ILSLVariableDeclarationNode variable)
 {
     _warningActionQueue.Enqueue(location.StartIndex,
                                 () => SyntaxWarningListener.GlobalVariableNeverUsed(location, variable));
 }
Example #17
0
 void ILSLSyntaxWarningListener.ParameterHidesGlobalVariable(LSLSourceCodeRange location,
                                                             ILSLFunctionSignature functionSignature,
                                                             ILSLParameterNode parameter, ILSLVariableDeclarationNode globalVariable)
 {
     _warningActionQueue.Enqueue(location.StartIndex,
                                 () =>
                                 SyntaxWarningListener.ParameterHidesGlobalVariable(location, functionSignature, parameter,
                                                                                    globalVariable));
 }
Example #18
0
 /// <summary>
 ///     Visits a local variable declaration inside of a user defined function or event handler during a syntax tree
 ///     traversal.
 /// </summary>
 /// <param name="node">The Syntax Tree Node.</param>
 /// <seealso cref="LSLValidatorNodeVisitor{T}.VisitVariableDeclaration">
 ///     VisitLocalVariableDeclaration makes a call to the
 ///     method seen here.
 /// </seealso>
 /// <returns>An object of type (T) from the visitor implementation of this function.</returns>
 public virtual T VisitLocalVariableDeclaration(ILSLVariableDeclarationNode node)
 {
     return(VisitVariableDeclaration(node));
 }