pasuseanalyzer: test for wpo resourcestring in other unit

git-svn-id: trunk@37547 -
This commit is contained in:
Mattias Gaertner 2017-11-01 23:33:30 +00:00
parent 194c0c7073
commit 399beb084b
2 changed files with 56 additions and 16 deletions

View File

@ -1960,7 +1960,7 @@ begin
or C.InheritsFrom(TPasVariable) or C.InheritsFrom(TPasVariable)
or C.InheritsFrom(TPasProcedure) or C.InheritsFrom(TPasProcedure)
or C.InheritsFrom(TPasModule) or C.InheritsFrom(TPasModule)
or C.InheritsFrom(TPasResString); or (C=TPasResString);
end; end;
function TPasAnalyzer.IsImplBlockEmpty(El: TPasImplBlock): boolean; function TPasAnalyzer.IsImplBlockEmpty(El: TPasImplBlock): boolean;

View File

@ -60,6 +60,7 @@ type
procedure TestM_RangeType; procedure TestM_RangeType;
procedure TestM_Unary; procedure TestM_Unary;
procedure TestM_Const; procedure TestM_Const;
procedure TestM_ResourceString;
procedure TestM_Record; procedure TestM_Record;
procedure TestM_Array; procedure TestM_Array;
procedure TestM_NestedFuncResult; procedure TestM_NestedFuncResult;
@ -110,6 +111,7 @@ type
// whole program optimization // whole program optimization
procedure TestWP_LocalVar; procedure TestWP_LocalVar;
procedure TestWP_UnitUsed; procedure TestWP_UnitUsed;
procedure TestWP_UnitUsed_ResourceString;
procedure TestWP_UnitNotUsed; procedure TestWP_UnitNotUsed;
procedure TestWP_UnitInitialization; procedure TestWP_UnitInitialization;
procedure TestWP_UnitFinalization; procedure TestWP_UnitFinalization;
@ -545,21 +547,40 @@ end;
procedure TTestUseAnalyzer.TestM_Const; procedure TTestUseAnalyzer.TestM_Const;
begin begin
StartProgram(false); StartProgram(false);
Add('resourcestring {#rs_used}rs = ''txt'';'); Add([
Add('procedure {#DoIt_used}DoIt;'); 'procedure {#DoIt_used}DoIt;',
Add('var'); 'var',
Add(' {#a_used}a: longint;'); ' {#a_used}a: longint;',
Add(' {#b_used}b: boolean;'); ' {#b_used}b: boolean;',
Add(' {#c_used}c: array of longint;'); ' {#c_used}c: array of longint;',
Add(' {#d_used}d: string;'); ' {#d_used}d: string;',
Add('begin'); 'begin',
Add(' a:=+1;'); ' a:=+1;',
Add(' b:=true;'); ' b:=true;',
Add(' c:=nil;'); ' c:=nil;',
Add(' d:=''foo''+rs;'); ' d:=''foo'';',
Add('end;'); 'end;',
Add('begin'); 'begin',
Add(' DoIt;'); ' DoIt;']);
AnalyzeProgram;
end;
procedure TTestUseAnalyzer.TestM_ResourceString;
begin
StartProgram(false);
Add([
'resourcestring',
'resourcestring',
' {#a_used}a = ''txt'';',
' {#b_used}b = ''foo'';',
'procedure {#DoIt_used}DoIt(s: string);',
'var',
' {#d_used}d: string;',
'begin',
' d:=b;',
'end;',
'begin',
' DoIt(a);']);
AnalyzeProgram; AnalyzeProgram;
end; end;
@ -1519,6 +1540,25 @@ begin
CheckUnitUsed('unit2.pp',true); CheckUnitUsed('unit2.pp',true);
end; end;
procedure TTestUseAnalyzer.TestWP_UnitUsed_ResourceString;
begin
AddModuleWithIntfImplSrc('unit2.pp',
LinesToStr([
'resourcestring rs = ''txt'';',
'procedure DoIt;',
'']),
LinesToStr([
'procedure DoIt; begin end;']));
StartProgram(true);
Add('uses unit2;');
Add('begin');
Add(' if rs='''' then ;');
AnalyzeWholeProgram;
CheckUnitUsed('unit2.pp',true);
end;
procedure TTestUseAnalyzer.TestWP_UnitNotUsed; procedure TTestUseAnalyzer.TestWP_UnitNotUsed;
begin begin
AddModuleWithIntfImplSrc('unit2.pp', AddModuleWithIntfImplSrc('unit2.pp',