Browse Source

* Merging revisions r46441 from trunk:
------------------------------------------------------------------------
r46441 | michael | 2020-08-15 09:25:48 +0200 (Sat, 15 Aug 2020) | 1 line

* Check unit alias possibility
------------------------------------------------------------------------

git-svn-id: branches/fixes_3_2@46622 -

michael 5 years ago
parent
commit
b36e691404
1 changed files with 15 additions and 2 deletions
  1. 15 2
      packages/fcl-passrc/src/paswrite.pp

+ 15 - 2
packages/fcl-passrc/src/paswrite.pp

@@ -43,6 +43,8 @@ type
                       );
   TPasWriterOptions = Set of TPasWriterOption;
 
+  TOnUnitAlias = function(const UnitName : String) : String of Object;
+
   TPasWriter = class
   private
     FCurrentLineNumber : Integer;
@@ -51,6 +53,7 @@ type
     FForwardClasses: TStrings;
     FLineEnding: String;
     FLineNumberWidth: Integer;
+    FOnUnitAlias: TOnUnitAlias;
     FOPtions: TPasWriterOptions;
     FStream: TStream;
     FIndentSize : Integer;
@@ -63,6 +66,7 @@ type
     FInImplementation : Boolean;
     procedure SetForwardClasses(AValue: TStrings);
     procedure SetIndentSize(AValue: Integer);
+    function CheckUnitAlias(const AUnitName : String) : String;
   protected
     procedure DisableHintsWarnings;
     procedure PrepareDeclSectionInStruct(const ADeclSection: string);
@@ -132,6 +136,7 @@ type
     procedure wrtln;overload; deprecated ;
     property Stream: TStream read FStream;
   Published
+    Property OnUnitAlias : TOnUnitAlias Read FOnUnitAlias Write FOnUnitAlias;
     Property Options : TPasWriterOptions Read FOPtions Write FOptions;
     Property IndentSize : Integer Read FIndentSize Write SetIndentSize;
     Property LineEnding : String Read FLineEnding Write FLineEnding;
@@ -478,7 +483,7 @@ end;
 procedure TPasWriter.WriteUnit(aModule: TPasModule);
 
 begin
-  AddLn('unit ' + AModule.SafeName + ';');
+  AddLn('unit ' + CheckUnitAlias(AModule.SafeName) + ';');
   if Assigned(AModule.GlobalDirectivesSection) then
     begin
     AddLn;
@@ -556,7 +561,7 @@ Var
       Add(', ')
     else
       Add('uses ');
-    Add(AName);
+    Add(CheckUnitAlias(AName));
     if (AUnitFile<>Nil) then
       Add(' in '+GetExpr(AUnitFile));
     Inc(c);
@@ -1491,6 +1496,14 @@ begin
   FIndentStep:=StringOfChar(' ',aValue);
 end;
 
+function TPasWriter.CheckUnitAlias(const AUnitName: String): String;
+begin
+  if Assigned(FOnUnitAlias) then
+    Result := FOnUnitAlias(AUnitName)
+  else
+    Result := AUnitName;
+end;
+
 function TPasWriter.HasOption(aOption: TPasWriterOption): Boolean;
 begin
   Result:=(aOption in FOptions)