Browse Source

* moved functionality to create a global recorddef based on a tfplist of
tdefs to the new trecorddef.create_global_from_deflist() constructor

git-svn-id: branches/hlcgllvm@28322 -

Jonas Maebe 11 năm trước cách đây
mục cha
commit
5a49727cdf
2 tập tin đã thay đổi với 47 bổ sung22 xóa
  1. 1 22
      compiler/llvm/llvmdef.pas
  2. 46 0
      compiler/symdef.pas

+ 1 - 22
compiler/llvm/llvmdef.pas

@@ -657,28 +657,7 @@ implementation
           internalerror(2014012002);
         res:=current_module.llvmdefs.FindOrAdd(@typename[1],length(typename));
         if not assigned(res^.Data) then
-          begin
-            oldsymtablestack:=symtablestack;
-            { do not simply push/pop current_module.localsymtable, because
-              that can have side-effects (e.g., it removes helpers) }
-            symtablestack:=nil;
-
-            hrecst:=trecordsymtable.create(typename,packrecords);
-            hrecdef:=trecorddef.create(typename,hrecst);
-            for i:=0 to fieldtypes.count-1 do
-              begin
-                sym:=tfieldvarsym.create('$f'+tostr(i),vs_value,tdef(fieldtypes[i]),[]);
-                hrecst.insert(sym);
-                hrecst.addfield(sym,vis_hidden);
-              end;
-
-            res^.Data:=hrecdef;
-            if assigned(current_module.localsymtable) then
-              current_module.localsymtable.insertdef(tdef(res^.Data))
-            else
-              current_module.globalsymtable.insertdef(tdef(res^.Data));
-            symtablestack:=oldsymtablestack;
-          end;
+          res^.Data:=crecorddef.create_global_from_deflist(typename,fieldtypes,packrecords);
         result:=trecorddef(res^.Data);
       end;
 

+ 46 - 0
compiler/symdef.pas

@@ -286,6 +286,7 @@ interface
           variantrecdesc : pvariantrecdesc;
           isunion       : boolean;
           constructor create(const n:string; p:TSymtable);virtual;
+          constructor create_global_from_deflist(n: string; fieldtypes: tfplist; packrecords: shortint); virtual;
           constructor ppuload(ppufile:tcompilerppufile);
           destructor destroy;override;
           function getcopy : tstoreddef;override;
@@ -3897,6 +3898,51 @@ implementation
       end;
 
 
+    constructor trecorddef.create_global_from_deflist(n: string; fieldtypes: tfplist; packrecords: shortint);
+      var
+        i: longint;
+        hdef: tdef;
+        sym: tfieldvarsym;
+        oldsymtablestack: tsymtablestack;
+        definedname: boolean;
+      begin
+        { construct name }
+        definedname:=n<>'';
+        if not definedname then
+          n:='$InternalRec'+tostr(current_module.deflist.count);
+        oldsymtablestack:=symtablestack;
+        { do not simply push/pop current_module.localsymtable, because
+          that can have side-effects (e.g., it removes helpers) }
+        symtablestack:=nil;
+
+        symtable:=trecordsymtable.create(n,packrecords);
+        symtable.defowner:=self;
+        isunion:=false;
+        for i:=0 to fieldtypes.count-1 do
+          begin
+            sym:=cfieldvarsym.create('$f'+tostr(i),vs_value,tdef(fieldtypes[i]),[]);
+            symtable.insert(sym);
+            trecordsymtable(symtable).addfield(sym,vis_hidden);
+          end;
+        inherited create(n,recorddef);
+        if assigned(current_module.localsymtable) then
+          begin
+            current_module.localsymtable.insertdef(self);
+            { if we specified a name, then we'll probably wan't to look up the
+              type again by name too }
+            if definedname then
+              current_module.localsymtable.insert(ctypesym.create(n,self));
+          end
+        else
+          begin
+            current_module.globalsymtable.insertdef(self);
+            if definedname then
+              current_module.localsymtable.insert(ctypesym.create(n,self));
+          end;
+        symtablestack:=oldsymtablestack;
+      end;
+
+
     constructor trecorddef.ppuload(ppufile:tcompilerppufile);
 
       procedure readvariantrecdesc(var variantrecdesc : pvariantrecdesc);