Example #1
0
        public override void Run()
        {
            if (!TypeSystemServices.CompilerGeneratedTypesModuleExists())
            {
                return;
            }

            var cgm            = TypeSystemServices.GetCompilerGeneratedTypesModule();
            var callableFinder = new TypeFinder(new TypeCollector(type => type.ParentNamespace == cgm.Entity));

            foreach (var module in CompileUnit.Modules)
            {
                if (module != cgm)
                {
                    module.Accept(callableFinder);
                }
            }

            var foundSet = new HashSet <IType>(callableFinder.Results);
            var count    = 0;

            while (foundSet.Count > count)
            {
                count = foundSet.Count;
                var sweeper = new TypeFinder(new TypeCollector(type => foundSet.Contains(type)));
                cgm.Accept(sweeper);
                foreach (var swept in sweeper.Results)
                {
                    foundSet.Add(swept);
                }
            }

            var rejects = cgm.Members
                          .Cast <TypeDefinition>()
                          .Where(td => !td.Name.Contains("$adaptor$") && !foundSet.Contains(td.Entity));

            foreach (var type in rejects)
            {
                cgm.Members.Remove(type);
            }
        }
Example #2
0
        private IType CreateConcreteCallableType(Node sourceNode, AnonymousCallableType anonymousType)
        {
            var module = TypeSystemServices.GetCompilerGeneratedTypesModule();

            var name = GenerateCallableTypeNameFrom(sourceNode, module);

            ClassDefinition cd = My <CallableTypeBuilder> .Instance.CreateEmptyCallableDefinition(name);

            cd.Annotate(AnonymousCallableTypeAnnotation);
            cd.Modifiers  |= TypeMemberModifiers.Public;
            cd.LexicalInfo = sourceNode.LexicalInfo;

            cd.Members.Add(CreateInvokeMethod(anonymousType));

            Method beginInvoke = CreateBeginInvokeMethod(anonymousType);

            cd.Members.Add(beginInvoke);

            cd.Members.Add(CreateEndInvokeMethod(anonymousType));
            AddGenericTypes(cd);
            module.Members.Add(cd);
            return((IType)cd.Entity);
        }
 void RegisterAdaptor(ICallableType to, ICallableType from, ClassDefinition adaptor)
 {
     _adaptors.Add(new AdaptorRecord(to, from, adaptor));
     TypeSystemServices.GetCompilerGeneratedTypesModule().Members.Add(adaptor);
 }