Esempio n. 1
0
        /// <summary>
        /// Tries create a qualifier value given an object literal.
        /// </summary>
        public static bool TryCreate(
            ImmutableContextBase context,
            ModuleLiteral env,
            object potentialLiteral,
            out QualifierValue qualifierValue,
            LineInfo lineInfo = default(LineInfo))
        {
            Contract.Requires(context != null);
            Contract.Requires(env != null);
            Contract.Requires(potentialLiteral != null);

            qualifierValue = null;

            if (potentialLiteral is ObjectLiteral0)
            {
                qualifierValue = CreateEmpty(context.FrontEndContext.QualifierTable);
                return(true);
            }

            if (potentialLiteral is ObjectLiteralSlim || potentialLiteral is ObjectLiteralN)
            {
                return(TryCreate(context, env, out qualifierValue, lineInfo, (ObjectLiteral)potentialLiteral));
            }

            var location = lineInfo.AsUniversalLocation(env, context);

            context.Logger.ReportQualifierMustEvaluateToObjectLiteral(context.LoggingContext, location.AsLoggingLocation(), context.GetStackTraceAsErrorMessage(location));
            return(false);
        }
Esempio n. 2
0
        /// <nodoc />
        public void ReportCycle(ModuleLiteral env, LineInfo lineInfo)
        {
            Contract.Requires(env != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportCycle(LoggingContext, location.AsLoggingLocation(),
                               Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 3
0
        /// <nodoc />
        public void ReportContractFail(ModuleLiteral env, string message, LineInfo lineInfo, string callStack)
        {
            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportContractFail(
                LoggingContext,
                location.AsLoggingLocation(),
                message,
                callStack);
        }
Esempio n. 4
0
        public void ReportInputValidationException(ModuleLiteral env, InputValidationException inputValidationException, LineInfo lineInfo)
        {
            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportInputValidationError(
                LoggingContext,
                location.AsLoggingLocation(),
                inputValidationException.ErrorContext.ToErrorString(Context),
                !string.IsNullOrEmpty(inputValidationException.Message) ? ": " + inputValidationException.Message : string.Empty,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 5
0
        /// <nodoc />
        public void ReportWhileLoopOverflow(ModuleLiteral env, LineInfo lineInfo, int loopThreshold)
        {
            Contract.Requires(env != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportWhileLoopOverflow(
                LoggingContext,
                location.AsLoggingLocation(),
                loopThreshold,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 6
0
        /// <nodoc />
        public void ReportStackOverflow(ModuleLiteral env, LineInfo lineInfo)
        {
            Contract.Requires(env != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportStackOverflow(
                LoggingContext,
                location.AsLoggingLocation(),
                Context.CallStackSize,
                ImmutableContextBase.CallStackThreshold,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 7
0
        /// <nodoc />
        public void ReportArithmeticOverflow(
            ModuleLiteral env,
            Expression expression,
            LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportArithmeticOverflow(
                LoggingContext,
                location.AsLoggingLocation(),
                expression.ToDisplayString(Context));
        }
Esempio n. 8
0
        /// <nodoc />
        public void ReportArgumentIndexOutOfBound(ModuleLiteral env, int index, int numberOfArguments, LineInfo lineInfo)
        {
            Contract.Requires(env != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportArgumentIndexOutOfBound(
                LoggingContext,
                location.AsLoggingLocation(),
                index,
                numberOfArguments,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 9
0
        public void ReportDivideByZeroException(ModuleLiteral env, Expression expression, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(expression != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportDivideByZero(
                LoggingContext,
                location.AsLoggingLocation(),
                expression.ToDisplayString(Context),
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 10
0
        public void ReportSpreadIsNotAppliedToArrayValue(ModuleLiteral env, Expression expression, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(expression != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportSpreadIsNotAppliedToArrayValue(
                LoggingContext,
                location.AsLoggingLocation(),
                expression.ToDisplayString(Context),
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 11
0
        /// <nodoc />
        public void ReportUnexpectedAmbientException(ModuleLiteral env, Exception exception, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(exception != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            // TODO: print nested messages as well!!
            Logger.ReportUnexpectedAmbientException(
                LoggingContext,
                location.AsLoggingLocation(),
                exception.Message,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 12
0
        public void ReportFailResolveSelectorDueToUndefined(ModuleLiteral env, Expression thisExpression, SymbolAtom name, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(name.IsValid);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportFailResolveSelectorDueToUndefined(
                LoggingContext,
                location.AsLoggingLocation(),
                name.ToDisplayString(Context),
                thisExpression.ToDisplayString(Context),
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 13
0
        /// <nodoc />
        public void ReportMissingProperty(ModuleLiteral env, SymbolAtom selector, object receiver, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(receiver != null);

            var locationForLogging = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportMissingInstanceMember(
                LoggingContext,
                locationForLogging.AsLoggingLocation(),
                selector.ToDisplayString(Context),
                receiver.GetType().ToDisplayString(Context),
                Context.GetStackTraceAsString(locationForLogging));
        }
Esempio n. 14
0
        /// <nodoc />
        public void ReportStringIndexOufOfRange(ModuleLiteral env, int index, string target, LineInfo lineInfo)
        {
            Contract.Requires(env != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportStringIndexOufOfRange(
                LoggingContext,
                location.AsLoggingLocation(),
                index,
                target,
                target.Length,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 15
0
        /// <nodoc />
        public void ReportInvalidRadix(
            ModuleLiteral env,
            Expression expression,
            LineInfo lineInfo,
            int radix)
        {
            Contract.Requires(env != null);
            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportInvalidRadix(
                LoggingContext,
                location.AsLoggingLocation(),
                expression.ToDisplayString(Context),
                radix);
        }
Esempio n. 16
0
        /// <nodoc />
        public void ReportMissingNamespace(ModuleLiteral env, FullSymbol name, ModuleLiteral relatedEnv, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(name.IsValid);
            Contract.Requires(relatedEnv != null);
            var relatedLocation = relatedEnv.Location.AsLoggingLocation(relatedEnv, Context).ToDisplayString();
            var relatedMessage  = env == relatedEnv ? string.Empty : I($", related location '{relatedLocation}'");

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportMissingNamespace(
                LoggingContext,
                location.AsLoggingLocation(),
                name.ToDisplayString(Context),
                relatedMessage,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 17
0
        public void ReportContractRequire(ModuleLiteral env, Expression expression, string message, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(expression != null);

            string additionalInformation = string.IsNullOrEmpty(message)
                ? string.Empty
                : I($" : {message}");

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportContractRequire(
                LoggingContext,
                location.AsLoggingLocation(),
                expression.ToDisplayString(Context),
                additionalInformation,
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 18
0
        private static bool TryCreate(
            ImmutableContextBase context,
            ModuleLiteral env,
            out QualifierValue qualifierValue,
            LineInfo lineInfo,
            ObjectLiteral objectLiteral)
        {
            Contract.Requires(context != null);
            Contract.Requires(env != null);
            Contract.Requires(objectLiteral != null);

            qualifierValue = null;

            if (objectLiteral.Count == 0)
            {
                qualifierValue = CreateEmpty(context.FrontEndContext.QualifierTable);
                return(true);
            }

            Tuple <StringId, StringId>[] qualifierKvps = new Tuple <StringId, StringId> [objectLiteral.Count];

            int i = 0;

            foreach (var kvp in objectLiteral.Members)
            {
                if (!(kvp.Value.Value is string value))
                {
                    var location = lineInfo.AsUniversalLocation(env, context);
                    var error    = new ErrorContext(name: kvp.Key, objectCtx: objectLiteral).ToErrorString(context);
                    context.Logger.ReportQualifierValueMustEvaluateToString(context.LoggingContext, location.AsLoggingLocation(), error, context.GetStackTraceAsErrorMessage(location));
                    return(false);
                }

                qualifierKvps[i] = Tuple.Create(kvp.Key, context.FrontEndContext.StringTable.AddString(value));
                ++i;
            }

            QualifierId qualifierId = context.FrontEndContext.QualifierTable.CreateQualifier(qualifierKvps);

            qualifierValue = new QualifierValue(objectLiteral, qualifierId);

            return(true);
        }
Esempio n. 19
0
        /// <nodoc />
        public void ReportUnexpectedValueTypeOnConversion(
            ModuleLiteral env,
            ConvertException exception,
            LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(exception != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportUnexpectedValueTypeOnConversion(
                LoggingContext,
                location.AsLoggingLocation(),
                exception.ExpectedTypesToString(Context),
                exception.ErrorContext.ErrorReceiverAsString(Context),
                ValueToString(exception.Value, Context),
                ValueTypeToString(exception.Value, Context),
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 20
0
        public void ReportApplyAmbientNumberOfArgumentsLessThanMinArity(
            ModuleLiteral env,
            Expression functor,
            int minArity,
            int numOfArguments,
            LineInfo lineInfo = default(LineInfo))
        {
            Contract.Requires(env != null);
            Contract.Requires(functor != null);
            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportApplyAmbientNumberOfArgumentsLessThanMinArity(
                LoggingContext,
                location.AsLoggingLocation(),
                Context.GetStackTraceAsErrorMessage(location),
                functor.ToDisplayString(Context),
                minArity,
                numOfArguments);
        }
Esempio n. 21
0
        /// <nodoc />
        public void ReportUnexpectedValueTypeForName(
            ModuleLiteral env,
            SymbolAtom name,
            string expectedTypes,
            EvaluationResult value,
            LineInfo lineInfo = default(LineInfo))
        {
            Contract.Requires(env != null);
            Contract.Requires(name.IsValid);
            Contract.Requires(expectedTypes != null);

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportUnexpectedValueTypeForName(
                LoggingContext,
                location.AsLoggingLocation(),
                name.ToString(Context.FrontEndContext.SymbolTable),
                expectedTypes,
                ValueToString(value, Context),
                ValueTypeToString(value, Context),
                Context.GetStackTraceAsErrorMessage(location));
        }
Esempio n. 22
0
 public static Location AsLoggingLocation(this LineInfo lineInfo, ModuleLiteral moduleLiteral, ImmutableContextBase context)
 {
     return(lineInfo.AsUniversalLocation(moduleLiteral, context).AsLoggingLocation());
 }