src/verilogPreproc/verilogPreproc.cpp
//method call when `include is found
method call when `include is found
method call when ` include is found
antlrcpp::Any VerilogPreproc::visitInclude(
		verilogPreprocParser::IncludeContext *ctx) {
	auto incdir_iter = container.incdirs.begin();
	bool found = false;
	string inc_file_path;
	auto mc = ctx->macro_call();
	if (mc) {
		inc_file_path = visitMacro_call(mc).as<string>();
	} else {
		inc_file_path = ctx->STR()->getText();
	}
	filesystem::path filename;
	while (incdir_iter != container.incdirs.end() && found == false) {
		filename = (*incdir_iter)
				/ inc_file_path.substr(1, inc_file_path.size() - 2);
		if (filesystem::exists(filename)) {
			found = true;
		}
		incdir_iter++;
	}
	if (found == false) {
		string msg = inc_file_path 
				+ " was not found in include directories\n";
		throw_input_caused_error(ctx, msg);
	} else if (container.incfile_stack.size() > include_depth_limit) {
		stringstream msg;
		msg << "Nested include limit reach" << endl;
		for (auto f : container.incfile_stack) {
			msg << "    " << f.first << endl;
		}
		throw_input_caused_error(ctx, msg.str());
	} else {
		misc::Interval token = ctx->getSourceInterval();
		_rewriter.Delete(token.a, token.b);
		filesystem::path my_incdir;
		if (added_incdir) {
			my_incdir = container.incdirs.back();
			container.incdirs.pop_back();
		}
		auto replacement = container.run_preproc_file(filename);
		if (added_incdir) {
			container.incdirs.push_back(my_incdir);
		}
		_rewriter.insertAfter(ctx->getStop(), replacement);
	}
	return nullptr;
}
antlrcpp :: Any VerilogPreproc :: visitInclude ( verilogPreprocParser :: IncludeContext * ctx ) { auto incdir_iter = container . incdirs . begin ( ) ; bool found = false ; string inc_file_path ; auto mc = ctx -> macro_call ( ) ; if ( mc ) { inc_file_path = visitMacro_call ( mc ) . as < string > ( ) ; } else { inc_file_path = ctx -> STR ( ) -> getText ( ) ; } filesystem :: path filename ; while ( incdir_iter != container . incdirs . end ( ) && found == false ) { filename = ( * incdir_iter ) / inc_file_path . substr ( 1 , inc_file_path . size ( ) - 2 ) ; if ( filesystem :: exists ( filename ) ) { found = true ; } incdir_iter ++ ; } if ( found == false ) { string msg = inc_file_path + " \n " ; throw_input_caused_error ( ctx , msg ) ; } else if ( container . incfile_stack . size ( ) > include_depth_limit ) { stringstream msg ; msg << " " << endl ; for ( auto f : container . incfile_stack ) { msg << " " << f . first << endl ; } throw_input_caused_error ( ctx , msg . str ( ) ) ; } else { misc :: Interval token = ctx -> getSourceInterval ( ) ; _rewriter . Delete ( token . a , token . b ) ; filesystem :: path my_incdir ; if ( added_incdir ) { my_incdir = container . incdirs . back ( ) ; container . incdirs . pop_back ( ) ; } auto replacement = container . run_preproc_file ( filename ) ; if ( added_incdir ) { container . incdirs . push_back ( my_incdir ) ; } _rewriter . insertAfter ( ctx -> getStop ( ) , replacement ) ; } return nullptr ; }
method call when `include is found
method call when ` include is found
// printf("@%s\n",__PRETTY_FUNCTION__); //iterator on the list of inc. directory // iterate on list of directory until we found the file. // build the filename //Test if the file exist // the file exist. we rise the flag to leave the loop over the // directory list //continue on next directory // The file was not found. We throw a exception //.substr(1, inc_file_path.size() - 2) // test the number of nested include. // If so throw an exception // We are going to replace the content of the `include // directive by the content of the processed file // run the pre-processor on it //update the current source code