Bläddra i källkod

* give a proper error if macros are too deeply nested

git-svn-id: trunk@48357 -
florian 4 år sedan
förälder
incheckning
9803318fef
3 ändrade filer med 20 tillägg och 2 borttagningar
  1. 1 0
      .gitattributes
  2. 8 2
      compiler/scanner.pas
  3. 11 0
      tests/webtbf/tw38287.pp

+ 1 - 0
.gitattributes

@@ -16702,6 +16702,7 @@ tests/webtbf/tw37476.pp svneol=native#text/pascal
 tests/webtbf/tw37763.pp svneol=native#text/pascal
 tests/webtbf/tw3790.pp svneol=native#text/plain
 tests/webtbf/tw3812.pp svneol=native#text/plain
+tests/webtbf/tw38287.pp svneol=native#text/pascal
 tests/webtbf/tw38289a.pp svneol=native#text/pascal
 tests/webtbf/tw38289b.pp svneol=native#text/pascal
 tests/webtbf/tw3930a.pp svneol=native#text/plain

+ 8 - 2
compiler/scanner.pas

@@ -135,6 +135,8 @@ interface
           { if nexttoken<>NOTOKEN, then nexttokenpos holds its filepos }
           next_filepos   : tfileposinfo;
 
+          { current macro nesting depth }
+          macro_nesting_depth,
           comment_level,
           yylexcount     : longint;
           ignoredirectives : TFPHashList; { ignore directives, used to give warnings only once }
@@ -2922,7 +2924,10 @@ type
         if assigned(inputfile.next) then
          begin
            if inputfile.is_macro then
-             to_dispose:=inputfile
+             begin
+               to_dispose:=inputfile;
+               dec(macro_nesting_depth);
+             end
            else
              begin
                to_dispose:=nil;
@@ -3686,6 +3691,7 @@ type
         addfile(hp);
         with inputfile do
          begin
+           inc(macro_nesting_depth);
            setmacro(p,len);
          { local buffer }
            inputbuffer:=buf;
@@ -4868,7 +4874,7 @@ type
                  mac:=tmacro(search_macro(pattern));
                  if assigned(mac) and (not mac.is_compiler_var) and (assigned(mac.buftext)) then
                   begin
-                    if yylexcount<max_macro_nesting then
+                    if (yylexcount<max_macro_nesting) and (macro_nesting_depth<max_macro_nesting) then
                      begin
                        mac.is_used:=true;
                        inc(yylexcount);

+ 11 - 0
tests/webtbf/tw38287.pp

@@ -0,0 +1,11 @@
+{$macro on}
+var
+  a,b,s : real;
+
+begin
+  a:=1;
+  b:=2;
+{$define sum:=a+b }
+{$define b:=sum} { DON’T do this !!!}
+  s:=sum;         { Will be infinitely recursively expanded... }
+end.