bool emit_line_directive(ContextT const& ctx, ContainerT &pending, typename ContextT::token_type const& act_token) { if (!need_emit_line_directives(ctx.get_language()) || !enable_relative_names_in_line_directives()) { return false; } // emit a #line directive showing the relative filename instead typename ContextT::position_type pos = act_token.get_position(); unsigned int column = 6; typedef typename ContextT::token_type result_type; using namespace boost::wave; pos.set_column(1); pending.push_back(result_type(T_PP_LINE, "#line", pos)); pos.set_column(column); // account for '#line' pending.push_back(result_type(T_SPACE, " ", pos)); // 21 is the max required size for a 64 bit integer represented as a // string char buffer[22]; using namespace std; // for some systems sprintf is in namespace std sprintf (buffer, "%d", pos.get_line()); pos.set_column(++column); // account for ' ' pending.push_back(result_type(T_INTLIT, buffer, pos)); pos.set_column(column += (unsigned int)strlen(buffer)); // account for <number> pending.push_back(result_type(T_SPACE, " ", pos)); pos.set_column(++column); // account for ' ' std::string file("\""); boost::filesystem::path filename( boost::wave::util::create_path(ctx.get_current_relative_filename().c_str())); using boost::wave::util::impl::escape_lit; file += escape_lit(boost::wave::util::native_file_string(filename)) + "\""; pending.push_back(result_type(T_STRINGLIT, file.c_str(), pos)); pos.set_column(column += (unsigned int)file.size()); // account for filename pending.push_back(result_type(T_GENERATEDNEWLINE, "\n", pos)); return true; }
bool CPreProcessor::emit_line_directive(ContextT const& ctx, ContainerT&pending, typename ContextT::token_type const& act_token) { //std::cout << "in emit_line_directive" << std::endl; // emit a #line directive showing the relative filename instead typename ContextT::position_type pos = act_token.get_position(); unsigned int column = 1; typedef typename ContextT::token_type result_type; pos.set_column(column); std::string comments = "// From file: "; pending.push_back(result_type(wave::T_STRINGLIT, comments.c_str(), pos)); pos.set_column(column += (unsigned int)comments.size()); // account for comments std::string file(""); boost::filesystem::path filename(wave::util::create_path(ctx.get_current_filename().c_str())); file += boost::wave::util::impl::escape_lit(wave::util::native_file_string(filename)) + ""; pending.push_back(result_type(wave::T_STRINGLIT, file.c_str(), pos)); pos.set_column(column += (unsigned int)file.size()); // account for filename pending.push_back(result_type(wave::T_GENERATEDNEWLINE, "\n", pos)); return true; }
bool found_include_directive(const ContextT &ctx, const std::string &filename, bool include_next) { bool isSystem = filename[0] == '<'; std::string path = filename.substr(1, filename.length() - 2); std::string dirPath, nativePath; bool result = ctx.find_include_file(path, dirPath, isSystem, nullptr); return !result; }
//run command and perform simple caching petabricks::FormulaListPtr petabricks::MaximaWrapper::runCommand(const std::string& cmd){ if(!_pendingAssume.empty()) { //we delay assume() commands since they often aren't followed by anything ContextT ctx; ctx.swap(_pendingAssume); for(ContextT::const_iterator i=ctx.begin(); i!=ctx.end(); ++i) { runCommandRaw(i->c_str(), i->length()); } clearCache(); } CacheT::const_iterator i = _cache.find(cmd); if(i != _cache.end()) { return i->second; } FormulaListPtr rv = runCommandRaw(cmd.c_str(), cmd.length()); #ifdef MAXIMA_CACHING _cache[cmd]=rv; #endif return rv; }
bool locate_include_file(ContextT& ctx, std::string &file_path, bool is_system, char const *current_name, std::string &dir_path, std::string &native_name) { if (!ctx.find_include_file (file_path, dir_path, is_system, current_name)) return false; // could not locate file namespace fs = boost::filesystem; fs::path native_path(wave::util::create_path(file_path)); if (!fs::exists(native_path)) { BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, bad_include_file, file_path.c_str(), ctx.get_main_pos()); return false; } // return the unique full file system path of the located file native_name = wave::util::native_file_string(native_path); return true; // include file has been located successfully }
bool CPreProcessor::locate_include_file(ContextT& ctx, std::string& file_path, bool is_system, char const* current_name, std::string& dir_path, std::string& native_name) { //if (is_system) { // Check if file is in the files map if ( CPreProcessor::files_.find(file_path) != CPreProcessor::files_.end()) { //std::cout << "locate_include_file 1: file_path:" << file_path << " dir_path:" << dir_path << " native_name:" << native_name << std::endl; native_name = file_path; return true; } else { namespace fs = boost::filesystem; //} else { // could not locate file fs::path baseDir = fs::path(baseDirectory_); if ( fs::exists(baseDir) && fs::is_directory(baseDir)) { file_path = baseDir.string() + std::string("/") + file_path; } //std::cout << "baseDirectory_: " << baseDirectory_ << std::endl; //std::cout << "locate_include_file doesn't exist 2: file_path:" << file_path << " dir_path:" << dir_path << " native_name:" << native_name << std::endl; if ( !ctx.find_include_file(file_path, dir_path, is_system, current_name)) { return false; } fs::path native_path(wave::util::create_path(file_path)); if ( !fs::exists(native_path)) { //BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, bad_include_file, // file_path.c_str(), ctx.get_main_pos()); //std::cout << "error: doesn't exist" << std::endl; //std::cout << "locate_include_file doesn't exist 3: file_path:" << file_path << " dir_path:" << dir_path << " native_name:" << native_name << std::endl; return false; } // return the unique full file system path of the located file native_name = wave::util::native_file_string(native_path); return true; } // include file has not been located return false; }
void opened_include_file(ContextT const& ctx, std::string const &relname, std::string const &absname, bool is_system_include) { std::size_t include_depth = ctx.get_iteration_depth(); #endif if (enabled_include_tracing()) { // print indented filename for (std::size_t i = 0; i < include_depth; ++i) includestrm << " "; if (is_system_include) includestrm << "<" << relname << "> (" << absname << ")"; else includestrm << "\"" << relname << "\" (" << absname << ")"; includestrm << std::endl; } }