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


Python c_ast.TypeDecl方法代码示例

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


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

示例1: type_from_ctype

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

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import TypeDecl [as 别名]
def visit_Block(self, node, kind):
        name = node.name
        if not name:
            name = self.path_name(kind[0])
        if not node.decls:
            if self.child_of(c_ast.TypeDecl, -2):
                # not a definition, must be a reference
                self.append(name)
            return
        fields = self.collect(node)
        # add the struct/union definition to the top level
        self.decl_stack[0].append(Block(name, fields, kind))
        if self.child_of(c_ast.TypeDecl, -2):
            # inline struct/union, add a reference to whatever name it was
            # defined on the top level
            self.append(name) 
开发者ID:tarruda,项目名称:python-autopxd,代码行数:18,代码来源:__init__.py

示例3: find_substruct_array

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import TypeDecl [as 别名]
def find_substruct_array(
    type: Type, offset: int, scale: int, typemap: TypeMap
) -> Optional[Tuple[str, int, CType]]:
    type = type.get_representative()
    if not type.ptr_to or isinstance(type.ptr_to, Type):
        return None
    ctype = resolve_typedefs(type.ptr_to, typemap)
    if not isinstance(ctype, ca.TypeDecl):
        return None
    if not isinstance(ctype.type, (ca.Struct, ca.Union)):
        return None
    struct = get_struct(ctype.type, typemap)
    if not struct:
        return None
    try:
        sub_offset = max(off for off in struct.fields.keys() if off <= offset)
    except ValueError:
        return None
    for field in struct.fields[sub_offset]:
        field_type = resolve_typedefs(field.type, typemap)
        if isinstance(field_type, ca.ArrayDecl):
            size = var_size_align(field_type.type, typemap)[0]
            if size == scale:
                return field.name, sub_offset, field_type.type
    return None 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:27,代码来源:types.py

示例4: _explain_type

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

示例5: ast_to_typeid_typedecl

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

示例6: _find_typedecl

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import TypeDecl [as 别名]
def _find_typedecl(self, node):
        while not isinstance(node, c_ast.TypeDecl):
            node = node.type
        return node 
开发者ID:pyhandle,项目名称:hpy,代码行数:6,代码来源:autogen.py

示例7: visit_Decl

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import TypeDecl [as 别名]
def visit_Decl(self, node):
        if isinstance(node.type, c_ast.FuncDecl):
            self._visit_function(node)
        elif isinstance(node.type, c_ast.TypeDecl):
            self._visit_global_var(node) 
开发者ID:pyhandle,项目名称:hpy,代码行数:7,代码来源:autogen.py

示例8: visit_Enum

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import TypeDecl [as 别名]
def visit_Enum(self, node):
        items = []
        if node.values:
            for item in node.values.enumerators:
                items.append(item.name)
        name = node.name
        type_decl = self.child_of(c_ast.TypeDecl, -2)
        if not name and type_decl:
            name = self.path_name('e')
        # add the enum definition to the top level
        if len(items):
            self.decl_stack[0].append(Enum(name, items))
        if type_decl:
            self.append(name) 
开发者ID:tarruda,项目名称:python-autopxd,代码行数:16,代码来源:__init__.py

示例9: basic_type

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

示例10: resolve_typedefs

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

示例11: pointer_decay

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

示例12: is_void

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

示例13: is_struct_type

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import TypeDecl [as 别名]
def is_struct_type(type: CType, typemap: TypeMap) -> bool:
    type = resolve_typedefs(type, typemap)
    if not isinstance(type, TypeDecl):
        return False
    return isinstance(type.type, (ca.Struct, ca.Union)) 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:7,代码来源:c_types.py

示例14: set_decl_name

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import TypeDecl [as 别名]
def set_decl_name(decl: ca.Decl) -> None:
    name = decl.name
    type = decl.type
    while not isinstance(type, TypeDecl):
        type = type.type
    type.declname = name 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:8,代码来源:c_types.py

示例15: type_to_string

# 需要导入模块: from pycparser import c_ast [as 别名]
# 或者: from pycparser.c_ast import TypeDecl [as 别名]
def type_to_string(type: CType) -> str:
    if isinstance(type, TypeDecl) and isinstance(type.type, (ca.Struct, ca.Union)):
        su = "struct" if isinstance(type.type, ca.Struct) else "union"
        return type.type.name or f"anon {su}"
    else:
        decl = ca.Decl("", [], [], [], type, None, None)
        set_decl_name(decl)
        return to_c(decl) 
开发者ID:matt-kempster,项目名称:mips_to_c,代码行数:10,代码来源:c_types.py


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