/// <summary>
        /// Gets the enclosing binder associated with the node
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        internal override Binder GetEnclosingBinderInternal(int position)
        {
            AssertPositionAdjusted(position);
            SyntaxToken token = this.Root.FindToken(position);

            // If we're before the start of the first token, just return
            // the binder for the compilation unit.
            if (position == 0 && position != token.SpanStart)
            {
                return(_binderFactory.GetBinder(this.Root, position, true).WithAdditionalFlags(GetSemanticModelBinderFlags()));
            }

            MemberSemanticModel memberModel = GetMemberModel(position);

            if (memberModel != null)
            {
                return(memberModel.GetEnclosingBinder(position));
            }

            return(_binderFactory.GetBinder(token).WithAdditionalFlags(GetSemanticModelBinderFlags()));
        }
Exemple #2
0
        private void AddDelegateMembers(
            ArrayBuilder <Symbol> symbols,
            DelegateDeclarationSyntax syntax,
            BinderFactory binderFactory,
            DiagnosticBag diagnostics)
        {
            var bodyBinder = binderFactory.GetBinder(syntax.ParameterList);

            // A delegate has the following members: (see CLI spec 13.6)
            // (1) a method named Invoke with the specified signature
            var invoke = new DelegateInvokeMethodImplementation(this, syntax, bodyBinder, diagnostics);

            invoke.CheckMethodVarianceSafety(diagnostics);
            symbols.Add(invoke);

            // (2) a constructor with argument types (object, System.IntPtr)
            symbols.Add(new DelegateConstructor(this, syntax, bodyBinder));

            var delegateBinder = new DelegateBinder(bodyBinder, this, invoke);

            // (3) BeginInvoke
            symbols.Add(new DelegateBeginInvokeMethod(this, syntax, delegateBinder, diagnostics));

            // and (4) EndInvoke methods
            symbols.Add(new DelegateEndInvokeMethod(this, syntax, delegateBinder, diagnostics));

            if (this.DeclaredAccessibility <= Accessibility.Private)
            {
                return;
            }

            if (!this.IsNoMoreVisibleThan(invoke.ReturnType))
            {
                // Inconsistent accessibility: return type '{1}' is less accessible than delegate '{0}'
                diagnostics.Add(ErrorCode.ERR_BadVisDelegateReturn, Locations[0], this, invoke.ReturnType);
            }

            foreach (var parameter in invoke.Parameters)
            {
                if (!parameter.Type.IsAtLeastAsVisibleAs(this))
                {
                    // Inconsistent accessibility: parameter type '{1}' is less accessible than delegate '{0}'
                    diagnostics.Add(ErrorCode.ERR_BadVisDelegateParam, Locations[0], this, parameter.Type);
                }
            }
        }
        private void AddDelegateMembers(
            ArrayBuilder<Symbol> symbols,
            DelegateDeclarationSyntax syntax,
            BinderFactory binderFactory,
            DiagnosticBag diagnostics)
        {
            var bodyBinder = binderFactory.GetBinder(syntax.ParameterList);

            // A delegate has the following members: (see CLI spec 13.6)
            // (1) a method named Invoke with the specified signature
            var invoke = new DelegateInvokeMethodImplementation(this, syntax, bodyBinder, diagnostics);
            invoke.CheckMethodVarianceSafety(diagnostics);
            symbols.Add(invoke);

            // (2) a constructor with argument types (object, System.IntPtr)
            symbols.Add(new DelegateConstructor(this, syntax, bodyBinder));

            var delegateBinder = new DelegateBinder(bodyBinder, this, invoke);

            // (3) BeginInvoke
            symbols.Add(new DelegateBeginInvokeMethod(this, syntax, delegateBinder, diagnostics));

            // and (4) EndInvoke methods
            symbols.Add(new DelegateEndInvokeMethod(this, syntax, delegateBinder, diagnostics));

            if (this.DeclaredAccessibility <= Accessibility.Private)
            {
                return;
            }

            if (!this.IsNoMoreVisibleThan(invoke.ReturnType))
            {
                // Inconsistent accessibility: return type '{1}' is less accessible than delegate '{0}'
                diagnostics.Add(ErrorCode.ERR_BadVisDelegateReturn, Locations[0], this, invoke.ReturnType);
            }

            foreach (var parameter in invoke.Parameters)
            {
                if (!parameter.Type.IsAtLeastAsVisibleAs(this))
                {
                    // Inconsistent accessibility: parameter type '{1}' is less accessible than delegate '{0}'
                    diagnostics.Add(ErrorCode.ERR_BadVisDelegateParam, Locations[0], this, parameter.Type);
                }
            }

        }
Exemple #4
0
        public void CrefTypeParameterEquality1()
        {
            var source = @"
/// <see cref=""C{Q}""/>
class C<T>
{
}
";

            var compilation = CreateCompilationWithMscorlibAndDocumentationComments(source);
            compilation.VerifyDiagnostics();

            var tree = compilation.SyntaxTrees.Single();
            var cref = GetCrefSyntaxes(compilation).Single();

            Func<Symbol> lookupSymbol = () =>
            {
                var factory = new BinderFactory(compilation, tree);
                var binder = factory.GetBinder(cref);
                var lookupResult = LookupResult.GetInstance();
                HashSet<DiagnosticInfo> useSiteDiagnostics = null;
                binder.LookupSymbolsSimpleName(
                    lookupResult,
                    qualifierOpt: null,
                    plainName: "Q",
                    arity: 0,
                    basesBeingResolved: null,
                    options: LookupOptions.Default,
                    diagnose: false,
                    useSiteDiagnostics: ref useSiteDiagnostics);
                Assert.Equal(LookupResultKind.Viable, lookupResult.Kind);
                var symbol = lookupResult.Symbols.Single();
                lookupResult.Free();
                Assert.NotNull(symbol);
                Assert.IsType<CrefTypeParameterSymbol>(symbol);
                return symbol;
            };

            var symbol1 = lookupSymbol();
            var symbol2 = lookupSymbol();
            Assert.Equal(symbol1, symbol2); // Required for correctness.
            Assert.NotSame(symbol1, symbol2); // Not required, just documenting.
        }
Exemple #5
0
        static int Main(string[] args)
        {
            const string usageMessage = "Usage:\nepoxy <configuration json file>";

            if (args.Length != 1 || args[0] == "-h" || args[0] == "--help")
            {
                Console.Error.WriteLine(usageMessage);
                return(-1);
            }

            string configurationJsonFilePath = args[0];

            if (!File.Exists(configurationJsonFilePath))
            {
                Console.Error.WriteLine($"Configuration file '{configurationJsonFilePath}' does not exist.");

                if (!Path.IsPathRooted(configurationJsonFilePath))
                {
                    Console.Error.WriteLine($"Path appears to be relative and the current working directory is '{Directory.GetCurrentDirectory()}'.");
                }

                return(-2);
            }

            Configuration config = JsonConvert.DeserializeObject <Configuration>(File.ReadAllText(configurationJsonFilePath));

            (bool configIsValid, string message) = config.Validate();
            if (!configIsValid)
            {
                if (!message.IsNullOrEmpty())
                {
                    Console.Error.WriteLine($"Invalid configuration: {message}");
                }

                return(-3);
            }

            Graph graph = GraphLoader.LoadGraph(Directory.EnumerateFiles(config.DoxygenXmlDirectory).Where(file => Path.GetExtension(file) == ".xml"));

            if (graph == null)
            {
                Console.Error.WriteLine("Failed to load C++ library definitions successfully.");
                return(-4);
            }

            foreach (BinderConfiguration binderConfig in config.Binders)
            {
                IBinder binder = BinderFactory.GetBinder(binderConfig);
                if (binder == null)
                {
                    Console.WriteLine($"Warning: language '{binderConfig.Language}' currently does not have a binder implemented-skipping.");
                    continue;
                }

                binder.GenerateNativeBindings(graph);
                binder.GenerateLanguageBindings(graph);
            }

            Console.WriteLine("SUCCESS");
            return(0);
        }