Exemplo n.º 1
0
    def __init__(self, project):
        ProjectAgent.__init__(self, project, "gen printf")

        # --- printf options ---
        self.min_nb_arg = 1
        self.max_nb_arg = 6
        self.types = 'aAcCdeEfFgGimnopuxXsS%'
        self.format_attr = ('#', '0', '-', ' ', '+', "'", 'I', '')
        self.min_width = 0
        self.max_width = 10 * 1000 * 1000
        self.max_precision = 10 * 1000 * 1000
        self.values = {
            'str': quoteString('Hello'),
            'wide str': quoteString(HELLO_UTF32),
            'char': "'A'",
            'wide char': "(wchar_t)322",  # 'ł'
            'double': "(double)3.14",
            'short': "(short)7",
            'pointer': "(void *)0xDEADBEEF",
            'int': "(int)42",
            'intmax': "(intmax_t)232",
            'size_t': "(size_t)-1",
            'long': "(long)1234567890",
            'long long': "(long long)10101010",
            'ptrdiff_t': "(ptrdiff_t)100",
            'write': "&written",
            'long double': '(long double)5.92',
        }
        int_modifiers = {
            'hh': 'char',
            'h': 'short',
            'l': 'long',
            'll': 'long long',
            'q': 'long long',
            'j': 'intmax',
            'z': 'size_t',
            't': 'ptrdiff_t',
        }
        self.modifiers = {
            'int': dict(int_modifiers),
            'char': dict(int_modifiers),
            'wide char': dict(int_modifiers),
            'pointer': dict(int_modifiers),
            'str': {
                'l': 'wide str'
            },
            'wide str': {
                'l': 'wide str'
            },
            'double': {
                'L': 'long double'
            },
        }
Exemplo n.º 2
0
    def generate(self, nb_arg):
        text = []
        arguments = []
        for index in xrange(nb_arg):
            if text:
                text.append(' -- ')

            # Generate format and value
            format, prefix, size = self.genFormat(index)
            if size:
                value = self.printf.values[size]
            else:
                value = None

            # Append format and value
            format = ''.join(format)
            text.append('x%s' % index + '=' + format)
            if prefix:
                arguments.append(prefix)
            if value is not None:
                if value == "&written":
                    arguments.append('/* written bytes at x%s */ ' % index +
                                     value)
                else:
                    arguments.append('/* x%s value */ ' % index + value)
        text.append('\n')
        return [quoteString(''.join(text))] + arguments
Exemplo n.º 3
0
 def createLength(self):
     return quoteString(self.long_string.createValue())
Exemplo n.º 4
0
 def createCharacter(self):
     value = self.character_generator.createValue()
     return quoteString(value)
Exemplo n.º 5
0
 def createRandomString(self):
     value = self.random_string_generator.createValue()
     return quoteString(value)
Exemplo n.º 6
0
 def createSmartString(self):
     value = self.smart_string_generator.createValue()
     return quoteString(value)
Exemplo n.º 7
0
 def createPrintf(self):
     count = randint(1, 20)
     format = ('%' + choice(self.printf_set) for index in xrange(count))
     value = ''.join(format)
     return quoteString(value)