/// <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)); }
void ILSLSyntaxWarningListener.LocalVariableNeverUsed(LSLSourceCodeRange location, ILSLVariableDeclarationNode variable, ILSLEventSignature inEvent) { _warningActionQueue.Enqueue(location.StartIndex, () => SyntaxWarningListener.LocalVariableNeverUsed(location, variable, inEvent)); }
void ILSLSyntaxWarningListener.ReturnedValueFromEventHandler(LSLSourceCodeRange location, ILSLEventSignature eventSignature, ILSLReadOnlyExprNode returnExpression) { _warningActionQueue.Enqueue(location.StartIndex, () => SyntaxWarningListener.ReturnedValueFromEventHandler(location, eventSignature, returnExpression)); }
void ILSLSyntaxWarningListener.UseOfDeprecatedLibraryEventHandler(LSLSourceCodeRange location, ILSLEventSignature eventSignature) { _warningActionQueue.Enqueue(location.StartIndex, () => SyntaxWarningListener.UseOfDeprecatedLibraryEventHandler(location, eventSignature)); }
/// <summary> /// A local variable name inside of a library defined event handler hides the definition of one of the event handlers /// parameters. /// </summary> /// <param name="location">The location in source code of the local variable that hides the event handler parameter.</param> /// <param name="eventHandlerSignature">The 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 parameter.</param> /// <param name="parameter">The parameter node of the parameter that was hidden.</param> public virtual void LocalVariableHidesParameter(LSLSourceCodeRange location, ILSLEventSignature eventHandlerSignature, ILSLVariableDeclarationNode localVariable, ILSLParameterNode parameter) { OnWarning(location, string.Format("Local variable \"{0}\" in event handler \"{1}\" hides parameter \"{2}\".", localVariable.Name, eventHandlerSignature.Name, parameter.Name)); }
/// <summary> /// A library event handler that was marked as being deprecated was used. /// </summary> /// <param name="location">The location in source code where the deprecated event handler was referenced.</param> /// <param name="eventSignature">The event signature of the deprecated event handler that was referenced.</param> public virtual void UseOfDeprecatedLibraryEventHandler(LSLSourceCodeRange location, ILSLEventSignature eventSignature) { OnWarning(location, string.Format( "The library event handler \"{0}\" is deprecated, it is recommended you use an alternative or remove it.", eventSignature.Name)); }
void ILSLSyntaxWarningListener.LocalVariableHidesGlobalVariable(LSLSourceCodeRange location, ILSLEventSignature eventHandlerSignature, ILSLVariableDeclarationNode localVariable, ILSLVariableDeclarationNode globalVariable) { _warningActionQueue.Enqueue(location.StartIndex, () => SyntaxWarningListener.LocalVariableHidesGlobalVariable(location, eventHandlerSignature, localVariable, globalVariable)); }
void ILSLSyntaxErrorListener.IncorrectEventHandlerSignature(LSLSourceCodeRange location, ILSLEventSignature givenEventHandlerSignature, ILSLEventSignature correctEventHandlerSignature) { _errorActionQueue.Enqueue(location.StartIndex, () => SyntaxErrorListener.IncorrectEventHandlerSignature(location, givenEventHandlerSignature, correctEventHandlerSignature)); }
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 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))); }
/// <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> /// Construct an event signature by cloning another <see cref="ILSLEventSignature" /> object. /// </summary> /// <param name="other">The <see cref="ILSLEventSignature" /> to copy construct from.</param> /// <exception cref="ArgumentNullException"><paramref name="other"/> is <c>null</c>.</exception> public LSLEventSignature(ILSLEventSignature other) { if (other == null) { throw new ArgumentNullException("other"); } Name = other.Name; _parameters = new GenericArray <LSLParameterSignature>(other.Parameters); }
/// <summary> /// Dead code was detected, but it was not an error because it was inside an event handler. /// </summary> /// <param name="location">The location in the source code.</param> /// <param name="currentEvent">The signature of the event handler that dead code was detected in.</param> /// <param name="deadSegment">An object describing the range of code that is considered to be dead.</param> public virtual void DeadCodeDetected(LSLSourceCodeRange location, ILSLEventSignature currentEvent, ILSLDeadCodeSegment deadSegment) { if (deadSegment.SourceRange.IsSingleLine) { OnWarning(location, "Unreachable code detected in event handler \"" + currentEvent.Name + "\"."); } else { OnWarning(location, string.Format( "Unreachable code detected in event handler \"" + currentEvent.Name + "\" between lines {0} and {1}.", MapLineNumber(deadSegment.SourceRange.LineStart), MapLineNumber(deadSegment.SourceRange.LineEnd))); } }
/// <summary> /// Determines if two event handler signatures match exactly, parameter names do not matter but parameter /// types do. /// </summary> /// <param name="otherSignature">The other event handler signature to compare to.</param> /// <returns>True if the two signatures are identical.</returns> /// <exception cref="ArgumentNullException"><paramref name="otherSignature"/> is <c>null</c>.</exception> public bool SignatureMatches(ILSLEventSignature otherSignature) { if (otherSignature == null) { throw new ArgumentNullException("otherSignature"); } if (Name != otherSignature.Name) { return(false); } if (ParameterCount != otherSignature.ParameterCount) { return(false); } for (var i = 0; i < ParameterCount; i++) { if (Parameters[i].Type != otherSignature.Parameters[i].Type) { return(false); } } return(true); }
void ILSLSyntaxWarningListener.DeadCodeDetected(LSLSourceCodeRange location, ILSLEventSignature currentEvent, ILSLDeadCodeSegment deadSegment) { _warningActionQueue.Enqueue(location.StartIndex, () => SyntaxWarningListener.DeadCodeDetected(location, currentEvent, deadSegment)); }
/// <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)); }
void ILSLSyntaxErrorListener.UnknownEventHandlerDeclared(LSLSourceCodeRange location, ILSLEventSignature givenEventHandlerSignature) { _errorActionQueue.Enqueue(location.StartIndex, () => SyntaxErrorListener.UnknownEventHandlerDeclared(location, givenEventHandlerSignature)); }
/// <summary> /// Construct an LSLLibraryEventSignature by copying the signature details from an <see cref="ILSLEventSignature" /> /// object. /// </summary> /// <param name="sig">The <see cref="ILSLEventSignature" /> object to copy signatures details from.</param> public LSLLibraryEventSignature(ILSLEventSignature sig) : base(sig) { DocumentationString = ""; }