Exemplo n.º 1
0
        /// <inheritdoc />
        public override bool TryProject(Context context, SymbolAtom name, ModuleLiteral origin, out EvaluationResult result, LineInfo location)
        {
            if (name == context.ContextTree.CommonConstants.Length)
            {
                result = EvaluationResult.Create(Length);
                return(true);
            }

            var resolvedMember = ((ModuleRegistry)context.FrontEndHost.ModuleRegistry).PredefinedTypes.AmbientArray.ResolveMember(this, name);

            if (resolvedMember == null)
            {
                // Array literals could not have arbitrary members.
                // So if the name was not resolved, reporting an error.
                // var locationForLogging = LocationForLogging(context, origin);
                var locationForLogging = UniversalLocation.FromLineInfo(location, origin.Path, context.PathTable);

                context.Logger.ReportMissingInstanceMember(
                    context.LoggingContext,
                    locationForLogging.AsLoggingLocation(),
                    name.ToDisplayString(context),
                    DisplayStringHelper.TypeToString(GetType(), context),
                    context.GetStackTraceAsString(locationForLogging));

                result = EvaluationResult.Error;
            }
            else
            {
                result = EvaluationResult.Create(resolvedMember);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a namespace with a given name.
        /// </summary>
        internal virtual void AddNamespace(FullSymbol name, UniversalLocation location, QualifierSpaceId?qualifierSpaceId, out TypeOrNamespaceModuleLiteral module)
        {
            Contract.Requires(name.IsValid);
            Contract.Requires(Qualifier == QualifierValue.Unqualified);
            Contract.Assert(IsFileOrGlobal, "Current instance should be a file module or global ambient module");

            lock (m_syncRoot)
            {
                m_nsBindings = m_nsBindings ?? new NsBindingDictionary();

                if (m_nsBindings.ContainsKey(name))
                {
                    var moduleBinding = m_nsBindings[name];
                    Contract.Assert(moduleBinding.Body is TypeOrNamespaceModuleLiteral);

                    module = (TypeOrNamespaceModuleLiteral)moduleBinding.Body;
                    return;
                }

                module = CreateTypeOrNamespaceModule(name, outerScope: this, location: location.AsLineInfo());

                // Module is always exported.
                m_nsBindings.Add(name, new ModuleBinding(module, Declaration.DeclarationFlags.Export, location.AsLineInfo()));
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        internal override void AddType(FullSymbol name, UniversalLocation location, QualifierSpaceId?qualifierSpaceId, out TypeOrNamespaceModuleLiteral module)
        {
            module = CreateTypeOrNamespaceModule(name, outerScope: this, location: location.AsLineInfo());

            Contract.Assert(qualifierSpaceId == null, "Only namespace support qualifier types");

            AddResolvedEntry(location.AsFilePosition(), new ResolvedEntry(name, module));
        }
Exemplo n.º 4
0
        /// <nodoc />
        public ImportAliasExpression(DeserializationContext context, LineInfo location)
            : base(location)
        {
            var reader = context.Reader;

            m_referencedPath      = reader.ReadAbsolutePath();
            m_referencingLocation = new UniversalLocation(context, location);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="referencedPath">Referenced absolute path to be aliased.</param>
        /// <param name="referencingLocation">Location of the expression. Includes absolute path for the file containing this expression, which may be consumed for error reporting.</param>
        public ImportAliasExpression(AbsolutePath referencedPath, UniversalLocation referencingLocation)
            : base(referencingLocation)
        {
            Contract.Requires(referencedPath.IsValid);

            m_referencedPath      = referencedPath;
            m_referencingLocation = referencingLocation;
        }
 /// <summary>
 /// Constructor which deserializes from the given DeserializationContext.
 /// </summary>
 public CoerceQualifierTypeExpression(DeserializationContext context, LineInfo location)
     : base(location)
 {
     TargetExpression            = ReadExpression(context);
     TargetQualifierSpaceId      = context.Reader.ReadQualifierSpaceId();
     ShouldUseDefaultsOnCoercion = context.Reader.ReadBoolean();
     ReferencedLocation          = new UniversalLocation(context, location);
 }
Exemplo n.º 7
0
        /// <inheritdoc />
        internal override void AddNamespace(FullSymbol name, UniversalLocation location, QualifierSpaceId?qualifierSpaceId, out TypeOrNamespaceModuleLiteral module)
        {
            module = CreateTypeOrNamespaceModule(name, outerScope: this, location: location.AsLineInfo());

            Contract.Assert(qualifierSpaceId != null, "Qualifier type should be provided for a semantic evaluation");
            m_moduleRegistry.AddUninstantiatedModuleInfo(new UninstantiatedModuleInfo(sourceFile: null, typeOrNamespaceLiteral: module, qualifierSpaceId: qualifierSpaceId.Value));

            AddResolvedEntry(location.AsFilePosition(), new ResolvedEntry(name, module));
        }
Exemplo n.º 8
0
        /// <nodoc />
        private VariableDefinition(SymbolAtom name, int index, UniversalLocation locationDefinition, bool isConstant)
        {
            Contract.Requires(name.IsValid);

            Name  = name;
            Index = index;
            LocationDefinition = locationDefinition;
            IsConstant         = isConstant;
        }
        /// <nodoc/>
        public CoerceQualifierTypeExpression(Expression targetExpression, QualifierSpaceId targetQualifierSpaceId, bool shouldUseDefault, LineInfo referencingLocation, UniversalLocation referencedLocation)
            : base(referencingLocation)
        {
            Contract.Requires(targetExpression != null, "targetExpression != null");
            Contract.Requires(targetQualifierSpaceId.IsValid, "targetQualifierSpaceId.IsValid");

            TargetExpression            = targetExpression;
            TargetQualifierSpaceId      = targetQualifierSpaceId;
            ShouldUseDefaultsOnCoercion = shouldUseDefault;
            ReferencedLocation          = referencedLocation;
        }
Exemplo n.º 10
0
        private EvaluationResult ReportError(Context context, UnaryExpression spread)
        {
            var location = UniversalLocation.FromLineInfo(spread.Location, m_path, context.PathTable);

            context.Logger.ReportFailResolveSelectorDueToUndefined(
                context.LoggingContext,
                location.AsLoggingLocation(),
                spread.Expression.ToDisplayString(context),
                spread.ToDisplayString(context),
                context.GetStackTraceAsString(location));

            return(EvaluationResult.Error);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Adds a type with a given name.
 /// qualifierSpaceId is null for V1 and not null for v2.
 /// This is needed for a semantic-based evaluation and helps to filter nested variable declarations from the evaluation.
 /// </summary>
 internal virtual void AddType(FullSymbol name, UniversalLocation location, QualifierSpaceId?qualifierSpaceId, out TypeOrNamespaceModuleLiteral module)
 {
     AddNamespace(name, location, qualifierSpaceId, out module);
 }
        public void TestCoerceQualifierTypeExpression()
        {
            CoerceQualifierTypeExpression node = new CoerceQualifierTypeExpression(GetExpression1(), m_qualifierSpaceId, false, DefaultLineInfo, UniversalLocation.FromLineInfo(DefaultLineInfo, GetAbsolutePath(), m_pathTable));

            CheckSerializationRoundTrip(node);
        }
        public void TestImportAliasExpression()
        {
            ImportAliasExpression node = new ImportAliasExpression(GetAbsolutePath(), UniversalLocation.FromLineInfo(DefaultLineInfo, GetAbsolutePath(), m_pathTable));

            CheckSerializationRoundTrip(node);
        }
Exemplo n.º 14
0
 /// <inheritdoc/>
 public override void ReportError(EvaluationErrors errors, ModuleLiteral environment, LineInfo location, Expression expression, Context context)
 {
     errors.ReportContractFail(environment, Message, location, context.GetStackTraceAsString(UniversalLocation.FromLineInfo(location, environment.Path, context.PathTable)));
 }