当前位置: 首页>>代码示例>>Python>>正文


Python c_ast.PtrDecl方法代码示例

本文整理汇总了Python中pycparser.c_ast.PtrDecl方法的典型用法代码示例。如果您正苦于以下问题:Python c_ast.PtrDecl方法的具体用法?Python c_ast.PtrDecl怎么用?Python c_ast.PtrDecl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycparser.c_ast的用法示例。


在下文中一共展示了c_ast.PtrDecl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: type_from_ctype

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def type_from_ctype(ctype: CType, typemap: TypeMap) -> Type:
    ctype = resolve_typedefs(ctype, typemap)
    if isinstance(ctype, (ca.PtrDecl, ca.ArrayDecl)):
        return Type.ptr(ctype.type)
    if isinstance(ctype, ca.FuncDecl):
        return Type.ptr(ctype)
    if isinstance(ctype, ca.TypeDecl):
        if isinstance(ctype.type, (ca.Struct, ca.Union)):
            return Type.any()
        names = ["int"] if isinstance(ctype.type, ca.Enum) else ctype.type.names
        if "double" in names:
            return Type.f64()
        if "float" in names:
            return Type.f32()
        size = 8 * primitive_size(ctype.type)
        sign = Type.UNSIGNED if "unsigned" in names else Type.SIGNED
        return Type(kind=Type.K_INT, size=size, sign=sign) 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:19,代码来源:types.py

示例2: visit_FuncDecl

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def visit_FuncDecl(self, node):
        decls = self.collect(node)
        return_type = decls[-1].type_name
        fname = decls[-1].name
        args = decls[:-1]
        if (len(args) == 1 and isinstance(args[0], IdentifierType) and
            args[0].type_name == 'void'):
            args = []
        if (self.child_of(c_ast.PtrDecl, -2) and not
            self.child_of(c_ast.Typedef, -3)):
            # declaring a variable or parameter
            name = self.path_name('ft'.format(fname))
            self.decl_stack[0].append(Type(Ptr(Function(return_type, name, args))))
            self.append(name)
        else:
            self.append(Function(return_type, fname, args)) 
开发者ID:tarruda,项目名称:python-autopxd,代码行数:18,代码来源:__init__.py

示例3: parse_struct_member

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def parse_struct_member(
    type: CType, field_name: str, typemap: TypeMap
) -> Tuple[int, int, Optional[Struct]]:
    type = resolve_typedefs(type, typemap)
    if isinstance(type, PtrDecl):
        return 4, 4, None
    if isinstance(type, ArrayDecl):
        if type.dim is None:
            raise DecompFailure(f"Array field {field_name} must have a size")
        dim = parse_constant_int(type.dim)
        size, align, _ = parse_struct_member(type.type, field_name, typemap)
        return size * dim, align, None
    assert not isinstance(type, FuncDecl), "Struct can not contain a function"
    inner_type = type.type
    if isinstance(inner_type, (ca.Struct, ca.Union)):
        substr = parse_struct(inner_type, typemap)
        return substr.size, substr.align, substr
    # Otherwise it has to be of type Enum or IdentifierType
    size = primitive_size(inner_type)
    return size, size, None 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:22,代码来源:c_types.py

示例4: __str__

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def __str__(self) -> str:
        type = self.get_representative()
        size = type.size or 32
        sign = "s" if type.sign & Type.SIGNED else "u"
        if type.kind == Type.K_ANY:
            if type.size is not None:
                return f"?{size}"
            return "?"
        if type.kind == Type.K_PTR:
            if type.ptr_to is not None:
                if isinstance(type.ptr_to, Type):
                    return (str(type.ptr_to) + " *").replace("* *", "**")
                return type_to_string(ca.PtrDecl([], type.ptr_to))
            return "void *"
        if type.kind == Type.K_FLOAT:
            return f"f{size}"
        return f"{sign}{size}" 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:19,代码来源:types.py

示例5: _explain_type

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def _explain_type(decl):
    """ Recursively explains a type decl node
    """
    typ = type(decl)

    if typ == c_ast.TypeDecl:
        quals = ' '.join(decl.quals) + ' ' if decl.quals else ''
        return quals + _explain_type(decl.type)
    elif typ == c_ast.Typename or typ == c_ast.Decl:
        return _explain_type(decl.type)
    elif typ == c_ast.IdentifierType:
        return ' '.join(decl.names)
    elif typ == c_ast.PtrDecl:
        quals = ' '.join(decl.quals) + ' ' if decl.quals else ''
        return quals + 'pointer to ' + _explain_type(decl.type)
    elif typ == c_ast.ArrayDecl:
        arr = 'array'
        if decl.dim: arr += '[%s]' % decl.dim.value

        return arr + " of " + _explain_type(decl.type)

    elif typ == c_ast.FuncDecl:
        if decl.args:
            params = [_explain_type(param) for param in decl.args.params]
            args = ', '.join(params)
        else:
            args = ''

        return ('function(%s) returning ' % (args) +
                _explain_type(decl.type)) 
开发者ID:johncsnyder,项目名称:SwiftKitten,代码行数:32,代码来源:cdecl.py

示例6: ast_to_typeid_ptrdecl

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def ast_to_typeid_ptrdecl(self, ast):
        """Return the CTypeBase of a PtrDecl ast"""
        return CTypePtr(self.ast_to_typeid(ast.type)) 
开发者ID:cea-sec,项目名称:miasm,代码行数:5,代码来源:ctypesmngr.py

示例7: ast_parse_ptrdecl

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def ast_parse_ptrdecl(self, ast):
        """Parse ast PtrDecl"""
        return CTypePtr(self.ast_parse_declaration(ast.type)) 
开发者ID:cea-sec,项目名称:miasm,代码行数:5,代码来源:ctypesmngr.py

示例8: ctx_decl

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def ctx_decl(self):
        # e.g. "HPy (*ctx_Module_Create)(HPyContext ctx, HPyModuleDef *def)"
        #
        # turn the function declaration into a function POINTER declaration
        newnode = deepcopy(self.node)
        newnode.type = c_ast.PtrDecl(type=newnode.type, quals=[])
        # fix the name of the function pointer
        typedecl = self._find_typedecl(newnode)
        typedecl.declname = self.ctx_name()
        return toC(newnode) 
开发者ID:pyhandle,项目名称:hpy,代码行数:12,代码来源:autogen.py

示例9: pointer

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def pointer(type: CType) -> CType:
    return PtrDecl(quals=[], type=type) 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:4,代码来源:c_types.py

示例10: pointer_decay

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def pointer_decay(type: CType, typemap: TypeMap) -> SimpleType:
    real_type = resolve_typedefs(type, typemap)
    if isinstance(real_type, ArrayDecl):
        return PtrDecl(quals=[], type=real_type.type)
    if isinstance(real_type, FuncDecl):
        return PtrDecl(quals=[], type=type)
    if isinstance(real_type, TypeDecl) and isinstance(real_type.type, ca.Enum):
        return basic_type(["int"])
    assert not isinstance(
        type, (ArrayDecl, FuncDecl)
    ), "resolve_typedefs can't hide arrays/functions"
    return type 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:14,代码来源:c_types.py

示例11: deref_type

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def deref_type(type: CType, typemap: TypeMap) -> CType:
    type = resolve_typedefs(type, typemap)
    assert isinstance(type, (ArrayDecl, PtrDecl)), "dereferencing non-pointer"
    return type.type 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:6,代码来源:c_types.py

示例12: function_arg_size_align

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def function_arg_size_align(type: CType, typemap: TypeMap) -> Tuple[int, int]:
    type = resolve_typedefs(type, typemap)
    if isinstance(type, PtrDecl) or isinstance(type, ArrayDecl):
        return 4, 4
    assert not isinstance(type, FuncDecl), "Function argument can not be a function"
    inner_type = type.type
    if isinstance(inner_type, (ca.Struct, ca.Union)):
        struct = get_struct(inner_type, typemap)
        assert (
            struct is not None
        ), "Function argument can not be of an incomplete struct"
        return struct.size, struct.align
    size = primitive_size(inner_type)
    return size, size 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:16,代码来源:c_types.py

示例13: transform_array_decl_to_malloc

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def transform_array_decl_to_malloc(decl, with_init=True):
    """
    Transform ast of "type var_name[N]" to "type* var_name = aligned_malloc(sizeof(type)*N, 32)"

    In-place operation.

    :param with_init: if False, ommit malloc
    """
    if type(decl.type) is not c_ast.ArrayDecl:
        # Not an array declaration, can be ignored
        return

    type_ = c_ast.PtrDecl([], decl.type.type)
    if with_init:
        decl.init = c_ast.FuncCall(
            c_ast.ID('aligned_malloc'),
            c_ast.ExprList([
                c_ast.BinaryOp(
                    '*',
                    c_ast.UnaryOp(
                        'sizeof',
                        c_ast.Typename(None, [], c_ast.TypeDecl(
                            None, [], decl.type.type.type))),
                    decl.type.dim),
                c_ast.Constant('int', '32')]))
    decl.type = type_ 
开发者ID:RRZE-HPC,项目名称:kerncraft,代码行数:28,代码来源:kernel.py

示例14: get_function_name

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def get_function_name(node):
    '''
        Gets the function name from ast node
    '''
    if type(node.type) == c_ast.PtrDecl:
        return node.type.type.declname
    else:
        return node.type.declname 
开发者ID:embedded-sec,项目名称:halucinator,代码行数:10,代码来源:map_hal2intercepts.py

示例15: __init__

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import PtrDecl [as 别名]
def __init__(self, psize=4, bigend=False):

        self.psize = psize
        self.pclass = vs_prim.v_ptr32

        self.cls_parsers = {
            c_ast.Decl:             self.c_getVsDecl,
            c_ast.Struct:           self.c_getVsStruct,
            c_ast.FileAST:          self.c_getFileAst,
            c_ast.PtrDecl:          self.c_getPointer,
            #c_ast.FuncDecl:         self.c_getFuncDecl,
            c_ast.Constant:         self.c_getConstant,
            c_ast.TypeDecl:         self.c_getVsType,
            c_ast.ArrayDecl:        self.c_getVsArray,
            c_ast.IdentifierType:   self.c_getIdentType,
        }

        self.vs_ctypes = {
            ('char',):                  vs_prim.v_int8,
            ('unsigned','char'):        vs_prim.v_uint8,

            ('short',):                 vs_prim.v_int16,
            ('short','int'):            vs_prim.v_int16,

            ('unsigned', 'short',):     vs_prim.v_uint16,
            ('unsigned', 'short','int'):vs_prim.v_uint16,

            ('int',):                   vs_prim.v_int32,
            ('unsigned','int',):        vs_prim.v_uint32,

            ('long',):                  vs_prim.v_int32,
            ('long','int'):             vs_prim.v_int32,

            ('unsigned','long',):       vs_prim.v_uint32,
            ('unsigned','long','int'):  vs_prim.v_uint32,
        }

        if psize == 8:
            self.pclass = vs_prim.v_ptr64
            self.vs_ctypes.update({
                ('long',):                  vs_prim.v_int64,
                ('long','int'):             vs_prim.v_int64,

                ('unsigned','long',):       vs_prim.v_uint64,
                ('unsigned','long','int'):  vs_prim.v_uint64,
            }) 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:48,代码来源:cparse.py


注:本文中的pycparser.c_ast.PtrDecl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。