123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335(*
Copyright 2013-2018 RIKEN
Copyright 2018-2025 Chiba Institude of Technology
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)(* Author: Masatomo Hashimoto <m.hashimoto@stair.center> *)(* common.ml *)[%%prepare_logger]moduleXqueue=Diffast_misc.XqueuemoduleXset=Diffast_misc.XsetmoduleXlist=Diffast_misc.XlistmoduleXoption=Diffast_misc.XoptionmoduleXprint=Diffast_misc.XprintmodulePB=Langs_common.Parserlib_basemoduleLoc=Langs_common.AstlocmoduleDirectiveLine=structtypetag=|OCL|OMP|ACC|XLF|DECtyperaw={tag:tag;head:string;line:string;queue:Obj.tXqueue.c;fixed_cont:bool;free_cont:bool;}lettag_to_string=function|OCL->"OCL"|OMP->"OMP"|ACC->"ACC"|XLF->"XLF"|DEC->"DEC"letdummy_queue=newXqueue.cletmkomplineqfixed_contfree_cont={tag=OMP;head="!$omp";line=line;queue=q;fixed_cont=fixed_cont;free_cont=free_cont;}letmkacclineqfixed_contfree_cont={tag=ACC;head="!$acc";line=line;queue=q;fixed_cont=fixed_cont;free_cont=free_cont;}letmkoclline={tag=OCL;head="!OCL";line=line;queue=dummy_queue;fixed_cont=false;free_cont=false;}letmkdecprefixline={tag=DEC;head=prefix;line=line;queue=dummy_queue;fixed_cont=false;free_cont=false;}letmkxlftriggerlineqfixed_contfree_cont={tag=XLF;head=trigger;line=line;queue=q;fixed_cont=fixed_cont;free_cont=free_cont;}endletextensions=[".f";".for";".f90";".f95"]moduleLangSpec=structtypet=F77|F90|F95|F2003|F2008letto_string=function|F77->"F77(ISO1539:1980)"|F90->"F90(ISO/IEC1539:1991)"|F95->"F95(ISO/IEC1539-1:1997)"|F2003->"F2003(ISO/IEC1539-1:2004)"|F2008->"F2008(ISO/IEC1539-1:2010)"endmoduleLangExtension=structtypet=IBM|Intel|PGI|PGI_CUDA|Fujitsu|Apolloletto_string=function|Fujitsu->"Fujitsu"|IBM->"IBM XL Fortran"|Intel->"DEC/Compaq/Intel Fortran"|PGI->"PGI Fortran"|PGI_CUDA->"PGI CUDA Fortran"|Apollo->"Apollo/Domain Fortran"classset=objectvalexts=Xset.create0methodadde=Xset.addextsemethodto_string=Xlist.to_string(funs->"["^s^"]")""(List.mapto_string(Xset.to_listexts))endendmoduleSourceForm=structtypet=Unknown|Fixed|Free|Mixedletto_string=function|Unknown->"Unknown"|Fixed->"Fixed"|Free->"Free"|Mixed->"Mixed"end[%%capture_pathmoduleLangConfig=structletdefault_max_line_length_fixed=72letdefault_max_line_length_free=132classc=object(self)valmutablespec=LangSpec.F95valexts=newLangExtension.setvalmutablesource_form=SourceForm.Freevalmutablemax_line_length=default_max_line_length_fixedvalmutablemax_line_length_fixed=default_max_line_length_fixedvalmutablemax_line_length_free=default_max_line_length_freevalmutableparse_d_lines_flag=falsemethodparse_d_lines=parse_d_lines_flagmethod_set_parse_d_lines_flagb=parse_d_lines_flag<-bmethodset_parse_d_lines_flag=parse_d_lines_flag<-truemethodclear_parse_d_lines_flag=parse_d_lines_flag<-falsemethodspec=specmethodset_specs=spec<-smethodset_spec_F77=spec<-LangSpec.F77methodset_spec_F90=spec<-LangSpec.F90methodset_spec_F95=spec<-LangSpec.F95methodset_spec_F2003=spec<-LangSpec.F2003methodset_spec_F2008=spec<-LangSpec.F2008methodexts=extsmethodadd_ext_Fujitsu=exts#addLangExtension.Fujitsumethodadd_ext_IBM=exts#addLangExtension.IBMmethodadd_ext_Intel=exts#addLangExtension.Intelmethodadd_ext_PGI=exts#addLangExtension.PGImethodadd_ext_PGI_CUDA=exts#addLangExtension.PGI_CUDAmethodadd_ext_Apollo=exts#addLangExtension.Apollomethodsource_form=source_formmethodset_source_formsf=source_form<-sf;matchsfwith|SourceForm.Fixed->self#set_max_line_length__fixed|SourceForm.Free->self#set_max_line_length__free|_->()methodset_source_form_fixed=self#set_source_formSourceForm.Fixedmethodset_source_form_free=self#set_source_formSourceForm.Freemethodis_fixed_source_form=letb=source_form=SourceForm.Fixedin[%debug_log"%B"b];bmethodis_free_source_form=letb=source_form=SourceForm.Freein[%debug_log"%B"b];bmethodmax_line_length=max_line_lengthmethod_set_max_line_lengthn=[%debug_log"length=%d"n];max_line_length<-nmethodset_max_line_lengthn=self#_set_max_line_lengthn;max_line_length_fixed<-n;max_line_length_free<-nmethodset_max_line_length_fixedn=ifmax_line_length_fixed<nthenbegin[%debug_log"%d -> %d"max_line_length_fixedn];max_line_length_fixed<-nendmethodset_max_line_length_freen=ifmax_line_length_free<nthenbegin[%debug_log"%d -> %d"max_line_length_freen];max_line_length_free<-nendmethodset_max_line_length__fixed=self#_set_max_line_lengthmax_line_length_fixedmethodset_max_line_length__free=self#_set_max_line_lengthmax_line_length_freemethodconf_F77=self#set_spec_F77;self#set_source_form_fixed;self#set_max_line_length_fixedmethodconf_F90_free=self#set_spec_F90;self#set_source_form_free;self#set_max_line_length__freemethodconf_F90_fixed=self#set_spec_F90;self#set_source_form_fixed;self#set_max_line_length__fixedmethodconf_F95_free=self#set_spec_F95;self#set_source_form_free;self#set_max_line_length__freemethodconf_F95_fixed=self#set_spec_F95;self#set_source_form_fixed;self#set_max_line_length__fixedendend(* module Lang_config *)]exceptionUndefinedtypename=stringtypelabel=stringtypevar=stringletparse_warning_locloc=PB.parse_warning_loc~head:"[Fortran]"locletparse_warningsposepos=PB.parse_warning~head:"[Fortran]"sposeposexceptionParse_error=PB.Parse_errorexceptionInternal_errorofstringletfail_to_parse=PB.fail_to_parseletstring_opt_to_string?(prefix="")?(suffix="")s_opt=Xoption.to_string(funs->s)~prefix~suffixs_optletint_opt_to_string?(prefix="")?(suffix="")s_opt=Xoption.to_stringstring_of_int~prefix~suffixs_optletopt_to_string=Xoption.to_stringletopt_to_list=Xoption.to_listletopt_to_list_mapfo=tryXoption.to_list_mapfowithNot_found->[]letlist_opt_to_list=Xoption.list_opt_to_listletopt_list_to_list=Xoption.list_to_listletmap_optfo=tryXoption.mapfowithNot_found->Noneletstring_list_to_string?(prefix=" ")sepss=matchsswith|[]->""|_->prefix^(Xlist.to_string(funx->x)sepss)letint_list_to_string?(prefix=" ")sepil=matchilwith|[]->""|_->prefix^(Xlist.to_stringstring_of_intsepil)letnum_to_ordinaln=letsuffix=matchnmod10with|1->"st"|2->"nd"|3->"rd"|_->"th"inPrintf.sprintf"%d%s"nsuffixletwarning_msg=Xprint.warning~head:"[Fortran]"