static void load_loc (location &loc, Location const &sloc) { loc.file = files.add (sloc.file ()); loc.first_line = sloc.first_line (); loc.first_column = sloc.first_column (); loc.last_line = sloc.last_line (); loc.last_column = sloc.last_column (); }
ScannerBufferSource::ScannerBufferSource(Configuration const* config, char const* buffer, Location const& loc, bool track_position) : ScannerRawSource(config), _file(loc.file()), _line(loc.line()), _first_col(loc.col()), _track(track_position) { // figure out the size of the buffer _buffer_sz = strlen(buffer) + 1; _buffer = new char[_buffer_sz]; memcpy(_buffer, buffer, _buffer_sz); cursor() = _buffer; token() = _buffer; marker() = _buffer; ctxmarker() = _buffer; limit() = _buffer + _buffer_sz; _newline = _buffer - loc.col(); }
void MacroParser::_handle_include(statements::IncludeStatement const* stmt) { #ifndef NDEBUG _config->ostream(Verb::DETAIL) << "TRACE: Got include statement!" << std::endl; #endif Location l = stmt->beginLoc(); BOOST_FOREACH(ReferencedString const* name, *stmt) { fs::path p = fs::path(*name); try { // Try to resolve the name fs::path fullpath; // try to resolve the path of the file if (p.is_absolute() || !l.file()) { fullpath = p; } else if (!l.file()) { fullpath = fs::current_path() / p; } else { // Try a path relative to the current file we're in first // Then try resolving with our default path. fullpath = l.file()->parent_path() / p; if (!fs::exists(fullpath) || fs::is_directory(fullpath)) { fullpath = fs::current_path() / p; } } if (!fs::exists(fullpath)) { // We were unable to resolve the file.. std::ostream& out = _config->ostream(Verb::ERROR); out << "ERROR: " << l << ": Could not open file \"" << p.native() << "\". File does not exist." << std::endl; _stat = Status::ERR_SYNTAX; break; } if (fs::is_directory(fullpath)) { // We were unable to resolve the file.. std::ostream& out = _config->ostream(Verb::ERROR); out << "ERROR: " << l << ": Could not open file \"" << p.native() << "\". The file is a directory." << std::endl; _stat = Status::ERR_SYNTAX; break; // We can't open a directory. } // The file appears to be good. if (!_push_front(fullpath, false)) { std::ostream& out = _config->ostream(Verb::ERROR); out << "ERROR: " << l << ": An error occurred openning file \"" << p.native() << "\"." << std::endl; _stat = Status::ERR_IO; break; } } catch (fs::filesystem_error& err) { std::ostream& out = _config->ostream(Verb::ERROR); out << "ERROR: " << l << ": An error occurred openning file \"" << p.native() << "\"." << std::endl; _stat = Status::ERR_IO; break; } } }