Exemple #1
0
        /// <summary>
        /// Tries coercing qualifier.
        /// </summary>
        public bool TryCoerce(
            QualifierSpaceId targetQualifierSpaceId,
            QualifierTable qualifierTable,
            QualifierValueCache cache,
            PathTable pathTable,
            StringTable stringTable,
            LoggingContext loggingContext,
            out QualifierValue qualifierValue,
            LineInfo location,
            bool useDefaultsForCoercion,
            AbsolutePath path)
        {
            Contract.Requires(targetQualifierSpaceId.IsValid);
            Contract.Requires(qualifierTable != null);
            Contract.Requires(qualifierTable.IsValidQualifierSpaceId(targetQualifierSpaceId));
            Contract.Requires(pathTable != null);
            Contract.Requires(stringTable != null);
            Contract.Requires(loggingContext != null);
#if DEBUG
            Contract.Ensures(Contract.ValueAtReturn(out qualifierValue) == null || Contract.Result <bool>() == true, "expected 'qualifierValue' to be set to null when return value is 'false'");
            Contract.Ensures(Contract.ValueAtReturn(out qualifierValue) != null || Contract.Result <bool>() == false, "expected 'qualifierValue' to be set to non-null when return value is 'true'");
#endif
            qualifierValue = null;

            if (targetQualifierSpaceId == qualifierTable.EmptyQualifierSpaceId)
            {
                qualifierValue = CreateEmpty(qualifierTable);
                return(true);
            }

            if (qualifierTable.TryCreateQualifierForQualifierSpace(
                    pathTable,
                    loggingContext,
                    QualifierId,
                    targetQualifierSpaceId,
                    useDefaultsForCoercion,
                    out QualifierId resultingQualifierId,
                    out UnsupportedQualifierValue error))
            {
                qualifierValue = Create(resultingQualifierId, cache, qualifierTable, stringTable);
                return(true);
            }

            var errorLocation = LocationData.Create(path, location.Line, location.Position);
            error.Location = errorLocation.ToLogLocation(pathTable);

            Logger.Log.ErrorUnsupportedQualifierValue(
                loggingContext,
                error.Location,
                error.QualifierKey,
                error.InvalidValue,
                error.LegalValues);

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Tries coercing qualifier.
        /// </summary>
        public bool TryCoerce(
            QualifierSpaceId targetQualifierSpaceId,
            QualifierTable qualifierTable,
            QualifierValueCache cache,
            PathTable pathTable,
            StringTable stringTable,
            LoggingContext loggingContext,
            out QualifierValue qualifierValue,
            LineInfo location,
            bool useDefaultsForCoercion,
            AbsolutePath path)
        {
            Contract.Requires(targetQualifierSpaceId.IsValid);
            Contract.Requires(qualifierTable != null);
            Contract.Requires(qualifierTable.IsValidQualifierSpaceId(targetQualifierSpaceId));
            Contract.Requires(pathTable != null);
            Contract.Requires(stringTable != null);
            Contract.Requires(loggingContext != null);

            qualifierValue = null;

            if (targetQualifierSpaceId == qualifierTable.EmptyQualifierSpaceId)
            {
                qualifierValue = CreateEmpty(qualifierTable);
                return(true);
            }

            if (qualifierTable.TryCreateQualifierForQualifierSpace(
                    pathTable,
                    loggingContext,
                    QualifierId,
                    targetQualifierSpaceId,
                    useDefaultsForCoercion,
                    out QualifierId resultingQualifierId,
                    out UnsupportedQualifierValue error))
            {
                qualifierValue = Create(resultingQualifierId, cache, qualifierTable, stringTable);
                return(true);
            }

            var errorLocation = LocationData.Create(path, location.Line, location.Position);

            error.Location = errorLocation.ToLogLocation(pathTable);

            Logger.Log.ErrorUnsupportedQualifierValue(
                loggingContext,
                error.Location,
                error.QualifierKey,
                error.InvalidValue,
                error.LegalValues);

            return(false);
        }
Exemple #3
0
        private void TestTryCoerceScopeToSpace(
            Func <QualifierTable, QualifierId> getQualifier,
            Dictionary <string, string[]> space,
            string expectedQualifier,
            bool expectedSuccess       = true,
            bool useDefaultsOnCoercion = true)
        {
            var context = FrontEndContext.CreateInstanceForTesting();
            var table   = new QualifierTable(context.StringTable);

            var testQualifier = getQualifier(table);
            var testSpace     = table.CreateQualifierSpace(space.Select(kvp => new Tuple <string, string[]>(kvp.Key, kvp.Value)).ToArray());

            QualifierId q;
            UnsupportedQualifierValue error;
            var result = table.TryCreateQualifierForQualifierSpace(
                context.PathTable,
                context.LoggingContext,
                testQualifier,
                testSpace,
                useDefaultsForCoercion: useDefaultsOnCoercion,
                resultingQualifierId: out q,
                error: out error);

            XAssert.AreEqual(expectedSuccess, result);

            if (result)
            {
                XAssert.AreEqual(expectedQualifier, ToString(q, table, context));
            }
            else
            {
                var location = LocationData.Create(AbsolutePath.Create(context.PathTable, m_path), 10, 10);
                Logger.Log.ErrorUnsupportedQualifierValue(
                    context.LoggingContext,
                    location.ToLogLocation(context.PathTable),
                    error.QualifierKey,
                    error.InvalidValue,
                    error.LegalValues
                    );
            }
        }