param_key: fix container of when no struct member is referenced
[smatch.git] / smatch_data / db / insert_manual_states.pl
blobc6682702d65ca0949dc21f824e79cb2ea3e4a11e
1 #!/usr/bin/perl -w
3 use strict;
4 use warnings;
5 use File::Basename;
6 use DBI;
8 my $bin_dir = dirname($0);
9 my $project = shift;
10 my $db_file = shift;
11 if (!defined($db_file)) {
12 print "usage: $0 <project> <db_file>\n";
13 exit(1);
15 my $insertions = "$bin_dir/$project.insert.return_states";
17 my $db = DBI->connect("dbi:SQLite:$db_file", "", "", {AutoCommit => 0});
18 $db->do("PRAGMA cache_size = 800000");
19 $db->do("PRAGMA journal_mode = OFF");
20 $db->do("PRAGMA count_changes = OFF");
21 $db->do("PRAGMA temp_store = MEMORY");
22 $db->do("PRAGMA locking = EXCLUSIVE");
24 sub insert_record($$$$$$$)
26 my $file = shift;
27 my $func = shift;
28 my $ret = shift;
29 my $type = shift;
30 my $param = shift;
31 my $key = shift;
32 my $value = shift;
34 # print "file = '$file' func = '$func' ret = $ret\n";
35 # print "type = $type param = $param, key = $key, value = '$value'\n";
36 # print "select file, return_id, return, static from return_states where function = '$func' and return = '$ret' and type = 0;'\n";
38 my $sth;
39 if ($file ne '') {
40 $sth = $db->prepare("select file, return_id, call_id, static from return_states where file = ? and function = ? and return = ? and type = 0;");
41 $sth->execute($file, $func, $ret);
42 } else {
43 $sth = $db->prepare("select file, return_id, call_id, static from return_states where function = ? and return = ? and type = 0;");
44 $sth->execute($func, $ret);
47 my $exists = $db->prepare("select count(*) from return_states where file = ? and function = ? and return_id = ? and static = ? and return = ? and type = ? and parameter = ? and key = ? and value = ?;");
48 my $insert = $db->prepare("insert into return_states values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
49 while (my @row = $sth->fetchrow_array()) {
50 my $file = $row[0];
51 my $return_id = $row[1];
52 my $call_id = $row[2];
53 my $static = $row[3];
55 $exists->execute($file, $func, $return_id, $static, $ret, $type, $param, $key, $value);
56 my $count = $exists->fetchrow_array();
57 if ($count == 1) {
58 next;
61 $insert->execute($file, $func, $call_id, $return_id, $ret, $static, $type, $param, $key, $value);
65 my ($ret, $insert, $file, $func, $type, $param, $key, $value);
67 open(FILE, "<$insertions");
68 while (<FILE>) {
70 if ($_ =~ /^\s*#/) {
71 next;
74 ($ret, $insert) = split(/\|/, $_);
76 if ($ret =~ /(.+),\W*(.+),\W*"(.*)"/) {
77 $file = $1;
78 $func = $2;
79 $ret = $3;
80 } elsif ($ret =~ /(.+),\W*"(.*)"/) {
81 $file = "";
82 $func = $1;
83 $ret = $2;
84 } else {
85 next;
88 ($type, $param, $key, $value) = split(/,/, $insert);
90 $type = int($type);
91 $param = int($param);
92 $key =~ s/^["\s]+|["\s]+$//g;
93 $value =~ s/^["\s]+|["\s]+$//g;
94 chomp($value);
96 insert_record($file, $func, $ret, $type, $param, $key, $value);
98 close(FILE);
100 $db->commit();
101 $db->disconnect();