12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019 |
- {
- $Id$
- Copyright (C) 1993-98 by Florian Klaempfl
- This unit provides some help routines for type handling
- 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.
- ****************************************************************************
- }
- unit types;
- interface
- uses
- cobjects,globals,symtable,tree,aasm;
- type
- tmmxtype = (mmxno,mmxu8bit,mmxs8bit,mmxu16bit,mmxs16bit,
- mmxu32bit,mmxs32bit,mmxfixed16,mmxsingle);
- { returns true, if def defines an ordinal type }
- function is_ordinal(def : pdef) : boolean;
- { true if p points to an open array def }
- function is_open_array(p : pdef) : boolean;
- { true if o is an ansi string def }
- function is_ansistring(p : pdef) : boolean;
- { true if o is a long string def }
- function is_longstring(p : pdef) : boolean;
- { true if o is a wide string def }
- function is_widestring(p : pdef) : boolean;
- { true if o is a short string def }
- function is_shortstring(p : pdef) : boolean;
- { returns true, if def defines a signed data type (only for ordinal types) }
- function is_signed(def : pdef) : boolean;
- { returns true, if def uses FPU }
- function is_fpu(def : pdef) : boolean;
- { true if the return value is in EAX }
- function ret_in_acc(def : pdef) : boolean;
- { true if uses a parameter as return value }
- function ret_in_param(def : pdef) : boolean;
- { true if a const parameter is too large to copy }
- function dont_copy_const_param(def : pdef) : boolean;
- { true if we must never copy this parameter }
- const
- never_copy_const_param : boolean = false;
- { true, if def1 and def2 are semantical the same }
- function is_equal(def1,def2 : pdef) : boolean;
- { checks for type compatibility (subgroups of type) }
- { used for case statements... probably missing stuff }
- { to use on other types }
- function is_subequal(def1, def2: pdef): boolean;
- { true, if two parameter lists are equal }
- { if value_equal_const is true, call by value }
- { and call by const parameter are assumed as }
- { equal }
- function equal_paras(def1,def2 : pdefcoll;value_equal_const : boolean) : boolean;
- { gibt den ordinalen Werten der Node zurueck oder falls sie }
- { keinen ordinalen Wert hat, wird ein Fehler erzeugt }
- function get_ordinal_value(p : ptree) : longint;
- { if l isn't in the range of def a range check error is generated }
- procedure testrange(def : pdef;l : longint);
- { returns the range of def }
- procedure getrange(def : pdef;var l : longint;var h : longint);
- { generates a VMT for _class }
- procedure genvmt(_class : pobjectdef);
- { true, if p is a pointer to a const int value }
- function is_constintnode(p : ptree) : boolean;
- { like is_constintnode }
- function is_constboolnode(p : ptree) : boolean;
- function is_constrealnode(p : ptree) : boolean;
- function is_constcharnode(p : ptree) : boolean;
- { some type helper routines for MMX support }
- function is_mmx_able_array(p : pdef) : boolean;
- { returns the mmx type }
- function mmx_type(p : pdef) : tmmxtype;
- implementation
- uses verbose;
- function is_constintnode(p : ptree) : boolean;
- begin
- {DM: According to me, an orddef with anysize, is
- a correct constintnode. Anyway I commented changed s32bit check,
- because it caused problems with statements like a:=high(word).}
- is_constintnode:=((p^.treetype=ordconstn) and
- (p^.resulttype^.deftype=orddef) and
- (porddef(p^.resulttype)^.typ in [u8bit,s8bit,u16bit,s16bit,
- u32bit,s32bit,uauto]));
- end;
- function is_constcharnode(p : ptree) : boolean;
- begin
- is_constcharnode:=((p^.treetype=ordconstn) and
- (p^.resulttype^.deftype=orddef) and
- (porddef(p^.resulttype)^.typ=uchar));
- end;
- function is_constrealnode(p : ptree) : boolean;
- begin
- is_constrealnode:=(p^.treetype=realconstn);
- end;
- function is_constboolnode(p : ptree) : boolean;
- begin
- is_constboolnode:=((p^.treetype=ordconstn) and
- (p^.resulttype^.deftype=orddef) and
- (porddef(p^.resulttype)^.typ=bool8bit));
- end;
- function equal_paras(def1,def2 : pdefcoll;value_equal_const : boolean) : boolean;
- begin
- while (assigned(def1)) and (assigned(def2)) do
- begin
- if value_equal_const then
- begin
- if not(is_equal(def1^.data,def2^.data)) or
- ((def1^.paratyp<>def2^.paratyp) and
- ((def1^.paratyp=vs_var) or
- (def1^.paratyp=vs_var)
- )
- ) then
- begin
- equal_paras:=false;
- exit;
- end;
- end
- else
- begin
- if not(is_equal(def1^.data,def2^.data)) or
- (def1^.paratyp<>def2^.paratyp) then
- begin
- equal_paras:=false;
- exit;
- end;
- end;
- def1:=def1^.next;
- def2:=def2^.next;
- end;
- if (def1=nil) and (def2=nil) then
- equal_paras:=true
- else
- equal_paras:=false;
- end;
- { returns true, if def uses FPU }
- function is_fpu(def : pdef) : boolean;
- begin
- is_fpu:=(def^.deftype=floatdef) and (pfloatdef(def)^.typ<>f32bit);
- end;
- function is_ordinal(def : pdef) : boolean;
- var
- dt : tbasetype;
- begin
- case def^.deftype of
- orddef : begin
- dt:=porddef(def)^.typ;
- is_ordinal:=(dt=s32bit) or (dt=u32bit) or (dt=uchar) or (dt=u8bit) or
- (dt=s8bit) or (dt=s16bit) or (dt=bool8bit) or (dt=u16bit);
- end;
- enumdef : is_ordinal:=true;
- else is_ordinal:=false;
- end;
- end;
- function is_signed(def : pdef) : boolean;
- var
- dt : tbasetype;
- begin
- case def^.deftype of
- orddef : begin
- dt:=porddef(def)^.typ;
- is_signed:=(dt=s32bit) or (dt=s8bit) or (dt=s16bit);
- end;
- enumdef : is_signed:=false;
- else internalerror(1001);
- end;
- end;
- { true, if p points to an open array def }
- function is_open_array(p : pdef) : boolean;
- begin
- is_open_array:=(p^.deftype=arraydef) and
- (parraydef(p)^.lowrange=0) and
- (parraydef(p)^.highrange=-1);
- end;
- { true if o is an ansi string def }
- function is_ansistring(p : pdef) : boolean;
- begin
- is_ansistring:=(p^.deftype=stringdef) and
- (pstringdef(p)^.string_typ=ansistring);
- end;
- { true if o is an long string def }
- function is_longstring(p : pdef) : boolean;
- begin
- is_longstring:=(p^.deftype=stringdef) and
- (pstringdef(p)^.string_typ=longstring);
- end;
- { true if o is an long string def }
- function is_widestring(p : pdef) : boolean;
- begin
- is_widestring:=(p^.deftype=stringdef) and
- (pstringdef(p)^.string_typ=widestring);
- end;
- { true if o is an short string def }
- function is_shortstring(p : pdef) : boolean;
- begin
- is_shortstring:=(p^.deftype=stringdef) and
- (pstringdef(p)^.string_typ=shortstring);
- end;
- { true if the return value is in accumulator (EAX for i386), D0 for 68k }
- function ret_in_acc(def : pdef) : boolean;
- begin
- ret_in_acc:=(def^.deftype=orddef) or
- (def^.deftype=pointerdef) or
- (def^.deftype=enumdef) or
- ((def^.deftype=procvardef) and
- ((pprocvardef(def)^.options and pomethodpointer)=0)) or
- (def^.deftype=classrefdef) or
- ((def^.deftype=objectdef) and
- pobjectdef(def)^.isclass
- ) or
- ((def^.deftype=setdef) and
- (psetdef(def)^.settype=smallset)) or
- ((def^.deftype=floatdef) and
- (pfloatdef(def)^.typ=f32bit));
- end;
- { true if uses a parameter as return value }
- function ret_in_param(def : pdef) : boolean;
- begin
- ret_in_param:=(def^.deftype=arraydef) or
- (def^.deftype=stringdef) or
- ((def^.deftype=procvardef) and
- ((pprocvardef(def)^.options and pomethodpointer)<>0)) or
- ((def^.deftype=objectdef) and
- ((pobjectdef(def)^.options and oois_class)=0)
- ) or
- (def^.deftype=recorddef) or
- ((def^.deftype=setdef) and
- (psetdef(def)^.settype<>smallset));
- end;
- { true if a const parameter is too large to copy }
- function dont_copy_const_param(def : pdef) : boolean;
- begin
- dont_copy_const_param:=(def^.deftype=arraydef) or
- (def^.deftype=stringdef) or
- (def^.deftype=objectdef) or
- (def^.deftype=formaldef) or
- (def^.deftype=recorddef) or
- ((def^.deftype=procvardef) and
- ((pprocvardef(def)^.options and pomethodpointer)<>0)) or
- ((def^.deftype=setdef) and
- (psetdef(def)^.settype<>smallset));
- end;
- procedure testrange(def : pdef;l : longint);
- var
- lv,hv: longint;
- begin
- getrange(def,lv,hv);
- if (def^.deftype=orddef) and
- (porddef(def)^.typ=u32bit) then
- begin
- if lv<=hv then
- begin
- if (l<lv) or (l>hv) then
- Message(parser_e_range_check_error);
- end
- else
- { this happens with the wrap around problem }
- { if lv is positive and hv is over $7ffffff }
- { so it seems negative }
- begin
- if ((l>=0) and (l<lv)) or
- ((l<0) and (l>hv)) then
- Message(parser_e_range_check_error);
- end;
- end
- else if (l<lv) or (l>hv) then
- Message(parser_e_range_check_error);
- end;
- procedure getrange(def : pdef;var l : longint;var h : longint);
- begin
- if def^.deftype=orddef then
- case porddef(def)^.typ of
- s32bit,s16bit,u16bit,s8bit,u8bit :
- begin
- l:=porddef(def)^.von;
- h:=porddef(def)^.bis;
- end;
- bool8bit : begin
- l:=0;
- h:=1;
- end;
- uchar : begin
- l:=0;
- h:=255;
- end;
- u32bit : begin
- { this should work now }
- l:=porddef(def)^.von;
- h:=porddef(def)^.bis;
- end;
- end
- else
- if def^.deftype=enumdef then
- begin
- l:=0;
- h:=penumdef(def)^.max;
- end;
- end;
- function get_ordinal_value(p : ptree) : longint;
- begin
- if p^.treetype=ordconstn then
- get_ordinal_value:=p^.value
- else
- Message(parser_e_ordinal_expected);
- end;
- function mmx_type(p : pdef) : tmmxtype;
- begin
- mmx_type:=mmxno;
- if is_mmx_able_array(p) then
- begin
- if parraydef(p)^.definition^.deftype=floatdef then
- case pfloatdef(parraydef(p)^.definition)^.typ of
- s32real:
- mmx_type:=mmxsingle;
- f16bit:
- mmx_type:=mmxfixed16
- end
- else
- case porddef(parraydef(p)^.definition)^.typ of
- u8bit:
- mmx_type:=mmxu8bit;
- s8bit:
- mmx_type:=mmxs8bit;
- u16bit:
- mmx_type:=mmxu16bit;
- s16bit:
- mmx_type:=mmxs16bit;
- u32bit:
- mmx_type:=mmxu32bit;
- s32bit:
- mmx_type:=mmxs32bit;
- end;
- end;
- end;
- function is_mmx_able_array(p : pdef) : boolean;
- begin
- {$ifdef SUPPORT_MMX}
- if (cs_mmx_saturation in aktswitches) then
- begin
- is_mmx_able_array:=(p^.deftype=arraydef) and
- (
- ((parraydef(p)^.definition^.deftype=orddef) and
- (
- (parraydef(p)^.lowrange=0) and
- (parraydef(p)^.highrange=1) and
- (porddef(parraydef(p)^.definition)^.typ in [u32bit,s32bit])
- ) or
- (
- (parraydef(p)^.lowrange=0) and
- (parraydef(p)^.highrange=3) and
- (porddef(parraydef(p)^.definition)^.typ in [u16bit,s16bit])
- )
- )
- ) or
- (
- ((parraydef(p)^.definition^.deftype=floatdef) and
- (
- (parraydef(p)^.lowrange=0) and
- (parraydef(p)^.highrange=3) and
- (pfloatdef(parraydef(p)^.definition)^.typ=f16bit)
- ) or
- (
- (parraydef(p)^.lowrange=0) and
- (parraydef(p)^.highrange=1) and
- (pfloatdef(parraydef(p)^.definition)^.typ=s32real)
- )
- )
- );
- end
- else
- begin
- is_mmx_able_array:=(p^.deftype=arraydef) and
- (
- ((parraydef(p)^.definition^.deftype=orddef) and
- (
- (parraydef(p)^.lowrange=0) and
- (parraydef(p)^.highrange=1) and
- (porddef(parraydef(p)^.definition)^.typ in [u32bit,s32bit])
- ) or
- (
- (parraydef(p)^.lowrange=0) and
- (parraydef(p)^.highrange=3) and
- (porddef(parraydef(p)^.definition)^.typ in [u16bit,s16bit])
- ) or
- (
- (parraydef(p)^.lowrange=0) and
- (parraydef(p)^.highrange=7) and
- (porddef(parraydef(p)^.definition)^.typ in [u8bit,s8bit])
- )
- )
- ) or
- (
- ((parraydef(p)^.definition^.deftype=floatdef) and
- (
- (parraydef(p)^.lowrange=0) and
- (parraydef(p)^.highrange=3) and
- (pfloatdef(parraydef(p)^.definition)^.typ=f32bit)
- )
- or
- (
- (parraydef(p)^.lowrange=0) and
- (parraydef(p)^.highrange=1) and
- (pfloatdef(parraydef(p)^.definition)^.typ=s32real)
- )
- )
- );
- end;
- {$else SUPPORT_MMX}
- is_mmx_able_array:=false;
- {$endif SUPPORT_MMX}
- end;
- function is_equal(def1,def2 : pdef) : boolean;
- var
- b : boolean;
- hd : pdef;
- hp1,hp2 : pdefcoll;
- begin
- { both types must exists }
- if not (assigned(def1) and assigned(def2)) then
- begin
- is_equal:=false;
- exit;
- end;
- { be sure, that if there is a stringdef, that this is def1 }
- if def2^.deftype=stringdef then
- begin
- hd:=def1;
- def1:=def2;
- def2:=hd;
- end;
- b:=false;
- { wenn beide auf die gleiche Definition zeigen sind sie wohl gleich...}
- if def1=def2 then
- b:=true
- else
- { pointer with an equal definition are equal }
- if (def1^.deftype=pointerdef) and (def2^.deftype=pointerdef) then
- { here a problem detected in tabsolutesym }
- { the types can be forward type !! }
- begin
- if assigned(def1^.sym) and ((def1^.sym^.properties and sp_forwarddef)<>0) then
- b:=(def1^.sym=def2^.sym)
- else
- b:=is_equal(ppointerdef(def1)^.definition,ppointerdef(def2)^.definition);
- end
- else
- { Grundtypen sind gleich, wenn sie den selben Grundtyp haben, }
- { und wenn noetig den selben Unterbereich haben }
- if (def1^.deftype=orddef) and (def2^.deftype=orddef) then
- begin
- case porddef(def1)^.typ of
- u32bit,u8bit,s32bit,s8bit,u16bit,s16bit : begin
- if porddef(def1)^.typ=porddef(def2)^.typ then
- if (porddef(def1)^.von=porddef(def2)^.von) and
- (porddef(def1)^.bis=porddef(def2)^.bis) then
- b:=true;
- end;
- uvoid,bool8bit,uchar :
- b:=porddef(def1)^.typ=porddef(def2)^.typ;
- end;
- end
- else
- if (def1^.deftype=floatdef) and (def2^.deftype=floatdef) then
- b:=pfloatdef(def1)^.typ=pfloatdef(def2)^.typ
- else
- { strings with the same length are equal }
- if (def1^.deftype=stringdef) and (def2^.deftype=stringdef) and
- (pstringdef(def1)^.len=pstringdef(def2)^.len) then
- b:=true
- { STRING[N] ist equivalent zu ARRAY[0..N] OF CHAR (N<256) }
- {
- else if ((def1^.deftype=stringdef) and (def2^.deftype=arraydef)) and
- (parraydef(def2)^.definition^.deftype=orddef) and
- (porddef(parraydef(def1)^.definition)^.typ=uchar) and
- (parraydef(def2)^.lowrange=0) and
- (parraydef(def2)^.highrange=pstringdef(def1)^.len) then
- b:=true }
- else
- if (def1^.deftype=formaldef) and (def2^.deftype=formaldef) then
- b:=true
- { file types with the same file element type are equal }
- { this is a problem for assign !! }
- { changed to allow if one is untyped }
- { all typed files are equal to the special }
- { typed file that has voiddef as elemnt type }
- { but must NOT match for text file !!! }
- else
- if (def1^.deftype=filedef) and (def2^.deftype=filedef) then
- b:=(pfiledef(def1)^.filetype=pfiledef(def2)^.filetype) and
- ((
- ((pfiledef(def1)^.typed_as=nil) and
- (pfiledef(def2)^.typed_as=nil)) or
- (
- (pfiledef(def1)^.typed_as<>nil) and
- (pfiledef(def2)^.typed_as<>nil) and
- is_equal(pfiledef(def1)^.typed_as,pfiledef(def2)^.typed_as)
- ) or
- ( (pfiledef(def1)^.typed_as=pdef(voiddef)) or
- (pfiledef(def2)^.typed_as=pdef(voiddef))
- )))
- { sets with the same element type are equal }
- else
- if (def1^.deftype=setdef) and (def2^.deftype=setdef) then
- begin
- if assigned(psetdef(def1)^.setof) and
- assigned(psetdef(def2)^.setof) then
- b:=is_equal(psetdef(def1)^.setof,psetdef(def2)^.setof)
- else b:=true;
- end
- else
- if (def1^.deftype=procvardef) and (def2^.deftype=procvardef) then
- begin
- { poassembler isn't important for compatibility }
- b:=((pprocvardef(def1)^.options and not(poassembler))=
- (pprocvardef(def2)^.options and not(poassembler))
- ) and
- is_equal(pprocvardef(def1)^.retdef,pprocvardef(def2)^.retdef);
- { now evalute the parameters }
- if b then
- begin
- hp1:=pprocvardef(def1)^.para1;
- hp2:=pprocvardef(def1)^.para1;
- while assigned(hp1) and assigned(hp2) do
- begin
- if not(is_equal(hp1^.data,hp2^.data)) or
- not(hp1^.paratyp=hp2^.paratyp) then
- begin
- b:=false;
- break;
- end;
- hp1:=hp1^.next;
- hp2:=hp2^.next;
- end;
- b:=(hp1=nil) and (hp2=nil);
- end;
- end
- else
- if (def1^.deftype=arraydef) and (def2^.deftype=arraydef) and
- (is_open_array(def1) or is_open_array(def2)) then
- begin
- b:=is_equal(parraydef(def1)^.definition,parraydef(def2)^.definition);
- end
- else
- if (def1^.deftype=classrefdef) and (def2^.deftype=classrefdef) then
- begin
- { similar to pointerdef: }
- if assigned(def1^.sym) and ((def1^.sym^.properties and sp_forwarddef)<>0) then
- b:=(def1^.sym=def2^.sym)
- else
- b:=is_equal(pclassrefdef(def1)^.definition,pclassrefdef(def2)^.definition);
- end;
- is_equal:=b;
- end;
- function is_subequal(def1, def2: pdef): boolean;
- Begin
- if assigned(def1) and assigned(def2) then
- Begin
- is_subequal := FALSE;
- if (def1^.deftype = orddef) and (def2^.deftype = orddef) then
- Begin
- { see p.47 of Turbo Pascal 7.01 manual for the separation of types }
- { range checking for case statements is done with testrange }
- case porddef(def1)^.typ of
- s32bit,u32bit,u8bit,s8bit,s16bit,u16bit:
- Begin
- { PROBABLE CODE GENERATION BUG HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! }
- { if porddef(def2)^.typ in [s32bit,u32bit,u8bit,s8bit,s16bit,u16bit] then
- is_subequal := TRUE; }
- if (porddef(def2)^.typ = s32bit) or
- (porddef(def2)^.typ = u32bit) or
- (porddef(def2)^.typ = u8bit) or
- (porddef(def2)^.typ = s8bit) or
- (porddef(def2)^.typ = s16bit) or
- (porddef(def2)^.typ = u16bit) then
- Begin
- is_subequal:=TRUE;
- end;
- end;
- bool8bit: if porddef(def2)^.typ = bool8bit then is_subequal := TRUE;
- uchar: if porddef(def2)^.typ = uchar then is_subequal := TRUE;
- end;
- end
- else
- Begin
- { I assume that both enumerations are equal when the first }
- { pointers are equal. }
- if (def1^.deftype = enumdef) and (def2^.deftype =enumdef) then
- Begin
- if penumdef(def1)^.first = penumdef(def2)^.first then
- is_subequal := TRUE;
- end;
- end;
- end; { endif assigned ... }
- end;
- type
- pprocdefcoll = ^tprocdefcoll;
- tprocdefcoll = record
- next : pprocdefcoll;
- data : pprocdef;
- end;
- psymcoll = ^tsymcoll;
- tsymcoll = record
- next : psymcoll;
- name : pstring;
- data : pprocdefcoll;
- end;
- var
- wurzel : psymcoll;
- nextvirtnumber : longint;
- _c : pobjectdef;
- has_constructor,has_virtual_method : boolean;
- procedure eachsym(sym : psym);{$ifndef FPC}far;{$endif}
- var
- procdefcoll : pprocdefcoll;
- hp : pprocdef;
- symcoll : psymcoll;
- _name : string;
- stored : boolean;
- { creates a new entry in the procsym list }
- procedure newentry;
- begin
- { if not, generate a new symbol item }
- new(symcoll);
- symcoll^.name:=stringdup(sym^.name);
- symcoll^.next:=wurzel;
- symcoll^.data:=nil;
- wurzel:=symcoll;
- hp:=pprocsym(sym)^.definition;
- { inserts all definitions }
- while assigned(hp) do
- begin
- new(procdefcoll);
- procdefcoll^.data:=hp;
- procdefcoll^.next:=symcoll^.data;
- symcoll^.data:=procdefcoll;
- { if it's a virtual method }
- if (hp^.options and povirtualmethod)<>0 then
- begin
- { then it gets a number ... }
- hp^.extnumber:=nextvirtnumber;
- { and we inc the number }
- inc(nextvirtnumber);
- has_virtual_method:=true;
- end;
- if (hp^.options and poconstructor)<>0 then
- has_constructor:=true;
- { check, if a method should be overridden }
- if (hp^.options and pooverridingmethod)<>0 then
- Message1(parser_e_nothing_to_be_overridden,_c^.name^+'.'+_name);
- { next overloaded method }
- hp:=hp^.nextoverloaded;
- end;
- end;
- begin
- { put only sub routines into the VMT }
- if sym^.typ=procsym then
- begin
- _name:=sym^.name;
- symcoll:=wurzel;
- while assigned(symcoll) do
- begin
- { does the symbol already exist in the list ? }
- if _name=symcoll^.name^ then
- begin
- { walk through all defs of the symbol }
- hp:=pprocsym(sym)^.definition;
- while assigned(hp) do
- begin
- { compare with all stored definitions }
- procdefcoll:=symcoll^.data;
- stored:=false;
- while assigned(procdefcoll) do
- begin
- { compare parameters }
- if equal_paras(procdefcoll^.data^.para1,hp^.para1,false) and
- (
- ((procdefcoll^.data^.options and povirtualmethod)<>0) or
- ((hp^.options and povirtualmethod)<>0)
- ) then
- begin
- { wenn sie gleich sind }
- { und eine davon virtual deklariert ist }
- { Fehler falls nur eine VIRTUAL }
- if (procdefcoll^.data^.options and povirtualmethod)<>
- (hp^.options and povirtualmethod) then
- begin
- { in classes, we hide the old method }
- if _c^.isclass then
- begin
- { warn only if it is the first time,
- we hide the method }
- if _c=hp^._class then
- Message1(parser_w_should_use_override,_c^.name^+'.'+_name);
- newentry;
- exit;
- end
- else
- begin
- Message1(parser_e_overloaded_are_not_both_virtual,_c^.name^+'.'+_name);
- end;
- end;
- { check, if the overridden directive is set }
- { (povirtualmethod is set! }
- { class ? }
- if _c^.isclass and
- ((hp^.options and pooverridingmethod)=0) then
- begin
- { warn only if it is the first time,
- we hide the method }
- if _c=hp^._class then
- Message1(parser_w_should_use_override,_c^.name^+'.'+_name);
- newentry;
- exit;
- end;
- { error, if the return types aren't equal }
- if not(is_equal(procdefcoll^.data^.retdef,hp^.retdef)) then
- Message1(parser_e_overloaded_methodes_not_same_ret,_c^.name^+'.'+_name);
- { the flags have to match }
- { except abstract and override }
- if (procdefcoll^.data^.options and not(poabstractmethod or pooverridingmethod))<>
- (hp^.options and not(poabstractmethod or pooverridingmethod)) then
- Message1(parser_e_header_dont_match_forward,_c^.name^+'.'+_name);
- { now set the number }
- hp^.extnumber:=procdefcoll^.data^.extnumber;
- { and exchange }
- procdefcoll^.data:=hp;
- stored:=true;
- end;
- procdefcoll:=procdefcoll^.next;
- end;
- { if it isn't saved in the list }
- { we create a new entry }
- if not(stored) then
- begin
- new(procdefcoll);
- procdefcoll^.data:=hp;
- procdefcoll^.next:=symcoll^.data;
- symcoll^.data:=procdefcoll;
- { if the method is virtual ... }
- if (hp^.options and povirtualmethod)<>0 then
- begin
- { ... it will get a number }
- hp^.extnumber:=nextvirtnumber;
- inc(nextvirtnumber);
- end;
- { check, if a method should be overridden }
- if (hp^.options and pooverridingmethod)<>0 then
- Message1(parser_e_nothing_to_be_overridden,_c^.name^+'.'+_name);
- end;
- hp:=hp^.nextoverloaded;
- end;
- exit;
- end;
- symcoll:=symcoll^.next;
- end;
- newentry;
- end;
- end;
- procedure genvmt(_class : pobjectdef);
- procedure do_genvmt(p : pobjectdef);
- begin
- { start with the base class }
- if assigned(p^.childof) then
- do_genvmt(p^.childof);
- { walk through all public syms }
- _c:=_class;
- {$ifdef tp}
- p^.publicsyms^.foreach(eachsym);
- {$else}
- p^.publicsyms^.foreach(@eachsym);
- {$endif}
- end;
- var
- symcoll : psymcoll;
- procdefcoll : pprocdefcoll;
- i : longint;
- begin
- wurzel:=nil;
- nextvirtnumber:=0;
- has_constructor:=false;
- has_virtual_method:=false;
- { generates a tree of all used methods }
- do_genvmt(_class);
- if has_virtual_method and not(has_constructor) then
- Message1(parser_w_virtual_without_constructor,_class^.name^);
-
- { generates the VMT }
- { walk trough all numbers for virtual methods and search }
- { the method }
- for i:=0 to nextvirtnumber-1 do
- begin
- symcoll:=wurzel;
- { walk trough all symbols }
- while assigned(symcoll) do
- begin
- { walk trough all methods }
- procdefcoll:=symcoll^.data;
- while assigned(procdefcoll) do
- begin
- { writes the addresses to the VMT }
- { but only this which are declared as virtual }
- if procdefcoll^.data^.extnumber=i then
- begin
- if (procdefcoll^.data^.options and povirtualmethod)<>0 then
- begin
- { if a method is abstract, then is also the }
- { class abstract and it's not allow to }
- { generates an instance }
- if (procdefcoll^.data^.options and poabstractmethod)<>0 then
- begin
- _class^.options:=_class^.options or oois_abstract;
- datasegment^.concat(new(pai_const,init_symbol('ABSTRACTERROR')));
- end
- else
- begin
- datasegment^.concat(new(pai_const,init_symbol(
- strpnew(procdefcoll^.data^.mangledname))));
- maybe_concat_external(procdefcoll^.data^.owner,
- procdefcoll^.data^.mangledname);
- end;
- end;
- end;
- procdefcoll:=procdefcoll^.next;
- end;
- symcoll:=symcoll^.next;
- end;
- end;
- { disposes the above generated tree }
- symcoll:=wurzel;
- while assigned(symcoll) do
- begin
- wurzel:=symcoll^.next;
- stringdispose(symcoll^.name);
- procdefcoll:=symcoll^.data;
- while assigned(procdefcoll) do
- begin
- symcoll^.data:=procdefcoll^.next;
- dispose(procdefcoll);
- procdefcoll:=symcoll^.data;
- end;
- dispose(symcoll);
- symcoll:=wurzel;
- end;
- end;
- end.
- {
- $Log$
- Revision 1.12 1998-05-12 10:47:00 peter
- * moved printstatus to verb_def
- + V_Normal which is between V_Error and V_Warning and doesn't have a
- prefix like error: warning: and is included in V_Default
- * fixed some messages
- * first time parameter scan is only for -v and -T
- - removed old style messages
- Revision 1.11 1998/05/01 16:38:46 florian
- * handling of private and protected fixed
- + change_keywords_to_tp implemented to remove
- keywords which aren't supported by tp
- * break and continue are now symbols of the system unit
- + widestring, longstring and ansistring type released
- Revision 1.10 1998/04/29 10:34:08 pierre
- + added some code for ansistring (not complete nor working yet)
- * corrected operator overloading
- * corrected nasm output
- + started inline procedures
- + added starstarn : use ** for exponentiation (^ gave problems)
- + started UseTokenInfo cond to get accurate positions
- Revision 1.9 1998/04/21 10:16:49 peter
- * patches from strasbourg
- * objects is not used anymore in the fpc compiled version
- Revision 1.8 1998/04/12 22:39:44 florian
- * problem with read access to properties solved
- * correct handling of hidding methods via virtual (COM)
- * correct result type of constructor calls (COM), the resulttype
- depends now on the type of the class reference
- Revision 1.7 1998/04/10 21:36:56 florian
- + some stuff to support method pointers (procedure of object) added
- (declaration, parameter handling)
- Revision 1.6 1998/04/10 15:39:49 florian
- * more fixes to get classes.pas compiled
- Revision 1.5 1998/04/09 23:02:16 florian
- * small problems solved to get remake3 work
- Revision 1.4 1998/04/08 16:58:09 pierre
- * several bugfixes
- ADD ADC and AND are also sign extended
- nasm output OK (program still crashes at end
- and creates wrong assembler files !!)
- procsym types sym in tdef removed !!
- Revision 1.3 1998/04/08 11:34:22 peter
- * nasm works (linux only tested)
- }
|