12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330(*
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> *)(* parser_aux.ml *)[%%prepare_logger]moduleXstring=Diffast_misc.XstringmoduleXhash=Diffast_misc.XhashmoduleFname=Langs_common.FnamemoduleEnv_base=Langs_common.Env_basemoduleParserlib_base=Langs_common.Parserlib_baseopenPrintfopenCommonopenLabelsopenAstmoduleL=LabelmoduleI=PinfomoduleN=I.NamemodulePB=Parserlib_basemoduleC=ContextmoduleB=BindingmoduleBID=Binding.IDtypechar_context=|CH_NONE|CH_SINGLE|CH_DOUBLEletchar_context_to_string=function|CH_NONE->"NONE"|CH_SINGLE->"SINGLE QUOTE"|CH_DOUBLE->"DOUBLE QUOTE"typestate={s_at_bopu:bool;s_symbol_tbl:(name,N.frame)Hashtbl.t;s_stack:N.frameStack.t;s_in_format_context:bool;s_in_open_context:bool;s_in_close_context:bool;s_in_position_context:bool;s_in_io_control_context:bool;s_in_wait_context:bool;s_in_flush_context:bool;s_in_if_context:bool;s_in_inquire_context:bool;s_in_implicit_context:bool;s_in_letter_context:bool;s_in_intent_context:bool;s_in_result_context:bool;s_in_character_context:bool;s_in_typeof_context:bool;s_in_do_context:bool;s_in_slash_name_context:bool;s_in_allocate_context:bool;s_in_type_spec_context:bool;s_in_bind_context:bool;s_in_contains_context:bool;s_in_access_context:bool;s_in_data_context:bool;s_in_type_guard_context:bool;s_in_procedure_context:bool;s_in_type_context:bool;s_in_only_context:bool;s_in_pu_head_context:bool;s_name_context:int;s_paren_context:int;s_array_ctor_context:int;s_interface_context:int;s_structure_context:int;s_select_type_context:int;s_char_context:char_context;}letmkstatebopustblstackin_fin_oin_clin_poin_ioin_win_flin_ifin_inqin_imin_ltin_intin_resin_chrin_tofin_doin_snin_ain_tsin_bin_cin_accin_din_tgin_pin_tin_onin_phncpcacicscstccc={s_at_bopu=bopu;s_symbol_tbl=stbl;s_stack=stack;s_in_format_context=in_f;s_in_open_context=in_o;s_in_close_context=in_cl;s_in_position_context=in_po;s_in_io_control_context=in_io;s_in_wait_context=in_w;s_in_flush_context=in_fl;s_in_if_context=in_if;s_in_inquire_context=in_inq;s_in_implicit_context=in_im;s_in_letter_context=in_lt;s_in_intent_context=in_int;s_in_result_context=in_res;s_in_character_context=in_chr;s_in_typeof_context=in_tof;s_in_do_context=in_do;s_in_slash_name_context=in_sn;s_in_allocate_context=in_a;s_in_type_spec_context=in_ts;s_in_bind_context=in_b;s_in_contains_context=in_c;s_in_access_context=in_acc;s_in_data_context=in_d;s_in_type_guard_context=in_tg;s_in_procedure_context=in_p;s_in_type_context=in_t;s_in_only_context=in_on;s_in_pu_head_context=in_ph;s_name_context=nc;s_paren_context=pc;s_array_ctor_context=ac;s_interface_context=ic;s_structure_context=sc;s_select_type_context=stc;s_char_context=cc;}letstack_to_stringstack=letbuf=Buffer.create0inStack.iter(funfrm->Buffer.add_stringbuf(N.ScopingUnit.to_stringfrm#scope);Buffer.add_stringbuf"\n";)stack;Buffer.contentsbufletstat_to_string{s_at_bopu=bopu;s_symbol_tbl=(*stbl*)_;s_stack=stack;s_in_format_context=in_f;s_in_open_context=in_o;s_in_close_context=in_cl;s_in_position_context=in_po;s_in_io_control_context=in_io;s_in_wait_context=in_w;s_in_flush_context=in_fl;s_in_if_context=in_if;s_in_inquire_context=in_inq;s_in_implicit_context=in_im;s_in_letter_context=in_lt;s_in_intent_context=in_int;s_in_result_context=in_res;s_in_character_context=in_chr;s_in_typeof_context=in_tof;s_in_do_context=in_do;s_in_slash_name_context=in_sn;s_in_allocate_context=in_a;s_in_type_spec_context=in_ts;s_in_bind_context=in_b;s_in_contains_context=in_c;s_in_access_context=in_acc;s_in_data_context=in_d;s_in_type_guard_context=in_tg;s_in_procedure_context=in_p;s_in_type_context=in_t;s_in_only_context=in_on;s_in_pu_head_context=in_ph;s_name_context=nc;s_paren_context=pc;s_array_ctor_context=ac;s_interface_context=ic;s_structure_context=sc;s_select_type_context=stc;s_char_context=cc;}=letfmt="stack:\n%s"^^"at_BOPU : %B\n"^^"in_format_context : %B\n"^^"in_open_context : %B\n"^^"in_close_context : %B\n"^^"in_position_context : %B\n"^^"in_io_control_context : %B\n"^^"in_wait_context : %B\n"^^"in_flush_context : %B\n"^^"in_if_context : %B\n"^^"in_inquire_context : %B\n"^^"in_implicit_context : %B\n"^^"in_letter_context : %B\n"^^"in_intent_context : %B\n"^^"in_result_context : %B\n"^^"in_character_context : %B\n"^^"in_typeof_context : %B\n"^^"in_do_context : %B\n"^^"in_slash_name_context : %B\n"^^"in_allocate_context : %B\n"^^"in_type_spec_context : %B\n"^^"in_bind_context : %B\n"^^"in_contains_context : %B\n"^^"in_access_context : %B\n"^^"in_data_context : %B\n"^^"in_type_guard_context : %B\n"^^"in_procedure_context : %B\n"^^"in_type_context : %B\n"^^"in_only_context : %B\n"^^"in_pu_head_context : %B\n"^^"name_context : %d\n"^^"paren_context : %d\n"^^"array_ctor_context : %d\n"^^"interface_context : %d\n"^^"structure_context : %d\n"^^"select_type_context: %d\n"^^"char_context : %s\n"insprintffmt(stack_to_stringstack)bopuin_fin_oin_clin_poin_ioin_win_flin_ifin_inqin_imin_ltin_intin_resin_chrin_tofin_doin_snin_ain_tsin_bin_cin_accin_din_tgin_pin_tin_onin_phncpcacicscstc(char_context_to_stringcc)moduleLineStat=structtypet=|AssumedBlank|Nonblank|PureComment|MixedComment|Continuedletto_string=function|AssumedBlank->"AssumedBlank"|Nonblank->"Nonblank"|PureComment->"PureComment"|MixedComment->"MixedComment"|Continued->"Continued"letis_pure_comment=function|PureComment->true|_->falseletis_assumed_blank=function|AssumedBlank->true|_->falseletis_continued=function|Continued->true|_->falseendtypelexer_mode=|LEX_NORMAL|LEX_QUEUE|LEX_QUEUE_THEN_DOof(unit->Obj.t)typeline_format=|LF_FIXED|LF_TAB|LF_FREE|LF_UNKNOWNletstrip_locloc=loc.Astloc.filename<-(Fname.striploc.Astloc.filename)[%%capture_pathclassenv=object(self)inherit[Source.c]Env_base.cassupervalbidgen=newBID.generatorvalmutableeffective_lines_for_source_form_guess=0valmutableignore_include_flag=falsevalmutablecontext_enter_flag=falsevalmutablecontext_activate_flag=falsevalmutablelast_active_ofss=(0,0)valmutablepartial_parsing_flag=falsevalmutablebol_flag=true(* beginning of line *)valmutablebos_flag=false(* beginning of statement *)valmutablecontinuable_flag=falsevalmutablecontinued_flag=falsevalmutableamp_line_flag=false(* '&' found in the line *)valmutablebocl_flag=false(* beginning of continued line *)valmutabletoken_feeded_flag=false(* is Ulexer.token called after encounter with line_terminator *)valmutableline_stat=LineStat.AssumedBlank(*
val mutable prev_line_stat = LineStat.AssumedBlank
*)valmutablepending_EOL_obj=(None:Obj.toption)valpending_RAWOMP_obj_queue=(Queue.create():Obj.tQueue.t)valpending_token_obj_queue=(Queue.create():Obj.tQueue.t)valmutablelast_lex_qtoken_obj=Obj.repr()valmutablelex_mode=LEX_NORMALvalmutablelex_paren_context=0vallex_pp_branch_stack=Stack.create()methodlex_enter_pp_branch(br:PpDirective.branch)=Stack.push(br,lex_paren_context)lex_pp_branch_stackmethodlex_exit_pp_branch=tryStack.poplex_pp_branch_stackwithStack.Empty->failwith"Parser_aux.env#lex_exit_pp_branch"methodlex_current_pp_branch=tryStack.toplex_pp_branch_stackwithStack.Empty->failwith"Parser_aux.env#lex_current_pp_branch"valmutablelast_char='\000'methodset_last_charc=last_char<-cmethodlast_char=last_charvalsource_form_tbl=(Hashtbl.create0:(string,SourceForm.t)Hashtbl.t)methodadd_source_formpathform=Hashtbl.replacesource_form_tblpathformmethodget_source_formpath=Hashtbl.findsource_form_tblpathvalmutablediscarded_branch_entry_count=0methoddiscarded_branch_entry_count=discarded_branch_entry_countmethodincr_discarded_branch_entry_count=[%debug_log"%d -> %d"discarded_branch_entry_count(discarded_branch_entry_count+1)];discarded_branch_entry_count<-discarded_branch_entry_count+1methoddecr_discarded_branch_entry_count=[%debug_log"%d -> %d"discarded_branch_entry_count(discarded_branch_entry_count-1)];discarded_branch_entry_count<-discarded_branch_entry_count-1valloc_stack=newLayeredloc.loc_stackvalmutablebase_file=""methodset_base_filep=base_file<-pvalmutablecurrent_loc_layers=[]valmutableprev_loc_layers=[]valmutablecurrent_loc_layers_encoded=""methodcurrent_loc_layers=current_loc_layersmethodcurrent_loc_layers_encoded=current_loc_layers_encodedmethodloc_stack_level=loc_stack#get_levelmethodpush_locloc=[%debug_log"pushing [%s]"(Astloc.to_string~short:trueloc)];letloc=ifFname.is_extendedloc.Astloc.filenamethenLoc.get_strippedlocelselocin[%debug_log"loc stack: %s"loc_stack#to_string];loc_stack#pushloc;prev_loc_layers<-current_loc_layers;current_loc_layers<-loc_stack#get_layers;current_loc_layers_encoded<-Layeredloc.encode_layerscurrent_loc_layersmethodpop_loc=loc_stack#pop;prev_loc_layers<-current_loc_layers;current_loc_layers<-loc_stack#get_layers;current_loc_layers_encoded<-Layeredloc.encode_layerscurrent_loc_layersmethodmkllocloc=Layeredloc.of_loclocvalmutablepredefined_macrotbl=(None:Macro.tableoption)methodset_predefined_macrotbltbl=predefined_macrotbl<-tblvalmacrotbl=newMacro.table"main"methodmacrotbl=macrotblmethoddefine_macro?(conditional=false)idbody=[%debug_log"id=%s conditional=%B"idconditional];macrotbl#define~conditionalidbodymethodundefine_macroid=[%debug_log"%s"id];macrotbl#undefineidmethodfind_macroid=[%debug_log"id=%s"id];trymacrotbl#findidwithNot_found->matchpredefined_macrotblwith|Sometbl->tbl#findid|None->raiseNot_foundmethodfind_all_macrosid=[%debug_log"id=%s"id];letms=macrotbl#find_allidinifms=[]thenmatchpredefined_macrotblwith|Sometbl->tbl#find_allid|None->[]elsemsmethodmacro_definedid=trylet_=self#find_macroidintruewithNot_found->falsevallex_macrotbl=newMacro.table"lex"methodlex_macrotbl=lex_macrotblmethodlex_define_macroidbody=[%debug_log"%s"id];lex_macrotbl#defineidbodymethodlex_undefine_macroid=[%debug_log"%s"id];lex_macrotbl#undefineidmethodlex_find_macroid=[%debug_log"id=%s"id];trylex_macrotbl#findidwithNot_found->matchpredefined_macrotblwith|Sometbl->tbl#findid|None->raiseNot_foundmethodlex_find_all_macrosid=[%debug_log"id=%s"id];letms=lex_macrotbl#find_allidinifms=[]thenmatchpredefined_macrotblwith|Sometbl->tbl#find_allid|None->raiseNot_foundelsemsvalmutableignore_case_flag=falsemethodignore_case=ignore_case_flagmethodset_ignore_case_flag=ignore_case_flag<-truemethodclear_ignore_case_flag=ignore_case_flag<-falsevalfname_ext_cache=(Hashtbl.create0:Fname.ext_cache_t)methodfname_ext_cache=fname_ext_cachevalmutableline_format=LF_UNKNOWNmethodline_format=line_formatmethodenter_fixed_line=line_format<-LF_FIXEDmethodenter_tab_line=line_format<-LF_TABmethodenter_free_line=line_format<-LF_FREEmethodin_fixed_line=line_format=LF_FIXEDmethodin_tab_line=line_format=LF_TABmethodfragment_impossible=[%debug_log"in_interface_context: %B"self#in_interface_context];[%debug_log"in_contains_context : %B"self#in_contains_context];[%debug_log"in_pu_head_context : %B"self#in_pu_head_context];[%debug_log"current scope: %s"(Pinfo.Name.ScopingUnit.to_stringself#current_frame#scope)];letb=self#in_interface_context||self#in_contains_context||self#in_pu_head_context||(matchself#current_frame#scopewith|Pinfo.Name.ScopingUnit.Program->false|Pinfo.Name.ScopingUnit.MainProgram(_,headed)->!headed|_->true)in[%debug_log"%B"b];b(* put in saved states *)valmutablebopu_flag=true(* beginning of program unit *)vallabel_tbl=(Hashtbl.create0:((string*int),label*Loc.t)Hashtbl.t)valmutablesymbol_tbl=Hashtbl.create0valmutablestack=Stack.create()valmutablestack_backup=Stack.create()valmutablein_format_context=falsevalmutablein_open_context=falsevalmutablein_close_context=falsevalmutablein_position_context=falsevalmutablein_io_control_context=falsevalmutablein_wait_context=falsevalmutablein_flush_context=falsevalmutablein_if_context=falsevalmutablein_inquire_context=falsevalmutablein_implicit_context=falsevalmutablein_letter_context=falsevalmutablein_intent_context=falsevalmutablein_result_context=falsevalmutablein_character_context=falsevalmutablein_typeof_context=falsevalmutablein_do_context=falsevalmutablein_slash_name_context=falsevalmutablein_allocate_context=falsevalmutablein_type_spec_context=falsevalmutablein_bind_context=falsevalmutablein_contains_context=falsevalmutablein_access_context=falsevalmutablein_data_context=falsevalmutablein_type_guard_context=falsevalmutablein_procedure_context=falsevalmutablein_type_context=falsevalmutablein_only_context=falsevalmutablein_pu_head_context=falsevalmutablein_vfe_context=falsevalmutablename_context=0valmutableparen_context=0valmutablearray_ctor_context=0valmutableinterface_context=0valmutablestructure_context=0valmutableselect_type_context=0valmutablechar_context=CH_NONEvalcheckpoint_tbl=Hashtbl.create0(* C.key_t -> state *)valambiguous_nodes=Xset.create0valtoplevel_frame=N.make_toplevel_frame()(* val latest_stmt_nodes_stack = (Stack.create() : Ast.node Xset.t Stack.t)*)(* other methods *)methodchange_stacks=[%debug_log"called"];stack_backup<-stack;stack<-smethodrecover_stack=[%debug_log"called"];stack<-stack_backupmethodreset_stack=[%debug_log"called"];stack<-Stack.create();ignore(self#_begin_scopeN.ScopingUnit.Program);ignore(self#_begin_scope(N.ScopingUnit.MainProgram(None,reffalse)))methodgenbidlod=tryletloc=N.Spec.loc_of_decl_to_loclodin[%debug_log"filename=\"%s\""loc.Loc.filename];letstree=self#current_source#treeinletdigest=Xhash.to_hex(stree#get_entryloc.Loc.filename)#file_digestinlets=sprintf"%s-%d_%d"digestloc.Loc.start_offsetloc.Loc.end_offsetinBID.make_globalswithNot_found->bidgen#gen(*
method latest_stmt_node_set =
try
Stack.top latest_stmt_nodes_stack
with
Stack.Empty ->
[%debug_log "stack empty"];
Xset.create 0
method add_latest_stmt_node nd =
try
let s = Stack.top latest_stmt_nodes_stack in
Xset.add s nd
with
Stack.Empty -> [%debug_log "stack empty"]
method push_latest_stmt_node_set =
[%debug_log "called"];
Stack.push (Xset.create 0) latest_stmt_nodes_stack
method pop_latest_stmt_node_set =
[%debug_log "called"];
try
let _ = Stack.pop latest_stmt_nodes_stack in
()
with
Stack.Empty -> [%debug_log "stack empty"]
method init_latest_stmt_node_set_stack =
Stack.clear latest_stmt_nodes_stack;
self#push_latest_stmt_node_set;
self#push_latest_stmt_node_set
*)methodcontext_enter_flag=context_enter_flagmethodset_context_enter_flag=context_enter_flag<-truemethodclear_context_enter_flag=context_enter_flag<-falsemethodcontext_activate_flag=context_activate_flagmethodset_context_activate_flag=context_activate_flag<-truemethodclear_context_activate_flag=context_activate_flag<-falsemethodset_partial_parsing_flag=partial_parsing_flag<-truemethodclear_partial_parsing_flag=partial_parsing_flag<-falsemethodpartial_parsing_flag=partial_parsing_flagmethodget_last_active_ofss=last_active_ofssmethodset_last_active_ofss(st,ed)=[%debug_log"%d - %d"sted];last_active_ofss<-(st,ed)methodlex_mode=lex_modemethodreset_lex_mode=lex_mode<-LEX_NORMALmethodset_lex_mode_queue=lex_mode<-LEX_QUEUEmethodset_lex_mode_queue_then_dof=lex_mode<-(LEX_QUEUE_THEN_DOf)methodat_BOPU=[%debug_log"BOPU_flag=%B"bopu_flag];bopu_flagmethodset_BOPU=[%debug_log"BOPU_flag set"];bopu_flag<-truemethodclear_BOPU=[%debug_log"BOPU_flag cleared"];bopu_flag<-falsemethodat_BOL=bol_flagmethodset_BOL=[%debug_log"BOL set"];bol_flag<-true;self#clear_token_feeded;(*
let lstat =
match line_stat with
| LineStat.AssumedBlank -> LineStat.PureComment
| _ -> line_stat
in
prev_line_stat <- lstat;
[%debug_log "prev_line_stat: set to %s" (LineStat.to_string prev_line_stat)];
*)self#set_line_stat_assumed_blankmethodclear_BOL=[%debug_log"BOL cleared"];bol_flag<-falsemethodat_BOS=bos_flagmethodset_BOS=[%debug_log"BOS flag set"];bos_flag<-truemethodclear_BOS=[%debug_log"BOS flag cleared"];bos_flag<-falsemethodcontinuable=continuable_flagmethodset_continuable=continuable_flag<-truemethodclear_continuable=continuable_flag<-falsemethodtoken_feeded=token_feeded_flagmethodset_token_feeded=[%debug_log"token feeded flag set"];token_feeded_flag<-truemethodclear_token_feeded=[%debug_log"token feeded flag cleared"];token_feeded_flag<-falsemethodline_stat=line_statmethodset_line_stats=[%debug_log"setting line status to %s"(LineStat.to_strings)];line_stat<-smethodset_line_stat_assumed_blank=self#set_line_statLineStat.AssumedBlankmethodset_line_stat_nonblank=self#set_line_statLineStat.Nonblankmethodset_line_stat_pure_comment=self#set_line_statLineStat.PureCommentmethodset_line_stat_mixed_comment=self#set_line_statLineStat.MixedCommentmethodset_line_stat_continued=self#set_line_statLineStat.Continued(*
method prev_line_stat = prev_line_stat
*)methodcontinued=continued_flagmethodset_continued=[%debug_log"continued flag set"];continued_flag<-truemethodclear_continued=[%debug_log"continued flag cleared"];continued_flag<-falsemethodamp_line=amp_line_flagmethodset_amp_line=[%debug_log"amp line flag set"];amp_line_flag<-truemethodclear_amp_line=[%debug_log"amp line flag cleared"];amp_line_flag<-falsemethodat_BOCL=bocl_flagmethodset_BOCL=[%debug_log"BOCL flag set"];bocl_flag<-truemethodclear_BOCL=[%debug_log"BOCL flag cleared"];bocl_flag<-falsemethodset_pending_EOL_objo=[%debug_log"set!"];pending_EOL_obj<-Someomethodclear_pending_EOL_obj=[%debug_log"cleared!"];pending_EOL_obj<-Nonemethodget_pending_EOL_obj=matchpending_EOL_objwith|Someo->o|_->raiseNot_foundmethodtake_pending_EOL_obj=matchpending_EOL_objwith|Someo->pending_EOL_obj<-None;o|_->raiseNot_foundmethodpending_RAWOMP_obj_queue_length=Queue.lengthpending_RAWOMP_obj_queuemethodadd_pending_RAWOMP_objo=Queue.addopending_RAWOMP_obj_queuemethodclear_pending_RAWOMP_obj_queue=[%debug_log"called"];Queue.clearpending_RAWOMP_obj_queuemethodtake_pending_RAWOMP_obj=Queue.takepending_RAWOMP_obj_queuemethodpending_token_obj_queue_length=Queue.lengthpending_token_obj_queuemethodadd_pending_token_objo=Queue.addopending_token_obj_queuemethodclear_pending_token_obj_queue=[%debug_log"called"];Queue.clearpending_token_obj_queuemethodtake_pending_token_obj=Queue.takepending_token_obj_queuemethodset_last_lex_qtoken_objo=[%debug_log"called"];last_lex_qtoken_obj<-omethodget_last_lex_qtoken_obj=last_lex_qtoken_objmethodin_format_context=in_format_contextmethodenter_format_context=[%debug_log"entering format context"];in_format_context<-truemethodexit_format_context=[%debug_log"exiting format context"];in_format_context<-falsemethodin_open_context=in_open_contextmethodenter_open_context=[%debug_log"entering open context"];in_open_context<-truemethodexit_open_context=[%debug_log"exiting open context"];in_open_context<-falsemethodin_close_context=in_close_contextmethodenter_close_context=[%debug_log"entering close context"];in_close_context<-truemethodexit_close_context=[%debug_log"exiting close context"];in_close_context<-falsemethodin_position_context=in_position_contextmethodenter_position_context=[%debug_log"entering position context"];in_position_context<-truemethodexit_position_context=[%debug_log"exiting position context"];in_position_context<-falsemethodin_io_control_context=in_io_control_contextmethodenter_io_control_context=[%debug_log"entering io_control context"];in_io_control_context<-truemethodexit_io_control_context=[%debug_log"exiting io_control context"];in_io_control_context<-falsemethodin_wait_context=in_wait_contextmethodenter_wait_context=[%debug_log"entering wait context"];in_wait_context<-truemethodexit_wait_context=[%debug_log"exiting wait context"];in_wait_context<-falsemethodin_flush_context=in_flush_contextmethodenter_flush_context=[%debug_log"entering flush context"];in_flush_context<-truemethodexit_flush_context=[%debug_log"exiting flush context"];in_flush_context<-falsemethodin_if_context=in_if_contextmethodenter_if_context=[%debug_log"entering if context"];in_if_context<-truemethodexit_if_context=[%debug_log"exiting if context"];in_if_context<-falsemethodin_inquire_context=in_inquire_contextmethodenter_inquire_context=[%debug_log"entering inquire context"];in_inquire_context<-truemethodexit_inquire_context=[%debug_log"exiting inquire context"];in_inquire_context<-falsemethodin_implicit_context=in_implicit_contextmethodenter_implicit_context=[%debug_log"entering implicit context"];in_implicit_context<-truemethodexit_implicit_context=[%debug_log"exiting implicit context"];in_implicit_context<-falsemethodin_letter_context=in_letter_contextmethodenter_letter_context=[%debug_log"entering letter context"];in_letter_context<-truemethodexit_letter_context=[%debug_log"exiting letter context"];in_letter_context<-falsemethodin_intent_context=in_intent_contextmethodenter_intent_context=[%debug_log"entering intent context"];in_intent_context<-truemethodexit_intent_context=[%debug_log"exiting intent context"];in_intent_context<-falsemethodin_result_context=in_result_contextmethodenter_result_context=[%debug_log"entering result context"];in_result_context<-truemethodexit_result_context=[%debug_log"exiting result context"];in_result_context<-falsemethodin_character_context=in_character_contextmethodenter_character_context=[%debug_log"entering character context"];in_character_context<-truemethodexit_character_context=[%debug_log"exiting character context"];in_character_context<-falsemethodin_typeof_context=in_typeof_contextmethodenter_typeof_context=[%debug_log"entering typeof context"];in_typeof_context<-truemethodexit_typeof_context=[%debug_log"exiting typeof context"];in_typeof_context<-falsemethodin_do_context=in_do_contextmethodenter_do_context=[%debug_log"entering do context"];in_do_context<-truemethodexit_do_context=[%debug_log"exiting do context"];in_do_context<-falsemethodin_slash_name_context=in_slash_name_contextmethodenter_slash_name_context=[%debug_log"entering slash_name context"];in_slash_name_context<-truemethodexit_slash_name_context=[%debug_log"exiting slash_name context"];in_slash_name_context<-falsemethodin_allocate_context=in_allocate_contextmethodenter_allocate_context=[%debug_log"entering allocate context"];in_allocate_context<-truemethodexit_allocate_context=[%debug_log"exiting allocate context"];in_allocate_context<-falsemethodin_type_spec_context=in_type_spec_contextmethodenter_type_spec_context=[%debug_log"entering type-spec context"];in_type_spec_context<-truemethodexit_type_spec_context=[%debug_log"exiting type-spec context"];in_type_spec_context<-falsemethodin_bind_context=in_bind_contextmethodenter_bind_context=[%debug_log"entering bind context"];in_bind_context<-truemethodexit_bind_context=[%debug_log"exiting bind context"];in_bind_context<-falsemethodin_interface_context=interface_context>0methodenter_interface_context=interface_context<-interface_context+1;[%debug_log"entering interface context (->%d)"interface_context]methodexit_interface_context=begin%debug_blockifinterface_context=0then[%debug_log"unbalanced end of interface"]end;interface_context<-interface_context-1;[%debug_log"exiting interface context (->%d)"interface_context]methodin_structure_context=structure_context>0methodenter_structure_context=structure_context<-structure_context+1;[%debug_log"entering structure context (->%d)"structure_context]methodexit_structure_context=begin%debug_blockifstructure_context=0then[%debug_log"unbalanced end of structure"]end;structure_context<-structure_context-1;[%debug_log"exiting structure context (->%d)"structure_context]methodin_select_type_context=select_type_context>0methodenter_select_type_context=select_type_context<-select_type_context+1;[%debug_log"entering select-type context (->%d)"select_type_context]methodexit_select_type_context=begin%debug_blockifselect_type_context=0then[%debug_log"unbalanced end of select-type"]end;select_type_context<-select_type_context-1;[%debug_log"exiting select-type context (->%d)"select_type_context]methodin_contains_context=in_contains_contextmethodenter_contains_context=[%debug_log"entering contains context"];in_contains_context<-truemethodexit_contains_context=[%debug_log"exiting contains context"];in_contains_context<-falsemethodin_access_context=in_access_contextmethodenter_access_context=[%debug_log"entering access context"];in_access_context<-truemethodexit_access_context=[%debug_log"exiting access context"];in_access_context<-falsemethodin_data_context=in_data_contextmethodenter_data_context=[%debug_log"entering data context"];in_data_context<-truemethodexit_data_context=[%debug_log"exiting data context"];in_data_context<-falsemethodin_type_guard_context=in_type_guard_contextmethodenter_type_guard_context=[%debug_log"entering type-guard context"];in_type_guard_context<-truemethodexit_type_guard_context=[%debug_log"exiting type-guard context"];in_type_guard_context<-falsemethodin_procedure_context=in_procedure_contextmethodenter_procedure_context=[%debug_log"entering procedure context"];in_procedure_context<-truemethodexit_procedure_context=[%debug_log"exiting procedure context"];in_procedure_context<-falsemethodin_type_context=in_type_contextmethodenter_type_context=[%debug_log"entering type context"];in_type_context<-truemethodexit_type_context=[%debug_log"exiting type context"];in_type_context<-falsemethodin_only_context=in_only_contextmethodenter_only_context=[%debug_log"entering only context"];in_only_context<-truemethodexit_only_context=[%debug_log"exiting only context"];in_only_context<-falsemethodin_pu_head_context=in_pu_head_contextmethodenter_pu_head_context=[%debug_log"entering PU-head context"];in_pu_head_context<-truemethodexit_pu_head_context=[%debug_log"exiting PU-head context"];in_pu_head_context<-falsemethodin_vfe_context=in_vfe_contextmethodenter_vfe_context=[%debug_log"entering vfe context"];in_vfe_context<-truemethodexit_vfe_context=[%debug_log"exiting vfe context"];in_vfe_context<-falsemethodin_array_ctor_context=array_ctor_context>0methodenter_array_ctor_context=array_ctor_context<-array_ctor_context+1;[%debug_log"entering array constructor context (->%d)"array_ctor_context]methodexit_array_ctor_context=begin%debug_blockifarray_ctor_context=0then[%debug_log"unbalanced array constructor"]end;array_ctor_context<-array_ctor_context-1;[%debug_log"exiting array constructor context (->%d)"array_ctor_context]methodin_char_context=char_context<>CH_NONEmethodchar_context=char_contextmethodenter_char_single=[%debug_log"entering char single context"];char_context<-CH_SINGLEmethodenter_char_double=[%debug_log"entering char double context"];char_context<-CH_DOUBLEmethodexit_char=[%debug_log"exiting char context"];char_context<-CH_NONEmethodin_paren_context=paren_context>0methodenter_paren_context=paren_context<-paren_context+1;[%debug_log"entering paren context (->%d)"paren_context]methodexit_paren_context=begin%debug_blockifparen_context=0then[%debug_log"unbalanced parentheses"]end;paren_context<-paren_context-1;[%debug_log"exiting paren context (->%d)"paren_context]methodin_name_context=name_context>0methodenter_name_context=name_context<-name_context+1;[%debug_log"entering name context (->%d)"name_context]methodexit_name_context=begin%debug_blockifname_context=0then[%debug_log"unbalanced name_context"]end;name_context<-name_context-1;[%debug_log"exiting name context (->%d)"name_context]methodlex_in_paren_context=lex_paren_context>0methodlex_paren_level=lex_paren_contextmethodlex_enter_paren_context=lex_paren_context<-lex_paren_context+1;[%debug_log"entering lex paren context (->%d)"lex_paren_context];methodlex_exit_paren_context=begin%debug_blockiflex_paren_context=0then[%debug_log"unbalanced parentheses (lexer)"];end;lex_paren_context<-lex_paren_context-1;[%debug_log"exiting lex paren context (->%d)"lex_paren_context];methodregister_labelpathline((lab,loc)aslabel)=let_=labinlet_=locin[%debug_log"registering: %s:%d -> label:%s[%s]"pathlinelab(Loc.to_stringloc)];Hashtbl.addlabel_tbl(path,line)labelmethodfind_labelpath_line=Hashtbl.findlabel_tblpath_linemethodregister_ambiguous_node(node:Ast.node)=[%debug_log"registering: %s"node#to_string];Xset.addambiguous_nodes(node,self#__copy_stackstack)methoditer_ambiguous_nodes(f:Ast.node->unit)=letl=Xset.to_listambiguous_nodesinletsorted=List.fast_sort(fun(n0,_)(n1,_)->Stdlib.comparen1#loc.Loc.start_offsetn0#loc.Loc.start_offset)linList.iter(fun(nd,_stk)->letstk=self#_copy_stack_stkinself#change_stackstk;(*[%debug_log "top frame:\n%s\n" (Stack.top stk)#to_string];*)fnd;self#recover_stack)sortedmethodcheckpoint(key:C.key_t)=[%debug_log"key=%s"(C.key_to_stringkey)];letstat=mkstatebopu_flag(Hashtbl.copysymbol_tbl)(self#__copy_stackstack)in_format_contextin_open_contextin_close_contextin_position_contextin_io_control_contextin_wait_contextin_flush_contextin_if_contextin_inquire_contextin_implicit_contextin_letter_contextin_intent_contextin_result_contextin_character_contextin_typeof_contextin_do_contextin_slash_name_contextin_allocate_contextin_type_spec_contextin_bind_contextin_contains_contextin_access_contextin_data_contextin_type_guard_contextin_procedure_contextin_type_contextin_only_contextin_pu_head_contextname_contextparen_contextarray_ctor_contextinterface_contextstructure_contextselect_type_contextchar_contextin[%debug_log"status:\n%s"(stat_to_stringstat)];(*
if Hashtbl.mem checkpoint_tbl key then
[%debug_log "already checkpointed: key=%s" (C.key_to_string key)];
*)Hashtbl.addcheckpoint_tblkeystat;methodrecover?(remove=false)key=[%debug_log"key=%s remove=%B"(C.key_to_stringkey)remove];tryletstat=Hashtbl.findcheckpoint_tblkeyin[%debug_log"\n%s"(stat_to_stringstat)];bopu_flag<-stat.s_at_bopu;symbol_tbl<-Hashtbl.copystat.s_symbol_tbl;stack<-self#__copy_stackstat.s_stack;in_format_context<-stat.s_in_format_context;in_open_context<-stat.s_in_open_context;in_close_context<-stat.s_in_close_context;in_position_context<-stat.s_in_position_context;in_io_control_context<-stat.s_in_io_control_context;in_wait_context<-stat.s_in_wait_context;in_flush_context<-stat.s_in_flush_context;in_if_context<-stat.s_in_if_context;in_inquire_context<-stat.s_in_inquire_context;in_implicit_context<-stat.s_in_implicit_context;in_letter_context<-stat.s_in_letter_context;in_intent_context<-stat.s_in_intent_context;in_result_context<-stat.s_in_result_context;in_character_context<-stat.s_in_character_context;in_typeof_context<-stat.s_in_typeof_context;in_do_context<-stat.s_in_do_context;in_slash_name_context<-stat.s_in_slash_name_context;in_allocate_context<-stat.s_in_allocate_context;in_type_spec_context<-stat.s_in_type_spec_context;in_bind_context<-stat.s_in_bind_context;in_contains_context<-stat.s_in_contains_context;in_access_context<-stat.s_in_access_context;in_data_context<-stat.s_in_data_context;in_type_guard_context<-stat.s_in_type_guard_context;in_procedure_context<-stat.s_in_procedure_context;in_type_context<-stat.s_in_type_context;in_only_context<-stat.s_in_only_context;in_pu_head_context<-stat.s_in_pu_head_context;name_context<-stat.s_name_context;paren_context<-stat.s_paren_context;array_ctor_context<-stat.s_array_ctor_context;interface_context<-stat.s_interface_context;structure_context<-stat.s_structure_context;select_type_context<-stat.s_select_type_context;char_context<-stat.s_char_context;ifremovethenHashtbl.removecheckpoint_tblkeywithNot_found->raise(Internal_error(Printf.sprintf"state not found: key=%s"(C.key_to_stringkey)));methodremove_checkpoint_keykey=Hashtbl.removecheckpoint_tblkeymethodreset_stat=[%debug_log"resetting..."];self#reset_stack;(*
bopu_flag <- stat.s_at_bopu;
symbol_tbl <- Hashtbl.copy stat.s_symbol_tbl;
stack <- self#_copy_stack stat.s_stack;
*)in_format_context<-false;in_open_context<-false;in_close_context<-false;in_position_context<-false;in_io_control_context<-false;in_wait_context<-false;in_flush_context<-false;in_if_context<-false;in_inquire_context<-false;in_implicit_context<-false;in_letter_context<-false;in_intent_context<-false;in_result_context<-false;in_character_context<-false;in_typeof_context<-false;in_do_context<-false;in_slash_name_context<-false;in_allocate_context<-false;in_type_spec_context<-false;in_bind_context<-false;in_contains_context<-false;in_access_context<-false;in_data_context<-false;in_type_guard_context<-false;in_procedure_context<-false;in_type_context<-false;in_only_context<-false;in_pu_head_context<-false;name_context<-0;paren_context<-0;array_ctor_context<-0;interface_context<-0;structure_context<-0;select_type_context<-0;char_context<-CH_NONEmethodeffective_lines_for_source_form_guess=effective_lines_for_source_form_guessmethodignore_include_flag=ignore_include_flagmethodset_ignore_include_flag=ignore_include_flag<-truemethodclear_ignore_include_flag=ignore_include_flag<-false(*
method find_symbol id =
try
Hashtbl.find symbol_tbl id
with
Not_found -> Hashtbl.find base_symbol_tbl id
*)methodcurrent_frame=tryStack.topstackwithStack.Empty->raise(Internal_error"Parser_aux.get_current_frame: stack empty")methodprivate_copy_stacks=(* let copy = Stack.copy s in*)letcopy=Stack.create()inletfs=ref[]inStack.iter(funf->fs:=f#copy::!fs)s;List.iter(funf->Stack.pushfcopy)!fs;copymethodprivate__copy_stacks=letcopy=Stack.create()inletfs=ref[]inStack.iter(funf->fs:=f#_copy::!fs)s;List.iter(funf->Stack.pushfcopy)!fs;copymethodprivatename_implicit_spec_of_ispec_node(node:Ast.node)=matchnode#labelwith|L.ImplicitSpec->beginmatchnode#childrenwith|ty::lss->beginlettspec=I.TypeSpec.of_labelty#labelin[%debug_log"type=%s"(I.TypeSpec.to_stringtspec)];letispec=newN.ImplicitSpec.ctspecinletlod=N.Spec.loc_of_decl_implicitnode#orig_locinletiod=Oo.idnodeinletbid=self#genbidlodinnode#set_binding(B.make_unknown_defbidtrue);ispec#set_letter_spec_list(Xlist.filter_map(funls->N.ImplicitSpec.letter_spec_of_labells#label)lss);ispec#set_loc_of_decllod;ispec#set_id_of_decliod;ispec#set_bidbid;Someispecend|_->parse_warning_locnode#loc"empty ImplicitSpec";Noneend|lab->parse_warning_locnode#loc"not an implicit-spec: %s"(L.to_simple_stringlab);Nonemethodset_implicit_spec(ispec_nds:Ast.nodelist)=self#current_frame#set_implicit_spec_list(Xlist.filter_mapself#name_implicit_spec_of_ispec_nodeispec_nds)methodadd_implicit_spec(ispec_nds:Ast.nodelist)=self#current_frame#add_implicit_spec_list(Xlist.filter_mapself#name_implicit_spec_of_ispec_nodeispec_nds)methoddefault_accessibility=self#current_frame#default_accessibilitymethodset_default_accessibility_public=self#current_frame#set_default_accessibility_publicmethodset_default_accessibility_private=self#current_frame#set_default_accessibility_privatemethodregister_used_modulemname=[%debug_log"%s"mname];(*Printf.printf "!!! register_used_module: %s (%s)\n%!"
mname (N.ScopingUnit.to_string self#current_frame#scope);*)self#current_frame#add_used_modulemnamemethodregister_global_name(id:name)spec=[%debug_log"[stack size:%d] \"%s\" -> %s (FRM:%s)"(Stack.lengthstack)id(N.Spec.to_stringspec)(N.ScopingUnit.to_stringtoplevel_frame#scope)];toplevel_frame#addidspecmethodregister_name?(nth=0)(id:name)spec=letlen=Stack.lengthstackinletfrm=refself#current_frameinifnth>0&&nth<lenthenbeginletcount=ref0intryStack.iter(funf->if!count=nththenbeginfrm:=f;raiseExitend;incrcount)stackwithExit->()end;[%debug_log"[stack size:%d][nth=%d] \"%s\" -> %s (FRM:%s)"lennthid(N.Spec.to_stringspec)(N.ScopingUnit.to_string(!frm)#scope)];(!frm)#addidspecmethoditer_used_modulesf=Stack.iter(funframe->frame#iter_used_modulesf)stackmethodlookup_name?(allow_implicit=true)?(afilt=(fun_->true))(id:name)=[%debug_log"[stack size:%d] \"%s\""(Stack.lengthstack)id];(* let id_ = String.lowercase_ascii id in *)letall=ref[]inletall_filtered=ref[]inlethas_open_module_use=reffalseinbeginStack.iter(funframe->[%debug_log"FRM: <%s>"(N.ScopingUnit.to_stringframe#scope)];ifframe#has_open_module_usethenhas_open_module_use:=true;tryletspecs:N.Spec.tlist=frame#find_allidinifspecs<>[]thenbegin[%debug_log"[not filtered] %s ->\n%s"id(Xlist.to_string(N.Spec.to_string)"\n"specs)];all:=!all@specsend;letfiltered=List.filterafiltspecsiniffiltered<>[]thenbegin[%debug_log"[filtered] %s ->\n%s"id(Xlist.to_string(N.Spec.to_string)"\n"filtered)];all_filtered:=!all_filtered@filteredendwithNot_found->())stackend;if!all=[]&&allow_implicitthenbegintryif!has_open_module_usethenraiseNot_foundelseletimplicit_spec=self#current_frame#post_findidinself#register_nameidimplicit_spec;List.filterafilt[implicit_spec]withNot_found->beginletext_specs=ref[N.Spec.mkext""id]inStack.iter(funframe->ext_specs:=!ext_specs@(frame#get_ext_namesid))stack;List.iter(funs->self#register_nameids)!ext_specs;List.filterafilt!ext_specsendendelsebegin!all_filteredendmethod_begin_scopescope=letfrm=matchscopewith|N.ScopingUnit.Program->toplevel_frame|N.ScopingUnit.Module_->letf=newN.framescopeinf#set_default_accessibility_public;f|_->newN.framescopein[%debug_log"PUSH(%d): FRM: <%s>"(Stack.lengthstack)(N.ScopingUnit.to_stringscope)];Stack.pushfrmstack;frmmethodend_scope=tryletfrm=(Stack.popstack)in[%debug_log"POP(%d): FRM: <%s>"(Stack.lengthstack)(N.ScopingUnit.to_stringfrm#scope)];matchfrm#scopewith(*
| SKpackage id -> Hashtbl.add symbol_tbl id frm
| SKclass id -> begin
try
let a = self#lookup_name id in
match a with
| (IAclass tblr)::_ -> tblr := frm.f_tbl
| _ -> assert false
with
Not_found -> assert false (* toplevel *)
end
*)|_->()withStack.Empty->raise(Internal_error"Parser_aux.end_scope: stack empty")methodfind_frame_forid=tryStack.iter(funframe->tryifframe#memidthenraise(N.Frame_foundframe)withNot_found->())stack;raiseNot_foundwithN.Frame_foundfrm->frmmethod!init=bidgen#reset;super#init;Queue.clearpending_RAWOMP_obj_queue;Queue.clearpending_token_obj_queue;(*self#init_latest_stmt_node_set_stack;*)loc_stack#init;Hashtbl.clearsymbol_tbl;Stack.clearstack;Hashtbl.clearcheckpoint_tbl;Hashtbl.clearfname_ext_cache;(*
condtbl#reset;
*)context_enter_flag<-false;context_activate_flag<-false;last_active_ofss<-(0,0);partial_parsing_flag<-falseinitializerself#initend(* of class env *)]moduletypeSTATE_T=sigvalenv:envvalcontext_stack:Context.stackend[%%capture_pathmoduleF(Stat:STATE_T)=structopenStatletparse_errorsposepos:('a,unit,string,'b)format4->'a=PB.parse_errorenv(funloc->newAst.node~lloc:(env#mkllocloc)(L.ERROR""))sposeposletparse_error_locloc:('a,unit,string,'b)format4->'a=PB.parse_error_locenv(funloc->newAst.node~lloc:(env#mkllocloc)(L.ERROR""))locletcheck_error(node:Ast.node)=ifnotenv#partial_parsing_flagthenbeginAst.visit(funnd->ifL.is_errornd#label&&nd#lloc#get_level=0thenenv#missed_regions#addnd#loc)nodeendletregister_unknownname=env#register_namenameN.Spec.Unknownletregister_mainname=env#register_global_namenameN.Spec.MainProgramletregister_associate_namename=env#register_namenameN.Spec.AssociateNameletregister_object?(nth=0)?(node=Ast.dummy_node)?(attr_handler=fun_->())namemkspec=[%debug_log"name=\"%s\""name];letis_dummy_node=Ast.is_dummy_nodenodeinletlod,iod=ifis_dummy_nodethenN.Spec.loc_of_decl_unknown,-1elseN.Spec.loc_of_decl_explicitnode#orig_loc,Oo.idnodeinletbid=env#genbidlodinletospec=N.Spec.mkobj~loc_of_decl:lod~id_of_decl:iod~bid_opt:(Somebid)()inbegintryleta=ospec#attrinattr_handlera;beginmatchenv#lookup_name~allow_implicit:falsenamewith|[]->a#set_access_specenv#default_accessibility|spec::_->begintrya#set_access_spec(N.Spec.get_access_specspec)with_->a#set_access_specenv#default_accessibilityendendwithNot_found->assertfalseend;letspec=mkspecospecinifis_dummy_nodethenbeginnode#set_binding(B.make_unknown_defbidtrue);node#set_info(I.mknamespecspec)end;env#register_name~nthnamespec(* func register_object *)letregister_function?(node=Ast.dummy_node)name=register_object~nodenameN.Spec.mkfunctionletregister_subroutine?(node=Ast.dummy_node)name=register_object~nodenameN.Spec.mksubroutineletregister_separate_module_subprogram?(node=Ast.dummy_node)name=register_object~nodenameN.Spec.mkseparate_module_subprogramletregister_entry?(node=Ast.dummy_node)name=ignorename;matchenv#current_frame#scopewith|N.ScopingUnit.FunctionSubprogramn->register_function~noden|N.ScopingUnit.SubroutineSubprogramn->register_subroutine~noden|N.ScopingUnit.SeparateModuleSubprogramn->register_separate_module_subprogram~noden|_->failwith(Printf.sprintf"invalid scoping unit: %s"(N.ScopingUnit.to_stringenv#current_frame#scope))letregister_generic?(node=Ast.dummy_node)name=register_object~nodenameN.Spec.mkgenericletregister_namelist_group?(node=Ast.dummy_node)name=register_object~nodenameN.Spec.mknamelistgroupletregister_derived_type?(node=Ast.dummy_node)aspec_nodesnamefrm=letattr_specs=List.fold_left(funlaspec_node->matchaspec_node#labelwith|L.TypeAttrSpeca->a::l|_->l)[]aspec_nodesinletattr_handlera=List.iter(function|TypeAttrSpec.Public->a#set_access_spec_public|TypeAttrSpec.Private->a#set_access_spec_private|TypeAttrSpec.Abstract->()|TypeAttrSpec.Bind->()|TypeAttrSpec.Extends_->())attr_specsinregister_object~nth:1~node~attr_handlername(N.Spec.mkderivedtype(N.Spec.mkframev~find:frm#find~add:frm#add))letregister_interface_namename=env#register_namename(N.Spec.mkinamename)letregister_modulenamefrm=letspec=N.make_modulenamefrminenv#register_global_namenamespecletregister_submodulenamefrm=letspec=N.make_modulenamefrminenv#register_global_namenamespecletregister_block_dataname=env#register_global_namenameN.Spec.BlockDataletregister_common_blockname=env#register_global_namenameN.Spec.CommonBlockletregister_external_namenamemodule_nameuse_name=env#register_namename(N.Spec.mkextmodule_nameuse_name)letrecregister_external?(exclude=Xset.create0)mod_namend=matchnd#label,nd#childrenwith|L.Rename,[ln;un]->begintryletn=String.lowercase_asciiln#get_nameinifnot(Xset.memexcluden)thenregister_external_namenmod_nameun#get_namewithNot_found->()end|L.Ambiguous(Ambiguous.GenericSpecOrUseNamen),[]|L.GenericSpec(GenericSpec.Namen),_->ifnot(Xset.memexclude(String.lowercase_asciin))thenregister_external_namenmod_namen|L.OnlyList,onlys->List.iter(register_external~excludemod_name)onlys|_->()letregister_edecl_nodetype_specattr_optnode=[%debug_log"%s"node#to_string];matchnode#labelwith|L.EntityDecln|L.ComponentDecln->beginleta_opt=letds=Xlist.filter_map(funx->ifL.is_array_specx#label||L.is_component_array_specx#labelthenSome(N.Dimension.of_labelx#label)elseNone)node#childreninletcs=Xlist.filter_map(funx->ifL.is_coarray_specx#labelthenSome(N.Codimension.of_labelx#label)elseNone)node#childreninletno_attr=attr_opt=None&&ds=[]&&cs=[]inifno_attrthenbeginleta=newN.Attribute.cina#set_access_specenv#default_accessibility;Someaendelsebeginletattr=matchattr_optwith|Somea->a|None->newN.Attribute.cinifattr#access_spec_not_setthenattr#set_access_specenv#default_accessibility;List.iterattr#set_dimensionds;List.iterattr#set_codimensioncs;Someattrendin(* a_opt *)letlod=N.Spec.loc_of_decl_explicitnode#orig_locinletiod=Oo.idnodeinletbid=env#genbidlodinnode#set_binding(B.make_unknown_defbidtrue);letspec=matchenv#lookup_name~afilt:N.Spec.has_data_object_specnwith|spc::_->letdobj=N.Spec.get_data_object_specspcindobj#set_type_spectype_spec;dobj#set_loc_of_decllod;dobj#set_id_of_decliod;dobj#set_bidbid;beginmatcha_optwith|Somea->begintrydobj#attr#mergeawithNot_found->dobj#set_attraend|None->()end;[%debug_log" --> %s"(N.Spec.to_stringspc)];spc|[]->letspc=N.Spec.mkdobj~loc_of_decl:lod~id_of_decl:iod~bid_opt:(Somebid)~type_speca_optinenv#register_namenspc;spcinnode#set_info(I.mknamespecspec)end|_->parse_warning_locnode#loc"not an entity-decl or a component-decl"letregister_pdecl_nodeaspec_nodespinode=[%debug_log"%s"node#to_string];matchnode#labelwith|L.ProcDecln->beginletlod=N.Spec.loc_of_decl_explicitnode#orig_locinletiod=Oo.idnodeinletbid=env#genbidlodinnode#set_binding(B.make_unknown_defbidtrue);letpspec=N.Spec.mkproc~loc_of_decl:lod~id_of_decl:iod~bid_opt:(Somebid)piinleta=trypspec#attrwithNot_found->assertfalseinifaspec_nodes<>[]thenbeginletattr_specs=List.fold_left(funlaspec_node->matchaspec_node#labelwith|L.ProcAttrSpeca->a::l|_->l)[]aspec_nodesinList.iter(function|ProcAttrSpec.Public->a#set_access_spec_public|ProcAttrSpec.Private->a#set_access_spec_private|ProcAttrSpec.Bind->a#set_bind|ProcAttrSpec.Intenti->a#set_intent_spec(N.IntentSpec.of_ispec_labeli)|ProcAttrSpec.Optional->a#set_optional|ProcAttrSpec.Pointer->a#set_pointer|ProcAttrSpec.Save->a#set_save|ProcAttrSpec.Protected->a#set_protected|_->())attr_specsend;beginmatchenv#lookup_name~allow_implicit:falsenwith|[]->a#set_access_specenv#default_accessibility|spec::_->begintrya#set_access_spec(N.Spec.get_access_specspec)with_->a#set_access_specenv#default_accessibilityendend;letspec=N.Spec.mkprocedurepspecinnode#set_info(I.mknamespecspec);env#register_namenspecend|_->parse_warning_locnode#loc"not a procedure-decl"letbegin_program_scope()=ignore(env#_begin_scopeN.ScopingUnit.Program)letbegin_derived_type_def_scopen=env#_begin_scope(N.ScopingUnit.DerivedTypeDefn)letbegin_headless_main_program_scope()=ignore(env#_begin_scope(N.ScopingUnit.MainProgram(None,reffalse)))letbegin_main_program_scopen_opt=ignore(env#_begin_scope(N.ScopingUnit.MainProgram(n_opt,reftrue)))letbegin_function_subprogram_scopen=ignore(env#_begin_scope(N.ScopingUnit.FunctionSubprogramn))letbegin_subroutine_subprogram_scopen=ignore(env#_begin_scope(N.ScopingUnit.SubroutineSubprogramn))letbegin_separated_module_subprogram_scopen=ignore(env#_begin_scope(N.ScopingUnit.SeparateModuleSubprogramn))letbegin_module_scopen=env#_begin_scope(N.ScopingUnit.Modulen)letbegin_submodule_scopen=env#_begin_scope(N.ScopingUnit.Modulen)letbegin_block_data_scopen_opt=ignore(env#_begin_scope(N.ScopingUnit.BlockDatan_opt))letbegin_block_scopen_opt=ignore(env#_begin_scope(N.ScopingUnit.BlockConstructn_opt))letbegin_structure_decl_scopen_opt=env#_begin_scope(N.ScopingUnit.StructureDecln_opt)letend_scope()=env#end_scopeletset_headed()=[%debug_log"current scope: %s"(N.ScopingUnit.to_stringenv#current_frame#scope)];matchenv#current_frame#scopewith|N.ScopingUnit.MainProgram(_,hd)->hd:=true|_->()letcancel_main_program_scope()=[%debug_log"current scope: %s"(N.ScopingUnit.to_stringenv#current_frame#scope)];matchenv#current_frame#scopewith|N.ScopingUnit.MainProgram_->end_scope()|_->()letnormalize_labellab=Xstring.lstrip~strs:["0"]labletprefix_digits_pat=Str.regexp"^[0-9]+"letstartswith_digitsstr=Str.string_matchprefix_digits_patstr0letsplit_data_edit_desc=letsplits=letb=Str.string_matchprefix_digits_pats0inifbthenbeginleti_str=Str.matched_stringsintryleti=int_of_stringi_strinletdesc=Xstring.lstrip~strs:[" ";i_str]sinSomei,descwith_->assertfalseendelseNone,sinsplitletmake_vfe_lab?(i_opt=None)?(tail="")str=leti_opt',s=split_data_edit_descstrinleti_opt''=matchi_opt,i_opt'with|None,None->None|None,x_opt|x_opt,None->x_opt|Somex,Somey->trySome(int_of_string((string_of_intx)^(string_of_inty)))with_->assertfalseinL.FormatItem(FormatItem.VariableFormatDesc(i_opt'',s^tail))leti_opt_of_r_opt=function|None->None|Somer->trySome(int_of_stringr)with_->assertfalseletat_EOPU()=ifnotenv#at_BOPUthenbegin[%debug_log"handling EOPU"];begin_headless_main_program_scope();context_stack#push(Context.spec__exec());env#set_BOPUendletlloc_of_posspos0pos1=letloc=Astloc.of_lexposspos0pos1inletlayers=env#current_loc_layersinnewLayeredloc.c~layerslocletmake_error_nodestart_posend_pos=begin%debug_block[%debug_log"start_offset=%d, end_offset=%d"start_pos.Lexing.pos_cnumend_pos.Lexing.pos_cnum];letst,ed=env#get_last_active_ofssin[%debug_log"last_active_ofss: %d - %d"sted];end;letlloc=lloc_of_possstart_posend_posinifnotenv#partial_parsing_flag&&lloc#get_level=0thenenv#missed_regions#addlloc#get_loc;newAst.node~lloc(L.ERROR"")letlocal_name_of_rename_node(node:Ast.node)=matchnode#labelwith|L.Rename->beginmatchnode#childrenwith|n::_->Somen#get_name|[]->parse_warning_locnode#loc"malformed rename";Noneend|_->Noneletlocal_name_list_of_rename_nodes=Xlist.filter_maplocal_name_of_rename_nodeletname_attribute_of_aspec_nodesnodes=letattr=newN.Attribute.cinList.iter(funnode->matchnode#labelwith|L.AttrSpeca->beginmatchawith|AttrSpec.Parameter->attr#set_parameter|AttrSpec.Public->attr#set_access_spec_public|AttrSpec.Private->attr#set_access_spec_private|AttrSpec.Allocatable->attr#set_allocatable|AttrSpec.Dimension->beginletd=matchnode#childrenwith|[a]->N.Dimension.of_labela#label|_->parse_warning_locnode#loc"invalid dimension";N.Dimension.NoDimensioninattr#set_dimensiondend|AttrSpec.Codimension->beginletd=matchnode#childrenwith|[a]->N.Codimension.of_labela#label|_->parse_warning_locnode#loc"invalid codimension";N.Codimension.NoCodimensioninattr#set_codimensiondend|AttrSpec.External->attr#set_external|AttrSpec.Intenti->attr#set_intent_spec(N.IntentSpec.of_ispec_labeli)|AttrSpec.Intrinsic->attr#set_intrinsic|AttrSpec.Optional->attr#set_optional|AttrSpec.Pointer->attr#set_pointer|AttrSpec.Save->attr#set_save|AttrSpec.Target->attr#set_target|AttrSpec.Asynchronous->attr#set_asynchronous|AttrSpec.Bind->attr#set_bind|AttrSpec.Protected->attr#set_protected|AttrSpec.Value->attr#set_value|AttrSpec.Volatile->attr#set_volatile|AttrSpec.Contiguous->attr#set_contiguous|AttrSpec.Automatic->attr#set_automatic|AttrSpec.Static->attr#set_static|AttrSpec.Device->attr#set_device|AttrSpec.Managed->attr#set_managed|AttrSpec.Constant->attr#set_constant|AttrSpec.Shared->attr#set_shared|AttrSpec.Pinned->attr#set_pinned|AttrSpec.Texture->attr#set_textureend|_->assertfalse)nodes;attrletset_attr_of_data_object?(type_spec=I.TypeSpec.Unknown)(setter:N.Attribute.c->unit)name=[%debug_log"name=\"%s\""name];tryletattr=matchenv#lookup_name~afilt:N.Spec.has_data_object_specnamewith|[]->begin[%debug_log"setting attribute of unknown data object: %s"name];leta=newN.Attribute.cinletnspec=N.Spec.mkdobj~type_spec(Somea)inenv#register_namenamenspec;aend|spec::_->begintryN.Spec.get_data_object_attrspecwithNot_found->leta=newN.Attribute.cin(N.Spec.get_data_object_specspec)#set_attra;aendinsetterattr;[%debug_log"attr --> %s"attr#to_string]withNot_found->assertfalseletset_access_attraspecmkdefaultname=[%debug_log"name=\"%s\""name];tryletattr=letafilt=N.Spec.has_accessibility_attrinmatchenv#lookup_name~allow_implicit:false~afiltnamewith|[]->beginmkdefault()end|spec::_->begintryN.Spec.get_accessibility_attrspecwithNot_found->assertfalseendinattr#set_access_specaspec;[%debug_log"attr: %s"attr#to_string]withNot_found->assertfalseletset_access_spec_attraspecnode=matchnode#labelwith|L.Namename|L.Ambiguous(Ambiguous.Designatorname)->set_access_attraspec(fun()->letafilt=N.Spec.has_data_object_specinmatchenv#lookup_name~allow_implicit:false~afiltnamewith|[]->begin[%debug_log"setting attribute of unknown data object: %s"name];leta=newN.Attribute.cinletnspec=N.Spec.mkdobj(Somea)inenv#register_namenamenspec;(a:>N.Attribute.accessibility)end|spec::_->begintry(N.Spec.get_data_object_attrspec:>N.Attribute.accessibility)withNot_found->leta=newN.Attribute.cin(N.Spec.get_data_object_specspec)#set_attra;(a:>N.Attribute.accessibility)end)name|L.Ambiguous(Ambiguous.GenericSpecOrUseNamename)->set_access_attraspec(fun()->letafilt=N.Spec.has_object_specinmatchenv#lookup_name~allow_implicit:false~afiltnamewith|[]->begin[%debug_log"setting attribute of unknown object: %s"name];leta=newN.Attribute.accessibilityinleto=newN.Spec.object_spec()ino#set_attra;letnspec=N.Spec.mkobjectoinenv#register_namenamenspec;aend|spec::_->begintry(N.Spec.get_object_attrspec:>N.Attribute.accessibility)withNot_found->leta=newN.Attribute.accessibilityin(N.Spec.get_object_specspec)#set_attra;aend)name|L.GenericSpec(GenericSpec.Namename)->set_access_attraspec(fun()->letnspec=N.Spec.mkobj()inenv#register_namename(N.Spec.mkgenericnspec);nspec#attr)name|_->()letfinalize_object_spec?(multi_bind=false)namenode=[%debug_log"name=\"%s\""name];[%debug_log"node=%s"node#to_string];trymatchenv#lookup_name~allow_implicit:false~afilt:N.Spec.has_object_specnamewith|[]->()|specs->letbid_opt=refNoneinList.iter(funspec->[%debug_log"spec: %s"(N.Spec.to_stringspec)];letfirst_time=!bid_opt=Noneintryletospec=N.Spec.get_object_specspecin[%debug_log"ospec: %s"ospec#to_string];letlod=N.Spec.loc_of_decl_explicitnode#orig_locinletiod=Oo.idnodeinospec#set_loc_of_decllod;ospec#set_id_of_decliod;[%debug_log" -> %s"ospec#to_string];[%debug_log"ospec#bid=%a"BID.psospec#bid];letbid=match!bid_optwith|Somebid->ifospec#bid<>bidthenbegin[%debug_log"%a -> %a"BID.psospec#bidBID.psbid];ospec#set_bidbidend;bid|None->bid_opt:=Someospec#bid;ospec#bidinifmulti_bindthenbeginiffirst_timethenbegin[%debug_log"adding %a"BID.psbid];node#add_binding(B.make_unknown_defbidtrue);node#add_info(I.mknamespecspec)endendelsebegin[%debug_log"setting %a"BID.psbid];node#set_binding(B.make_unknown_defbidtrue);node#set_info(I.mknamespecspec)endwithNot_found->())(List.revspecs)withNot_found->assertfalseletocl_tuple_to_n_opt_names=OclDirective.ocl_tuple_to_n_opt_namesletocl_tuple_to_names=OclDirective.ocl_tuple_to_namesletocl_tuple_to_name=OclDirective.ocl_tuple_to_nameletocl_tuple_opt_to_names=OclDirective.ocl_tuple_opt_to_namesletocl_tuple_opt_to_num_opt=OclDirective.ocl_tuple_opt_to_num_optletocl_tuple_to_nn=OclDirective.ocl_tuple_to_nnletocl_tuple_to_num=OclDirective.ocl_tuple_to_numletocl_tuple_to_nums=OclDirective.ocl_tuple_to_numsletmknn=letname=ifenv#ignore_casethenString.lowercase_asciinelseninL.Namenameletfinalize_directivend=matchnd#childrenwith|[d]->d#set_llocnd#lloc;d|_->ndletmark_EOPU?(ending_scope=true)()=[%debug_log"current scope: %s"(N.ScopingUnit.to_stringenv#current_frame#scope)];ifending_scopethenbeginend_scope();[%debug_log" -> %s"(N.ScopingUnit.to_stringenv#current_frame#scope)]end;beginmatchenv#current_frame#scopewith|N.ScopingUnit.Program->beginenv#exit_contains_context;end|_->()endletrecis_xxx_part_construct(quantifier:(Ast.node->bool)->Ast.nodelist->bool)label_is_xxx_part_constructnd=letlab=nd#labelinletb=matchlabwith|L.PpSectionIf_|L.PpSectionIfdef_|L.PpSectionIfndef_|L.PpSectionElif_|L.PpSectionElse->beginquantifier(funn->label_is_xxx_part_constructn#label)nd#childrenend|L.PpBranch|L.PpBranchDo|L.PpBranchForall|L.PpBranchIf|L.PpBranchSelect|L.PpBranchWhere|L.PpBranchDerivedType|L.PpBranchEndDo|L.PpBranchEndForall|L.PpBranchEndIf|L.PpBranchEndSelect|L.PpBranchEndWhere|L.PpBranchEndType->beginquantifier(is_xxx_part_constructquantifierlabel_is_xxx_part_construct)nd#childrenend|_->label_is_xxx_part_constructlabin[%debug_log"%s -> %B"(L.to_stringlab)b];bletis_execution_part_construct=is_xxx_part_constructList.existsL.is_execution_part_constructletis_specification_part_construct=is_xxx_part_constructList.for_allL.is_specification_part_constructletchange_top_uop_into_bopnd=letchange_labeln=matchn#labelwith|L.IntrinsicOperatorop->beginmatchopwith|IntrinsicOperator.Id->n#relab(L.IntrinsicOperatorIntrinsicOperator.Add)|IntrinsicOperator.Neg->n#relab(L.IntrinsicOperatorIntrinsicOperator.Subt)|_->()end|_->()inletchange_sectionn=matchn#labelwith|L.PpSectionIf_|L.PpSectionIfdef_|L.PpSectionIfndef_|L.PpSectionElif_|L.PpSectionElse->beginList.iterchange_labeln#childrenend|_->()inmatchnd#labelwith|L.PpBranch->beginList.iterchange_sectionnd#childrenend|_->change_sectionndletty_of_nodenode=[%debug_log"%s"node#to_string];letlab=node#labelintryI.TypeSpec.of_labellabwithFailure_->lettys=Xset.create0inmatchlabwith|L.PpBranch|L.PpSectionIf_|L.PpSectionIfdef_|L.PpSectionIfndef_|L.PpSectionElif_|L.PpSectionElse->beginAst.visit(funnd->matchnd#labelwith|L.TypeSpec_->Xset.addtys(I.TypeSpec.of_labelnd#label)|_->())node;I.TypeSpec.PpBranchTypeSpec(Xset.to_listtys)end|_->failwith"Parser_aux.F.ty_of_node"letnode_to_locnd=nd#lloc#to_loc?cache:(Some(Someenv#fname_ext_cache))()letnode_to_lexpossnd=Loc.to_lexposs(node_to_locnd)end(* of functor Parser_aux.F *)]