コード例 #1
0
		internal AnonymousCallableType(TypeSystemServices services, CallableSignature signature)
		{
			if (null == services)
				throw new ArgumentNullException("services");
			if (null == signature)
				throw new ArgumentNullException("signature");
			_typeSystemServices = services;
			_signature = signature;
		}
コード例 #2
0
		public ICallableType GetCallableType(CallableSignature signature)
		{
			AnonymousCallableType type = GetCachedCallableType(signature);
			if (type == null)
			{
				type = new AnonymousCallableType(TypeSystemServices, signature);
				_cache.Add(signature, type);
			}
			return type;
		}
コード例 #3
0
ファイル: InternalCallableType.cs プロジェクト: 0xb1dd1e/boo
		public CallableSignature GetSignature()
		{
			if (null == _signature)
			{
				IMethod invoke = GetInvokeMethod();
				if (null == invoke) return null;
				_signature = invoke.CallableType.GetSignature();
			}
			return _signature;
		}
コード例 #4
0
        /// <summary>
        /// Gets the names of the type parameters in the provided method.
        /// </summary>
        /// <param name="MethodSignature">The method's signature</param>
        /// <returns>A list of all of the method's type parameter names.</returns>
        private List <string> GetTypeParameterNames(CallableSignature MethodSignature)
        {
            List <string> typeParameterNames = new List <string>();

            foreach (QsSymbol symbol in MethodSignature.TypeParameters)
            {
                string name = GetSymbolName(symbol);
                typeParameterNames.Add(name);
            }

            return(typeParameterNames);
        }
コード例 #5
0
        /// <summary>
        /// Gets a list of names for each of the parameters in a method.
        /// </summary>
        /// <param name="MethodSignature">The signature of the method to process</param>
        /// <returns>A list of all of the method's parameter names.</returns>
        private List <string> GetParameterNames(CallableSignature MethodSignature)
        {
            List <string> parameterNames = new List <string>();

            // The method's parameters will all be encapsulated into one large tuple, so it can be
            // processed the same way as a nested tuple parameter.
            QsTuple <Tuple <QsSymbol, QsType> > .QsTuple parameterTuple =
                (QsTuple <Tuple <QsSymbol, QsType> > .QsTuple)MethodSignature.Argument;
            ProcessTupleParameter(parameterTuple, parameterNames);

            return(parameterNames);
        }
コード例 #6
0
 public CallableSignature GetSignature()
 {
     if (null == _signature)
     {
         IMethod invoke = GetInvokeMethod();
         if (null == invoke)
         {
             return(null);
         }
         _signature = invoke.CallableType.GetSignature();
     }
     return(_signature);
 }
コード例 #7
0
        int GetByRefParamCount(CallableSignature signature)
        {
            int count = 0;

            foreach (IParameter param in signature.Parameters)
            {
                if (param.IsByRef)
                {
                    ++count;
                }
            }
            return(count);
        }
コード例 #8
0
        private void InferInputTypesFromContextType(ICallableType type)
        {
            CallableSignature sig = type.GetSignature();

            for (int i = 0; i < Math.Min(ParameterTypes.Length, sig.Parameters.Length); i++)
            {
                if (ParameterTypes[i] != null)
                {
                    continue;
                }
                ParameterTypes[i] = sig.Parameters[i].Type;
            }
        }
コード例 #9
0
        public virtual IType MapCallableType(AnonymousCallableType sourceType)
        {
            CallableSignature signature = sourceType.GetSignature();

            IType returnType = MapType(signature.ReturnType);

            IParameter[] parameters = MapParameters(signature.Parameters);

            CallableSignature mappedSignature = new CallableSignature(
                parameters, returnType, signature.AcceptVarArgs);

            return(TypeSystemServices.GetCallableType(mappedSignature));
        }
コード例 #10
0
        /// <summary>
        /// Yields the generic parameters used in a (bound) type.
        /// </summary>
        public static IEnumerable <IGenericParameter> FindGenericParameters(IType type)
        {
            IGenericParameter genericParameter = type as IGenericParameter;

            if (genericParameter != null)
            {
                yield return(genericParameter);

                yield break;
            }

            if (type is IArrayType)
            {
                foreach (IGenericParameter gp in FindGenericParameters(type.ElementType))
                {
                    yield return(gp);
                }
                yield break;
            }

            if (type.ConstructedInfo != null)
            {
                foreach (IType typeArgument in type.ConstructedInfo.GenericArguments)
                {
                    foreach (IGenericParameter gp in FindGenericParameters(typeArgument))
                    {
                        yield return(gp);
                    }
                }
                yield break;
            }

            ICallableType callableType = type as ICallableType;

            if (callableType != null)
            {
                CallableSignature signature = callableType.GetSignature();
                foreach (IGenericParameter gp in FindGenericParameters(signature.ReturnType))
                {
                    yield return(gp);
                }
                foreach (IParameter parameter in signature.Parameters)
                {
                    foreach (IGenericParameter gp in FindGenericParameters(parameter.Type))
                    {
                        yield return(gp);
                    }
                }
                yield break;
            }
        }
コード例 #11
0
        public CallableSignature GetSignature()
        {
            if (_signature == null)
            {
                CallableSignature definitionSignature = ((ICallableType)_definition).GetSignature();

                IParameter[] parameters = GenericMapping.MapParameters(definitionSignature.Parameters);
                IType returnType = GenericMapping.MapType(definitionSignature.ReturnType);

                _signature = new CallableSignature(parameters, returnType);
            }

            return _signature;
        }
コード例 #12
0
        private void CheckEventUnsubscribe(BinaryExpression node, IEvent eventInfo)
        {
            CallableSignature expected = ((ICallableType)eventInfo.Type).GetSignature();
            CallableSignature actual   = GetCallableSignature(node.Right);

            if (expected != actual)
            {
                Warnings.Add(
                    CompilerWarningFactory.InvalidEventUnsubscribe(
                        node,
                        eventInfo.FullName,
                        expected));
            }
        }
コード例 #13
0
        public CallableSignature GetSignature()
        {
            if (_signature == null)
            {
                CallableSignature definitionSignature = ((ICallableType)_definition).GetSignature();

                IParameter[] parameters = GenericMapping.MapParameters(definitionSignature.Parameters);
                IType        returnType = GenericMapping.MapType(definitionSignature.ReturnType);

                _signature = new CallableSignature(parameters, returnType);
            }

            return(_signature);
        }
コード例 #14
0
        private void ProcessMethodImplementation(Method method, IMethod baseMethod)
        {
            IMethod           methodEntity  = GetEntity(method);
            CallableSignature baseSignature = TypeSystemServices.GetOverriddenSignature(baseMethod, methodEntity);

            if (IsUnknown(methodEntity.ReturnType))
            {
                method.ReturnType = CodeBuilder.CreateTypeReference(baseSignature.ReturnType);
            }
            else if (baseSignature.ReturnType != methodEntity.ReturnType)
            {
                Error(CompilerErrorFactory.ConflictWithInheritedMember(method, methodEntity, baseMethod));
            }
        }
コード例 #15
0
        private void InitializeDependencies(IGenericParameter[] genericParameters, CallableSignature signature)
        {
            IType[] parameterTypes = GetParameterTypes(signature);

            foreach (IType parameterType in parameterTypes)
            {
                ICallableType callableParameterType = parameterType as ICallableType;
                if (callableParameterType == null)
                {
                    continue;
                }
                CalculateDependencies(callableParameterType.GetSignature());
            }
        }
コード例 #16
0
        void ImplementRegularICallableCall(
            Method call,
            InternalCallableType type,
            ClassDefinition node,
            CallableSignature signature)
        {
            MethodInvocationExpression mie = CreateInvokeInvocation(type);

            IParameter[] parameters            = signature.Parameters;
            int          fixedParametersLength = signature.AcceptVarArgs ? parameters.Length - 1 : parameters.Length;

            for (int i = 0; i < fixedParametersLength; ++i)
            {
                SlicingExpression slice = CodeBuilder.CreateSlicing(
                    CodeBuilder.CreateReference(call.Parameters[0]),
                    i);
                mie.Arguments.Add(slice);
            }

            if (signature.AcceptVarArgs)
            {
                if (parameters.Length == 1)
                {
                    mie.Arguments.Add(CodeBuilder.CreateReference(call.Parameters[0]));
                }
                else
                {
                    mie.Arguments.Add(
                        CodeBuilder.CreateMethodInvocation(
                            RuntimeServices_GetRange1,
                            CodeBuilder.CreateReference(call.Parameters[0]),
                            CodeBuilder.CreateIntegerLiteral(fixedParametersLength)));
                }
            }

            if (TypeSystemServices.VoidType == signature.ReturnType)
            {
                call.Body.Add(mie);
            }
            else
            {
                call.Body.Add(new ReturnStatement(mie));
            }
            CheckMethodGenerics(call, node);
        }
コード例 #17
0
        private bool InferCallableType(ICallableType formalType, IType actualType, TypeInference inference)
        {
            ICallableType callableActualType = actualType as ICallableType;

            if (callableActualType == null)
            {
                return(false);
            }

            CallableSignature formalSignature = formalType.GetSignature();
            CallableSignature actualSignature = callableActualType.GetSignature();

            if (formalSignature.AcceptVarArgs)
            {
                if (actualSignature.Parameters.Length < formalSignature.Parameters.Length)
                {
                    return(false);
                }
            }
            else if (formalSignature.Parameters.Length != actualSignature.Parameters.Length)
            {
                return(false);
            }

            // Infer return type, maintaining inference direction
            if (!Infer(formalSignature.ReturnType, actualSignature.ReturnType, inference))
            {
                return(false);
            }

            // Infer parameter types, inverting inference direction
            for (int i = 0; i < formalSignature.Parameters.Length; ++i)
            {
                bool inferenceSuccessful = Infer(
                    formalSignature.Parameters[i].Type,
                    actualSignature.Parameters[i].Type,
                    Invert(inference));

                if (!inferenceSuccessful)
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #18
0
        void ImplementICallableCall(InternalCallableType type, ClassDefinition node)
        {
            Method call = (Method)node.Members["Call"];

            Debug.Assert(null != call);
            Debug.Assert(0 == call.Body.Statements.Count);

            CallableSignature signature = type.GetSignature();
            int byRefCount = GetByRefParamCount(signature);

            if (byRefCount > 0)
            {
                ImplementByRefICallableCall(call, type, node, signature, byRefCount);
            }
            else
            {
                ImplementRegularICallableCall(call, type, node, signature);
            }
        }
コード例 #19
0
        private void InitializeArguments(ExpressionCollection arguments)
        {
            _typedArguments = new TypedArgument[arguments.Count];
            CallableSignature methodSignature = GenericMethod.CallableType.GetSignature();
            int   count      = Math.Min(arguments.Count, methodSignature.Parameters.Length);
            IType formalType = null;

            for (int i = 0; i < count; i++)
            {
                formalType = methodSignature.Parameters[i].Type;
                if (GenericMethod.AcceptVarArgs && i == count - 1)
                {
                    formalType = formalType.ElementType;
                }
                _typedArguments[i] = new TypedArgument(arguments[i], formalType);
            }

            for (int i = count; i < arguments.Count; i++)
            {
                _typedArguments[i] = new TypedArgument(arguments[i], GenericMethod.AcceptVarArgs ? formalType : null);
            }
        }
コード例 #20
0
        public Method CreateEndInvokeMethod(ICallableType anonymousType)
        {
            CallableSignature signature = anonymousType.GetSignature();
            Method            method    = CodeBuilder.CreateRuntimeMethod("EndInvoke", signature.ReturnType);

            int delta = 1;

            foreach (IParameter p in signature.Parameters)
            {
                if (p.IsByRef)
                {
                    method.Parameters.Add(
                        CodeBuilder.CreateParameterDeclaration(++delta,
                                                               p.Name,
                                                               p.Type,
                                                               true));
                }
            }
            delta = method.Parameters.Count;
            method.Parameters.Add(
                CodeBuilder.CreateParameterDeclaration(delta + 1, "result", TypeSystemServices.Map(typeof(IAsyncResult))));
            return(method);
        }
コード例 #21
0
 private IType[] GetParameterTypes(CallableSignature signature)
 {
     return(Array.ConvertAll <IParameter, IType>(
                signature.Parameters,
                delegate(IParameter p) { return p.Type; }));
 }
コード例 #22
0
        void ImplementICallableCall(InternalCallableType type, ClassDefinition node)
        {
            Method call = (Method)node.Members["Call"];

            Debug.Assert(null != call);
            Debug.Assert(0 == call.Body.Statements.Count);

            CallableSignature          signature = type.GetSignature();
            MethodInvocationExpression mie       = CodeBuilder.CreateMethodInvocation(
                CodeBuilder.CreateSelfReference(type),
                type.GetInvokeMethod());

            int          byrefcount    = 0;
            ILocalEntity invokeresults = null;

            ILocalEntity[]      tempvals;
            IParameter[]        parameters = signature.Parameters;
            ReferenceExpression args       = null;

            foreach (IParameter param in parameters)
            {
                if (param.IsByRef)
                {
                    ++byrefcount;
                }
            }

            tempvals = new InternalLocal[byrefcount];

            if (parameters.Length > 0)
            {
                args = CodeBuilder.CreateReference(call.Parameters[0]);
            }

            int byrefindex = 0;

            for (int i = 0; i < parameters.Length; ++i)
            {
                SlicingExpression slice = CodeBuilder.CreateSlicing(args.CloneNode(), i);

                if (parameters[i].IsByRef)
                {
                    tempvals[byrefindex] = CodeBuilder.DeclareLocal(call,
                                                                    "__temp_" + parameters[i].Name,
                                                                    parameters[i].Type);

                    call.Body.Add(
                        CodeBuilder.CreateAssignment(
                            CodeBuilder.CreateReference(tempvals[byrefindex]),
                            CodeBuilder.CreateCast(
                                parameters[i].Type,
                                slice)));

                    mie.Arguments.Add(CodeBuilder.CreateReference(tempvals[byrefindex]));

                    ++byrefindex;
                }
                else
                {
                    mie.Arguments.Add(slice);
                }
            }

            if (TypeSystemServices.VoidType == signature.ReturnType)
            {
                call.Body.Add(mie);
            }
            else if (byrefcount > 0)
            {
                invokeresults = CodeBuilder.DeclareLocal(call,
                                                         "__result", signature.ReturnType);
                call.Body.Add(
                    CodeBuilder.CreateAssignment(
                        CodeBuilder.CreateReference(invokeresults),
                        mie));
            }

            byrefindex = 0;
            for (int i = 0; i < parameters.Length; ++i)
            {
                if (parameters[i].IsByRef)
                {
                    SlicingExpression slice = CodeBuilder.CreateSlicing(args.CloneNode(), i);

                    call.Body.Add(
                        CodeBuilder.CreateAssignment(
                            slice,
                            CodeBuilder.CreateReference(tempvals[byrefindex])));

                    ++byrefindex;
                }
            }

            if (TypeSystemServices.VoidType != signature.ReturnType)
            {
                if (byrefcount > 0)
                {
                    call.Body.Add(new ReturnStatement(
                                      CodeBuilder.CreateReference(invokeresults)));
                }
                else
                {
                    call.Body.Add(new ReturnStatement(mie));
                }
            }
        }
コード例 #23
0
        ClassDefinition CreateAdaptor(ICallableType to, ICallableType from)
        {
            BooClassBuilder adaptor = CodeBuilder.CreateClass("$adaptor$" + from.Name + "$" + to.Name + "$" + _adaptors.Count);

            adaptor.AddBaseType(TypeSystemServices.ObjectType);
            adaptor.Modifiers = TypeMemberModifiers.Final | TypeMemberModifiers.Internal;

            Field callable = adaptor.AddField("$from", from);

            BooMethodBuilder     constructor = adaptor.AddConstructor();
            ParameterDeclaration param       = constructor.AddParameter("from", from);

            constructor.Body.Add(
                CodeBuilder.CreateSuperConstructorInvocation(TypeSystemServices.ObjectType));
            constructor.Body.Add(
                CodeBuilder.CreateAssignment(
                    CodeBuilder.CreateReference(callable),
                    CodeBuilder.CreateReference(param)));

            CallableSignature signature = to.GetSignature();
            BooMethodBuilder  invoke    = adaptor.AddMethod("Invoke", signature.ReturnType);

            foreach (IParameter parameter in signature.Parameters)
            {
                invoke.AddParameter(parameter.Name, parameter.Type, parameter.IsByRef);
            }
            MethodInvocationExpression mie = CodeBuilder.CreateMethodInvocation(
                CodeBuilder.CreateReference(callable),
                GetInvokeMethod(from));
            int fromParameterCount = from.GetSignature().Parameters.Length;

            for (int i = 0; i < fromParameterCount; ++i)
            {
                mie.Arguments.Add(
                    CodeBuilder.CreateReference(invoke.Parameters[i]));
            }
            if (signature.ReturnType != TypeSystemServices.VoidType &&
                from.GetSignature().ReturnType != TypeSystemServices.VoidType)
            {
                invoke.Body.Add(new ReturnStatement(mie));
            }
            else
            {
                invoke.Body.Add(mie);
            }

            BooMethodBuilder adapt = adaptor.AddMethod("Adapt", to);

            adapt.Modifiers = TypeMemberModifiers.Static | TypeMemberModifiers.Public;
            param           = adapt.AddParameter("from", from);
            adapt.Body.Add(
                new ReturnStatement(
                    CodeBuilder.CreateConstructorInvocation(
                        to.GetConstructors().First(),
                        CodeBuilder.CreateConstructorInvocation(
                            (IConstructor)constructor.Entity,
                            CodeBuilder.CreateReference(param)),
                        CodeBuilder.CreateAddressOfExpression(invoke.Entity))));

            RegisterAdaptor(to, from, adaptor.ClassDefinition);

            return(adaptor.ClassDefinition);
        }
コード例 #24
0
        Method CreateInvokeMethod(AnonymousCallableType anonymousType)
        {
            CallableSignature signature = anonymousType.GetSignature();

            return(CodeBuilder.CreateRuntimeMethod("Invoke", signature.ReturnType, signature.Parameters, signature.AcceptVarArgs));
        }
コード例 #25
0
		public IType GetConcreteCallableType(Node sourceNode, CallableSignature signature)
		{
			var type = GetCallableType(signature);
			var anonymous = type as AnonymousCallableType;
			return anonymous != null ? GetConcreteCallableType(sourceNode, anonymous) : type;
		}
コード例 #26
0
 private IType[] GetParameterTypes(CallableSignature signature)
 {
     return Array.ConvertAll<IParameter, IType>(
         signature.Parameters,
         delegate(IParameter p) { return p.Type; });
 }
コード例 #27
0
 private void CalculateDependencies(CallableSignature signature)
 {
     foreach (IType inputType in GetParameterTypes(signature))
     {
         CalculateDependencies(inputType, signature.ReturnType);
     }
 }
コード例 #28
0
 public static CompilerWarning InvalidEventUnsubscribe(Node node, string eventName, CallableSignature expected)
 {
     return(new CompilerWarning("BCW0005", AstUtil.SafeLexicalInfo(node), eventName, expected));
 }
コード例 #29
0
        void ImplementByRefICallableCall(
            Method call,
            InternalCallableType type,
            ClassDefinition node,
            CallableSignature signature,
            int byRefCount)
        {
            MethodInvocationExpression mie = CreateInvokeInvocation(type);

            IParameter[]        parameters = signature.Parameters;
            ReferenceExpression args       = CodeBuilder.CreateReference(call.Parameters[0]);

            InternalLocal[] temporaries = new InternalLocal[byRefCount];

            int byRefIndex = 0;

            for (int i = 0; i < parameters.Length; ++i)
            {
                SlicingExpression slice = CodeBuilder.CreateSlicing(args.CloneNode(), i);

                IParameter parameter = parameters[i];
                if (parameter.IsByRef)
                {
                    IType tempType = parameter.Type;
                    if (tempType.IsByRef)
                    {
                        tempType = tempType.GetElementType();
                    }
                    temporaries[byRefIndex] = CodeBuilder.DeclareLocal(call,
                                                                       "__temp_" + parameter.Name,
                                                                       tempType);

                    call.Body.Add(
                        CodeBuilder.CreateAssignment(
                            CodeBuilder.CreateReference(temporaries[byRefIndex]),
                            CodeBuilder.CreateCast(
                                tempType,
                                slice)));

                    mie.Arguments.Add(
                        CodeBuilder.CreateReference(
                            temporaries[byRefIndex]));

                    ++byRefIndex;
                }
                else
                {
                    mie.Arguments.Add(slice);
                }
            }

            if (TypeSystemServices.VoidType == signature.ReturnType)
            {
                call.Body.Add(mie);
                PropagateByRefParameterChanges(call, parameters, temporaries);
            }
            else
            {
                InternalLocal invokeReturnValue = CodeBuilder.DeclareLocal(call,
                                                                           "__returnValue", signature.ReturnType);
                call.Body.Add(
                    CodeBuilder.CreateAssignment(
                        CodeBuilder.CreateReference(invokeReturnValue),
                        mie));
                PropagateByRefParameterChanges(call, parameters, temporaries);
                call.Body.Add(
                    new ReturnStatement(
                        CodeBuilder.CreateReference(invokeReturnValue)));
            }
        }
コード例 #30
0
		private AnonymousCallableType GetCachedCallableType(CallableSignature signature)
		{
			AnonymousCallableType result;
			_cache.TryGetValue(signature, out result);
			return result;
		}
コード例 #31
0
 bool AreParametersTheSame(TypeMember lhs, TypeMember rhs)
 {
     IParameter[] lhsParameters = GetParameters(lhs.Entity);
     IParameter[] rhsParameters = GetParameters(rhs.Entity);
     return(CallableSignature.AreSameParameters(lhsParameters, rhsParameters));
 }
コード例 #32
0
 /// <summary>
 /// Determines whether or not the method returns something based on its signature.
 /// </summary>
 /// <param name="MethodSignature">The signature of the method to process</param>
 /// <returns>True if it returns something, false if the return type is Unit.</returns>
 private bool CheckForReturnType(CallableSignature MethodSignature)
 {
     return(MethodSignature.ReturnType.Type != QsTypeKind <QsType, QsSymbol, QsSymbol, Affiliation> .UnitType);
 }
コード例 #33
0
        private void InitializeDependencies(IGenericParameter[] genericParameters, CallableSignature signature)
        {
            IType[] parameterTypes = GetParameterTypes(signature);

            foreach (IType parameterType in parameterTypes)
            {
                ICallableType callableParameterType = parameterType as ICallableType;
                if (callableParameterType == null) continue;
                CalculateDependencies(callableParameterType.GetSignature());
            }
        }
コード例 #34
0
 internal AnonymousCallableType(TypeSystemServices services, CallableSignature signature)
 {
     _typeSystemServices = services;
     _signature          = signature;
 }
コード例 #35
0
ファイル: AnonymousCallableType.cs プロジェクト: 0xb1dd1e/boo
		internal AnonymousCallableType(TypeSystemServices services, CallableSignature signature)
		{
			_typeSystemServices = services;
			_signature = signature;
		}