/// <summary>
        ///     Returns true if all strategy properties are non null.
        /// </summary>
        /// <param name="strategies">The <see cref="ILSLCodeValidatorStrategies" /> to check.</param>
        /// <param name="describeNulls">
        ///     A string describing which properties are null if
        ///     <see cref="IsComplete(ILSLCodeValidatorStrategies, out string)" /> returns <c>false</c>
        /// </param>
        /// <returns>True if all properties are initialized.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="strategies" /> is <c>null</c>.</exception>
        public static bool IsComplete(this ILSLCodeValidatorStrategies strategies, out string describeNulls)
        {
            if (strategies == null)
            {
                throw new ArgumentNullException("strategies");
            }


            string nullProps = string.Empty;

            if (strategies.ExpressionValidator == null)
            {
                nullProps += typeof(ILSLCodeValidatorStrategies).Name + ".ExpressionValidator is null." +
                             Environment.NewLine;
            }
            if (strategies.LibraryDataProvider == null)
            {
                nullProps += typeof(ILSLCodeValidatorStrategies).Name + ".LibraryDataProvider is null." +
                             Environment.NewLine;
            }
            if (strategies.SyntaxErrorListener == null)
            {
                nullProps += typeof(ILSLCodeValidatorStrategies).Name + ".SyntaxErrorListener is null." +
                             Environment.NewLine;
            }
            if (strategies.SyntaxWarningListener == null)
            {
                nullProps += typeof(ILSLCodeValidatorStrategies).Name + ".SyntaxWarningListener is null.";
            }

            describeNulls = string.IsNullOrEmpty(nullProps) ? null : nullProps;

            return(describeNulls == null);
        }
Beispiel #2
0
        public LSLLabelCollectorPrePass(LSLCodeValidatorVisitorScopeTracker scopingManager,
                                        ILSLCodeValidatorStrategies validatorStrategies)
        {
            _scopingManager      = scopingManager;
            _validatorStrategies = validatorStrategies;

            _statementIndexStack.Push(new StatementIndexContainer {
                Index = 0, ScopeId = 0
            });
        }
        /// <summary>
        ///     Returns true if all strategy properties are non null.
        /// </summary>
        /// <param name="strategies">The <see cref="ILSLCodeValidatorStrategies" /> to check.</param>
        /// <returns>True if all properties are initialized.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="strategies" /> is <c>null</c>.</exception>
        public static bool IsComplete(this ILSLCodeValidatorStrategies strategies)
        {
            if (strategies == null)
            {
                throw new ArgumentNullException("strategies");
            }


            return(strategies.ExpressionValidator != null &&
                   strategies.LibraryDataProvider != null &&
                   strategies.StringLiteralPreProcessor != null &&
                   strategies.SyntaxErrorListener != null &&
                   strategies.SyntaxWarningListener != null);
        }
Beispiel #4
0
        /// <summary>
        ///     Constructs an LSLCodeValidator using the given <see cref="ILSLCodeValidatorStrategies" />.
        /// </summary>
        /// <see cref="ILSLCodeValidatorStrategies" />
        /// <param name="validatorStrategies">The <see cref="ILSLCodeValidatorStrategies" /> to use.</param>
        /// <exception cref="ArgumentException">
        ///     If one or more of <paramref name="validatorStrategies" /> properties are
        ///     <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentNullException"><paramref name="validatorStrategies" /> is <c>null</c>.</exception>
        public LSLCodeValidator(ILSLCodeValidatorStrategies validatorStrategies)
        {
            if (validatorStrategies == null)
            {
                throw new ArgumentNullException("validatorStrategies");
            }


            ValidatorStrategies = validatorStrategies;

            string describeNulls;

            if (!validatorStrategies.IsComplete(out describeNulls))
            {
                throw new ArgumentException(typeof(ILSLCodeValidatorStrategies).Name + " is incomplete:" +
                                            Environment.NewLine +
                                            Environment.NewLine +
                                            describeNulls);
            }


            _validatorVisitor        = new LSLCodeValidatorVisitor(validatorStrategies);
            _antlrParserErrorHandler = new LSLAntlrErrorHandler(validatorStrategies.SyntaxErrorListener);
        }
Beispiel #5
0
 public LSLFunctionAndStateDefinitionPrePass(LSLCodeValidatorVisitorScopeTracker scopingManager,
                                             ILSLCodeValidatorStrategies validatorStrategies)
 {
     _scopingManager      = scopingManager;
     _validatorStrategies = validatorStrategies;
 }
Beispiel #6
0
        /// <summary>
        ///     Builds a parameter list node directly from a parser context, checking for duplicates and reporting
        ///     duplicate parameter errors via a validator strategies object. <see cref="ILSLCodeValidatorStrategies" />.
        /// </summary>
        /// <param name="context">The context to build from</param>
        /// <param name="validatorStrategies">The validator strategies object to use for reporting errors or warnings</param>
        /// <param name="parameterListType">The parameter list type.</param>
        /// <returns>the created parameter list node</returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="context" /> or <paramref name="validatorStrategies" /> is
        ///     <c>null</c>.
        /// </exception>
        internal static LSLParameterListNode BuildFromParserContext(LSLParser.OptionalParameterListContext context,
                                                                    LSLParameterListType parameterListType, ILSLCodeValidatorStrategies validatorStrategies)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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


            var result = new LSLParameterListNode(context, parameterListType);

            var parameterList = context.parameterList();

            if (parameterList == null)
            {
                return(result);
            }

            var parameterNames = new HashSet <string>();

            var parameterIndex = 0;

            foreach (var comma in parameterList.children)
            {
                //'comma' for some reason will be an internal object
                //that cannot be accessed via cast when a COMMA token is encountered.
                //
                //However, Payload contains a CommonToken instance, which implements IToken.
                var token = comma.Payload as IToken;

                //when a parameter def is found, 'comma' will be the grammar defined
                //LSLParser.ParameterDefinitionContext type.
                var parameter = comma as LSLParser.ParameterDefinitionContext;

                if (token != null)
                {
                    result._sourceRangeCommaList.Add(new LSLSourceCodeRange(token));
                }
                else if (parameter != null)
                {
                    if (parameterNames.Contains(parameter.ID().GetText()))
                    {
                        var paramLocation = new LSLSourceCodeRange(parameter);

                        validatorStrategies.SyntaxErrorListener.ParameterNameRedefined(
                            paramLocation,
                            parameterListType,
                            LSLTypeTools.FromLSLTypeName(parameter.TYPE().GetText()),
                            parameter.ID().GetText());

                        result.HasErrors = true;

                        result._parameters.Clear();

                        return(result);
                    }


                    parameterNames.Add(parameter.ID().GetText());

                    var addition = new LSLParameterNode(parameter)
                    {
                        ParameterIndex = parameterIndex
                    };

                    result.Add(addition);

                    parameterIndex++;
                }
            }

            parameterNames.Clear();

            return(result);
        }
 public LSLCodeValidatorVisitorScopeTracker(ILSLCodeValidatorStrategies validatorStrategies)
 {
     ValidatorStrategies = validatorStrategies;
 }