CodeTools: Initialize variables based on compiler warnings. Contains ToDo items.

git-svn-id: trunk@48480 -
This commit is contained in:
juha 2015-03-24 17:51:40 +00:00
parent 653207f24f
commit 232c983159
17 changed files with 61 additions and 35 deletions

View File

@ -1865,6 +1865,7 @@ var
CloseBracket: Char;
StartPos: LongInt;
begin
Result:=false;
case Src[AtomStart] of
'{': CloseBracket:='}';
'[': CloseBracket:=']';
@ -1873,7 +1874,7 @@ begin
else
if ExceptionOnNotFound then
RaiseExpectedButAtomFound('(');
exit(false);
exit;
end;
StartPos:=AtomStart;
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
@ -2227,7 +2228,7 @@ begin
MoveCursorToNode(FuncNode);
repeat
ReadNextAtom;
if AtomStart>SrcLen then exit;
if AtomStart>SrcLen then exit(false);
if AtomIs('(') then exit(true);
if (IsIdentStartChar[Src[AtomStart]])
or (AtomIs('*')) then begin

View File

@ -478,7 +478,7 @@ function TCodeCompletionCodeTool.OnTopLvlIdentifierFound(
var
TrimmedIdentifier: string;
begin
if not (fdfTopLvlResolving in Params.Flags) then exit;
if not (fdfTopLvlResolving in Params.Flags) then exit(ifrProceedSearch);
with Params do begin
case NewNode.Desc of
ctnTypeDefinition,ctnVarDefinition,ctnConstDefinition,ctnGenericType:
@ -1041,6 +1041,7 @@ begin
// find the level and find sections in front
Node:=Tree.Root;
CursorNode:=nil;
VarSectionNode:=nil;
OtherSectionNode:=nil;
HeaderNode:=nil;
@ -3623,7 +3624,7 @@ begin
case ReferingType of
ctnTypeDefinition: NewSection:='type';
ctnConstDefinition: NewSection:='const';
ctnProcedure: NewSrc:='';
ctnProcedure: NewSection:=''; // Changed from NewSrc to NewSection. Is it correct? Juha
else NewSection:='bug';
end;
@ -6929,6 +6930,8 @@ var
AccessParam:=copy(Src,Parts[ppRead].StartPos,
Parts[ppRead].EndPos-Parts[ppRead].StartPos)
else begin
AccessParam:=''; // This was missing
// ToDo: Fix this test. AccessParam is now empty.
if (Parts[ppParamList].StartPos>0) or (Parts[ppIndexWord].StartPos>0)
or (SysUtils.CompareText(AccessParamPrefix,
LeftStr(AccessParam,length(AccessParamPrefix)))=0)
@ -6951,8 +6954,7 @@ var
if Parts[ppReadWord].StartPos>0 then begin
// 'read' keyword exists -> insert read identifier behind
InsertPos:=Parts[ppReadWord].EndPos;
FSourceChangeCache.Replace(gtSpace,gtNone,InsertPos,InsertPos,
AccessParam);
FSourceChangeCache.Replace(gtSpace,gtNone,InsertPos,InsertPos,AccessParam);
end else begin
// 'read' keyword does not exist -> insert behind index and type
if Parts[ppIndex].StartPos>0 then
@ -8600,10 +8602,10 @@ var
// Try to insert new proc behind existing methods
// find last method (go to last brother and search backwards)
if (StartSearchProc<>nil)
and (StartSearchProc.Parent<>nil) then begin
NearestProcNode:=StartSearchProc.Parent.LastChild;
end;
if (StartSearchProc<>nil) and (StartSearchProc.Parent<>nil) then
NearestProcNode:=StartSearchProc.Parent.LastChild
else
NearestProcNode:=nil;
while (NearestProcNode<>nil) and (not NodeIsMethodBody(NearestProcNode)) do
NearestProcNode:=NearestProcNode.PriorBrother;
if NearestProcNode<>nil then begin

View File

@ -3922,17 +3922,14 @@ var
InFilename:='';
aFilename:=CodeToolBoss.DirectoryCachePool.FindUnitSourceInCompletePath(
'',TheUnitName,InFilename,true);
if aFilename<>'' then
exit(true);
// user search
if Assigned(OnFindSource) then begin
OnFindSource(Self,ctnUnit,TheUnitName,aFilename);
Result:=aFilename<>'';
end else if Assigned(OnFindFPCMangledSource) then begin
OnFindFPCMangledSource(Self,ctnUnit,TheUnitName,aFilename);
Result:=aFilename<>'';
if aFilename='' then begin
// user search
if Assigned(OnFindSource) then
OnFindSource(Self,ctnUnit,TheUnitName,aFilename)
else if Assigned(OnFindFPCMangledSource) then
OnFindFPCMangledSource(Self,ctnUnit,TheUnitName,aFilename)
end;
Result:=aFilename<>'';
end;
function FindProgram(TheSrcName: string; out aFilename: string): boolean;
@ -5667,7 +5664,9 @@ begin
if CompareFileExt(AFilename,'.ppu',false)=0 then
Result:=GetPPUSrcPathForDirectory(ExtractFilePath(AFilename))
else if CompareFileExt(AFilename,'.dcu',false)=0 then
Result:=GetDCUSrcPathForDirectory(ExtractFilePath(AFilename));
Result:=GetDCUSrcPathForDirectory(ExtractFilePath(AFilename))
else
Result:='';
if Result='' then
Result:=GetCompiledSrcPathForDirectory(ExtractFilePath(AFilename));
end;

View File

@ -1248,7 +1248,7 @@ procedure TCTCfgScriptVariables.Define(Name: PChar; const Value: string);
var
p: PChar;
begin
if Value='' then exit;
if Value='' then exit(false);
p:=PChar(Value);
if p^='-' then inc(p);
while (p^ in ['0'..'9']) do inc(p);
@ -2420,6 +2420,7 @@ begin
inc(Column);
end;
end;
Result:=true;
end;
function TCTConfigScriptEngine.PosToStr(p: PChar): string;

View File

@ -2162,6 +2162,7 @@ var
LastPos: Integer;
begin
ErrorPosition:=CursorPos;
Msg:='';
// check position in code buffer
if CursorPos.Code=nil then
Msg:='cursor position without code buffer'

View File

@ -2579,6 +2579,7 @@ begin
end;
end;
cdnEnd: exit(false);
else exit(false);
end;
end;

View File

@ -913,6 +913,7 @@ var
i: Integer;
begin
Result:='';
i:=0;
if ShortFilename='' then exit;
if Directory<>'' then begin
case FileCase of
@ -1128,9 +1129,10 @@ begin
if IsAbsolute then begin
CurPath:=AppendPathDelim(CurPath);
Result:=Pool.FindUnitInDirectory(CurPath,AUnitName,AnyCase);
end else if (CurPath='.') and (Directory='') then begin
Result:=Pool.FindVirtualUnit(AUnitname);
end;
end else if (CurPath='.') and (Directory='') then
Result:=Pool.FindVirtualUnit(AUnitname)
else
Result:='';
if Result<>'' then exit;
end;
StartPos:=p+1;

View File

@ -1376,6 +1376,7 @@ var
StartPos: Integer;
begin
// enclose all $ELSE code in WITH blocks
Result:=false;
WithHeader:='';
WithFooter:='';
p:=Max(StatementNode.StartPos,BeginKeyWord.EndPos);

View File

@ -1403,8 +1403,9 @@ var
p: Integer;
StartPos: integer;
begin
Result:='';
if BeginsWith='' then
exit('');
exit;
p:=1;
while ReadNextFPCParameter(CmdLine,p,StartPos) do begin
Param:=ExtractFPCParameter(CmdLine,StartPos);
@ -1445,6 +1446,7 @@ var
ShortFile: String;
FileInfo: TSearchRec;
begin
Result:='';
Base:=AppendPathDelim(BaseDirectory);
ShortFile:=Filename;
if System.Pos(PathDelim,ShortFile)>0 then begin
@ -1472,7 +1474,6 @@ begin
ctsfcAllCase:
begin
// search file
Result:='';
Base:=FindDiskFilename(Base);
if FindFirstUTF8(Base+FileMask,faAnyFile,FileInfo)=0 then
begin

View File

@ -3669,11 +3669,10 @@ begin
if (ExprType.Desc=xtContext) then
Result:=ExprType.Context
else begin
Result:=CleanFindContext;
if fdfExceptionOnNotFound in Params.Flags then begin
MoveCursorToCleanPos(EndPos);
RaiseException(ctsNoContextNodeFoundAtCursor);
end else begin
Result:=CleanFindContext;
end;
end;
end;
@ -6049,7 +6048,9 @@ begin
OldExtractedOperand:=Params.ExtractedOperand;
WithVarExpr:=FindExpressionTypeOfTerm(WithVarNode.StartPos,-1,Params,true);
if fdfExtractOperand in Params.Flags then
NewExtractedOperand:=Params.ExtractedOperand+'.';
NewExtractedOperand:=Params.ExtractedOperand+'.'
else
NewExtractedOperand:='';
if (WithVarExpr.Desc<>xtContext)
or (WithVarExpr.Context.Node=nil)
or (WithVarExpr.Context.Node=OldInput.ContextNode)

View File

@ -2790,7 +2790,8 @@ function TH2PasTool.CreatePascalNameFromCCode(const CCode: string;
function Add(var PascalName: string; const Addition: string): boolean;
begin
if Addition='' then exit(true);
Result:=true;
if Addition='' then exit;
if length(PascalName)+length(Addition)>DefaultMaxPascalIdentLen then
exit(false);
PascalName:=PascalName+Addition;

View File

@ -3554,6 +3554,7 @@ var
IncFilename: string;
DynamicExtension: Boolean;
begin
Result:=false;
if StoreDirectives then
FDirectives[FDirectivesCount-1].Kind:=lsdkInclude;
inc(SrcPos);

View File

@ -1128,6 +1128,7 @@ function TPascalParserTool.KeyWordFuncClassClass: boolean;
class var
}
begin
Result:=false;
ReadNextAtom;
if UpAtomIs('PROCEDURE') or UpAtomIs('FUNCTION') or UpAtomIs('CONSTRUCTOR')
or UpAtomIs('DESTRUCTOR') or UpAtomIs('OPERATOR') then begin
@ -2045,6 +2046,7 @@ function TPascalParserTool.ReadRequiresSection(ExceptionOnError: boolean): boole
requires name1, name2, name3;
}
begin
Result:=false;
CreateChildNode;
CurNode.Desc:=ctnRequiresSection;
repeat

View File

@ -1749,6 +1749,7 @@ begin
if StartPos>SrcLen then exit;
if EndPos>SrcLen then EndPos:=SrcLen+1;
if StartPos>=EndPos then exit;
Range:=epriInCode;
p:=@Src[StartPos];
EndP:=p+EndPos-StartPos;
while p<EndP do begin

View File

@ -1898,6 +1898,9 @@ begin
2-3 - amount of bytes for line
4-5 - amount of bytes for column
}
fileindex:=0;
line:=0;
column:=0;
info:=ReadEntryByte;
case (info and $03) of
0 : fileindex:=ReadEntryByte;

View File

@ -762,6 +762,7 @@ function TSourceChangeCache.IndentBlock(FromPos, ToPos, IndentDiff: integer): bo
var
p: LongInt;
begin
Result:=false;
if ToPos<1 then ToPos:=1;
if (IndentDiff=0) or (FromPos>=ToPos) then exit;
if MainScanner=nil then begin
@ -1817,6 +1818,7 @@ var
KeyWordPos: LongInt;
Level: Integer;
begin
Result:='';
p:=1;
ProcLen:=length(AProcCode);
// read proc keyword 'procedure', 'function', ...

View File

@ -1916,10 +1916,13 @@ begin
InitializationNode:=FindInitializationNode;
if InitializationNode=nil then exit;
LinkIndex:=Scanner.LinkIndexAtCleanPos(InitializationNode.StartPos);
end else
end else begin
InitializationNode:=nil;
inc(LinkIndex);
end;
if (LinkIndex<0) or (LinkIndex>=Scanner.LinkCount) then exit;
StartCode:=TCodeBuffer(Scanner.Links[LinkIndex].Code);
// ToDo: Fix the test for InitializationNode, it can be Nil.
while (LinkIndex<Scanner.LinkCount)
and (Scanner.Links[LinkIndex].CleanedPos<InitializationNode.EndPos) do begin
Result:=TCodeBuffer(Scanner.Links[LinkIndex].Code);
@ -2078,6 +2081,7 @@ begin
IncludeEnd:=Scanner.Links[LinkIndex].CleanedPos;
IncludeStart:=IncludeEnd-1;
if IncludeStart<1 then exit;
FileEnd:=0;
case Src[IncludeStart] of
'}':
begin
@ -2475,13 +2479,14 @@ var
VariableTypeName:='';
if (ChildContext.Node.Desc=ctnVarDefinition) then begin
DefinitionNode:=ChildContext.Tool.FindTypeNodeOfDefinition(ChildContext.Node);
if DefinitionNode<>nil then begin
if DefinitionNode<>nil then
VariableTypeName:=ChildContext.Tool.ExtractDefinitionNodeType(ChildContext.Node);
end;
end else if (ChildContext.Node.Desc=ctnProperty) then begin
DefinitionNode:=ChildContext.Node;
VariableTypeName:=ChildContext.Tool.ExtractPropType(ChildContext.Node,false,false);
end;
end
else
DefinitionNode:=nil;
if DefinitionNode=nil then begin
LFMTree.AddError(lfmeObjectIncompatible,LFMObject,
LFMObjectName+' is not a variable'
@ -5469,6 +5474,7 @@ var
var
p: LongInt;
begin
Result:=false;
if NewCode='' then exit(true);
// try to avoid changing current line
if (FrontGap=gtEmptyLine) then begin