Save typedef symbols into a type_definitions.php file.
772360
private function SaveTypeDefToPHP()
    {
        $output_file = fopen(
            $this->definitions_path . "type_definitions.php", 
            "w"
        );
        
        fwrite($output_file, "<?php\n\n");
        
        fwrite($output_file, "use Peg\Lib\Definitions\Element\TypeDef;\n");
        
        foreach($this->symbols->headers as $header)
        {
            if(!$header->HasTypeDefs())
                continue;
            
            foreach($header->namespaces as $namespace)
            {
                if(!$namespace->HasTypeDefs())
                    continue;
                
                foreach($namespace->type_definitions as $typedef)
                {
                    $type = addslashes($typedef->original_type);
                    $description = addslashes($typedef->description);
                    $namespace_name = addslashes($namespace->name);
                    
                    $output = "\n";
                    $output .= '$symbols->AddTypeDef(' . "\n";
                    $output .= '    new TypeDef(' . "\n";
                    $output .= '        "'.$typedef->name.'",' . "\n";
                    $output .= '        "'.$type.'",' . "\n";
                    $output .= '        "'.$description.'"' . "\n";
                    $output .= '    ),' . "\n";
                    $output .= '    "'.$header->name.'",' . "\n";
                    $output .= '    "'.$namespace_name.'"' . "\n";
                    $output .= ');' . "\n";
                    
                    fwrite($output_file, $output);
                }
            }
        }
        
        fclose($output_file);
    }
772728
function toTypeRefs() {
    for (var _len = arguments.length, types = new Array(_len), _key = 0; _key < _len; _key++) {
      types[_key] = arguments[_key];
    }

    return types.map(toTypeRef);
  }
826218
def search_typedef(stmt, name):
    """"""
    mod = stmt.i_orig_module
    while stmt is not None:
        if name in stmt.i_typedefs:
            t = stmt.i_typedefs[name]
            if (mod is not None and
                mod != t.i_orig_module and
                t.i_orig_module.keyword == 'submodule'):
                # make sure this submodule is included
                if mod.search_one('include', t.i_orig_module.arg) is None:
                    return None
            return t
        stmt = stmt.parent
    return None
137142
def cdefs(features):
    

    code = ''

    # apparently the safest way to do this
    is_64bits = sys.maxsize > 2 ** 32

    # GType is an int the size of a pointer ... I don't think we can just use
    # size_t, sadly
    if is_64bits:
        code += '''
            typedef uint64_t GType;
        '''
    else:
        code += '''
            typedef uint32_t GType;
        '''

    code += '''
        typedef void (*GLogFunc) (const char* log_domain,
            int log_level,
            const char* message, void* user_data);
        int g_log_set_handler (const char* log_domain,
            int log_levels,
            GLogFunc log_func, void* user_data);

        extern "Python" void _log_handler_callback (const char*, int,
            const char*, void*);

        void g_log_remove_handler (const char* log_domain, int handler_id);

        typedef struct _VipsImage VipsImage;
        typedef struct _GValue GValue;

        void* g_malloc (size_t size);
        void g_free (void* data);
        int vips_free (void* a);

        void vips_leak_set (int leak);

        char* vips_path_filename7 (const char* path);
        char* vips_path_mode7 (const char* path);

        GType vips_type_find (const char* basename, const char* nickname);
        const char* vips_nickname_find (GType type);

        const char* g_type_name (GType gtype);
        GType g_type_from_name (const char* name);

        typedef void* (*VipsTypeMap2Fn) (GType type, void* a, void* b);
        void* vips_type_map (GType base, VipsTypeMap2Fn fn, void* a, void* b);

        const char* vips_error_buffer (void);
        void vips_error_clear (void);

        typedef struct _GValue {
            GType g_type;
            uint64_t data[2];
        } GValue;

        void g_value_init (GValue* value, GType gtype);
        void g_value_unset (GValue* value);
        GType g_type_fundamental (GType gtype);

        int vips_enum_from_nick (const char* domain,
            GType gtype, const char* str);
        const char *vips_enum_nick (GType gtype, int value);

        void g_value_set_boolean (GValue* value, int v_boolean);
        void g_value_set_int (GValue* value, int i);
        void g_value_set_uint64 (GValue* value, uint64_t ull);
        void g_value_set_double (GValue* value, double d);
        void g_value_set_enum (GValue* value, int e);
        void g_value_set_flags (GValue* value, unsigned int f);
        void g_value_set_string (GValue* value, const char* str);
        void vips_value_set_ref_string (GValue* value, const char* str);
        void g_value_set_object (GValue* value, void* object);
        void vips_value_set_array_double (GValue* value,
            const double* array, int n );
        void vips_value_set_array_int (GValue* value,
            const int* array, int n );
        void vips_value_set_array_image (GValue *value, int n);
        typedef int (*VipsCallbackFn)(void* a, void* b);
        void vips_value_set_blob (GValue* value,
            VipsCallbackFn free_fn, void* data, size_t length);

        int g_value_get_boolean (const GValue* value);
        int g_value_get_int (GValue* value);
        uint64_t g_value_get_uint64 (GValue* value);
        double g_value_get_double (GValue* value);
        int g_value_get_enum (GValue* value);
        unsigned int g_value_get_flags (GValue* value);
        const char* g_value_get_string (GValue* value);
        const char* vips_value_get_ref_string (const GValue* value,
            size_t* length);
        void* g_value_get_object (GValue* value);
        double* vips_value_get_array_double (const GValue* value, int* n);
        int* vips_value_get_array_int (const GValue* value, int* n);
        VipsImage** vips_value_get_array_image (const GValue* value, int* n);
        void* vips_value_get_blob (const GValue* value, size_t* length);

        // need to make some of these by hand
        GType vips_interpretation_get_type (void);
        GType vips_operation_flags_get_type (void);
        GType vips_band_format_get_type (void);
        GType vips_token_get_type (void);
        GType vips_saveable_get_type (void);
        GType vips_image_type_get_type (void);

        typedef struct _GData GData;

        typedef struct _GTypeClass GTypeClass;

        typedef struct _GTypeInstance {
            GTypeClass *g_class;
        } GTypeInstance;

        typedef struct _GObject {
            GTypeInstance g_type_instance;
            unsigned int ref_count;
            GData *qdata;
        } GObject;

        typedef struct _GParamSpec {
            GTypeInstance g_type_instance;

            const char* name;
            unsigned int flags;
            GType value_type;
            GType owner_type;

            // private, but cffi in API mode needs these to be able to get the
            // offset of any member
            char* _nick;
            char* _blurb;
            GData* qdata;
            unsigned int ref_count;
            unsigned int param_id;
        } GParamSpec;

        typedef struct _GEnumValue {
            int value;

            const char *value_name;
            const char *value_nick;
        } GEnumValue;

        typedef struct _GEnumClass {
          GTypeClass *g_type_class;

          int minimum;
          int maximum;
          unsigned int n_values;
          GEnumValue *values;
        } GEnumClass;

        void* g_type_class_ref (GType type);

        void g_object_ref (void* object);
        void g_object_unref (void* object);

        void g_object_set_property (GObject* object,
            const char *name, GValue* value);
        void g_object_get_property (GObject* object,
            const char* name, GValue* value);

        typedef struct _VipsObject {
    '''

    # this field changed name in libvips 8.4
    if _at_least(features, 8, 4):
        code += '''
            GObject parent_instance;
        '''
    else:
        code += '''
            GObject parent_object;
        '''

    code += '''
            bool constructed;
            bool static_object;
            void *argument_table;
            char *nickname;
            char *description;
            bool preclose;
            bool close;
            bool postclose;
            size_t local_memory;
        } VipsObject;

        typedef struct _VipsObjectClass VipsObjectClass;

        typedef struct _VipsArgument {
            GParamSpec *pspec;
        } VipsArgument;

        typedef struct _VipsArgumentInstance {
            VipsArgument parent;

            // more
        } VipsArgumentInstance;

        typedef enum _VipsArgumentFlags {
            VIPS_ARGUMENT_NONE = 0,
            VIPS_ARGUMENT_REQUIRED = 1,
            VIPS_ARGUMENT_CONSTRUCT = 2,
            VIPS_ARGUMENT_SET_ONCE = 4,
            VIPS_ARGUMENT_SET_ALWAYS = 8,
            VIPS_ARGUMENT_INPUT = 16,
            VIPS_ARGUMENT_OUTPUT = 32,
            VIPS_ARGUMENT_DEPRECATED = 64,
            VIPS_ARGUMENT_MODIFY = 128
        } VipsArgumentFlags;

        typedef struct _VipsArgumentClass {
            VipsArgument parent;

            VipsObjectClass *object_class;
            VipsArgumentFlags flags;
            int priority;
            unsigned int offset;
        } VipsArgumentClass;

        int vips_object_get_argument (VipsObject* object,
            const char *name, GParamSpec** pspec,
            VipsArgumentClass** argument_class,
            VipsArgumentInstance** argument_instance);

        void vips_object_print_all (void);

        int vips_object_set_from_string (VipsObject* object,
            const char* options);

        const char* vips_object_get_description (VipsObject* object);

        const char* g_param_spec_get_blurb (GParamSpec* pspec);

        typedef struct _VipsImage {
    '''

    # this field changed name in libvips 8.4
    if _at_least(features, 8, 4):
        code += '''
            VipsObject parent_instance;
        '''
    else:
        code += '''
            VipsObject parent_object;
        '''

    code += '''
            // more
        } VipsImage;

        const char* vips_foreign_find_load (const char* name);
        const char* vips_foreign_find_load_buffer (const void* data,
            size_t size);
        const char* vips_foreign_find_save (const char* name);
        const char* vips_foreign_find_save_buffer (const char* suffix);

        VipsImage* vips_image_new_matrix_from_array (int width, int height,
                const double* array, int size);
        VipsImage* vips_image_new_from_memory (const void* data, size_t size,
                int width, int height, int bands, int format);

        VipsImage* vips_image_copy_memory (VipsImage* image);

        GType vips_image_get_typeof (const VipsImage* image,
            const char* name);
        int vips_image_get (const VipsImage* image,
            const char* name, GValue* value_copy);
        void vips_image_set (VipsImage* image,
            const char* name, GValue* value);
        int vips_image_remove (VipsImage* image, const char* name);

        char* vips_filename_get_filename (const char* vips_filename);
        char* vips_filename_get_options (const char* vips_filename);

        VipsImage* vips_image_new_temp_file (const char* format);

        int vips_image_write (VipsImage* image, VipsImage* out);
        void* vips_image_write_to_memory (VipsImage* in, size_t* size_out);

        typedef struct _VipsInterpolate {
            VipsObject parent_object;

            // more
        } VipsInterpolate;

        VipsInterpolate* vips_interpolate_new (const char* name);

        typedef struct _VipsOperation {
            VipsObject parent_instance;

            // more
        } VipsOperation;

        VipsOperation* vips_operation_new (const char* name);

        typedef void* (*VipsArgumentMapFn) (VipsObject* object,
            GParamSpec* pspec,
            VipsArgumentClass* argument_class,
            VipsArgumentInstance* argument_instance,
            void* a, void* b);

        void* vips_argument_map (VipsObject* object,
            VipsArgumentMapFn fn, void* a, void* b);

        typedef struct _VipsRegion {
            GObject parent_object;

            // more
        } VipsRegion;

        VipsRegion* vips_region_new (VipsImage*);

        VipsOperation* vips_cache_operation_build (VipsOperation* operation);
        void vips_object_unref_outputs (VipsObject* object);

        int vips_operation_get_flags (VipsOperation* operation);

        void vips_cache_set_max (int max);
        void vips_cache_set_max_mem (size_t max_mem);
        void vips_cache_set_max_files (int max_files);
        void vips_cache_set_trace (int trace);

    '''

    if _at_least(features, 8, 5):
        code += '''
            char** vips_image_get_fields (VipsImage* image);
            int vips_image_hasalpha (VipsImage* image);

        '''

    if _at_least(features, 8, 6):
        code += '''
            GType vips_blend_mode_get_type (void);
            void vips_value_set_blob_free (GValue* value,
                void* data, size_t length);

        '''

    if _at_least(features, 8, 7):
        code += '''
            int vips_object_get_args (VipsObject* object,
                const char*** names, int** flags, int* n_args);

        '''

    if _at_least(features, 8, 8):
        code += '''
            char** vips_foreign_get_suffixes (void);

            void* vips_region_fetch (VipsRegion*, int, int, int, int,
                size_t* length);
            int vips_region_width (VipsRegion*);
            int vips_region_height (VipsRegion*);

        '''

    # we must only define these in API mode ... in ABI mode we need to call
    # these things earlier
    if features['api']:
        code += '''
            int vips_init (const char* argv0);
            int vips_version (int flag);
        '''

    # ... means inherit from C defines
    code += '#define VIPS_MAJOR_VERSION ...\n'
    code += '#define VIPS_MINOR_VERSION ...\n'
    code += '#define VIPS_MICRO_VERSION ...\n'

    # add contents of features as a comment ... handy for debugging
    for key, value in features.items():
        code += '//%s = %s\n' % (key, value)

    return code
774258
def declare_type_info(config):
    """"""
    settings = config.registry.settings
    settings['_type_info'] = []
    for line in settings['exports-allowable-types'].splitlines():
        if not line.strip():
            continue
        type_name, type_info = line.strip().split(':', 1)
        type_info = type_info.split(',', 3)
        settings['_type_info'].append((type_name, {
            'type_name': type_name,
            'file_extension': type_info[0],
            'mimetype': type_info[1],
            'user_friendly_name': type_info[2],
            'description': type_info[3],
            }))
1283762
private function SaveEnumerationsToJson()
    {
        $enumerations = array();
        
        foreach($this->symbols->headers as $header)
        {
            if(!$header->HasEnumerations())
                continue;
            
            foreach($header->namespaces as $namespace)
            {
                if(!$namespace->HasEnumerations())
                    continue;
                
                foreach($namespace->enumerations as $enumeration)
                {
                    if(trim($enumeration->description))
                    {
                        $enumerations[$header->name][$namespace->name]
                            [$enumeration->name] = [
                                "options" => $enumeration->options,
                                "description" => $enumeration->description
                            ]
                        ;
                    }
                    else
                    {
                        $enumerations[$header->name][$namespace->name]
                            [$enumeration->name] = [
                                "options" => $enumeration->options
                            ]
                        ;
                    }
                }
            }
        }
        
        if(count($enumerations) > 0)
        {
            file_put_contents(
                $this->definitions_path . "enumerations.json", 
                Json::Encode($enumerations)
            );

            unset($enumerations);
        }
    }
790946
function TypeDef(arity, type, repeats) {
  // arity for the parameter
  this.arity = arity;

  // type declarations as an array
  this.type = type;

  // does this value accumulate repeating declarations
  this.repeats = repeats;
}
468912
def typeinfo_to_ctypes(info, return_value=False):
    

    tag = info.tag.value
    ptr = info.is_pointer

    mapping = {
        GITypeTag.BOOLEAN: gboolean,
        GITypeTag.INT8: gint8,
        GITypeTag.UINT8: guint8,
        GITypeTag.INT16: gint16,
        GITypeTag.UINT16: guint16,
        GITypeTag.INT32: gint32,
        GITypeTag.UINT32: guint32,
        GITypeTag.INT64: gint64,
        GITypeTag.UINT64: guint64,
        GITypeTag.FLOAT: gfloat,
        GITypeTag.DOUBLE: gdouble,
        GITypeTag.VOID: None,
        GITypeTag.GTYPE: GType,
        GITypeTag.UNICHAR: gunichar,
    }

    if ptr:
        if tag == GITypeTag.INTERFACE:
            return gpointer
        elif tag in (GITypeTag.UTF8, GITypeTag.FILENAME):
            if return_value:
                # ctypes does auto conversion to str and gives us no chance
                # to free the pointer if transfer=everything
                return gpointer
            else:
                return gchar_p
        elif tag == GITypeTag.ARRAY:
            return gpointer
        elif tag == GITypeTag.ERROR:
            return GErrorPtr
        elif tag == GITypeTag.GLIST:
            return GListPtr
        elif tag == GITypeTag.GSLIST:
            return GSListPtr
        else:
            if tag in mapping:
                return ctypes.POINTER(mapping[tag])
    else:
        if tag == GITypeTag.INTERFACE:
            iface = info.get_interface()
            iface_type = iface.type.value
            if iface_type == GIInfoType.ENUM:
                return guint32
            elif iface_type == GIInfoType.OBJECT:
                return gpointer
            elif iface_type == GIInfoType.STRUCT:
                return gpointer
            elif iface_type == GIInfoType.UNION:
                return gpointer
            elif iface_type == GIInfoType.FLAGS:
                return guint
            elif iface_type == GIInfoType.CALLBACK:
                return GCallback

            raise NotImplementedError(
                "Could not convert interface: %r to ctypes type" % iface.type)
        else:
            if tag in mapping:
                return mapping[tag]

    raise NotImplementedError("Could not convert %r to ctypes type" % info.tag)
1293959
public function AddTypeDef(
        \Peg\Lib\Definitions\Element\TypeDef $typedef,
        $header,
        $namespace="\\"
    )
    {
        $this->AddHeader($header);

        $this->headers[$header]->AddTypeDef($typedef, $namespace);
    }
1281205
def _determine_uses(self, included_files, forward_declarations):
        """"""
        file_uses = dict.fromkeys(included_files, UNUSED)
        decl_uses = dict.fromkeys(forward_declarations, UNUSED)
        symbol_table = self.symbol_table

        for name, node in forward_declarations.items():
            try:
                symbol_table.lookup_symbol(node.name, node.namespace)
                decl_uses[name] |= USES_REFERENCE
            except symbols.Error:
                module = Module(name, None)
                symbol_table.add_symbol(node.name, node.namespace, node,
                                        module)

        def _do_lookup(name, namespace):
            try:
                file_use_node = symbol_table.lookup_symbol(name, namespace)
            except symbols.Error:
                return
            name = file_use_node[1].filename
            file_uses[name] = file_uses.get(name, 0) | USES_DECLARATION

        def _add_declaration(name, namespace):
            if not name:
                # Ignore anonymous struct. It is not standard, but we might as
                # well avoid crashing if it is easy.
                return

            names = [n for n in namespace if n is not None]
            if names:
                name = '::'.join(names) + '::' + name
            if name in decl_uses:
                decl_uses[name] |= USES_DECLARATION

        def _add_reference(name, namespace):
            try:
                file_use_node = symbol_table.lookup_symbol(name, namespace)
            except symbols.Error:
                return

            name = file_use_node[1].filename
            if file_use_node[1].ast_list is None:
                decl_uses[name] |= USES_REFERENCE
            elif name in file_uses:
                # enum and typedef can't be forward declared
                if isinstance(file_use_node[0], (ast.Enum, ast.Typedef)):
                    file_uses[name] |= USES_DECLARATION
                else:
                    file_uses[name] |= USES_REFERENCE

        def _add_use(node, namespace, name=''):
            if isinstance(node, basestring):
                name = node
            elif isinstance(node, list):
                # name contains a list of tokens.
                name = '::'.join([n.name for n in name])

            # node is a Type so look for its symbol immediately.
            if name:
                _do_lookup(name, namespace)
                return

            # Try to search for the value of the variable declaration for any
            # symbols, such as `#define` values or other variable names which
            # may be included in other files.
            obj = getattr(node, 'initial_value', None)
            if obj:
                _do_lookup(obj, namespace)

            # If node is a VariableDeclaration, check if the variable type is
            # a symbol used in other includes.
            obj = getattr(node, 'type', None)
            if obj and isinstance(obj.name, basestring):
                _do_lookup(obj.name, namespace)

            if not isinstance(node, basestring):
                # Happens when variables are defined with inlined types, e.g.:
                #   enum {...} variable;
                return

        def _add_variable(node, namespace, reference=False):
            obj = node.type if isinstance(
                node, ast.VariableDeclaration) else node

            if obj.reference or obj.pointer or reference:
                _add_reference(obj.name, namespace)
            else:
                # Add a use for the variable declaration type as well as the
                # variable value.
                _add_use(obj.name, namespace)
                _add_use(node, namespace)
            # This needs to recurse when the node is a templated type.
            _add_template_use(obj.name,
                              obj.templated_types,
                              namespace,
                              reference)

        def _process_function(function, namespace):
            reference = function.body is None
            if function.return_type:
                return_type = function.return_type
                _add_variable(return_type, namespace, reference)

            for s in function.specializations:
                _add_variable(s, namespace, not function.body)

            templated_types = function.templated_types or ()
            for p in function.parameters:
                node = p.type
                if node.name not in templated_types:
                    if function.body and p.name:
                        # Assume that if the function has a body and a name
                        # the parameter type is really used.
                        # NOTE(nnorwitz): this is over-aggressive. It would be
                        # better to iterate through the body and determine
                        # actual uses based on local vars and data members
                        # used.
                        _add_use(node.name, namespace)
                    elif (
                        p.default and
                        p.default[0].name != '0' and
                        p.default[0].name != 'NULL' and
                        p.default[0].name != 'nullptr'
                    ):
                        _add_use(node.name, namespace)
                    elif node.reference or node.pointer or reference:
                        _add_reference(node.name, namespace)
                    else:
                        _add_use(node.name, namespace)
                    _add_template_use(node.name,
                                      node.templated_types,
                                      namespace,
                                      reference)

        def _process_function_body(function, namespace):
            previous = None
            save = namespace[:]
            for t in function.body:
                if t.token_type == tokenize.NAME:
                    previous = t
                    if not keywords.is_keyword(t.name):
                        # TODO(nnorwitz): handle static function calls.
                        # TODO(nnorwitz): handle using statements in file.
                        # TODO(nnorwitz): handle using statements in function.
                        # TODO(nnorwitz): handle namespace assignment in file.
                        _add_use(t.name, namespace)
                elif t.name == '::' and previous is not None:
                    namespace.append(previous.name)
                elif t.name in (':', ';'):
                    namespace = save[:]

        def _add_template_use(name, types, namespace, reference=False):
            for cls in types or ():
                if cls.pointer or cls.reference or reference:
                    _add_reference(cls.name, namespace)
                elif name.endswith('_ptr'):
                    # Special case templated classes that end w/_ptr.
                    # These are things like auto_ptr which do
                    # not require the class definition, only decl.
                    _add_reference(cls.name, namespace)
                elif name.startswith('Q') and name.endswith('Pointer'):
                    # Special case templated classes from the Qt framework.
                    _add_reference(cls.name, namespace)
                else:
                    _add_use(cls.name, namespace)
                _add_template_use(cls.name, cls.templated_types,
                                  namespace, reference)

        def _process_types(nodes, namespace):
            for node in nodes:
                if isinstance(node, ast.Type):
                    _add_variable(node, namespace)

        # Iterate through the source AST/tokens, marking each symbols use.
        ast_seq = [self.ast_list]
        namespace_stack = []
        while ast_seq:
            for node in ast_seq.pop():
                if isinstance(node, ast.VariableDeclaration):
                    namespace = namespace_stack + node.namespace
                    _add_variable(node, namespace)
                elif isinstance(node, ast.Function):
                    namespace = namespace_stack + node.namespace
                    _process_function(node, namespace)
                    if node.body:
                        _process_function_body(node, namespace)
                elif isinstance(node, ast.Typedef):
                    namespace = namespace_stack + node.namespace
                    _process_types(node.alias, namespace)
                elif isinstance(node, ast.Friend):
                    expr = node.expr
                    namespace = namespace_stack + node.namespace
                    if isinstance(expr, ast.Type):
                        _add_reference(expr.name, namespace)
                    elif isinstance(expr, ast.Function):
                        _process_function(expr, namespace)
                elif isinstance(node, ast.Union) and node.body is not None:
                    ast_seq.append(node.body)
                elif isinstance(node, ast.Class) and node.body is not None:
                    _add_declaration(node.name, node.namespace)
                    namespace = namespace_stack + node.namespace
                    _add_template_use('', node.bases, namespace)
                    ast_seq.append(node.body)
                elif isinstance(node, ast.Using):
                    if node.names[0].name == 'namespace':
                        namespace_stack.append(node.names[1].name)

        return file_uses, decl_uses
624059
def declare_type(self, declared_type):  # type: (TypeDef) -> TypeDef
        """"""
        if declared_type not in self.collected_types:
            self.collected_types[declared_type.name] = declared_type
        return declared_type
238177
def _typed_from_items(items):
    
    dct = {}
    for name, attr in items:
        if isinstance(attr, Typed):
            dct[name] = attr(name)
    return dct
383593
public function AddTypeDef(
        \Peg\Lib\Definitions\Element\TypeDef $typedef, 
        $namespace = "\\"
    )
    {
        $this->CreateNamespace($namespace);
        
        $typedef->header =& $this;
        $typedef->namespace =& $this->namespaces[$namespace];

        $this->namespaces[$namespace]
            ->type_definitions[$typedef->name] = $typedef
        ;
    }
647289
def create_typedef(
            self,
            typedef_name,
            class_alias=None,
            with_defaults=True):
        
        has_const_str = ''
        if self.has_const:
            has_const_str = 'const'
        if None is class_alias:
            if with_defaults:
                class_alias = self.class_inst.decl_string
            else:
                class_alias = self.class_inst.partial_decl_string

        return member_function_type_t.TYPEDEF_NAME_TEMPLATE % {
            'typedef_name': typedef_name,
            'return_type': self.return_type.build_decl_string(with_defaults),
            'class': class_alias,
            'arguments': ','.join(
                [_f(x, with_defaults) for x in self.arguments_types]),
            'has_const': has_const_str}
641936
def p_typedef(self, p):
        ''''''
        p[0] = ast.Typedef(
            name=p[3], target_type=p[2], annotations=p[4], lineno=p.lineno(3)
        )
1177760
private function SaveGloablVariablesToPHP()
    {
        $output_file = fopen(
            $this->definitions_path . "variables.php", 
            "w"
        );
        
        fwrite($output_file, "<?php\n\n");
        
        fwrite($output_file, "use Peg\Lib\Definitions\Element\GlobalVariable;\n");
        
        foreach($this->symbols->headers as $header)
        {
            if(!$header->HasGlobalVariables())
                continue;
            
            foreach($header->namespaces as $namespace)
            {
                if(!$namespace->HasGlobalVariables())
                    continue;
                
                foreach($namespace->global_variables as $variable)
                {
                    $type = addslashes($variable->original_type);
                    $description = addslashes($variable->description);
                    $namespace_name = addslashes($namespace->name);
                    
                    $output = "\n";
                    $output .= '$symbols->AddGlobalVar(' . "\n";
                    $output .= '    new GlobalVariable(' . "\n";
                    $output .= '        "'.$variable->name.'",' . "\n";
                    $output .= '        "'.$type.'",' . "\n";
                    $output .= '        "'.$description.'"' . "\n";
                    $output .= '    ),' . "\n";
                    $output .= '    "'.$header->name.'",' . "\n";
                    $output .= '    "'.$namespace_name.'"' . "\n";
                    $output .= ');' . "\n";
                    
                    fwrite($output_file, $output);
                }
            }
        }
        
        fclose($output_file);
    }
1105404
def basicsize(obj, **opts):
    '''
    '''
    v = _typedefof(obj, **opts)
    if v:
        v = v.base
    return v