Skip to content

Commit 1cdbff4

Browse files
thk123tautschnig
thk123
authored andcommitted
Updated dump-C to use the new class
1 parent ecd864a commit 1cdbff4

File tree

4 files changed

+55
-302
lines changed

4 files changed

+55
-302
lines changed

src/goto-instrument/dump_c.cpp

Lines changed: 4 additions & 261 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ void dump_ct::operator()(std::ostream &os)
148148

149149
// we don't want to dump in full all definitions; in particular
150150
// do not dump anonymous types that are defined in system headers
151-
if((!tag_added || symbol.is_type) && ignore(symbol))
151+
if((!tag_added || symbol.is_type) &&
152+
system_symbols.is_symbol_internal_symbol(symbol, system_headers))
152153
continue;
153154

154155
bool inserted=symbols_sorted.insert(name_str).second;
@@ -317,7 +318,7 @@ void dump_ct::convert_compound(
317318
ns.lookup(to_symbol_type(type).get_identifier());
318319
DATA_INVARIANT(symbol.is_type, "symbol expected to be type symbol");
319320

320-
if(!ignore(symbol))
321+
if(!system_symbols.is_symbol_internal_symbol(symbol, system_headers))
321322
convert_compound(symbol.type, unresolved, recursive, os);
322323
}
323324
else if(type.id()==ID_c_enum_tag)
@@ -326,7 +327,7 @@ void dump_ct::convert_compound(
326327
ns.lookup(to_c_enum_tag_type(type).get_identifier());
327328
DATA_INVARIANT(symbol.is_type, "symbol expected to be type symbol");
328329

329-
if(!ignore(symbol))
330+
if(!system_symbols.is_symbol_internal_symbol(symbol, system_headers))
330331
convert_compound(symbol.type, unresolved, recursive, os);
331332
}
332333
else if(type.id()==ID_array || type.id()==ID_pointer)
@@ -581,195 +582,6 @@ void dump_ct::convert_compound_enum(
581582
os << ";\n\n";
582583
}
583584

584-
#define ADD_TO_SYSTEM_LIBRARY(v, header) \
585-
for(size_t i=0; i<sizeof(v)/sizeof(char*); ++i) \
586-
system_library_map.insert( \
587-
std::make_pair(v[i], header))
588-
589-
void dump_ct::init_system_library_map()
590-
{
591-
// ctype.h
592-
const char* ctype_syms[]=
593-
{
594-
"isalnum", "isalpha", "isblank", "iscntrl", "isdigit", "isgraph",
595-
"islower", "isprint", "ispunct", "isspace", "isupper", "isxdigit",
596-
"tolower", "toupper"
597-
};
598-
ADD_TO_SYSTEM_LIBRARY(ctype_syms, "ctype.h");
599-
600-
// fcntl.h
601-
const char* fcntl_syms[]=
602-
{
603-
"creat", "fcntl", "open"
604-
};
605-
ADD_TO_SYSTEM_LIBRARY(fcntl_syms, "fcntl.h");
606-
607-
// locale.h
608-
const char* locale_syms[]=
609-
{
610-
"setlocale"
611-
};
612-
ADD_TO_SYSTEM_LIBRARY(locale_syms, "locale.h");
613-
614-
// math.h
615-
const char* math_syms[]=
616-
{
617-
"acos", "acosh", "asin", "asinh", "atan", "atan2", "atanh",
618-
"cbrt", "ceil", "copysign", "cos", "cosh", "erf", "erfc", "exp",
619-
"exp2", "expm1", "fabs", "fdim", "floor", "fma", "fmax", "fmin",
620-
"fmod", "fpclassify", "frexp", "hypot", "ilogb", "isfinite",
621-
"isinf", "isnan", "isnormal", "j0", "j1", "jn", "ldexp", "lgamma",
622-
"llrint", "llround", "log", "log10", "log1p", "log2", "logb",
623-
"lrint", "lround", "modf", "nan", "nearbyint", "nextafter", "pow",
624-
"remainder", "remquo", "rint", "round", "scalbln", "scalbn",
625-
"signbit", "sin", "sinh", "sqrt", "tan", "tanh", "tgamma",
626-
"trunc", "y0", "y1", "yn"
627-
};
628-
ADD_TO_SYSTEM_LIBRARY(math_syms, "math.h");
629-
630-
// pthread.h
631-
const char* pthread_syms[]=
632-
{
633-
"pthread_cleanup_pop", "pthread_cleanup_push",
634-
"pthread_cond_broadcast", "pthread_cond_destroy",
635-
"pthread_cond_init", "pthread_cond_signal",
636-
"pthread_cond_timedwait", "pthread_cond_wait", "pthread_create",
637-
"pthread_detach", "pthread_equal", "pthread_exit",
638-
"pthread_getspecific", "pthread_join", "pthread_key_delete",
639-
"pthread_mutex_destroy", "pthread_mutex_init",
640-
"pthread_mutex_lock", "pthread_mutex_trylock",
641-
"pthread_mutex_unlock", "pthread_once", "pthread_rwlock_destroy",
642-
"pthread_rwlock_init", "pthread_rwlock_rdlock",
643-
"pthread_rwlock_unlock", "pthread_rwlock_wrlock",
644-
"pthread_rwlockattr_destroy", "pthread_rwlockattr_getpshared",
645-
"pthread_rwlockattr_init", "pthread_rwlockattr_setpshared",
646-
"pthread_self", "pthread_setspecific",
647-
/* non-public struct types */
648-
"tag-__pthread_internal_list", "tag-__pthread_mutex_s",
649-
"pthread_mutex_t"
650-
};
651-
ADD_TO_SYSTEM_LIBRARY(pthread_syms, "pthread.h");
652-
653-
// setjmp.h
654-
const char* setjmp_syms[]=
655-
{
656-
"_longjmp", "_setjmp", "longjmp", "longjmperror", "setjmp",
657-
"siglongjmp", "sigsetjmp"
658-
};
659-
ADD_TO_SYSTEM_LIBRARY(setjmp_syms, "setjmp.h");
660-
661-
// stdio.h
662-
const char* stdio_syms[]=
663-
{
664-
"asprintf", "clearerr", "fclose", "fdopen", "feof", "ferror",
665-
"fflush", "fgetc", "fgetln", "fgetpos", "fgets", "fgetwc",
666-
"fgetws", "fileno", "fopen", "fprintf", "fpurge", "fputc",
667-
"fputs", "fputwc", "fputws", "fread", "freopen", "fropen",
668-
"fscanf", "fseek", "fsetpos", "ftell", "funopen", "fwide",
669-
"fwopen", "fwprintf", "fwrite", "getc", "getchar", "getdelim",
670-
"getline", "gets", "getw", "getwc", "getwchar", "mkdtemp",
671-
"mkstemp", "mktemp", "perror", "printf", "putc", "putchar",
672-
"puts", "putw", "putwc", "putwchar", "remove", "rewind", "scanf",
673-
"setbuf", "setbuffer", "setlinebuf", "setvbuf", "snprintf",
674-
"sprintf", "sscanf", "swprintf", "sys_errlist",
675-
"sys_nerr", "tempnam", "tmpfile", "tmpnam", "ungetc", "ungetwc",
676-
"vasprintf", "vfprintf", "vfscanf", "vfwprintf", "vprintf",
677-
"vscanf", "vsnprintf", "vsprintf", "vsscanf", "vswprintf",
678-
"vwprintf", "wprintf",
679-
/* non-public struct types */
680-
"tag-__sFILE", "tag-__sbuf", // OS X
681-
"tag-_IO_FILE", "tag-_IO_marker", // Linux
682-
};
683-
ADD_TO_SYSTEM_LIBRARY(stdio_syms, "stdio.h");
684-
685-
// stdlib.h
686-
const char* stdlib_syms[]=
687-
{
688-
"abort", "abs", "atexit", "atof", "atoi", "atol", "atoll",
689-
"bsearch", "calloc", "div", "exit", "free", "getenv", "labs",
690-
"ldiv", "llabs", "lldiv", "malloc", "mblen", "mbstowcs", "mbtowc",
691-
"qsort", "rand", "realloc", "srand", "strtod", "strtof", "strtol",
692-
"strtold", "strtoll", "strtoul", "strtoull", "system", "wcstombs",
693-
"wctomb"
694-
};
695-
ADD_TO_SYSTEM_LIBRARY(stdlib_syms, "stdlib.h");
696-
697-
// string.h
698-
const char* string_syms[]=
699-
{
700-
"strcat", "strncat", "strchr", "strrchr", "strcmp", "strncmp",
701-
"strcpy", "strncpy", "strerror", "strlen", "strpbrk", "strspn",
702-
"strcspn", "strstr", "strtok"
703-
};
704-
ADD_TO_SYSTEM_LIBRARY(string_syms, "string.h");
705-
706-
// time.h
707-
const char* time_syms[]=
708-
{
709-
"asctime", "asctime_r", "ctime", "ctime_r", "difftime", "gmtime",
710-
"gmtime_r", "localtime", "localtime_r", "mktime", "strftime",
711-
/* non-public struct types */
712-
"tag-timespec", "tag-timeval", "tag-tm"
713-
};
714-
ADD_TO_SYSTEM_LIBRARY(time_syms, "time.h");
715-
716-
// unistd.h
717-
const char* unistd_syms[]=
718-
{
719-
"_exit", "access", "alarm", "chdir", "chown", "close", "dup",
720-
"dup2", "execl", "execle", "execlp", "execv", "execve", "execvp",
721-
"fork", "fpathconf", "getcwd", "getegid", "geteuid", "getgid",
722-
"getgroups", "getlogin", "getpgrp", "getpid", "getppid", "getuid",
723-
"isatty", "link", "lseek", "pathconf", "pause", "pipe", "read",
724-
"rmdir", "setgid", "setpgid", "setsid", "setuid", "sleep",
725-
"sysconf", "tcgetpgrp", "tcsetpgrp", "ttyname", "ttyname_r",
726-
"unlink", "write"
727-
};
728-
ADD_TO_SYSTEM_LIBRARY(unistd_syms, "unistd.h");
729-
730-
// sys/select.h
731-
const char* sys_select_syms[]=
732-
{
733-
"select",
734-
/* non-public struct types */
735-
"fd_set"
736-
};
737-
ADD_TO_SYSTEM_LIBRARY(sys_select_syms, "sys/select.h");
738-
739-
// sys/socket.h
740-
const char* sys_socket_syms[]=
741-
{
742-
"accept", "bind", "connect",
743-
/* non-public struct types */
744-
"tag-sockaddr"
745-
};
746-
ADD_TO_SYSTEM_LIBRARY(sys_socket_syms, "sys/socket.h");
747-
748-
// sys/stat.h
749-
const char* sys_stat_syms[]=
750-
{
751-
"fstat", "lstat", "stat",
752-
/* non-public struct types */
753-
"tag-stat"
754-
};
755-
ADD_TO_SYSTEM_LIBRARY(sys_stat_syms, "sys/stat.h");
756-
757-
/*
758-
// sys/types.h
759-
const char* sys_types_syms[]=
760-
{
761-
};
762-
ADD_TO_SYSTEM_LIBRARY(sys_types_syms, "sys/types.h");
763-
*/
764-
765-
// sys/wait.h
766-
const char* sys_wait_syms[]=
767-
{
768-
"wait", "waitpid"
769-
};
770-
ADD_TO_SYSTEM_LIBRARY(sys_wait_syms, "sys/wait.h");
771-
}
772-
773585
/*******************************************************************\
774586
775587
Function: dump_ct::ignore
@@ -790,75 +602,6 @@ bool dump_ct::ignore(const typet &type)
790602
return ignore(symbol);
791603
}
792604

793-
/*******************************************************************\
794-
795-
Function: dump_ct::ignore
796-
797-
Inputs: type input to check whether it should not be dumped
798-
799-
Outputs: true, iff the symbol should not be printed
800-
801-
Purpose: Ignore selected symbols as they are covered via system headers
802-
803-
\*******************************************************************/
804-
805-
bool dump_ct::ignore(const symbolt &symbol)
806-
{
807-
const std::string &name_str=id2string(symbol.name);
808-
809-
if(has_prefix(name_str, CPROVER_PREFIX) ||
810-
name_str=="__func__" ||
811-
name_str=="__FUNCTION__" ||
812-
name_str=="__PRETTY_FUNCTION__" ||
813-
name_str=="argc'" ||
814-
name_str=="argv'" ||
815-
name_str=="envp'" ||
816-
name_str=="envp_size'")
817-
return true;
818-
819-
if(has_suffix(name_str, "$object"))
820-
return true;
821-
822-
const std::string &file_str=id2string(symbol.location.get_file());
823-
824-
// don't dump internal GCC builtins
825-
if(has_prefix(file_str, "gcc_builtin_headers_") &&
826-
has_prefix(name_str, "__builtin_"))
827-
return true;
828-
829-
if(name_str=="__builtin_va_start" ||
830-
name_str=="__builtin_va_end" ||
831-
symbol.name==ID_gcc_builtin_va_arg)
832-
{
833-
system_headers.insert("stdarg.h");
834-
return true;
835-
}
836-
837-
system_library_mapt::const_iterator it=
838-
system_library_map.find(symbol.name);
839-
840-
if(it!=system_library_map.end())
841-
{
842-
system_headers.insert(it->second);
843-
return true;
844-
}
845-
846-
if(use_all_headers &&
847-
has_prefix(file_str, "/usr/include/"))
848-
{
849-
if(file_str.find("/bits/")==std::string::npos)
850-
{
851-
// Do not include transitive includes of system headers!
852-
std::string::size_type prefix_len=std::string("/usr/include/").size();
853-
system_headers.insert(file_str.substr(prefix_len));
854-
}
855-
856-
return true;
857-
}
858-
859-
return false;
860-
}
861-
862605
void dump_ct::cleanup_decl(
863606
code_declt &decl,
864607
std::list<irep_idt> &local_static,

src/goto-instrument/dump_c_class.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected]
1818
#include <util/language.h>
1919

2020
#include <langapi/mode.h>
21+
#include <goto-programs/system_library_symbols.h>
2122

2223
class dump_ct
2324
{
@@ -35,7 +36,7 @@ class dump_ct
3536
use_all_headers(use_all_headers)
3637
{
3738
if(use_system_headers)
38-
init_system_library_map();
39+
system_symbols=system_library_symbolst();
3940
}
4041

4142
virtual ~dump_ct()
@@ -57,9 +58,7 @@ class dump_ct
5758

5859
std::set<std::string> system_headers;
5960

60-
typedef std::unordered_map<irep_idt, std::string, irep_id_hash>
61-
system_library_mapt;
62-
system_library_mapt system_library_map;
61+
system_library_symbolst system_symbols;
6362

6463
typedef std::unordered_map<irep_idt, irep_idt, irep_id_hash>
6564
declared_enum_constants_mapt;
@@ -89,7 +88,6 @@ class dump_ct
8988
std::string type_to_string(const typet &type);
9089
std::string expr_to_string(const exprt &expr);
9190

92-
bool ignore(const symbolt &symbol);
9391
bool ignore(const typet &type);
9492

9593
static std::string indent(const unsigned n)

0 commit comments

Comments
 (0)