26 const std::string &line,
30 std::string error_msg=line;
35 const char *tptr=line.c_str();
37 std::string
file, line_no, column, _error_msg,
function;
51 else if(
has_prefix(tptr,
" column ") && state != 4)
57 else if(
has_prefix(tptr,
" function ") && state != 4)
63 else if(*tptr==
':' && state!=4)
65 if(tptr[1]==
' ' && previous!=
':')
69 while(*tptr==
' ') tptr++;
94 saved_error_location.
set_line(line_no);
99 else if(
has_prefix(line,
"In file included from "))
104 const char *tptr=line.c_str();
106 std::string
file, line_no;
121 else if(isdigit(*tptr))
134 saved_error_location.
set_line(line_no);
146 std::istream &errors,
152 while(std::getline(errors, line))
158 std::istream &instream,
159 std::ostream &outstream,
164 std::ofstream tmp(tmp_file());
173 tmp << instream.rdbuf();
177 bool result=
c_preprocess(tmp_file(), outstream, message_handler);
204 const std::string &path,
205 std::ostream &outstream,
239 const std::string &
file,
240 std::ostream &outstream,
255 std::ofstream command_file(command_file_name());
259 command_file << char(0xef) << char(0xbb) << char(0xbf);
261 command_file <<
"/nologo" <<
'\n';
262 command_file <<
"/E" <<
'\n';
267 command_file <<
"/source-charset:utf-8" <<
'\n';
269 command_file <<
"/D__CPROVER__" <<
"\n";
274 command_file <<
"\"/D__PTRDIFF_TYPE__=long long int\"" <<
"\n";
276 command_file <<
"/D_WIN64" <<
"\n";
283 "Pointer difference expected to be long int typed");
284 command_file <<
"/D__PTRDIFF_TYPE__=long" <<
'\n';
290 "Pointer difference expected to be int typed");
291 command_file <<
"/D__PTRDIFF_TYPE__=int" <<
"\n";
295 command_file <<
"/J" <<
"\n";
298 command_file <<
"/D" <<
shell_quote(define) <<
"\n";
301 command_file <<
"/I" <<
shell_quote(include_path) <<
"\n";
304 command_file <<
"/FI" <<
shell_quote(include_file) <<
"\n";
314 run(
"cl", {
"cl",
"@" + command_file_name()},
"", outstream, stderr_file());
317 std::ifstream stderr_stream(stderr_file());
331 std::istream &instream,
332 std::ostream &outstream)
348 std::getline(instream, line);
351 line[0]==
'#' && (line[1]==
'#' || line[1]==
' ' || line[1]==
'\t'))
355 else if(line.size()>=3 &&
356 line[0]==
'/' && line[1]==
'*' && line[2]==
' ')
358 outstream << line.c_str()+3 <<
"\n";
361 outstream << line <<
"\n";
367 const std::string &
file,
368 std::ostream &outstream,
380 std::vector<std::string> command = {
381 "mwcceppc",
"-E",
"-P",
"-D__CPROVER__",
"-ppopt",
"line",
"-ppopt full"};
384 command.push_back(
" -D" + define);
387 command.push_back(
" -I" + include_path);
391 command.push_back(
" -include");
392 command.push_back(include_file);
396 command.push_back(opt);
399 command.push_back(
file);
400 command.push_back(
"-o");
401 command.push_back(tmpi());
403 int result =
run(command[0], command,
"",
"", stderr_file());
405 std::ifstream stream_i(tmpi());
415 message.
error() <<
"Preprocessing failed (fopen failed)"
421 std::ifstream stderr_stream(stderr_file());
435 const std::string &
file,
436 std::ostream &outstream,
449 std::vector<std::string> argv;
452 argv.push_back(
"clang");
454 argv.push_back(
"gcc");
456 argv.push_back(
"-E");
457 argv.push_back(
"-D__CPROVER__");
463 if(arch ==
"i386" || arch ==
"x86_64" || arch ==
"x32")
464 argv.push_back(
"-m16");
466 argv.push_back(
"-mips16");
470 if(arch ==
"i386" || arch ==
"x86_64")
471 argv.push_back(
"-m32");
472 else if(arch ==
"x32")
473 argv.push_back(
"-mx32");
475 argv.push_back(
"-mabi=32");
476 else if(arch ==
"powerpc" || arch ==
"ppc64" || arch ==
"ppc64le")
477 argv.push_back(
"-m32");
478 else if(arch ==
"s390" || arch ==
"s390x")
479 argv.push_back(
"-m31");
480 else if(arch ==
"sparc" || arch ==
"sparc64")
481 argv.push_back(
"-m32");
485 if(arch ==
"i386" || arch ==
"x86_64" || arch ==
"x32")
486 argv.push_back(
"-m64");
488 argv.push_back(
"-mabi=64");
489 else if(arch ==
"powerpc" || arch ==
"ppc64" || arch ==
"ppc64le")
490 argv.push_back(
"-m64");
491 else if(arch ==
"s390" || arch ==
"s390x")
492 argv.push_back(
"-m64");
493 else if(arch ==
"sparc" || arch ==
"sparc64")
494 argv.push_back(
"-m64");
499 argv.push_back(
"-fshort-wchar");
502 argv.push_back(
"-funsigned-char");
505 argv.push_back(
"-nostdinc");
520 #if defined(__OpenBSD__)
522 argv.push_back(
"-std=c++98");
525 argv.push_back(
"-std=gnu++98");
529 #if defined(__OpenBSD__)
531 argv.push_back(
"-std=c++03");
534 argv.push_back(
"-std=gnu++03");
538 #if defined(__OpenBSD__)
540 argv.push_back(
"-std=c++11");
543 argv.push_back(
"-std=gnu++11");
547 #if defined(__OpenBSD__)
549 argv.push_back(
"-std=c++14");
552 argv.push_back(
"-std=gnu++14");
561 #if defined(__OpenBSD__)
563 argv.push_back(
"-std=c89");
566 argv.push_back(
"-std=gnu89");
570 #if defined(__OpenBSD__)
572 argv.push_back(
"-std=c99");
575 argv.push_back(
"-std=gnu99");
579 #if defined(__OpenBSD__)
581 argv.push_back(
"-std=c11");
584 argv.push_back(
"-std=gnu11");
590 argv.push_back(
"-D" + define);
593 argv.push_back(
"-I" + include_path);
597 argv.push_back(
"-include");
598 argv.push_back(include_file);
610 case configt::ansi_ct::flavourt::GCC_C: command+=
" -x c";
break;
611 case configt::ansi_ct::flavourt::GCC_CPP: command+=
" -x c++";
break;
619 argv.push_back(
file);
622 result =
run(argv[0], argv,
"", outstream, stderr_file());
625 std::ifstream stderr_stream(stderr_file());
639 const std::string &
file,
640 std::ostream &outstream,
652 std::vector<std::string> argv;
654 argv.push_back(
"armcc");
655 argv.push_back(
"-E");
656 argv.push_back(
"-D__CPROVER__");
659 argv.push_back(
"--bigend");
661 argv.push_back(
"--littleend");
664 argv.push_back(
"--unsigned_chars");
666 argv.push_back(
"--signed_chars");
672 argv.push_back(
"--c90");
677 argv.push_back(
"--c99");
682 argv.push_back(
"-D" + define);
685 argv.push_back(
"-I" + include_path);
688 argv.push_back(
file);
693 result =
run(argv[0], argv,
"", outstream, stderr_file());
696 std::ifstream stderr_stream(stderr_file());
710 const std::string &
file,
711 std::ostream &outstream,
717 std::ifstream infile(
file);
736 while(infile.read(&ch, 1))
745 "#include <stdlib.h>\n"
751 std::ostringstream out;
bool c_preprocess_visual_studio(const std::string &, std::ostream &, message_handlert &)
ANSI-C preprocessing.
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'.
mstreamt & warning() const
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)
std::string shell_quote(const std::string &src)
quote a string for bash and CMD
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
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)