Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public ContextTree(
            [NotNull] FrontEndHost frontEndHost,
            [NotNull] FrontEndContext frontEndContext,
            [NotNull] GlobalConstants constants,
            [NotNull] ModuleRegistry moduleRegistry,
            [NotNull] Logger logger,
            [NotNull] EvaluationStatistics statistics,
            QualifierValueCache qualifierValueCache,
            bool isBeingDebugged,
            IDecorator <EvaluationResult> decorator,
            [NotNull] FileModuleLiteral module,
            [NotNull] EvaluatorConfiguration configuration,
            [NotNull] IEvaluationScheduler evaluationScheduler,
            FileType fileType)
        {
            Contract.Requires(frontEndHost != null);
            Contract.Requires(frontEndContext != null);
            Contract.Requires(constants != null);
            Contract.Requires(moduleRegistry != null);
            Contract.Requires(logger != null);
            Contract.Requires(statistics != null);
            Contract.Requires(module != null);

            EvaluationScheduler = evaluationScheduler;

            FrontEndHost        = frontEndHost;
            FrontEndContext     = frontEndContext;
            Constants           = constants;
            ModuleRegistry      = moduleRegistry;
            Logger              = logger;
            Statistics          = statistics;
            IsBeingDebugged     = isBeingDebugged;
            Decorator           = decorator;
            EvaluationScheduler = evaluationScheduler;
            QualifierValueCache = qualifierValueCache;
            ToolDefinitionCache = new ConcurrentDictionary <ObjectLiteral, CachedToolDefinition>();
            ValueCache          = new ConcurrentDictionary <Fingerprint, EvaluationResult>();
            CommonConstants     = new CommonConstants(frontEndContext.StringTable);

            RootContext =
                new Context(
                    contextTree: this,
                    parent: null,
                    module: module,
                    topLevelValueInfo: null,
                    fileType: fileType,
                    configuration: configuration,
                    evaluationScheduler: evaluationScheduler);

            Interlocked.Increment(ref statistics.ContextTrees);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a qualifier value given a qualifier id.
        /// </summary>
        public static QualifierValue Create(
            QualifierId qualifierId,
            QualifierValueCache cache,
            QualifierTable qualifierTable,
            StringTable stringTable)
        {
            var result = cache.TryGet(qualifierId);

            if (result == null)
            {
                result = Create(qualifierId, qualifierTable, stringTable);
                cache.TryAdd(result);
            }

            return(result);
        }