Beispiel #1
0
    private static TypeSet Intersect(ImmutableArray <ITypeSymbol> a, ImmutableArray <ITypeSymbol> b)
    {
        if (a.IsDefault)
        {
            return(new TypeSet(b));
        }
        else if (b.IsDefault)
        {
            return(new TypeSet(a));
        }
        else
        {
            TypeSet intersection = Empty;

            //
            // TODO: this seem ... inefficient
            //
            for (Int32 i = 0; i < a.Length; i++)
            {
                for (Int32 j = 0; j < b.Length; j++)
                {
                    if (a[i].IsAssignableTo(b[j]))
                    {
                        intersection.Add(b);
                    }
                    else if (b[j].IsAssignableTo(a[i]))
                    {
                        intersection.Add(a);
                    }
                }
            }

            return(intersection);
        }
    }
Beispiel #2
0
        public override Scene Process(Scene input, ContentProcessorContext context)
        {
            Dictionary <int, UnityObject> idMap = new Dictionary <int, UnityObject>();

            input.AfterLoad(idMap);
            scene = input;

            // Create static batch renderers
            CreateStaticBatchRenderers(context, idMap);
            PurgeColliders();

            foreach (Component cmp in scene.components)
            {
                Type tp = cmp.GetType();
                if (!assembliesUsed.Contains(tp.Assembly))
                {
                    assembliesUsed.Add(tp.Assembly);
                }
            }

            TypeSet tc = new TypeSet();

            foreach (Assembly ass in assembliesUsed)
            {
                foreach (Type type in ass.GetTypes())
                {
                    tc.Add(type);
                }
            }
            scene.typeCaps = tc.ToList();
            Application.Reset();
            scene.hasBeenProcessed = true;
            return(input);
        }
Beispiel #3
0
    internal TypeSet Add(IEnumerable <ITypeSymbol> types)
    {
        TypeSet union = this;

        foreach (ITypeSymbol type in types)
        {
            union = union.Add(type);
        }

        return(union);
    }
    private static void AnalyzeConstructorBody(OperationAnalysisContext context)
    {
        IConstructorBodyOperation operation = ((IConstructorBodyOperation)context.Operation);
        Compilation compilation             = context.Compilation;

        TypeSet exceptions = GetIgnoredExceptionSet(compilation);

        IMethodSymbol symbol = operation.GetSymbol();

        if (symbol.IsStatic)
        {
            foreach (CrefSyntax cref in operation.GetDeclarationSyntax().GetDocumentedExceptions())
            {
                Diagnostic diagnostic = Diagnostic.Create(
                    descriptor: Descriptors.StaticConstructorsShouldNotThrowExceptions,
                    location: cref.Ancestors().OfType <XmlNodeSyntax>().FirstOrDefault()?.GetLocation()
                    );

                context.ReportDiagnostic(diagnostic);
            }

            context.ReportUndocumentedExceptions(
                descriptorForThrow: Descriptors.StaticConstructorsShouldNotThrowExceptions,
                descriptorForInvocation: Descriptors.StaticConstructorsShouldCatchCalleeExceptions,
                documented: exceptions,
                exceptions: operation.GetExceptionalOperations(compilation)
                );
        }
        else
        {
            exceptions = exceptions.Add(operation.GetDocumentedExceptions());

            context.ReportUndocumentedExceptions(
                descriptorForThrow: Descriptors.DocumentThrownExceptions,
                descriptorForInvocation: Descriptors.DocumentCalleeExceptions,
                documented: exceptions,
                exceptions: operation.GetExceptionalOperations(compilation)
                );

            if (operation.Initializer is null)
            {
                //
                // HACK: Implicit/compiler-generated calls to parameterless base-class constructors are
                //       not included in the operation hierarchy and need to be handled explicitly.
                //
                if (
                    (symbol is IMethodSymbol constructor) && !constructor.IsStatic &&
                    (constructor.ContainingType is INamedTypeSymbol type) && (type.TypeKind == TypeKind.Class) &&
                    (type.BaseType is INamedTypeSymbol baseType) &&
                    (baseType.GetParameterlessInstanceConstructor() is IMethodSymbol baseParameterlessConstructor)
                    )
                {
                    Location location = operation.GetDeclarationSyntax().GetIdentifierLocations().First();

                    //
                    // TODO: better diagnostic message which refers to the implicit parameterless constructor call
                    //
                    context.ReportUndocumentedExceptions(
                        descriptorForThrow: Descriptors.DocumentThrownExceptions,
                        descriptorForInvocation: Descriptors.DocumentCalleeExceptions,
                        documented: exceptions,
                        exceptions: baseParameterlessConstructor
                        .GetDocumentedExceptions(compilation)
                        .Select(exception => new ExceptionalOperation(location, baseParameterlessConstructor, exception))
                        );
                }
            }
        }
    }
Beispiel #5
0
        public bool Match(SourceStream source, out StructType result)
        {
            result = null;

            if (!source.IsValid())
            {
                return(false);
            }

            var slice = source.GetSlice();

            if (!slice.MatchString(KeywordStruct))
            {
                return(false);
            }

            SkipCommentsAndWhitespace(slice);

            if (!slice.ReadWord(out string name))
            {
                throw new ParseError("expected struct name.", slice);
            }

            if (!name.IsNameLegal())
            {
                slice.MoveBy(-name.Length);
                throw new ParseError($"'{name}' is not a legal struct name.", slice);
            }

            SkipCommentsAndWhitespace(slice);

            if (!slice.MatchString(TokenStructFirst))
            {
                throw new ParseError($"expeceted '{TokenStructFirst}'.", slice);
            }

            var members = new TypeSet();

            while (slice.IsValid())
            {
                SkipCommentsAndWhitespace(slice);

                if (slice.MatchString(TokenStructFinal))
                {
                    break;
                }

                if (!Match(slice, out MemberType member))
                {
                    throw new ParseError("failed to parse member.", slice);
                }

                members.Add(member.Ordinal(), member);
            }

            var span = source.Join(slice);

            result = new StructType(name, members, span);

            return(true);
        }