Browse Source

compiler: refactor preproc_substitutedtoken - pass the searchstr into it

git-svn-id: trunk@25475 -
paul 12 years ago
parent
commit
73dab82a7f
1 changed files with 18 additions and 22 deletions
  1. 18 22
      compiler/scanner.pas

+ 18 - 22
compiler/scanner.pas

@@ -1415,7 +1415,7 @@ type
                end;
                end;
           end;
           end;
 
 
-        function preproc_substitutedtoken(eval : Boolean): texprvalue;
+        function preproc_substitutedtoken(searchstr:string;eval:Boolean):texprvalue;
         { Currently this parses identifiers as well as numbers.
         { Currently this parses identifiers as well as numbers.
           The result from this procedure can either be that the token
           The result from this procedure can either be that the token
           itself is a value, or that it is a compile time variable/macro,
           itself is a value, or that it is a compile time variable/macro,
@@ -1423,24 +1423,23 @@ type
           recursivelly substituted).}
           recursivelly substituted).}
 
 
         var
         var
-          hs,pp: string;
+          hs: string;
           mac: tmacro;
           mac: tmacro;
           macrocount,
           macrocount,
           len: integer;
           len: integer;
         begin
         begin
-          pp:=current_scanner.preproc_pattern;
           if not eval then
           if not eval then
             begin
             begin
-              result:=texprvalue.create_str(pp);
+              result:=texprvalue.create_str(searchstr);
               exit;
               exit;
             end;
             end;
 
 
-          mac:= nil;
+          mac:=nil;
           { Substitue macros and compiler variables with their content/value.
           { Substitue macros and compiler variables with their content/value.
             For real macros also do recursive substitution. }
             For real macros also do recursive substitution. }
           macrocount:=0;
           macrocount:=0;
           repeat
           repeat
-            mac:=tmacro(search_macro(pp));
+            mac:=tmacro(search_macro(searchstr));
 
 
             inc(macrocount);
             inc(macrocount);
             if macrocount>max_macro_nesting then
             if macrocount>max_macro_nesting then
@@ -1461,18 +1460,16 @@ type
                     len:=mac.buflen;
                     len:=mac.buflen;
                   hs[0]:=char(len);
                   hs[0]:=char(len);
                   move(mac.buftext^,hs[1],len);
                   move(mac.buftext^,hs[1],len);
-                  pp:=upcase(hs);
+                  searchstr:=upcase(hs);
                   mac.is_used:=true;
                   mac.is_used:=true;
                 end
                 end
               else
               else
                 begin
                 begin
-                  Message1(scan_e_error_macro_lacks_value, pp);
+                  Message1(scan_e_error_macro_lacks_value,searchstr);
                   break;
                   break;
                 end
                 end
             else
             else
-              begin
-                  break;
-              end;
+              break;
 
 
             if mac.is_compiler_var then
             if mac.is_compiler_var then
               break;
               break;
@@ -1480,12 +1477,12 @@ type
 
 
           { At this point, result do contain the value. Do some decoding and
           { At this point, result do contain the value. Do some decoding and
             determine the type.}
             determine the type.}
-          result:=texprvalue.try_parse_number(pp);
+          result:=texprvalue.try_parse_number(searchstr);
           if not assigned(result) then
           if not assigned(result) then
             begin
             begin
-              if assigned(mac) and (pp='FALSE') then
+              if assigned(mac) and (searchstr='FALSE') then
                 result:=texprvalue.create_bool(false)
                 result:=texprvalue.create_bool(false)
-              else if assigned(mac) and (pp='TRUE') then
+              else if assigned(mac) and (searchstr='TRUE') then
                 result:=texprvalue.create_bool(true)
                 result:=texprvalue.create_bool(true)
               else if (m_mac in current_settings.modeswitches) and
               else if (m_mac in current_settings.modeswitches) and
                       (not assigned(mac) or not mac.defined) and
                       (not assigned(mac) or not mac.defined) and
@@ -1493,11 +1490,11 @@ type
                 begin
                 begin
                   {Errors in mode mac is issued here. For non macpas modes there is
                   {Errors in mode mac is issued here. For non macpas modes there is
                    more liberty, but the error will eventually be caught at a later stage.}
                    more liberty, but the error will eventually be caught at a later stage.}
-                  Message1(scan_e_error_macro_undefined, pp);
-                  result:=texprvalue.create_str(pp); { just to have something }
+                  Message1(scan_e_error_macro_undefined,searchstr);
+                  result:=texprvalue.create_str(searchstr); { just to have something }
                 end
                 end
               else
               else
-                result:=texprvalue.create_str(pp);
+                result:=texprvalue.create_str(searchstr);
             end;
             end;
         end;
         end;
 
 
@@ -1850,24 +1847,23 @@ type
                   end
                   end
                 else
                 else
                   begin
                   begin
-                    result:=preproc_substitutedtoken(eval);
-
-                    { Default is to return the original symbol }
                     storedpattern:=current_scanner.preproc_pattern;
                     storedpattern:=current_scanner.preproc_pattern;
                     preproc_consume(_ID);
                     preproc_consume(_ID);
                     current_scanner.skipspace;
                     current_scanner.skipspace;
+                    { first look for a macros/int/float }
+                    result:=preproc_substitutedtoken(storedpattern,eval);
                     if eval and (result.consttyp=conststring) then
                     if eval and (result.consttyp=conststring) then
                       if searchsym(storedpattern,srsym,srsymtable) then
                       if searchsym(storedpattern,srsym,srsymtable) then
                         begin
                         begin
                           try_consume_nestedsym(srsym,srsymtable);
                           try_consume_nestedsym(srsym,srsymtable);
                           if assigned(srsym) then
                           if assigned(srsym) then
                             case srsym.typ of
                             case srsym.typ of
-                              constsym :
+                              constsym:
                                 begin
                                 begin
                                   result.free;
                                   result.free;
                                   result:=texprvalue.create_const(tconstsym(srsym));
                                   result:=texprvalue.create_const(tconstsym(srsym));
                                 end;
                                 end;
-                              enumsym :
+                              enumsym:
                                 begin
                                 begin
                                   result.free;
                                   result.free;
                                   result:=texprvalue.create_int(tenumsym(srsym).value);
                                   result:=texprvalue.create_int(tenumsym(srsym).value);