def test_kind_groups(): """Check that every kind classifies to exactly one group.""" assert CursorKind.UNEXPOSED_DECL.is_declaration() assert CursorKind.TYPE_REF.is_reference() assert CursorKind.DECL_REF_EXPR.is_expression() assert CursorKind.UNEXPOSED_STMT.is_statement() assert CursorKind.INVALID_FILE.is_invalid() assert CursorKind.TRANSLATION_UNIT.is_translation_unit() assert not CursorKind.TYPE_REF.is_translation_unit() assert CursorKind.PREPROCESSING_DIRECTIVE.is_preprocessing() assert not CursorKind.TYPE_REF.is_preprocessing() assert CursorKind.UNEXPOSED_DECL.is_unexposed() assert not CursorKind.TYPE_REF.is_unexposed() for k in CursorKind.get_all_kinds(): group = [ n for n in ('is_declaration', 'is_reference', 'is_expression', 'is_statement', 'is_invalid', 'is_attribute') if getattr(k, n)() ] if k in (CursorKind.TRANSLATION_UNIT, CursorKind.MACRO_DEFINITION, CursorKind.MACRO_INSTANTIATION, CursorKind.INCLUSION_DIRECTIVE, CursorKind.PREPROCESSING_DIRECTIVE, CursorKind.VISIBILITY_ATTR, CursorKind.DLLEXPORT_ATTR, CursorKind.DLLIMPORT_ATTR, CursorKind.TYPE_ALIAS_TEMPLATE_DECL): assert len(group) == 0, "Group %s, kind %s" % (group, k) else: assert len(group) == 1, "Group %s, kind %s" % (group, k)
def test_kind_groups(self): """Check that every kind classifies to exactly one group.""" self.assertTrue(CursorKind.UNEXPOSED_DECL.is_declaration()) self.assertTrue(CursorKind.TYPE_REF.is_reference()) self.assertTrue(CursorKind.DECL_REF_EXPR.is_expression()) self.assertTrue(CursorKind.UNEXPOSED_STMT.is_statement()) self.assertTrue(CursorKind.INVALID_FILE.is_invalid()) self.assertTrue(CursorKind.TRANSLATION_UNIT.is_translation_unit()) self.assertFalse(CursorKind.TYPE_REF.is_translation_unit()) self.assertTrue(CursorKind.PREPROCESSING_DIRECTIVE.is_preprocessing()) self.assertFalse(CursorKind.TYPE_REF.is_preprocessing()) self.assertTrue(CursorKind.UNEXPOSED_DECL.is_unexposed()) self.assertFalse(CursorKind.TYPE_REF.is_unexposed()) for k in CursorKind.get_all_kinds(): group = [n for n in ('is_declaration', 'is_reference', 'is_expression', 'is_statement', 'is_invalid', 'is_attribute') if getattr(k, n)()] if k in ( CursorKind.TRANSLATION_UNIT, CursorKind.MACRO_DEFINITION, CursorKind.MACRO_INSTANTIATION, CursorKind.INCLUSION_DIRECTIVE, CursorKind.PREPROCESSING_DIRECTIVE, CursorKind.OVERLOAD_CANDIDATE): self.assertEqual(len(group), 0) else: self.assertEqual(len(group), 1)
def test_kind_groups(): """Check that every kind classifies to exactly one group.""" assert CursorKind.UNEXPOSED_DECL.is_declaration() assert CursorKind.TYPE_REF.is_reference() assert CursorKind.DECL_REF_EXPR.is_expression() assert CursorKind.UNEXPOSED_STMT.is_statement() assert CursorKind.INVALID_FILE.is_invalid() assert CursorKind.TRANSLATION_UNIT.is_translation_unit() assert not CursorKind.TYPE_REF.is_translation_unit() assert CursorKind.PREPROCESSING_DIRECTIVE.is_preprocessing() assert not CursorKind.TYPE_REF.is_preprocessing() assert CursorKind.UNEXPOSED_DECL.is_unexposed() assert not CursorKind.TYPE_REF.is_unexposed() for k in CursorKind.get_all_kinds(): group = [n for n in ('is_declaration', 'is_reference', 'is_expression', 'is_statement', 'is_invalid', 'is_attribute') if getattr(k, n)()] if k in ( CursorKind.TRANSLATION_UNIT, CursorKind.MACRO_DEFINITION, CursorKind.MACRO_INSTANTIATION, CursorKind.INCLUSION_DIRECTIVE, CursorKind.PREPROCESSING_DIRECTIVE, CursorKind.OVERLOAD_CANDIDATE): assert len(group) == 0 else: assert len(group) == 1
def is_function_declaration(args, c): return CursorKind.is_declaration(c.kind) \ and not c.is_definition() \ and (c.linkage == LinkageKind.EXTERNAL \ or c.linkage == LinkageKind.NO_LINKAGE) \ and c.result_type != None \ and c.result_type.get_canonical().kind != TypeKind.INVALID \ and c.spelling not in args.skip
def test_get_all_kinds(): kinds = CursorKind.get_all_kinds() assert CursorKind.UNEXPOSED_DECL in kinds assert CursorKind.TRANSLATION_UNIT in kinds assert CursorKind.VARIABLE_REF in kinds assert CursorKind.LAMBDA_EXPR in kinds assert CursorKind.OBJ_BOOL_LITERAL_EXPR in kinds assert CursorKind.OBJ_SELF_EXPR in kinds assert CursorKind.MS_ASM_STMT in kinds assert CursorKind.MODULE_IMPORT_DECL in kinds
def test_get_all_kinds(self): kinds = CursorKind.get_all_kinds() self.assertIn(CursorKind.UNEXPOSED_DECL, kinds) self.assertIn(CursorKind.TRANSLATION_UNIT, kinds) self.assertIn(CursorKind.VARIABLE_REF, kinds) self.assertIn(CursorKind.LAMBDA_EXPR, kinds) self.assertIn(CursorKind.OBJ_BOOL_LITERAL_EXPR, kinds) self.assertIn(CursorKind.OBJ_SELF_EXPR, kinds) self.assertIn(CursorKind.MS_ASM_STMT, kinds) self.assertIn(CursorKind.MODULE_IMPORT_DECL, kinds) self.assertIn(CursorKind.TYPE_ALIAS_TEMPLATE_DECL, kinds)
def test_kind_groups(): """Check that every kind classifies to exactly one group.""" assert CursorKind.UNEXPOSED_DECL.is_declaration() assert CursorKind.TYPE_REF.is_reference() assert CursorKind.DECL_REF_EXPR.is_expression() assert CursorKind.UNEXPOSED_STMT.is_statement() assert CursorKind.INVALID_FILE.is_invalid() for k in CursorKind.get_all_kinds(): group = [ n for n in ('is_declaration', 'is_reference', 'is_expression', 'is_statement', 'is_invalid') if getattr(k, n)() ] if k == CursorKind.TRANSLATION_UNIT: assert len(group) == 0 else: assert len(group) == 1
def test_kind_groups(): """Check that every kind classifies to exactly one group.""" assert CursorKind.UNEXPOSED_DECL.is_declaration() assert CursorKind.TYPE_REF.is_reference() assert CursorKind.DECL_REF_EXPR.is_expression() assert CursorKind.UNEXPOSED_STMT.is_statement() assert CursorKind.INVALID_FILE.is_invalid() for k in CursorKind.get_all_kinds(): group = [ n for n in ("is_declaration", "is_reference", "is_expression", "is_statement", "is_invalid") if getattr(k, n)() ] if k == CursorKind.TRANSLATION_UNIT: assert len(group) == 0 else: assert len(group) == 1
def test_kind_groups(): """Check that every kind classifies to exactly one group.""" assert CursorKind.UNEXPOSED_DECL.is_declaration() assert CursorKind.TYPE_REF.is_reference() assert CursorKind.DECL_REF_EXPR.is_expression() assert CursorKind.UNEXPOSED_STMT.is_statement() assert CursorKind.INVALID_FILE.is_invalid() assert CursorKind.TRANSLATION_UNIT.is_translation_unit() assert not CursorKind.TYPE_REF.is_translation_unit() assert CursorKind.PREPROCESSING_DIRECTIVE.is_preprocessing() assert not CursorKind.TYPE_REF.is_preprocessing() assert CursorKind.UNEXPOSED_DECL.is_unexposed() assert not CursorKind.TYPE_REF.is_unexposed() for k in CursorKind.get_all_kinds(): group = [ n for n in ('is_declaration', 'is_reference', 'is_expression', 'is_statement', 'is_invalid', 'is_attribute') if getattr(k, n)() ] # _ATTR not supported in Clang 3.4 if k.value >= 400 and k.value < 500: continue if k in (CursorKind.TRANSLATION_UNIT, CursorKind.MACRO_DEFINITION, CursorKind.MACRO_INSTANTIATION, CursorKind.INCLUSION_DIRECTIVE, CursorKind.PREPROCESSING_DIRECTIVE, CursorKind.OVERLOAD_CANDIDATE): assert len(group) == 0 else: if len(group) != 1: print(k) assert len(group) == 1
def test_kind_groups(): """Check that every kind classifies to exactly one group.""" assert CursorKind.UNEXPOSED_DECL.is_declaration() assert CursorKind.TYPE_REF.is_reference() assert CursorKind.DECL_REF_EXPR.is_expression() assert CursorKind.UNEXPOSED_STMT.is_statement() assert CursorKind.INVALID_FILE.is_invalid() for k in CursorKind.get_all_kinds(): group = [ n for n in ('is_declaration', 'is_reference', 'is_expression', 'is_statement', 'is_invalid', 'is_attribute') if getattr(k, n)() ] if k in (CursorKind.TRANSLATION_UNIT, CursorKind.MACRO_DEFINITION, CursorKind.MACRO_INSTANTIATION, CursorKind.INCLUSION_DIRECTIVE, CursorKind.PREPROCESSING_DIRECTIVE): assert len(group) == 0 else: assert len(group) == 1
from __future__ import unicode_literals from clang.cindex import Cursor, CursorKind, TypeKind, Token, TokenGroup, TokenKind from . import utils if False: # pylint: disable=using-constant-test from clang import cindex # pylint: disable=unused-import from typing import ( # pylint: disable=unused-import Container, Iterator, List, Optional, Text, Union) EXPRESSION_KINDS = frozenset({ kind for kind in CursorKind.get_all_kinds() if kind.is_expression() and not kind.is_statement() }) RECORD_KINDS = frozenset([ CursorKind.CLASS_DECL, CursorKind.STRUCT_DECL, ]) TYPE_KINDS = frozenset([ CursorKind.CLASS_DECL, CursorKind.STRUCT_DECL, CursorKind.TYPEDEF_DECL, ]) SCOPE_CURSOR_KINDS = frozenset([ CursorKind.TRANSLATION_UNIT, CursorKind.NAMESPACE,
def test_get_all_kinds(): assert CursorKind.UNEXPOSED_DECL in CursorKind.get_all_kinds() assert CursorKind.TRANSLATION_UNIT in CursorKind.get_all_kinds()
#!/usr/bin/env python2 # -*- coding: utf-8 -*- from clang.cindex import CursorKind as K dontcare = '^.*$' if __name__ == '__main__': for kind in K.get_all_kinds(): fmt = '{}: \'{}\'' msg = fmt.format(kind.name.lower(), dontcare) print(msg)