Exemplo n.º 1
0
def update_type_map(type_map, ctags_fname):
    logger.debug("processing %s ...", ctags_fname)
    tag = CTags(ctags_fname.encode())
    tag.setSortType(ctags.TAG_SORTED)
    entry = TagEntry()

    # First traverse all entries
    status = tag.first(entry)
    while status:
        name = entry["name"].decode()
        kind = entry["kind"].decode()
        typeref = (entry[b"typeref"] or b"").decode()
        pattern = entry["pattern"].decode()

        # TODO: Check multiple declaration
        if name in type_map:
            status = tag.next(entry)
            continue

        # TODO: handle macro properly. currently, assume macros are integers.
        # Also, skip allocation.
        if kind == "macro" or "=" in pattern:
            status = tag.next(entry)
            continue

        if kind in ["func", "proc", "function", "procedure", "method"]:
            ret_type = "func"
        elif kind.startswith("enum"):
            ret_type = "enum"
        elif kind == "union":
            ret_type = "union"
        elif kind.startswith("struct"):
            ret_type = "struct"
        elif kind.startswith("class"):
            ret_type = "struct"
        elif kind == "label":
            ret_type = ret_type
        elif kind in ["label", "typedef", "member", "variable"]:
            if typeref:
                ret_type = typeref.split(":")[0]
            else:
                ret_type = pattern[:pattern.rindex(name)].rstrip()
        else:
            status = tag.next(entry)
            continue

        ret_type = sanitize(ret_type)

        if "(" in ret_type:
            ret_type = "func"

        if "*" in ret_type:
            ret_type + " *"

        type_map[name] = ret_type
        status = tag.next(entry)

    # Now check until no update exists
    while True:
        is_updated = False
        status = tag.first(entry)
        while status:
            name = entry["name"].decode()
            kind = entry["kind"].decode()
            typeref = (entry[b"typeref"] or b"").decode()
            pattern = entry["pattern"].decode()

            # No need to handle a macro as it is already replaced by a constant.
            # Also, skip allocation.
            if kind == "macro" or "=" in pattern:
                status = tag.next(entry)
                continue

            if name not in type_map:
                ret_type = "int"
            else:
                ret_type = type_map[name]
                ret_type = ret_type.split()[0]  # remove pointer for here
                while ret_type in type_map and ret_type != type_map[ret_type]:
                    ret_type = ret_type.split()[0]  # remove pointer for here
                    ret_type = type_map[ret_type]

                if ret_type not in type_map:
                    ret_type = "int"

                # use a single '*' for denoting a pointer
                if "*" not in ret_type and "*" in type_map[name]:
                    ret_type = ret_type + " *"

                if ret_type != type_map[name]:
                    type_map[name] = ret_type
                    is_updated = True

            status = tag.next(entry)

        if is_updated == False:
            break

    return None
Exemplo n.º 2
0
from __future__ import print_function
import ctags
from ctags import CTags, TagEntry
import sys

try:
    tagFile = CTags(b'tags')
except:
    sys.exit(1)
    
   
entry = TagEntry()
status = tagFile.setSortType(ctags.TAG_SORTED)
status = tagFile.first(entry)

print(tagFile['name'])
print(tagFile['author'])
print(tagFile['format'])
if status:
    print(entry['name'])
    print(entry['kind'])
    
if tagFile.find(entry, b'find', ctags.TAG_PARTIALMATCH | ctags.TAG_IGNORECASE):
    print('found')
    print(entry['lineNumber'])
    print(entry['pattern'])
    print(entry['kind'])

status = tagFile.findNext(entry)
if status:
    print(entry['lineNumber'])
Exemplo n.º 3
0
from __future__ import print_function

import sys

import ctags
from ctags import CTags, TagEntry

try:
    tagFile = CTags(b"tags")
except:
    sys.exit(1)

entry = TagEntry()
status = tagFile.setSortType(ctags.TAG_SORTED)
status = tagFile.first(entry)

print(tagFile["name"])
print(tagFile["author"])
print(tagFile["format"])
if status:
    print(entry["name"])
    print(entry["kind"])

if tagFile.find(entry, b"find", ctags.TAG_PARTIALMATCH | ctags.TAG_IGNORECASE):
    print("found")
    print(entry["lineNumber"])
    print(entry["pattern"])
    print(entry["kind"])

status = tagFile.findNext(entry)
if status: