Inheritance: AbstractType, ICallableType
Esempio n. 1
0
        private void CreateCallableTypeBeginInvokeExtensions(AnonymousCallableType anonymousType, Method beginInvoke)
        {
            ClassDefinition extensions = TypeSystemServices.GetCompilerGeneratedExtensionsClass();

            extensions.Members.Add(CreateBeginInvokeCallbackOnlyExtension(anonymousType, beginInvoke));
            extensions.Members.Add(CreateBeginInvokeSimplerExtension(anonymousType, beginInvoke));
        }
Esempio n. 2
0
        private AnonymousCallableType GetCachedCallableType(CallableSignature signature)
        {
            AnonymousCallableType result = null;

            _cache.TryGetValue(signature, out result);
            return(result);
        }
Esempio n. 3
0
        protected virtual IType CreateConcreteCallableType(Node sourceNode, AnonymousCallableType anonymousType)
        {
            Module module = GetAnonymousTypesModule();

            string          name = string.Format("___callable{0}", module.Members.Count);
            ClassDefinition cd   = CreateCallableDefinition(name);

            cd.Modifiers  |= TypeMemberModifiers.Public;
            cd.LexicalInfo = sourceNode.LexicalInfo;

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

            Method beginInvoke = CreateBeginInvokeMethod(anonymousType);

            cd.Members.Add(beginInvoke);

            // XXX: find an alternative way to support BeginInvoke overloads...
            if (Version1)
            {
                cd.Members.Add(CreateBeginInvokeCallbackOnlyOverload(anonymousType, beginInvoke));
                cd.Members.Add(CreateBeginInvokeSimplerOverload(anonymousType, beginInvoke));
            }

            cd.Members.Add(CreateEndInvokeMethod(anonymousType));
            _anonymousTypesModule.Members.Add(cd);

            return((IType)cd.Entity);
        }
Esempio n. 4
0
 public IType GetConcreteCallableType(Node sourceNode, AnonymousCallableType anonymousType)
 {
     if (null == anonymousType.ConcreteType)
     {
         anonymousType.ConcreteType = CreateConcreteCallableType(sourceNode, anonymousType);
     }
     return(anonymousType.ConcreteType);
 }
Esempio n. 5
0
        public AnonymousCallableType GetCallableType(CallableSignature signature)
        {
            AnonymousCallableType type = GetCachedCallableType(signature);

            if (type == null)
            {
                type = new AnonymousCallableType(TypeSystemServices, signature);
                _cache.Add(signature, type);
            }
            return(type);
        }
Esempio n. 6
0
        public AnonymousCallableType GetCallableType(CallableSignature signature)
        {
            AnonymousCallableType type = (AnonymousCallableType)_anonymousCallableTypes[signature];

            if (null == type)
            {
                type = new AnonymousCallableType(this, signature);
                _anonymousCallableTypes.Add(signature, type);
            }
            return(type);
        }
Esempio n. 7
0
        public IType GetConcreteExpressionType(Expression expression)
        {
            IType type = GetExpressionType(expression);
            AnonymousCallableType anonymousType = type as AnonymousCallableType;

            if (null != anonymousType)
            {
                IType concreteType = GetConcreteCallableType(expression, anonymousType);
                expression.ExpressionType = concreteType;
                return(concreteType);
            }
            return(type);
        }
Esempio n. 8
0
        private IType CreateConcreteCallableType(Node sourceNode, AnonymousCallableType anonymousType)
        {
            Module module = TypeSystemServices.GetCompilerGeneratedTypesModule();

            string          name = string.Format("___callable{0}", module.Members.Count);
            ClassDefinition cd   = TypeSystemServices.CreateCallableDefinition(name);

            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));
            module.Members.Add(cd);

            CreateCallableTypeBeginInvokeExtensions(anonymousType, beginInvoke);

            return((IType)cd.Entity);
        }
Esempio n. 9
0
 public virtual IType GetConcreteCallableType(Node sourceNode, AnonymousCallableType anonymousType)
 {
     return _anonymousCallablesManager.GetConcreteCallableType(sourceNode, anonymousType);
 }
Esempio n. 10
0
        public IType GetConcreteCallableType(Node sourceNode, CallableSignature signature)
        {
            AnonymousCallableType type = GetCallableType(signature);

            return(GetConcreteCallableType(sourceNode, type));
        }
Esempio n. 11
0
        Method CreateInvokeMethod(AnonymousCallableType anonymousType)
        {
            CallableSignature signature = anonymousType.GetSignature();

            return(CodeBuilder.CreateRuntimeMethod("Invoke", signature.ReturnType, signature.Parameters, signature.AcceptVarArgs));
        }
Esempio n. 12
0
        public AnonymousCallableType GetCallableType(CallableSignature signature)
        {
            AnonymousCallableType type = GetCachedCallableType(signature);

            if (type == null)
            {
                type = new AnonymousCallableType(TypeSystemServices, signature);
                _cache.Add(signature, type);
            }
            return type;
        }
Esempio n. 13
0
 Method CreateInvokeMethod(AnonymousCallableType anonymousType)
 {
     CallableSignature signature = anonymousType.GetSignature();
     return CodeBuilder.CreateRuntimeMethod("Invoke", signature.ReturnType, signature.Parameters, signature.AcceptVarArgs);
 }
Esempio n. 14
0
        private IType CreateConcreteCallableType(Node sourceNode, AnonymousCallableType anonymousType)
        {
            Module module = TypeSystemServices.GetCompilerGeneratedTypesModule();

            TypeMember enclosing = (sourceNode.GetAncestor(NodeType.ClassDefinition) ?? sourceNode.GetAncestor(NodeType.InterfaceDefinition) ?? sourceNode.GetAncestor(NodeType.EnumDefinition) ?? sourceNode.GetAncestor(NodeType.Module)) as TypeMember;
            string prefix = "";
            string postfix = "";
            if(enclosing != null)
            {
                prefix += enclosing.Name;
                enclosing = (sourceNode.GetAncestor(NodeType.Method)
                        ?? sourceNode.GetAncestor(NodeType.Property)
                        ?? sourceNode.GetAncestor(NodeType.Event)
                        ?? sourceNode.GetAncestor(NodeType.Field)) as TypeMember;
                if(enclosing != null)
                {
                    prefix += "_" + enclosing.Name;
                }
                prefix += "$";
            }
            else if (!sourceNode.LexicalInfo.Equals(LexicalInfo.Empty))
            {
                prefix += System.IO.Path.GetFileNameWithoutExtension(sourceNode.LexicalInfo.FileName) + "$";
            }
            if(!sourceNode.LexicalInfo.Equals(LexicalInfo.Empty))
            {
                postfix = "$" + sourceNode.LexicalInfo.Line + "_" + sourceNode.LexicalInfo.Column + postfix;
            }
            string name = "__" + prefix + "callable" + module.Members.Count + postfix + "__";
            ClassDefinition cd = TypeSystemServices.CreateCallableDefinition(name);
            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));
            module.Members.Add(cd);

            CreateCallableTypeBeginInvokeExtensions(anonymousType, beginInvoke);

            return (IType)cd.Entity;
        }
Esempio n. 15
0
 private void CreateCallableTypeBeginInvokeExtensions(AnonymousCallableType anonymousType, Method beginInvoke)
 {
     ClassDefinition extensions = TypeSystemServices.GetCompilerGeneratedExtensionsClass();
     extensions.Members.Add(CreateBeginInvokeCallbackOnlyExtension(anonymousType, beginInvoke));
     extensions.Members.Add(CreateBeginInvokeSimplerExtension(anonymousType, beginInvoke));
 }
Esempio n. 16
0
 public IType GetConcreteCallableType(Node sourceNode, AnonymousCallableType anonymousType)
 {
     if (null == anonymousType.ConcreteType)
     {
         anonymousType.ConcreteType = CreateConcreteCallableType(sourceNode, anonymousType);
     }
     return anonymousType.ConcreteType;
 }
Esempio n. 17
0
 public virtual IType GetConcreteCallableType(Node sourceNode, AnonymousCallableType anonymousType)
 {
     return(_anonymousCallablesManager.GetConcreteCallableType(sourceNode, anonymousType));
 }
Esempio n. 18
0
 public IType GetConcreteCallableType(Node sourceNode, AnonymousCallableType anonymousType)
 {
     return anonymousType.ConcreteType ??
            (anonymousType.ConcreteType = CreateConcreteCallableType(sourceNode, anonymousType));
 }