From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2441 invoked by alias); 16 Oct 2007 19:47:14 -0000 Received: (qmail 2410 invoked by uid 22791); 16 Oct 2007 19:47:09 -0000 X-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,DK_POLICY_SIGNSOME,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 16 Oct 2007 19:47:03 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.1) with ESMTP id l9GJl0VS019265 for ; Tue, 16 Oct 2007 15:47:00 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l9GJkx3U017079 for ; Tue, 16 Oct 2007 15:46:59 -0400 Received: from [172.16.57.153] (multics.rdu.redhat.com [172.16.57.153]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l9GJkuAp031827; Tue, 16 Oct 2007 15:46:56 -0400 Subject: Re: generating type tests From: Stan Cox To: Andrew Cagney Cc: Frysk List In-Reply-To: <47139A01.8070404@redhat.com> References: <1192223570.2947.145.camel@multics.rdu.redhat.com> <470FFAC8.1050909@redhat.com> <1192413836.2947.150.camel@multics.rdu.redhat.com> <47139A01.8070404@redhat.com> Content-Type: multipart/mixed; boundary="=-qpj6tYBY/DWeasBKYvOB" Date: Tue, 16 Oct 2007 19:47:00 -0000 Message-Id: <1192563628.2947.213.camel@multics.rdu.redhat.com> Mime-Version: 1.0 X-Mailer: Evolution 2.10.3 (2.10.3-2.fc7) X-Virus-Checked: Checked by ClamAV on sourceware.org X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2007-q4/txt/msg00058.txt.bz2 --=-qpj6tYBY/DWeasBKYvOB Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 856 On Mon, 2007-10-15 at 12:49 -0400, Andrew Cagney wrote: > if they only need to read/edit a > simple text (.c) file to add additional type tests. The expected > results could be marked with comments: > // LTYPE: struct bar { > // LTYPE: struct foo *f; > // LTYPE: struct bar *b; > // LTYPE: } > // VALUE: { 0x.*, 0x.* } > // STYPE: struct bar > // TEST: bp > > and a page of AWK could translate that into the body of a test. > > For the easy cases, can the generator produce a file like that; I interpreted this as "create a generator that produces output like the above from C source. This python script pretty much does that from an input file of C source. I think it is reasonably solid, but as per the meeting discussion if the preference is to have a tightly defined input file syntax instead then that is okay too. --=-qpj6tYBY/DWeasBKYvOB Content-Disposition: attachment; filename=gen-typetests.py Content-Type: text/x-python; name=gen-typetests.py; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 3178 #!/usr/bin/python import os,posix,sys import re from subprocess import * from os.path import * def usage (): print "Usage: " + sys.argv[0] + " {-help} File" sys.exit(1) def get_dcl (): get_a_line = True dcl = "" semi_count = 0 while (get_a_line): line = d_file.readline() if (line == ""): break if (line.lstrip().find("//") >= 0): continue dcl = dcl + line for c in line: if (c == '{'): semi_count += 1 elif (c == '}'): semi_count -= 1 if (semi_count == 0 and re.compile("^.*; *$").match(line)): break return dcl if (len (sys.argv) == 1): usage() if (sys.argv[1] == "-help"): print "The input file contains C declarations that are converted to tests." print "The following declaration forms are recognized:" print "basic_type string = initial;" print "type string [N]... = {initial};" print "type (* string) [N]... = initial;" print "struct string {initial};" print "struct string string = {initial};" print "enum string {initial};" usage() d_file = open(sys.argv[1], 'r') if (d_file == 0): usage() dcl = get_dcl() types = {'char': "char", 'short': "short", 'int': "int", 'long': "long", 'long long': "long long", 'float': "float", 'double': "double"} while (dcl != ""): dcl = dcl.rstrip() initial = "" if (dcl.find("=") == -1 or dcl.find("enum") >= 0): dcl_end = len(dcl) else: dcl_end = dcl.find("=")-1 print "\nDcl: " + dcl.rstrip()[0:dcl_end] have_arr_ptr = re.compile("\( *\*.*\)").search(dcl) # struct bar b = { 0, 0 }; have_struct_type = re.compile("^\s*(struct|union).*{.*};").search(dcl) and dcl.find("=") == -1 have_typedef = False have_initial = dcl.find("=") >= 0 and dcl.find("enum") == -1 dcl = dcl.rstrip(';') if (have_struct_type): tokens = dcl.split() name = tokens[0] + " " + tokens[1] dcl = re.compile("\s*struct\s*\w+\s+").sub("",dcl,1) elif (have_arr_ptr): name = have_arr_ptr.group(0) name = name[2:len(name)-1].strip() dcl = re.compile("\s" + name + "\s").sub(" ",dcl,1) else: tokens = dcl.split() previous = "" name = tokens[len(tokens)-1] if (have_initial): for t in tokens: if (t == "="): name = previous initial = dcl[dcl.find("="):] break previous = t if (tokens[0] == "typedef"): have_typedef = True if name.find('[') >= 0: name = name[0:name.find('[')] dcl = re.compile("\s+" + name + "[^\w]").sub(" ",dcl,1) print "Name: " + name print "Initial: " + initial.lstrip("=").strip().strip(";") dcl = dcl.replace(initial,"").strip() dcl = re.compile("\s*(static|extern|typedef)\s*").sub("",dcl,1) print "Type: " + dcl if (have_struct_type or have_typedef): types[name] = dcl try: print "Expanded Type:" + types[dcl] except KeyError: True dcl = get_dcl() --=-qpj6tYBY/DWeasBKYvOB Content-Disposition: attachment; filename=sample-types.txt Content-Type: text/plain; name=sample-types.txt; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 14362 struct foo { int i; } f = { 1 }; struct bar { struct foo* f; struct bar *b;}; struct bar b = { 0, 0 }; struct bar bp = { &f, &b }; // char static char char_var = 176; static const char const_char_var = 41; static volatile char volatile_char_var = 41; static char * ptr_char_var = &char_var; static const char * ptr_const_char_var = &char_var; static char * const char_ptr_const_var = &char_var; static volatile char * ptr_volatile_char_var = &char_var; static char * volatile char_ptr_volatile_var = &char_var; // short int static short int short_int_var = 32767; static const short int const_short_int_var = -32767-1; static volatile short int volatile_short_int_var = -32767-1; static short int * ptr_short_int_var = &short_int_var; static const short int * ptr_const_short_int_var = &short_int_var; static short int * const short_int_ptr_const_var = &short_int_var; static volatile short int * ptr_volatile_short_int_var = &short_int_var; static short int * volatile short_int_ptr_volatile_var = &short_int_var; // int static int int_var = 2147483647; static const int const_int_var = -2147483647-1; static volatile int volatile_int_var = -2147483647-1; static int * ptr_int_var = &int_var; static const int * ptr_const_int_var = &int_var; static int * const int_ptr_const_var = &int_var; static volatile int * ptr_volatile_int_var = &int_var; static int * volatile int_ptr_volatile_var = &int_var; // long int static long int long_int_var = 2147483647L; static const long int const_long_int_var = -2147483647L-1; static volatile long int volatile_long_int_var = -2147483647L-1; static long int * ptr_long_int_var = &long_int_var; static const long int * ptr_const_long_int_var = &long_int_var; static long int * const long_int_ptr_const_var = &long_int_var; static volatile long int * ptr_volatile_long_int_var = &long_int_var; static long int * volatile long_int_ptr_volatile_var = &long_int_var; // long long int static long long int long_long_int_var = 9223372036854775807LL; static const long long int const_long_long_int_var = -9223372036854775807LL-1; static volatile long long int volatile_long_long_int_var = -9223372036854775807LL-1; static long long int * ptr_long_long_int_var = &long_long_int_var; static const long long int * ptr_const_long_long_int_var = &long_long_int_var; static long long int * const long_long_int_ptr_const_var = &long_long_int_var; static volatile long long int * ptr_volatile_long_long_int_var = &long_long_int_var; static long long int * volatile long_long_int_ptr_volatile_var = &long_long_int_var; // float static float float_var = 3.402823E+38; static const float const_float_var = 1.175494E-38; static volatile float volatile_float_var = 1.175494E-38; static float * ptr_float_var = &float_var; static const float * ptr_const_float_var = &float_var; static float * const float_ptr_const_var = &float_var; static volatile float * ptr_volatile_float_var = &float_var; static float * volatile float_ptr_volatile_var = &float_var; // double static double double_var = 1.797693E+308; static const double const_double_var = 2.225074E-308; static volatile double volatile_double_var = 2.225074E-308; static double * ptr_double_var = &double_var; static const double * ptr_const_double_var = &double_var; static double * const double_ptr_const_var = &double_var; static volatile double * ptr_volatile_double_var = &double_var; static double * volatile double_ptr_volatile_var = &double_var; // array of char static char arr_char[2] = {41,176}; static char arr_arr_char[2][2] = {{41,176},{41,176}}; static char arr_arr_arr_char[2][2][2] = {{{41,176},{41,176}},{{41,176},{41,176}}}; static char * arr_ptr_arr_arr_char[2] = {arr_arr_char[0],arr_arr_char[1]}; static char (* ptr_arr_char)[2] = &arr_char; // array of short int static short int arr_short_int[2] = {-32767-1,32767}; static short int arr_arr_short_int[2][2] = {{-32767-1,32767},{-32767-1,32767}}; static short int arr_arr_arr_short_int[2][2][2] = {{{-32767-1,32767},{-32767-1,32767}},{{-32767-1,32767},{-32767-1,32767}}}; static short int * arr_ptr_arr_arr_short_int[2] = {arr_arr_short_int[0],arr_arr_short_int[1]}; static short int (* ptr_arr_short_int)[2] = &arr_short_int; // array of int static int arr_int[2] = {-2147483647-1,2147483647}; static int arr_arr_int[2][2] = {{-2147483647-1,2147483647},{-2147483647-1,2147483647}}; static int arr_arr_arr_int[2][2][2] = {{{-2147483647-1,2147483647},{-2147483647-1,2147483647}},{{-2147483647-1,2147483647},{-2147483647-1,2147483647}}}; static int * arr_ptr_arr_arr_int[2] = {arr_arr_int[0],arr_arr_int[1]}; static int (* ptr_arr_int)[2] = &arr_int; // array of long int static long int arr_long_int[2] = {-2147483647L-1,2147483647L}; static long int arr_arr_long_int[2][2] = {{-2147483647L-1,2147483647L},{-2147483647L-1,2147483647L}}; static long int arr_arr_arr_long_int[2][2][2] = {{{-2147483647L-1,2147483647L},{-2147483647L-1,2147483647L}},{{-2147483647L-1,2147483647L},{-2147483647L-1,2147483647L}}}; static long int * arr_ptr_arr_arr_long_int[2] = {arr_arr_long_int[0],arr_arr_long_int[1]}; static long int (* ptr_arr_long_int)[2] = &arr_long_int; // array of long long int static long long int arr_long_long_int[2] = {-9223372036854775807LL-1,9223372036854775807LL}; static long long int arr_arr_long_long_int[2][2] = {{-9223372036854775807LL-1,9223372036854775807LL},{-9223372036854775807LL-1,9223372036854775807LL}}; static long long int arr_arr_arr_long_long_int[2][2][2] = {{{-9223372036854775807LL-1,9223372036854775807LL},{-9223372036854775807LL-1,9223372036854775807LL}},{{-9223372036854775807LL-1,9223372036854775807LL},{-9223372036854775807LL-1,9223372036854775807LL}}}; static long long int * arr_ptr_arr_arr_long_long_int[2] = {arr_arr_long_long_int[0],arr_arr_long_long_int[1]}; static long long int (* ptr_arr_long_long_int)[2] = &arr_long_long_int; // array of float static float arr_float[2] = {1.175494E-38,3.402823E+38}; static float arr_arr_float[2][2] = {{1.175494E-38,3.402823E+38},{1.175494E-38,3.402823E+38}}; static float arr_arr_arr_float[2][2][2] = {{{1.175494E-38,3.402823E+38},{1.175494E-38,3.402823E+38}},{{1.175494E-38,3.402823E+38},{1.175494E-38,3.402823E+38}}}; static float * arr_ptr_arr_arr_float[2] = {arr_arr_float[0],arr_arr_float[1]}; static float (* ptr_arr_float)[2] = &arr_float; // array of double static double arr_double[2] = {2.225074E-308,1.797693E+308}; static double arr_arr_double[2][2] = {{2.225074E-308,1.797693E+308},{2.225074E-308,1.797693E+308}}; static double arr_arr_arr_double[2][2][2] = {{{2.225074E-308,1.797693E+308},{2.225074E-308,1.797693E+308}},{{2.225074E-308,1.797693E+308},{2.225074E-308,1.797693E+308}}}; static double * arr_ptr_arr_arr_double[2] = {arr_arr_double[0],arr_arr_double[1]}; static double (* ptr_arr_double)[2] = &arr_double; static int one = 1, two = 2, three = 3, four = 4; static struct { int int_var; } arr_struct[2] = {{1},{2}}; static union { int int_var; float float_var; } arr_union[2] = {{1},{2}}; static struct { int int_var; } arr_arr_struct[2][2] = {{{1},{2}},{{3},{4}}}; static union { int int_var; float float_var; } arr_arr_union[2][2] = {{{1},{2}},{{3},{4}}}; static int * arr_arr_ptr[2][2] = {{&one,&two},{&three,&four}}; static struct { int arr_int[2]; } arr_struct_arr_int[2] = {{{1, 2}}, {{3, 4}}}; static struct { struct { int int_var; } struct_a; } arr_struct_struct[2] = {{{1}},{{2}}}; static struct { union { int int_var; float float_var; } struct_a; } arr_struct_union[2] = {{{1}},{{2}}}; static struct { int * ptr; } arr_struct_ptr[2] = {{&one},{&two}}; static union { int arr_int[2]; float arr_float[2]; } arr_union_arr_int[2] = {{{1, 2}}, {{3, 4}}}; static union { struct { int int_var; } struct_a; } arr_union_struct[2] = {{{1}}, {{2}}}; static union { union { int int_var; } union_a; } arr_union_union[2] = {{{1}}, {{2}}}; static union { int * ptr; } arr_union_ptr[2] = {{&one}, {&two}}; static struct { int int_var; } * arr_ptr_struct[2] ; static union { int int_var; float float_var; } * arr_ptr_union[2] ; static int * * arr_ptr_ptr[2] ; static struct { int int_var; } (* ptr_arr_struct)[2] ; static union { int int_var; } (* ptr_arr_union)[2] ; static int * (* ptr_arr_ptr)[2] ; typedef struct { char char_var; short short_var; int int_var; long long_var; float float_var; double double_var; char arr_char[4]; } type_struct; typedef struct { type_struct type_struct_min; type_struct type_struct_max; } type_type_struct; type_type_struct type_minmax_struct = {{41, -32767-1, -2147483647-1, -2147483647L-1, 1.175494E-38, 2.225074E-308, "ABC"}, {176, 32767, 2147483647, 2147483647L, 3.402823E+38, 1.797693E+308, "XYZ"} }; static struct { unsigned int bit1_0:1; unsigned int bit1_1:1; char char_2; unsigned int bit1_6:1; unsigned int bit1_7:1; char char_8; unsigned int bit1_9:1; unsigned int bit1_10:1; } bitfields_small_var = {1, 0, 0x7f, 1, 0, 0x7f, 1, 0}; static struct { unsigned char char_0; int bit1_4:1; unsigned int bit1_5:1; int bit2_6:2; unsigned int bit2_8:2; int bit3_10:3; unsigned int bit3_13:3; int bit9_16:9; unsigned int bit9_25:9; char char_34; } bitfields_bit_var = {0x7f, 1, 1, 1, 3, 3, 7, UINT8_MAX, 511, 0x7f}; static struct { short int arr_short[2]; } struct_arr_short_var = {{1, 2}}; static struct { struct { int int_var; } struct_a; } struct_struct_var = {{1}}; static struct { union { int int_var; } union_a; } struct_union_var = {{1}}; static struct { int * ptr_int; } struct_ptr_var = {&one}; static union { int arr_int[4]; float arr_float[4]; } union_arr_var = {{1, 2, 3, 4}}; static union { struct { int int_var; } struct_a; } union_struct_var = {{1}}; static union { union { int int_var; float float_var; } union_a; } union_union_var = {{1}}; static union { int * ptr_int; } union_ptr_var = {&one}; static struct { int int_var; } * ptr_struct_var ; static union { int int_var; } * ptr_union_var ; static struct { int arr_arr_int[2][2]; } struct_arr_arr_int_var = {{{1, 2}, {3, 4}}}; static struct { struct { int int_var; } arr_struct[2]; } struct_arr_struct_var = {{{1}, {2}}}; static struct { union { int int_var; } arr_union[4]; } struct_arr_union_var = {{{1}, {2}}}; static struct { int * arr_ptr[2]; } struct_arr_ptr_var = {{&one, &two}}; static struct { struct { int arr_int[2]; } struct_arr; } struct_struct_arr_int_var = {{{1, 2}}}; static struct { struct { struct { int int_var; } struct_a; } struct_struct; } struct_struct_struct_var = {{{1}}}; static struct { struct { union { char int_var; } union_a; } struct_union; } struct_struct_union_var = {{{1}}}; static struct { struct { int * ptr_int; } sp; } struct_struct_ptr_var = {{&three}}; static struct { union { int arr_int[4]; } union_arr_int; } struct_union_arr_var = {{{1, 2, 3, 4}}}; static struct { union { struct { int int_var; } struct_a; } union_struct; } struct_union_struct_var = {{{1}}}; static struct { union { union { long int int_var; float float_var; } union_a; } union_union; } struct_union_union_var = {{{1.0}}}; static struct { union { int * ptr_int; } union_ptr; } struct_union_ptr_var = {{&four}}; static struct { int (* ptr_arr)[4]; } struct_ptr_arr_var ; static struct { struct { int int_var; } * ptr_struct; } struct_ptr_struct_var ; static struct { union { int int_var; } * ptr_union; } struct_ptr_union_var ; static struct { int * * ptr_ptr; } struct_ptr_ptr_var ; static union { int arr_int[2][2]; float arr_float[2][2]; } union_arr_int_var = {{{1, 2}, {3, 4}}}; static union { struct { int int_var; } arr_struct[2]; } union_arr_struct_var = {{{1}}}; static union { union { int int_var; float float_var; } arr_union[2]; } union_arr_union_var = {{{1.1}}}; static union { int * arr_ptr[4]; } union_arr_ptr_var = {{&one}}; static union { struct { int arr_int[4]; } struct_arr; } union_struct_arr_int_var = {{{1, 2, 3, 4}}}; static union { struct { struct { int int_var; } struct_a; } struct_b; } union_struct_struct_var = {{{1}}}; static union { struct { union { int int_var; float float_var; } union_a; } struct_a; } union_struct_union_var = {{{1.1}}}; static union { struct { int * ptr_int; } struct_ptr; } union_struct_ptr_var = {{&one}}; static union { union { long long int arr_int[4]; } union_arr; } union_union_arr_int_var = {{{1, 2, 3, 4}}}; static union { union { struct { long long int int_var; } struct_a; } union_a; } union_union_struct_var = {{{1}}}; static union { union { union { int int_var; float float_var; } union_a; } union_b; } union_union_union_var = {{{1.1}}}; static union { union { int * ptr_int; float * ptr_float; } union_ptr; } union_union_ptr_var = {{&one}}; static union { int (* ptr_arr)[4]; } union_ptr_arr_var ; static union { struct { int int_var; } * ptr_struct; } union_ptr_struct_var ; static union { union { int int_var; } * ptr_union; } union_ptr_union_var ; static union { int * * ptr_ptr; } union_ptr_ptr_var ; static struct { int arr_int[4]; } * ptr_struct_arr_int_var ; static struct { struct { int int_var; } struct_a; } * ptr_struct_struct_var ; static struct { union { int int_var; } union_a; } * ptr_struct_union_var ; static struct { int * ptr_int; } * ptr_struct_ptr_var ; static union { int arr_int[4]; } * ptr_union_arr_int_var ; static union { struct { int int_var; } struct_a; } * ptr_union_struct_var ; static union { union { int int_var; } union_a; } * ptr_union_union_var ; static union { int * ptr_int; } * ptr_union_ptr_var ; static struct { int int_var; } * * ptr_ptr_struct_var ; static union { int int_var; } * * ptr_ptr_union_var ; static enum { red = 0, green = 1, blue = 2 } primary_colors_var ; static enum colors { orange = 0, yellow = 1, violet = 2, indigo = 3 } rainbow_colors_var ; static enum { chevy = 33, dodge = 44, ford = 55 } usa_cars_var ; static enum cars { bmw = 0, mercedes = 1, porsche = 2 } european_cars_var ; --=-qpj6tYBY/DWeasBKYvOB--