check_deref: use add_dereference_hook()
[smatch.git] / smatch_data / db / init_constraints.pl
blobe2bc868553180d5515d1fadb2f9b5f6bfa583772
1 #!/usr/bin/perl -w
3 use strict;
4 use warnings;
5 use bigint;
6 use DBI;
7 use Data::Dumper;
8 use File::Basename;
9 use Try::Tiny;
11 my $project = shift;
12 $project =~ s/.*=(.*)/$1/;
13 my $warns = shift;
14 my $db_file = shift;
16 sub preserve_existing_constraints()
18 if (! -e "smatch_db.sqlite") {
19 return;
22 my $db = DBI->connect("dbi:SQLite:$db_file", "", "",);
23 $db->do('attach "smatch_db.sqlite" as old_db');
24 $db->do('insert into constraints select * from old_db.constraints');
25 $db->disconnect();
28 my $db;
30 sub connect_to_db($)
32 my $name = shift;
34 $db = DBI->connect("dbi:SQLite:$name", "", "", {AutoCommit => 0});
36 $db->do("PRAGMA cache_size = 800000");
37 $db->do("PRAGMA journal_mode = OFF");
38 $db->do("PRAGMA count_changes = OFF");
39 $db->do("PRAGMA temp_store = MEMORY");
40 $db->do("PRAGMA locking = EXCLUSIVE");
43 sub load_manual_constraints($$)
45 my $full_path = shift;
46 my $project = shift;
47 my $dir = dirname($full_path);
49 if ($project =~ /^$/) {
50 return;
53 open(FILE, "$dir/$project.constraints");
54 while (<FILE>) {
55 s/\n//;
56 $db->do("insert or ignore into constraints (str) values ('$_')");
58 close(FILE);
60 open(FILE, "$dir/$project.constraints_required");
61 while (<FILE>) {
62 my $limit;
63 my $dummy;
65 ($dummy, $dummy, $limit) = split(/,/);
66 $limit =~ s/^ +//;
67 $limit =~ s/\n//;
68 try {
69 $db->do("insert or ignore into constraints (str) values ('$limit')");
70 } catch {}
72 close(FILE);
74 $db->commit();
77 preserve_existing_constraints();
79 connect_to_db($db_file);
80 load_manual_constraints($0, $project);
82 $db->commit();
83 $db->disconnect();