12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990 |
- {
- $Id$
- Copyright (C) 1998-2000 by Daniel Mantione
- and other members of the Free Pascal development team
- This unit handles definitions
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ****************************************************************************
- }
- {$ifdef TP}
- {$N+,E+,F+}
- {$endif}
- unit defs;
- interface
- uses symtable,objects,{$IFDEF TP}xobjects,{$ENDIF}
- cobjects,symtablt,globtype
- {$ifdef i386}
- ,cpubase
- {$endif}
- {$ifdef m68k}
- ,m68k
- {$endif}
- {$ifdef alpha}
- ,alpha
- {$endif};
- type Targconvtyp=(act_convertable,act_equal,act_exact);
- Tvarspez=(vs_value,vs_const,vs_var);
- Tobjprop=(sp_public,sp_private,sp_protected,sp_published,sp_static);
- Tobjpropset=set of Tobjprop;
- Tobjoption=(oo_has_abstract, {The object/class has
- an abstract method => no
- instances can be created.}
- oo_is_class, {The object is a class.}
- oo_has_virtual, {The object/class has
- virtual methods.}
- oo_has_private, {The object has private members.}
- oo_has_protected, {The obejct has protected
- members.}
- oo_isforward, {The class is only a forward
- declared yet.}
- oo_can_have_published, {True, if the class has rtti, i.e.
- you can publish properties.}
- oo_has_constructor, {The object/class has a
- constructor.}
- oo_has_destructor, {The object/class has a
- destructor.}
- oo_has_vmt, {The object/class has a vmt.}
- oo_has_msgstr,
- oo_has_msgint,
- oo_cppvmt); {The object/class uses an C++
- compatible vmt, all members of
- the same class tree, must use
- then a C++ compatible vmt.}
- Tobjoptionset=set of Tobjoption;
- {Calling convention for tprocdef and Tprocvardef.}
- Tproccalloption=(pocall_none,
- pocall_clearstack, {Use IBM flat calling
- convention. (Used by GCC.)}
- pocall_leftright, {Push parameters from left to
- right.}
- pocall_cdecl, {Procedure uses C styled
- calling.}
- pocall_register, {Procedure uses register
- (fastcall) calling.}
- pocall_stdcall, {Procedure uses stdcall
- call.}
- pocall_safecall, {Safe call calling
- conventions.}
- pocall_palmossyscall, {Procedure is a PalmOS
- system call.}
- pocall_system,
- pocall_inline, {Procedure is an assembler
- macro.}
- pocall_internproc, {Procedure has compiler
- magic.}
- pocall_internconst); {Procedure has constant
- evaluator intern.}
- Tproccalloptionset=set of Tproccalloption;
- {Basic type for tprocdef and tprocvardef }
- Tproctypeoption=(potype_none,
- potype_proginit, {Program initialization.}
- potype_unitinit, {Unit initialization.}
- potype_unitfinalize, {Unit finalization.}
- potype_constructor, {Procedure is a constructor.}
- potype_destructor, {Procedure is a destructor.}
- potype_operator); {Procedure defines an
- operator.}
- {Other options for Tprocdef and Tprocvardef.}
- Tprocoption=(po_none,
- poclassmethod, {Class method.}
- povirtualmethod, {Procedure is a virtual method.}
- poabstractmethod, {Procedure is an abstract method.}
- postaticmethod, {Static method.}
- pooverridingmethod, {Method with override directive.}
- pomethodpointer, {Method pointer, only in procvardef, also used for 'with object do'.}
- pocontainsself, {Self is passed explicit to the compiler.}
- pointerrupt, {Procedure is an interrupt handler.}
- poiocheck, {IO checking should be done after a call to the procedure.}
- poassembler, {Procedure is written in assembler.}
- pomsgstr, {Method for string message handling.}
- pomsgint, {Method for int message handling.}
- poexports, {Procedure has export directive (needed for OS/2).}
- poexternal, {Procedure is external (in other object or lib).}
- posavestdregs, {Save std regs cdecl and stdcall need that !}
- posaveregisters); {Save all registers }
- Tprocoptionset=set of Tprocoption;
- Tarrayoption=(ap_variant,ap_constructor,ap_arrayofconst);
- Tarrayoptionset=set of Tarrayoption;
- Pparameter=^Tparameter;
- Tparameter=object(Tobject)
- data:Psym;
- paratyp:Tvarspez;
- argconvtyp:Targconvtyp;
- convertlevel:byte;
- register:Tregister;
- end;
- Tfiletype=(ft_text,ft_typed,ft_untyped);
- Pfiledef=^Tfiledef;
- Tfiledef=object(Tdef)
- filetype:Tfiletype;
- definition:Pdef;
- constructor init(Aowner:Pcontainingsymtable;
- ft:Tfiletype;tas:Pdef);
- constructor load(var s:Tstream);
- procedure deref;virtual;
- function gettypename:string;virtual;
- procedure setsize;
- {$ifdef GDB}
- function stabstring:Pchar;virtual;
- procedure concatstabto(asmlist:Paasmoutput);virtual;
- {$endif GDB}
- procedure store(var s:Tstream);virtual;
- end;
- Pformaldef=^Tformaldef;
- Tformaldef=object(Tdef)
- constructor init(Aowner:Pcontainingsymtable);
- constructor load(var s:Tstream);
- procedure store(var s:Tstream);virtual;
- {$ifdef GDB}
- function stabstring:Pchar;virtual;
- procedure concatstabto(asmlist:Paasmoutput);virtual;
- {$endif GDB}
- function gettypename:string;virtual;
- end;
- Perrordef=^Terrordef;
- Terrordef=object(Tdef)
- {$IFDEF TP}
- constructor init(Aowner:Pcontainingsymtable);
- {$ENDIF}
- {$ifdef GDB}
- function stabstring:Pchar;virtual;
- {$endif GDB}
- function gettypename:string;virtual;
- end;
- Pabstractpointerdef=^Tabstractpointerdef;
- Tabstractpointerdef=object(Tdef)
- definition:Pdef;
- defsym:Psym;
- constructor init(Aowner:Pcontainingsymtable;def:Pdef);
- constructor load(var s:Tstream);
- procedure deref;virtual;
- procedure store(var s:Tstream);virtual;
- {$ifdef GDB}
- function stabstring:Pchar;virtual;
- procedure concatstabto(asmlist:Paasmoutput);virtual;
- {$endif GDB}
- end;
- Ppointerdef=^Tpointerdef;
- Tpointerdef=object(Tabstractpointerdef)
- is_far:boolean;
- constructor initfar(Aowner:Pcontainingsymtable;def:Pdef);
- constructor load(var s:Tstream);
- procedure store(var s:Tstream);virtual;
- function gettypename:string;virtual;
- end;
- Pclassrefdef=^Tclassrefdef;
- Tclassrefdef=object(Tpointerdef)
- {$IFDEF TP}
- constructor init(Aowner:Pcontainingsymtable;def:Pdef);
- {$ENDIF TP}
- {$ifdef GDB}
- function stabstring : pchar;virtual;
- procedure concatstabto(asmlist : paasmoutput);virtual;
- {$endif GDB}
- function gettypename:string;virtual;
- end;
- Pobjectdef=^Tobjectdef;
- Tobjectdef=object(Tdef)
- childof:Pobjectdef;
- objname:Pstring;
- privatesyms,
- protectedsyms,
- publicsyms:Pobjectsymtable;
- options:Tobjoptionset;
- {To be able to have a variable vmt position
- and no vmt field for objects without virtuals }
- vmt_offset:longint;
- constructor init(const n:string;Aowner:Pcontainingsymtable;
- parent:Pobjectdef;isclass:boolean);
- constructor load(var s:Tstream);
- procedure check_forwards;
- procedure insertvmt;
- function is_related(d:Pobjectdef):boolean;
- function search(const s:string):Psym;
- function speedsearch(const s:string;
- speedvalue:longint):Psym;virtual;
- function size:longint;virtual;
- procedure store(var s:Tstream);virtual;
- function vmt_mangledname : string;
- function rtti_name : string;
- procedure set_parent(parent:Pobjectdef);
- {$ifdef GDB}
- function stabstring : pchar;virtual;
- {$endif GDB}
- procedure deref;virtual;
- function needs_inittable:boolean;virtual;
- procedure write_init_data;virtual;
- procedure write_child_init_data;virtual;
- {Rtti }
- function get_rtti_label:string;virtual;
- procedure generate_rtti;virtual;
- procedure write_rtti_data;virtual;
- procedure write_child_rtti_data;virtual;
- function next_free_name_index:longint;
- function is_publishable:boolean;virtual;
- destructor done;virtual;
- end;
- Parraydef=^Tarraydef;
- Tarraydef=object(Tdef)
- lowrange,
- highrange:Tconstant;
- definition:Pdef;
- rangedef:Pdef;
- options:Tarrayoptionset;
- constructor init(const l,h:Tconstant;rd:Pdef;
- Aowner:Pcontainingsymtable);
- constructor load(var s:Tstream);
- function elesize:longint;
- function gettypename:string;virtual;
- procedure store(var s:Tstream);virtual;
- {$ifdef GDB}
- function stabstring : pchar;virtual;
- procedure concatstabto(asmlist : paasmoutput);virtual;
- {$endif GDB}
- procedure deref;virtual;
- function size : longint;virtual;
- { generates the ranges needed by the asm instruction BOUND (i386)
- or CMP2 (Motorola) }
- procedure genrangecheck;
- { returns the label of the range check string }
- function getrangecheckstring : string;
- function needs_inittable : boolean;virtual;
- procedure write_rtti_data;virtual;
- procedure write_child_rtti_data;virtual;
- private
- rangenr:longint;
- end;
- Penumdef=^Tenumdef;
- Tenumdef=object(Tdef)
- rangenr,
- minval,
- maxval:longint;
- has_jumps:boolean;
- symbols:Pcollection;
- basedef:Penumdef;
- constructor init(Aowner:Pcontainingsymtable);
- constructor init_subrange(Abasedef:Penumdef;Amin,Amax:longint;
- Aowner:Pcontainingsymtable);
- constructor load(var s:Tstream);
- procedure deref;virtual;
- procedure calcsavesize;
- function getrangecheckstring:string;
- procedure genrangecheck;
- procedure setmax(Amax:longint);
- procedure setmin(Amin:longint);
- procedure store(var s:Tstream);virtual;
- {$ifdef GDB}
- function stabstring:Pchar;virtual;
- {$endif GDB}
- procedure write_child_rtti_data;virtual;
- procedure write_rtti_data;virtual;
- function is_publishable : boolean;virtual;
- function gettypename:string;virtual;
- end;
- Tbasetype=(uauto,uvoid,uchar,
- u8bit,u16bit,u32bit,
- s8bit,s16bit,s32bit,
- bool8bit,bool16bit,bool32bit,
- s64bit,u64bit,s64bitint,uwidechar);
- Porddef=^Torddef;
- Torddef=object(Tdef)
- low,high:Tconstant;
- rangenr:longint;
- typ:Tbasetype;
- constructor init(t:tbasetype;l,h:Tconstant;
- Aowner:Pcontainingsymtable);
- constructor load(var s:Tstream);
- procedure store(var s:Tstream);virtual;
- procedure setsize;
- { generates the ranges needed by the asm instruction BOUND }
- { or CMP2 (Motorola) }
- procedure genrangecheck;
- { returns the label of the range check string }
- function getrangecheckstring : string;
- procedure write_rtti_data;virtual;
- function is_publishable:boolean;virtual;
- function gettypename:string;virtual;
- {$ifdef GDB}
- function stabstring:Pchar;virtual;
- {$endif GDB}
- end;
- {S80real is dependant on the cpu, s64comp is also
- dependant on the size (tp = 80bit for both)
- The EXTENDED format exists on the motorola FPU
- but it uses 96 bits instead of 80, with some
- unused bits within the number itself! Pretty
- complicated to support, so no support for the
- moment.
- S64comp is considered as a real because all
- calculations are done by the fpu.}
- Tfloattype=(s32real,s64real,s80real,s64comp,f16bit,f32bit);
- Pfloatdef=^Tfloatdef;
- Tfloatdef=object(tdef)
- typ:Tfloattype;
- constructor init(t:Tfloattype;Aowner:Pcontainingsymtable);
- constructor load(var s:Tstream);
- function is_publishable : boolean;virtual;
- procedure setsize;
- {$ifdef GDB}
- function stabstring:Pchar;virtual;
- {$endif GDB}
- procedure store(var s:Tstream);virtual;
- procedure write_rtti_data;virtual;
- function gettypename:string;virtual;
- end;
- Tsettype=(normset,smallset,varset);
- Psetdef=^Tsetdef;
- Tsetdef=object(Tdef)
- definition:Pdef;
- settype:Tsettype;
- constructor init(s:Pdef;high:longint;Aowner:Pcontainingsymtable);
- constructor load(var s:Tstream);
- procedure store(var s:Tstream);virtual;
- {$ifdef GDB}
- function stabstring : pchar;virtual;
- procedure concatstabto(asmlist : paasmoutput);virtual;
- {$endif GDB}
- procedure deref;virtual;
- function is_publishable : boolean;virtual;
- procedure write_rtti_data;virtual;
- procedure write_child_rtti_data;virtual;
- function gettypename:string;virtual;
- end;
- Precorddef=^Trecorddef;
- Trecorddef=object(Tdef)
- symtable:Precordsymtable;
- constructor init(s:Precordsymtable;Aowner:Pcontainingsymtable);
- constructor load(var s:Tstream);
- procedure store(var s:Tstream);virtual;
- {$ifdef GDB}
- function stabstring : pchar;virtual;
- procedure concatstabto(asmlist : paasmoutput);virtual;
- {$endif GDB}
- procedure deref;virtual;
- function needs_inittable : boolean;virtual;
- procedure write_rtti_data;virtual;
- procedure write_init_data;virtual;
- procedure write_child_rtti_data;virtual;
- procedure write_child_init_data;virtual;
- function gettypename:string;virtual;
- destructor done;virtual;
- end;
- {String types}
- Tstringtype=(st_default,st_shortstring,st_longstring,
- st_ansistring,st_widestring);
- {This object needs to be splitted into multiple objects,
- one for each stringtype. This is because all code in this
- object is different for all string types.}
- Pstringdef=^Tstringdef;
- Tstringdef=object(Tdef)
- string_typ:Tstringtype;
- len:longint;
- constructor shortinit(l:byte;Aowner:Pcontainingsymtable);
- constructor shortload(var s:Tstream);
- constructor longinit(l:longint;Aowner:Pcontainingsymtable);
- constructor longload(var s:Tstream);
- constructor ansiinit(l:longint;Aowner:Pcontainingsymtable);
- constructor ansiload(var s:Tstream);
- constructor wideinit(l:longint;Aowner:Pcontainingsymtable);
- constructor wideload(var s:Tstream);
- function stringtypname:string;
- function size:longint;virtual;
- procedure store(var s:Tstream);virtual;
- function gettypename:string;virtual;
- function is_publishable : boolean;virtual;
- { debug }
- {$ifdef GDB}
- function stabstring:Pchar;virtual;
- procedure concatstabto(asmlist : Paasmoutput);virtual;
- {$endif GDB}
- { init/final }
- function needs_inittable : boolean;virtual;
- { rtti }
- procedure write_rtti_data;virtual;
- end;
- Pabstractprocdef=^Pabstractprocdef;
- Tabstractprocdef=object(Tdef)
- {Saves a definition to the return type }
- retdef:Pdef;
- fpu_used:byte; {How many stack fpu must be empty.}
- proctype:Tproctypeoption;
- options:Tprocoptionset; {Save the procedure options.}
- calloptions:Tproccalloptionset;
- parameters:Pcollection;
- constructor init(Aowner:Pcontainingsymtable);
- constructor load(var s:Tstream);
- destructor done;virtual;
- procedure deref;virtual;
- function demangled_paras:string;
- function para_size:longint;
- procedure store(var s:Tstream);virtual;
- procedure test_if_fpu_result;
- {$ifdef GDB}
- function stabstring : pchar;virtual;
- procedure concatstabto(asmlist : paasmoutput);virtual;
- {$endif GDB}
- end;
- Pprocvardef=^Tprocvardef;
- Tprocvardef=object(Tabstractprocdef)
- {$IFDEF TP}
- constructor init(Aowner:Pcontainingsymtable);
- {$ENDIF TP}
- function size:longint;virtual;
- {$ifdef GDB}
- function stabstring:Pchar;virtual;
- procedure concatstabto(asmlist:Paasmoutput); virtual;
- {$endif GDB}
- procedure write_child_rtti_data;virtual;
- function is_publishable:boolean;virtual;
- procedure write_rtti_data;virtual;
- function gettypename:string;virtual;
- end;
- {This datastructure is used to store the message information
- when a procedure is declared as:
- ;message 'str';
- ;message int;
- ;virtual int;
- }
- Tmessageinf=record
- case integer of
- 0:(str:Pchar);
- 1:(i:longint);
- end;
- {This object can be splitted into a Tprocdef, for normal procedures,
- a Tmethoddef for methods, and a Tinlinedprocdef and a
- Tinlinedmethoddef for inlined procedures.}
- Pprocdef = ^Tprocdef;
- Tprocdef = object(tabstractprocdef)
- objprop:Tobjpropset;
- extnumber:longint;
- messageinf:Tmessageinf;
- { where is this function defined, needed here because there
- is only one symbol for all overloaded functions }
- fileinfo:Tfileposinfo;
- { pointer to the local symbol table }
- localst:Pprocsymtable;
- _mangledname:Pstring;
- { it's a tree, but this not easy to handle }
- { used for inlined procs }
- code : pointer;
- { true, if the procedure is only declared }
- { (forward procedure) }
- references:Pcollection;
- forwarddef,
- { true if the procedure is declared in the interface }
- interfacedef : boolean;
- { check the problems of manglednames }
- count : boolean;
- is_used : boolean;
- { set which contains the modified registers }
- usedregisters:Tregisterset;
- constructor init(Aowner:Pcontainingsymtable);
- constructor load(var s:Tstream);
- procedure store(var s:Tstream);virtual;
- {$ifdef GDB}
- function cplusplusmangledname : string;
- function stabstring : pchar;virtual;
- procedure concatstabto(asmlist : paasmoutput);virtual;
- {$endif GDB}
- procedure deref;virtual;
- function mangledname:string;
- procedure setmangledname(const s:string);
- procedure load_references;
- function write_references:boolean;
- destructor done;virtual;
- end;
- Pforwarddef=^Tforwarddef;
- Tforwarddef=object(Tdef)
- tosymname:string;
- forwardpos:Tfileposinfo;
- constructor init(Aowner:Pcontainingsymtable;
- const s:string;const pos:Tfileposinfo);
- function gettypename:string;virtual;
- end;
- {Relevant options for assigning a proc or a procvar to a procvar.}
- const po_compatibility_options=[
- poclassmethod,
- postaticmethod,
- pomethodpointer,
- pocontainsself,
- pointerrupt,
- poiocheck,
- poexports
- ];
- var cformaldef:Pformaldef; {Unique formal definition.}
- voiddef:Porddef; {Pointer to void (procedure) type.}
- cchardef:Porddef; {Pointer to char type.}
- booldef:Porddef; {Pointer to boolean type.}
- u8bitdef:Porddef; {Pointer to 8-bit unsigned type.}
- u16bitdef:Porddef; {Pointer to 16-bit unsigned type.}
- u32bitdef:Porddef; {Pointer to 32-bit unsigned type.}
- s32bitdef:Porddef; {Pointer to 32-bit signed type.}
- cu64bitdef:Porddef; {Pointer to 64 bit unsigned def.}
- cs64bitdef:Porddef; {Pointer to 64 bit signed def.}
- voidpointerdef, {Pointer for Void-Pointerdef.}
- charpointerdef, {Pointer for Char-Pointerdef.}
- voidfarpointerdef:ppointerdef;
- s32floatdef : pfloatdef; {Pointer for realconstn.}
- s64floatdef : pfloatdef; {Pointer for realconstn.}
- s80floatdef : pfloatdef; {Pointer to type of temp. floats.}
- s32fixeddef : pfloatdef; {Pointer to type of temp. fixed.}
- cshortstringdef, {Pointer to type of short string const.}
- openshortstringdef, {Pointer to type of an openshortstring,
- needed for readln().}
- clongstringdef, {Pointer to type of long string const.}
- cansistringdef, {Pointer to type of ansi string const.}
- cwidestringdef:Pstringdef; {Pointer to type of wide string const.}
- openchararraydef:Parraydef; {Pointer to type of an open array of
- char, needed for readln().}
- cfiledef:Pfiledef; {Get the same definition for all files
- used for stabs.}
- implementation
- uses systems,symbols,verbose,globals,aasm,files,strings;
- const {If you change one of the following contants,
- you have also to change the typinfo unit
- and the rtl/i386,template/rttip.inc files.}
- tkunknown = 0;
- tkinteger = 1;
- tkchar = 2;
- tkenumeration = 3;
- tkfloat = 4;
- tkset = 5;
- tkmethod = 6;
- tksstring = 7;
- tkstring = tksstring;
- tklstring = 8;
- tkastring = 9;
- tkwstring = 10;
- tkvariant = 11;
- tkarray = 12;
- tkrecord = 13;
- tkinterface = 14;
- tkclass = 15;
- tkobject = 16;
- tkwchar = 17;
- tkbool = 18;
- otsbyte = 0;
- otubyte = 1;
- otsword = 2;
- otuword = 3;
- otslong = 4;
- otulong = 5;
- ftsingle = 0;
- ftdouble = 1;
- ftextended = 2;
- ftcomp = 3;
- ftcurr = 4;
- ftfixed16 = 5;
- ftfixed32 = 6;
- {****************************************************************************
- Tfiledef
- ****************************************************************************}
- constructor Tfiledef.init(Aowner:Pcontainingsymtable;ft:Tfiletype;tas:Pdef);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- filetype:=ft;
- definition:=tas;
- setsize;
- end;
- constructor Tfiledef.load(var s:Tstream);
- begin
- inherited load(s);
- { filetype:=tfiletype(readbyte);
- if filetype=ft_typed then
- typed_as:=readdefref
- else
- typed_as:=nil;}
- setsize;
- end;
- procedure Tfiledef.deref;
- begin
- { if filetype=ft_typed then
- resolvedef(typed_as);}
- end;
- procedure Tfiledef.setsize;
- begin
- case filetype of
- ft_text:
- savesize:=572;
- ft_typed,ft_untyped:
- savesize:=316;
- end;
- end;
- procedure Tfiledef.store(var s:Tstream);
- begin
- { inherited store(s);
- writebyte(byte(filetype));
- if filetype=ft_typed then
- writedefref(typed_as);
- current_ppu^.writeentry(ibfiledef);}
- end;
- function Tfiledef.gettypename : string;
- begin
- case filetype of
- ft_untyped:
- gettypename:='File';
- ft_typed:
- gettypename:='File Of '+definition^.typename;
- ft_text:
- gettypename:='Text'
- end;
- end;
- {****************************************************************************
- Tformaldef
- ****************************************************************************}
- {Tformaldef is used for var parameters without a type.}
- constructor Tformaldef.init(Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- savesize:=target_os.size_of_pointer;
- end;
- constructor Tformaldef.load(var s:Tstream);
- begin
- inherited load(s);
- savesize:=target_os.size_of_pointer;
- end;
- procedure Tformaldef.store(var s:Tstream);
- begin
- inherited store(s);
- { current_ppu^.writeentry(ibformaldef);}
- end;
- function Tformaldef.gettypename:string;
- begin
- gettypename:='Var';
- end;
- {****************************************************************************
- Terrordef
- ****************************************************************************}
- {$IFDEF TP}
- constructor Terrordef.init(Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- setparent(typeof(Tdef));
- end;
- {$ENDIF TP}
- function Terrordef.gettypename:string;
- begin
- gettypename:='<erroneous type>';
- end;
- {****************************************************************************
- Tabstractpointerdef
- ****************************************************************************}
- constructor Tabstractpointerdef.init(Aowner:Pcontainingsymtable;def:Pdef);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- include(properties,dp_ret_in_acc);
- definition:=def;
- savesize:=target_os.size_of_pointer;
- end;
- constructor Tabstractpointerdef.load(var s:Tstream);
- begin
- inherited load(s);
- (* {The real address in memory is calculated later (deref).}
- definition:=readdefref; *)
- savesize:=target_os.size_of_pointer;
- end;
- procedure Tabstractpointerdef.deref;
- begin
- { resolvedef(definition);}
- end;
- procedure Tabstractpointerdef.store(var s:Tstream);
- begin
- inherited store(s);
- { writedefref(definition);
- current_ppu^.writeentry(ibpointerdef);}
- end;
- {****************************************************************************
- Tpointerdef
- ****************************************************************************}
- constructor Tpointerdef.initfar(Aowner:Pcontainingsymtable;def:Pdef);
- begin
- inherited init(Aowner,def);
- {$IFDEF TP}setparent(typeof(Tabstractpointerdef));{$ENDIF}
- is_far:=true;
- end;
- constructor Tpointerdef.load(var s:Tstream);
- begin
- inherited load(s);
- { is_far:=(readbyte<>0);}
- end;
- function Tpointerdef.gettypename : string;
- begin
- gettypename:='^'+definition^.typename;
- end;
- procedure Tpointerdef.store(var s:Tstream);
- begin
- inherited store(s);
- { writebyte(byte(is_far));}
- end;
- {****************************************************************************
- Tclassrefdef
- ****************************************************************************}
- {$IFDEF TP}
- constructor Tclassrefdef.init(Aowner:Pcontainingsymtable;def:Pdef);
- begin
- inherited init(Aowner,def);
- setparent(typeof(Tpointerdef));
- end;
- {$ENDIF TP}
- function Tclassrefdef.gettypename:string;
- begin
- gettypename:='Class of '+definition^.typename;
- end;
- {***************************************************************************
- TOBJECTDEF
- ***************************************************************************}
- constructor Tobjectdef.init(const n:string;Aowner:Pcontainingsymtable;
- parent:Pobjectdef;isclass:boolean);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- new(publicsyms,init);
- publicsyms^.name:=stringdup(n);
- publicsyms^.defowner:=@self;
- set_parent(parent);
- objname:=stringdup(n);
- if isclass then
- begin
- include(properties,dp_ret_in_acc);
- include(options,oo_is_class);
- end;
- end;
- procedure tobjectdef.set_parent(parent:Pobjectdef);
- const inherited_options=[oo_has_virtual,oo_has_private,oo_has_protected,
- oo_has_constructor,oo_has_destructor];
- begin
- {Nothing to do if the parent was not forward !}
- if childof=nil then
- begin
- childof:=parent;
- {Some options are inherited...}
- if parent<>nil then
- begin
- options:=options+parent^.options*inherited_options;
- {Add the data of the anchestor class.}
- inc(publicsyms^.datasize,parent^.publicsyms^.datasize);
- if parent^.privatesyms<>nil then
- begin
- if privatesyms=nil then
- new(privatesyms,init);
- inc(privatesyms^.datasize,
- parent^.privatesyms^.datasize);
- end;
- if parent^.protectedsyms<>nil then
- begin
- if protectedsyms<>nil then
- new(protectedsyms,init);
- inc(protectedsyms^.datasize,
- parent^.protectedsyms^.datasize);
- end;
- if oo_has_vmt in (options*parent^.options) then
- publicsyms^.datasize:=publicsyms^.datasize-
- target_os.size_of_pointer;
- {If parent has a vmt field then
- the offset is the same for the child PM }
- if [oo_has_vmt,oo_is_class]*parent^.options<>[] then
- begin
- vmt_offset:=parent^.vmt_offset;
- include(options,oo_has_vmt);
- end;
- end;
- savesize:=publicsyms^.datasize;
- end;
- end;
- constructor Tobjectdef.load(var s:Tstream);
- var oldread_member:boolean;
- begin
- inherited load(s);
- (* savesize:=readlong;
- vmt_offset:=readlong;
- objname:=stringdup(readstring);
- childof:=pobjectdef(readdefref);
- options:=readlong;
- oldread_member:=read_member;
- read_member:=true;
- publicsyms:=new(psymtable,loadas(objectsymtable));
- read_member:=oldread_member;
- publicsyms^.defowner:=@self;
- { publicsyms^.datasize:=savesize; }
- publicsyms^.name := stringdup(objname^);
- { handles the predefined class tobject }
- { the last TOBJECT which is loaded gets }
- { it ! }
- if (objname^='TOBJECT') and
- isclass and (childof=nil) then
- class_tobject:=@self;
- has_rtti:=true;*)
- end;
- procedure Tobjectdef.insertvmt;
- begin
- if oo_has_vmt in options then
- internalerror($990803)
- else
- begin
- {First round up to aktpakrecords.}
- publicsyms^.datasize:=align(publicsyms^.datasize,
- packrecordalignment[aktpackrecords]);
- vmt_offset:=publicsyms^.datasize;
- publicsyms^.datasize:=publicsyms^.datasize+
- target_os.size_of_pointer;
- include(options,oo_has_vmt);
- end;
- end;
- procedure Tobjectdef.check_forwards;
- begin
- publicsyms^.check_forwards;
- if oo_isforward in options then
- begin
- { ok, in future, the forward can be resolved }
- message1(sym_e_class_forward_not_resolved,objname^);
- exclude(options,oo_isforward);
- end;
- end;
- { true, if self inherits from d (or if they are equal) }
- function Tobjectdef.is_related(d:Pobjectdef):boolean;
- var hp:Pobjectdef;
- begin
- hp:=@self;
- is_related:=false;
- while assigned(hp) do
- begin
- if hp=d then
- begin
- is_related:=true;
- break;
- end;
- hp:=hp^.childof;
- end;
- end;
- function Tobjectdef.search(const s:string):Psym;
- begin
- search:=speedsearch(s,getspeedvalue(s));
- end;
- function Tobjectdef.speedsearch(const s:string;speedvalue:longint):Psym;
- var r:Psym;
- begin
- r:=publicsyms^.speedsearch(s,speedvalue);
- {Privatesyms should be set to nil after compilation of the unit.
- This way, private syms are not found by objects in other units.}
- if (r=nil) and (privatesyms<>nil) then
- r:=privatesyms^.speedsearch(s,speedvalue);
- if (r=nil) and (protectedsyms<>nil) then
- r:=protectedsyms^.speedsearch(s,speedvalue);
- end;
- function Tobjectdef.size:longint;
- begin
- if oo_is_class in options then
- size:=target_os.size_of_pointer
- else
- size:=publicsyms^.datasize;
- end;
- procedure tobjectdef.deref;
- var oldrecsyms:Psymtable;
- begin
- { resolvedef(pdef(childof));
- oldrecsyms:=aktrecordsymtable;
- aktrecordsymtable:=publicsyms;
- publicsyms^.deref;
- aktrecordsymtable:=oldrecsyms;}
- end;
- function Tobjectdef.vmt_mangledname:string;
- begin
- if oo_has_vmt in options then
- message1(parser_object_has_no_vmt,objname^);
- vmt_mangledname:='VMT_'+owner^.name^+'$_'+objname^;
- end;
- function Tobjectdef.rtti_name:string;
- begin
- rtti_name:='RTTI_'+owner^.name^+'$_'+objname^;
- end;
- procedure Tobjectdef.store(var s:Tstream);
- var oldread_member:boolean;
- begin
- inherited store(s);
- (* writelong(size);
- writelong(vmt_offset);
- writestring(objname^);
- writedefref(childof);
- writelong(options);
- current_ppu^.writeentry(ibobjectdef);
- oldread_member:=read_member;
- read_member:=true;
- publicsyms^.writeas;
- read_member:=oldread_member;*)
- end;
- procedure tobjectdef.write_child_init_data;
- begin
- end;
- procedure Tobjectdef.write_init_data;
- var b:byte;
- begin
- if oo_is_class in options then
- b:=tkclass
- else
- b:=tkobject;
- rttilist^.concat(new(Pai_const,init_8bit(b)));
- { generate the name }
- rttilist^.concat(new(Pai_const,init_8bit(length(objname^))));
- rttilist^.concat(new(Pai_string,init(objname^)));
- (* rttilist^.concat(new(Pai_const,init_32bit(size)));
- publicsyms^.foreach({$ifndef TP}@{$endif}count_inittable_fields);
- rttilist^.concat(new(Pai_const,init_32bit(count)));
- publicsyms^.foreach({$ifndef TP}@{$endif}write_field_inittable);*)
- end;
- function Tobjectdef.needs_inittable:boolean;
- var oldb:boolean;
- begin
- { there are recursive calls to needs_inittable possible, }
- { so we have to change to old value how else should }
- { we do that ? check_rec_rtti can't be a nested }
- { procedure of needs_rtti ! }
- (* oldb:=binittable;
- binittable:=false;
- publicsyms^.foreach({$ifndef TP}@{$endif}check_rec_inittable);
- needs_inittable:=binittable;
- binittable:=oldb;*)
- end;
- destructor Tobjectdef.done;
- begin
- if publicsyms<>nil then
- dispose(publicsyms,done);
- if privatesyms<>nil then
- dispose(privatesyms,done);
- if protectedsyms<>nil then
- dispose(protectedsyms,done);
- if oo_isforward in options then
- message1(sym_e_class_forward_not_resolved,objname^);
- stringdispose(objname);
- inherited done;
- end;
- var count:longint;
- procedure count_published_properties(sym:Pnamedindexobject);
- {$ifndef fpc}far;{$endif}
- begin
- if (typeof(sym^)=typeof(Tpropertysym)) and
- (ppo_published in Ppropertysym(sym)^.properties) then
- inc(count);
- end;
- procedure write_property_info(sym:Pnamedindexobject);{$ifndef fpc}far;{$endif}
- var proctypesinfo : byte;
- procedure writeproc(sym:Psym;def:Pdef;shiftvalue:byte);
- var typvalue:byte;
- begin
- if not(assigned(sym)) then
- begin
- rttilist^.concat(new(pai_const,init_32bit(1)));
- typvalue:=3;
- end
- else if typeof(sym^)=typeof(Tvarsym) then
- begin
- rttilist^.concat(new(pai_const,init_32bit(
- Pvarsym(sym)^.address)));
- typvalue:=0;
- end
- else
- begin
- (* if (pprocdef(def)^.options and povirtualmethod)=0 then
- begin
- rttilist^.concat(new(pai_const_symbol,initname(pprocdef(def)^.mangledname)));
- typvalue:=1;
- end
- else
- begin
- {Virtual method, write vmt offset.}
- rttilist^.concat(new(pai_const,
- init_32bit(Pprocdef(def)^.extnumber*4+12)));
- typvalue:=2;
- end;*)
- end;
- proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
- end;
- begin
- if (typeof(sym^)=typeof(Tpropertysym)) and
- (ppo_indexed in Ppropertysym(sym)^.properties) then
- proctypesinfo:=$40
- else
- proctypesinfo:=0;
- if (typeof(sym^)=typeof(Tpropertysym)) and
- (ppo_published in Ppropertysym(sym)^.properties) then
- begin
- rttilist^.concat(new(pai_const_symbol,initname(
- Ppropertysym(sym)^.definition^.get_rtti_label)));
- writeproc(Ppropertysym(sym)^.readaccesssym,ppropertysym(sym)^.readaccessdef,0);
- writeproc(Ppropertysym(sym)^.writeaccesssym,ppropertysym(sym)^.writeaccessdef,2);
- { isn't it stored ? }
- if (ppo_stored in Ppropertysym(sym)^.properties) then
- begin
- rttilist^.concat(new(pai_const,init_32bit(1)));
- proctypesinfo:=proctypesinfo or (3 shl 4);
- end
- else
- writeproc(ppropertysym(sym)^.storedsym,ppropertysym(sym)^.storeddef,4);
- rttilist^.concat(new(pai_const,
- init_32bit(ppropertysym(sym)^.index)));
- rttilist^.concat(new(pai_const,
- init_32bit(ppropertysym(sym)^.default)));
- rttilist^.concat(new(pai_const,
- init_16bit(count)));
- inc(count);
- rttilist^.concat(new(pai_const,init_8bit(proctypesinfo)));
- rttilist^.concat(new(pai_const,
- init_8bit(length(ppropertysym(sym)^.name))));
- rttilist^.concat(new(pai_string,init(ppropertysym(sym)^.name)));
- end;
- end;
- procedure generate_published_child_rtti(sym:Pnamedindexobject);
- {$ifndef fpc}far;{$endif}
- begin
- if (typeof(sym^)=typeof(Tpropertysym)) and
- (ppo_published in Ppropertysym(sym)^.properties) then
- Ppropertysym(sym)^.definition^.get_rtti_label;
- end;
- procedure tobjectdef.write_child_rtti_data;
- begin
- publicsyms^.foreach({$ifndef TP}@{$endif}generate_published_child_rtti);
- end;
- procedure Tobjectdef.generate_rtti;
- begin
- { getdatalabel(rtti_label);
- write_child_rtti_data;
- rttilist^.concat(new(pai_symbol,initname_global(rtti_name)));
- rttilist^.concat(new(pai_label,init(rtti_label)));
- write_rtti_data;}
- end;
- function Tobjectdef.next_free_name_index : longint;
- var i:longint;
- begin
- if (childof<>nil) and (oo_can_have_published in childof^.options) then
- i:=childof^.next_free_name_index
- else
- i:=0;
- count:=0;
- publicsyms^.foreach({$ifndef TP}@{$endif}count_published_properties);
- next_free_name_index:=i+count;
- end;
- procedure tobjectdef.write_rtti_data;
- begin
- if oo_is_class in options then
- rttilist^.concat(new(pai_const,init_8bit(tkclass)))
- else
- rttilist^.concat(new(pai_const,init_8bit(tkobject)));
- {Generate the name }
- rttilist^.concat(new(pai_const,init_8bit(length(objname^))));
- rttilist^.concat(new(pai_string,init(objname^)));
- {Write class type }
- rttilist^.concat(new(pai_const_symbol,initname(vmt_mangledname)));
- { write owner typeinfo }
- if (childof<>nil) and (oo_can_have_published in childof^.options) then
- rttilist^.concat(new(pai_const_symbol,
- initname(childof^.get_rtti_label)))
- else
- rttilist^.concat(new(pai_const,init_32bit(0)));
- {Count total number of properties }
- if (childof<>nil) and (oo_can_have_published in childof^.options) then
- count:=childof^.next_free_name_index
- else
- count:=0;
- {Write it>}
- publicsyms^.foreach({$ifndef TP}@{$endif}count_published_properties);
- rttilist^.concat(new(Pai_const,init_16bit(count)));
- { write unit name }
- if owner^.name<>nil then
- begin
- rttilist^.concat(new(Pai_const,init_8bit(length(owner^.name^))));
- rttilist^.concat(new(Pai_string,init(owner^.name^)));
- end
- else
- rttilist^.concat(new(Pai_const,init_8bit(0)));
- { write published properties count }
- count:=0;
- publicsyms^.foreach({$ifndef TP}@{$endif}count_published_properties);
- rttilist^.concat(new(pai_const,init_16bit(count)));
- { count is used to write nameindex }
- { but we need an offset of the owner }
- { to give each property an own slot }
- if (childof<>nil) and (oo_can_have_published in childof^.options) then
- count:=childof^.next_free_name_index
- else
- count:=0;
- publicsyms^.foreach({$ifndef TP}@{$endif}write_property_info);
- end;
- function Tobjectdef.is_publishable:boolean;
- begin
- is_publishable:=oo_is_class in options;
- end;
- function Tobjectdef.get_rtti_label:string;
- begin
- get_rtti_label:=rtti_name;
- end;
- {***************************************************************************
- TARRAYDEF
- ***************************************************************************}
- constructor Tarraydef.init(const l,h:Tconstant;rd:Pdef;
- Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- lowrange:=l;
- highrange:=h;
- rangedef:=rd;
- end;
- constructor Tarraydef.load(var s:Tstream);
- begin
- inherited load(s);
- (* deftype:=arraydef;
- { the addresses are calculated later }
- definition:=readdefref;
- rangedef:=readdefref;
- lowrange:=readlong;
- highrange:=readlong;
- IsArrayOfConst:=boolean(readbyte);*)
- end;
- function Tarraydef.getrangecheckstring:string;
- begin
- if (cs_create_smart in aktmoduleswitches) then
- getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
- else
- getrangecheckstring:='R_'+tostr(rangenr);
- end;
- procedure Tarraydef.genrangecheck;
- begin
- if rangenr=0 then
- begin
- {Generates the data for range checking }
- getlabelnr(rangenr);
- if (cs_create_smart in aktmoduleswitches) then
- datasegment^.concat(new(pai_symbol,
- initname_global(getrangecheckstring,10)))
- else
- datasegment^.concat(new(pai_symbol,
- initname(getrangecheckstring,10)));
- datasegment^.concat(new(Pai_const,
- init_8bit(byte(lowrange.signed))));
- datasegment^.concat(new(Pai_const,
- init_32bit(lowrange.values)));
- datasegment^.concat(new(Pai_const,
- init_8bit(byte(highrange.signed))));
- datasegment^.concat(new(Pai_const,
- init_32bit(highrange.values)));
- end;
- end;
- procedure Tarraydef.deref;
- begin
- { resolvedef(definition);
- resolvedef(rangedef);}
- end;
- procedure Tarraydef.store(var s:Tstream);
- begin
- inherited store(s);
- (* writedefref(definition);
- writedefref(rangedef);
- writelong(lowrange);
- writelong(highrange);
- writebyte(byte(IsArrayOfConst));
- current_ppu^.writeentry(ibarraydef);*)
- end;
- function Tarraydef.elesize:longint;
- begin
- elesize:=definition^.size;
- end;
- function Tarraydef.size:longint;
- begin
- if (lowrange.signed) and (lowrange.values=-1) then
- internalerror($990804);
- if highrange.signed then
- begin
- {Check for overflow.}
- if (highrange.values-lowrange.values=$7fffffff) or
- (($7fffffff div elesize+elesize-1)>
- (highrange.values-lowrange.values)) then
- begin
- { message(sym_segment_too_large);}
- size:=1;
- end
- else
- size:=(highrange.values-lowrange.values+1)*elesize;
- end
- else
- begin
- {Check for overflow.}
- if (highrange.valueu-lowrange.valueu=$7fffffff) or
- (($7fffffff div elesize+elesize-1)>
- (highrange.valueu-lowrange.valueu)) then
- begin
- { message(sym_segment_too_small);}
- size:=1;
- end
- else
- size:=(highrange.valueu-lowrange.valueu+1)*elesize;
- end;
- end;
- function Tarraydef.needs_inittable:boolean;
- begin
- needs_inittable:=definition^.needs_inittable;
- end;
- procedure Tarraydef.write_child_rtti_data;
- begin
- definition^.get_rtti_label;
- end;
- procedure tarraydef.write_rtti_data;
- begin
- rttilist^.concat(new(Pai_const,init_8bit(13)));
- write_rtti_name;
- { size of elements }
- rttilist^.concat(new(Pai_const,init_32bit(definition^.size)));
- { count of elements }
- rttilist^.concat(new(Pai_const,
- init_32bit(highrange.values-lowrange.values+1)));
- { element type }
- rttilist^.concat(new(Pai_const_symbol,
- initname(definition^.get_rtti_label)));
- end;
- function Tarraydef.gettypename:string;
- var r:string;
- begin
- if [ap_arrayofconst,ap_constructor]*options<>[] then
- gettypename:='array of const'
- else if (lowrange.signed) and (lowrange.values=-1) then
- gettypename:='Array Of '+definition^.typename
- else
- begin
- r:='array[$1..$2 Of $3]';
- if typeof(rangedef^)=typeof(Tenumdef) then
- with Penumdef(rangedef)^.symbols^ do
- begin
- replace(r,'$1',Penumsym(at(0))^.name);
- replace(r,'$2',Penumsym(at(count-1))^.name);
- end
- else
- begin
- if lowrange.signed then
- replace(r,'$1',tostr(lowrange.values))
- else
- replace(r,'$1',tostru(lowrange.valueu));
- if highrange.signed then
- replace(r,'$2',tostr(highrange.values))
- else
- replace(r,'$2',tostr(highrange.valueu));
- replace(r,'$3',definition^.typename);
- end;
- gettypename:=r;
- end;
- end;
- {****************************************************************************
- Tenumdef
- ****************************************************************************}
- constructor Tenumdef.init(Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- include(properties,dp_ret_in_acc);
- new(symbols,init(8,8));
- calcsavesize;
- end;
- constructor Tenumdef.init_subrange(Abasedef:Penumdef;Amin,Amax:longint;
- Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- minval:=Amin;
- maxval:=Amax;
- basedef:=Abasedef;
- symbols:=Abasedef^.symbols;
- calcsavesize;
- end;
- constructor Tenumdef.load(var s:Tstream);
- begin
- inherited load(s);
- (* basedef:=penumdef(readdefref);
- minval:=readlong;
- maxval:=readlong;
- savesize:=readlong;*)
- end;
- procedure Tenumdef.calcsavesize;
- begin
- if (aktpackenum=4) or (minval<0) or (maxval>65535) then
- savesize:=4
- else if (aktpackenum=2) or (minval<0) or (maxval>255) then
- savesize:=2
- else
- savesize:=1;
- end;
- procedure Tenumdef.setmax(Amax:longint);
- begin
- maxval:=Amax;
- calcsavesize;
- end;
- procedure Tenumdef.setmin(Amin:longint);
- begin
- minval:=Amin;
- calcsavesize;
- end;
- procedure tenumdef.deref;
- begin
- { resolvedef(pdef(basedef));}
- end;
- procedure Tenumdef.store(var s:Tstream);
- begin
- inherited store(s);
- (* writedefref(basedef);
- writelong(min);
- writelong(max);
- writelong(savesize);
- current_ppu^.writeentry(ibenumdef);*)
- end;
- function tenumdef.getrangecheckstring : string;
- begin
- if (cs_create_smart in aktmoduleswitches) then
- getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
- else
- getrangecheckstring:='R_'+tostr(rangenr);
- end;
- procedure tenumdef.genrangecheck;
- begin
- if rangenr=0 then
- begin
- { generate two constant for bounds }
- getlabelnr(rangenr);
- if (cs_create_smart in aktmoduleswitches) then
- datasegment^.concat(new(Pai_symbol,
- initname_global(getrangecheckstring,8)))
- else
- datasegment^.concat(new(Pai_symbol,
- initname(getrangecheckstring,8)));
- datasegment^.concat(new(pai_const,init_32bit(minval)));
- datasegment^.concat(new(pai_const,init_32bit(maxval)));
- end;
- end;
- procedure Tenumdef.write_child_rtti_data;
- begin
- if assigned(basedef) then
- basedef^.get_rtti_label;
- end;
- procedure Tenumdef.write_rtti_data;
- var i:word;
- begin
- rttilist^.concat(new(pai_const,init_8bit(tkEnumeration)));
- write_rtti_name;
- case savesize of
- 1:
- rttilist^.concat(new(Pai_const,init_8bit(otUByte)));
- 2:
- rttilist^.concat(new(Pai_const,init_8bit(otUWord)));
- 4:
- rttilist^.concat(new(Pai_const,init_8bit(otULong)));
- end;
- rttilist^.concat(new(pai_const,init_32bit(minval)));
- rttilist^.concat(new(pai_const,init_32bit(maxval)));
- if assigned(basedef) then
- rttilist^.concat(new(pai_const_symbol,initname(basedef^.get_rtti_label)))
- else
- rttilist^.concat(new(pai_const,init_32bit(0)));
- for i:=0 to symbols^.count-1 do
- begin
- rttilist^.concat(new(Pai_const,
- init_8bit(length(Penumsym(symbols^.at(i))^.name))));
- rttilist^.concat(new(Pai_string,
- init(globals.lower(Penumsym(symbols^.at(i))^.name))));
- end;
- rttilist^.concat(new(pai_const,init_8bit(0)));
- end;
- function Tenumdef.is_publishable:boolean;
- begin
- is_publishable:=true;
- end;
- function Tenumdef.gettypename:string;
- var i:word;
- v:longint;
- r:string;
- begin
- r:='(';
- for i:=0 to symbols^.count-1 do
- begin
- v:=Penumsym(symbols^.at(i))^.value;
- if (v>=minval) and (v<=maxval) then
- r:=r+Penumsym(symbols^.at(i))^.name+',';
- end;
- {Turn ',' into ')'.}
- r[length(r)]:=')';
- end;
- {****************************************************************************
- Torddef
- ****************************************************************************}
- constructor Torddef.init(t:Tbasetype;l,h:Tconstant;
- Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- include(properties,dp_ret_in_acc);
- low:=l;
- high:=h;
- typ:=t;
- setsize;
- end;
- constructor Torddef.load(var s:Tstream);
- begin
- inherited load(s);
- (* typ:=tbasetype(readbyte);
- low:=readlong;
- high:=readlong;*)
- setsize;
- end;
- procedure Torddef.setsize;
- begin
- if typ=uauto then
- begin
- {Generate a unsigned range if high<0 and low>=0 }
- if (low.values>=0) and (high.values<=255) then
- typ:=u8bit
- else if (low.signed) and (low.values>=-128) and (high.values<=127) then
- typ:=s8bit
- else if (low.values>=0) and (high.values<=65536) then
- typ:=u16bit
- else if (low.signed) and (low.values>=-32768) and (high.values<=32767) then
- typ:=s16bit
- else if low.signed then
- typ:=s32bit
- else
- typ:=u32bit
- end;
- case typ of
- u8bit,s8bit,uchar,bool8bit:
- savesize:=1;
- u16bit,s16bit,bool16bit:
- savesize:=2;
- s32bit,u32bit,bool32bit:
- savesize:=4;
- u64bit,s64bitint:
- savesize:=8;
- else
- savesize:=0;
- end;
- rangenr:=0;
- end;
- function Torddef.getrangecheckstring:string;
- begin
- if (cs_create_smart in aktmoduleswitches) then
- getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
- else
- getrangecheckstring:='R_'+tostr(rangenr);
- end;
- procedure Torddef.genrangecheck;
- begin
- if rangenr=0 then
- begin
- {Generate two constant for bounds.}
- getlabelnr(rangenr);
- if (cs_create_smart in aktmoduleswitches) then
- datasegment^.concat(new(Pai_symbol,
- initname_global(getrangecheckstring,10)))
- else
- datasegment^.concat(new(Pai_symbol,
- initname(getrangecheckstring,10)));
- datasegment^.concat(new(Pai_const,init_8bit(byte(low.signed))));
- datasegment^.concat(new(Pai_const,init_32bit(low.values)));
- datasegment^.concat(new(Pai_const,init_8bit(byte(high.signed))));
- datasegment^.concat(new(Pai_const,init_32bit(high.values)));
- end;
- end;
- procedure Torddef.store(var s:Tstream);
- begin
- inherited store(s);
- (* writebyte(byte(typ));
- writelong(low);
- writelong(high);
- current_ppu^.writeentry(iborddef);*)
- end;
- procedure Torddef.write_rtti_data;
- const trans:array[uchar..bool8bit] of byte=
- (otubyte,otubyte,otuword,otulong,
- otsbyte,otsword,otslong,otubyte);
- begin
- case typ of
- bool8bit:
- rttilist^.concat(new(Pai_const,init_8bit(tkbool)));
- uchar:
- rttilist^.concat(new(Pai_const,init_8bit(tkchar)));
- else
- rttilist^.concat(new(Pai_const,init_8bit(tkinteger)));
- end;
- write_rtti_name;
- rttilist^.concat(new(Pai_const,init_8bit(byte(trans[typ]))));
- rttilist^.concat(new(Pai_const,init_32bit(low.values)));
- rttilist^.concat(new(Pai_const,init_32bit(high.values)));
- end;
- function Torddef.is_publishable:boolean;
- begin
- is_publishable:=typ in [uchar..bool8bit];
- end;
- function Torddef.gettypename:string;
- const names:array[Tbasetype] of string[20]=('<unknown type>',
- 'untyped','char','byte','word','dword','shortInt',
- 'smallint','longInt','boolean','wordbool',
- 'longbool','qword','int64','card64','widechar');
- begin
- gettypename:=names[typ];
- end;
- {****************************************************************************
- Tfloatdef
- ****************************************************************************}
- constructor Tfloatdef.init(t:Tfloattype;Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- if t=f32bit then
- include(properties,dp_ret_in_acc);
- typ:=t;
- setsize;
- end;
- constructor Tfloatdef.load(var s:Tstream);
- begin
- inherited load(s);
- (* typ:=Tfloattype(readbyte);*)
- setsize;
- end;
- procedure tfloatdef.setsize;
- begin
- case typ of
- f16bit:
- savesize:=2;
- f32bit,
- s32real:
- savesize:=4;
- s64real:
- savesize:=8;
- s80real:
- savesize:=extended_size;
- s64comp:
- savesize:=8;
- else
- savesize:=0;
- end;
- end;
- procedure Tfloatdef.store(var s:Tstream);
- begin
- inherited store(s);
- (* writebyte(byte(typ));
- current_ppu^.writeentry(ibfloatdef);*)
- end;
- procedure Tfloatdef.write_rtti_data;
- const translate:array[Tfloattype] of byte=
- (ftsingle,ftdouble,ftextended,ftcomp,ftfixed16,ftfixed32);
- begin
- rttilist^.concat(new(Pai_const,init_8bit(tkfloat)));
- write_rtti_name;
- rttilist^.concat(new(Pai_const,init_8bit(translate[typ])));
- end;
- function Tfloatdef.is_publishable:boolean;
- begin
- is_publishable:=true;
- end;
- function Tfloatdef.gettypename:string;
- const names:array[Tfloattype] of string[20]=(
- 'single','double','extended','comp','fixed','shortfixed');
- begin
- gettypename:=names[typ];
- end;
- {***************************************************************************
- Tsetdef
- ***************************************************************************}
- { For i386 smallsets work,
- for m68k there are problems
- can be test by compiling with -dusesmallset PM }
- {$ifdef i386}
- {$define usesmallset}
- {$endif i386}
- constructor Tsetdef.init(s:Pdef;high:longint;Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- definition:=s;
- if high<32 then
- begin
- settype:=smallset;
- savesize:=4;
- include(properties,dp_ret_in_acc);
- end
- else if high<256 then
- begin
- settype:=normset;
- savesize:=32;
- end
- {$ifdef testvarsets}
- else if high<$10000 then
- begin
- settype:=varset;
- savesize:=4*((high+31) div 32);
- end
- {$endif testvarsets}
- else
- message(sym_e_ill_type_decl_set);
- end;
- constructor Tsetdef.load(var s:Tstream);
- begin
- inherited load(s);
- (* setof:=readdefref;
- settype:=tsettype(readbyte);
- case settype of
- normset:
- savesize:=32;
- varset:
- savesize:=readlong;
- smallset:
- savesize:=sizeof(longint);
- end;*)
- end;
- procedure Tsetdef.store(var s:Tstream);
- begin
- inherited store(s);
- (* writedefref(setof);
- writebyte(byte(settype));
- if settype=varset then
- writelong(savesize);
- current_ppu^.writeentry(ibsetdef);*)
- end;
- procedure Tsetdef.deref;
- begin
- { resolvedef(setof);}
- end;
- procedure Tsetdef.write_rtti_data;
- begin
- rttilist^.concat(new(pai_const,init_8bit(tkset)));
- write_rtti_name;
- rttilist^.concat(new(pai_const,init_8bit(otuLong)));
- rttilist^.concat(new(pai_const_symbol,initname(definition^.get_rtti_label)));
- end;
- procedure Tsetdef.write_child_rtti_data;
- begin
- definition^.get_rtti_label;
- end;
- function Tsetdef.is_publishable:boolean;
- begin
- is_publishable:=settype=smallset;
- end;
- function Tsetdef.gettypename:string;
- begin
- gettypename:='set of '+definition^.typename;
- end;
- {***************************************************************************
- Trecorddef
- ***************************************************************************}
- constructor Trecorddef.init(s:Precordsymtable;Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- symtable:=s;
- savesize:=symtable^.datasize;
- end;
- constructor Trecorddef.load(var s:Tstream);
- var oldread_member:boolean;
- begin
- (* inherited load(s);
- savesize:=readlong;
- oldread_member:=read_member;
- read_member:=true;
- symtable:=new(psymtable,loadas(recordsymtable));
- read_member:=oldread_member;
- symtable^.defowner := @self;*)
- end;
- destructor Trecorddef.done;
- begin
- if symtable<>nil then
- dispose(symtable,done);
- inherited done;
- end;
- var
- binittable : boolean;
- procedure check_rec_inittable(s:Pnamedindexobject);
- begin
- if (typeof(s^)=typeof(Tvarsym)) and
- ((typeof((Pvarsym(s)^.definition^))<>typeof(Tobjectdef)) or
- not (oo_is_class in Pobjectdef(Pvarsym(s)^.definition)^.options)) then
- binittable:=pvarsym(s)^.definition^.needs_inittable;
- end;
- function Trecorddef.needs_inittable:boolean;
- var oldb:boolean;
- begin
- { there are recursive calls to needs_rtti possible, }
- { so we have to change to old value how else should }
- { we do that ? check_rec_rtti can't be a nested }
- { procedure of needs_rtti ! }
- oldb:=binittable;
- binittable:=false;
- symtable^.foreach({$ifndef TP}@{$endif}check_rec_inittable);
- needs_inittable:=binittable;
- binittable:=oldb;
- end;
- procedure Trecorddef.deref;
- var oldrecsyms:Psymtable;
- begin
- (* oldrecsyms:=aktrecordsymtable;
- aktrecordsymtable:=symtable;
- { now dereference the definitions }
- symtable^.deref;
- aktrecordsymtable:=oldrecsyms;*)
- end;
- procedure Trecorddef.store(var s:Tstream);
- var oldread_member:boolean;
- begin
- (* oldread_member:=read_member;
- read_member:=true;
- inherited store(s);
- writelong(savesize);
- current_ppu^.writeentry(ibrecorddef);
- self.symtable^.writeas;
- read_member:=oldread_member;*)
- end;
- procedure count_inittable_fields(sym:Pnamedindexobject);
- {$ifndef fpc}far;{$endif}
- begin
- if (typeof(sym^)=typeof(Tvarsym)) and
- (Pvarsym(sym)^.definition^.needs_inittable) then
- inc(count);
- end;
- procedure count_fields(sym:Pnamedindexobject);{$ifndef fpc}far;{$endif}
- begin
- inc(count);
- end;
- procedure write_field_inittable(sym:Pnamedindexobject);
- {$ifndef fpc}far;{$endif}
- begin
- if (typeof(sym^)=typeof(Tvarsym)) and
- Pvarsym(sym)^.definition^.needs_inittable then
- begin
- rttilist^.concat(new(Pai_const_symbol,
- init(pvarsym(sym)^.definition^.get_inittable_label)));
- rttilist^.concat(new(Pai_const,
- init_32bit(pvarsym(sym)^.address)));
- end;
- end;
- procedure write_field_rtti(sym:Pnamedindexobject);{$ifndef fpc}far;{$endif}
- begin
- rttilist^.concat(new(Pai_const_symbol,
- initname(Pvarsym(sym)^.definition^.get_rtti_label)));
- rttilist^.concat(new(Pai_const,
- init_32bit(Pvarsym(sym)^.address)));
- end;
- procedure generate_child_inittable(sym:Pnamedindexobject);
- {$ifndef fpc}far;{$endif}
- begin
- if (typeof(sym^)=typeof(Tvarsym)) and
- Pvarsym(sym)^.definition^.needs_inittable then
- {Force inittable generation }
- Pvarsym(sym)^.definition^.get_inittable_label;
- end;
- procedure generate_child_rtti(sym:Pnamedindexobject);
- {$ifndef fpc}far;{$endif}
- begin
- Pvarsym(sym)^.definition^.get_rtti_label;
- end;
- procedure Trecorddef.write_child_rtti_data;
- begin
- symtable^.foreach({$ifndef TP}@{$endif}generate_child_rtti);
- end;
- procedure Trecorddef.write_child_init_data;
- begin
- symtable^.foreach({$ifndef TP}@{$endif}generate_child_inittable);
- end;
- procedure Trecorddef.write_rtti_data;
- begin
- rttilist^.concat(new(pai_const,init_8bit(tkrecord)));
- write_rtti_name;
- rttilist^.concat(new(pai_const,init_32bit(size)));
- count:=0;
- symtable^.foreach({$ifndef TP}@{$endif}count_fields);
- rttilist^.concat(new(pai_const,init_32bit(count)));
- symtable^.foreach({$ifndef TP}@{$endif}write_field_rtti);
- end;
- procedure Trecorddef.write_init_data;
- begin
- rttilist^.concat(new(pai_const,init_8bit(14)));
- write_rtti_name;
- rttilist^.concat(new(pai_const,init_32bit(size)));
- count:=0;
- symtable^.foreach({$ifndef TP}@{$endif}count_inittable_fields);
- rttilist^.concat(new(pai_const,init_32bit(count)));
- symtable^.foreach({$ifndef TP}@{$endif}write_field_inittable);
- end;
- function Trecorddef.gettypename:string;
- begin
- gettypename:='<record type>'
- end;
- {***************************************************************************
- Tstringprocdef
- ***************************************************************************}
- constructor Tstringdef.shortinit(l:byte;Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- string_typ:=st_shortstring;
- len:=l;
- savesize:=len+1;
- end;
- constructor Tstringdef.shortload(var s:Tstream);
- begin
- inherited load(s);
- string_typ:=st_shortstring;
- { len:=readbyte;
- savesize:=len+1;}
- end;
- constructor Tstringdef.longinit(l:longint;Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- string_typ:=st_longstring;
- len:=l;
- savesize:=target_os.size_of_pointer;
- end;
- constructor Tstringdef.longload(var s:Tstream);
- begin
- inherited load(s);
- string_typ:=st_longstring;
- { len:=readlong;
- savesize:=target_os.size_of_pointer;}
- end;
- constructor tstringdef.ansiinit(l:longint;Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- include(properties,dp_ret_in_acc);
- string_typ:=st_ansistring;
- len:=l;
- savesize:=target_os.size_of_pointer;
- end;
- constructor Tstringdef.ansiload(var s:Tstream);
- begin
- inherited load(s);
- string_typ:=st_ansistring;
- { len:=readlong;
- savesize:=target_os.size_of_pointer;}
- end;
- constructor Tstringdef.wideinit(l:longint;Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- include(properties,dp_ret_in_acc);
- string_typ:=st_widestring;
- len:=l;
- savesize:=target_os.size_of_pointer;
- end;
- constructor Tstringdef.wideload(var s:Tstream);
- begin
- inherited load(s);
- string_typ:=st_widestring;
- { len:=readlong;
- savesize:=target_os.size_of_pointer;}
- end;
- function Tstringdef.stringtypname:string;
- const typname:array[tstringtype] of string[8]=
- ('','SHORTSTR','LONGSTR','ANSISTR','WIDESTR');
- begin
- stringtypname:=typname[string_typ];
- end;
- function tstringdef.size:longint;
- begin
- size:=savesize;
- end;
- procedure Tstringdef.store(var s:Tstream);
- begin
- inherited store(s);
- { if string_typ=st_shortstring then
- writebyte(len)
- else
- writelong(len);
- case string_typ of
- st_shortstring:
- current_ppu^.writeentry(ibshortstringdef);
- st_longstring:
- current_ppu^.writeentry(iblongstringdef);
- st_ansistring:
- current_ppu^.writeentry(ibansistringdef);
- st_widestring:
- current_ppu^.writeentry(ibwidestringdef);
- end;}
- end;
- {$ifdef GDB}
- function tstringdef.stabstring : pchar;
- var
- bytest,charst,longst : string;
- begin
- case string_typ of
- st_shortstring:
- begin
- charst := typeglobalnumber('char');
- { this is what I found in stabs.texinfo but
- gdb 4.12 for go32 doesn't understand that !! }
- {$IfDef GDBknowsstrings}
- stabstring := strpnew('n'+charst+';'+tostr(len));
- {$else}
- bytest := typeglobalnumber('byte');
- stabstring := strpnew('s'+tostr(len+1)+'length:'+bytest
- +',0,8;st:ar'+bytest
- +';1;'+tostr(len)+';'+charst+',8,'+tostr(len*8)+';;');
- {$EndIf}
- end;
- st_longstring:
- begin
- charst := typeglobalnumber('char');
- { this is what I found in stabs.texinfo but
- gdb 4.12 for go32 doesn't understand that !! }
- {$IfDef GDBknowsstrings}
- stabstring := strpnew('n'+charst+';'+tostr(len));
- {$else}
- bytest := typeglobalnumber('byte');
- longst := typeglobalnumber('longint');
- stabstring := strpnew('s'+tostr(len+5)+'length:'+longst
- +',0,32;dummy:'+bytest+',32,8;st:ar'+bytest
- +';1;'+tostr(len)+';'+charst+',40,'+tostr(len*8)+';;');
- {$EndIf}
- end;
- st_ansistring:
- begin
- { an ansi string looks like a pchar easy !! }
- stabstring:=strpnew('*'+typeglobalnumber('char'));
- end;
- st_widestring:
- begin
- { an ansi string looks like a pchar easy !! }
- stabstring:=strpnew('*'+typeglobalnumber('char'));
- end;
- end;
- end;
- procedure tstringdef.concatstabto(asmlist : paasmoutput);
- begin
- inherited concatstabto(asmlist);
- end;
- {$endif GDB}
- function tstringdef.needs_inittable : boolean;
- begin
- needs_inittable:=string_typ in [st_ansistring,st_widestring];
- end;
- function tstringdef.gettypename : string;
- const
- names : array[tstringtype] of string[20] = ('',
- 'ShortString','LongString','AnsiString','WideString');
- begin
- gettypename:=names[string_typ];
- end;
- procedure tstringdef.write_rtti_data;
- begin
- case string_typ of
- st_ansistring:
- begin
- rttilist^.concat(new(pai_const,init_8bit(tkAString)));
- write_rtti_name;
- end;
- st_widestring:
- begin
- rttilist^.concat(new(pai_const,init_8bit(tkWString)));
- write_rtti_name;
- end;
- st_longstring:
- begin
- rttilist^.concat(new(pai_const,init_8bit(tkLString)));
- write_rtti_name;
- end;
- st_shortstring:
- begin
- rttilist^.concat(new(pai_const,init_8bit(tkSString)));
- write_rtti_name;
- rttilist^.concat(new(pai_const,init_8bit(len)));
- end;
- end;
- end;
- function tstringdef.is_publishable : boolean;
- begin
- is_publishable:=true;
- end;
- {***************************************************************************
- Tabstractprocdef
- ***************************************************************************}
- constructor Tabstractprocdef.init(Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- include(properties,dp_ret_in_acc);
- retdef:=voiddef;
- savesize:=target_os.size_of_pointer;
- end;
- constructor Tabstractprocdef.load(var s:Tstream);
- var count,i:word;
- begin
- inherited load(s);
- (* retdef:=readdefref;
- fpu_used:=readbyte;
- options:=readlong;
- count:=readword;
- new(parameters);
- savesize:=target_os.size_of_pointer;
- for i:=1 to count do
- parameters^.readsymref;*)
- end;
- { all functions returning in FPU are
- assume to use 2 FPU registers
- until the function implementation
- is processed PM }
- procedure Tabstractprocdef.test_if_fpu_result;
- begin
- if (retdef<>nil) and (typeof(retdef^)=typeof(Tfloatdef)) and
- (Pfloatdef(retdef)^.typ in [f32bit,f16bit]) then
- fpu_used:=2;
- end;
- procedure Tabstractprocdef.deref;
- var i:longint;
- begin
- inherited deref;
- { resolvedef(retdef);}
- for i:=0 to parameters^.count-1 do
- Psym(parameters^.at(i))^.deref;
- end;
- function Tabstractprocdef.para_size:longint;
- var i,l:longint;
- begin
- l:=0;
- for i:=0 to parameters^.count-1 do
- inc(l,Pparamsym(parameters^.at(i))^.getpushsize);
- para_size:=l;
- end;
- procedure Tabstractprocdef.store(var s:Tstream);
- var count,i:word;
- begin
- inherited store(s);
- { writedefref(retdef);
- current_ppu^.do_interface_crc:=false;
- writebyte(fpu_used);
- writelong(options);
- writeword(parameters^.count);
- for i:=0 to parameters^.count-1 do
- begin
- writebyte(byte(hp^.paratyp));
- writesymfref(hp^.data);
- end;}
- end;
- function Tabstractprocdef.demangled_paras:string;
- var i:longint;
- s:string;
- procedure doconcat(p:Pparameter);
- begin
- s:=s+p^.data^.name;
- if p^.paratyp=vs_var then
- s:=s+'var'
- else if p^.paratyp=vs_const then
- s:=s+'const';
- end;
- begin
- s:='(';
- for i:=0 to parameters^.count-1 do
- doconcat(parameters^.at(i));
- s[length(s)]:=')';
- demangled_paras:=s;
- end;
- destructor Tabstractprocdef.done;
- begin
- dispose(parameters,done);
- inherited done;
- end;
- {***************************************************************************
- TPROCDEF
- ***************************************************************************}
- constructor Tprocdef.init(Aowner:Pcontainingsymtable);
- begin
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tabstractprocdef));{$ENDIF}
- fileinfo:=aktfilepos;
- extnumber:=-1;
- new(localst,init);
- if (cs_browser in aktmoduleswitches) and make_ref then
- begin
- new(references,init(2*owner^.index_growsize,
- owner^.index_growsize));
- references^.insert(new(Pref,init(tokenpos)));
- end;
- {First, we assume that all registers are used }
- usedregisters:=[low(Tregister)..high(Tregister)];
- forwarddef:=true;
- end;
- constructor Tprocdef.load(var s:Tstream);
- var a:string;
- begin
- inherited load(s);
- (* usedregisters:=readlong;
- a:=readstring;
- setstring(_mangledname,s);
- extnumber:=readlong;
- nextoerloaded:=pprocdef(readdefref);
- _class := pobjectdef(readdefref);
- readposinfo(fileinfo);
- if (cs_link_deffile in aktglobalswitches)
- and (poexports in options) then
- deffile.ddexport(mangledname);
- count:=true;*)
- end;
- const local_symtable_index : longint = $8001;
- procedure tprocdef.load_references;
- var pos:Tfileposinfo;
- pdo:Pobjectdef;
- move_last:boolean;
- begin
- (* move_last:=lastwritten=lastref;
- while (not current_ppu^.endofentry) do
- begin
- readposinfo(pos);
- inc(refcount);
- lastref:=new(pref,init(lastref,@pos));
- lastref^.is_written:=true;
- if refcount=1 then
- defref:=lastref;
- end;
- if move_last then
- lastwritten:=lastref;
- if ((current_module^.flags and uf_local_browser)<>0)
- and is_in_current then
- begin
- {$ifndef NOLOCALBROWSER}
- pdo:=_class;
- new(parast,loadas(parasymtable));
- parast^.next:=owner;
- parast^.load_browser;
- new(localst,loadas(localsymtable));
- localst^.next:=parast;
- localst^.load_browser;
- {$endif NOLOCALBROWSER}
- end;*)
- end;
- function Tprocdef.write_references:boolean;
- var ref:Pref;
- pdo:Pobjectdef;
- move_last:boolean;
- begin
- (* move_last:=lastwritten=lastref;
- if move_last and (((current_module^.flags and uf_local_browser)=0)
- or not is_in_current) then
- exit;
- {Write address of this symbol }
- writedefref(@self);
- {Write refs }
- if assigned(lastwritten) then
- ref:=lastwritten
- else
- ref:=defref;
- while assigned(ref) do
- begin
- if ref^.moduleindex=current_module^.unit_index then
- begin
- writeposinfo(ref^.posinfo);
- ref^.is_written:=true;
- if move_last then
- lastwritten:=ref;
- end
- else if not ref^.is_written then
- move_last:=false
- else if move_last then
- lastwritten:=ref;
- ref:=ref^.nextref;
- end;
- current_ppu^.writeentry(ibdefref);
- write_references:=true;
- if ((current_module^.flags and uf_local_browser)<>0)
- and is_in_current then
- begin
- pdo:=_class;
- if (owner^.symtabletype<>localsymtable) then
- while assigned(pdo) do
- begin
- if pdo^.publicsyms<>aktrecordsymtable then
- begin
- pdo^.publicsyms^.unitid:=local_symtable_index;
- inc(local_symtable_index);
- end;
- pdo:=pdo^.childof;
- end;
- {We need TESTLOCALBROWSER para and local symtables
- PPU files are then easier to read PM.}
- inc(local_symtable_index);
- parast^.write_browser;
- if not assigned(localst) then
- localst:=new(psymtable,init);
- localst^.writeas;
- localst^.unitid:=local_symtable_index;
- inc(local_symtable_index);
- localst^.write_browser;
- {Decrement for.}
- local_symtable_index:=local_symtable_index-2;
- pdo:=_class;
- if (owner^.symtabletype<>localsymtable) then
- while assigned(pdo) do
- begin
- if pdo^.publicsyms<>aktrecordsymtable then
- dec(local_symtable_index);
- pdo:=pdo^.childof;
- end;
- end;*)
- end;
- destructor Tprocdef.done;
- begin
- if pomsgstr in options then
- strdispose(messageinf.str);
- if references<>nil then
- dispose(references,done);
- if (localst<>nil) and (typeof(localst^)<>typeof(Timplsymtable)) then
- dispose(localst,done);
- { if (poinline in options) and (code,nil) then
- disposetree(ptree(code));}
- if _mangledname<>nil then
- disposestr(_mangledname);
- inherited done;
- end;
- procedure Tprocdef.store(var s:Tstream);
- begin
- (* inherited store(s);
- current_ppu^.do_interface_crc:=false;
- writelong(usedregisters);
- writestring(mangledname);
- current_ppu^.do_interface_crc:=true;
- writelong(extnumber);
- if (options and pooperator) = 0 then
- writedefref(nextoverloaded)
- else
- begin
- {Only write the overloads from the same unit }
- if assigned(nextoverloaded) and
- (nextoverloaded^.owner=owner) then
- writedefref(nextoverloaded)
- else
- writedefref(nil);
- end;
- writedefref(_class);
- writeposinfo(fileinfo);
- if (poinline and options) then
- begin
- {We need to save
- - the para and the local symtable
- - the code ptree !! PM
- writesymtable(parast);
- writesymtable(localst);
- writeptree(ptree(code));
- }
- end;
- current_ppu^.writeentry(ibprocdef);*)
- end;
- procedure Tprocdef.deref;
- begin
- { inherited deref;
- resolvedef(pdef(nextoverloaded));
- resolvedef(pdef(_class));}
- end;
- function Tprocdef.mangledname:string;
- var i:word;
- a:byte;
- s:Pprocsym;
- r:string;
- begin
- if _mangledname<>nil then
- mangledname:=_mangledname^
- else
- begin
- {If the procedure is in a unit, we start with the unitname.}
- if current_module^.is_unit then
- r:='_'+current_module^.modulename^
- else
- r:='';
- a:=length(r);
- {If we are a method we add the name of the object we are
- belonging to.}
- if (Pprocsym(sym)^._class<>nil) then
- r:=r+'_M'+Pprocsym(sym)^._class^.sym^.name+'_M';
- {Then we add the names of the procedures we are defined in
- (for the case we are a nested procedure).}
- s:=Pprocsym(sym)^.sub_of;
- while typeof(s^.owner^)=typeof(Tprocsymtable) do
- begin
- insert('_$'+s^.name,r,a);
- s:=s^.sub_of;
- end;
- r:=r+'_'+sym^.name;
- {Add the types of all parameters.}
- for i:=0 to parameters^.count-1 do
- begin
- r:=r+'$'+Pparameter(parameters^.at(i))^.data^.name;
- end;
- end;
- end;
- procedure Tprocdef.setmangledname(const s:string);
- begin
- if _mangledname<>nil then
- disposestr(_mangledname);
- _mangledname:=stringdup(s);
- if localst<>nil then
- begin
- stringdispose(localst^.name);
- localst^.name:=stringdup('locals of '+s);
- end;
- end;
- {***************************************************************************
- Tprocvardef
- ***************************************************************************}
- {$IFDEF TP}
- constructor Tprocvardef.init(Aowner:Pcontainingsymtable);
- begin
- setparent(typeof(Tabstractprocdef));
- end;
- {$ENDIF TP}
- function Tprocvardef.size:longint;
- begin
- if pomethodpointer in options then
- size:=2*target_os.size_of_pointer
- else
- size:=target_os.size_of_pointer;
- end;
- {$ifdef GDB}
- function tprocvardef.stabstring : pchar;
- var
- nss : pchar;
- i : word;
- param : pdefcoll;
- begin
- i := 0;
- param := para1;
- while assigned(param) do
- begin
- inc(i);
- param := param^.next;
- end;
- getmem(nss,1024);
- { it is not a function but a function pointer !! (PM) }
- strpcopy(nss,'*f'+retdef^.numberstring{+','+tostr(i)}+';');
- param := para1;
- i := 0;
- { this confuses gdb !!
- we should use 'F' instead of 'f' but
- as we use c++ language mode
- it does not like that either
- Please do not remove this part
- might be used once
- gdb for pascal is ready PM }
- (* while assigned(param) do
- begin
- inc(i);
- if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
- {Here we have lost the parameter names !!}
- pst := strpnew('p'+tostr(i)+':'+param^.data^.numberstring+','+vartyp+';');
- strcat(nss,pst);
- strdispose(pst);
- param := param^.next;
- end; *)
- {strpcopy(strend(nss),';');}
- stabstring := strnew(nss);
- freemem(nss,1024);
- end;
- procedure tprocvardef.concatstabto(asmlist : paasmoutput);
- begin
- if ( not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
- and not is_def_stab_written then
- inherited concatstabto(asmlist);
- is_def_stab_written:=true;
- end;
- {$endif GDB}
- procedure Tprocvardef.write_rtti_data;
- begin
- {!!!!!!!}
- end;
- procedure Tprocvardef.write_child_rtti_data;
- begin
- {!!!!!!!!}
- end;
- function Tprocvardef.is_publishable:boolean;
- begin
- is_publishable:=pomethodpointer in options;
- end;
- function Tprocvardef.gettypename:string;
- begin
- gettypename:='<procedure variable type>'
- end;
- {****************************************************************************
- Tforwarddef
- ****************************************************************************}
- constructor tforwarddef.init(Aowner:Pcontainingsymtable;
- const s:string;const pos:Tfileposinfo);
- var oldregisterdef:boolean;
- begin
- { never register the forwarddefs, they are disposed at the
- end of the type declaration block }
- { oldregisterdef:=registerdef;
- registerdef:=false;}
- inherited init(Aowner);
- {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
- { registerdef:=oldregisterdef;}
- tosymname:=s;
- forwardpos:=pos;
- end;
- function tforwarddef.gettypename:string;
- begin
- gettypename:='unresolved forward to '+tosymname;
- end;
- end.
- {
- $Log$
- Revision 1.5 2000-03-11 21:11:24 daniel
- * Ported hcgdata to new symtable.
- * Alignment code changed as suggested by Peter
- + Usage of my is operator replacement, is_object
- Revision 1.4 2000/03/01 11:43:55 daniel
- * Some more work on the new symtable.
- + Symtable stack unit 'symstack' added.
- }
|