Ejemplo n.º 1
0
        public virtual void AddProperty(MemberAddInfo member)
        {
            var desc = GetDescriptor(member.Name);

            VariableDef def = desc.Getter;

            if (def == null)
            {
                desc.Getter = def = new VariableDef();
            }

            FunctionValue func;

            if (member.Value is LazyPropertyFunctionValue)
            {
                func = member.Value as LazyPropertyFunctionValue;
            }
            else
            {
                func = new ReturningFunctionValue(ProjectEntry, member.Name, member.Value.Proxy);
            }
            def.AddTypes(ProjectState._builtinEntry, func.Proxy);
        }
        private void GenerateMethod(ExpandoValue exports, Dictionary<string, FunctionSpecializer> specialMethods, dynamic method) {
            string methodName = (string)method["name"];

            ObjectValue returnValue = null;
            if (methodName.StartsWith("create") && methodName.Length > 6) {
                string klassName = methodName.Substring(6);
                PropertyDescriptorValue propDesc;
                if (exports.Descriptors.TryGetValue(klassName, out propDesc) && propDesc.Values != null) {
                    var types = propDesc.Values.Types;
                    if (types != null && types.Count == 1) {
                        var type = types.First().Value;
                        if (type is FunctionValue) {
                            returnValue = ((FunctionValue)type)._instance;
                        }
                    }
                }
            }

            foreach (var sig in method["signatures"]) {
                BuiltinFunctionValue function;
                FunctionSpecializer specialMethod;
                if (specialMethods != null &&
                    specialMethods.TryGetValue(methodName, out specialMethod)) {
                    function = specialMethod.Specialize(
                        exports.ProjectEntry,
                        methodName,
                        ParseDocumentation((string)method["desc"]),
                        returnValue,
                        GetParameters(sig["params"])
                    );
                } else if (returnValue != null) {
                    function = new ReturningFunctionValue(
                        exports.ProjectEntry,
                        methodName,
                        returnValue.SelfSet,
                        ParseDocumentation((string)method["desc"]),
                        GetParameters(sig["params"])
                    );
                } else {
                    function = new BuiltinFunctionValue(
                        exports.ProjectEntry,
                        methodName,
                        ParseDocumentation((string)method["desc"]),
                        null,
                        GetParameters(sig["params"])
                    );
                }

                exports.Add(function);
            }
        }