Przeglądaj źródła

* getsym redesign, removed the globals srsym,srsymtable

peter 24 lat temu
rodzic
commit
d8abf76f6b

+ 6 - 1
compiler/i386/ag386bin.pas

@@ -604,6 +604,8 @@ implementation
                            end;
                            end;
                          top_symbol :
                          top_symbol :
                            begin
                            begin
+                             if sym=nil then
+                              sym:=sym;
                              UsedAsmSymbolListInsert(sym);
                              UsedAsmSymbolListInsert(sym);
                            end;
                            end;
                        end;
                        end;
@@ -1031,7 +1033,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.5  2001-03-05 21:39:11  peter
+  Revision 1.6  2001-03-11 22:58:51  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.5  2001/03/05 21:39:11  peter
     * changed to class with common TAssembler also for internal assembler
     * changed to class with common TAssembler also for internal assembler
 
 
   Revision 1.4  2000/12/25 00:07:31  peter
   Revision 1.4  2000/12/25 00:07:31  peter

+ 8 - 3
compiler/i386/n386cal.pas

@@ -261,7 +261,9 @@ implementation
          { we must pop this size also after !! }
          { we must pop this size also after !! }
 {        must_pop : boolean; }
 {        must_pop : boolean; }
          pop_size : longint;
          pop_size : longint;
+{$ifdef dummy}
          push_size : longint;
          push_size : longint;
+{$endif}
          pop_esp : boolean;
          pop_esp : boolean;
          pop_allowed : boolean;
          pop_allowed : boolean;
          regs_to_push : byte;
          regs_to_push : byte;
@@ -390,7 +392,7 @@ implementation
 {$endif GDB}
 {$endif GDB}
              end;
              end;
           end;
           end;
-         {
+{$ifdef dummy}
          if pop_allowed and (cs_align in aktglobalswitches) then
          if pop_allowed and (cs_align in aktglobalswitches) then
            begin
            begin
               pop_esp:=true;
               pop_esp:=true;
@@ -411,7 +413,7 @@ implementation
               emit_reg(A_PUSH,S_L,R_EDI);
               emit_reg(A_PUSH,S_L,R_EDI);
            end
            end
          else
          else
-         }
+{$endif dummy}
            pop_esp:=false;
            pop_esp:=false;
          if (resulttype<>pdef(voiddef)) and
          if (resulttype<>pdef(voiddef)) and
             ret_in_param(resulttype) then
             ret_in_param(resulttype) then
@@ -1587,7 +1589,10 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.18  2001-01-27 21:29:35  florian
+  Revision 1.19  2001-03-11 22:58:51  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.18  2001/01/27 21:29:35  florian
      * behavior -Oa optimized
      * behavior -Oa optimized
 
 
   Revision 1.17  2001/01/08 21:46:46  peter
   Revision 1.17  2001/01/08 21:46:46  peter

+ 7 - 3
compiler/i386/n386mem.pas

@@ -91,7 +91,7 @@ implementation
 {$endif GDB}
 {$endif GDB}
       globtype,systems,
       globtype,systems,
       cutils,verbose,globals,
       cutils,verbose,globals,
-      symconst,symbase,symdef,symsym,symtable,aasm,types,
+      symconst,symbase,symtype,symdef,symsym,symtable,aasm,types,
       hcodegen,temp_gen,pass_2,
       hcodegen,temp_gen,pass_2,
       pass_1,nld,ncon,nadd,
       pass_1,nld,ncon,nadd,
       cpubase,cpuasm,
       cpubase,cpuasm,
@@ -462,6 +462,7 @@ implementation
          hp  : preference;
          hp  : preference;
          href : treference;
          href : treference;
          tai : Taicpu;
          tai : Taicpu;
+         srsym : psym;
          pushed : tpushed;
          pushed : tpushed;
          hightree : tnode;
          hightree : tnode;
          hl,otl,ofl : pasmlabel;
          hl,otl,ofl : pasmlabel;
@@ -741,7 +742,7 @@ implementation
                         parraydef(left.resulttype)^.genrangecheck;
                         parraydef(left.resulttype)^.genrangecheck;
                         href.symbol:=newasmsymbol(parraydef(left.resulttype)^.getrangecheckstring);
                         href.symbol:=newasmsymbol(parraydef(left.resulttype)^.getrangecheckstring);
                         href.offset:=4;
                         href.offset:=4;
-                        getsymonlyin(tloadnode(left).symtable,
+                        srsym:=searchsymonlyin(tloadnode(left).symtable,
                           'high'+pvarsym(tloadnode(left).symtableentry)^.name);
                           'high'+pvarsym(tloadnode(left).symtableentry)^.name);
                         hightree:=genloadnode(pvarsym(srsym),tloadnode(left).symtable);
                         hightree:=genloadnode(pvarsym(srsym),tloadnode(left).symtable);
                         firstpass(hightree);
                         firstpass(hightree);
@@ -1060,7 +1061,10 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.9  2001-02-02 22:38:00  peter
+  Revision 1.10  2001-03-11 22:58:52  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.9  2001/02/02 22:38:00  peter
     * fixed crash with new(precord), merged
     * fixed crash with new(precord), merged
 
 
   Revision 1.8  2000/12/25 00:07:33  peter
   Revision 1.8  2000/12/25 00:07:33  peter

+ 9 - 11
compiler/i386/n386util.pas

@@ -1083,19 +1083,13 @@ implementation
        equal the check is also insert (needed for succ,pref,inc,dec)
        equal the check is also insert (needed for succ,pref,inc,dec)
      }
      }
       var
       var
-        neglabel,
-        poslabel : pasmlabel;
-        href   : treference;
-        rstr   : string;
-        hreg   : tregister;
+        neglabel : pasmlabel;
         opsize : topsize;
         opsize : topsize;
         op     : tasmop;
         op     : tasmop;
         fromdef : pdef;
         fromdef : pdef;
         lto,hto,
         lto,hto,
         lfrom,hfrom : longint;
         lfrom,hfrom : longint;
-        doublebound,
-        is_reg,
-        popecx : boolean;
+        is_reg : boolean;
       begin
       begin
         { range checking on and range checkable value? }
         { range checking on and range checkable value? }
         if not(cs_check_range in aktlocalswitches) or
         if not(cs_check_range in aktlocalswitches) or
@@ -1172,7 +1166,7 @@ implementation
               { since from is signed, values > maxlongint are < 0 and must }
               { since from is signed, values > maxlongint are < 0 and must }
               { be rejected                                                }
               { be rejected                                                }
               if hto < 0 then
               if hto < 0 then
-                hto := maxlongint; 
+                hto := maxlongint;
             end
             end
           else
           else
             { from is unsigned, to is signed }
             { from is unsigned, to is signed }
@@ -1253,10 +1247,11 @@ implementation
     procedure push_shortstring_length(p:tnode);
     procedure push_shortstring_length(p:tnode);
       var
       var
         hightree : tnode;
         hightree : tnode;
+        srsym    : psym;
       begin
       begin
         if is_open_string(p.resulttype) then
         if is_open_string(p.resulttype) then
          begin
          begin
-           getsymonlyin(tloadnode(p).symtable,'high'+pvarsym(tloadnode(p).symtableentry)^.name);
+           srsym:=searchsymonlyin(tloadnode(p).symtable,'high'+pvarsym(tloadnode(p).symtableentry)^.name);
            hightree:=genloadnode(pvarsym(srsym),tloadnode(p).symtable);
            hightree:=genloadnode(pvarsym(srsym),tloadnode(p).symtable);
            firstpass(hightree);
            firstpass(hightree);
            secondpass(hightree);
            secondpass(hightree);
@@ -1482,7 +1477,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.12  2001-03-04 10:26:56  jonas
+  Revision 1.13  2001-03-11 22:58:52  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.12  2001/03/04 10:26:56  jonas
     * new rangecheck code now handles conversion between signed and cardinal types correctly
     * new rangecheck code now handles conversion between signed and cardinal types correctly
 
 
   Revision 1.11  2001/03/03 12:41:22  jonas
   Revision 1.11  2001/03/03 12:41:22  jonas

+ 18 - 15
compiler/i386/ra386att.pas

@@ -43,7 +43,7 @@ Implementation
        { aasm }
        { aasm }
        cpubase,aasm,
        cpubase,aasm,
        { symtable }
        { symtable }
-       symconst,symtype,symsym,symtable,types,
+       symconst,symbase,symtype,symsym,symtable,types,
        { pass 1 }
        { pass 1 }
        nbas,
        nbas,
        { parser }
        { parser }
@@ -818,6 +818,7 @@ var
   errorflag : boolean;
   errorflag : boolean;
   prevtok : tasmtoken;
   prevtok : tasmtoken;
   sym : psym;
   sym : psym;
+  srsymtable : psymtable;
   hl  : PAsmLabel;
   hl  : PAsmLabel;
 Begin
 Begin
   asmsym:='';
   asmsym:='';
@@ -947,16 +948,16 @@ Begin
               BuildRecordOffsetSize(tempstr,k,l)
               BuildRecordOffsetSize(tempstr,k,l)
              else
              else
               begin
               begin
-                getsym(tempstr,false);
-                if assigned(srsym) then
+                searchsym(tempstr,sym,srsymtable);
+                if assigned(sym) then
                  begin
                  begin
-                   case srsym^.typ of
+                   case sym^.typ of
                      varsym :
                      varsym :
-                       l:=pvarsym(srsym)^.getsize;
+                       l:=pvarsym(sym)^.getsize;
                      typedconstsym :
                      typedconstsym :
-                       l:=ptypedconstsym(srsym)^.getsize;
+                       l:=ptypedconstsym(sym)^.getsize;
                      typesym :
                      typesym :
-                       l:=ptypesym(srsym)^.restype.def^.size;
+                       l:=ptypesym(sym)^.restype.def^.size;
                      else
                      else
                        Message(asmr_e_wrong_sym_type);
                        Message(asmr_e_wrong_sym_type);
                    end;
                    end;
@@ -991,24 +992,23 @@ Begin
                hs:=hl^.name
                hs:=hl^.name
              else
              else
               begin
               begin
-                getsym(tempstr,false);
-                sym:=srsym;
+                searchsym(tempstr,sym,srsymtable);
                 if assigned(sym) then
                 if assigned(sym) then
                  begin
                  begin
-                   case srsym^.typ of
+                   case sym^.typ of
                      varsym :
                      varsym :
                        begin
                        begin
                          if sym^.owner^.symtabletype in [localsymtable,parasymtable] then
                          if sym^.owner^.symtabletype in [localsymtable,parasymtable] then
                           Message(asmr_e_no_local_or_para_allowed);
                           Message(asmr_e_no_local_or_para_allowed);
-                         hs:=pvarsym(srsym)^.mangledname;
+                         hs:=pvarsym(sym)^.mangledname;
                        end;
                        end;
                      typedconstsym :
                      typedconstsym :
-                       hs:=ptypedconstsym(srsym)^.mangledname;
+                       hs:=ptypedconstsym(sym)^.mangledname;
                      procsym :
                      procsym :
-                       hs:=pprocsym(srsym)^.mangledname;
+                       hs:=pprocsym(sym)^.mangledname;
                      typesym :
                      typesym :
                        begin
                        begin
-                         if not(ptypesym(srsym)^.restype.def^.deftype in [recorddef,objectdef]) then
+                         if not(ptypesym(sym)^.restype.def^.deftype in [recorddef,objectdef]) then
                           Message(asmr_e_wrong_sym_type);
                           Message(asmr_e_wrong_sym_type);
                        end;
                        end;
                      else
                      else
@@ -2120,7 +2120,10 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.6  2000-12-25 00:07:34  peter
+  Revision 1.7  2001-03-11 22:58:52  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.6  2000/12/25 00:07:34  peter
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
       tlinkedlist objects)
       tlinkedlist objects)
 
 

+ 9 - 6
compiler/i386/ra386dir.pas

@@ -42,7 +42,7 @@ interface
        { aasm }
        { aasm }
        cpubase,aasm,
        cpubase,aasm,
        { symtable }
        { symtable }
-       symconst,symtype,symdef,symsym,symtable,types,
+       symconst,symbase,symtype,symdef,symsym,symtable,types,
        { pass 1 }
        { pass 1 }
        nbas,
        nbas,
        { parser }
        { parser }
@@ -62,7 +62,8 @@ interface
          retstr,s,hs : string;
          retstr,s,hs : string;
          c : char;
          c : char;
          ende : boolean;
          ende : boolean;
-         sym : psym;
+         srsym,sym : psym;
+         srsymtable : psymtable;
          code : TAAsmoutput;
          code : TAAsmoutput;
          i,l : longint;
          i,l : longint;
 
 
@@ -121,7 +122,7 @@ interface
                          begin
                          begin
                             if c=':' then
                             if c=':' then
                               begin
                               begin
-                                getsym(upper(hs),false);
+                                searchsym(upper(hs),srsym,srsymtable);
                                 if srsym<>nil then
                                 if srsym<>nil then
                                   if (srsym^.typ = labelsym) then
                                   if (srsym^.typ = labelsym) then
                                     Begin
                                     Begin
@@ -208,8 +209,7 @@ interface
 
 
                                         begin
                                         begin
 {$ifndef IGNOREGLOBALVAR}
 {$ifndef IGNOREGLOBALVAR}
-                                           getsym(upper(hs),false);
-                                           sym:=srsym;
+                                           searchsym(upper(hs),sym,srsymtable);
                                            if assigned(sym) and (sym^.owner^.symtabletype in [unitsymtable,
                                            if assigned(sym) and (sym^.owner^.symtabletype in [unitsymtable,
                                              globalsymtable,staticsymtable]) then
                                              globalsymtable,staticsymtable]) then
                                              begin
                                              begin
@@ -288,7 +288,10 @@ interface
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.4  2000-12-25 00:07:34  peter
+  Revision 1.5  2001-03-11 22:58:52  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.4  2000/12/25 00:07:34  peter
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
       tlinkedlist objects)
       tlinkedlist objects)
 
 

+ 18 - 16
compiler/i386/ra386int.pas

@@ -43,7 +43,7 @@ Implementation
        { aasm }
        { aasm }
        cpubase,aasm,
        cpubase,aasm,
        { symtable }
        { symtable }
-       symconst,symtype,symsym,symtable,types,
+       symconst,symbase,symtype,symsym,symtable,types,
        { pass 1 }
        { pass 1 }
        nbas,
        nbas,
        { parser }
        { parser }
@@ -705,6 +705,7 @@ var
   prevtok : tasmtoken;
   prevtok : tasmtoken;
   hl : PAsmLabel;
   hl : PAsmLabel;
   sym : psym;
   sym : psym;
+  srsymtable : psymtable;
 Begin
 Begin
   { reset }
   { reset }
   value:=0;
   value:=0;
@@ -812,16 +813,16 @@ Begin
               BuildRecordOffsetSize(tempstr,k,l)
               BuildRecordOffsetSize(tempstr,k,l)
              else
              else
               begin
               begin
-                getsym(tempstr,false);
-                if assigned(srsym) then
+                searchsym(tempstr,sym,srsymtable);
+                if assigned(sym) then
                  begin
                  begin
-                   case srsym^.typ of
+                   case sym^.typ of
                      varsym :
                      varsym :
-                       l:=pvarsym(srsym)^.getsize;
+                       l:=pvarsym(sym)^.getsize;
                      typedconstsym :
                      typedconstsym :
-                       l:=ptypedconstsym(srsym)^.getsize;
+                       l:=ptypedconstsym(sym)^.getsize;
                      typesym :
                      typesym :
-                       l:=ptypesym(srsym)^.restype.def^.size;
+                       l:=ptypesym(sym)^.restype.def^.size;
                      else
                      else
                        Message(asmr_e_wrong_sym_type);
                        Message(asmr_e_wrong_sym_type);
                    end;
                    end;
@@ -877,24 +878,23 @@ Begin
                hs:=hl^.name
                hs:=hl^.name
              else
              else
               begin
               begin
-                getsym(tempstr,false);
-                sym:=srsym;
+                searchsym(tempstr,sym,srsymtable);
                 if assigned(sym) then
                 if assigned(sym) then
                  begin
                  begin
-                   case srsym^.typ of
+                   case sym^.typ of
                      varsym :
                      varsym :
                        begin
                        begin
                          if sym^.owner^.symtabletype in [localsymtable,parasymtable] then
                          if sym^.owner^.symtabletype in [localsymtable,parasymtable] then
                           Message(asmr_e_no_local_or_para_allowed);
                           Message(asmr_e_no_local_or_para_allowed);
-                         hs:=pvarsym(srsym)^.mangledname;
+                         hs:=pvarsym(sym)^.mangledname;
                        end;
                        end;
                      typedconstsym :
                      typedconstsym :
-                       hs:=ptypedconstsym(srsym)^.mangledname;
+                       hs:=ptypedconstsym(sym)^.mangledname;
                      procsym :
                      procsym :
-                       hs:=pprocsym(srsym)^.mangledname;
+                       hs:=pprocsym(sym)^.mangledname;
                      typesym :
                      typesym :
                        begin
                        begin
-                         if not(ptypesym(srsym)^.restype.def^.deftype in [recorddef,objectdef]) then
+                         if not(ptypesym(sym)^.restype.def^.deftype in [recorddef,objectdef]) then
                           Message(asmr_e_wrong_sym_type);
                           Message(asmr_e_wrong_sym_type);
                        end;
                        end;
                      else
                      else
@@ -1605,7 +1605,6 @@ Procedure T386IntelInstruction.BuildOpCode;
 var
 var
   PrefixOp,OverrideOp: tasmop;
   PrefixOp,OverrideOp: tasmop;
   size : topsize;
   size : topsize;
-  lasttoken : tasmtoken;
   operandnum : longint;
   operandnum : longint;
 Begin
 Begin
   PrefixOp:=A_None;
   PrefixOp:=A_None;
@@ -1950,7 +1949,10 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.9  2001-02-20 21:51:36  peter
+  Revision 1.10  2001-03-11 22:58:52  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.9  2001/02/20 21:51:36  peter
     * fpu fixes (merged)
     * fpu fixes (merged)
 
 
   Revision 1.8  2001/02/09 23:42:49  peter
   Revision 1.8  2001/02/09 23:42:49  peter

+ 51 - 2
compiler/pbase.pas

@@ -29,7 +29,7 @@ interface
     uses
     uses
        cutils,cobjects,cclasses,
        cutils,cobjects,cclasses,
        tokens,globals,
        tokens,globals,
-       symbase,symdef,symsym
+       symconst,symbase,symtype,symdef,symsym,symtable
 {$ifdef fixLeaksOnError}
 {$ifdef fixLeaksOnError}
        ,comphook
        ,comphook
 {$endif fixLeaksOnError}
 {$endif fixLeaksOnError}
@@ -98,6 +98,10 @@ interface
     { consumes tokens while they are semicolons }
     { consumes tokens while they are semicolons }
     procedure emptystats;
     procedure emptystats;
 
 
+    { consume a symbol, if not found give an error and
+      and return an errorsym }
+    function consume_sym(var srsym:psym;var srsymtable:psymtable):boolean;
+
     { reads a list of identifiers into a string list }
     { reads a list of identifiers into a string list }
     function idlist : tidstringlist;
     function idlist : tidstringlist;
 
 
@@ -239,6 +243,48 @@ implementation
       end;
       end;
 
 
 
 
+
+    function consume_sym(var srsym:psym;var srsymtable:psymtable):boolean;
+      begin
+        { first check for identifier }
+        if token<>_ID then
+         begin
+           consume(_ID);
+           srsym:=generrorsym;
+           srsymtable:=nil;
+           consume_sym:=false;
+           exit;
+         end;
+        searchsym(pattern,srsym,srsymtable);
+        if assigned(srsym) then
+         begin
+           if (srsym^.typ=unitsym) then
+            begin
+              { only allow unit.symbol access if the name was
+                found in the current module }
+              if srsym^.owner^.unitid=0 then
+               begin
+                 consume(_ID);
+                 consume(_POINT);
+                 srsymtable:=punitsym(srsym)^.unitsymtable;
+                 srsym:=searchsymonlyin(srsymtable,pattern);
+               end
+              else
+               srsym:=nil;
+            end;
+         end;
+        { if nothing found give error and return errorsym }
+        if srsym=nil then
+         begin
+           identifier_not_found(pattern);
+           srsym:=generrorsym;
+           srsymtable:=nil;
+         end;
+        consume(_ID);
+        consume_sym:=assigned(srsym);
+      end;
+
+
     { reads a list of identifiers into a string list }
     { reads a list of identifiers into a string list }
     function idlist : tidstringlist;
     function idlist : tidstringlist;
       var
       var
@@ -276,7 +322,10 @@ end.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.7  2000-12-25 00:07:27  peter
+  Revision 1.8  2001-03-11 22:58:49  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.7  2000/12/25 00:07:27  peter
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
       tlinkedlist objects)
       tlinkedlist objects)
 
 

+ 9 - 4
compiler/pdecl.pas

@@ -269,6 +269,8 @@ implementation
         hpd,pd : pdef;
         hpd,pd : pdef;
         stpos  : tfileposinfo;
         stpos  : tfileposinfo;
         again  : boolean;
         again  : boolean;
+        srsym  : psym;
+        srsymtable : psymtable;
       begin
       begin
          { Check only typesyms or record/object fields }
          { Check only typesyms or record/object fields }
          case psym(p)^.typ of
          case psym(p)^.typ of
@@ -305,7 +307,7 @@ implementation
                     akttokenpos:=pforwarddef(hpd)^.forwardpos;
                     akttokenpos:=pforwarddef(hpd)^.forwardpos;
                     resolving_forward:=true;
                     resolving_forward:=true;
                     make_ref:=false;
                     make_ref:=false;
-                    getsym(pforwarddef(hpd)^.tosymname,false);
+                    searchsym(pforwarddef(hpd)^.tosymname,srsym,srsymtable);
                     make_ref:=true;
                     make_ref:=true;
                     resolving_forward:=false;
                     resolving_forward:=false;
                     akttokenpos:=stpos;
                     akttokenpos:=stpos;
@@ -371,6 +373,7 @@ implementation
          typename,orgtypename : stringid;
          typename,orgtypename : stringid;
          newtype  : ptypesym;
          newtype  : ptypesym;
          sym      : psym;
          sym      : psym;
+         srsymtable : psymtable;
          tt       : ttype;
          tt       : ttype;
          defpos,storetokenpos : tfileposinfo;
          defpos,storetokenpos : tfileposinfo;
          old_block_type : tblock_type;
          old_block_type : tblock_type;
@@ -389,8 +392,7 @@ implementation
            if token=_TYPE then
            if token=_TYPE then
             Consume(_TYPE);
             Consume(_TYPE);
            { is the type already defined? }
            { is the type already defined? }
-           getsym(typename,false);
-           sym:=srsym;
+           searchsym(typename,sym,srsymtable);
            newtype:=nil;
            newtype:=nil;
            { found a symbol with this name? }
            { found a symbol with this name? }
            if assigned(sym) then
            if assigned(sym) then
@@ -544,7 +546,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.24  2000-12-25 00:07:27  peter
+  Revision 1.25  2001-03-11 22:58:49  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.24  2000/12/25 00:07:27  peter
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
       tlinkedlist objects)
       tlinkedlist objects)
 
 

+ 10 - 10
compiler/pdecobj.pas

@@ -281,10 +281,9 @@ implementation
                            begin
                            begin
                              p^.readaccess^.addsym(sym);
                              p^.readaccess^.addsym(sym);
                              consume(_POINT);
                              consume(_POINT);
-                             getsymonlyin(precorddef(pvarsym(sym)^.vartype.def)^.symtable,pattern);
-                             if not assigned(srsym) then
+                             sym:=searchsymonlyin(precorddef(pvarsym(sym)^.vartype.def)^.symtable,pattern);
+                             if not assigned(sym) then
                                Message1(sym_e_illegal_field,pattern);
                                Message1(sym_e_illegal_field,pattern);
-                             sym:=srsym;
                              consume(_ID);
                              consume(_ID);
                            end;
                            end;
                        end;
                        end;
@@ -332,10 +331,9 @@ implementation
                            begin
                            begin
                              p^.writeaccess^.addsym(sym);
                              p^.writeaccess^.addsym(sym);
                              consume(_POINT);
                              consume(_POINT);
-                             getsymonlyin(precorddef(pvarsym(sym)^.vartype.def)^.symtable,pattern);
-                             if not assigned(srsym) then
+                             sym:=searchsymonlyin(precorddef(pvarsym(sym)^.vartype.def)^.symtable,pattern);
+                             if not assigned(sym) then
                                Message1(sym_e_illegal_field,pattern);
                                Message1(sym_e_illegal_field,pattern);
-                             sym:=srsym;
                              consume(_ID);
                              consume(_ID);
                            end;
                            end;
                        end;
                        end;
@@ -395,10 +393,9 @@ implementation
                                       begin
                                       begin
                                         p^.storedaccess^.addsym(sym);
                                         p^.storedaccess^.addsym(sym);
                                         consume(_POINT);
                                         consume(_POINT);
-                                        getsymonlyin(precorddef(pvarsym(sym)^.vartype.def)^.symtable,pattern);
-                                        if not assigned(srsym) then
+                                        sym:=searchsymonlyin(precorddef(pvarsym(sym)^.vartype.def)^.symtable,pattern);
+                                        if not assigned(sym) then
                                           Message1(sym_e_illegal_field,pattern);
                                           Message1(sym_e_illegal_field,pattern);
-                                        sym:=srsym;
                                         consume(_ID);
                                         consume(_ID);
                                       end;
                                       end;
                                   end;
                                   end;
@@ -1168,7 +1165,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.15  2000-12-25 00:07:27  peter
+  Revision 1.16  2001-03-11 22:58:49  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.15  2000/12/25 00:07:27  peter
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
       tlinkedlist objects)
       tlinkedlist objects)
 
 

+ 24 - 12
compiler/pdecsub.pas

@@ -99,6 +99,7 @@ implementation
         tt      : ttype;
         tt      : ttype;
         hvs,
         hvs,
         vs      : Pvarsym;
         vs      : Pvarsym;
+        srsym   : psym;
         hs1,hs2 : string;
         hs1,hs2 : string;
         varspez : Tvarspez;
         varspez : Tvarspez;
         inserthigh : boolean;
         inserthigh : boolean;
@@ -174,8 +175,7 @@ implementation
                      if (token=_CONST) and (m_objpas in aktmodeswitches) then
                      if (token=_CONST) and (m_objpas in aktmodeswitches) then
                       begin
                       begin
                         consume(_CONST);
                         consume(_CONST);
-                        srsym:=nil;
-                        getsymonlyin(systemunit,'TVARREC');
+                        srsym:=searchsymonlyin(systemunit,'TVARREC');
                         if not assigned(srsym) then
                         if not assigned(srsym) then
                          InternalError(1234124);
                          InternalError(1234124);
                         Parraydef(tt.def)^.elementtype:=ptypesym(srsym)^.restype;
                         Parraydef(tt.def)^.elementtype:=ptypesym(srsym)^.restype;
@@ -314,6 +314,7 @@ var orgsp,sp:stringid;
     sym:Psym;
     sym:Psym;
     hs:string;
     hs:string;
     st : psymtable;
     st : psymtable;
+    srsymtable : psymtable;
     overloaded_level:word;
     overloaded_level:word;
     storepos,procstartfilepos : tfileposinfo;
     storepos,procstartfilepos : tfileposinfo;
     i: longint;
     i: longint;
@@ -337,7 +338,8 @@ begin
     end;
     end;
 
 
     { examine interface map: function/procedure iname.functionname=locfuncname }
     { examine interface map: function/procedure iname.functionname=locfuncname }
-    if parse_only and assigned(procinfo^._class) and
+    if parse_only and
+       assigned(procinfo^._class) and
        assigned(procinfo^._class^.implementedinterfaces) and
        assigned(procinfo^._class^.implementedinterfaces) and
        (procinfo^._class^.implementedinterfaces^.count>0) and
        (procinfo^._class^.implementedinterfaces^.count>0) and
        try_to_consume(_POINT) then
        try_to_consume(_POINT) then
@@ -345,11 +347,14 @@ begin
          storepos:=akttokenpos;
          storepos:=akttokenpos;
          akttokenpos:=procstartfilepos;
          akttokenpos:=procstartfilepos;
          { get interface syms}
          { get interface syms}
-         getsym(sp,true);
-         sym:=srsym;
+         searchsym(sp,sym,srsymtable);
+         if not assigned(sym) then
+          begin
+            identifier_not_found(orgsp);
+            sym:=generrorsym;
+          end;
          akttokenpos:=storepos;
          akttokenpos:=storepos;
          { load proc name }
          { load proc name }
-         sp:=pattern;
          if sym^.typ=typesym then
          if sym^.typ=typesym then
            i:=procinfo^._class^.implementedinterfaces^.searchintf(ptypesym(sym)^.restype.def);
            i:=procinfo^._class^.implementedinterfaces^.searchintf(ptypesym(sym)^.restype.def);
          { qualifier is interface name? }
          { qualifier is interface name? }
@@ -378,22 +383,27 @@ begin
      (lexlevel=normal_function_level) and
      (lexlevel=normal_function_level) and
      try_to_consume(_POINT) then
      try_to_consume(_POINT) then
    begin
    begin
+     { search for object name }
      storepos:=akttokenpos;
      storepos:=akttokenpos;
      akttokenpos:=procstartfilepos;
      akttokenpos:=procstartfilepos;
-     getsym(sp,true);
-     sym:=srsym;
+     searchsym(sp,sym,srsymtable);
+     if not assigned(sym) then
+      begin
+        identifier_not_found(orgsp);
+        sym:=generrorsym;
+      end;
      akttokenpos:=storepos;
      akttokenpos:=storepos;
-     { load proc name }
+     { consume proc name }
      sp:=pattern;
      sp:=pattern;
      orgsp:=orgpattern;
      orgsp:=orgpattern;
      procstartfilepos:=akttokenpos;
      procstartfilepos:=akttokenpos;
+     consume(_ID);
      { qualifier is class name ? }
      { qualifier is class name ? }
      if (sym^.typ<>typesym) or
      if (sym^.typ<>typesym) or
         (ptypesym(sym)^.restype.def^.deftype<>objectdef) then
         (ptypesym(sym)^.restype.def^.deftype<>objectdef) then
        begin
        begin
           Message(parser_e_class_id_expected);
           Message(parser_e_class_id_expected);
           aktprocsym:=nil;
           aktprocsym:=nil;
-          consume(_ID);
        end
        end
      else
      else
        begin
        begin
@@ -401,7 +411,6 @@ begin
           aktobjectdef:=pobjectdef(ptypesym(sym)^.restype.def);
           aktobjectdef:=pobjectdef(ptypesym(sym)^.restype.def);
           procinfo^._class:=pobjectdef(ptypesym(sym)^.restype.def);
           procinfo^._class:=pobjectdef(ptypesym(sym)^.restype.def);
           aktprocsym:=pprocsym(procinfo^._class^.symtable^.search(sp));
           aktprocsym:=pprocsym(procinfo^._class^.symtable^.search(sp));
-          consume(_ID);
           {The procedure has been found. So it is
           {The procedure has been found. So it is
            a global one. Set the flags to mark this.}
            a global one. Set the flags to mark this.}
           procinfo^.flags:=procinfo^.flags or pi_is_global;
           procinfo^.flags:=procinfo^.flags or pi_is_global;
@@ -1878,7 +1887,10 @@ end;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.12  2001-03-06 18:28:02  peter
+  Revision 1.13  2001-03-11 22:58:50  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.12  2001/03/06 18:28:02  peter
     * patch from Pavel with a new and much faster DLL Scanner for
     * patch from Pavel with a new and much faster DLL Scanner for
       automatic importing so $linklib works for DLLs. Thanks Pavel!
       automatic importing so $linklib works for DLLs. Thanks Pavel!
 
 

+ 13 - 24
compiler/pdecvar.pas

@@ -25,8 +25,6 @@ unit pdecvar;
 
 
 {$i defines.inc}
 {$i defines.inc}
 
 
-{$define UseUnionSymtable}
-
 interface
 interface
 
 
     procedure read_var_decs(is_record,is_object,is_threadvar:boolean);
     procedure read_var_decs(is_record,is_object,is_threadvar:boolean);
@@ -120,13 +118,13 @@ implementation
          { startvarrec contains the start of the variant part of a record }
          { startvarrec contains the start of the variant part of a record }
          maxsize,maxalignment,startvarrecalign,startvarrecsize : longint;
          maxsize,maxalignment,startvarrecalign,startvarrecsize : longint;
          pt : tnode;
          pt : tnode;
-{$ifdef UseUnionSymtable}
+         srsym : psym;
+         srsymtable : psymtable;
          unionsymtable : psymtable;
          unionsymtable : psymtable;
          offset : longint;
          offset : longint;
          uniondef : precorddef;
          uniondef : precorddef;
          unionsym : pvarsym;
          unionsym : pvarsym;
          uniontype : ttype;
          uniontype : ttype;
-{$endif UseUnionSymtable}
       begin
       begin
          old_current_object_option:=current_object_option;
          old_current_object_option:=current_object_option;
          { all variables are public if not in a object declaration }
          { all variables are public if not in a object declaration }
@@ -212,15 +210,7 @@ implementation
                 { parse the rest }
                 { parse the rest }
                 if token=_ID then
                 if token=_ID then
                  begin
                  begin
-                   getsym(pattern,true);
-                   consume(_ID);
-                   { support unit.variable }
-                   if srsym^.typ=unitsym then
-                    begin
-                      consume(_POINT);
-                      getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
-                      consume(_ID);
-                    end;
+                   consume_sym(srsym,srsymtable);
                    { we should check the result type of srsym }
                    { we should check the result type of srsym }
                    if not (srsym^.typ in [varsym,typedconstsym,funcretsym]) then
                    if not (srsym^.typ in [varsym,typedconstsym,funcretsym]) then
                      Message(parser_e_absolute_only_to_var_or_const);
                      Message(parser_e_absolute_only_to_var_or_const);
@@ -447,17 +437,17 @@ implementation
               maxalignment:=0;
               maxalignment:=0;
               consume(_CASE);
               consume(_CASE);
               s:=pattern;
               s:=pattern;
-              getsym(s,false);
+              searchsym(s,srsym,srsymtable);
               { may be only a type: }
               { may be only a type: }
               if assigned(srsym) and (srsym^.typ in [typesym,unitsym]) then
               if assigned(srsym) and (srsym^.typ in [typesym,unitsym]) then
                begin
                begin
                  { for records, don't search the recordsymtable for
                  { for records, don't search the recordsymtable for
                    the symbols of the types }
                    the symbols of the types }
                  oldsymtablestack:=symtablestack;
                  oldsymtablestack:=symtablestack;
-                     symtablestack:=symtablestack^.next;
+                 symtablestack:=symtablestack^.next;
                  read_type(casetype,'');
                  read_type(casetype,'');
-                     symtablestack:=oldsymtablestack;
-                   end
+                 symtablestack:=oldsymtablestack;
+               end
               else
               else
                 begin
                 begin
                   consume(_ID);
                   consume(_ID);
@@ -465,22 +455,20 @@ implementation
                   { for records, don't search the recordsymtable for
                   { for records, don't search the recordsymtable for
                     the symbols of the types }
                     the symbols of the types }
                   oldsymtablestack:=symtablestack;
                   oldsymtablestack:=symtablestack;
-                      symtablestack:=symtablestack^.next;
+                  symtablestack:=symtablestack^.next;
                   read_type(casetype,'');
                   read_type(casetype,'');
-                      symtablestack:=oldsymtablestack;
+                  symtablestack:=oldsymtablestack;
                   symtablestack^.insert(new(pvarsym,init(s,casetype)));
                   symtablestack^.insert(new(pvarsym,init(s,casetype)));
                 end;
                 end;
               if not(is_ordinal(casetype.def)) or is_64bitint(casetype.def)  then
               if not(is_ordinal(casetype.def)) or is_64bitint(casetype.def)  then
                Message(type_e_ordinal_expr_expected);
                Message(type_e_ordinal_expr_expected);
               consume(_OF);
               consume(_OF);
-{$ifdef UseUnionSymtable}
               UnionSymtable:=new(pstoredsymtable,init(recordsymtable));
               UnionSymtable:=new(pstoredsymtable,init(recordsymtable));
               UnionSymtable^.next:=symtablestack;
               UnionSymtable^.next:=symtablestack;
               registerdef:=false;
               registerdef:=false;
               UnionDef:=new(precorddef,init(unionsymtable));
               UnionDef:=new(precorddef,init(unionsymtable));
               registerdef:=true;
               registerdef:=true;
               symtablestack:=UnionSymtable;
               symtablestack:=UnionSymtable;
-{$endif UseUnionSymtable}
               startvarrecsize:=symtablestack^.datasize;
               startvarrecsize:=symtablestack^.datasize;
               startvarrecalign:=symtablestack^.dataalignment;
               startvarrecalign:=symtablestack^.dataalignment;
               repeat
               repeat
@@ -517,7 +505,6 @@ implementation
               { at last set the record size to that of the biggest variant }
               { at last set the record size to that of the biggest variant }
               symtablestack^.datasize:=maxsize;
               symtablestack^.datasize:=maxsize;
               symtablestack^.dataalignment:=maxalignment;
               symtablestack^.dataalignment:=maxalignment;
-{$ifdef UseUnionSymtable}
               uniontype.def:=uniondef;
               uniontype.def:=uniondef;
               uniontype.sym:=nil;
               uniontype.sym:=nil;
               UnionSym:=new(pvarsym,init('case',uniontype));
               UnionSym:=new(pvarsym,init('case',uniontype));
@@ -532,7 +519,6 @@ implementation
               UnionSym^.owner:=nil;
               UnionSym^.owner:=nil;
               dispose(unionsym,done);
               dispose(unionsym,done);
               dispose(uniondef,done);
               dispose(uniondef,done);
-{$endif UseUnionSymtable}
            end;
            end;
          block_type:=old_block_type;
          block_type:=old_block_type;
          current_object_option:=old_current_object_option;
          current_object_option:=old_current_object_option;
@@ -541,7 +527,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.10  2001-03-06 18:28:02  peter
+  Revision 1.11  2001-03-11 22:58:50  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.10  2001/03/06 18:28:02  peter
     * patch from Pavel with a new and much faster DLL Scanner for
     * patch from Pavel with a new and much faster DLL Scanner for
       automatic importing so $linklib works for DLLs. Thanks Pavel!
       automatic importing so $linklib works for DLLs. Thanks Pavel!
 
 

+ 86 - 93
compiler/pexports.pas

@@ -39,7 +39,7 @@ implementation
        globals,tokens,verbose,
        globals,tokens,verbose,
        systems,
        systems,
        { symtable }
        { symtable }
-       symconst,symdef,symsym,symtable,
+       symconst,symbase,symtype,symdef,symsym,symtable,
        { pass 1 }
        { pass 1 }
        node,pass_1,
        node,pass_1,
        ncon,
        ncon,
@@ -56,9 +56,10 @@ implementation
          hp        : texported_item;
          hp        : texported_item;
          orgs,
          orgs,
          DefString : string;
          DefString : string;
-         ProcName  : string;
          InternalProcName : string;
          InternalProcName : string;
-         pt        : tnode;
+         pt               : tnode;
+         srsym            : psym;
+         srsymtable : psymtable;
       begin
       begin
          DefString:='';
          DefString:='';
          InternalProcName:='';
          InternalProcName:='';
@@ -68,96 +69,85 @@ implementation
               hp:=texported_item.create;
               hp:=texported_item.create;
               if token=_ID then
               if token=_ID then
                 begin
                 begin
-                   getsym(pattern,true);
-                   if srsym^.typ=unitsym then
-                     begin
-                        consume(_ID);
-                        consume(_POINT);
-                        getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
-                     end;
                    orgs:=orgpattern;
                    orgs:=orgpattern;
-                   consume(_ID);
-                   if assigned(srsym) then
-                     begin
-                        hp.sym:=srsym;
-                        if ((hp.sym^.typ<>procsym) or
-                            ((tf_need_export in target_info.flags) and
-                             not(po_exports in pprocdef(pprocsym(srsym)^.definition)^.procoptions)
-                            )
-                           ) and
-                           (srsym^.typ<>varsym) and (srsym^.typ<>typedconstsym) then
-                         Message(parser_e_illegal_symbol_exported)
-                        else
-                         begin
-                          ProcName:=orgs;
-                          InternalProcName:=hp.sym^.mangledname;
-                          { This is wrong if the first is not
-                            an underline }
-                          if InternalProcName[1]='_' then
-                            delete(InternalProcName,1,1)
-                          else if (target_os.id=os_i386_win32) and UseDeffileForExport then
-                            begin
-                              Message(parser_e_dlltool_unit_var_problem);
-                              Message(parser_e_dlltool_unit_var_problem2);
-                            end;
-                          if length(InternalProcName)<2 then
-                           Message(parser_e_procname_to_short_for_export);
-                          DefString:=ProcName+'='+InternalProcName;
-                         end;
-                        if (idtoken=_INDEX) then
-                          begin
-                             consume(_INDEX);
-                             pt:=comp_expr(true);
-                             do_firstpass(pt);
-                             if pt.nodetype=ordconstn then
-                               hp.index:=tordconstnode(pt).value
-                             else
-                                begin
-                                   hp.index:=0;
-                                   consume(_INTCONST);
-                                end;
-                             hp.options:=hp.options or eo_index;
-                             pt.free;
-                             if target_os.id=os_i386_win32 then
-                               DefString:=ProcName+'='+InternalProcName+' @ '+tostr(hp.index)
-                             else
-                               DefString:=ProcName+'='+InternalProcName; {Index ignored!}
-                          end;
-                        if (idtoken=_NAME) then
-                          begin
-                             consume(_NAME);
-                             pt:=comp_expr(true);
-                             do_firstpass(pt);
-                             if pt.nodetype=stringconstn then
-                               hp.name:=stringdup(strpas(tstringconstnode(pt).value_str))
-                             else
-                                begin
-                                   hp.name:=stringdup('');
-                                   consume(_CSTRING);
-                                end;
-                             hp.options:=hp.options or eo_name;
-                             pt.free;
-                             DefString:=hp.name^+'='+InternalProcName;
-                          end;
-                        if (idtoken=_RESIDENT) then
-                          begin
-                             consume(_RESIDENT);
-                             hp.options:=hp.options or eo_resident;
-                             DefString:=ProcName+'='+InternalProcName;{Resident ignored!}
-                          end;
-                        if (DefString<>'') and UseDeffileForExport then
-                         DefFile.AddExport(DefString);
-                        { Default to generate a name entry with the provided name }
-                        if not assigned(hp.name) then
-                         begin
-                           hp.name:=stringdup(orgs);
-                           hp.options:=hp.options or eo_name;
-                         end;
-                        if hp.sym^.typ=procsym then
-                          exportlib.exportprocedure(hp)
-                        else
-                          exportlib.exportvar(hp);
-                     end;
+                   consume_sym(srsym,srsymtable);
+                   hp.sym:=srsym;
+                   if ((hp.sym^.typ<>procsym) or
+                       ((tf_need_export in target_info.flags) and
+                        not(po_exports in pprocdef(pprocsym(srsym)^.definition)^.procoptions)
+                       )
+                      ) and
+                      (srsym^.typ<>varsym) and (srsym^.typ<>typedconstsym) then
+                    Message(parser_e_illegal_symbol_exported)
+                   else
+                    begin
+                      InternalProcName:=srsym^.mangledname;
+                      { This is wrong if the first is not
+                        an underline }
+                      if InternalProcName[1]='_' then
+                        delete(InternalProcName,1,1)
+                      else if (target_os.id=os_i386_win32) and UseDeffileForExport then
+                        begin
+                          Message(parser_e_dlltool_unit_var_problem);
+                          Message(parser_e_dlltool_unit_var_problem2);
+                        end;
+                      if length(InternalProcName)<2 then
+                       Message(parser_e_procname_to_short_for_export);
+                      DefString:=srsym^.realname+'='+InternalProcName;
+                    end;
+                   if (idtoken=_INDEX) then
+                    begin
+                      consume(_INDEX);
+                      pt:=comp_expr(true);
+                      do_firstpass(pt);
+                      if pt.nodetype=ordconstn then
+                       hp.index:=tordconstnode(pt).value
+                      else
+                       begin
+                         hp.index:=0;
+                         consume(_INTCONST);
+                       end;
+                      hp.options:=hp.options or eo_index;
+                      pt.free;
+                      if target_os.id=os_i386_win32 then
+                       DefString:=srsym^.realname+'='+InternalProcName+' @ '+tostr(hp.index)
+                      else
+                       DefString:=srsym^.realname+'='+InternalProcName; {Index ignored!}
+                    end;
+                   if (idtoken=_NAME) then
+                    begin
+                      consume(_NAME);
+                      pt:=comp_expr(true);
+                      do_firstpass(pt);
+                      if pt.nodetype=stringconstn then
+                       hp.name:=stringdup(strpas(tstringconstnode(pt).value_str))
+                      else
+                       begin
+                         hp.name:=stringdup('');
+                         consume(_CSTRING);
+                       end;
+                      hp.options:=hp.options or eo_name;
+                      pt.free;
+                      DefString:=hp.name^+'='+InternalProcName;
+                    end;
+                   if (idtoken=_RESIDENT) then
+                    begin
+                      consume(_RESIDENT);
+                      hp.options:=hp.options or eo_resident;
+                      DefString:=srsym^.realname+'='+InternalProcName;{Resident ignored!}
+                    end;
+                   if (DefString<>'') and UseDeffileForExport then
+                    DefFile.AddExport(DefString);
+                   { Default to generate a name entry with the provided name }
+                   if not assigned(hp.name) then
+                    begin
+                      hp.name:=stringdup(orgs);
+                      hp.options:=hp.options or eo_name;
+                    end;
+                   if hp.sym^.typ=procsym then
+                    exportlib.exportprocedure(hp)
+                   else
+                    exportlib.exportvar(hp);
                 end
                 end
               else
               else
                 consume(_ID);
                 consume(_ID);
@@ -175,7 +165,10 @@ end.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.11  2001-01-03 13:12:50  jonas
+  Revision 1.12  2001-03-11 22:58:50  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.11  2001/01/03 13:12:50  jonas
     * fixed copy/past bugs
     * fixed copy/past bugs
 
 
   Revision 1.10  2000/12/30 22:53:25  peter
   Revision 1.10  2000/12/30 22:53:25  peter

+ 319 - 326
compiler/pexpr.pas

@@ -43,7 +43,7 @@ interface
     function string_dec : pdef;
     function string_dec : pdef;
 
 
     { the ID token has to be consumed before calling this function }
     { the ID token has to be consumed before calling this function }
-    procedure do_member_read(getaddr : boolean;const sym : psym;var p1 : tnode;
+    procedure do_member_read(getaddr : boolean;sym : psym;var p1 : tnode;
       var pd : pdef;var again : boolean);
       var pd : pdef;var again : boolean);
 
 
 {$ifdef int64funcresok}
 {$ifdef int64funcresok}
@@ -904,12 +904,13 @@ implementation
 
 
 
 
     { the ID token has to be consumed before calling this function }
     { the ID token has to be consumed before calling this function }
-    procedure do_member_read(getaddr : boolean;const sym : psym;var p1 : tnode;
+    procedure do_member_read(getaddr : boolean;sym : psym;var p1 : tnode;
       var pd : pdef;var again : boolean);
       var pd : pdef;var again : boolean);
 
 
       var
       var
          static_name : string;
          static_name : string;
          isclassref : boolean;
          isclassref : boolean;
+         srsymtable : psymtable;
          objdef : pobjectdef;
          objdef : pobjectdef;
 
 
       begin
       begin
@@ -978,10 +979,10 @@ implementation
                         Message(parser_e_only_class_methods_via_class_ref);
                         Message(parser_e_only_class_methods_via_class_ref);
                       if (sp_static in sym^.symoptions) then
                       if (sp_static in sym^.symoptions) then
                         begin
                         begin
-                           static_name:=lower(srsym^.owner^.name^)+'_'+sym^.name;
-                           getsym(static_name,true);
+                           static_name:=lower(sym^.owner^.name^)+'_'+sym^.name;
+                           searchsym(static_name,sym,srsymtable);
                            p1.destroy;
                            p1.destroy;
-                           p1:=genloadnode(pvarsym(srsym),srsymtable);
+                           p1:=genloadnode(pvarsym(sym),srsymtable);
                         end
                         end
                       else
                       else
                         p1:=gensubscriptnode(pvarsym(sym),p1);
                         p1:=gensubscriptnode(pvarsym(sym),p1);
@@ -991,7 +992,7 @@ implementation
                    begin
                    begin
                       if isclassref then
                       if isclassref then
                         Message(parser_e_only_class_methods_via_class_ref);
                         Message(parser_e_only_class_methods_via_class_ref);
-                      handle_propertysym(sym,srsymtable,p1,pd);
+                      handle_propertysym(sym,sym^.owner,p1,pd);
                    end;
                    end;
                  else internalerror(16);
                  else internalerror(16);
               end;
               end;
@@ -1032,11 +1033,10 @@ implementation
                          Is_func_ret
                          Is_func_ret
          ---------------------------------------------}
          ---------------------------------------------}
 
 
-        function is_func_ret(sym : psym) : boolean;
+        function is_func_ret(var sym : psym;var srsymtable:psymtable) : boolean;
         var
         var
            p : pprocinfo;
            p : pprocinfo;
            storesymtablestack : psymtable;
            storesymtablestack : psymtable;
-
         begin
         begin
           is_func_ret:=false;
           is_func_ret:=false;
           if not assigned(procinfo) or
           if not assigned(procinfo) or
@@ -1073,14 +1073,17 @@ implementation
                  end;
                  end;
                p:=p^.parent;
                p:=p^.parent;
             end;
             end;
-          { we must use the function call }
+          { we must use the function call, update the
+            sym to be the procsym }
           if (sym^.typ=funcretsym) then
           if (sym^.typ=funcretsym) then
             begin
             begin
                storesymtablestack:=symtablestack;
                storesymtablestack:=symtablestack;
-               symtablestack:=srsymtable^.next;
-               getsym(sym^.name,true);
-               if srsym^.typ<>procsym then
-                 Message(cg_e_illegal_expression);
+               symtablestack:=sym^.owner^.next;
+               searchsym(sym^.name,sym,srsymtable);
+               if not assigned(sym) then
+                sym:=generrorsym;
+               if (sym^.typ<>procsym) then
+                Message(cg_e_illegal_expression);
                symtablestack:=storesymtablestack;
                symtablestack:=storesymtablestack;
             end;
             end;
         end;
         end;
@@ -1093,326 +1096,318 @@ implementation
          var
          var
            pc : pchar;
            pc : pchar;
            len : longint;
            len : longint;
+           srsym : psym;
+           srsymtable : psymtable;
          begin
          begin
            { allow post fix operators }
            { allow post fix operators }
            again:=true;
            again:=true;
+           consume_sym(srsym,srsymtable);
+           if not is_func_ret(srsym,srsymtable) then
             begin
             begin
-              if lastsymknown then
+              { check semantics of private }
+              if (srsym^.typ in [propertysym,procsym,varsym]) and
+                 (srsym^.owner^.symtabletype=objectsymtable) then
                begin
                begin
-                 srsym:=lastsrsym;
-                 srsymtable:=lastsrsymtable;
-                 lastsymknown:=false;
-               end
-              else
-               getsym(pattern,true);
-              consume(_ID);
-               if not is_func_ret(srsym) then
-              { else it's a normal symbol }
-                begin
-                { is it defined like UNIT.SYMBOL ? }
-                  if srsym^.typ=unitsym then
-                   begin
-                     consume(_POINT);
-                     getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
-{$ifdef TEST_PROCSYMS}
-                     unit_specific:=true;
-{$endif TEST_PROCSYMS}
-                     consume(_ID);
-{$ifdef TEST_PROCSYMS}
-                   end
-                  else
-                   unit_specific:=false;
-{$else TEST_PROCSYMS}
-                   end;
-{$endif TEST_PROCSYMS}
-                  if not assigned(srsym) then
-                   Begin
-                     p1:=cerrornode.create;
-                     { try to clean up }
-                     pd:=generrordef;
-                   end
-                  else
-                   Begin
-                     { check semantics of private }
-                     if (srsym^.typ in [propertysym,procsym,varsym]) and
-                        (srsymtable^.symtabletype=objectsymtable) then
-                      begin
-                         if (sp_private in srsym^.symoptions) and
-                            (pobjectdef(srsym^.owner^.defowner)^.owner^.symtabletype=unitsymtable) then
-                            Message(parser_e_cant_access_private_member);
-                      end;
-                     case srsym^.typ of
-              absolutesym : begin
-                              p1:=genloadnode(pvarsym(srsym),srsymtable);
-                              pd:=pabsolutesym(srsym)^.vartype.def;
-                            end;
-                   varsym : begin
-                              { are we in a class method ? }
-                              if (srsymtable^.symtabletype=objectsymtable) and
-                                 assigned(aktprocsym) and
-                                 (po_classmethod in aktprocsym^.definition^.procoptions) then
-                                Message(parser_e_only_class_methods);
-                              if (sp_static in srsym^.symoptions) then
-                               begin
-                                 static_name:=lower(srsym^.owner^.name^)+'_'+srsym^.name;
-                                 getsym(static_name,true);
-                               end;
-                              p1:=genloadnode(pvarsym(srsym),srsymtable);
-                              if pvarsym(srsym)^.varstate=vs_declared then
-                               begin
-                                 include(p1.flags,nf_first);
-                                 { set special between first loaded until checked in firstpass }
-                                 pvarsym(srsym)^.varstate:=vs_declared_and_first_found;
-                               end;
-                              pd:=pvarsym(srsym)^.vartype.def;
-                            end;
-            typedconstsym : begin
-                              p1:=gentypedconstloadnode(ptypedconstsym(srsym),srsymtable);
-                              pd:=ptypedconstsym(srsym)^.typedconsttype.def;
-                            end;
-                   syssym : p1:=statement_syssym(psyssym(srsym)^.number,pd);
-                  typesym : begin
-                              pd:=ptypesym(srsym)^.restype.def;
-                              if not assigned(pd) then
+                 if (sp_private in srsym^.symoptions) and
+                    (pobjectdef(srsym^.owner^.defowner)^.owner^.symtabletype=unitsymtable) then
+                   Message(parser_e_cant_access_private_member);
+               end;
+              case srsym^.typ of
+                absolutesym :
+                  begin
+                    p1:=genloadnode(pvarsym(srsym),srsymtable);
+                    pd:=pabsolutesym(srsym)^.vartype.def;
+                  end;
+
+                varsym :
+                  begin
+                    { are we in a class method ? }
+                    if (srsym^.owner^.symtabletype=objectsymtable) and
+                       assigned(aktprocsym) and
+                       (po_classmethod in aktprocsym^.definition^.procoptions) then
+                      Message(parser_e_only_class_methods);
+                    if (sp_static in srsym^.symoptions) then
+                     begin
+                       static_name:=lower(srsym^.owner^.name^)+'_'+srsym^.name;
+                       searchsym(static_name,srsym,srsymtable);
+                     end;
+                    p1:=genloadnode(pvarsym(srsym),srsymtable);
+                    if pvarsym(srsym)^.varstate=vs_declared then
+                     begin
+                       include(p1.flags,nf_first);
+                       { set special between first loaded until checked in firstpass }
+                       pvarsym(srsym)^.varstate:=vs_declared_and_first_found;
+                     end;
+                    pd:=pvarsym(srsym)^.vartype.def;
+                  end;
+
+                typedconstsym :
+                  begin
+                    p1:=gentypedconstloadnode(ptypedconstsym(srsym),srsymtable);
+                    pd:=ptypedconstsym(srsym)^.typedconsttype.def;
+                  end;
+
+                syssym :
+                  p1:=statement_syssym(psyssym(srsym)^.number,pd);
+
+                typesym :
+                  begin
+                    pd:=ptypesym(srsym)^.restype.def;
+                    if not assigned(pd) then
+                     begin
+                       pd:=generrordef;
+                       again:=false;
+                     end
+                    else
+                     begin
+                       { if we read a type declaration  }
+                       { we have to return the type and }
+                       { nothing else               }
+                       if block_type=bt_type then
+                        begin
+                          { we don't need sym reference when it's in the
+                            current unit or system unit, because those
+                            units are always loaded (PFV) }
+                          if not(assigned(pd^.owner)) or
+                             (pd^.owner^.unitid=0) or
+                             (pd^.owner^.unitid=1) then
+                           p1:=gentypenode(pd,nil)
+                          else
+                           p1:=gentypenode(pd,ptypesym(srsym));
+                          { here we can also set resulttype !! }
+                          p1.resulttype:=pd;
+                          pd:=voiddef;
+                        end
+                       else { not type block }
+                        begin
+                          if token=_LKLAMMER then
+                           begin
+                             consume(_LKLAMMER);
+                             p1:=comp_expr(true);
+                             consume(_RKLAMMER);
+                             p1:=gentypeconvnode(p1,pd);
+                             include(p1.flags,nf_explizit);
+                           end
+                          else { not LKLAMMER }
+                           if (token=_POINT) and
+                              is_object(pd) then
+                            begin
+                              consume(_POINT);
+                              if assigned(procinfo) and
+                                 assigned(procinfo^._class) and
+                                 not(getaddr) then
                                begin
                                begin
-                                 pd:=generrordef;
-                                 again:=false;
+                                 if procinfo^._class^.is_related(pobjectdef(pd)) then
+                                  begin
+                                    p1:=gentypenode(pd,ptypesym(srsym));
+                                    p1.resulttype:=pd;
+                                    { search also in inherited methods }
+                                    repeat
+                                      sym:=pvarsym(pobjectdef(pd)^.symtable^.search(pattern));
+                                      if assigned(sym) then
+                                       break;
+                                      pd:=pobjectdef(pd)^.childof;
+                                    until not assigned(pd);
+                                    consume(_ID);
+                                    do_member_read(false,sym,p1,pd,again);
+                                  end
+                                 else
+                                  begin
+                                    Message(parser_e_no_super_class);
+                                    pd:=generrordef;
+                                    again:=false;
+                                  end;
                                end
                                end
                               else
                               else
                                begin
                                begin
-                                 { if we read a type declaration  }
-                                 { we have to return the type and }
-                                 { nothing else               }
-                                  if block_type=bt_type then
-                                   begin
-                                     { we don't need sym reference when it's in the
-                                       current unit or system unit, because those
-                                       units are always loaded (PFV) }
-                                     if not(assigned(pd^.owner)) or
-                                        (pd^.owner^.unitid=0) or
-                                        (pd^.owner^.unitid=1) then
-                                      p1:=gentypenode(pd,nil)
-                                     else
-                                      p1:=gentypenode(pd,ptypesym(srsym));
-                                     { here we can also set resulttype !! }
-                                     p1.resulttype:=pd;
-                                     pd:=voiddef;
-                                   end
-                                 else { not type block }
+                                 { allows @TObject.Load }
+                                 { also allows static methods and variables }
+                                 p1:=ctypenode.create(nil,nil);
+                                 p1.resulttype:=pd;
+                                 { TP allows also @TMenu.Load if Load is only }
+                                 { defined in an anchestor class              }
+                                 sym:=pvarsym(search_class_member(pobjectdef(pd),pattern));
+                                 if not assigned(sym) then
+                                  Message1(sym_e_id_no_member,pattern)
+                                 else if not(getaddr) and not(sp_static in sym^.symoptions) then
+                                  Message(sym_e_only_static_in_static)
+                                 else
                                   begin
                                   begin
-                                    if token=_LKLAMMER then
-                                     begin
-                                       consume(_LKLAMMER);
-                                       p1:=comp_expr(true);
-                                       consume(_RKLAMMER);
-                                       p1:=gentypeconvnode(p1,pd);
-                                       include(p1.flags,nf_explizit);
-                                     end
-                                    else { not LKLAMMER }
-                                     if (token=_POINT) and
-                                        is_object(pd) then
-                                       begin
-                                         consume(_POINT);
-                                         if assigned(procinfo) and
-                                            assigned(procinfo^._class) and
-                                            not(getaddr) then
-                                          begin
-                                            if procinfo^._class^.is_related(pobjectdef(pd)) then
-                                             begin
-                                               p1:=gentypenode(pd,ptypesym(srsym));
-                                               p1.resulttype:=pd;
-                                               { search also in inherited methods }
-                                               repeat
-                                                 srsymtable:=pobjectdef(pd)^.symtable;
-                                                 sym:=pvarsym(srsymtable^.search(pattern));
-                                                 if assigned(sym) then
-                                                  break;
-                                                 pd:=pobjectdef(pd)^.childof;
-                                               until not assigned(pd);
-                                               consume(_ID);
-                                               do_member_read(false,sym,p1,pd,again);
-                                             end
-                                            else
-                                             begin
-                                               Message(parser_e_no_super_class);
-                                               pd:=generrordef;
-                                               again:=false;
-                                             end;
-                                          end
-                                         else
-                                          begin
-                                            { allows @TObject.Load }
-                                            { also allows static methods and variables }
-                                            p1:=ctypenode.create(nil,nil);
-                                            p1.resulttype:=pd;
-                                            { TP allows also @TMenu.Load if Load is only }
-                                            { defined in an anchestor class              }
-                                            sym:=pvarsym(search_class_member(pobjectdef(pd),pattern));
-                                            if not assigned(sym) then
-                                              Message1(sym_e_id_no_member,pattern)
-                                            else if not(getaddr) and not(sp_static in sym^.symoptions) then
-                                              Message(sym_e_only_static_in_static)
-                                            else
-                                             begin
-                                               consume(_ID);
-                                               do_member_read(getaddr,sym,p1,pd,again);
-                                             end;
-                                          end;
-                                       end
-                                     else
-                                       begin
-                                          { class reference ? }
-                                          if is_class(pd) then
-                                            begin
-                                               if getaddr and (token=_POINT) then
-                                                 begin
-                                                    consume(_POINT);
-                                                    { allows @Object.Method }
-                                                    { also allows static methods and variables }
-                                                    p1:=gentypenode(nil,nil);
-                                                    p1.resulttype:=pd;
-                                                    { TP allows also @TMenu.Load if Load is only }
-                                                    { defined in an anchestor class              }
-                                                    sym:=pvarsym(search_class_member(pobjectdef(pd),pattern));
-                                                    if not assigned(sym) then
-                                                      Message1(sym_e_id_no_member,pattern)
-                                                    else
-                                                     begin
-                                                       consume(_ID);
-                                                       do_member_read(getaddr,sym,p1,pd,again);
-                                                     end;
-                                                 end
-                                               else
-                                                 begin
-                                                    p1:=gentypenode(pd,nil);
-                                                    p1.resulttype:=pd;
-                                                    pd:=new(pclassrefdef,init(pd));
-                                                    p1:=cloadvmtnode.create(p1);
-                                                    p1.resulttype:=pd;
-                                                 end;
-                                            end
-                                          else
-                                            begin
-                                               { generate a type node }
-                                               { (for typeof etc)     }
-                                               if allow_type then
-                                                 begin
-                                                    p1:=gentypenode(pd,nil);
-                                                    { here we must use typenodetype explicitly !! PM
-                                                    p1.resulttype:=pd; }
-                                                    pd:=voiddef;
-                                                 end
-                                               else
-                                                 Message(parser_e_no_type_not_allowed_here);
-                                            end;
-                                       end;
+                                    consume(_ID);
+                                    do_member_read(getaddr,sym,p1,pd,again);
                                   end;
                                   end;
                                end;
                                end;
-                            end;
-                  enumsym : begin
-                              p1:=genenumnode(penumsym(srsym));
-                              pd:=p1.resulttype;
-                            end;
-                 constsym : begin
-                              case pconstsym(srsym)^.consttyp of
-                                constint :
-                                  { do a very dirty trick to bootstrap this code }
-                                  if (pconstsym(srsym)^.value>=-(int64(2147483647)+int64(1))) and (pconstsym(srsym)^.value<=2147483647) then
-                                    p1:=genordinalconstnode(pconstsym(srsym)^.value,s32bitdef)
-                                  else if (pconstsym(srsym)^.value > maxlongint) and (pconstsym(srsym)^.value <= int64(maxlongint)+int64(maxlongint)+1) then
-                                    p1:=genordinalconstnode(pconstsym(srsym)^.value,u32bitdef)
-                                  else
-                                    p1:=genordinalconstnode(pconstsym(srsym)^.value,cs64bitdef);
-                                conststring :
-                                  begin
-                                    len:=pconstsym(srsym)^.len;
-                                    if not(cs_ansistrings in aktlocalswitches) and (len>255) then
-                                     len:=255;
-                                    getmem(pc,len+1);
-                                    move(pchar(tpointerord(pconstsym(srsym)^.value))^,pc^,len);
-                                    pc[len]:=#0;
-                                    p1:=genpcharconstnode(pc,len);
-                                  end;
-                                constchar :
-                                  p1:=genordinalconstnode(pconstsym(srsym)^.value,cchardef);
-                                constreal :
-                                  p1:=genrealconstnode(pbestreal(tpointerord(pconstsym(srsym)^.value))^,bestrealdef^);
-                                constbool :
-                                  p1:=genordinalconstnode(pconstsym(srsym)^.value,booldef);
-                                constset :
-                                  p1:=gensetconstnode(pconstset(tpointerord(pconstsym(srsym)^.value)),
-                                        psetdef(pconstsym(srsym)^.consttype.def));
-                                constord :
-                                  p1:=genordinalconstnode(pconstsym(srsym)^.value,
-                                        pconstsym(srsym)^.consttype.def);
-                                constpointer :
-                                  p1:=genpointerconstnode(pconstsym(srsym)^.value,
-                                        pconstsym(srsym)^.consttype.def);
-                                constnil :
-                                  p1:=cnilnode.create;
-                                constresourcestring:
-                                  begin
-                                     p1:=genloadnode(pvarsym(srsym),srsymtable);
-                                     p1.resulttype:=cansistringdef;
-                                  end;
+                            end
+                          else
+                           begin
+                             { class reference ? }
+                             if is_class(pd) then
+                              begin
+                                if getaddr and (token=_POINT) then
+                                 begin
+                                   consume(_POINT);
+                                   { allows @Object.Method }
+                                   { also allows static methods and variables }
+                                   p1:=gentypenode(nil,nil);
+                                   p1.resulttype:=pd;
+                                   { TP allows also @TMenu.Load if Load is only }
+                                   { defined in an anchestor class              }
+                                   sym:=pvarsym(search_class_member(pobjectdef(pd),pattern));
+                                   if not assigned(sym) then
+                                    Message1(sym_e_id_no_member,pattern)
+                                   else
+                                    begin
+                                      consume(_ID);
+                                      do_member_read(getaddr,sym,p1,pd,again);
+                                    end;
+                                 end
+                                else
+                                 begin
+                                   p1:=gentypenode(pd,nil);
+                                   p1.resulttype:=pd;
+                                   pd:=new(pclassrefdef,init(pd));
+                                   p1:=cloadvmtnode.create(p1);
+                                   p1.resulttype:=pd;
+                                 end;
+                              end
+                             else
+                              begin
+                                { generate a type node }
+                                { (for typeof etc)     }
+                                if allow_type then
+                                 begin
+                                   p1:=gentypenode(pd,nil);
+                                   { here we must use typenodetype explicitly !! PM
+                                     p1.resulttype:=pd; }
+                                   pd:=voiddef;
+                                 end
+                                else
+                                 Message(parser_e_no_type_not_allowed_here);
                               end;
                               end;
-                              pd:=p1.resulttype;
-                            end;
-                  procsym : begin
-                              { are we in a class method ? }
-                              possible_error:=(srsymtable^.symtabletype=objectsymtable) and
-                                              assigned(aktprocsym) and
-                                              (po_classmethod in aktprocsym^.definition^.procoptions);
-                              p1:=gencallnode(pprocsym(srsym),srsymtable);
-{$ifdef TEST_PROCSYMS}
-                              p1.unit_specific:=unit_specific;
-{$endif TEST_PROCSYMS}
-                              do_proc_call(getaddr or
-                                (getprocvar and
-                                 ((block_type=bt_const) or
-                                  ((m_tp_procvar in aktmodeswitches) and
-                                   proc_to_procvar_equal(pprocsym(srsym)^.definition,getprocvardef)
+                           end;
+                        end;
+                     end;
+                  end;
+
+                enumsym :
+                  begin
+                    p1:=genenumnode(penumsym(srsym));
+                    pd:=p1.resulttype;
+                  end;
+
+                constsym :
+                  begin
+                    case pconstsym(srsym)^.consttyp of
+                      constint :
+                        begin
+                          { do a very dirty trick to bootstrap this code }
+                          if (pconstsym(srsym)^.value>=-(int64(2147483647)+int64(1))) and (pconstsym(srsym)^.value<=2147483647) then
+                           p1:=genordinalconstnode(pconstsym(srsym)^.value,s32bitdef)
+                          else if (pconstsym(srsym)^.value > maxlongint) and (pconstsym(srsym)^.value <= int64(maxlongint)+int64(maxlongint)+1) then
+                           p1:=genordinalconstnode(pconstsym(srsym)^.value,u32bitdef)
+                          else
+                           p1:=genordinalconstnode(pconstsym(srsym)^.value,cs64bitdef);
+                        end;
+                      conststring :
+                        begin
+                          len:=pconstsym(srsym)^.len;
+                          if not(cs_ansistrings in aktlocalswitches) and (len>255) then
+                           len:=255;
+                          getmem(pc,len+1);
+                          move(pchar(tpointerord(pconstsym(srsym)^.value))^,pc^,len);
+                          pc[len]:=#0;
+                          p1:=genpcharconstnode(pc,len);
+                        end;
+                      constchar :
+                        p1:=genordinalconstnode(pconstsym(srsym)^.value,cchardef);
+                      constreal :
+                        p1:=genrealconstnode(pbestreal(tpointerord(pconstsym(srsym)^.value))^,bestrealdef^);
+                      constbool :
+                        p1:=genordinalconstnode(pconstsym(srsym)^.value,booldef);
+                      constset :
+                        p1:=gensetconstnode(pconstset(tpointerord(pconstsym(srsym)^.value)),
+                                            psetdef(pconstsym(srsym)^.consttype.def));
+                      constord :
+                        p1:=genordinalconstnode(pconstsym(srsym)^.value,pconstsym(srsym)^.consttype.def);
+                      constpointer :
+                        p1:=genpointerconstnode(pconstsym(srsym)^.value,pconstsym(srsym)^.consttype.def);
+                      constnil :
+                        p1:=cnilnode.create;
+                      constresourcestring:
+                        begin
+                          p1:=genloadnode(pvarsym(srsym),srsymtable);
+                          p1.resulttype:=cansistringdef;
+                        end;
+                    end;
+                    pd:=p1.resulttype;
+                  end;
+
+                procsym :
+                  begin
+                    { are we in a class method ? }
+                    possible_error:=(srsym^.owner^.symtabletype=objectsymtable) and
+                                    assigned(aktprocsym) and
+                                    (po_classmethod in aktprocsym^.definition^.procoptions);
+                    p1:=gencallnode(pprocsym(srsym),srsymtable);
+                    do_proc_call(getaddr or
+                                 (getprocvar and
+                                  ((block_type=bt_const) or
+                                   ((m_tp_procvar in aktmodeswitches) and
+                                    proc_to_procvar_equal(pprocsym(srsym)^.definition,getprocvardef)
+                                   )
                                   )
                                   )
-                                 )
-                                ),again,tcallnode(p1),pd);
-                              if (block_type=bt_const) and
-                                 getprocvar then
-                                handle_procvar(getprocvardef,p1);
-                              if possible_error and
-                                 not(po_classmethod in tcallnode(p1).procdefinition^.procoptions) then
-                                Message(parser_e_only_class_methods);
-                            end;
-              propertysym : begin
-                              { access to property in a method }
-                              { are we in a class method ? }
-                              if (srsymtable^.symtabletype=objectsymtable) and
-                                 assigned(aktprocsym) and
-                                 (po_classmethod in aktprocsym^.definition^.procoptions) then
-                               Message(parser_e_only_class_methods);
-                              { no method pointer }
-                              p1:=nil;
-                              handle_propertysym(srsym,srsymtable,p1,pd);
-                            end;
-                 errorsym : begin
-                              p1:=cerrornode.create;
-                              p1.resulttype:=generrordef;
-                              pd:=generrordef;
-                              if token=_LKLAMMER then
-                               begin
-                                 consume(_LKLAMMER);
-                                 parse_paras(false,false);
-                                 consume(_RKLAMMER);
-                               end;
-                            end;
-                     else
-                       begin
-                         p1:=cerrornode.create;
-                         pd:=generrordef;
-                         Message(cg_e_illegal_expression);
-                       end;
-                     end; { end case }
-                   end;
-                end;
+                                 ),again,tcallnode(p1),pd);
+                    if (block_type=bt_const) and
+                       getprocvar then
+                     handle_procvar(getprocvardef,p1);
+                    if possible_error and
+                       not(po_classmethod in tcallnode(p1).procdefinition^.procoptions) then
+                     Message(parser_e_only_class_methods);
+                  end;
+
+                propertysym :
+                  begin
+                    { access to property in a method }
+                    { are we in a class method ? }
+                    if (srsym^.owner^.symtabletype=objectsymtable) and
+                       assigned(aktprocsym) and
+                       (po_classmethod in aktprocsym^.definition^.procoptions) then
+                     Message(parser_e_only_class_methods);
+                    { no method pointer }
+                    p1:=nil;
+                    handle_propertysym(srsym,srsymtable,p1,pd);
+                  end;
+
+                labelsym :
+                  begin
+                    consume(_COLON);
+                    if plabelsym(srsym)^.defined then
+                     Message(sym_e_label_already_defined);
+                    plabelsym(srsym)^.defined:=true;
+                    p1:=clabelnode.create(plabelsym(srsym)^.lab,nil);
+                    pd:=voiddef;
+                  end;
+
+                errorsym :
+                  begin
+                    p1:=cerrornode.create;
+                    p1.resulttype:=generrordef;
+                    pd:=generrordef;
+                    if token=_LKLAMMER then
+                     begin
+                       consume(_LKLAMMER);
+                       parse_paras(false,false);
+                       consume(_RKLAMMER);
+                     end;
+                  end;
+
+                else
+                  begin
+                    p1:=cerrornode.create;
+                    pd:=generrordef;
+                    Message(cg_e_illegal_expression);
+                  end;
+              end; { end case }
             end;
             end;
          end;
          end;
 
 
@@ -1522,7 +1517,6 @@ implementation
 
 
         var
         var
            store_static : boolean;
            store_static : boolean;
-
         { p1 and p2 must contain valid value_str }
         { p1 and p2 must contain valid value_str }
         begin
         begin
           check_tokenpos;
           check_tokenpos;
@@ -1677,7 +1671,6 @@ implementation
                              while assigned(classh) do
                              while assigned(classh) do
                               begin
                               begin
                                 sym:=psym(classh^.symtable^.search(pattern));
                                 sym:=psym(classh^.symtable^.search(pattern));
-                                srsymtable:=classh^.symtable;
                                 if assigned(sym) then
                                 if assigned(sym) then
                                  break;
                                  break;
                                 classh:=classh^.childof;
                                 classh:=classh^.childof;
@@ -1707,7 +1700,6 @@ implementation
                               while assigned(classh) do
                               while assigned(classh) do
                                 begin
                                 begin
                                    sym:=psym(classh^.symtable^.search(pattern));
                                    sym:=psym(classh^.symtable^.search(pattern));
-                                   srsymtable:=classh^.symtable;
                                    if assigned(sym) then
                                    if assigned(sym) then
                                      break;
                                      break;
                                    classh:=classh^.childof;
                                    classh:=classh^.childof;
@@ -1867,7 +1859,6 @@ implementation
                         while assigned(classh) do
                         while assigned(classh) do
                          begin
                          begin
                            sym:=psym(classh^.symtable^.search(pattern));
                            sym:=psym(classh^.symtable^.search(pattern));
-                           srsymtable:=classh^.symtable;
                            if assigned(sym) then
                            if assigned(sym) then
                             break;
                             break;
                            classh:=classh^.childof;
                            classh:=classh^.childof;
@@ -1935,8 +1926,7 @@ implementation
                     classh:=procinfo^._class^.childof;
                     classh:=procinfo^._class^.childof;
                     while assigned(classh) do
                     while assigned(classh) do
                      begin
                      begin
-                       srsymtable:=pobjectdef(classh)^.symtable;
-                       sym:=psym(srsymtable^.search(hs));
+                       sym:=psym(pobjectdef(classh)^.symtable^.search(hs));
                        if assigned(sym) then
                        if assigned(sym) then
                         begin
                         begin
                           { only for procsyms we need to set the type (PFV) }
                           { only for procsyms we need to set the type (PFV) }
@@ -2420,7 +2410,10 @@ _LECKKLAMMER : begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.24  2000-12-25 00:07:27  peter
+  Revision 1.25  2001-03-11 22:58:50  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.24  2000/12/25 00:07:27  peter
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
       tlinkedlist objects)
       tlinkedlist objects)
 
 

+ 33 - 49
compiler/pstatmnt.pas

@@ -524,6 +524,8 @@ implementation
          old_block_type : tblock_type;
          old_block_type : tblock_type;
          exceptsymtable : psymtable;
          exceptsymtable : psymtable;
          objname : stringid;
          objname : stringid;
+         srsym : psym;
+         srsymtable : psymtable;
 
 
       begin
       begin
          procinfo^.flags:=procinfo^.flags or
          procinfo^.flags:=procinfo^.flags or
@@ -576,19 +578,14 @@ implementation
                      if token=_ID then
                      if token=_ID then
                        begin
                        begin
                           objname:=pattern;
                           objname:=pattern;
-                          getsym(objname,false);
+                          { can't use consume_sym here, because we need already
+                            to check for the colon }
+                          searchsym(objname,srsym,srsymtable);
                           consume(_ID);
                           consume(_ID);
                           { is a explicit name for the exception given ? }
                           { is a explicit name for the exception given ? }
                           if try_to_consume(_COLON) then
                           if try_to_consume(_COLON) then
                             begin
                             begin
-                               getsym(pattern,true);
-                               consume(_ID);
-                               if srsym^.typ=unitsym then
-                                 begin
-                                    consume(_POINT);
-                                    getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
-                                    consume(_ID);
-                                 end;
+                               consume_sym(srsym,srsymtable);
                                if (srsym^.typ=typesym) and
                                if (srsym^.typ=typesym) and
                                   is_class(ptypesym(srsym)^.restype.def) then
                                   is_class(ptypesym(srsym)^.restype.def) then
                                  begin
                                  begin
@@ -615,16 +612,23 @@ implementation
                                  with "e: Exception" the e is not necessary }
                                  with "e: Exception" the e is not necessary }
                                if srsym=nil then
                                if srsym=nil then
                                 begin
                                 begin
-                                  Message1(sym_e_id_not_found,objname);
+                                  identifier_not_found(objname);
                                   srsym:=generrorsym;
                                   srsym:=generrorsym;
                                 end;
                                 end;
-                               { only exception type }
+                               { support unit.identifier }
                                if srsym^.typ=unitsym then
                                if srsym^.typ=unitsym then
                                  begin
                                  begin
                                     consume(_POINT);
                                     consume(_POINT);
-                                    getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
+                                    srsym:=searchsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
                                     consume(_ID);
                                     consume(_ID);
+                                    if srsym=nil then
+                                     begin
+                                       identifier_not_found(objname);
+                                       srsym:=generrorsym;
+                                     end;
                                  end;
                                  end;
+                               { check if type is valid, must be done here because
+                                 with "e: Exception" the e is not necessary }
                                if (srsym^.typ=typesym) and
                                if (srsym^.typ=typesym) and
                                   is_class(ptypesym(srsym)^.restype.def) then
                                   is_class(ptypesym(srsym)^.restype.def) then
                                  ot:=pobjectdef(ptypesym(srsym)^.restype.def)
                                  ot:=pobjectdef(ptypesym(srsym)^.restype.def)
@@ -941,7 +945,7 @@ implementation
                       end
                       end
                     else
                     else
                       begin
                       begin
-                        p2:=ccallnode.create(pprocsym(sym),srsymtable,p2);
+                        p2:=ccallnode.create(pprocsym(sym),sym^.owner,p2);
                         { support dispose(p,done()); }
                         { support dispose(p,done()); }
                         if try_to_consume(_LKLAMMER) then
                         if try_to_consume(_LKLAMMER) then
                           begin
                           begin
@@ -1016,9 +1020,8 @@ implementation
          p       : tnode;
          p       : tnode;
          code    : tnode;
          code    : tnode;
          filepos : tfileposinfo;
          filepos : tfileposinfo;
-         sr      : plabelsym;
-      label
-         ready;
+         srsym   : psym;
+         srsymtable : psymtable;
       begin
       begin
          filepos:=akttokenpos;
          filepos:=akttokenpos;
          case token of
          case token of
@@ -1034,8 +1037,7 @@ implementation
                   end
                   end
                 else
                 else
                   begin
                   begin
-                     getsym(pattern,true);
-                     consume(token);
+                     consume_sym(srsym,srsymtable);
                      if srsym^.typ<>labelsym then
                      if srsym^.typ<>labelsym then
                        begin
                        begin
                           Message(sym_e_id_is_no_label_id);
                           Message(sym_e_id_is_no_label_id);
@@ -1092,36 +1094,16 @@ implementation
              Message(scan_f_end_of_file);
              Message(scan_f_end_of_file);
          else
          else
            begin
            begin
-              if (token in [_INTCONST,_ID]) then
-                begin
-                   getsym(pattern,true);
-                   lastsymknown:=true;
-                   lastsrsym:=srsym;
-                   { it is NOT necessarily the owner
-                     it can be a withsymtable !!! }
-                   lastsrsymtable:=srsymtable;
-                   if assigned(srsym) and (srsym^.typ=labelsym) then
-                     begin
-                        consume(token);
-                        consume(_COLON);
-                        { we must preserve srsym to set code later }
-                        sr:=plabelsym(srsym);
-                        if sr^.defined then
-                          Message(sym_e_label_already_defined);
-                        sr^.defined:=true;
-
-                        { statement modifies srsym }
-                        lastsymknown:=false;
-                        { the pointer to the following instruction }
-                        { isn't a very clean way                   }
-                        code:=clabelnode.create(sr^.lab,statement{$ifdef FPCPROCVAR}(){$endif});
-                        sr^.code:=code;
-                        { sorry, but here is a jump the easiest way }
-                        goto ready;
-                     end;
-                end;
               p:=expr;
               p:=expr;
-              if not(p.nodetype in [calln,assignn,breakn,inlinen,continuen]) then
+
+              if p.nodetype=labeln then
+               begin
+                 { the pointer to the following instruction }
+                 { isn't a very clean way                   }
+                 tlabelnode(p).left:=statement{$ifdef FPCPROCVAR}(){$endif};
+               end;
+
+              if not(p.nodetype in [calln,assignn,breakn,inlinen,continuen,labeln]) then
                 Message(cg_e_illegal_expression);
                 Message(cg_e_illegal_expression);
               { specify that we don't use the value returned by the call }
               { specify that we don't use the value returned by the call }
               { Question : can this be also improtant
               { Question : can this be also improtant
@@ -1134,7 +1116,6 @@ implementation
               code:=p;
               code:=p;
            end;
            end;
          end;
          end;
-         ready:
          if assigned(code) then
          if assigned(code) then
           code.set_tree_filepos(filepos);
           code.set_tree_filepos(filepos);
          statement:=code;
          statement:=code;
@@ -1259,7 +1240,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.19  2000-12-25 00:07:27  peter
+  Revision 1.20  2001-03-11 22:58:50  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.19  2000/12/25 00:07:27  peter
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
       tlinkedlist objects)
       tlinkedlist objects)
 
 

+ 5 - 1
compiler/ptconst.pas

@@ -77,6 +77,7 @@ implementation
          tmpguid   : tguid;
          tmpguid   : tguid;
          aktpos    : longint;
          aktpos    : longint;
          obj       : pobjectdef;
          obj       : pobjectdef;
+         srsym     : psym;
          symt      : psymtable;
          symt      : psymtable;
          value     : bestreal;
          value     : bestreal;
          strval    : pchar;
          strval    : pchar;
@@ -864,7 +865,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.17  2001-02-04 11:12:16  jonas
+  Revision 1.18  2001-03-11 22:58:50  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.17  2001/02/04 11:12:16  jonas
     * fixed web bug 1377 & const pointer arithmtic
     * fixed web bug 1377 & const pointer arithmtic
 
 
   Revision 1.16  2001/02/03 00:26:35  peter
   Revision 1.16  2001/02/03 00:26:35  peter

+ 8 - 3
compiler/ptype.pas

@@ -76,6 +76,8 @@ implementation
       var
       var
         is_unit_specific : boolean;
         is_unit_specific : boolean;
         pos : tfileposinfo;
         pos : tfileposinfo;
+        srsym : psym;
+        srsymtable : psymtable;
       begin
       begin
          s:=pattern;
          s:=pattern;
          pos:=akttokenpos;
          pos:=akttokenpos;
@@ -95,13 +97,13 @@ implementation
            end;
            end;
          { try to load the symbol to see if it's a unitsym }
          { try to load the symbol to see if it's a unitsym }
          is_unit_specific:=false;
          is_unit_specific:=false;
-         getsym(s,false);
+         searchsym(s,srsym,srsymtable);
          consume(_ID);
          consume(_ID);
          if assigned(srsym) and
          if assigned(srsym) and
             (srsym^.typ=unitsym) then
             (srsym^.typ=unitsym) then
            begin
            begin
               consume(_POINT);
               consume(_POINT);
-              getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
+              srsym:=searchsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
               pos:=akttokenpos;
               pos:=akttokenpos;
               s:=pattern;
               s:=pattern;
               consume(_ID);
               consume(_ID);
@@ -577,7 +579,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.17  2000-12-07 17:19:43  jonas
+  Revision 1.18  2001-03-11 22:58:50  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.17  2000/12/07 17:19:43  jonas
     * new constant handling: from now on, hex constants >$7fffffff are
     * new constant handling: from now on, hex constants >$7fffffff are
       parsed as unsigned constants (otherwise, $80000000 got sign extended
       parsed as unsigned constants (otherwise, $80000000 got sign extended
       and became $ffffffff80000000), all constants in the longint range
       and became $ffffffff80000000), all constants in the longint range

+ 22 - 10
compiler/rautils.pas

@@ -791,12 +791,12 @@ Function TOperand.SetupVar(const hs:string;GetOffset : boolean): Boolean;
 { if not found returns FALSE.                               }
 { if not found returns FALSE.                               }
 var
 var
   sym : psym;
   sym : psym;
+  srsymtable : psymtable;
   harrdef : parraydef;
   harrdef : parraydef;
 Begin
 Begin
   SetupVar:=false;
   SetupVar:=false;
 { are we in a routine ? }
 { are we in a routine ? }
-  getsym(hs,false);
-  sym:=srsym;
+  searchsym(hs,sym,srsymtable);
   if sym=nil then
   if sym=nil then
    exit;
    exit;
   case sym^.typ of
   case sym^.typ of
@@ -1179,8 +1179,11 @@ end;
 ****************************************************************************}
 ****************************************************************************}
 
 
 Function SearchType(const hs:string): Boolean;
 Function SearchType(const hs:string): Boolean;
+var
+  srsym : psym;
+  srsymtable : psymtable;
 begin
 begin
-  getsym(hs,false);
+  searchsym(hs,srsym,srsymtable);
   SearchType:=assigned(srsym) and
   SearchType:=assigned(srsym) and
              (srsym^.typ=typesym);
              (srsym^.typ=typesym);
 end;
 end;
@@ -1188,10 +1191,13 @@ end;
 
 
 
 
 Function SearchRecordType(const s:string): boolean;
 Function SearchRecordType(const s:string): boolean;
+var
+  srsym : psym;
+  srsymtable : psymtable;
 Begin
 Begin
   SearchRecordType:=false;
   SearchRecordType:=false;
 { Check the constants in symtable }
 { Check the constants in symtable }
-  getsym(s,false);
+  searchsym(s,srsym,srsymtable);
   if srsym <> nil then
   if srsym <> nil then
    Begin
    Begin
      case srsym^.typ of
      case srsym^.typ of
@@ -1217,6 +1223,9 @@ Function SearchIConstant(const s:string; var l:longint): boolean;
 { Remarks: Also handle TRUE and FALSE returning in those cases 1 and 0 }
 { Remarks: Also handle TRUE and FALSE returning in those cases 1 and 0 }
 {  respectively.                                                       }
 {  respectively.                                                       }
 {**********************************************************************}
 {**********************************************************************}
+var
+  srsym : psym;
+  srsymtable : psymtable;
 Begin
 Begin
   SearchIConstant:=false;
   SearchIConstant:=false;
 { check for TRUE or FALSE reserved words first }
 { check for TRUE or FALSE reserved words first }
@@ -1233,7 +1242,7 @@ Begin
      exit;
      exit;
    end;
    end;
 { Check the constants in symtable }
 { Check the constants in symtable }
-  getsym(s,false);
+  searchsym(s,srsym,srsymtable);
   if srsym <> nil then
   if srsym <> nil then
    Begin
    Begin
      case srsym^.typ of
      case srsym^.typ of
@@ -1266,6 +1275,7 @@ var
   st   : psymtable;
   st   : psymtable;
   harrdef : parraydef;
   harrdef : parraydef;
   sym  : psym;
   sym  : psym;
+  srsymtable : psymtable;
   i    : longint;
   i    : longint;
   base : string;
   base : string;
 Begin
 Begin
@@ -1281,8 +1291,7 @@ Begin
    st:=procinfo^._class^.symtable
    st:=procinfo^._class^.symtable
   else
   else
    begin
    begin
-     getsym(base,false);
-     sym:=srsym;
+     searchsym(base,sym,srsymtable);
      st:=nil;
      st:=nil;
      { we can start with a var,type,typedconst }
      { we can start with a var,type,typedconst }
      case sym^.typ of
      case sym^.typ of
@@ -1365,14 +1374,14 @@ end;
 Function SearchLabel(const s: string; var hl: pasmlabel;emit:boolean): boolean;
 Function SearchLabel(const s: string; var hl: pasmlabel;emit:boolean): boolean;
 var
 var
   sym : psym;
   sym : psym;
+  srsymtable : psymtable;
   hs  : string;
   hs  : string;
 Begin
 Begin
   hl:=nil;
   hl:=nil;
   SearchLabel:=false;
   SearchLabel:=false;
 { Check for pascal labels, which are case insensetive }
 { Check for pascal labels, which are case insensetive }
   hs:=upper(s);
   hs:=upper(s);
-  getsym(hs,false);
-  sym:=srsym;
+  searchsym(hs,sym,srsymtable);
   if sym=nil then
   if sym=nil then
    exit;
    exit;
   case sym^.typ of
   case sym^.typ of
@@ -1556,7 +1565,10 @@ end;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.15  2001-02-26 19:44:54  peter
+  Revision 1.16  2001-03-11 22:58:50  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.15  2001/02/26 19:44:54  peter
     * merged generic m68k updates from fixes branch
     * merged generic m68k updates from fixes branch
 
 
   Revision 1.14  2000/12/25 00:07:28  peter
   Revision 1.14  2000/12/25 00:07:28  peter

+ 11 - 4
compiler/symdef.pas

@@ -5425,6 +5425,8 @@ Const local_symtable_index : longint = $8001;
 
 
       var st : string;
       var st : string;
           symt : psymtable;
           symt : psymtable;
+          srsym : psym;
+          srsymtable : psymtable;
           old_make_ref : boolean;
           old_make_ref : boolean;
       begin
       begin
          old_make_ref:=make_ref;
          old_make_ref:=make_ref;
@@ -5434,7 +5436,7 @@ Const local_symtable_index : longint = $8001;
          if pos('.',s) > 0 then
          if pos('.',s) > 0 then
            begin
            begin
            st := copy(s,1,pos('.',s)-1);
            st := copy(s,1,pos('.',s)-1);
-           getsym(st,false);
+           searchsym(st,srsym,srsymtable);
            st := copy(s,pos('.',s)+1,255);
            st := copy(s,pos('.',s)+1,255);
            if assigned(srsym) then
            if assigned(srsym) then
              begin
              begin
@@ -5445,8 +5447,10 @@ Const local_symtable_index : longint = $8001;
                end else srsym := nil;
                end else srsym := nil;
              end;
              end;
            end else st := s;
            end else st := s;
-         if srsym = nil then getsym(st,true);
-         if srsym^.typ<>typesym then
+         if srsym = nil then
+          searchsym(st,srsym,srsymtable);
+         if (srsym=nil) or
+            (srsym^.typ<>typesym) then
            begin
            begin
              Message(type_e_type_id_expected);
              Message(type_e_type_id_expected);
              exit;
              exit;
@@ -5561,7 +5565,10 @@ Const local_symtable_index : longint = $8001;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.20  2001-01-06 20:11:29  peter
+  Revision 1.21  2001-03-11 22:58:50  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.20  2001/01/06 20:11:29  peter
     * merged c packrecords fix
     * merged c packrecords fix
 
 
   Revision 1.19  2000/12/25 00:07:29  peter
   Revision 1.19  2000/12/25 00:07:29  peter

+ 13 - 10
compiler/symsym.pas

@@ -1186,10 +1186,7 @@ implementation
          absseg:=false;
          absseg:=false;
          case abstyp of
          case abstyp of
            tovar :
            tovar :
-             begin
-               asmname:=stringdup(readstring);
-               ref:=pstoredsym(srsym);
-             end;
+             asmname:=stringdup(readstring);
            toasm :
            toasm :
              asmname:=stringdup(readstring);
              asmname:=stringdup(readstring);
            toaddr :
            toaddr :
@@ -1231,16 +1228,19 @@ implementation
 
 
 
 
     procedure tabsolutesym.deref;
     procedure tabsolutesym.deref;
+      var
+        srsym : psym;
+        srsymtable : psymtable;
       begin
       begin
          tvarsym.deref;
          tvarsym.deref;
          if (abstyp=tovar) and (asmname<>nil) then
          if (abstyp=tovar) and (asmname<>nil) then
            begin
            begin
               { search previous loaded symtables }
               { search previous loaded symtables }
-              getsym(asmname^,false);
-              if not(assigned(srsym)) then
-                getsymonlyin(owner,asmname^);
-              if not(assigned(srsym)) then
-                srsym:=generrorsym;
+              searchsym(asmname^,srsym,srsymtable);
+              if not assigned(srsym) then
+               srsym:=searchsymonlyin(owner,asmname^);
+              if not assigned(srsym) then
+               srsym:=generrorsym;
               ref:=pstoredsym(srsym);
               ref:=pstoredsym(srsym);
               stringdispose(asmname);
               stringdispose(asmname);
            end;
            end;
@@ -2471,7 +2471,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.7  2000-12-25 00:07:30  peter
+  Revision 1.8  2001-03-11 22:58:51  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.7  2000/12/25 00:07:30  peter
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
     + new tlinkedlist class (merge of old tstringqueue,tcontainer and
       tlinkedlist objects)
       tlinkedlist objects)
 
 

+ 86 - 80
compiler/symtable.pas

@@ -116,19 +116,14 @@ interface
 
 
 
 
     var
     var
-       srsym          : psym;           { result of the last search }
-       srsymtable     : psymtable;
-       lastsrsym      : psym;           { last sym found in statement }
-       lastsrsymtable : psymtable;
-       lastsymknown   : boolean;
        constsymtable  : psymtable;      { symtable were the constants can be inserted }
        constsymtable  : psymtable;      { symtable were the constants can be inserted }
        systemunit     : punitsymtable;  { pointer to the system unit }
        systemunit     : punitsymtable;  { pointer to the system unit }
-       read_member : boolean;      { reading members of an symtable }
+       read_member    : boolean;        { reading members of an symtable }
 
 
-       lexlevel : longint;       { level of code                     }
-                                   { 1 for main procedure             }
-                                   { 2 for normal function or proc     }
-                                   { higher for locals           }
+       lexlevel       : longint;       { level of code }
+                                       { 1 for main procedure }
+                                       { 2 for normal function or proc }
+                                       { higher for locals }
 
 
 {****************************************************************************
 {****************************************************************************
                              Functions
                              Functions
@@ -138,11 +133,13 @@ interface
     function  globaldef(const s : string) : pdef;
     function  globaldef(const s : string) : pdef;
     function  findunitsymtable(st:psymtable):psymtable;
     function  findunitsymtable(st:psymtable):psymtable;
     procedure duplicatesym(sym:psym);
     procedure duplicatesym(sym:psym);
+    procedure identifier_not_found(const s:string);
 
 
 {*** Search ***}
 {*** Search ***}
+    function  searchsym(const s : stringid;var srsym:psym;var srsymtable:psymtable):boolean;
     function  search_a_symtable(const symbol:string;symtabletype:tsymtabletype):Psym;
     function  search_a_symtable(const symbol:string;symtabletype:tsymtabletype):Psym;
-    procedure getsym(const s : stringid;notfounderror : boolean);
-    procedure getsymonlyin(p : psymtable;const s : stringid);
+    function  searchsymonlyin(p : psymtable;const s : stringid):psym;
+    function  search_class_member(pd : pobjectdef;const s : string):psym;
 
 
 {*** PPU Write/Loading ***}
 {*** PPU Write/Loading ***}
     procedure writeunitas(const s : string;unittable : punitsymtable;only_crc : boolean);
     procedure writeunitas(const s : string;unittable : punitsymtable;only_crc : boolean);
@@ -150,7 +147,6 @@ interface
     procedure load_interface;
     procedure load_interface;
 
 
 {*** Object Helpers ***}
 {*** Object Helpers ***}
-    function search_class_member(pd : pobjectdef;const n : string) : psym;
     function search_default_property(pd : pobjectdef) : ppropertysym;
     function search_default_property(pd : pobjectdef) : ppropertysym;
 
 
 {*** symtable stack ***}
 {*** symtable stack ***}
@@ -386,6 +382,8 @@ implementation
     procedure chainprocsym(p : psym);
     procedure chainprocsym(p : psym);
       var
       var
          storesymtablestack : psymtable;
          storesymtablestack : psymtable;
+         srsym : psym;
+         srsymtable : psymtable;
       begin
       begin
          if p^.typ=procsym then
          if p^.typ=procsym then
            begin
            begin
@@ -394,8 +392,9 @@ implementation
               while assigned(symtablestack) do
               while assigned(symtablestack) do
                 begin
                 begin
                   { search for same procsym in other units }
                   { search for same procsym in other units }
-                  getsym(p^.name,false);
-                  if assigned(srsym) and (srsym^.typ=procsym) then
+                  searchsym(p^.name,srsym,srsymtable)
+                  if assigned(srsym) and
+                     (srsym^.typ=procsym) then
                     begin
                     begin
                        pprocsym(p)^.nextprocsym:=pprocsym(srsym);
                        pprocsym(p)^.nextprocsym:=pprocsym(srsym);
                        symtablestack:=storesymtablestack;
                        symtablestack:=storesymtablestack;
@@ -448,6 +447,8 @@ implementation
         p : pprocsym;
         p : pprocsym;
         t : ttoken;
         t : ttoken;
         def : pprocdef;
         def : pprocdef;
+        srsym : psym;
+        srsymtable,
         storesymtablestack : psymtable;
         storesymtablestack : psymtable;
       begin
       begin
          storesymtablestack:=symtablestack;
          storesymtablestack:=symtablestack;
@@ -461,12 +462,15 @@ implementation
               { each operator has a unique lowercased internal name PM }
               { each operator has a unique lowercased internal name PM }
               while assigned(symtablestack) do
               while assigned(symtablestack) do
                 begin
                 begin
-                  getsym(overloaded_names[t],false);
-                  if (t=_STARSTAR) and (srsym=nil) then
-                    begin
-                      symtablestack:=systemunit;
-                      getsym('POWER',false);
-                    end;
+                  searchsym(overloaded_names[t],srsym,srsymtable);
+                  if not assigned(srsym) then
+                   begin
+                     if (t=_STARSTAR) then
+                      begin
+                        symtablestack:=systemunit;
+                        searchsym('POWER',srsym,srsymtable);
+                      end;
+                   end;
                   if assigned(srsym) then
                   if assigned(srsym) then
                     begin
                     begin
                        if (srsym^.typ<>procsym) then
                        if (srsym^.typ<>procsym) then
@@ -486,7 +490,7 @@ implementation
                          (def^.nextoverloaded^.owner=p^.owner) do
                          (def^.nextoverloaded^.owner=p^.owner) do
                          def:=def^.nextoverloaded;
                          def:=def^.nextoverloaded;
                        def^.nextoverloaded:=nil;
                        def^.nextoverloaded:=nil;
-                       symtablestack:=srsymtable^.next;
+                       symtablestack:=srsym^.owner^.next;
                     end
                     end
                   else
                   else
                     begin
                     begin
@@ -734,7 +738,6 @@ implementation
 
 
     procedure tstoredsymtable.prederef;
     procedure tstoredsymtable.prederef;
       var
       var
-        hp : pdef;
         hs : psym;
         hs : psym;
       begin
       begin
         { first deref the ttypesyms }
         { first deref the ttypesyms }
@@ -1085,8 +1088,8 @@ implementation
              is_object(pdef(defowner))
              is_object(pdef(defowner))
             ) then
             ) then
            begin
            begin
-              hsym:=search_class_member(pobjectdef(defowner),sym^.name);
               { but private ids can be reused }
               { but private ids can be reused }
+              hsym:=search_class_member(pobjectdef(defowner),sym^.name);
               if assigned(hsym) and
               if assigned(hsym) and
                 (not(sp_private in hsym^.symoptions) or
                 (not(sp_private in hsym^.symoptions) or
                  (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
                  (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
@@ -2047,7 +2050,7 @@ implementation
          { show a fatal that you need -S2 or -Sd, but only
          { show a fatal that you need -S2 or -Sd, but only
            if we just parsed the a token that has m_class }
            if we just parsed the a token that has m_class }
          if not(m_class in aktmodeswitches) and
          if not(m_class in aktmodeswitches) and
-            (s=pattern) and
+            (Upper(s)=pattern) and
             (tokeninfo^[idtoken].keyword=m_class) then
             (tokeninfo^[idtoken].keyword=m_class) then
            Message(parser_f_need_objfpc_or_delphi_mode);
            Message(parser_f_need_objfpc_or_delphi_mode);
        end;
        end;
@@ -2058,55 +2061,73 @@ implementation
                                   Search
                                   Search
 *****************************************************************************}
 *****************************************************************************}
 
 
-    procedure getsym(const s : stringid;notfounderror : boolean);
+    function  searchsym(const s : stringid;var srsym:psym;var srsymtable:psymtable):boolean;
       var
       var
         speedvalue : longint;
         speedvalue : longint;
       begin
       begin
          speedvalue:=getspeedvalue(s);
          speedvalue:=getspeedvalue(s);
-         lastsrsym:=nil;
          srsymtable:=symtablestack;
          srsymtable:=symtablestack;
          while assigned(srsymtable) do
          while assigned(srsymtable) do
            begin
            begin
               srsym:=psym(srsymtable^.speedsearch(s,speedvalue));
               srsym:=psym(srsymtable^.speedsearch(s,speedvalue));
               if assigned(srsym) then
               if assigned(srsym) then
-                exit
+               begin
+                 searchsym:=true;
+                 exit;
+               end
               else
               else
-                srsymtable:=srsymtable^.next;
+               srsymtable:=srsymtable^.next;
            end;
            end;
-         if notfounderror then
-           begin
-              identifier_not_found(s);
-              srsym:=generrorsym;
-           end
-         else
-           srsym:=nil;
+         searchsym:=false;
       end;
       end;
 
 
 
 
-    procedure getsymonlyin(p : psymtable;const s : stringid);
+    function  searchsymonlyin(p : psymtable;const s : stringid):psym;
+      var
+        srsym      : psym;
       begin
       begin
-         { the caller have to take care if srsym=nil (FK) }
-         srsym:=nil;
+         { the caller have to take care if srsym=nil }
          if assigned(p) then
          if assigned(p) then
            begin
            begin
-              srsymtable:=p;
-              srsym:=psym(srsymtable^.search(s));
+              srsym:=psym(p^.search(s));
               if assigned(srsym) then
               if assigned(srsym) then
-                exit
-              else
                begin
                begin
-                  if (punitsymtable(srsymtable)=punitsymtable(current_module.globalsymtable)) then
-                    begin
-                       getsymonlyin(psymtable(current_module.localsymtable),s);
-                       if assigned(srsym) then
-                         srsymtable:=psymtable(current_module.localsymtable)
-                       else
-                         identifier_not_found(s);
-                    end
-                  else
-                    identifier_not_found(s);
+                 searchsymonlyin:=srsym;
+                 exit;
                end;
                end;
+              { also check in the local symtbale if it exists }
+              if (punitsymtable(p)=punitsymtable(current_module.globalsymtable)) then
+                begin
+                   srsym:=psym(psymtable(current_module.localsymtable)^.search(s));
+                   if assigned(srsym) then
+                    begin
+                      searchsymonlyin:=srsym;
+                      exit;
+                    end;
+                end
            end;
            end;
+         searchsymonlyin:=nil;
+       end;
+
+
+    function search_class_member(pd : pobjectdef;const s : string):psym;
+    { searches n in symtable of pd and all anchestors }
+      var
+        speedvalue : longint;
+        srsym      : psym;
+      begin
+        speedvalue:=getspeedvalue(s);
+        while assigned(pd) do
+         begin
+           srsym:=psym(pd^.symtable^.speedsearch(s,speedvalue));
+           if assigned(srsym) then
+            begin
+              search_class_member:=srsym;
+              exit;
+            end;
+           pd:=pd^.childof;
+         end;
+        search_class_member:=nil;
       end;
       end;
 
 
 
 
@@ -2138,12 +2159,14 @@ implementation
 
 
       var st : string;
       var st : string;
           symt : psymtable;
           symt : psymtable;
+          srsym      : psym;
+          srsymtable : psymtable;
       begin
       begin
          srsym := nil;
          srsym := nil;
          if pos('.',s) > 0 then
          if pos('.',s) > 0 then
            begin
            begin
            st := copy(s,1,pos('.',s)-1);
            st := copy(s,1,pos('.',s)-1);
-           getsym(st,false);
+           searchsym(st,srsym,srsymtable);
            st := copy(s,pos('.',s)+1,255);
            st := copy(s,pos('.',s)+1,255);
            if assigned(srsym) then
            if assigned(srsym) then
              begin
              begin
@@ -2154,10 +2177,12 @@ implementation
                end else srsym := nil;
                end else srsym := nil;
              end;
              end;
            end else st := s;
            end else st := s;
-         if srsym = nil then getsym(st,false);
          if srsym = nil then
          if srsym = nil then
-           getsymonlyin(systemunit,st);
-         if srsym^.typ<>typesym then
+          searchsym(st,srsym,srsymtable);
+         if srsym = nil then
+           srsym:=searchsymonlyin(systemunit,st);
+         if (not assigned(srsym)) or
+            (srsym^.typ<>typesym) then
            begin
            begin
              Message(type_e_type_id_expected);
              Message(type_e_type_id_expected);
              exit;
              exit;
@@ -2169,28 +2194,6 @@ implementation
                               Object Helpers
                               Object Helpers
 ****************************************************************************}
 ****************************************************************************}
 
 
-    function search_class_member(pd : pobjectdef;const n : string) : psym;
-    { searches n in symtable of pd and all anchestors }
-      var
-         sym : psym;
-      begin
-         sym:=nil;
-         while assigned(pd) do
-           begin
-              sym:=psym(pd^.symtable^.search(n));
-              if assigned(sym) then
-                break;
-              pd:=pd^.childof;
-           end;
-         { this is needed for static methods in do_member_read pexpr unit PM
-           caused bug0214 }
-         if assigned(sym) then
-           begin
-             srsymtable:=pd^.symtable;
-           end;
-         search_class_member:=sym;
-      end;
-
    var
    var
       _defaultprop : ppropertysym;
       _defaultprop : ppropertysym;
 
 
@@ -2374,7 +2377,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.26  2001-02-21 19:37:19  peter
+  Revision 1.27  2001-03-11 22:58:51  peter
+    * getsym redesign, removed the globals srsym,srsymtable
+
+  Revision 1.26  2001/02/21 19:37:19  peter
     * moved deref to be done after loading of implementation units. prederef
     * moved deref to be done after loading of implementation units. prederef
       is still done directly after loading of symbols and definitions.
       is still done directly after loading of symbols and definitions.