How to use the pycparser.c_ast.PtrDecl function in pycparser

To help you get started, we’ve selected a few pycparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AMReX-Codes / amrex / Tools / typechecker / typechecker.py View on Github external
def c_ast_get_type(decl):
    typ = type(decl)
    if typ == c_ast.IdentifierType:
        #return ' '.join(decl.names)
        return decl.names[0]
    elif typ == c_ast.PtrDecl or typ == c_ast.ArrayDecl:
        return c_ast_get_type(decl.type) + ' pointer'
    else:
        return c_ast_get_type(decl.type)
github cea-sec / miasm / miasm2 / core / ctypesmngr.py View on Github external
c_ast.Typename: self.ast_to_typeid_typename,
            c_ast.FuncDecl: self.ast_to_typeid_funcdecl,
            c_ast.Enum: self.ast_to_typeid_enum,
            c_ast.PtrDecl: self.ast_to_typeid_ptrdecl,
            c_ast.EllipsisParam: self.ast_to_typeid_ellipsisparam,
            c_ast.ArrayDecl: self.ast_to_typeid_arraydecl,
        }

        self.ast_parse_rules = {
            c_ast.Struct: self.ast_parse_struct,
            c_ast.Union: self.ast_parse_union,
            c_ast.Typedef: self.ast_parse_typedef,
            c_ast.TypeDecl: self.ast_parse_typedecl,
            c_ast.IdentifierType: self.ast_parse_identifiertype,
            c_ast.Decl: self.ast_parse_decl,
            c_ast.PtrDecl: self.ast_parse_ptrdecl,
            c_ast.Enum: self.ast_parse_enum,
            c_ast.ArrayDecl: self.ast_parse_arraydecl,
            c_ast.FuncDecl: self.ast_parse_funcdecl,
            c_ast.FuncDef: self.ast_parse_funcdef,
            c_ast.Pragma: self.ast_parse_pragma,
        }
github dapetcu21 / defold-fmod / bridge / generate_bindings.py View on Github external
def __init__(self, *, node=None, name=None, c_type="", type=TypeBasic, readable=True, writeable=True):
            if node != None:
                if isinstance(node, c_ast.PtrDecl):
                    child = ParsedTypeDecl(node=node.type)
                    self.name = "ptr_" + child.name
                    self.c_type = child.c_type + "*"
                    self.const = "const" in node.quals
                    self.type = TypePointer

                    if self.const:
                        self.c_type = self.c_type + " const"

                    base_type = types[child.name] if child.name in types else TypeUnknown
                    self.readable = base_type == TypeStruct or base_type == TypeClass or child.c_type == "char"
                    self.writeable = False

                    self.child = child
                    return
github LedgerHQ / nanos-secure-sdk / pycparser / c_parser.py View on Github external
def p_pointer(self, p):
        """ pointer : TIMES type_qualifier_list_opt
                    | TIMES type_qualifier_list_opt pointer
        """
        coord = self._coord(p.lineno(1))

        p[0] = c_ast.PtrDecl(
            quals=p[2] or [],
            type=p[3] if len(p) > 3 else None,
            coord=coord)
github rreilink / pylvgl / sourceparser.py View on Github external
def type_repr(arg):
    ptrs = ''
    while isinstance(arg, c_ast.PtrDecl):
        ptrs += '*'
        arg = arg.type
    
    quals = ''.join('%s ' % qual for qual in sorted(arg.quals)) if hasattr(arg, 'quals') else ''
    
    return f'{quals}{generate_c(arg)}{ptrs}'
github cloudera / hue / desktop / core / ext-py / cffi-1.3.1 / cffi / cparser.py View on Github external
if decl.name == '__dotdotdot__':
                break
        #
        try:
            for decl in iterator:
                if isinstance(decl, pycparser.c_ast.Decl):
                    self._parse_decl(decl)
                elif isinstance(decl, pycparser.c_ast.Typedef):
                    if not decl.name:
                        raise api.CDefError("typedef does not declare any name",
                                            decl)
                    quals = 0
                    if (isinstance(decl.type.type, pycparser.c_ast.IdentifierType)
                            and decl.type.type.names[-1] == '__dotdotdot__'):
                        realtype = self._get_unknown_type(decl)
                    elif (isinstance(decl.type, pycparser.c_ast.PtrDecl) and
                          isinstance(decl.type.type, pycparser.c_ast.TypeDecl) and
                          isinstance(decl.type.type.type,
                                     pycparser.c_ast.IdentifierType) and
                          decl.type.type.type.names == ['__dotdotdot__']):
                        realtype = model.unknown_ptr_type(decl.name)
                    else:
                        realtype, quals = self._get_type_and_quals(
                            decl.type, name=decl.name)
                    self._declare('typedef ' + decl.name, realtype, quals=quals)
                else:
                    raise api.CDefError("unrecognized construct", decl)
        except api.FFIError as e:
            msg = self._convert_pycparser_error(e, csource)
            if msg:
                e.args = (e.args[0] + "\n    *** Err: %s" % msg,)
            raise