Bladeren bron

New class function tsymsym.find_by_number() to find a tsymsym instance based on it's number. The list containing the mapping from the indices to the symbols is created and freed using the init/done registration mechanism.

git-svn-id: trunk@33889 -
svenbarth 9 jaren geleden
bovenliggende
commit
2ed7a6de68
1 gewijzigde bestanden met toevoegingen van 40 en 0 verwijderingen
  1. 40 0
      compiler/symsym.pas

+ 40 - 0
compiler/symsym.pas

@@ -426,6 +426,7 @@ interface
           { do not override this routine in platform-specific subclasses,
           { do not override this routine in platform-specific subclasses,
             override ppuwrite_platform instead }
             override ppuwrite_platform instead }
           procedure ppuwrite(ppufile:tcompilerppufile);override;final;
           procedure ppuwrite(ppufile:tcompilerppufile);override;final;
+          class function find_by_number(l:longint):tsyssym;
        end;
        end;
        tsyssymclass = class of tsyssym;
        tsyssymclass = class of tsyssym;
 
 
@@ -2634,17 +2635,34 @@ implementation
                                   TSYSSYM
                                   TSYSSYM
 ****************************************************************************}
 ****************************************************************************}
 
 
+
+    var
+      syssym_list : TFPHashObjectList;
+
+
     constructor tsyssym.create(const n : string;l : longint);
     constructor tsyssym.create(const n : string;l : longint);
+      var
+        s : shortstring;
       begin
       begin
          inherited create(syssym,n,true);
          inherited create(syssym,n,true);
          number:=l;
          number:=l;
+         str(l,s);
+         if assigned(syssym_list.find(s)) then
+           internalerror(2016060303);
+         syssym_list.add(s,self);
       end;
       end;
 
 
     constructor tsyssym.ppuload(ppufile:tcompilerppufile);
     constructor tsyssym.ppuload(ppufile:tcompilerppufile);
+      var
+        s : shortstring;
       begin
       begin
          inherited ppuload(syssym,ppufile);
          inherited ppuload(syssym,ppufile);
          number:=ppufile.getlongint;
          number:=ppufile.getlongint;
          ppuload_platform(ppufile);
          ppuload_platform(ppufile);
+         str(number,s);
+         if assigned(syssym_list.find(s)) then
+           internalerror(2016060304);
+         syssym_list.add(s,self);
       end;
       end;
 
 
     destructor tsyssym.destroy;
     destructor tsyssym.destroy;
@@ -2660,6 +2678,14 @@ implementation
       end;
       end;
 
 
 
 
+    class function tsyssym.find_by_number(l:longint):tsyssym;
+      var
+        s : shortstring;
+      begin
+        str(l,s);
+        result:=tsyssym(syssym_list.find(s));
+      end;
+
 {*****************************************************************************
 {*****************************************************************************
                                  TMacro
                                  TMacro
 *****************************************************************************}
 *****************************************************************************}
@@ -2728,4 +2754,18 @@ implementation
       end;
       end;
 
 
 
 
+    procedure init_symsym;
+      begin
+        syssym_list:=tfphashobjectlist.create(false);
+      end;
+
+
+    procedure done_symsym;
+      begin
+        syssym_list.free;
+      end;
+
+
+initialization
+  register_initdone_proc(@init_symsym,@done_symsym);
 end.
 end.