src/verilogPreproc/verilogPreproc.cpp
//method call when the definition of a macro is found
method call when the definition of a macro is found
method call when the definition of a macro is found
antlrcpp::Any VerilogPreproc::visitDefine(
		verilogPreprocParser::DefineContext *ctx) {
	string def_name = ctx->macro_id()->getText();
	string body;
	auto da = ctx->define_args();
	vector<MacroDefVerilog::param_info_t> *params;
	vector<MacroDefVerilog::param_info_t> params_dummy;
	if (da)
		params = visitDefine_args(da);
	else {
		params = &params_dummy;
	}
	if (ctx->replacement() != nullptr) {
		body = _tokens.getText(ctx->replacement()->getSourceInterval());
		remove_comment(ctx->replacement()->getStart(),
				ctx->replacement()->getStop(), &body);
		body = rtrim(body);
	}
	bool has_params = da != nullptr;
	try {
		auto item = new MacroDefVerilog(def_name, has_params, *params, body);
		container.defineDB.insert( { def_name, item });
	} catch (const ParseException &e) {
		throw_input_caused_error(ctx, e.what());
	}
	if (da)
		delete params;
	replace_context_by_bank(ctx);
	return NULL;
}
antlrcpp :: Any VerilogPreproc :: visitDefine ( verilogPreprocParser :: DefineContext * ctx ) { string def_name = ctx -> macro_id ( ) -> getText ( ) ; string body ; auto da = ctx -> define_args ( ) ; vector < MacroDefVerilog :: param_info_t > * params ; vector < MacroDefVerilog :: param_info_t > params_dummy ; if ( da ) params = visitDefine_args ( da ) ; else { params = & params_dummy ; } if ( ctx -> replacement ( ) != nullptr ) { body = _tokens . getText ( ctx -> replacement ( ) -> getSourceInterval ( ) ) ; remove_comment ( ctx -> replacement ( ) -> getStart ( ) , ctx -> replacement ( ) -> getStop ( ) , & body ) ; body = rtrim ( body ) ; } bool has_params = da != nullptr ; try { auto item = new MacroDefVerilog ( def_name , has_params , * params , body ) ; container . defineDB . insert ( { def_name , item } ) ; } catch ( const ParseException & e ) { throw_input_caused_error ( ctx , e . what ( ) ) ; } if ( da ) delete params ; replace_context_by_bank ( ctx ) ; return NULL ; }
method call when the definition of a macro is found
method call when the definition of a macro is found
//printf("@%s - %s\n",__PRETTY_FUNCTION__,ctx->getText().c_str()); // get the macro name //printf("%s\n", macroName.c_str()); // get the template // the macro definition is replace by an empty string in the original // source code