コード例 #1
0
    def __init__(self, *args):
        DataStoragePhp.__init__(self, *args)

        object = Object()
        object.type = self.name
        object.name = '__json'
        object.initial_value = 'NULL'
        object.is_static = True
        object.access = AccessSpecifier.private
        self.members.append(object)

        object = Object()
        object.type = 'string'
        object.name = 'PATH_TO_DATA'
        object.initial_value = '"assets/data/data.json"'
        object.is_static = True
        object.access = AccessSpecifier.public
        self.members.append(object)
コード例 #2
0
    def __init__(self, *args):
        DataStorage.__init__(self, *args)

        self.create_deserialize()

        object = Object()
        object.type = self.name
        object.name = '__instance'
        object.is_static = True
        object.access = AccessSpecifier.private
        self.members.append(object)
コード例 #3
0
    def __init__(self, name, classes, parser):
        Class.__init__(self)
        self.parser = parser

        self.name = name
        self.is_serialized = True

        string_obj = Object()
        string_obj.type = 'string'
        for class_ in classes:
            if class_.is_storage and (class_.side == parser.side or class_.side == 'both'):
                object = Object()
                object.type = 'map'
                object.name = get_data_list_name(get_data_name(class_.name))
                object.template_args.append(string_obj)
                object.template_args.append(class_)
                object.access = AccessSpecifier.public
                self.members.append(object)

        loaded = Object()
        loaded.is_runtime = True
        loaded.name = '_loaded'
        loaded.type = 'bool'
        loaded.initial_value = 'false'
        loaded.access = AccessSpecifier.private
        self.members.append(loaded)

        self.create_shared_method()

        function = Function()
        function.name = 'initialize'
        function.return_type = 'void'
        function.is_const = True
        function.args.append(['buffer', 'string'])
        self.add_initialize_function_operations(function)
        self.functions.append(function)
        self.create_getters(classes)
コード例 #4
0
ファイル: WriterCpp.py プロジェクト: gferter/mlc-tools
    def convert_to_enum(self, cls):
        shift = 0
        cast = 'int'
        values = []
        for m in cls.members:
            if len(m.name):
                continue
            m.name = m.type
            m.type = cast
            m.is_static = True
            m.is_const = True
            if m.initial_value is None:
                if cast == 'int':
                    m.initial_value = '(1 << {})'.format(shift)
            values.append(1 << shift)
            shift += 1

        def add_function(type_, name, args, const):
            function = Function()
            function.return_type = type_
            function.name = name
            function.args = args
            function.is_const = const
            cls.functions.append(function)
            return function

        add_function(
            '',
            cls.name,
            [],
            False). \
            operations = ['_value = {};'.format(cls.members[0].name)]
        add_function(
            '',
            cls.name,
            [['value', cast]],
            False). \
            operations = ['_value = value;']
        add_function(
            '',
            cls.name,
            [['rhs', 'const {0}&'.format(cls.name)]],
            False). \
            operations = ['_value = rhs._value;']
        add_function(
            '',
            'operator int',
            [],
            True). \
            operations = ['return _value;']
        add_function(
            '{0}&:const'.format(cls.name),
            'operator =',
            [['rhs', 'const {0}&'.format(cls.name)]],
            False). \
            operations = ['_value = rhs._value;', 'return *this;']
        add_function(
            'bool',
            'operator ==',
            [['rhs', 'const {0}&'.format(cls.name)]],
            True). \
            operations = ['return _value == rhs._value;']
        add_function(
            'bool',
            'operator ==',
            [['rhs', 'int']],
            True). \
            operations = ['return _value == rhs;']
        add_function('bool', 'operator <', [['rhs', 'const {0}&'.format(cls.name)]], True). \
            operations = ['return _value < rhs._value;']

        function1 = add_function('', cls.name, [['value', 'string']], False)
        function2 = add_function('{0}&:const'.format(cls.name), 'operator =',
                                 [['value', 'string']], False)
        function3 = add_function('', 'operator std::string', [], True)
        function4 = add_function('string', 'str', [], True)
        index = 0
        for m in cls.members:
            if m.name == '_value':
                continue
            if index >= len(values):
                continue
            function1.operations.append(
                'if(value == "{0}") {1}_value = {0}; return; {2};'.format(
                    m.name, '{', '}'))
            function2.operations.append(
                'if(value == "{0}") {1}_value = {0}; return *this; {2};'.
                format(m.name, '{', '}'))
            function1.operations.append(
                'if(value == "{0}") {1}_value = {0}; return; {2};'.format(
                    values[index], '{', '}'))
            function2.operations.append(
                'if(value == "{0}") {1}_value = {0}; return *this; {2};'.
                format(values[index], '{', '}'))
            function3.operations.append(
                'if(_value == {0}) return "{0}";'.format(m.name))
            function4.operations.append(
                'if(_value == {0}) return "{0}";'.format(m.name))
            index += 1
        function1.operations.append('_value = 0;')
        function2.operations.append('return *this;')
        function3.operations.append('return "";')
        function4.operations.append('return "";')

        value = Object()
        value.initial_value = cls.members[0].name
        value.name = '_value'
        value.type = cast
        value.access = AccessSpecifier.private
        cls.members.append(value)
        return values