buf_size, db: if a struct member size is set in the file that's the size
[smatch.git] / smatch_scripts / db / fill_db_type_size.pl
blob6b27476fb05be3a61f603b308970edc2e985d49c
1 #!/usr/bin/perl -w
3 use strict;
4 use DBI;
6 my $warns = shift;
8 if (!defined($warns)) {
9 print "usage: $0 <warns.txt>\n";
10 exit(1);
13 my $db = DBI->connect("dbi:SQLite:smatch_db.sqlite", "", "", {RaiseError => 1, AutoCommit => 0});
14 $db->do("PRAGMA synchronous = OFF");
15 $db->do("PRAGMA cache_size = 800000");
16 $db->do("PRAGMA journal_mode = OFF");
18 $db->do("delete from type_size;");
20 my $types = {};
21 my ($file_and_line, $file, $dummy, $struct_bit, $member, $size);
23 open(WARNS, "<$warns");
24 while (<WARNS>) {
25 if (!($_ =~ / allocated_buf_size /)) {
26 next;
29 # lib/prio_heap.c:12 heap_init() info: '(struct ptr_heap)->ptrs' allocated_buf_size 4096
31 s/\n//;
32 s/'//g;
34 ($file_and_line, $dummy, $dummy, $struct_bit, $member, $dummy, $size) = split(/ /, $_);
35 ($file, $dummy) = split(/:/, $file_and_line);
37 if (!defined($size)) {
38 next;
40 if (!($struct_bit =~ /^\(struct$/)) {
41 next;
44 if (defined($types->{$member}) && $types->{$member} != $size) {
45 $size = -1;
48 $types->{$member} = $size;
49 $db->do("insert into type_size values ('$file', '(struct $member', '$size')\n");
53 #foreach my $key (keys($types)) {
54 # if ($types->{$key} != -1) {
55 # $db->do("insert into type_size values ('$file', '(struct $key', '$types->{$key}')\n");
56 # }
59 $db->commit();
60 $db->disconnect();