Esempio n. 1
0
function enum_name($typename)
{
    $proper = convert_typename($typename);
    if (strlen($proper) > 4 && substr($proper, 0, 4) == '_GTK') {
        return 'GTK_TYPE' . substr($proper, 4);
    } else {
        return 'GTK_TYPE' . $proper;
    }
}
Esempio n. 2
0
 function write_constructor($object)
 {
     $this->log_print("  %-20s ", "constructors");
     $num_written = $num_skipped = 0;
     $ctors = $this->parser->find_constructor($object, $this->overrides);
     $ctor_defs = array();
     $ctor_arginfos = '';
     if ($ctors) {
         $dict['class'] = $object->c_name;
         $dict['typecode'] = $object->typecode;
         $first = 1;
         foreach ($ctors as $ctor) {
             if ($this->overrides->is_deprecated($ctor->c_name)) {
                 $ctor->deprecated = $this->overrides->get_deprecated($ctor->c_name);
             }
             $ctor_name = $ctor->c_name;
             if ($first) {
                 $ctor_fe_name = '__construct';
                 $flags = 'ZEND_ACC_PUBLIC';
                 $template_name = 'constructor';
                 if (!$ctor->caller_owns_return) {
                     $dict['post_create_code'] = "\tg_object_ref(wrapped_obj);";
                 }
             } else {
                 // remove class name from the constructor name, i.e. turn
                 // gtk_button_new_with_mnemonic into new_with_mnemonic
                 $ctor_fe_name = substr($ctor_name, strlen(convert_typename($ctor->is_constructor_of)));
                 $flags = 'ZEND_ACC_PUBLIC|ZEND_ACC_STATIC';
                 $template_name = 'static_constructor';
             }
             $dict['ctor_with_props'] = false;
             /* Use simple no-prop constructor only for default constructors
                with no parameters. */
             if ($object->def_type == 'object' && !$ctor->params && $first) {
                 $template = Templates::constructor_without_props;
                 $dict['ctor_with_props'] = true;
             } else {
                 if ($object->def_type == 'object' && $ctor->properties) {
                     $template = Templates::constructor_with_props;
                     $dict['ctor_with_props'] = true;
                 } else {
                     $template = $this->template_map[$object->def_type][$template_name];
                 }
             }
             try {
                 list($arginfo, $reflection_func) = $this->genReflectionArgInfo($ctor, $object, $ctor_fe_name);
                 if ($overriden = $this->overrides->is_overriden($ctor_name)) {
                     list(, $ctor_override, $ctor_flags) = $this->overrides->get_override($ctor_name);
                     if (!empty($ctor_flags)) {
                         $flags = $ctor_flags;
                     }
                     $ctor_override = preg_replace('!^.*(PHP_METHOD).*$!m', "static \$1({$ctor->is_constructor_of}, {$ctor_fe_name})", $ctor_override);
                     $this->write_override($ctor_override, $ctor->c_name);
                 } else {
                     $dict['name'] = $ctor_fe_name;
                     $code = $this->write_callable($ctor, $template, false, false, $dict);
                     $this->fp->write($code);
                 }
                 $ctor_defs[] = sprintf(Templates::method_entry, $ctor->is_constructor_of, $ctor_fe_name, $reflection_func, $flags);
                 $this->divert("gen", "%s  %-11s %s::%s\n", $overriden ? "%%" : "  ", "constructor", $object->c_name, $ctor_fe_name);
                 $num_written++;
                 $this->cover["ctors"]->written();
                 if ($arginfo !== null) {
                     $ctor_arginfos .= $arginfo;
                 }
             } catch (Exception $e) {
                 $this->divert("notgen", "  %-11s %s::%s: %s\n", "constructor", $object->c_name, $ctor_fe_name, $e->getMessage());
                 $num_skipped++;
                 $this->cover["ctors"]->skipped();
                 // mark class as non-instantiable directly if we were trying
                 // to generate default constructor
                 if ($ctor_fe_name == '__construct') {
                     $ctor_defs[] = sprintf(Templates::function_entry, $ctor_fe_name, 'no_direct_constructor', $ctor_fe_name, 'no_direct_constructor');
                 }
             }
             $first = 0;
         }
     } else {
         if ($this->overrides->have_extra_methods($object->c_name)) {
             $ctor_name = '__construct';
             $extras = $this->overrides->get_extra_methods($object->c_name);
             if (isset($extras[$ctor_name])) {
                 $ctor_body = $extras[$ctor_name];
                 $ctor_body = preg_replace('!^.*(PHP_METHOD).*$!m', "static \$1({$object->c_name}, {$ctor_name})", $ctor_body);
                 $this->write_override($ctor_body, $object->c_name, $ctor_name);
                 $ctor_defs[] = sprintf(Templates::method_entry, $object->c_name, $ctor_name, 'NULL', 'ZEND_ACC_PUBLIC');
                 $this->divert("gen", "%%%%  %-11s %s::%s\n", "constructor", $object->c_name, $ctor_name);
                 $num_written++;
             }
         } else {
             // mark class as non-instantiable directly, only if it's not
             // GObject. For GObject's we let it chain up to GObject
             // constructor
             if ($object->def_type != 'object') {
                 $ctor_defs[] = sprintf(Templates::function_entry, '__construct', 'no_direct_constructor', '__construct', 'no_direct_constructor');
             }
         }
     }
     $this->log_print("(%d written, %d skipped)\n", $num_written, $num_skipped);
     return array($ctor_defs, $ctor_arginfos);
 }