Browse Source

* Patch from Mattias Gaertner to check implicit units when there is no uses list

git-svn-id: trunk@34214 -
michael 9 years ago
parent
commit
57ab472c72
1 changed files with 35 additions and 24 deletions
  1. 35 24
      packages/fcl-passrc/src/pparser.pp

+ 35 - 24
packages/fcl-passrc/src/pparser.pp

@@ -257,6 +257,8 @@ type
     function DoParseExpression(Aparent : TPaselement;InitExpr: TPasExpr=nil): TPasExpr;
     function DoParseExpression(Aparent : TPaselement;InitExpr: TPasExpr=nil): TPasExpr;
     function DoParseConstValueExpression(AParent : TPasElement): TPasExpr;
     function DoParseConstValueExpression(AParent : TPasElement): TPasExpr;
     function CheckPackMode: TPackMode;
     function CheckPackMode: TPackMode;
+    function CheckUseUnit(ASection: TPasSection; AUnitName : string): TPasElement;
+    procedure CheckImplicitUsedUnits(ASection: TPasSection);
     // Overload handling
     // Overload handling
     procedure AddProcOrFunction(Decs: TPasDeclarations; AProc: TPasProcedure);
     procedure AddProcOrFunction(Decs: TPasDeclarations; AProc: TPasProcedure);
     function  CheckIfOverloaded(AParent: TPasElement; const AName: String): TPasElement;
     function  CheckIfOverloaded(AParent: TPasElement; const AName: String): TPasElement;
@@ -1965,8 +1967,10 @@ begin
   NextToken;
   NextToken;
   if CurToken=tkuses then
   if CurToken=tkuses then
     ParseUsesList(ASection)
     ParseUsesList(ASection)
-  else
+  else begin
+    CheckImplicitUsedUnits(ASection);
     UngetToken;
     UngetToken;
+  end;
 end;
 end;
 
 
 // Starts after the "interface" token
 // Starts after the "interface" token
@@ -2347,8 +2351,8 @@ begin
   end;
   end;
 end;
 end;
 
 
-// Starts after the "uses" token
-procedure TPasParser.ParseUsesList(ASection: TPasSection);
+function TPasParser.CheckUseUnit(ASection: TPasSection; AUnitName: string
+  ): TPasElement;
 
 
   procedure CheckDuplicateInUsesList(AUnitName : string; UsesList: TFPList);
   procedure CheckDuplicateInUsesList(AUnitName : string; UsesList: TFPList);
   var
   var
@@ -2360,34 +2364,41 @@ procedure TPasParser.ParseUsesList(ASection: TPasSection);
         ParseExc(nParserDuplicateIdentifier,SParserDuplicateIdentifier,[AUnitName]);
         ParseExc(nParserDuplicateIdentifier,SParserDuplicateIdentifier,[AUnitName]);
   end;
   end;
 
 
-  function CheckUnit(AUnitName : string):TPasElement;
-  begin
-    if CompareText(AUnitName,CurModule.Name)=0 then
-      ParseExc(nParserDuplicateIdentifier,SParserDuplicateIdentifier,[AUnitName]);
-    CheckDuplicateInUsesList(AUnitName,ASection.UsesList);
-    if ASection.ClassType=TImplementationSection then
-      CheckDuplicateInUsesList(AUnitName,CurModule.InterfaceSection.UsesList);
-
-    result := Engine.FindModule(AUnitName);  // should we resolve module here when "IN" filename is not known yet?
-    if Assigned(result) then
-      result.AddRef
-    else
-      Result := TPasType(CreateElement(TPasUnresolvedUnitRef, AUnitName,
-        ASection));
-    ASection.UsesList.Add(Result);
-  end;
+begin
+  if CompareText(AUnitName,CurModule.Name)=0 then
+    ParseExc(nParserDuplicateIdentifier,SParserDuplicateIdentifier,[AUnitName]);
+  CheckDuplicateInUsesList(AUnitName,ASection.UsesList);
+  if ASection.ClassType=TImplementationSection then
+    CheckDuplicateInUsesList(AUnitName,CurModule.InterfaceSection.UsesList);
+
+  result := Engine.FindModule(AUnitName);  // should we resolve module here when "IN" filename is not known yet?
+  if Assigned(result) then
+    result.AddRef
+  else
+    Result := TPasType(CreateElement(TPasUnresolvedUnitRef, AUnitName,
+      ASection));
+  ASection.UsesList.Add(Result);
+end;
 
 
+procedure TPasParser.CheckImplicitUsedUnits(ASection: TPasSection);
 var
 var
-  AUnitName: String;
-  Element: TPasElement;
   i: Integer;
   i: Integer;
 begin
 begin
-  If not (Asection.ClassType=TImplementationSection) Then // interface,program,library,package
+  If not (ASection.ClassType=TImplementationSection) Then // interface,program,library,package
     begin
     begin
     // load implicit units, like 'System'
     // load implicit units, like 'System'
     for i:=0 to ImplicitUses.Count-1 do
     for i:=0 to ImplicitUses.Count-1 do
-      CheckUnit(ImplicitUses[i]);
+      CheckUseUnit(ASection,ImplicitUses[i]);
     end;
     end;
+end;
+
+// Starts after the "uses" token
+procedure TPasParser.ParseUsesList(ASection: TPasSection);
+var
+  AUnitName: String;
+  Element: TPasElement;
+begin
+  CheckImplicitUsedUnits(ASection);
 
 
   Repeat
   Repeat
     AUnitName := ExpectIdentifier;
     AUnitName := ExpectIdentifier;
@@ -2398,7 +2409,7 @@ begin
       AUnitName := AUnitName + '.' + CurTokenString;
       AUnitName := AUnitName + '.' + CurTokenString;
       NextToken;
       NextToken;
     end;
     end;
-    Element := CheckUnit(AUnitName);
+    Element := CheckUseUnit(ASection,AUnitName);
     if (CurToken=tkin) then
     if (CurToken=tkin) then
       begin
       begin
       ExpectToken(tkString);
       ExpectToken(tkString);