예제 #1
0
        private bool UpdateName(Function function)
        {
            if (function.TranslationUnit.Module != null)
                Generator.CurrentOutputNamespace = function.TranslationUnit.Module.OutputNamespace;

            var @params = function.Parameters.Where(p => p.Kind != ParameterKind.IndirectReturnType)
                                .Select(p => p.QualifiedType.ToString());
            // Include the conversion type in case of conversion operators
            var method = function as Method;
            if (method != null &&
                method.IsOperator &&
                (method.OperatorKind == CXXOperatorKind.Conversion ||
                 method.OperatorKind == CXXOperatorKind.ExplicitConversion))
                @params = @params.Concat(new[] { method.ConversionType.ToString() });
            var signature = string.Format("{0}({1})", function.Name, string.Join( ", ", @params));
            signature = FixSignatureForConversions(function, signature);

            if (Count == 0)
                Count++;

            if (!methodSignatures.ContainsKey(signature))
            {
                methodSignatures.Add(signature, 0);
                return false;
            }

            var methodCount = ++methodSignatures[signature];

            if (Count < methodCount + 1)
                Count = methodCount + 1;

            if (function.IsOperator)
            {
                // TODO: turn into a method; append the original type (say, "signed long")
                // of the last parameter to the type so that the user knows which overload is called
                diagnostics.Warning("Duplicate operator {0} ignored", function.Name);
                function.ExplicitlyIgnore();
            }
            else if (method != null && method.IsConstructor)
            {
                diagnostics.Warning("Duplicate constructor {0} ignored", function.Name);
                function.ExplicitlyIgnore();
            }
            else
                function.Name += methodCount.ToString(CultureInfo.InvariantCulture);
            return true;
        }
예제 #2
0
        public override bool VisitFunctionDecl(Function function)
        {
            if (function.GenerationKind == GenerationKind.None)
                return false;

            if (function.Parameters.Any(param => IsStdType(param.QualifiedType)))
            {
                function.ExplicitlyIgnore();
                return false;
            }

            return true;
        }
예제 #3
0
        static bool CheckDefaultParameters(Function function, Function overload)
        {
            var commonParameters = Math.Min(function.Parameters.Count, overload.Parameters.Count);

            var i = 0;
            for (; i < commonParameters; ++i)
            {
                var funcParam = function.Parameters[i];
                var overloadParam = overload.Parameters[i];

                if (!funcParam.QualifiedType.Equals(overloadParam.QualifiedType))
                    return false;
            }

            for (; i < function.Parameters.Count; ++i)
            {
                var funcParam = function.Parameters[i];
                if (!funcParam.HasDefaultValue)
                    return false;
            }

            for (; i < overload.Parameters.Count; ++i)
            {
                var overloadParam = overload.Parameters[i];
                if (!overloadParam.HasDefaultValue)
                    return false;
            }

            if (function.Parameters.Count > overload.Parameters.Count)
                overload.ExplicitlyIgnore();
            else
                function.ExplicitlyIgnore();

            return true;
        }
예제 #4
0
        public override bool VisitFunctionDecl(Function function)
        {
            if (!VisitDeclaration(function))
                return false;

            var ret = function.ReturnType;

            string msg;
            if (HasInvalidType(ret.Type, out msg))
            {
                function.ExplicitlyIgnore();
                Log.Debug("Function '{0}' was ignored due to {1} return decl",
                    function.Name, msg);
                return false;
            }

            foreach (var param in function.Parameters)
            {
                if (HasInvalidDecl(param, out msg))
                {
                    function.ExplicitlyIgnore();
                    Log.Debug("Function '{0}' was ignored due to {1} param",
                        function.Name, msg);
                    return false;
                }

                if (HasInvalidType(param.Type, out msg))
                {
                    function.ExplicitlyIgnore();
                    Log.Debug("Function '{0}' was ignored due to {1} param",
                        function.Name, msg);
                    return false;
                }

                var decayedType = param.Type.Desugar() as DecayedType;
                if (decayedType != null)
                {
                    function.ExplicitlyIgnore();
                    Log.Debug("Function '{0}' was ignored due to unsupported decayed type param",
                        function.Name);
                    return false;
                }

                if (param.Kind == ParameterKind.IndirectReturnType)
                {
                    Class retClass;
                    param.Type.Desugar().TryGetClass(out retClass);
                    if (retClass == null)
                    {
                        function.ExplicitlyIgnore();
                        Log.Debug(
                            "Function '{0}' was ignored due to an indirect return param not of a tag type",
                            function.Name);
                        return false;
                    }
                }
            }

            return true;
        }
예제 #5
0
        private static bool CheckSingleParameterPointerConstnessForAmbiguity(
            Function function, Function overload)
        {
            var functionParams = function.Parameters.Where(
                p => p.Kind == ParameterKind.Regular).ToList();
            // It's difficult to handle this case for more than one parameter
            // For example, if we have:
            //     void f(float&, const int&);
            //     void f(const float&, int&);
            // what should we do? Generate both? Generate the first one encountered?
            // Generate the one with the least amount of "complex" parameters?
            // So let's just start with the simplest case for the time being
            if (functionParams.Count != 1)
                return false;
            var overloadParams = overload.Parameters.Where(
                p => p.Kind == ParameterKind.Regular).ToList();
            if (overloadParams.Count != 1)
                return false;

            var parameterFunction = functionParams[0];
            var parameterOverload = overloadParams[0];

            var pointerParamFunction = parameterFunction.Type.Desugar() as PointerType;
            var pointerParamOverload = parameterOverload.Type.Desugar() as PointerType;

            if (pointerParamFunction == null || pointerParamOverload == null)
                return false;

            if (!pointerParamFunction.GetPointee().Equals(pointerParamOverload.GetPointee()))
                return false;

            if (parameterFunction.IsConst && !parameterOverload.IsConst)
            {
                function.ExplicitlyIgnore();
                return true;
            }

            if (parameterOverload.IsConst && !parameterFunction.IsConst)
            {
                overload.ExplicitlyIgnore();
                return true;
            }

            if (pointerParamFunction.Modifier == PointerType.TypeModifier.RVReference &&
                pointerParamOverload.Modifier != PointerType.TypeModifier.RVReference)
            {
                function.ExplicitlyIgnore();
                return true;
            }

            if (pointerParamFunction.Modifier != PointerType.TypeModifier.RVReference &&
                pointerParamOverload.Modifier == PointerType.TypeModifier.RVReference)
            {
                overload.ExplicitlyIgnore();
                return true;
            }

            return false;
        }