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


Python c_ast.IdentifierType方法代码示例

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


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

示例1: _explain_type

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [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

示例2: visit_TypeDecl

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [as 别名]
def visit_TypeDecl(self, node):
        """Retrieve the name in a function declaration:
        Only one IdentifierType is present"""
        self.node_name = node 
开发者ID:cea-sec,项目名称:miasm,代码行数:6,代码来源:ctypesmngr.py

示例3: ast_to_typeid_identifiertype

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

示例4: ast_parse_identifiertype

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

示例5: basic_type

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [as 别名]
def basic_type(names: List[str]) -> TypeDecl:
    idtype = IdentifierType(names=names)
    return TypeDecl(declname=None, quals=[], type=idtype) 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:5,代码来源:c_types.py

示例6: resolve_typedefs

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [as 别名]
def resolve_typedefs(type: CType, typemap: TypeMap) -> CType:
    while (
        isinstance(type, TypeDecl)
        and isinstance(type.type, IdentifierType)
        and len(type.type.names) == 1
        and type.type.names[0] in typemap.typedefs
    ):
        type = typemap.typedefs[type.type.names[0]]
    return type 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:11,代码来源:c_types.py

示例7: is_void

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [as 别名]
def is_void(type: CType) -> bool:
    return (
        isinstance(type, ca.TypeDecl)
        and isinstance(type.type, ca.IdentifierType)
        and type.type.names == ["void"]
    ) 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:8,代码来源:c_types.py

示例8: primitive_size

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [as 别名]
def primitive_size(type: Union[ca.Enum, ca.IdentifierType]) -> int:
    if isinstance(type, ca.Enum):
        return 4
    names = type.names
    if "double" in names:
        return 8
    if "float" in names:
        return 4
    if "short" in names:
        return 2
    if "char" in names:
        return 1
    if names.count("long") == 2:
        return 8
    return 4 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:17,代码来源:c_types.py

示例9: get_primitive_list

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [as 别名]
def get_primitive_list(type: CType, typemap: TypeMap) -> Optional[List[str]]:
    type = resolve_typedefs(type, typemap)
    if not isinstance(type, TypeDecl):
        return None
    inner_type = type.type
    if isinstance(inner_type, ca.Enum):
        return ["int"]
    if isinstance(inner_type, ca.IdentifierType):
        return inner_type.names
    return None 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:12,代码来源:c_types.py

示例10: _build_const_declartions

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [as 别名]
def _build_const_declartions(self, with_init=True):
        """
        Generate constants declarations

        :return: list of declarations
        """
        decls = []

        # Use type as provided by user in loop indices
        index_type = self.get_index_type()

        i = 2  # subscript for cli input, 1 is reserved for repeat
        for k in self.constants:
            # const long long N = strtoul(argv[2])
            # with increasing N and 1
            # TODO change subscript of argv depending on constant count
            type_decl = c_ast.TypeDecl(k.name, ['const'], c_ast.IdentifierType(index_type))
            init = None
            if with_init:
                init = c_ast.FuncCall(
                    c_ast.ID('atoi'),
                    c_ast.ExprList([c_ast.ArrayRef(c_ast.ID('argv'),
                                                   c_ast.Constant('int', str(i)))]))
            i += 1
            decls.append(c_ast.Decl(
                k.name, ['const'], [], [],
                type_decl, init, None))

        return decls 
开发者ID:RRZE-HPC,项目名称:kerncraft,代码行数:31,代码来源:kernel.py

示例11: _build_kernel_function_declaration

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [as 别名]
def _build_kernel_function_declaration(self, name='kernel'):
        """Build and return kernel function declaration"""
        array_declarations, array_dimensions = self._build_array_declarations(with_init=False)
        const_declarations = self._build_const_declartions(with_init=False)
        return c_ast.FuncDecl(args=c_ast.ParamList(params=array_declarations +
                                                          const_declarations),
                              type=c_ast.TypeDecl(declname=name,
                                                  quals=[],
                                                  type=c_ast.IdentifierType(names=['void']))) 
开发者ID:RRZE-HPC,项目名称:kerncraft,代码行数:11,代码来源:kernel.py

示例12: is_type_void

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [as 别名]
def is_type_void(node):
    '''
        Checks if the nodes type is void
        Return True if void
    '''
    ty = node.type
    if type(ty) == c_ast.IdentifierType and 'void' in ty.names:
        return True
    else:
        return False 
开发者ID:embedded-sec,项目名称:halucinator,代码行数:12,代码来源:map_hal2intercepts.py

示例13: __init__

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [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

示例14: get_ctypes_type

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [as 别名]
def get_ctypes_type(typedecl, typedefs):
    ptr_indirection = 0

    if isinstance(typedecl, c_ast.TypeDecl):
        if isinstance(typedecl.type, c_ast.IdentifierType):
            tnames = typedecl.type.names

            while True:
                if ((len(tnames) == 1 and tnames[0] in typedefs) or
                        (tnames[-1] in typedefs and tnames[-2] not in
                            {'struct', 'union'})):
                    tnames = list(tnames[:-1]) + list(typedefs[tnames[-1]])
                else:
                    break

            ptr_indirection = 1 if tnames[-1] == '*' else 0
            if ptr_indirection:
                tnames = tnames[:-1]

            if len(tnames) > 1 and tnames[-2] == 'struct':
                ctype = 'ctypes.c_void_p'
                ptr_indirection = 0
            elif len(tnames) > 1 and tnames[-2] == 'union':
                ctype = 'ctypes.c_void_p'
                ptr_indirection = 0
            else:
                ctype = ctype_map.get(tuple(tnames))
                if ctype is None:
                    die('unrecognized C type: {}'.format(' '.join(tnames)))

        elif isinstance(typedecl.type, c_ast.Struct):
            ctype = 'ctypes.c_void_p'

        elif isinstance(typedecl.type, c_ast.Union):
            ctype = 'ctypes.c_void_p'

        else:
            die('unexpected syntax in type declaration: {!r}'.format(
                typedecl.type))

    elif isinstance(typedecl, c_ast.PtrDecl):
        ctype, ptr_indirection = get_ctypes_type(
            typedecl.type, typedefs)

        if ctype != 'ctypes.c_void_p':
            ptr_indirection += 1

    elif isinstance(typedecl, c_ast.ArrayDecl):
        array_type, ptr_indirection = get_ctypes_type(typedecl.type, typedefs)
        dim = fold_const_expr(typedecl.dim, typedefs)
        ctype = '{} * {}'.format(array_type, dim)

    else:
        die('unexpected syntax in type declaration: {!r}'.format(
            typedecl))

    return ctype, ptr_indirection 
开发者ID:pinterest,项目名称:ptracer,代码行数:59,代码来源:extract_ptrace_constants.py

示例15: render_type

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import IdentifierType [as 别名]
def render_type(typedecl):
    res = []

    if isinstance(typedecl, (c_ast.TypeDecl, c_ast.Typename)):
        res.extend(typedecl.quals)
        res.extend(render_type(typedecl.type))

    elif isinstance(typedecl, c_ast.PtrDecl):
        res.extend(typedecl.quals)
        res.extend(render_type(typedecl.type))
        res.append('*')

    elif isinstance(typedecl, c_ast.IdentifierType):
        res.extend(typedecl.names)

    elif isinstance(typedecl, c_ast.Struct):
        res.extend(['struct', typedecl.name])

    elif isinstance(typedecl, c_ast.Union):
        res.extend(['union', typedecl.name])

    elif isinstance(typedecl, (c_ast.FuncDecl, ext_c_parser.FuncDeclExt)):
        ret = render_type(typedecl.type)
        args = []
        for param in typedecl.args.params:
            args.append(' '.join(render_type(param)))
        ret.append('({})'.format(', '.join(args)))

        res.extend(ret)

    elif isinstance(typedecl, c_ast.ArrayDecl):
        res.extend(render_type(typedecl.type))
        if typedecl.dim is None:
            res.append('[]')
        elif isinstance(typedecl.dim, c_ast.Constant):
            res.append('[{}]'.format(typedecl.dim.value))
        else:
            die('non-constant dimension in array declaration')

    else:
        die('unexpected {!r}'.format(typedecl))

    return res 
开发者ID:pinterest,项目名称:ptracer,代码行数:45,代码来源:extract_ptrace_constants.py


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