<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os.path
import warnings
import re
from pygccxml import parser
from pygccxml import declarations
from module import Module
from typehandlers.codesink import FileCodeSink
from typehandlers.base import ReturnValue, Parameter, TypeLookupError, TypeConfigurationError, NotSupportedError
from enum import Enum
from function import Function
from cppclass import CppClass, CppConstructor, CppMethod
from pygccxml.declarations import type_traits
from pygccxml.declarations import cpptypes
from pygccxml.declarations import calldef
from pygccxml.declarations import templates
import settings

#from pygccxml.declarations.calldef import \
#    destructor_t, constructor_t, member_function_t
from pygccxml.declarations.variable import variable_t

## ------------------------

class ErrorHandler(settings.ErrorHandler):
    def handle_error(self, wrapper, exception, traceback_):
        if hasattr(wrapper, "gccxml_definition"):
            definition = wrapper.gccxml_definition
        elif hasattr(wrapper, "main_wrapper"):
            try:
                definition = wrapper.main_wrapper.gccxml_definition
            except AttributeError:
                definition = None
        else:
            definition = None

        if definition is None:
            print >> sys.stderr, "exception %r in wrapper %s" % (exception, wrapper)
        else:
            warnings.warn_explicit("exception %r in wrapper for %s"
                                   % (exception, definition),
                                   Warning, definition.location.file_name,
                                   definition.location.line)
        return True
settings.error_handler = ErrorHandler()

_digits = re.compile(r"\s*\d+\s*")
def normalize_name(decl_string):
    if templates.is_instantiation(decl_string):
        cls_name, template_parameters = templates.split(decl_string)
    else:
        cls_name = decl_string
        template_parameters = None
    if not _digits.match(cls_name):
        if not cls_name.startswith('::'):
            cls_name = '::' + cls_name
    if template_parameters is None:
        return cls_name
    else:
        return "%s< %s >" % (cls_name, ', '.join([normalize_name(name) for name in template_parameters]))


class GccXmlTypeRegistry(object):
    def __init__(self):
        self.classes = {}  # registered classes dictionary
        self.ordered_classes = [] # registered classes list, by registration order
        self._root_ns_rx = re.compile(r"(^|\s)(::)")
    
    def register_class(self, cpp_class, alias=None):
        assert isinstance(cpp_class, CppClass)
        full_name = normalize_name(cpp_class.full_name)
        #print >> sys.stderr, "******** registering class %s as %s" \
        #    % (cpp_class.gccxml_definition, full_name)
        self.classes[full_name] = cpp_class
        self.ordered_classes.append(cpp_class)
        if alias is not None:
            alias = normalize_name(alias)<commit_msg>Don't add :: prefix to C++ fundamental types<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os.path
import warnings
import re
from pygccxml import parser
from pygccxml import declarations
from module import Module
from typehandlers.codesink import FileCodeSink
from typehandlers.base import ReturnValue, Parameter, TypeLookupError, TypeConfigurationError, NotSupportedError
from enum import Enum
from function import Function
from cppclass import CppClass, CppConstructor, CppMethod
from pygccxml.declarations import type_traits
from pygccxml.declarations import cpptypes
from pygccxml.declarations import calldef
from pygccxml.declarations import templates
import settings

#from pygccxml.declarations.calldef import \
#    destructor_t, constructor_t, member_function_t
from pygccxml.declarations.variable import variable_t

## ------------------------

class ErrorHandler(settings.ErrorHandler):
    def handle_error(self, wrapper, exception, traceback_):
        if hasattr(wrapper, "gccxml_definition"):
            definition = wrapper.gccxml_definition
        elif hasattr(wrapper, "main_wrapper"):
            try:
                definition = wrapper.main_wrapper.gccxml_definition
            except AttributeError:
                definition = None
        else:
            definition = None

        if definition is None:
            print >> sys.stderr, "exception %r in wrapper %s" % (exception, wrapper)
        else:
            warnings.warn_explicit("exception %r in wrapper for %s"
                                   % (exception, definition),
                                   Warning, definition.location.file_name,
                                   definition.location.line)
        return True
settings.error_handler = ErrorHandler()

_digits = re.compile(r"\s*\d+\s*")
def normalize_name(decl_string):
    if templates.is_instantiation(decl_string):
        cls_name, template_parameters = templates.split(decl_string)
    else:
        cls_name = decl_string
        template_parameters = None
    if not _digits.match(cls_name):
        if not cls_name.startswith('::') and cls_name not in cpptypes.FUNDAMENTAL_TYPES:
            cls_name = '::' + cls_name
    if template_parameters is None:
        return cls_name
    else:
        return "%s< %s >" % (cls_name, ', '.join([normalize_name(name) for name in template_parameters]))


class GccXmlTypeRegistry(object):
    def __init__(self):
        self.classes = {}  # registered classes dictionary
        self.ordered_classes = [] # registered classes list, by registration order
        self._root_ns_rx = re.compile(r"(^|\s)(::)")
    
    def register_class(self, cpp_class, alias=None):
        assert isinstance(cpp_class, CppClass)
        full_name = normalize_name(cpp_class.full_name)
        #print >> sys.stderr, "******** registering class %s as %s" \
        #    % (cpp_class.gccxml_definition, full_name)
        self.classes[full_name] = cpp_class
        self.ordered_classes.append(cpp_class)
        if alias is not None:
            alias = normalize_name(alias)
{'fraction_non_alphanumeric': 0.09328968903436989, 'fraction_numerical': 0.0003273322422258593, 'mean_word_length': 2.83856783919598, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 24}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3796514', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1661, 'n_words': 438}