27 if(src.find(
' ')==std::string::npos &&
28 src.find(
'"')==std::string::npos &&
29 src.find(
'&')==std::string::npos &&
30 src.find(
'|')==std::string::npos &&
31 src.find(
'(')==std::string::npos &&
32 src.find(
')')==std::string::npos &&
33 src.find(
'<')==std::string::npos &&
34 src.find(
'>')==std::string::npos &&
35 src.find(
'^')==std::string::npos)
45 for(
const char ch : src)
60 if(src.find(
' ')==std::string::npos &&
61 src.find(
'"')==std::string::npos &&
62 src.find(
'*')==std::string::npos &&
63 src.find(
'$')==std::string::npos &&
64 src.find(
'\\')==std::string::npos &&
65 src.find(
'?')==std::string::npos &&
66 src.find(
'&')==std::string::npos &&
67 src.find(
'|')==std::string::npos &&
68 src.find(
'>')==std::string::npos &&
69 src.find(
'<')==std::string::npos &&
70 src.find(
'^')==std::string::npos &&
71 src.find(
'\'')==std::string::npos)
82 for(
const char ch : src)
96 const std::string &line,
100 std::string error_msg=line;
105 const char *tptr=line.c_str();
107 std::string
file, line_no, column, _error_msg,
function;
121 else if(
has_prefix(tptr,
" column ") && state != 4)
127 else if(
has_prefix(tptr,
" function ") && state != 4)
133 else if(*tptr==
':' && state!=4)
135 if(tptr[1]==
' ' && previous!=
':')
139 while(*tptr==
' ') tptr++;
164 saved_error_location.
set_line(line_no);
166 error_msg=_error_msg;
169 else if(
has_prefix(line,
"In file included from "))
174 const char *tptr=line.c_str();
176 std::string
file, line_no;
191 else if(isdigit(*tptr))
204 saved_error_location.
set_line(line_no);
216 std::istream &errors,
222 while(std::getline(errors, line))
228 std::istream &instream,
229 std::ostream &outstream,
234 std::ofstream tmp(tmp_file());
243 tmp << instream.rdbuf();
247 bool result=
c_preprocess(tmp_file(), outstream, message_handler);
274 const std::string &path,
275 std::ostream &outstream,
309 const std::string &
file,
310 std::ostream &outstream,
325 std::ofstream command_file(command_file_name());
329 command_file << char(0xef) << char(0xbb) << char(0xbf);
331 command_file <<
"/nologo" <<
'\n';
332 command_file <<
"/E" <<
'\n';
337 command_file <<
"/source-charset:utf-8" <<
'\n';
339 command_file <<
"/D__CPROVER__" <<
"\n";
344 command_file <<
"\"/D__PTRDIFF_TYPE__=long long int\"" <<
"\n";
346 command_file <<
"/D_WIN64" <<
"\n";
353 "Pointer difference expected to be long int typed");
354 command_file <<
"/D__PTRDIFF_TYPE__=long" <<
'\n';
360 "Pointer difference expected to be int typed");
361 command_file <<
"/D__PTRDIFF_TYPE__=int" <<
"\n";
365 command_file <<
"/J" <<
"\n";
368 command_file <<
"/D" <<
shell_quote(define) <<
"\n";
371 command_file <<
"/I" <<
shell_quote(include_path) <<
"\n";
374 command_file <<
"/FI" <<
shell_quote(include_file) <<
"\n";
384 run(
"cl", {
"cl",
"@" + command_file_name()},
"", outstream, stderr_file());
387 std::ifstream stderr_stream(stderr_file());
401 std::istream &instream,
402 std::ostream &outstream)
418 std::getline(instream, line);
421 line[0]==
'#' && (line[1]==
'#' || line[1]==
' ' || line[1]==
'\t'))
425 else if(line.size()>=3 &&
426 line[0]==
'/' && line[1]==
'*' && line[2]==
' ')
428 outstream << line.c_str()+3 <<
"\n";
431 outstream << line <<
"\n";
437 const std::string &
file,
438 std::ostream &outstream,
450 std::vector<std::string> command = {
451 "mwcceppc",
"-E",
"-P",
"-D__CPROVER__",
"-ppopt",
"line",
"-ppopt full"};
454 command.push_back(
" -D" + define);
457 command.push_back(
" -I" + include_path);
461 command.push_back(
" -include");
462 command.push_back(include_file);
466 command.push_back(opt);
469 command.push_back(
file);
470 command.push_back(
"-o");
471 command.push_back(tmpi());
473 int result =
run(command[0], command,
"",
"", stderr_file());
475 std::ifstream stream_i(tmpi());
485 message.error() <<
"Preprocessing failed (fopen failed)"
491 std::ifstream stderr_stream(stderr_file());
505 const std::string &
file,
506 std::ostream &outstream,
519 std::vector<std::string> argv;
522 argv.push_back(
"clang");
524 argv.push_back(
"gcc");
526 argv.push_back(
"-E");
527 argv.push_back(
"-D__CPROVER__");
533 if(arch ==
"i386" || arch ==
"x86_64" || arch ==
"x32")
534 argv.push_back(
"-m16");
536 argv.push_back(
"-mips16");
540 if(arch ==
"i386" || arch ==
"x86_64")
541 argv.push_back(
"-m32");
542 else if(arch ==
"x32")
543 argv.push_back(
"-mx32");
545 argv.push_back(
"-mabi=32");
546 else if(arch ==
"powerpc" || arch ==
"ppc64" || arch ==
"ppc64le")
547 argv.push_back(
"-m32");
548 else if(arch ==
"s390" || arch ==
"s390x")
549 argv.push_back(
"-m31");
550 else if(arch ==
"sparc" || arch ==
"sparc64")
551 argv.push_back(
"-m32");
555 if(arch ==
"i386" || arch ==
"x86_64" || arch ==
"x32")
556 argv.push_back(
"-m64");
558 argv.push_back(
"-mabi=64");
559 else if(arch ==
"powerpc" || arch ==
"ppc64" || arch ==
"ppc64le")
560 argv.push_back(
"-m64");
561 else if(arch ==
"s390" || arch ==
"s390x")
562 argv.push_back(
"-m64");
563 else if(arch ==
"sparc" || arch ==
"sparc64")
564 argv.push_back(
"-m64");
569 argv.push_back(
"-fshort-wchar");
572 argv.push_back(
"-funsigned-char");
575 argv.push_back(
"-nostdinc");
590 #if defined(__OpenBSD__)
592 argv.push_back(
"-std=c++98");
595 argv.push_back(
"-std=gnu++98");
599 #if defined(__OpenBSD__)
601 argv.push_back(
"-std=c++03");
604 argv.push_back(
"-std=gnu++03");
608 #if defined(__OpenBSD__)
610 argv.push_back(
"-std=c++11");
613 argv.push_back(
"-std=gnu++11");
617 #if defined(__OpenBSD__)
619 argv.push_back(
"-std=c++14");
622 argv.push_back(
"-std=gnu++14");
631 #if defined(__OpenBSD__)
633 argv.push_back(
"-std=c89");
636 argv.push_back(
"-std=gnu89");
640 #if defined(__OpenBSD__)
642 argv.push_back(
"-std=c99");
645 argv.push_back(
"-std=gnu99");
649 #if defined(__OpenBSD__)
651 argv.push_back(
"-std=c11");
654 argv.push_back(
"-std=gnu11");
660 argv.push_back(
"-D" + define);
663 argv.push_back(
"-I" + include_path);
667 argv.push_back(
"-include");
668 argv.push_back(include_file);
680 case configt::ansi_ct::flavourt::GCC_C: command+=
" -x c";
break;
681 case configt::ansi_ct::flavourt::GCC_CPP: command+=
" -x c++";
break;
689 argv.push_back(
file);
692 result =
run(argv[0], argv,
"", outstream, stderr_file());
695 std::ifstream stderr_stream(stderr_file());
709 const std::string &
file,
710 std::ostream &outstream,
722 std::vector<std::string> argv;
724 argv.push_back(
"armcc");
725 argv.push_back(
"-E");
726 argv.push_back(
"-D__CPROVER__");
729 argv.push_back(
"--bigend");
731 argv.push_back(
"--littleend");
734 argv.push_back(
"--unsigned_chars");
736 argv.push_back(
"--signed_chars");
742 argv.push_back(
"--c90");
747 argv.push_back(
"--c99");
752 argv.push_back(
"-D" + define);
755 argv.push_back(
"-I" + include_path);
758 argv.push_back(
file);
763 result =
run(argv[0], argv,
"", outstream, stderr_file());
766 std::ifstream stderr_stream(stderr_file());
780 const std::string &
file,
781 std::ostream &outstream,
787 std::ifstream infile(
file);
806 while(infile.read(&ch, 1))
815 "#include <stdlib.h>\n"
821 std::ostringstream out;
bool c_preprocess_visual_studio(const std::string &, std::ostream &, message_handlert &)
ANSI-C preprocessing.
static std::string shell_quote(const std::string &src)
quote a string for bash and CMD
bool c_preprocess_arm(const std::string &, std::ostream &, message_handlert &)
ANSI-C preprocessing.
bool c_preprocess_none(const std::string &, std::ostream &, message_handlert &)
ANSI-C preprocessing.
static void error_parse(std::istream &errors, bool warning_only, messaget &message)
const char c_test_program[]
tests ANSI-C preprocessing
bool c_preprocess_codewarrior(const std::string &, std::ostream &, message_handlert &)
ANSI-C preprocessing.
static void error_parse_line(const std::string &line, bool warning_only, messaget &message)
void postprocess_codewarrior(std::istream &instream, std::ostream &outstream)
post-processing specifically for CodeWarrior
bool c_preprocess(std::istream &instream, std::ostream &outstream, message_handlert &message_handler)
ANSI-C preprocessing.
bool test_c_preprocessor(message_handlert &message_handler)
bool c_preprocess_gcc_clang(const std::string &, std::ostream &, message_handlert &, configt::ansi_ct::preprocessort)
ANSI-C preprocessing.
static bool is_dot_i_file(const std::string &path)
ANSI-C preprocessing.
signedbv_typet signed_long_int_type()
signedbv_typet signed_int_type()
signedbv_typet pointer_diff_type()
signedbv_typet signed_long_long_int_type()
struct configt::ansi_ct ansi_c
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
source_locationt source_location
Class that provides messages with a built-in verbosity 'level'.
void set_column(const irep_idt &column)
void set_file(const irep_idt &file)
void set_line(const irep_idt &line)
void set_function(const irep_idt &function)
bool has_prefix(const std::string &s, const std::string &prefix)
const std::string & id2string(const irep_idt &d)
int run(const std::string &what, const std::vector< std::string > &argv)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
static const char * message(const statust &status)
Makes a status message string from a status.
std::list< std::string > include_paths
enum configt::ansi_ct::c_standardt c_standard
std::size_t pointer_width
std::list< std::string > include_files
std::list< std::string > preprocessor_options
std::list< std::string > defines
std::size_t wchar_t_width
preprocessort preprocessor
std::size_t short_int_width
enum configt::cppt::cpp_standardt cpp_standard
bool has_suffix(const std::string &s, const std::string &suffix)
std::wstring widen(const char *s)