MCPcopy Create free account
hub / github.com/Gecode/gecode / parse

Function parse

gecode/flatzinc/parser.tab.cpp:570–618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

568namespace Gecode { namespace FlatZinc {
569
570 FlatZincSpace* parse(const std::string& filename, Printer& p, std::ostream& err,
571 FlatZincSpace* fzs, Rnd& rnd) {
572#ifdef HAVE_MMAP
573 int fd;
574 char* data;
575 struct stat sbuf;
576 fd = open(filename.c_str(), O_RDONLY);
577 if (fd == -1) {
578 err << "Cannot open file " << filename << endl;
579 return NULL;
580 }
581 if (stat(filename.c_str(), &sbuf) == -1) {
582 err << "Cannot stat file " << filename << endl;
583 return NULL;
584 }
585 data = (char*)mmap((caddr_t)0, sbuf.st_size, PROT_READ, MAP_SHARED, fd,0);
586 if (data == (caddr_t)(-1)) {
587 err << "Cannot mmap file " << filename << endl;
588 return NULL;
589 }
590
591 if (fzs == NULL) {
592 fzs = new FlatZincSpace(rnd);
593 }
594 ParserState pp(data, sbuf.st_size, err, fzs);
595#else
596 std::ifstream file;
597 file.open(filename.c_str());
598 if (!file.is_open()) {
599 err << "Cannot open file " << filename << endl;
600 return NULL;
601 }
602 std::string s = string(istreambuf_iterator<char>(file),
603 istreambuf_iterator<char>());
604 if (fzs == NULL) {
605 fzs = new FlatZincSpace(rnd);
606 }
607 ParserState pp(s, err, fzs);
608#endif
609 yylex_init(&pp.yyscanner);
610 yyset_extra(&pp, pp.yyscanner);
611 // yydebug = 1;
612 yyparse(&pp);
613 fillPrinter(pp, p);
614
615 if (pp.yyscanner)
616 yylex_destroy(pp.yyscanner);
617 return pp.hadError ? NULL : pp.fg;
618 }
619
620 FlatZincSpace* parse(std::istream& is, Printer& p, std::ostream& err,
621 FlatZincSpace* fzs, Rnd& rnd) {

Callers 15

mainFunction · 0.85
runMethod · 0.85
parseMethod · 0.85
parseMethod · 0.85
parseMethod · 0.85
parseMethod · 0.85
parseMethod · 0.85
parseMethod · 0.85
parseMethod · 0.85
parseMethod · 0.85
parseMethod · 0.85
parseMethod · 0.85

Calls 6

statClass · 0.85
yylex_initFunction · 0.85
yyset_extraFunction · 0.85
yyparseFunction · 0.85
fillPrinterFunction · 0.85
yylex_destroyFunction · 0.85

Tested by

no test coverage detected