Exemple #1
0
    def _build_tree(file_path, compiler_parameters):
        file_path = os.path.abspath(file_path)

        def build_tree_recursive(cursor, parent, access):
            node = Node(cursor, parent, access)

            for child in cursor.get_children():
                if child.kind == CursorKind.COMPOUND_STMT:
                    # Ignore nodes defining code logic
                    continue

                if not child.location.file or os.path.abspath(
                        child.location.file.name) != file_path:
                    # Ignore nodes from other files
                    continue

                child_access = child.access_specifier
                if child_access == AccessSpecifier.INVALID:
                    child_access = access
                child_node = build_tree_recursive(child, node, child_access)
                node.children.append(child_node)
                assert child_node.parent == node
            return node

        index = Index(conf.lib.clang_createIndex(False, True))
        translation_unit = index.parse(
            file_path,
            compiler_parameters,
            options=TranslationUnit.PARSE_INCOMPLETE
            | TranslationUnit.PARSE_SKIP_FUNCTION_BODIES
            | TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION)
        return build_tree_recursive(translation_unit.cursor, None,
                                    AccessSpecifier.NONE)
Exemple #2
0
    def get_translation_unit(file, project=None):
        """
        Returns the clang translation unit corresponding to this file. You can
        use that as a full libclang translation unit.

        :param GPS.File file: The file to get the translation unit for
        :rtype: clang.cindex.TranslationUnit
        """
        from clang.cindex import TranslationUnit, c_object_p, Index
        from ctypes import cast

        project = project or file.project()
        tu_ptr, index_ptr = GPS.Libclang._get_translation_unit(file, project)

        # If tu_ptr or index_ptr are 0, then we return nothing
        if tu_ptr and index_ptr:
            return TranslationUnit(cast(tu_ptr, c_object_p),
                                   Index(cast(index_ptr, c_object_p)))
Exemple #3
0
#!/usr/bin/env python
import sys
import os
import threading
import time
import clang.cindex
from clang.cindex import Index, TokenKind, TranslationUnit

###
# Globals
# Use the following index, if you want clang to print its diagnostic messages
_clangIndex = Index(clang.cindex.conf.lib.clang_createIndex(False, 1))
#_clangIndex = Index.create()
_translationUnits = dict()


def translateFieldType(typeName):
    if typeName == 'c:Matrix.h@N@Eigen@T@Vector3f':
        return 'v3f'
    elif typeName == 'c:Matrix.h@N@Eigen@T@Vector2f':
        return 'v2f'
    else:
        return typeName
    pass


# Iterate over the source file, retrieving all classes and their
# public fields and methods
def parseCPPFileChildren(output, node, pragmaList, context):
    for child in node.get_children():
        childNode = parseCPPFileRec(child, pragmaList, context)