mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-10-26 16:33:45 +01:00 
			
		
		
		
	compiler, rtl, tests: write Delphi compatible (more or less) type information for Class Reference and Pointer types (mantis #0024367)
git-svn-id: trunk@24421 -
This commit is contained in:
		
							parent
							
								
									930b76e8fb
								
							
						
					
					
						commit
						d90445e5ee
					
				
							
								
								
									
										1
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							| @ -11689,6 +11689,7 @@ tests/test/trtti2.pp svneol=native#text/plain | |||||||
| tests/test/trtti3.pp svneol=native#text/plain | tests/test/trtti3.pp svneol=native#text/plain | ||||||
| tests/test/trtti4.pp svneol=native#text/plain | tests/test/trtti4.pp svneol=native#text/plain | ||||||
| tests/test/trtti5.pp svneol=native#text/plain | tests/test/trtti5.pp svneol=native#text/plain | ||||||
|  | tests/test/trtti6.pp svneol=native#text/pascal | ||||||
| tests/test/tsafecall1.pp svneol=native#text/plain | tests/test/tsafecall1.pp svneol=native#text/plain | ||||||
| tests/test/tsafecall2.pp svneol=native#text/pascal | tests/test/tsafecall2.pp svneol=native#text/pascal | ||||||
| tests/test/tsafecall3.pp svneol=native#text/pascal | tests/test/tsafecall3.pp svneol=native#text/pascal | ||||||
|  | |||||||
| @ -616,6 +616,20 @@ implementation | |||||||
|              end; |              end; | ||||||
|         end; |         end; | ||||||
| 
 | 
 | ||||||
|  |         procedure classrefdef_rtti(def:tclassrefdef); | ||||||
|  |         begin | ||||||
|  |           write_header(def,tkClassRef); | ||||||
|  |           maybe_write_align; | ||||||
|  |           current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.pointeddef,rt))); | ||||||
|  |         end; | ||||||
|  | 
 | ||||||
|  |         procedure pointerdef_rtti(def:tpointerdef); | ||||||
|  |         begin | ||||||
|  |           write_header(def,tkPointer); | ||||||
|  |           maybe_write_align; | ||||||
|  |           current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.pointeddef,rt))); | ||||||
|  |         end; | ||||||
|  | 
 | ||||||
|         procedure recorddef_rtti(def:trecorddef); |         procedure recorddef_rtti(def:trecorddef); | ||||||
|         begin |         begin | ||||||
|            write_header(def,tkRecord); |            write_header(def,tkRecord); | ||||||
| @ -938,6 +952,10 @@ implementation | |||||||
|             end; |             end; | ||||||
|           objectdef : |           objectdef : | ||||||
|             objectdef_rtti(tobjectdef(def)); |             objectdef_rtti(tobjectdef(def)); | ||||||
|  |           classrefdef : | ||||||
|  |             classrefdef_rtti(tclassrefdef(def)); | ||||||
|  |           pointerdef : | ||||||
|  |             pointerdef_rtti(tpointerdef(def)); | ||||||
|           else |           else | ||||||
|             unknown_rtti(tstoreddef(def)); |             unknown_rtti(tstoreddef(def)); | ||||||
|         end; |         end; | ||||||
|  | |||||||
| @ -66,6 +66,8 @@ const | |||||||
|   tkUChar    = 25; |   tkUChar    = 25; | ||||||
|   tkHelper   = 26; |   tkHelper   = 26; | ||||||
|   tkFile     = 27; |   tkFile     = 27; | ||||||
|  |   tkClassRef = 28; | ||||||
|  |   tkPointer  = 29; | ||||||
| 
 | 
 | ||||||
|   otSByte     = 0; |   otSByte     = 0; | ||||||
|   otUByte     = 1; |   otUByte     = 1; | ||||||
|  | |||||||
| @ -18,33 +18,36 @@ | |||||||
| Const | Const | ||||||
|    // please update tkManagedTypes below if you add new
 |    // please update tkManagedTypes below if you add new
 | ||||||
|    // values
 |    // values
 | ||||||
|    tkUnknown       = 0; |    tkUnknown        = 0; | ||||||
|    tkInteger       = 1; |    tkInteger        = 1; | ||||||
|    tkChar          = 2; |    tkChar           = 2; | ||||||
|    tkEnumeration   = 3; |    tkEnumeration    = 3; | ||||||
|    tkFloat         = 4; |    tkFloat          = 4; | ||||||
|    tkSet           = 5; |    tkSet            = 5; | ||||||
|    tkMethod        = 6; |    tkMethod         = 6; | ||||||
|    tkSString       = 7; |    tkSString        = 7; | ||||||
|    tkString        = tkSString; |    tkString         = tkSString; | ||||||
|    tkLString       = 8; |    tkLString        = 8; | ||||||
|    tkAString       = 9; |    tkAString        = 9; | ||||||
|    tkWString       = 10; |    tkWString        = 10; | ||||||
|    tkVariant       = 11; |    tkVariant        = 11; | ||||||
|    tkArray         = 12; |    tkArray          = 12; | ||||||
|    tkRecord        = 13; |    tkRecord         = 13; | ||||||
|    tkInterface     = 14; |    tkInterface      = 14; | ||||||
|    tkClass         = 15; |    tkClass          = 15; | ||||||
|    tkObject        = 16; |    tkObject         = 16; | ||||||
|    tkWChar         = 17; |    tkWChar          = 17; | ||||||
|    tkBool          = 18; |    tkBool           = 18; | ||||||
|    tkInt64         = 19; |    tkInt64          = 19; | ||||||
|    tkQWord         = 20; |    tkQWord          = 20; | ||||||
|    tkDynArray      = 21; |    tkDynArray       = 21; | ||||||
|    tkInterfaceCorba = 22; |    tkInterfaceCorba = 22; | ||||||
|    tkProcVar       = 23; |    tkProcVar        = 23; | ||||||
|    tkUString       = 24; |    tkUString        = 24; | ||||||
|    tkHelper        = 26; |    tkHelper         = 26; | ||||||
|  |    tkFile           = 27; | ||||||
|  |    tkClassRef       = 28; | ||||||
|  |    tkPointer        = 29; | ||||||
| 
 | 
 | ||||||
|   // all potentially managed types
 |   // all potentially managed types
 | ||||||
|   tkManagedTypes   = [tkAstring,tkWstring,tkUstring,tkArray, |   tkManagedTypes   = [tkAstring,tkWstring,tkUstring,tkArray, | ||||||
|  | |||||||
| @ -18,33 +18,36 @@ | |||||||
| Const | Const | ||||||
|    // please update tkManagedTypes below if you add new
 |    // please update tkManagedTypes below if you add new
 | ||||||
|    // values
 |    // values
 | ||||||
|    tkUnknown       = 0; |    tkUnknown        = 0; | ||||||
|    tkInteger       = 1; |    tkInteger        = 1; | ||||||
|    tkChar          = 2; |    tkChar           = 2; | ||||||
|    tkEnumeration   = 3; |    tkEnumeration    = 3; | ||||||
|    tkFloat         = 4; |    tkFloat          = 4; | ||||||
|    tkSet           = 5; |    tkSet            = 5; | ||||||
|    tkMethod        = 6; |    tkMethod         = 6; | ||||||
|    tkSString       = 7; |    tkSString        = 7; | ||||||
|    tkString        = tkSString; |    tkString         = tkSString; | ||||||
|    tkLString       = 8; |    tkLString        = 8; | ||||||
|    tkAString       = 9; |    tkAString        = 9; | ||||||
|    tkWString       = 10; |    tkWString        = 10; | ||||||
|    tkVariant       = 11; |    tkVariant        = 11; | ||||||
|    tkArray         = 12; |    tkArray          = 12; | ||||||
|    tkRecord        = 13; |    tkRecord         = 13; | ||||||
|    tkInterface     = 14; |    tkInterface      = 14; | ||||||
|    tkClass         = 15; |    tkClass          = 15; | ||||||
|    tkObject        = 16; |    tkObject         = 16; | ||||||
|    tkWChar         = 17; |    tkWChar          = 17; | ||||||
|    tkBool          = 18; |    tkBool           = 18; | ||||||
|    tkInt64         = 19; |    tkInt64          = 19; | ||||||
|    tkQWord         = 20; |    tkQWord          = 20; | ||||||
|    tkDynArray      = 21; |    tkDynArray       = 21; | ||||||
|    tkInterfaceCorba = 22; |    tkInterfaceCorba = 22; | ||||||
|    tkProcVar       = 23; |    tkProcVar        = 23; | ||||||
|    tkUString       = 24; |    tkUString        = 24; | ||||||
|    tkHelper        = 26; |    tkHelper         = 26; | ||||||
|  |    tkFile           = 27; | ||||||
|  |    tkClassRef       = 28; | ||||||
|  |    tkPointer        = 29; | ||||||
| 
 | 
 | ||||||
|   // all potentially managed types
 |   // all potentially managed types
 | ||||||
|   tkManagedTypes   = [tkAstring,tkWstring,tkUstring,tkArray, |   tkManagedTypes   = [tkAstring,tkWstring,tkUstring,tkArray, | ||||||
|  | |||||||
| @ -43,7 +43,7 @@ unit typinfo; | |||||||
|                    tkWString,tkVariant,tkArray,tkRecord,tkInterface, |                    tkWString,tkVariant,tkArray,tkRecord,tkInterface, | ||||||
|                    tkClass,tkObject,tkWChar,tkBool,tkInt64,tkQWord, |                    tkClass,tkObject,tkWChar,tkBool,tkInt64,tkQWord, | ||||||
|                    tkDynArray,tkInterfaceRaw,tkProcVar,tkUString,tkUChar, |                    tkDynArray,tkInterfaceRaw,tkProcVar,tkUString,tkUChar, | ||||||
|                    tkHelper); |                    tkHelper,tkFile,tkClassRef,tkPointer); | ||||||
| 
 | 
 | ||||||
|        TOrdType  = (otSByte,otUByte,otSWord,otUWord,otSLong,otULong); |        TOrdType  = (otSByte,otUByte,otSWord,otUWord,otSLong,otULong); | ||||||
| 
 | 
 | ||||||
| @ -202,6 +202,14 @@ unit typinfo; | |||||||
|               elType     : PPTypeInfo; |               elType     : PPTypeInfo; | ||||||
|               DynUnitName: ShortStringBase |               DynUnitName: ShortStringBase | ||||||
|               ); |               ); | ||||||
|  |             tkClassRef: | ||||||
|  |               ( | ||||||
|  |               InstanceType: PTypeInfo; | ||||||
|  |               ); | ||||||
|  |             tkPointer: | ||||||
|  |               ( | ||||||
|  |               RefType: PTypeInfo; | ||||||
|  |               ); | ||||||
|       end; |       end; | ||||||
| 
 | 
 | ||||||
|       // unsed, just for completeness |       // unsed, just for completeness | ||||||
|  | |||||||
| @ -6,13 +6,13 @@ Program trtti1; | |||||||
| Uses | Uses | ||||||
|   Typinfo; |   Typinfo; | ||||||
| 
 | 
 | ||||||
| Const TypeNames : Array [TTYpeKind] of string[15] = | Const TypeNames : Array [TTypeKind] of string[15] = | ||||||
|                     ('Unknown','Integer','Char','Enumeration', |                     ('Unknown','Integer','Char','Enumeration', | ||||||
|                      'Float','Set','Method','ShortString','LongString', |                      'Float','Set','Method','ShortString','LongString', | ||||||
|                      'AnsiString','WideString','Variant','Array','Record', |                      'AnsiString','WideString','Variant','Array','Record', | ||||||
|                      'Interface','Class','Object','WideChar','Bool','Int64','QWord', |                      'Interface','Class','Object','WideChar','Bool','Int64','QWord', | ||||||
|                      'DynamicArray','RawInterface','ProcVar','UnicodeString','UnicodeChar', |                      'DynamicArray','RawInterface','ProcVar','UnicodeString','UnicodeChar', | ||||||
| 					 'Helper'); |                      'Helper','File','ClassRef','Pointer'); | ||||||
| 
 | 
 | ||||||
| Const OrdinalTypes = [tkInteger,tkChar,tkENumeration,tkbool]; | Const OrdinalTypes = [tkInteger,tkChar,tkENumeration,tkbool]; | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										46
									
								
								tests/test/trtti6.pp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								tests/test/trtti6.pp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,46 @@ | |||||||
|  | program ptr_classref_test; | ||||||
|  | 
 | ||||||
|  | {$mode objfpc}{$H+} | ||||||
|  | 
 | ||||||
|  | uses | ||||||
|  |   typinfo; | ||||||
|  | 
 | ||||||
|  | type | ||||||
|  |   {$M+} | ||||||
|  |   TReferredClass = class | ||||||
|  |   end; | ||||||
|  |   {$M-} | ||||||
|  | 
 | ||||||
|  |   TClassRef = class of TReferredClass; | ||||||
|  | 
 | ||||||
|  |   {$M+} | ||||||
|  |   TClass = class | ||||||
|  |   private | ||||||
|  |     FRef: TClassRef; | ||||||
|  |   published | ||||||
|  |     property Ref: TClassRef read FRef; | ||||||
|  |   end; | ||||||
|  |   {$M-} | ||||||
|  | 
 | ||||||
|  |   TPtr = ^UnicodeString; | ||||||
|  | 
 | ||||||
|  | var | ||||||
|  |   Info: PTypeInfo; | ||||||
|  |   Data: PTypeData; | ||||||
|  | begin | ||||||
|  |   // first check TClass.Ref property | ||||||
|  |   Info := GetPropInfo(PTypeInfo(TClass.ClassInfo), 'Ref')^.PropType; | ||||||
|  |   if Info^.Kind <> tkClassRef then | ||||||
|  |     halt(1); | ||||||
|  |   Data := GetTypeData(Info); | ||||||
|  |   if Data^.RefType <> TReferredClass.ClassInfo then | ||||||
|  |     halt(2); | ||||||
|  |   // next check TRefferedClass.P method | ||||||
|  |   Info := TypeInfo(TPtr); | ||||||
|  |   if Info^.Kind <> tkPointer then | ||||||
|  |     halt(3); | ||||||
|  |   Data := GetTypeData(Info); | ||||||
|  |   if Data^.RefType <> TypeInfo(UnicodeString) then | ||||||
|  |     halt(4); | ||||||
|  | end. | ||||||
|  | 
 | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 paul
						paul