<commit_before># -*- coding: utf-8 -*-

import re
import linecache
import uuid

# FIXME: This will have to be abstracted, might be involved :)
import clang.cindex

from .links import LocalLink, Link
from ..utils.simple_signals import Signal
from ..utils.utils import all_subclasses
from .doc_tool import doc_tool

def ast_node_is_function_pointer (ast_node):
    if ast_node.kind == clang.cindex.TypeKind.POINTER and \
            ast_node.get_pointee().get_result().kind != \
            clang.cindex.TypeKind.INVALID:
        return True
    return False

class Symbol (object):
    def __init__(self, comment, name, location):
        from hotdoc.core.doc_tool import doc_tool
        self.comment = comment
        self.name = name
        self.original_text = None
        self.detailed_description = None
        self.link = LocalLink (self._make_unique_id(), "", self._make_name())
        doc_tool.link_resolver.add_local_link (self.link)
        self.location = location

    def parse_tags(self):
        if not self.comment:
            return []

        if not hasattr (self.comment, "tags"):
            return []

        tags = []
        for tag, value in self.comment.tags.iteritems():
            tags.append (Tag (tag, value.value))
        return tags

    def do_format (self):
        from hotdoc.core.doc_tool import doc_tool
        self.tags = self.parse_tags ()
        return doc_tool.formatter.format_symbol (self)

    def _make_name (self):
        return self.name

    def _make_unique_id (self):
        return self.name

    def get_extra_links (self):
        return []

    def add_annotation (self, annotation):
        self.annotations.append (annotation)

    def get_type_name (self):
        return ''

    def __apply_qualifiers (self, type_, tokens):
        if type_.is_const_qualified():
            tokens.append ('const ')
        if type_.is_restrict_qualified():
            tokens.append ('restrict ')
        if type_.is_volatile_qualified():
            tokens.append ('volatile ')

    def _make_c_style_type_name (self, type_):
        from hotdoc.core.doc_tool import doc_tool
        tokens = []
        while (type_.kind == clang.cindex.TypeKind.POINTER):
            self.__apply_qualifiers(type_, tokens)
            tokens.append ('*')
            type_ = type_.get_pointee()

        if type_.kind == clang.cindex.TypeKind.TYPEDEF:
            d = type_.get_declaration ()
            link = doc_tool.link_resolver.get_named_link (d.displayname)
            if link:
                tokens.append (link)
            else:
                tokens.append (d.displayname + ' ')
            self.__apply_qualifiers(type_, tokens)
        else:
            link = doc_tool.link_resolver.get_named_link (type_.spelling)
            if link:
                tokens.append (link)
            else:
                tokens.append (type_.spelling + ' ')

        tokens.reverse()
        return tokens

    def get_source_location (self):
        return self.location

class Tag:
    def __init__(self, name, value):
        self.name = name
        self.description = value

class FunctionSymbol (Symbol):
    def __init__(self, parameters, return_value, *args):
        Symbol.__init__(self, *args)
        self.parameters = parameters
        self.return_value = return_value
        self.throws = False
        self.is_method = False

    def get_type_name (self):
        if self.is_method:
            return 'Method'
        return 'Function'

class SignalSymbol (FunctionSymbol):
    def __init__(self, object_name, *args):
        self.object_name = object_name
        FunctionSymbol.__init__(self, *args)
        self.flags = []

    def get_type_name (self):<commit_msg>clang has been abstracted, fixed the hardest FIXME, was involved ...<commit_after># -*- coding: utf-8 -*-

import re
import linecache
import uuid

from .links import LocalLink, Link
from ..utils.simple_signals import Signal
from ..utils.utils import all_subclasses
from .doc_tool import doc_tool

class Symbol (object):
    def __init__(self, comment, name, location):
        from hotdoc.core.doc_tool import doc_tool
        self.comment = comment
        self.name = name
        self.original_text = None
        self.detailed_description = None
        self.link = LocalLink (self._make_unique_id(), "", self._make_name())
        doc_tool.link_resolver.add_local_link (self.link)
        self.location = location

    def parse_tags(self):
        if not self.comment:
            return []

        if not hasattr (self.comment, "tags"):
            return []

        tags = []
        for tag, value in self.comment.tags.iteritems():
            tags.append (Tag (tag, value.value))
        return tags

    def do_format (self):
        from hotdoc.core.doc_tool import doc_tool
        self.tags = self.parse_tags ()
        return doc_tool.formatter.format_symbol (self)

    def _make_name (self):
        return self.name

    def _make_unique_id (self):
        return self.name

    def get_extra_links (self):
        return []

    def add_annotation (self, annotation):
        self.annotations.append (annotation)

    def get_type_name (self):
        return ''

    def __apply_qualifiers (self, type_, tokens):
        if type_.is_const_qualified():
            tokens.append ('const ')
        if type_.is_restrict_qualified():
            tokens.append ('restrict ')
        if type_.is_volatile_qualified():
            tokens.append ('volatile ')

    def get_source_location (self):
        return self.location

class Tag:
    def __init__(self, name, value):
        self.name = name
        self.description = value

class FunctionSymbol (Symbol):
    def __init__(self, parameters, return_value, *args):
        Symbol.__init__(self, *args)
        self.parameters = parameters
        self.return_value = return_value
        self.throws = False
        self.is_method = False

    def get_type_name (self):
        if self.is_method:
            return 'Method'
        return 'Function'

class SignalSymbol (FunctionSymbol):
    def __init__(self, object_name, *args):
        self.object_name = object_name
        FunctionSymbol.__init__(self, *args)
        self.flags = []

    def get_type_name (self):
{'fraction_non_alphanumeric': 0.09435766656040803, 'fraction_numerical': 0.000318775900541919, 'mean_word_length': 2.2631305252210088, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3911687', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1769, 'n_words': 458}