ソースを参照

* for symbols used in preprocessor expressions, we don't want to increase references count (for smaller final binaries). Partial fix for problem presented in mantis 31675. Preprocessor functions like declared() in uses section will work only for symbols declared in implicytly included modules (for example like for heaptrc by option -gh, see example/test tw31675.pp)

+ added tests

git-svn-id: trunk@36128 -
maciej-izak 8 年 前
コミット
6d1ad52dc5
5 ファイル変更52 行追加1 行削除
  1. 2 0
      .gitattributes
  2. 5 0
      compiler/scanner.pas
  3. 7 1
      compiler/symtable.pas
  4. 25 0
      tests/webtbs/tw31675.pp
  5. 13 0
      tests/webtbs/uw31675.pp

+ 2 - 0
.gitattributes

@@ -15479,6 +15479,7 @@ tests/webtbs/tw3160b.pp svneol=native#text/plain
 tests/webtbs/tw3160c.pp svneol=native#text/plain
 tests/webtbs/tw3161.pp svneol=native#text/plain
 tests/webtbs/tw3165.pp svneol=native#text/plain
+tests/webtbs/tw31675.pp svneol=native#text/pascal
 tests/webtbs/tw3168.pp svneol=native#text/plain
 tests/webtbs/tw3170.pp svneol=native#text/plain
 tests/webtbs/tw3172.pp svneol=native#text/plain
@@ -16141,6 +16142,7 @@ tests/webtbs/uw2956.pp svneol=native#text/plain
 tests/webtbs/uw2984.pp svneol=native#text/plain
 tests/webtbs/uw3103.pp svneol=native#text/plain
 tests/webtbs/uw31431.pp svneol=native#text/pascal
+tests/webtbs/uw31675.pp svneol=native#text/pascal
 tests/webtbs/uw3179a.pp svneol=native#text/plain
 tests/webtbs/uw3179b.pp svneol=native#text/plain
 tests/webtbs/uw3184a.pp svneol=native#text/plain

+ 5 - 0
compiler/scanner.pas

@@ -238,6 +238,9 @@ interface
 {$endif PREPROCWRITE}
 
     var
+        { true, if we are parsing preprocessor expressions }
+        in_preproc_comp_expr: boolean = false;
+
         { read strings }
         c              : char;
         orgpattern,
@@ -2117,10 +2120,12 @@ type
         end;
 
      begin
+       in_preproc_comp_expr:=true;
        current_scanner.skipspace;
        { start preproc expression scanner }
        current_scanner.preproc_token:=current_scanner.readpreproc;
        preproc_comp_expr:=preproc_sub_expr(opcompare,true);
+       in_preproc_comp_expr:=false;
      end;
 
     function boolean_compile_time_expr(var valuedescr: string): Boolean;

+ 7 - 1
compiler/symtable.pas

@@ -459,7 +459,9 @@ implementation
       { codegen }
       procinfo,
       { ppu }
-      entfile
+      entfile,
+      { parser }
+      scanner
       ;
 
 
@@ -2795,6 +2797,10 @@ implementation
        var
          owner: tsymtable;
        begin
+         { for symbols used in preprocessor expressions, we don't want to
+           increase references count (for smaller final binaries) }
+         if in_preproc_comp_expr then
+           exit;
          { symbol uses count }
          sym.IncRefCount;
          owner:=sym.owner;

+ 25 - 0
tests/webtbs/tw31675.pp

@@ -0,0 +1,25 @@
+{ %opt=-gh }
+
+program tw31675;
+
+{$mode objfpc}{$H+}
+
+uses
+  Classes,
+  {$if declared(useheaptrace)}
+  uw31675,
+  {$endif}
+  SysUtils
+  ;
+
+var
+  i: Boolean = false;
+begin
+{$if declared(foo)}
+  i := true;
+{$endif}
+  if not i then
+    Halt(1);
+  WriteLn('ok');
+end.
+

+ 13 - 0
tests/webtbs/uw31675.pp

@@ -0,0 +1,13 @@
+unit uw31675;
+
+{$MODE DELPHI}
+
+interface
+
+var
+  foo: boolean;
+
+implementation
+
+end.
+