Esempio n. 1
0
        public IErrorReporter ErrorDisabledProtocols()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                // just testing if disabling protocols (default) option really works
                var env = Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                FunctionDefinition func_constraint = FunctionBuilder.CreateDeclaration("getMe",
                                                                                       ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference());

                FunctionDefinition func = root_ns.AddBuilder(FunctionBuilder.Create("proxy",
                                                                                    TemplateParametersBuffer.Create().Add("T").Values,
                                                                                    ExpressionReadMode.OptionalUse,
                                                                                    NameFactory.UnitNameReference(), Block.CreateStatement())
                                                             .Constraints(ConstraintBuilder.Create("T").Has(func_constraint)));

                resolver = NameResolver.Create(env);

                TypeDefinition template_type = func.NestedTypes().Single();
                EntityModifier type_modifier = template_type.Modifier;

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.DisabledProtocols, type_modifier));
            }

            return(resolver);
        }
Esempio n. 2
0
        public IErrorReporter ErrorTraitDefinition()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                root_ns.AddBuilder(TypeBuilder.Create("Bar")
                                   .SetModifier(EntityModifier.Base));

                TypeDefinition non_generic_trait = root_ns.AddBuilder(TypeBuilder.Create("Bar")
                                                                      .SetModifier(EntityModifier.Trait));

                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Foo", "T", VarianceMode.None)));

                TypeDefinition unconstrained_trait = root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Foo", "T", VarianceMode.None))
                                                                        .SetModifier(EntityModifier.Trait));

                TypeDefinition missing_host = root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("MissMe", "Y", VarianceMode.None))
                                                                 .SetModifier(EntityModifier.Trait)
                                                                 .Constraints(ConstraintBuilder.Create("Y")
                                                                              .SetModifier(EntityModifier.Const)));

                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Almost", "T", VarianceMode.None)));

                FunctionDefinition  trait_constructor = FunctionBuilder.CreateInitConstructor(Block.CreateStatement());
                VariableDeclaration trait_field       = VariableDeclaration.CreateStatement("f", NameFactory.Int64NameReference(), Int64Literal.Create("5"), EntityModifier.Public);
                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Almost", "T", VarianceMode.None))
                                   .SetModifier(EntityModifier.Trait)
                                   .With(trait_constructor)
                                   .With(trait_field)
                                   .Constraints(ConstraintBuilder.Create("T")
                                                .SetModifier(EntityModifier.Const)));

                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Inheriting", "T", VarianceMode.None)));

                NameReference parent_impl = NameReference.Create("Bar");
                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Inheriting", "T", VarianceMode.None))
                                   .Parents(parent_impl)
                                   .SetModifier(EntityModifier.Trait)
                                   .Constraints(ConstraintBuilder.Create("T")
                                                .SetModifier(EntityModifier.Const)));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(6, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.NonGenericTrait, non_generic_trait));
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.UnconstrainedTrait, unconstrained_trait));
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.MissingHostTypeForTrait, missing_host));
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.TraitConstructor, trait_constructor));
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.TraitInheritingTypeImplementation, parent_impl));
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.FieldInNonImplementationType, trait_field));
            }

            return(resolver);
        }
Esempio n. 3
0
        public void TestEmptyName()
        {
            var config = ConfigParams.FromTuples();
            var name   = NameResolver.Resolve(config);

            Assert.Null(name);
        }
Esempio n. 4
0
        public IErrorReporter ErrorMisplacedConstraint()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                TemplateConstraint constraints = ConstraintBuilder.Create("BOO").SetModifier(EntityModifier.Const);
                root_ns.AddBuilder(TypeBuilder.Create("Greeter", "BOO")
                                   .With(FunctionBuilder.Create("say", ExpressionReadMode.ReadRequired, NameFactory.UnitNameReference(),
                                                                Block.CreateStatement())
                                         .Constraints(constraints)));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.MisplacedConstraint, constraints));
            }

            return(resolver);
        }
Esempio n. 5
0
        public IErrorReporter ImplicitPointerReferenceConversion()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                    DiscardingAnyExpressionDuringTests = true
                }.SetMutability(mutability));
                var root_ns = env.Root;

                var decl_src = VariableDeclaration.CreateStatement("foo", NameFactory.PointerNameReference(NameFactory.Int64NameReference()),
                                                                   initValue: Undef.Create());
                var decl_dst = VariableDeclaration.CreateStatement("bar", NameFactory.ReferenceNameReference(NameFactory.Int64NameReference()),
                                                                   initValue: NameReference.Create("foo"));

                var func_def_void = root_ns.AddBuilder(FunctionBuilder.Create(
                                                           "notimportant",
                                                           ExpressionReadMode.OptionalUse,
                                                           NameFactory.UnitNameReference(),

                                                           Block.CreateStatement(new[] {
                    decl_src,
                    decl_dst,
                    ExpressionFactory.Readout("bar")
                })));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(0, resolver.ErrorManager.Errors.Count);
            }

            return(resolver);
        }
Esempio n. 6
0
        public IErrorReporter ErrorInitializingWithGetter()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                root_ns.AddBuilder(TypeBuilder.Create("Point")
                                   .With(PropertyBuilder.CreateAutoGetter(env.Options, "x", NameFactory.Nat8NameReference()))
                                   .With(FunctionBuilder.CreateInitConstructor(Block.CreateStatement(
                                                                                   Assignment.CreateStatement(NameReference.CreateThised("x"), Nat8Literal.Create("5"))
                                                                                   ))));

                root_ns.AddBuilder(FunctionBuilder.Create(
                                       "main",
                                       ExpressionReadMode.OptionalUse,
                                       NameFactory.Nat8NameReference(),
                                       Block.CreateStatement(new IExpression[] {
                    VariableDeclaration.CreateStatement("p", null,
                                                        ConstructorCall.StackConstructor(NameReference.Create("Point"))
                                                        // cannot use getter in post-initialization
                                                        .Init("x", Nat8Literal.Create("17"), out Assignment post_init)
                                                        .Build()),
                    Return.Create(NameReference.Create(NameReference.Create("p"), "x"))
                })));
Esempio n. 7
0
        public IErrorReporter ErrorMissingFunctionImplementation()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                root_ns.AddBuilder(TypeBuilder.Create("Inter")
                                   .With(FunctionBuilder.CreateDeclaration("bar",
                                                                           ExpressionReadMode.OptionalUse,
                                                                           NameFactory.Int64NameReference()))
                                   .SetModifier(EntityModifier.Interface));

                root_ns.AddBuilder(TypeBuilder.Create("MiddleImpl")
                                   // ok to ignore the functions inside abstract type
                                   .SetModifier(EntityModifier.Abstract)
                                   .Parents(NameReference.Create("Inter")));

                // there is still function to implement
                TypeDefinition type_impl = root_ns.AddBuilder(TypeBuilder.Create("Impl")
                                                              .Parents(NameReference.Create("MiddleImpl")));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.BaseFunctionMissingImplementation, type_impl));
            }

            return(resolver);
        }
Esempio n. 8
0
        public IErrorReporter ErrorCallingHeapMethodOnValue()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                root_ns.AddBuilder(TypeBuilder.Create("Hi")
                                   .With(FunctionBuilder.Create("give", NameFactory.UnitNameReference(), Block.CreateStatement())
                                         .SetModifier(EntityModifier.HeapOnly)));

                FunctionCall call = FunctionCall.Create(NameReference.Create("v", "give"));
                root_ns.AddBuilder(FunctionBuilder.Create(
                                       "notimportant",
                                       ExpressionReadMode.OptionalUse,
                                       NameFactory.UnitNameReference(),

                                       Block.CreateStatement(
                                           VariableDeclaration.CreateStatement("v", null, ExpressionFactory.StackConstructor("Hi")),
                                           call
                                           )));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.CallingHeapFunctionWithValue, call));
            }

            return(resolver);
        }
Esempio n. 9
0
        public IErrorReporter ParentNamesResolving()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns   = env.Root;
                var system_ns = env.SystemNamespace;

                var foo_type = TypeBuilder.Create(NameDefinition.Create("Foo", "V", VarianceMode.None)).Build();
                system_ns.AddNode(foo_type);
                var parent_ref = NameReference.Create("Foo", NameReference.Create("T"));
                var tuple_type = TypeBuilder.Create(NameDefinition.Create("Tuple", "T", VarianceMode.None)).Parents(parent_ref).Build();
                system_ns.AddNode(tuple_type);

                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, parent_ref.Binding.Matches.Count());
                Assert.AreEqual(foo_type, parent_ref.Binding.Match.Instance.Target);
                Assert.AreEqual(tuple_type.NestedTypes().Single(),
                                parent_ref.Binding.Match.Instance.TemplateArguments.Single().Target());
            }

            return(resolver);
        }
Esempio n. 10
0
        public IErrorReporter ErrorLoopedAncestors()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns   = env.Root;
                var system_ns = env.SystemNamespace;

                system_ns.AddBuilder(TypeBuilder.Create("Foo")
                                     .SetModifier(EntityModifier.Base)
                                     .Parents(NameReference.Create("Bar")));
                system_ns.AddBuilder(TypeBuilder.Create("Bar")
                                     .SetModifier(EntityModifier.Base)
                                     .Parents(NameReference.Create("Foo")));

                // if it does not hang, it is OK
                resolver = NameResolver.Create(env);
                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.AreEqual(ErrorCode.CyclicTypeHierarchy, resolver.ErrorManager.Errors.Single().Code);
            }

            return(resolver);
        }
Esempio n. 11
0
        public IErrorReporter LowestCommonAncestor()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                var abc_type   = root_ns.AddBuilder(TypeBuilder.Create("ABC"));
                var foo_type   = root_ns.AddBuilder(TypeBuilder.Create("Foo").Parents(NameReference.Create("ABC")));
                var bar_type   = root_ns.AddBuilder(TypeBuilder.Create("Bar").Parents(NameReference.Create("ABC")));
                var deriv_type = root_ns.AddBuilder(TypeBuilder.Create("Deriv").Parents(NameReference.Create("Foo")));

                var deriv_ref = root_ns.AddNode(NameReference.Create("Deriv"));
                var bar_ref   = root_ns.AddNode(NameReference.Create("Bar"));
                var abc_ref   = root_ns.AddNode(NameReference.Create("ABC"));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(bar_type, bar_ref.Binding.Match.Instance.Target);
                Assert.AreEqual(deriv_type, deriv_ref.Binding.Match.Instance.Target);
                Assert.AreEqual(abc_type, abc_ref.Binding.Match.Instance.Target);

                bool found = TypeMatcher.LowestCommonAncestor(resolver.Context,
                                                              bar_ref.Binding.Match.Instance, deriv_ref.Binding.Match.Instance, out IEntityInstance common);
                Assert.IsTrue(found);
                Assert.IsTrue(abc_ref.Binding.Match.Instance.HasSameCore(common));
            }

            return(resolver);
        }
Esempio n. 12
0
        public IErrorReporter ErrorShakingOffSelfType()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                    DiscardingAnyExpressionDuringTests = true
                }.SetMutability(mutability));
                var root_ns = env.Root;

                root_ns.AddBuilder(TypeBuilder.Create("What")
                                   .SetModifier(EntityModifier.Base)
                                   .With(FunctionBuilder.CreateInitConstructor(Block.CreateStatement(ExpressionFactory.Readout("x")))
                                         .SetModifier(EntityModifier.Pinned)
                                         .Parameters(FunctionParameter.Create("x", NameFactory.SelfNameReference()))));

                TypeDefinition next_type = root_ns.AddBuilder(TypeBuilder.Create("Next")
                                                              .Parents("What")
                                                              .With(FunctionBuilder.CreateInitConstructor(Block.CreateStatement(ExpressionFactory.Readout("y")))
                                                                    .SetModifier(EntityModifier.Pinned)
                                                                    // this is an error, we should preserve using self type
                                                                    .Parameters(FunctionParameter.Create("y", NameReference.Create("Next")))));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.BaseFunctionMissingImplementation, next_type));
            }

            return(resolver);
        }
Esempio n. 13
0
        public IErrorReporter ErrorTypeImplementationAsSecondaryParent()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Point1")).SetModifier(EntityModifier.Base));
                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Point2")).SetModifier(EntityModifier.Base));

                NameReference parent_name = NameReference.Create("Point2");
                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("PointEx"))
                                   .Parents(NameReference.Create("Point1"), parent_name));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.TypeImplementationAsSecondaryParent, parent_name));
            }

            return(resolver);
        }
Esempio n. 14
0
        public IErrorReporter BasicTraitDefinition()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Foo", "T", VarianceMode.None)));

                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Foo", "T", VarianceMode.None))
                                   .SetModifier(EntityModifier.Trait)
                                   .Constraints(ConstraintBuilder.Create("T")
                                                .SetModifier(EntityModifier.Const)));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(0, resolver.ErrorManager.Errors.Count);
            }

            return(resolver);
        }
Esempio n. 15
0
        public IErrorReporter ErrorConflictingConstConstraint()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                root_ns.AddBuilder(TypeBuilder.Create("Mut").SetModifier(EntityModifier.Mutable));

                NameReference parent_constraint = NameReference.Create("Mut");
                root_ns.AddBuilder(FunctionBuilder.Create("proxy",
                                                          TemplateParametersBuffer.Create().Add("T").Values,
                                                          ExpressionReadMode.CannotBeRead,
                                                          NameFactory.UnitNameReference(),

                                                          Block.CreateStatement())
                                   .Constraints(ConstraintBuilder.Create("T")
                                                .SetModifier(EntityModifier.Const)
                                                .Inherits(parent_constraint)));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(2, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.InheritanceMutabilityViolation, parent_constraint));
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.InheritingSealedType, parent_constraint));
            }

            return(resolver);
        }
Esempio n. 16
0
        /// <summary>
        /// Connects to the specified host. If the hostname resolves to more than one IP address,
        /// all IP addresses will be tried for connection, until one of them connects.
        /// </summary>
        /// <param name="host">Host name or IP address.</param>
        /// <param name="port">Port to connect.</param>
        /// <param name="ssl">Specifies if connects to SSL end point.</param>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
        /// <exception cref="InvalidOperationException">Is raised when client is already connected.</exception>
        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Is raised when port isnot in valid range.</exception>
        public void Connect(string host, int port, bool ssl)
        {
            ThrowIfObjectDisposed();
            ThrowIfConnected();

            AssertUtil.ArgumentNotEmpty(host, nameof(host));
            AssertUtil.AssertNetworkPort(port, nameof(port));

            var ips = NameResolver.GetHostAddresses(host);

            for (int i = 0; i < ips.Length; i++)
            {
                try
                {
                    Connect(null, new IPEndPoint(ips[i], port), ssl);
                    break;
                }
                catch (Exception ex)
                {
                    if (this.IsConnected)
                    {
                        throw ex;
                    }
                    // Connect failed for specified IP address,
                    // if there are some more IPs left, try next, otherwise forward exception.
                    else if (i == (ips.Length - 1))
                    {
                        throw ex;
                    }
                }
            }
        }
Esempio n. 17
0
        public IErrorReporter ErrorNoDefaultConstructor()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                var bar_def = root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Bar"))
                                                 .With(FunctionDefinition.CreateInitConstructor(EntityModifier.None,
                                                                                                new[] { FunctionParameter.Create("a", NameFactory.Int64NameReference(),
                                                                                                                                 Variadic.None, null, isNameRequired: false, usageMode: ExpressionReadMode.CannotBeRead) },
                                                                                                Block.CreateStatement())));
                VariableDeclaration field_decl = VariableDeclaration.CreateStatement("x", NameReference.Create("Bar"), null,
                                                                                     EntityModifier.Public);
                var type_def = root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Point"))
                                                  .With(field_decl));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.NoDefaultConstructor, field_decl));
            }

            return(resolver);
        }
Esempio n. 18
0
        public IErrorReporter ErrorStaticMemberReference()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                    StaticMemberOnlyThroughTypeName = true
                }.SetMutability(mutability));
                var root_ns = env.Root;

                root_ns.AddBuilder(TypeBuilder.Create("Foo")
                                   .With(VariableDeclaration.CreateStatement("field", NameFactory.RealNameReference(), null,
                                                                             EntityModifier.Static | EntityModifier.Public)));

                NameReference field_ref = NameReference.Create("f", "field");
                root_ns.AddBuilder(FunctionBuilder.Create("foo",
                                                          ExpressionReadMode.OptionalUse,
                                                          NameFactory.RealNameReference(),
                                                          Block.CreateStatement(new IExpression[] {
                    VariableDeclaration.CreateStatement("f", NameReference.Create("Foo"), Undef.Create()),
                    Return.Create(field_ref)
                })));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.StaticMemberAccessInInstanceContext, field_ref));
            }

            return(resolver);
        }
Esempio n. 19
0
        public IErrorReporter ErrorSelfTypeUsage()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                    DiscardingAnyExpressionDuringTests = true
                }.SetMutability(mutability));
                var root_ns = env.Root;

                NameReference invalid_self1 = NameFactory.SelfNameReference();
                NameReference invalid_self2 = NameFactory.SelfNameReference();

                // in time probably we will use Self type in more places, but for now we forbid everything we don't support
                root_ns.AddBuilder(TypeBuilder.Create("What")
                                   .With(FunctionBuilder.Create("foo", invalid_self1,
                                                                Block.CreateStatement(Return.Create(NameReference.Create("x"))))
                                         .Parameters(FunctionParameter.Create("x", invalid_self2))));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(2, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.SelfTypeOutsideConstructor, invalid_self1));
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.SelfTypeOutsideConstructor, invalid_self2));
            }

            return(resolver);
        }
Esempio n. 20
0
        public IErrorReporter ErrorCircularValueNesting()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                    DiscardingAnyExpressionDuringTests = true
                }.SetMutability(mutability));
                var root_ns = env.Root;

                VariableDeclaration decl1 = VariableDeclaration.CreateStatement("s", NameReference.Create("Form"), null, EntityModifier.Private);
                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Shape"))
                                   .With(FunctionBuilder.Create("reader", NameFactory.UnitNameReference(),
                                                                Block.CreateStatement(ExpressionFactory.Readout(NameReference.CreateThised("s")))))
                                   .With(decl1));

                VariableDeclaration decl2 = VariableDeclaration.CreateStatement("f", NameReference.Create("Shape"), null, EntityModifier.Private);
                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Form"))
                                   .With(FunctionBuilder.Create("reader", NameFactory.UnitNameReference(),
                                                                Block.CreateStatement(ExpressionFactory.Readout(NameReference.CreateThised("f")))))
                                   .With(decl2));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(2, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.NestedValueOfItself, decl1));
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.NestedValueOfItself, decl2));
            }

            return(resolver);
        }
Esempio n. 21
0
        public IErrorReporter ErrorUnusedVariableWithinUsedExpression()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                    DiscardingAnyExpressionDuringTests = true
                }.SetMutability(mutability));
                var root_ns = env.Root;

                VariableDeclaration decl = VariableDeclaration.CreateExpression("result", NameFactory.Int64NameReference(), initValue: Undef.Create());
                root_ns.AddBuilder(FunctionBuilder.Create("anything", null,
                                                          ExpressionReadMode.OptionalUse,
                                                          NameFactory.UnitNameReference(),

                                                          Block.CreateStatement(
                                                              // the declaration-expression is used, but the variable itself is not
                                                              // thus we report it as unused (in such code user should pass the init-value itself w/o creating variable)
                                                              ExpressionFactory.Readout(decl)
                                                              )));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.BindableNotUsed, decl.Name));
            }

            return(resolver);
        }
Esempio n. 22
0
        public IErrorReporter CatVarianceExample() // Programming in Scala, 2nd ed, p. 399
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                NameReference result_typename = NameReference.Create("Cat",
                                                                     NameReference.Create("Cat", NameReference.Create("U"), NameReference.Create("T")), NameReference.Create("U"));

                root_ns.AddBuilder(TypeBuilder.CreateInterface(NameDefinition.Create("Cat", TemplateParametersBuffer.Create()
                                                                                     .Add("T", VarianceMode.In).Add("U", VarianceMode.Out).Values))
                                   .With(FunctionBuilder.CreateDeclaration("meow", "W", VarianceMode.In, ExpressionReadMode.ReadRequired, result_typename)
                                         .Parameters(FunctionParameter.Create("volume", NameReference.Create("T")),
                                                     FunctionParameter.Create("listener",
                                                                              NameReference.Create("Cat", NameReference.Create("U"), NameReference.Create("T"))))));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(0, resolver.ErrorManager.Errors.Count);
            }

            return(resolver);
        }
Esempio n. 23
0
        public IErrorReporter AssignmentTypeChecking()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                    GlobalVariables = true, RelaxedMode = true
                }.SetMutability(mutability));
                var root_ns   = env.Root;
                var system_ns = env.SystemNamespace;

                root_ns.AddNode(VariableDeclaration.CreateStatement("x", NameFactory.RealNameReference(), Undef.Create()));
                root_ns.AddNode(VariableDeclaration.CreateStatement("y", NameFactory.RealNameReference(), NameReference.Create("x"),
                                                                    modifier: EntityModifier.Public));
                var x_ref = NameReference.Create("x");
                root_ns.AddNode(VariableDeclaration.CreateStatement("z", NameFactory.Int64NameReference(), x_ref,
                                                                    modifier: EntityModifier.Public));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.TypeMismatch, x_ref));
            }

            return(resolver);
        }
Esempio n. 24
0
        public IErrorReporter TypeInference()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                    DiscardingAnyExpressionDuringTests = true, DebugThrowOnError = true
                }.SetMutability(mutability));
                var root_ns = env.Root;

                var var_x = VariableDeclaration.CreateStatement("x", NameFactory.RealNameReference(), Undef.Create());
                var var_y = VariableDeclaration.CreateStatement("y", null, NameReference.Create("x"));

                var func_def_void = root_ns.AddBuilder(FunctionBuilder.Create(
                                                           "notimportant",
                                                           ExpressionReadMode.OptionalUse,
                                                           NameFactory.UnitNameReference(),

                                                           Block.CreateStatement(new[] {
                    var_x,
                    var_y,
                    ExpressionFactory.Readout("y")
                })));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(0, resolver.ErrorManager.Errors.Count);

                Assert.IsTrue(env.Real64Type.InstanceOf.HasSameCore(var_y.Evaluation.Components));
            }

            return(resolver);
        }
Esempio n. 25
0
        public IErrorReporter ErrorCompoundDefaultValue()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                    GlobalVariables = true, RelaxedMode = true, AllowProtocols = true
                }.SetMutability(mutability));
                var root_ns = env.Root;

                var decl = root_ns.AddNode(VariableDeclaration.CreateStatement("x", NameReferenceUnion.Create(
                                                                                   new[] { NameFactory.PointerNameReference(NameFactory.BoolNameReference()),
                                                                                           NameFactory.PointerNameReference(NameFactory.Int64NameReference()) }),
                                                                               initValue: null, modifier: EntityModifier.Public));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.CannotAutoInitializeCompoundType, decl));
            }

            return(resolver);
        }
Esempio n. 26
0
        public IErrorReporter VariableBinding()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns   = env.Root;
                var system_ns = env.SystemNamespace;

                var decl_1 = VariableDeclaration.CreateStatement("x", NameFactory.RealNameReference(), Undef.Create(), modifier: EntityModifier.Public);
                root_ns.AddNode(decl_1);
                var var_1_ref = NameReference.Create("x");
                var decl_2    = root_ns.AddNode(VariableDeclaration.CreateStatement("y", NameFactory.RealNameReference(),
                                                                                    var_1_ref, modifier: EntityModifier.Public));

                resolver = NameResolver.Create(env);
                Assert.AreEqual(1, decl_1.TypeName.Binding().Matches.Count);
                Assert.AreEqual(env.Real64Type, decl_1.TypeName.Binding().Match.Instance.Target);

                Assert.AreEqual(1, var_1_ref.Binding.Matches.Count);
                Assert.AreEqual(decl_1, var_1_ref.Binding.Match.Instance.Target);
            }

            return(resolver);
        }
Esempio n. 27
0
        public IErrorReporter ErrorReassigningFixedVariable()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                    DiscardingAnyExpressionDuringTests = true
                }.SetMutability(mutability));
                var root_ns = env.Root;

                IExpression assignment = Assignment.CreateStatement(NameReference.Create("x"), Int64Literal.Create("5"));
                root_ns.AddBuilder(FunctionBuilder.Create(
                                       "notimportant",
                                       ExpressionReadMode.OptionalUse,
                                       NameFactory.UnitNameReference(),

                                       Block.CreateStatement(new[] {
                    VariableDeclaration.CreateStatement("x", null, Int64Literal.Create("3")),
                    assignment,
                    ExpressionFactory.Readout("x")
                })));


                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.CannotReassignReadOnlyVariable, assignment));
            }

            return(resolver);
        }
        DataType TryResolveDataTypeIdentifier(AstIdentifier identifier)
        {
            var pi = NameResolver.TryResolveMemberRecursive(Namescope, identifier, null) ??
                     NameResolver.TryResolveUsingNamespace(Namescope, identifier, null);

            return((pi as PartialType)?.Type);
        }
Esempio n. 29
0
        private static (Stmt Stmt, NameResolver Resolver) ScanParseAndResolveSingleStatement(string program)
        {
            var interpreter = new PerlangInterpreter(AssertFailRuntimeErrorHandler, s => throw new ApplicationException(s));

            var scanAndParseResult = interpreter.ScanAndParse(
                program,
                AssertFailScanErrorHandler,
                AssertFailParseErrorHandler
                );

            Assert.True(scanAndParseResult.HasStatements);
            Assert.Single(scanAndParseResult.Statements !);

            Stmt singleStatement = scanAndParseResult.Statements !.Single();

            var resolver = new NameResolver(
                ImmutableDictionary <string, Type> .Empty,
                ImmutableDictionary <string, Type> .Empty,
                interpreter.BindingHandler,
                AssertFailAddGlobalClassHandler,
                AssertFailNameResolutionErrorHandler
                );

            resolver.Resolve(scanAndParseResult.Statements !);

            return(singleStatement, resolver);
        }
Esempio n. 30
0
        /// <summary>
        /// Enqueues an event to the actor with the specified id.
        /// </summary>
        private EnqueueStatus EnqueueEvent(Actor actor, Event e, Actor sender, Guid opGroupId, SendOptions options)
        {
            EventOriginInfo originInfo;

            string stateName = null;

            if (sender is StateMachine senderStateMachine)
            {
                originInfo = new EventOriginInfo(sender.Id, senderStateMachine.GetType().FullName,
                                                 NameResolver.GetStateNameForLogging(senderStateMachine.CurrentState));
                stateName = senderStateMachine.CurrentStateName;
            }
            else if (sender is Actor senderActor)
            {
                originInfo = new EventOriginInfo(sender.Id, senderActor.GetType().FullName, string.Empty);
            }
            else
            {
                // Message comes from the environment.
                originInfo = new EventOriginInfo(null, "Env", "Env");
            }

            EventInfo eventInfo = new EventInfo(e, originInfo)
            {
                MustHandle = options?.MustHandle ?? false,
                Assert     = options?.Assert ?? -1
            };

            this.LogWriter.LogSendEvent(actor.Id, sender?.Id.Name, sender?.Id.Type, stateName,
                                        e, opGroupId, isTargetHalted: false);
            return(actor.Enqueue(e, opGroupId, eventInfo));
        }
Esempio n. 31
0
        public void EditorKeyUp(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner scanner, System.Windows.Input.KeyEventArgs e)
        {
            Globals g = GetGlobals();
            if (g == null)
                return;
            // These keys halt and terminate intellisense
            switch (e.Key)
            {
                case Key.Home:
                case Key.End:
                case Key.Left:
                case Key.Right:
                case Key.Escape:
                case Key.LWin:
                case Key.RWin:
                case Key.Space:
                    if (currentComp != null)
                        currentComp.Close();
                    return;
            }
            // These keys halt further checks
            switch (e.Key)
            {
                case Key.Up:
                case Key.Down:
                case Key.PageDown:
                case Key.PageUp:
                case Key.LeftShift:
                case Key.RightShift:
                case Key.LeftAlt:
                case Key.RightAlt:
                case Key.LeftCtrl:
                case Key.RightCtrl:
                case Key.Scroll:
                case Key.Capital:
                case Key.CrSel:
                case Key.Clear:
                case Key.Insert:
                case Key.PrintScreen:
                case Key.Print:
                    return;
            }

            char KEY = KeyHelpers.GetCharFromKey(e.Key);
            if (KEY == ')' || KEY == ';')
            {
                if (currentComp != null)
                    currentComp.Close();
                return;
            }
            int curOfs = editor.TextArea.Caret.Offset;
            int line = editor.TextArea.Caret.Line;

            // Do not attempt intellisense inside of comments
            string txt = editor.Document.GetText(editor.Document.Lines[editor.TextArea.Caret.Line - 1]);
            if (txt.Trim().StartsWith("//"))
                return;

            // Check for anything to display in response to a potential namespace, scope, or dot
            if (e.Key == Key.OemPeriod || KEY == ':')
            {
                //IntellisenseHelper.ResemblesDotPath(editor.Document, curOfs-1, line-1)) {
                int ofs = TextUtilities.GetNextCaretPosition(editor.Document, curOfs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                ofs = TextUtilities.GetNextCaretPosition(editor.Document, ofs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                string word = "";
                for (; ofs < curOfs; ++ofs)
                {
                    if (editor.Document.Text[ofs] != '.')
                        word += editor.Document.Text[ofs];
                }

                NameResolver reso = new NameResolver(GetGlobals(), scanner);
                BaseTypeInfo info = null;
                string[] words = IntellisenseHelper.DotPath(editor.Document, curOfs - 1, line - 1);
                if (words.Length > 0)
                {
                    for (int i = 0; i < words.Length; ++i)
                    {
                        if (info == null)
                        {
                            info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, words[i]);
                            if (info == null && GetGlobals().ContainsProperty(words[i]))
                                info = GetGlobals().GetProperty(words[i], true);
                        }
                        else if (info != null)
                        {
                            info = info.ResolvePropertyPath(GetGlobals(), words[i]);
                        }
                    }
                }

                bool functionsOnly = false;
                //attempt to resolve it locally
                if (info == null)
                    info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, word);
                //attempt to resolve it from globals
                if (info == null && GetGlobals() != null && GetGlobals().ContainsProperty(word))
                    info = GetGlobals().GetProperty(word, true);
                if (info == null && word.Contains("::"))
                {
                    if (GetGlobals() == null)
                        return;
                    if (word.Length > 2)
                    {
                        string ns = word.Replace("::", "");
                        if (GetGlobals().ContainsTypeInfo(ns))
                        {
                            EnumInfo ti = GetGlobals().GetTypeInfo(word.Replace("::", "")) as EnumInfo;
                            if (ti != null)
                            {
                                currentComp = new CompletionWindow(editor.TextArea);
                                IList<ICompletionData> data = currentComp.CompletionList.CompletionData;
                                foreach (string str in ti.Values)
                                    data.Add(new BaseCompletionData(null, str));
                                currentComp.Show();
                                currentComp.Closed += comp_Closed;
                                return;
                            }
                            else
                            {
                                TypeInfo ty = GetGlobals().GetTypeInfo(word.Replace("::", ""));
                                if (ty != null)
                                {
                                    info = ty;
                                    functionsOnly = true;
                                }
                            }
                        }
                        else
                        { //list global functions because we've received "::" only
                            Globals globs = GetGlobals();
                            bool asNS = false;
                            if (globs.ContainsNamespace(ns))
                            {
                                asNS = true;
                                globs = globs.GetNamespace(ns);
                            }
                            currentComp = new CompletionWindow(editor.TextArea);
                            IList<ICompletionData> data = currentComp.CompletionList.CompletionData;
                            foreach (string str in globs.GetPropertyNames())
                            {
                                TypeInfo ti = globs.GetProperty(str, !asNS) as TypeInfo;
                                if (ti != null)
                                    data.Add(new PropertyCompletionData(ti, str));
                            }
                            foreach (FunctionInfo fi in globs.GetFunctions(null, false))
                                data.Add(new FunctionCompletionData(fi));
                            if (asNS) //Include classes
                            {
                                foreach (TypeInfo ti in globs.TypeInfo)
                                    data.Add(new ClassCompletionData(ti));
                            }
                            currentComp.Show();
                            currentComp.Closed += comp_Closed;
                            return;
                        }
                    }
                }

                //build the list
                if (info != null && info is TypeInfo)
                {
                    TypeInfo ti = info as TypeInfo;
                    currentComp = new CompletionWindow(editor.TextArea);
                    IList<ICompletionData> data = currentComp.CompletionList.CompletionData;
                    if (!functionsOnly)
                    {
                        foreach (string str in ti.Properties.Keys)
                        {
                            data.Add(new PropertyCompletionData(ti.Properties[str], str,
                                ti.ReadonlyProperties.Contains(str) ? PropertyAccess.Readonly :
                                (ti.ProtectedProperties.Contains(str) ? PropertyAccess.Protected : PropertyAccess.Public)));
                        }
                        foreach (TypeInfo t in ti.BaseTypes)
                        {
                            foreach (string str in t.Properties.Keys)
                            {
                                if (!t.PrivateProperties.Contains(str))
                                {
                                    data.Add(new PropertyCompletionData(t.Properties[str], str,
                                        t.ReadonlyProperties.Contains(str) ? PropertyAccess.Readonly :
                                        (t.ProtectedProperties.Contains(str) ? PropertyAccess.Protected : PropertyAccess.Public)));
                                }
                            }
                        }
                    }
                    foreach (FunctionInfo fi in ti.Functions)
                        data.Add(new FunctionCompletionData(fi));
                    foreach (TypeInfo t in ti.BaseTypes)
                    {
                        foreach (FunctionInfo fi in t.Functions)
                        {
                            if (!fi.IsPrivate)
                                data.Add(new FunctionCompletionData(fi));
                        }
                    }
                    currentComp.Show();
                    currentComp.Closed += comp_Closed;
                }
            }
            else if (KEY == '(' && IntellisenseHelper.ResemblesDotPath(editor.Document, curOfs - 2, line - 1))
            {

                NameResolver reso = new NameResolver(GetGlobals(), scanner);
                BaseTypeInfo info = null;
                FunctionInfo func = null;
                string[] words = IntellisenseHelper.DotPath(editor.Document, curOfs - 2, line - 1);
                if (words.Length > 1)
                {
                    for (int i = 0; i < words.Length; ++i)
                    {
                        if (i == words.Length - 1 && info != null)
                        {
                            if (info is TypeInfo)
                                func = ((TypeInfo)info).Functions.FirstOrDefault(f => f.Name.Equals(words[i]));
                        }
                        else
                        {
                            if (info == null)
                            {
                                info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, words[i]);
                            }
                            else if (info != null && info is TypeInfo)
                            {
                                if (((TypeInfo)info).Properties.ContainsKey(words[i]))
                                    info = ((TypeInfo)info).Properties[words[i]];
                            }
                        }
                    }
                }
                if (func != null && info != null)
                {
                    List<FunctionInfo> data = new List<FunctionInfo>();
                    if (info is TypeInfo)
                    {
                        TypeInfo ti = (TypeInfo)info;
                        foreach (FunctionInfo fi in ti.Functions.Where(f => { return f.Name.Equals(func.Name); }))
                            data.Add(fi);
                        if (data.Count > 0)
                        {
                            OverloadInsightWindow window = new OverloadInsightWindow(editor.TextArea);
                            window.Provider = new OverloadProvider(ti, data.ToArray());
                            window.Show();
                            //compWindow.Closed += comp_Closed;
                        }
                    }
                }
                else if (func == null && info == null) // Found nothing
                {
                    List<FunctionInfo> data = new List<FunctionInfo>();
                    foreach (FunctionInfo fi in GetGlobals().GetFunctions(words[0], true))
                        data.Add(fi);
                    if (data.Count > 0)
                    {
                        OverloadInsightWindow window = new OverloadInsightWindow(editor.TextArea);
                        window.Provider = new OverloadProvider(null, data.ToArray());
                        window.Show();
                        //compWindow.Closed += comp_Closed;
                    }
                }
            }
            else if (Char.IsLetter(KEY))
            {
                if (currentComp != null || editor.TextArea.Caret.Line == 1)
                    return;

                int ofs = TextUtilities.GetNextCaretPosition(editor.Document, curOfs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                int nextOfs = TextUtilities.GetNextCaretPosition(editor.Document, ofs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                if (nextOfs > 0)
                {
                    if (editor.Document.Text[nextOfs] == '.')
                        return;
                }
                string word = "";
                if (ofs < 0)
                    return;
                for (; ofs < curOfs; ++ofs)
                {
                    if (editor.Document.Text[ofs] != '.')
                        word += editor.Document.Text[ofs];
                }
                if (word.Contains("."))
                {
                    if (currentComp != null)
                        currentComp.Close();
                    //editor_KeyUp(sender, e);
                    return;
                }

                NameResolver reso = new NameResolver(GetGlobals(), scanner);
                List<string> suggestions = new List<string>();
                reso.GetNameMatch(editor.Document, editor.TextArea.Caret.Line - 2, word, ref suggestions);

                CompletionWindow compWindow = new CompletionWindow(editor.TextArea);
                compWindow.StartOffset = TextUtilities.GetNextCaretPosition(editor.Document, curOfs, LogicalDirection.Backward, CaretPositioningMode.WordStart);
                IList<ICompletionData> data = compWindow.CompletionList.CompletionData;
                //attempt local name resolution first
                if (suggestions.Count > 0)
                {
                    foreach (string str in suggestions) //text suggestions are of lower priority
                        data.Add(new BaseCompletionData(null, str) { Priority = 0.5 });
                }
                //Scan globals
                if (GetGlobals() != null)
                {
                    foreach (string str in GetGlobals().GetTypeInfoNames())
                    {
                        if (str.StartsWith(word))
                            data.Add(new ClassCompletionData(GetGlobals().GetTypeInfo(str)));
                    }
                    foreach (FunctionInfo fun in GetGlobals().GetFunctions(null, true))
                    {
                        if (fun.Name.StartsWith(word))
                            data.Add(new FunctionCompletionData(fun));
                    }
                }
                if (data.Count > 0)
                {
                    currentComp = compWindow;
                    currentComp.Show();
                    currentComp.Closed += comp_Closed;
                }
                else if (currentComp != null)
                {
                    currentComp.Close();
                }
            }
        }
Esempio n. 32
0
        public void EditorMouseHover(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner scanner, MouseEventArgs e)
        {
            TextViewPosition? pos = editor.GetPositionFromPoint(e.GetPosition(editor));
            if (pos != null)
            {
                try
                {
                    int line = pos.Value.Line;
                    int offset = editor.Document.GetOffset(pos.Value.Location);
                    Globals globs = GetGlobals();
                    if (globs != null)
                    {
                        bool isFunc = false;
                        string[] words = IntellisenseHelper.ExtractPath(editor.Document, offset, pos.Value.Location.Line, out isFunc);
                        if (words != null && words.Length > 0)
                        {
                            BaseTypeInfo info = null;
                            FunctionInfo func = null;
                            NameResolver reso = new NameResolver(globs, scanner);
                            if (words.Length > 1)
                            {
                                for (int i = 0; i < words.Length; ++i)
                                {
                                    if (i == words.Length - 1 && info != null && isFunc)
                                    {
                                        if (info is TypeInfo)
                                            func = ((TypeInfo)info).Functions.FirstOrDefault(f => f.Name.Equals(words[i]));
                                    }
                                    else
                                    {
                                        if (info == null)
                                        {
                                            info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, words[i]);
                                        }
                                        else if (info != null && info is TypeInfo)
                                        {
                                            if (((TypeInfo)info).Properties.ContainsKey(words[i]))
                                                info = ((TypeInfo)info).Properties[words[i]];
                                        }
                                    }
                                }
                            }
                            else if (isFunc && words.Length == 1)
                            {
                                func = globs.GetFunction(words[0]);
                            }
                            else if (!isFunc && words.Length == 1)
                            {
                                info = reso.GetClassType(editor.Document, line, words[0]);
                                if (info == null)
                                {
                                    TypeInfo ty = globs.GetTypeInfo(words[0]);
                                    if (ty != null)
                                        info = ty;
                                }
                            }

                            string msg = "";
                            // Ask documentation for the information
                            if (info != null && func != null && info is TypeInfo)
                            { //member function
                                msg = func.ReturnType.Name + " " + func.Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(((TypeInfo)info).Name + "::" + func.Name + func.Inner);
                                if (m != null)
                                    msg += "\r\n" + m;
                            }
                            else if (func != null)
                            { //global function
                                msg = func.ReturnType.Name + " " + func.Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(func.Name + func.Inner);
                                if (m != null)
                                    msg += "\r\n" + m;
                            }
                            else if (info != null && info is TypeInfo)
                            { //global or member type
                                msg = ((TypeInfo)info).Name;
                                string m = IDEProject.inst().DocDatabase.GetDocumentationFor(((TypeInfo)info).Name);
                                if (m != null)
                                    msg += "\r\n" + m;
                            }

                            if (msg.Length > 0)
                            {
                                InsightWindow window = new InsightWindow(editor.TextArea);
                                window.Content = msg;
                                window.Show();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //deliberately swallow any exceptions here
                }
            }
        }