Class construction methods
4723
function add( key, value ) {
		var desc;
		switch ( typeof value ) {
			case 'object'   : desc = util.type( value ) == 'descriptor' ? value : util.describe( { value : value }, 'cw' );          break;
			case 'function' : desc = util.describe( make_method( 'parent', value, get_method_descriptor( this, key ), key ), 'cw' ); break;
			default         : desc = util.describe( value, 'cew' );
		}
		util.def( this, key, desc, true );
		return this.constructor;
	}
1005597
function detect_class_members_from_object(cls, ast) {
  cls["members"] = []
  return each_pair_in_object_expression(ast, function(key, value, pair) {
    detect_method_or_property(cls, key, value, pair);
  });
}
752969
def instantiate(self, cls=None):
        
        if cls is None:
            cls = self.cls
        if cls is None:
            raise TypeError("cls must a class")
        return cls.create(*self.args, **self.kwargs)
676849
def create(cls, class_name: str, monoid_type=Union[Monoid, str]):
        

        def unit(cls, value):
            if hasattr(monoid_type, "empty"):
                log = monoid_type.empty()
            else:
                log = monoid_type()

            return cls(value, log)

        return type(class_name, (Writer, ), dict(unit=classmethod(unit)))
715329
def build_class(name, basenames=(), doc=None):
    """"""
    node = nodes.ClassDef(name, doc)
    for base in basenames:
        basenode = nodes.Name()
        basenode.name = base
        node.bases.append(basenode)
        basenode.parent = node
    return node
529278
function GENERATE_CLASSES(classes, parent) {
  return _.reduce(classes, function(memo, classSpec, className) {
    return memo
      + GENERATE_CLASS(className, classSpec.description, parent, classSpec.parent)
      + _.reduce(classSpec.methods, function(memo, methodSpec, methodName) {
        return memo += GENERATE_METHOD(methodName, methodSpec, className);
      }, '') 
      + _.reduce(classSpec.variables, function(memo, variableSpec, variableName) {
        return memo += GENERATE_VAR(variableName, variableSpec, className);
      }, '')
      + _.reduce(classSpec.enums, function(memo, enumSpec, enumName) {
        return memo += GENERATE_ENUM(enumName, enumSpec, className);
      }, '');
  }, '');
}
591951
function PseudoClass() {
			// Optimization: Requiring the new keyword and avoiding usage of Object.create() increases performance by 5x
			if (this instanceof PseudoClass === false) {
				throw new Error('Cannot create instance without new operator');
			}

			// Set properties
			var propertyDescriptors = PseudoClass.properties;
			if (propertyDescriptors) {
				Object.defineProperties(this, propertyDescriptors);
			}

			// Optimization: Avoiding conditionals in constructor increases performance of instantiation by 2x
			this.construct.apply(this, arguments);

			this.init();
		}
928521
def factory(cls, class_name):
        
        class_name = str(class_name.lstrip('_'))
        types = ParseResource.__subclasses__()
        while types:
            t = types.pop()
            if t.__name__ == class_name:
                return t
            types.extend(t.__subclasses__())
        else:
            return type(class_name, (Object,), {})
927955
private function createInternalClasses()
    {
        \danog\MadelineProto\Logger::log('Creating internal classes...', \danog\MadelineProto\Logger::NOTICE);
        $handle = fopen(dirname(__FILE__).'/InternalDoc.php', 'w');
        foreach ($this->methods->by_id as $id => $data) {
            if (!strpos($data['method'], '.')) {
                continue;
            }
            list($namespace, $method) = explode('.', $data['method']);
            if (!in_array($namespace, $this->get_method_namespaces())) {
                continue;
            }
            $type = str_replace(['.', '<', '>'], ['_', '_of_', ''], $data['type']);
            foreach ($data['params'] as $param) {
                if (in_array($param['name'], ['flags', 'random_id'])) {
                    continue;
                }
                $stype = 'type';
                if (isset($param['subtype'])) {
                    $stype = 'subtype';
                }
                $ptype = str_replace('.', '_', $param[$stype]);
                switch ($ptype) {
                    case 'true':
                    case 'false':
                        $ptype = 'boolean';
                }
                $internalDoc[$namespace][$method]['attr'][$param['name']] = $ptype;
            }
            if ($type === 'Bool') {
                $type = strtolower($type);
            }
            $internalDoc[$namespace][$method]['return'] = $type;
        }
        fwrite($handle, "<?php\n");
        fwrite($handle, "/**\n");
        fwrite($handle, " * This file is automatic generated by build_docs.php file\n");
        fwrite($handle, " * and is used only for autocomplete in multiple IDE\n");
        fwrite($handle, " * don't modify manually.\n");
        fwrite($handle, " */\n\n");
        fwrite($handle, "namespace danog\\MadelineProto;\n");
        foreach ($internalDoc as $namespace => $methods) {
            fwrite($handle, "\ninterface {$namespace}\n{");
            foreach ($methods as $method => $properties) {
                fwrite($handle, "\n    /**\n");
                if (isset($properties['attr'])) {
                    fwrite($handle, "     * @param array params [\n");
                    foreach ($properties['attr'] as $name => $type) {
                        fwrite($handle, "     *               {$type} {$name},\n");
                    }
                    fwrite($handle, "     *              ]\n");
                    fwrite($handle, "     *\n");
                }
                fwrite($handle, "     * @return {$properties['return']}\n");
                fwrite($handle, "     */\n");
                fwrite($handle, "    public function {$method}(");
                if (isset($properties['attr'])) {
                    fwrite($handle, 'array $params');
                }
                fwrite($handle, ");\n");
            }
            fwrite($handle, "}\n");
        }
        fclose($handle);
    }
725852
def classmethod(self, encoding):
        """"""
        # Add encodings for hidden self and cmd arguments.
        encoding = ensure_bytes(encoding)
        typecodes = parse_type_encoding(encoding)
        typecodes.insert(1, b'@:')
        encoding = b''.join(typecodes)

        def decorator(f):
            def objc_class_method(objc_cls, objc_cmd, *args):
                py_cls = ObjCClass(objc_cls)
                py_cls.objc_cmd = objc_cmd
                args = convert_method_arguments(encoding, args)
                result = f(py_cls, *args)
                if isinstance(result, ObjCClass):
                    result = result.ptr.value
                elif isinstance(result, ObjCInstance):
                    result = result.ptr.value
                return result
            name = f.__name__.replace('_', ':')
            self.add_class_method(objc_class_method, name, encoding)
            return objc_class_method
        return decorator
935881
private function buildObjects(): void
    {
        //deep dependency level, start to array end for not use array_reverse
        for ($i = \count($this->tree) - 1; $i >= 0; $i--) {

            //class
            foreach ($this->tree[$i] as $class => $arguments) {

                //try to find object in class
                $object = $this->cache[$class] ?? null;

                //if object is not in cache and need arguments try to build
                if ($object === null && \count($arguments)) {

                    //build arguments
                    $args = $this->buildArguments($class, $arguments);

                    //store object with dependencies in cache
                    $this->cache[$class] = (new ReflectionClass($class))->newInstanceArgs($args);

                    continue;
                }

                if ($object === null) {

                    //store object in cache
                    $this->cache[$class] = (new ReflectionClass($class))->newInstance();
                }
            }
        }
    }
1968
function _class (Constructor, members, Base) {
    var ResultConstructor;
    if (Base) {
        ResultConstructor = function () {
            Base.apply(this, arguments);
            Constructor.apply(this, arguments);
        };
        ResultConstructor.prototype = new Base();
    } else {
        ResultConstructor = function () {
            Constructor.apply(this, arguments);
        };
    }
    if (members) {
        Object.keys(members).forEach(function (memberName) {
            ResultConstructor.prototype[memberName] = members[memberName];
        });
    }
    return ResultConstructor;
}
711599
def _build_superclass_lists(self):
        
        cls_dict = self.all_classes
        for cls in list(cls_dict.values()):
            cls.all_superclasses = []
            superclass = cls.superclass
            try:
                while superclass:
                    superclass_obj = cls_dict[superclass]
                    cls.all_superclasses.append(superclass_obj)
                    superclass = superclass_obj.superclass
            except KeyError:
                print("Missing superclass: " + superclass)
124024
def _generate_constructor(cls, names):
        """"""

        cache = cls._constructors
        if names in cache:
            return cache[names]
        elif len(cache) > 3:
            cache.clear()

        func = generate_constructor(cls, names)
        cache[names] = func
        return func
393361
function construct(constructor, args) {
            var dynamicClass = function () {
                return new (constructor.bind.apply(constructor, [void 0].concat(args)))();
            };
            dynamicClass.prototype = constructor.prototype;
            return new dynamicClass();
        }
411935
def class_factory(name, base_class, class_dict):
    """"""

    def __init__(self, tcex):
        base_class.__init__(self, tcex)
        for k, v in class_dict.items():
            setattr(self, k, v)

    newclass = type(str(name), (base_class,), {'__init__': __init__})
    return newclass
183353
def build_model(self, n_features, n_classes):
        
        self._create_placeholders(n_features, n_classes)
        self._create_variables(n_features, n_classes)

        self.mod_y = tf.nn.softmax(
            tf.add(tf.matmul(self.input_data, self.W_), self.b_))

        self.cost = self.loss.compile(self.mod_y, self.input_labels)
        self.train_step = tf.train.GradientDescentOptimizer(
            self.learning_rate).minimize(self.cost)
        self.accuracy = Evaluation.accuracy(self.mod_y, self.input_labels)