Example #1
0
void
GlobObj::dumpSql(Sql *db, ostream &of)
{
	// First define all functions
	for (const_fmap_iterator_type i = fbegin(); i != fend(); i++) {
		Call *fun = i->second;
		Tokid t = fun->get_site();
		of << "INSERT INTO FUNCTIONS VALUES(" <<
		ptr_offset(fun) << ", '" <<
		fun->name << "', " <<
		db->boolval(fun->is_macro()) << ',' <<
		db->boolval(fun->is_defined()) << ',' <<
		db->boolval(fun->is_declared()) << ',' <<
		db->boolval(fun->is_file_scoped()) << ',' <<
		t.get_fileid().get_id() << ',' <<
		(unsigned)(t.get_streampos()) << ',' <<
		fun->get_num_caller();
		of << ");\n";

		if (fun->is_defined()) {
			of << "INSERT INTO FUNCTIONMETRICS VALUES(" << ptr_offset(fun);
			for (int j = 0; j < FunMetrics::metric_max; j++)
				if (!Metrics::is_internal<FunMetrics>(j))
					cout << ',' << fun->metrics().get_metric(j);
			of << ',' << fun->get_begin().get_tokid().get_fileid().get_id() <<
			',' << (unsigned)(fun->get_begin().get_tokid().get_streampos()) <<
			',' << fun->get_end().get_tokid().get_fileid().get_id() <<
			',' << (unsigned)(fun->get_end().get_tokid().get_streampos());
			of << ");\n";
		}

		int start = 0, ord = 0;
		for (dequeTpart::const_iterator j = fun->get_token().get_parts_begin(); j != fun->get_token().get_parts_end(); j++) {
			Tokid t2 = j->get_tokid();
			int len = j->get_len() - start;
			int pos = 0;
			while (pos < len) {
				Eclass *ec = t2.get_ec();
				of << "INSERT INTO FUNCTIONID VALUES(" <<
				ptr_offset(fun) << ',' <<
				ord << ',' <<
				ptr_offset(ec) << ");\n";
				pos += ec->get_len();
				t2 += ec->get_len();
				ord++;
			}
			start += j->get_len();
		}
	}

	// Then their calls to satisfy integrity constraints
	for (const_fmap_iterator_type i = fbegin(); i != fend(); i++) {
		Call *fun = i->second;
		for (Call::const_fiterator_type dest = fun->call_begin(); dest != fun->call_end(); dest++)
			of << "INSERT INTO FCALLS VALUES(" <<
			    ptr_offset(fun) << ',' <<
			    ptr_offset(*dest) << ");\n";
	}
}