Python clang.cindex.CursorKind.VAR_DECL Examples

The following are 4 code examples of clang.cindex.CursorKind.VAR_DECL(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module clang.cindex.CursorKind , or try the search function .
Example #1
Source File: libclang_parser.py    From AutoWIG with Apache License 2.0 5 votes vote down vote up
def read_cursor(asg, cursor, scope):
    if cursor.kind is CursorKind.UNEXPOSED_DECL:
        if cursor.spelling == '':
            children = []
            for child in cursor.get_children():
                children.extend(read_cursor(asg, child, scope))
            return children
        else:
            warnings.warn('Named unexposed cursor not read')
            return []
    elif cursor.kind is CursorKind.TYPEDEF_DECL:
        return read_typedef(asg, cursor, scope)
    elif cursor.kind in [CursorKind.VAR_DECL, CursorKind.PARM_DECL]:
        return read_variable(asg, cursor, scope)
    elif cursor.kind in [CursorKind.FUNCTION_DECL, CursorKind.CXX_METHOD,
            CursorKind.DESTRUCTOR, CursorKind.CONSTRUCTOR]:
        return read_function(asg, cursor, scope)
    elif cursor.kind is CursorKind.FIELD_DECL:
        return read_field(asg, cursor, scope)
    elif cursor.kind in [CursorKind.ENUM_DECL, CursorKind.STRUCT_DECL,
            CursorKind.UNION_DECL, CursorKind.CLASS_DECL]:
        return read_tag(asg, cursor, scope)
    elif cursor.kind is CursorKind.NAMESPACE:
        return read_namespace(asg, cursor, scope)
    elif cursor.kind in [CursorKind.NAMESPACE_ALIAS, CursorKind.FUNCTION_TEMPLATE,
            CursorKind.USING_DECLARATION, CursorKind.USING_DIRECTIVE,
            CursorKind.UNEXPOSED_ATTR, CursorKind.CLASS_TEMPLATE,
            CursorKind.CLASS_TEMPLATE_PARTIAL_SPECIALIZATION,
            CursorKind.CXX_ACCESS_SPEC_DECL, CursorKind.CONVERSION_FUNCTION]:
        return []
    else:
        warnings.warn('Undefined behaviour for \'' + str(cursor.kind) + '\' cursor')
        return [] 
Example #2
Source File: branch_analyzer.py    From macke with Apache License 2.0 5 votes vote down vote up
def get_sym_table(node):
    global sym_table
    # TODO: fix to include only declaration from the current file 
    if node.kind==CursorKind.VAR_DECL and str(node.location.file).endswith('.c'):
        sym_table[node.spelling] = node.location.line
    children = [get_sym_table(c) for c in node.get_children()] 
Example #3
Source File: ClangCountingConditions.py    From coala-bears with GNU Affero General Public License v3.0 5 votes vote down vote up
def is_reference(cursor):
    """
    Determines if the cursor is a reference to something, i.e. an identifier
    of a function or variable.

    :param cursor: A clang cursor from the AST.
    :return:       True if the cursor is a reference.
    """
    return cursor.kind in [CursorKind.VAR_DECL,
                           CursorKind.PARM_DECL,
                           CursorKind.DECL_REF_EXPR] 
Example #4
Source File: parser.py    From pyopenvr with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def parse_namespace(self, cursor):
        assert str(cursor.spelling) == 'vr'
        for child in cursor.get_children():
            if child.kind == CursorKind.VAR_DECL:
                self.parse_var_decl(child)
            elif child.kind == CursorKind.TYPEDEF_DECL:
                self.parse_typedef(child)
            elif child.kind == CursorKind.STRUCT_DECL:
                self.items.append(self.parse_struct(child))
            elif child.kind == CursorKind.UNION_DECL:
                union = self.parse_struct(child)
                union.base = 'Union'
                self.items.append(union)
            elif child.kind == CursorKind.ENUM_DECL:
                self.parse_enum(child)
            elif child.kind == CursorKind.FUNCTION_DECL:
                self.parse_function(child)
            elif child.kind == CursorKind.UNEXPOSED_DECL:
                self.parse_unexposed_decl(child)
            elif child.kind == CursorKind.CLASS_DECL:
                if child.spelling.startswith('IVR'):
                    self.items.append(self.parse_ivrclass(child))
                elif child.spelling.startswith('COpenVRContext'):
                    self.items.append(self.parse_copenvrcontext(child))
                else:
                    print(f'*** WARNING *** skipping class {child.spelling}(...)')
            elif child.kind == CursorKind.CXX_METHOD:
                cn = child.semantic_parent.spelling
                mn = child.spelling
                if cn == 'COpenVRContext' and mn == 'Clear':
                    pass  # OK - we manually wrap this one
                else:
                    print(f'*** WARNING *** skipping class method implementation {child.spelling}(...)')
            else:
                self.report_unparsed(child)