internal static CSDiagnosticInfo Add(this DiagnosticBag diagnostics, ErrorCode code, Location location, ImmutableArray <Symbol> symbols, params object[] args)
        {
            var info = new CSDiagnosticInfo(code, args, symbols, ImmutableArray <Location> .Empty);
            var diag = new CSDiagnostic(info, location);

            diagnostics.Add(diag);
            return(info);
        }
        /// <summary>
        /// Add a diagnostic to the bag.
        /// </summary>
        /// <param name="diagnostics"></param>
        /// <param name="code"></param>
        /// <param name="location"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        internal static CSDiagnosticInfo Add(this DiagnosticBag diagnostics, ErrorCode code, Location location, params object[] args)
        {
            var info = new CSDiagnosticInfo(code, args);
            var diag = new CSDiagnostic(info, location);

            diagnostics.Add(diag);
            return(info);
        }
Beispiel #3
0
        private static bool TryGetBuilderMember <TSymbol>(
            SyntheticBoundNodeFactory F,
            WellKnownMember?member,
            NamedTypeSymbol builderType,
            bool customBuilder,
            out TSymbol symbol)
            where TSymbol : Symbol
        {
            if (!member.HasValue)
            {
                symbol = null;
                return(true);
            }

            WellKnownMember memberValue = member.Value;

            if (customBuilder)
            {
                var descriptor = WellKnownMembers.GetDescriptor(memberValue);
                var sym        = CSharpCompilation.GetRuntimeMember(
                    builderType.OriginalDefinition,
                    ref descriptor,
                    F.Compilation.WellKnownMemberSignatureComparer,
                    accessWithinOpt: null);
                if ((object)sym != null)
                {
                    sym = sym.SymbolAsMember(builderType);
                }
                symbol = sym as TSymbol;
            }
            else
            {
                symbol = F.WellKnownMember(memberValue, isOptional: true) as TSymbol;
                if ((object)symbol != null)
                {
                    symbol = (TSymbol)symbol.SymbolAsMember(builderType);
                }
            }
            if ((object)symbol == null)
            {
                var descriptor = WellKnownMembers.GetDescriptor(memberValue);
                var diagnostic = new CSDiagnostic(
                    new CSDiagnosticInfo(ErrorCode.ERR_MissingPredefinedMember, (customBuilder ? (object)builderType : descriptor.DeclaringTypeMetadataName), descriptor.Name),
                    F.Syntax.Location);
                F.Diagnostics.Add(diagnostic);
                return(false);
            }
            return(true);
        }
Beispiel #4
0
        private static PropertySymbol GetCustomTaskProperty(
            SyntheticBoundNodeFactory F,
            NamedTypeSymbol builderType,
            NamedTypeSymbol returnType)
        {
            const string propertyName = "Task";
            var          members      = builderType.GetMembers(propertyName);

            foreach (var member in members)
            {
                if (member.Kind != SymbolKind.Property)
                {
                    continue;
                }
                var property = (PropertySymbol)member;
                if ((property.DeclaredAccessibility == Accessibility.Public) &&
                    !property.IsStatic &&
                    (property.ParameterCount == 0))
                {
                    if (!property.Type.TypeSymbol.Equals(returnType, TypeCompareKind.AllIgnoreOptions))
                    {
                        var badTaskProperty = new CSDiagnostic(
                            new CSDiagnosticInfo(ErrorCode.ERR_BadAsyncMethodBuilderTaskProperty, builderType, returnType, property.Type.TypeSymbol),
                            F.Syntax.Location);
                        F.Diagnostics.Add(badTaskProperty);
                        return(null);
                    }

                    return(property);
                }
            }
            var diagnostic = new CSDiagnostic(
                new CSDiagnosticInfo(ErrorCode.ERR_MissingPredefinedMember, builderType, propertyName),
                F.Syntax.Location);

            F.Diagnostics.Add(diagnostic);
            return(null);
        }
        internal static void Add(this DiagnosticBag diagnostics, DiagnosticInfo info, Location location)
        {
            var diag = new CSDiagnostic(info, location);

            diagnostics.Add(diag);
        }