`ifndefUVM_REGEX_NO_DPIimport"DPI-C" context function int uvm_re_match(string re, string str);import"DPI-C" context function void uvm_dump_re_cache();import"DPI-C" context function string uvm_glob_to_re(string glob);`else// The Verilog only version does not match regular expressions,// it only does glob style matching.functionintuvm_re_match(stringre,stringstr);inte,es,s,ss;stringtmp;e=0;s=0;es=0;ss=0;if(re.len()==0)return0;
`ifndefUVM_REGEX_NO_DPIimport"DPI-C" function string uvm_re_deglobbed(string glob, bit with_brackets);import"DPI-C" function string uvm_re_buffer();import"DPI-C" function void uvm_re_free(chandle rexp);import"DPI-C" function chandle uvm_re_comp(string re, bit deglob);import"DPI-C" function int uvm_re_exec(chandle rexp, string str);import"DPI-C" function chandle uvm_re_compexec(string re, string str, bit deglob, output int exec_ret);import"DPI-C" function bit uvm_re_compexecfree(string re, string str, bit deglob, output int exec_ret);typedefclassuvm_regex_cache;// The uvm_re_match cache is disabled by default, to avoid // potential issues with save-and-restore causing illegal c-side // dereferencing. When enabled, uvm_re_match should be significantly // faster. `ifdefUVM_ENABLE_RE_MATCH_CACHEfunctionintuvm_re_match(stringre,stringstr,bitdeglob=0);
endfunctionfunctionnew(stringname="");super.new(name);endfunctionvirtualfunctionvoidbegin_v();uvm_coreservice_tcs=uvm_coreservice_t::get();_root=cs.get_root();`ifdefUVM_NO_DPI`uvm_info("UVM/COMP/NAMECHECK","This implementation of the component name checks requires DPI to be enabled",UVM_NONE)`endifendfunctionvirtualfunctionvoidend_v();`ifndefUVM_NO_DPIuvm_dpi_regfree(visit.compiled_regex);visit.compiled_regex=null;`endifendfunction
// This method should return a regex for what is being considered a valid/good component name.// The visitor will check all component names using this regex and report failing namesvirtualfunctionstringget_name_constraint();return"/^[][[:alnum:](){}_:-]([][[:alnum:](){} _:-]*[][[:alnum:](){}_:-])?$/";endfunctionvirtualfunctionvoidvisit(NODEnode);// dont check the root componentif(_root!=node)begin`ifdefUVM_REGEX_NO_DPIstaticbitwarned;if(!warned)begin`uvm_warning("NO_VISIT_CHECK","Because UVM_REGEX_NO_DPI is defined, no uvm component name constraints will be checked")warned=1;end`elsestringregex=get_name_constraint();// if we don't have something surrounded by "/" characters, add themif((regex.len()<=2)||(regex[0]!="/")||(regex[regex.len()-1]!="/"))regex={"/",regex,"/"};if(!uvm_is_match(regex,node.get_name()))begin`uvm_warning("UVM/COMP/NAME",$sformatf("the name \"%s\" of the component \"%s\" violates the uvm component name constraints",node.get_name(),node.get_full_name()))end