Exemplo n.º 1
0
 def _getTokenSet(self):
     if self._token_set:
         return self._token_set
     extent = self.node.extent
     translation_unit = self.node.translation_unit
     self._token_set = ci.tokenize(translation_unit, extent)
     return self._token_set
Exemplo n.º 2
0
 def _getTokenSet(self):
     if self._token_set:
         return self._token_set
     extent = self.node.extent
     translation_unit = self.node.translation_unit
     self._token_set = ci.tokenize(translation_unit, extent)
     return self._token_set
Exemplo n.º 3
0
def get_typedef(cursor):
    tokens = cindex.tokenize(tu, cursor.extent)
    good = True
    if len(tokens) >= 4:
        for x in tokens[1:-2]:
            if x.kind != cindex.TokenKind.IDENTIFIER and x.kind != cindex.TokenKind.KEYWORD:
                good = False
                break
    else:
        good = False
    if good:
        kind = " ".join([t.spelling for t in tokens[1:len(tokens)-2]])
        name = tokens[len(tokens)-2].spelling
    else:
        data = ""
        for token in tokens:
            data += token.spelling + " "
        return None, data
    return name, kind
Exemplo n.º 4
0
def walk(cursor):
    global typedefs
    global enums
    global objecttypes
    global functions
    global objectmethods
    for child in cursor.get_children():
        if not child.location.file:
            continue
        filename = child.location.file.name
        if child.kind == cindex.CursorKind.TYPEDEF_DECL:
            name, kind = get_typedef(child)
            if name:
                typedef[name] = kind

        if fer and fer.search(filename):
            continue
        if fir and not fir.search(filename):
            continue

        if child.kind == cindex.CursorKind.MACRO_DEFINITION:
            tokens = cindex.tokenize(tu, child.extent)
            if tokens[0].kind == cindex.TokenKind.IDENTIFIER and tokens[1].kind == cindex.TokenKind.LITERAL and is_int(tokens[1].spelling):
                define = _assert("engine->RegisterEnumValue(\"HASH_DEFINES\", \"%s\", %s);" % (tokens[0].spelling, tokens[1].spelling))
                if define not in enums:
                    enums.append(define)
        elif child.kind == cindex.CursorKind.FUNCTION_DECL:
            try:
                f = Function(child)
                if "operator" in f.name:
                    raise Exception("Non member operator functions not supported currently")
                else:
                    functions.append(f)
                add_include(filename)
            except Exception as e:
                warn("Skipping function %s - %s" % (child.spelling, e))
        elif child.kind == cindex.CursorKind.TYPEDEF_DECL:
            name, kind = get_typedef(child)
            if name:
                typedef[name] = kind
                if get_real_type(kind) not in as_builtins:
                    warn("Typedef %s = %s can't be registered as it doesn't resolve to an AngelScript builtin type" % (name, kind))
                else:
                    typedefs.append(_assert("engine->RegisterTypedef(\"%s\", \"%s\");" % (name, get_real_type(kind))))
            else:
                warn("Typedef too complex, skipping: %s" % name)
        elif child.kind == cindex.CursorKind.CLASS_DECL or child.kind == cindex.CursorKind.STRUCT_DECL:
            children = child.get_children()
            if len(children) == 0:
                continue

            if oer and oer.search(child.spelling):
                continue
            if oir and not oir.search(child.spelling):
                continue

            classname = child.spelling
            if len(classname) == 0:
                classname = child.displayname
                if len(classname) == 0:
                    warn("Skipping class or struct defined at %s" % cursor.extent)
                    continue
            if classname in objecttypes:
                # TODO: different namespaces
                warn("Skipping type %s, as it is already defined" % classname)

            o = ObjectType(child, children, classname)

            objecttypes[classname] = o
            add_include(filename)
        elif child.kind == cindex.CursorKind.MACRO_INSTANTIATION or \
                child.kind == cindex.CursorKind.CONVERSION_FUNCTION or \
                 child.kind == cindex.CursorKind.INCLUSION_DIRECTIVE or \
                 child.kind == cindex.CursorKind.UNEXPOSED_DECL:
            continue
        else:
            warn("Unhandled cursor: %s, %s" % (child.displayname, child.kind))
Exemplo n.º 5
0
def is_const(cursor):
    tokens = cindex.tokenize(tu, cursor.extent)
    for token in tokens:
        if token.spelling == "const":
            return True
    return False