Browse Source

* Fix warnings and hints

git-svn-id: trunk@45512 -
michael 5 years ago
parent
commit
1877d667c4

+ 11 - 4
packages/fcl-passrc/src/pastree.pp

@@ -3821,7 +3821,9 @@ end;
 function TPasImplIfElse.Condition: string;
 function TPasImplIfElse.Condition: string;
 begin
 begin
   If Assigned(ConditionExpr) then
   If Assigned(ConditionExpr) then
-    Result:=ConditionExpr.GetDeclaration(True);
+    Result:=ConditionExpr.GetDeclaration(True)
+  else
+    Result:='';
 end;
 end;
 
 
 destructor TPasImplForLoop.Destroy;
 destructor TPasImplForLoop.Destroy;
@@ -4618,6 +4620,8 @@ function TPasVariable.Value: String;
 begin
 begin
   If Assigned(Expr) then
   If Assigned(Expr) then
     Result:=Expr.GetDeclaration(True)
     Result:=Expr.GetDeclaration(True)
+  else
+    Result:='';
 end;
 end;
 
 
 function TPasProperty.GetDeclaration (full : boolean) : string;
 function TPasProperty.GetDeclaration (full : boolean) : string;
@@ -4627,6 +4631,7 @@ Var
   I : Integer;
   I : Integer;
 
 
 begin
 begin
+  Result:='';
   If Assigned(VarType) then
   If Assigned(VarType) then
     begin
     begin
     If VarType.Name='' then
     If VarType.Name='' then
@@ -5105,8 +5110,8 @@ begin
     UsesUnit:=TPasUsesUnit.Create(AUnitName,Self);
     UsesUnit:=TPasUsesUnit.Create(AUnitName,Self);
     if aName<>nil then
     if aName<>nil then
       begin
       begin
-      Result.SourceFilename:=aName.SourceFilename;
-      Result.SourceLinenumber:=aName.SourceLinenumber;
+      UsesUnit.SourceFilename:=aName.SourceFilename;
+      UsesUnit.SourceLinenumber:=aName.SourceLinenumber;
       end;
       end;
     end;
     end;
   UsesClause[l]:=UsesUnit;
   UsesClause[l]:=UsesUnit;
@@ -5203,7 +5208,9 @@ end;
 function TPasImplWhileDo.Condition: string;
 function TPasImplWhileDo.Condition: string;
 begin
 begin
   If Assigned(ConditionExpr) then
   If Assigned(ConditionExpr) then
-    Result:=ConditionExpr.GetDeclaration(True);
+    Result:=ConditionExpr.GetDeclaration(True)
+  else
+    Result:='';
 end;
 end;
 
 
 { TPasImplCaseOf }
 { TPasImplCaseOf }

+ 31 - 11
packages/fcl-passrc/src/pparser.pp

@@ -101,6 +101,7 @@ const
   nParserOnlyOneVariableCanBeAbsolute = 2055;
   nParserOnlyOneVariableCanBeAbsolute = 2055;
   nParserXNotAllowedInY = 2056;
   nParserXNotAllowedInY = 2056;
   nFileSystemsNotSupported = 2057;
   nFileSystemsNotSupported = 2057;
+  nInvalidMessageType = 2058;
 
 
 // resourcestring patterns of messages
 // resourcestring patterns of messages
 resourcestring
 resourcestring
@@ -161,6 +162,7 @@ resourcestring
   SParserOnlyOneVariableCanBeAbsolute = 'Only one variable can be absolute';
   SParserOnlyOneVariableCanBeAbsolute = 'Only one variable can be absolute';
   SParserXNotAllowedInY = '%s is not allowed in %s';
   SParserXNotAllowedInY = '%s is not allowed in %s';
   SErrFileSystemNotSupported = 'No support for filesystems enabled';
   SErrFileSystemNotSupported = 'No support for filesystems enabled';
+  SErrInvalidMessageType = 'Invalid message type: string or integer expression expected';
 
 
 type
 type
   TPasScopeType = (
   TPasScopeType = (
@@ -1356,11 +1358,9 @@ begin
     if Parent is TPasClassType then
     if Parent is TPasClassType then
       begin
       begin
       if PM in [pmPublic,pmForward] then exit(false);
       if PM in [pmPublic,pmForward] then exit(false);
-      case TPasClassType(Parent).ObjKind of
-      okInterface,okDispInterface:
-        if not (PM in [pmOverload, pmMessage,
-                       pmDispId,pmNoReturn,pmFar,pmFinal]) then exit(false);
-      end;
+      if TPasClassType(Parent).ObjKind in [okInterface,okDispInterface] then
+        if not (PM in [pmOverload, pmMessage, pmDispId,pmNoReturn,pmFar,pmFinal]) then
+          exit(false);
       exit;
       exit;
       end
       end
     else if Parent is TPasRecordType then
     else if Parent is TPasRecordType then
@@ -2018,6 +2018,7 @@ begin
    tkprocedure : Result:=ParseProcedureType(Parent,NamePos,TypeName,ptProcedure);
    tkprocedure : Result:=ParseProcedureType(Parent,NamePos,TypeName,ptProcedure);
    tkfunction : Result:=ParseProcedureType(Parent,NamePos,TypeName,ptFunction);
    tkfunction : Result:=ParseProcedureType(Parent,NamePos,TypeName,ptFunction);
   else
   else
+    result:=Nil; // Fool compiler
     ParseExcTokenError('procedure or function');
     ParseExcTokenError('procedure or function');
   end;
   end;
   Result.IsReferenceTo:=True;
   Result.IsReferenceTo:=True;
@@ -2101,6 +2102,7 @@ function TPasParser.ExprToText(Expr: TPasExpr): String;
 var
 var
   C: TClass;
   C: TClass;
 begin
 begin
+  Result:='';
   C:=Expr.ClassType;
   C:=Expr.ClassType;
   if C=TPrimitiveExpr then
   if C=TPrimitiveExpr then
     Result:=TPrimitiveExpr(Expr).Value
     Result:=TPrimitiveExpr(Expr).Value
@@ -2286,6 +2288,7 @@ begin
     tkDot                   : Result:=eopSubIdent;
     tkDot                   : Result:=eopSubIdent;
     tkCaret                 : Result:=eopDeref;
     tkCaret                 : Result:=eopDeref;
   else
   else
+    result:=eopAdd; // Fool compiler
     ParseExc(nParserNotAnOperand,SParserNotAnOperand,[AToken,TokenInfos[AToken]]);
     ParseExc(nParserNotAnOperand,SParserNotAnOperand,[AToken,TokenInfos[AToken]]);
   end;
   end;
 end;
 end;
@@ -2961,6 +2964,7 @@ var
   OldMember: TPasElement;
   OldMember: TPasElement;
   OverloadedProc: TPasOverloadedProc;
   OverloadedProc: TPasOverloadedProc;
 begin
 begin
+  OldMember:=nil;
   With Decs do
   With Decs do
     begin
     begin
     if not (po_nooverloadedprocs in Options) then
     if not (po_nooverloadedprocs in Options) then
@@ -3417,6 +3421,7 @@ end;
 function TPasParser.GetProcTypeFromToken(tk: TToken; IsClass: Boolean
 function TPasParser.GetProcTypeFromToken(tk: TToken; IsClass: Boolean
   ): TProcType;
   ): TProcType;
 begin
 begin
+  Result:=ptProcedure;
   Case tk of
   Case tk of
     tkProcedure :
     tkProcedure :
       if IsClass then
       if IsClass then
@@ -4380,6 +4385,8 @@ function TPasParser.ParseGenericTypeDecl(Parent: TPasElement;
     ProcTypeEl: TPasProcedureType;
     ProcTypeEl: TPasProcedureType;
     ProcType: TProcType;
     ProcType: TProcType;
   begin
   begin
+    ProcTypeEl:=Nil;
+    ProcType:=ptProcedure;
     case CurToken of
     case CurToken of
     tkFunction:
     tkFunction:
       begin
       begin
@@ -5103,8 +5110,12 @@ begin
       begin
       begin
       TPasProcedure(Parent).MessageName:=TPrimitiveExpr(E).Value;
       TPasProcedure(Parent).MessageName:=TPrimitiveExpr(E).Value;
       case E.Kind of
       case E.Kind of
-      pekNumber, pekUnary: TPasProcedure(Parent).Messagetype:=pmtInteger;
-      pekString: TPasProcedure(Parent).Messagetype:=pmtString;
+        pekNumber, pekUnary:
+          TPasProcedure(Parent).Messagetype:=pmtInteger;
+        pekString:
+          TPasProcedure(Parent).Messagetype:=pmtString;
+      else
+        ParseExc(nInvalidMessageType,SErrInvalidMessageType);
       end;
       end;
       end;
       end;
     if CurToken<>tkSemicolon then
     if CurToken<>tkSemicolon then
@@ -5117,6 +5128,8 @@ begin
     if CurToken<>tkSemicolon then
     if CurToken<>tkSemicolon then
       UngetToken;
       UngetToken;
     end;
     end;
+  else
+    // Do nothing, satisfy compiler
   end; // Case
   end; // Case
 end;
 end;
 
 
@@ -5245,6 +5258,7 @@ begin
             or (CurModule is TPasProgram))
             or (CurModule is TPasProgram))
           then
           then
         begin
         begin
+        OK:=False;
         if Assigned(CurModule.InterfaceSection) then
         if Assigned(CurModule.InterfaceSection) then
           OK:=FindInSection(Parent.Name,CurModule.InterfaceSection)
           OK:=FindInSection(Parent.Name,CurModule.InterfaceSection)
         else if (CurModule is TPasProgram) and Assigned(TPasProgram(CurModule).ProgramSection) then
         else if (CurModule is TPasProgram) and Assigned(TPasProgram(CurModule).ProgramSection) then
@@ -5279,6 +5293,8 @@ begin
           ParseExc(nParserExpectedColonID,SParserExpectedColonID);
           ParseExc(nParserExpectedColonID,SParserExpectedColonID);
         ResultEl.ResultType := ParseType(ResultEl,CurSourcePos);
         ResultEl.ResultType := ParseType(ResultEl,CurSourcePos);
       end;
       end;
+  else
+    resultEl:=Nil;
   end;
   end;
   if OfObjectPossible then
   if OfObjectPossible then
     begin
     begin
@@ -5502,6 +5518,7 @@ function TPasParser.ParseProperty(Parent: TPasElement; const AName: String;
     else
     else
       begin
       begin
       Result := Result + '[';
       Result := Result + '[';
+      Param:=Nil;
       Params:=TParamsExpr(CreateElement(TParamsExpr,'',aParent));
       Params:=TParamsExpr(CreateElement(TParamsExpr,'',aParent));
       Params.Kind:=pekArrayParams;
       Params.Kind:=pekArrayParams;
       Params.Value:=Expr;
       Params.Value:=Expr;
@@ -5844,9 +5861,8 @@ var
     if (CurBlock.Elements.Count=0) then
     if (CurBlock.Elements.Count=0) then
       exit; // at start of block
       exit; // at start of block
     t:=GetPrevToken;
     t:=GetPrevToken;
-    case t of
-    tkSemicolon,tkColon,tkElse,tkotherwise: exit;
-    end;
+    if t in [tkSemicolon,tkColon,tkElse,tkotherwise] then
+      exit;
     {$IFDEF VerbosePasParser}
     {$IFDEF VerbosePasParser}
     writeln('TPasParser.ParseStatement.CheckSemicolon Prev=',GetPrevToken,' Cur=',CurToken,' ',CurBlock.ClassName,' ',CurBlock.Elements.Count,' ',TObject(CurBlock.Elements[0]).ClassName);
     writeln('TPasParser.ParseStatement.CheckSemicolon Prev=',GetPrevToken,' Cur=',CurToken,' ',CurBlock.ClassName,' ',CurBlock.Elements.Count,' ',TObject(CurBlock.Elements[0]).ClassName);
     {$ENDIF}
     {$ENDIF}
@@ -6393,7 +6409,8 @@ var
 begin
 begin
   Labels:=TPasLabels(CreateElement(TPasLabels, '', AParent));
   Labels:=TPasLabels(CreateElement(TPasLabels, '', AParent));
   repeat
   repeat
-    Labels.Labels.Add(ExpectIdentifier);
+    expectTokens([tkIdentifier,tkNumber]);
+    Labels.Labels.Add(CurTokenString);
     NextToken;
     NextToken;
     if not (CurToken in [tkSemicolon, tkComma]) then
     if not (CurToken in [tkSemicolon, tkComma]) then
       ParseExcTokenError(TokenInfos[tkSemicolon]);
       ParseExcTokenError(TokenInfos[tkSemicolon]);
@@ -6404,6 +6421,7 @@ end;
 function TPasParser.GetProcedureClass(ProcType: TProcType): TPTreeElement;
 function TPasParser.GetProcedureClass(ProcType: TProcType): TPTreeElement;
 
 
 begin
 begin
+  Result:=Nil;
   Case ProcType of
   Case ProcType of
     ptFunction       : Result:=TPasFunction;
     ptFunction       : Result:=TPasFunction;
     ptClassFunction  : Result:=TPasClassFunction;
     ptClassFunction  : Result:=TPasClassFunction;
@@ -6621,6 +6639,7 @@ begin
             Case OperatorType of
             Case OperatorType of
               otPositive : OperatorType:=otPlus;
               otPositive : OperatorType:=otPlus;
               otNegative : OperatorType:=otMinus;
               otNegative : OperatorType:=otMinus;
+            else
             end;
             end;
             Name:=OperatorNames[OperatorType];
             Name:=OperatorNames[OperatorType];
             TPasOperator(Result).CorrectName;
             TPasOperator(Result).CorrectName;
@@ -7033,6 +7052,7 @@ Var
   T : TPasType;
   T : TPasType;
   Done : Boolean;
   Done : Boolean;
 begin
 begin
+  Done:=False;
   //Writeln('Parsing local types');
   //Writeln('Parsing local types');
   while (CurToken=tkSquaredBraceOpen)
   while (CurToken=tkSquaredBraceOpen)
       and (msPrefixedAttributes in CurrentModeswitches) do
       and (msPrefixedAttributes in CurrentModeswitches) do

+ 19 - 1
packages/fcl-passrc/src/pscanner.pp

@@ -1955,6 +1955,8 @@ begin
             dec(Lvl);
             dec(Lvl);
             if Lvl=0 then break;
             if Lvl=0 then break;
             end;
             end;
+          else
+            // Do nothing, satisfy compiler
           end;
           end;
           NextToken;
           NextToken;
         until false;
         until false;
@@ -2103,6 +2105,8 @@ begin
               tkshr: R:=IntToStr(AInt shr BInt);
               tkshr: R:=IntToStr(AInt shr BInt);
               tkPlus: R:=IntToStr(AInt+BInt);
               tkPlus: R:=IntToStr(AInt+BInt);
               tkMinus: R:=IntToStr(AInt-BInt);
               tkMinus: R:=IntToStr(AInt-BInt);
+            else
+              // Do nothing, satisfy compiler
             end
             end
           else if IsExtended(B,BFloat) then
           else if IsExtended(B,BFloat) then
             case Op of
             case Op of
@@ -2153,6 +2157,8 @@ begin
           tkGreaterThan: R:=CondDirectiveBool[AInt>BInt];
           tkGreaterThan: R:=CondDirectiveBool[AInt>BInt];
           tkLessEqualThan: R:=CondDirectiveBool[AInt<=BInt];
           tkLessEqualThan: R:=CondDirectiveBool[AInt<=BInt];
           tkGreaterEqualThan: R:=CondDirectiveBool[AInt>=BInt];
           tkGreaterEqualThan: R:=CondDirectiveBool[AInt>=BInt];
+          else
+          // Do nothing, satisfy compiler
           end
           end
         else if IsExtended(A,AFloat) and IsExtended(B,BFloat) then
         else if IsExtended(A,AFloat) and IsExtended(B,BFloat) then
           case Op of
           case Op of
@@ -2162,6 +2168,8 @@ begin
           tkGreaterThan: R:=CondDirectiveBool[AFloat>BFloat];
           tkGreaterThan: R:=CondDirectiveBool[AFloat>BFloat];
           tkLessEqualThan: R:=CondDirectiveBool[AFloat<=BFloat];
           tkLessEqualThan: R:=CondDirectiveBool[AFloat<=BFloat];
           tkGreaterEqualThan: R:=CondDirectiveBool[AFloat>=BFloat];
           tkGreaterEqualThan: R:=CondDirectiveBool[AFloat>=BFloat];
+          else
+          // Do nothing, satisfy compiler
           end
           end
         else
         else
           case Op of
           case Op of
@@ -2171,6 +2179,8 @@ begin
           tkGreaterThan: R:=CondDirectiveBool[A>B];
           tkGreaterThan: R:=CondDirectiveBool[A>B];
           tkLessEqualThan: R:=CondDirectiveBool[A<=B];
           tkLessEqualThan: R:=CondDirectiveBool[A<=B];
           tkGreaterEqualThan: R:=CondDirectiveBool[A>=B];
           tkGreaterEqualThan: R:=CondDirectiveBool[A>=B];
+          else
+          // Do nothing, satisfy compiler
           end;
           end;
         end;
         end;
       else
       else
@@ -3093,6 +3103,7 @@ var
   end;
   end;
 
 
 begin
 begin
+  Result:=tkEOF;
   FCurTokenString := '';
   FCurTokenString := '';
   StartPos:=FTokenPos;
   StartPos:=FTokenPos;
   {$ifndef UsePChar}
   {$ifndef UsePChar}
@@ -3709,6 +3720,7 @@ Var
   Enable: Boolean;
   Enable: Boolean;
 
 
 begin
 begin
+  Enable:=False;
   PM:=Param;
   PM:=Param;
   p:=1;
   p:=1;
   while (p<=length(PM)) and (PM[p] in ['a'..'z','A'..'Z','_','0'..'9']) do
   while (p<=length(PM)) and (PM[p] in ['a'..'z','A'..'Z','_','0'..'9']) do
@@ -4112,7 +4124,10 @@ begin
   else if CompareText(Param,'off')=0 then
   else if CompareText(Param,'off')=0 then
     NewValue:=false
     NewValue:=false
   else
   else
+    begin
+    NewValue:=True;// Fool compiler
     Error(nErrXExpectedButYFound,SErrXExpectedButYFound,['on',Param]);
     Error(nErrXExpectedButYFound,SErrXExpectedButYFound,['on',Param]);
+    end;
   if (bs in CurrentBoolSwitches)=NewValue then exit;
   if (bs in CurrentBoolSwitches)=NewValue then exit;
   if bs in ReadOnlyBoolSwitches then
   if bs in ReadOnlyBoolSwitches then
     DoLog(mtWarning,nWarnIllegalCompilerDirectiveX,sWarnIllegalCompilerDirectiveX,
     DoLog(mtWarning,nWarnIllegalCompilerDirectiveX,sWarnIllegalCompilerDirectiveX,
@@ -4170,6 +4185,7 @@ var
   end;
   end;
 
 
 begin
 begin
+  TokenStart:={$ifdef UsePChar}nil{$else}0{$endif};
   Result:=tkLineEnding;
   Result:=tkLineEnding;
   if FTokenPos {$ifdef UsePChar}= nil{$else}<1{$endif} then
   if FTokenPos {$ifdef UsePChar}= nil{$else}<1{$endif} then
     if not FetchLine then
     if not FetchLine then
@@ -5266,12 +5282,14 @@ end;
 
 
 function TPascalScanner.IgnoreMsgType(MsgType: TMessageType): boolean;
 function TPascalScanner.IgnoreMsgType(MsgType: TMessageType): boolean;
 begin
 begin
+  Result:=false;
   case MsgType of
   case MsgType of
     mtWarning: if not (bsWarnings in FCurrentBoolSwitches) then exit(true);
     mtWarning: if not (bsWarnings in FCurrentBoolSwitches) then exit(true);
     mtNote: if not (bsNotes in FCurrentBoolSwitches) then exit(true);
     mtNote: if not (bsNotes in FCurrentBoolSwitches) then exit(true);
     mtHint: if not (bsHints in FCurrentBoolSwitches) then exit(true);
     mtHint: if not (bsHints in FCurrentBoolSwitches) then exit(true);
+  else
+    // Do nothing, satisfy compiler
   end;
   end;
-  Result:=false;
 end;
 end;
 
 
 end.
 end.