mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 20:19:29 +02:00
codetools: improved parsing variable section with errors
git-svn-id: trunk@9894 -
This commit is contained in:
parent
112b816466
commit
53dde5cff5
@ -733,6 +733,7 @@ var
|
|||||||
FPCDefines: TDefineTemplate;
|
FPCDefines: TDefineTemplate;
|
||||||
FPCSrcDefines: TDefineTemplate;
|
FPCSrcDefines: TDefineTemplate;
|
||||||
LazarusSrcDefines: TDefineTemplate;
|
LazarusSrcDefines: TDefineTemplate;
|
||||||
|
ATestPascalFile: String;
|
||||||
begin
|
begin
|
||||||
// set global values
|
// set global values
|
||||||
with GlobalValues do begin
|
with GlobalValues do begin
|
||||||
@ -747,8 +748,11 @@ begin
|
|||||||
FPCUnitPath:=Config.FPCUnitPath;
|
FPCUnitPath:=Config.FPCUnitPath;
|
||||||
TargetOS:=Config.TargetOS;
|
TargetOS:=Config.TargetOS;
|
||||||
TargetProcessor:=Config.TargetProcessor;
|
TargetProcessor:=Config.TargetProcessor;
|
||||||
|
ATestPascalFile:=Config.TestPascalFile;
|
||||||
|
if ATestPascalFile='' then
|
||||||
|
ATestPascalFile:=GetTempFilename('fpctest.pas','');
|
||||||
FPCDefines:=CreateFPCTemplate(Config.FPCPath, Config.FPCOptions,
|
FPCDefines:=CreateFPCTemplate(Config.FPCPath, Config.FPCOptions,
|
||||||
Config.TestPascalFile,
|
ATestPascalFile,
|
||||||
FPCUnitPath, TargetOS, TargetProcessor,
|
FPCUnitPath, TargetOS, TargetProcessor,
|
||||||
nil);
|
nil);
|
||||||
Add(FPCDefines);
|
Add(FPCDefines);
|
||||||
|
@ -189,6 +189,9 @@ const
|
|||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
{ TCodeTreeNode }
|
||||||
|
|
||||||
TCodeTreeNode = class
|
TCodeTreeNode = class
|
||||||
public
|
public
|
||||||
Desc: TCodeTreeNodeDesc;
|
Desc: TCodeTreeNodeDesc;
|
||||||
@ -210,6 +213,7 @@ type
|
|||||||
procedure Clear;
|
procedure Clear;
|
||||||
constructor Create;
|
constructor Create;
|
||||||
function ConsistencyCheck: integer; // 0 = ok
|
function ConsistencyCheck: integer; // 0 = ok
|
||||||
|
procedure WriteDebugReport(const Prefix: string; WithChilds: boolean);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCodeTree }
|
{ TCodeTree }
|
||||||
@ -228,7 +232,7 @@ type
|
|||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function ConsistencyCheck: integer; // 0 = ok
|
function ConsistencyCheck: integer; // 0 = ok
|
||||||
procedure WriteDebugReport;
|
procedure WriteDebugReport(WithChilds: boolean);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TCodeTreeNodeExtension = class
|
TCodeTreeNodeExtension = class
|
||||||
@ -520,6 +524,21 @@ begin
|
|||||||
Result:=0;
|
Result:=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCodeTreeNode.WriteDebugReport(const Prefix: string;
|
||||||
|
WithChilds: boolean);
|
||||||
|
var
|
||||||
|
Node: TCodeTreeNode;
|
||||||
|
begin
|
||||||
|
DebugLn([Prefix,DescAsString,' Range=',StartPos,'..',EndPos,' Cache=',DbgSName(Cache)]);
|
||||||
|
if WithChilds then begin
|
||||||
|
Node:=FirstChild;
|
||||||
|
while Node<>nil do begin
|
||||||
|
Node.WriteDebugReport(Prefix+' ',true);
|
||||||
|
Node:=Node.NextBrother;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCodeTreeNode.HasAsParent(Node: TCodeTreeNode): boolean;
|
function TCodeTreeNode.HasAsParent(Node: TCodeTreeNode): boolean;
|
||||||
var CurNode: TCodeTreeNode;
|
var CurNode: TCodeTreeNode;
|
||||||
begin
|
begin
|
||||||
@ -719,10 +738,12 @@ begin
|
|||||||
Result:=0;
|
Result:=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCodeTree.WriteDebugReport;
|
procedure TCodeTree.WriteDebugReport(WithChilds: boolean);
|
||||||
begin
|
begin
|
||||||
DebugLn('[TCodeTree.WriteDebugReport] Consistency=',dbgs(ConsistencyCheck),
|
DebugLn('[TCodeTree.WriteDebugReport] Consistency=',dbgs(ConsistencyCheck),
|
||||||
' Root=',dbgs(Root<>nil));
|
' Root=',dbgs(Root<>nil));
|
||||||
|
if Root<>nil then
|
||||||
|
Root.WriteDebugReport(' ',true);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCodeTreeNodeExtension }
|
{ TCodeTreeNodeExtension }
|
||||||
|
@ -37,6 +37,7 @@ interface
|
|||||||
|
|
||||||
{ $DEFINE ShowIgnoreError}
|
{ $DEFINE ShowIgnoreError}
|
||||||
{$DEFINE ShowDirtySrc}
|
{$DEFINE ShowDirtySrc}
|
||||||
|
{ $DEFINE VerboseUpdateNeeded}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
{$IFDEF MEM_CHECK}
|
{$IFDEF MEM_CHECK}
|
||||||
@ -176,7 +177,7 @@ type
|
|||||||
function MainFilename: string;
|
function MainFilename: string;
|
||||||
|
|
||||||
function FindDeepestNodeAtPos(P: integer;
|
function FindDeepestNodeAtPos(P: integer;
|
||||||
ExceptionOnNotFound: boolean): TCodeTreeNode;
|
ExceptionOnNotFound: boolean): TCodeTreeNode; inline;
|
||||||
function FindDeepestNodeAtPos(StartNode: TCodeTreeNode; P: integer;
|
function FindDeepestNodeAtPos(StartNode: TCodeTreeNode; P: integer;
|
||||||
ExceptionOnNotFound: boolean): TCodeTreeNode;
|
ExceptionOnNotFound: boolean): TCodeTreeNode;
|
||||||
function CaretToCleanPos(Caret: TCodeXYPosition;
|
function CaretToCleanPos(Caret: TCodeXYPosition;
|
||||||
@ -458,6 +459,9 @@ begin
|
|||||||
FLastScannerChangeStep:=Scanner.ChangeStep;
|
FLastScannerChangeStep:=Scanner.ChangeStep;
|
||||||
Scanner.SetIgnoreErrorAfter(IgnoreErrorAfter.P,IgnoreErrorAfter.Code);
|
Scanner.SetIgnoreErrorAfter(IgnoreErrorAfter.P,IgnoreErrorAfter.Code);
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF VerboseUpdateNeeded}
|
||||||
|
DebugLn(['TCustomCodeTool.SetScanner FForceUpdateNeeded:=true ',MainFilename]);
|
||||||
|
{$ENDIF}
|
||||||
FForceUpdateNeeded:=true;
|
FForceUpdateNeeded:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1612,6 +1616,9 @@ begin
|
|||||||
Src:=Scanner.CleanedSrc;
|
Src:=Scanner.CleanedSrc;
|
||||||
UpperSrc:=UpperCaseStr(Src);
|
UpperSrc:=UpperCaseStr(Src);
|
||||||
SrcLen:=length(Src);
|
SrcLen:=length(Src);
|
||||||
|
{$IFDEF VerboseUpdateNeeded}
|
||||||
|
DebugLn(['TCustomCodeTool.BeginParsing FForceUpdateNeeded:=true ',MainFilename]);
|
||||||
|
{$ENDIF}
|
||||||
FForceUpdateNeeded:=true;
|
FForceUpdateNeeded:=true;
|
||||||
DirtySrc.Free;
|
DirtySrc.Free;
|
||||||
DirtySrc:=nil;
|
DirtySrc:=nil;
|
||||||
@ -2007,7 +2014,8 @@ var
|
|||||||
ChildNode: TCodeTreeNode;
|
ChildNode: TCodeTreeNode;
|
||||||
Brother: TCodeTreeNode;
|
Brother: TCodeTreeNode;
|
||||||
begin
|
begin
|
||||||
if StartNode<>nil then begin
|
Result:=nil;
|
||||||
|
while StartNode<>nil do begin
|
||||||
//DebugLn('SearchInNode ',NodeDescriptionAsString(ANode.Desc),
|
//DebugLn('SearchInNode ',NodeDescriptionAsString(ANode.Desc),
|
||||||
//',',ANode.StartPos,',',ANode.EndPos,', p=',p,
|
//',',ANode.StartPos,',',ANode.EndPos,', p=',p,
|
||||||
//' "',copy(Src,ANode.StartPos,4),'" - "',copy(Src,ANode.EndPos-5,4),'"');
|
//' "',copy(Src,ANode.StartPos,4),'" - "',copy(Src,ANode.EndPos-5,4),'"');
|
||||||
@ -2029,11 +2037,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
Brother:=Brother.NextBrother;
|
Brother:=Brother.NextBrother;
|
||||||
end;
|
end;
|
||||||
end else
|
break;
|
||||||
|
end else begin
|
||||||
// search in next node
|
// search in next node
|
||||||
Result:=FindDeepestNodeAtPos(StartNode.NextBrother,P,false);
|
StartNode:=StartNode.NextBrother;
|
||||||
end else
|
end;
|
||||||
Result:=nil;
|
end;
|
||||||
if (Result=nil) and ExceptionOnNotFound then begin
|
if (Result=nil) and ExceptionOnNotFound then begin
|
||||||
MoveCursorToCleanPos(P);
|
MoveCursorToCleanPos(P);
|
||||||
RaiseNoNodeFoundAtCursor;
|
RaiseNoNodeFoundAtCursor;
|
||||||
@ -2266,6 +2275,9 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
if (FLastScannerChangeStep<>Scanner.ChangeStep) then begin
|
if (FLastScannerChangeStep<>Scanner.ChangeStep) then begin
|
||||||
|
{$IFDEF VerboseUpdateNeeded}
|
||||||
|
DebugLn(['TCustomCodeTool.UpdateNeeded because FLastScannerChangeStep<>Scanner.ChangeStep ',MainFilename]);
|
||||||
|
{$ENDIF}
|
||||||
Result:=true;
|
Result:=true;
|
||||||
end else begin
|
end else begin
|
||||||
if OnlyInterfaceNeeded then
|
if OnlyInterfaceNeeded then
|
||||||
@ -2273,6 +2285,10 @@ begin
|
|||||||
else
|
else
|
||||||
LinkScanRange:=lsrEnd;
|
LinkScanRange:=lsrEnd;
|
||||||
Result:=Scanner.UpdateNeeded(LinkScanRange, CheckFilesOnDisk);
|
Result:=Scanner.UpdateNeeded(LinkScanRange, CheckFilesOnDisk);
|
||||||
|
{$IFDEF VerboseUpdateNeeded}
|
||||||
|
if Result then
|
||||||
|
DebugLn(['TCustomCodeTool.UpdateNeeded because Scanner.UpdateNeeded ',MainFilename]);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
FForceUpdateNeeded:=Result;
|
FForceUpdateNeeded:=Result;
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
|
@ -2741,8 +2741,11 @@ var CmdLine: string;
|
|||||||
SrcOS2: String;
|
SrcOS2: String;
|
||||||
Step: String;
|
Step: String;
|
||||||
begin
|
begin
|
||||||
//DebugLn('TDefinePool.CreateFPCTemplate PPC386Path="',CompilerPath,'" PPCOptions="',CompilerOptions,'"');
|
|
||||||
Result:=nil;
|
Result:=nil;
|
||||||
|
//DebugLn('TDefinePool.CreateFPCTemplate PPC386Path="',CompilerPath,'" PPCOptions="',CompilerOptions,'"');
|
||||||
|
if TestPascalFile='' then begin
|
||||||
|
DebugLn(['WARNING: TDefinePool.CreateFPCTemplate TestPascalFile empty']);
|
||||||
|
end;
|
||||||
UnitSearchPath:='';
|
UnitSearchPath:='';
|
||||||
TargetOS:='';
|
TargetOS:='';
|
||||||
SrcOS:='';
|
SrcOS:='';
|
||||||
@ -3341,8 +3344,14 @@ begin
|
|||||||
{$IFDEF VerboseFPCSrcScan}
|
{$IFDEF VerboseFPCSrcScan}
|
||||||
DebugLn('CreateFPCSrcTemplate ',FPCSrcDir,': length(UnitSearchPath)=',DbgS(length(UnitSearchPath)),' Valid=',DbgS(UnitLinkListValid),' PPUExt=',PPUExt);
|
DebugLn('CreateFPCSrcTemplate ',FPCSrcDir,': length(UnitSearchPath)=',DbgS(length(UnitSearchPath)),' Valid=',DbgS(UnitLinkListValid),' PPUExt=',PPUExt);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
if UnitSearchPath='' then begin
|
||||||
|
DebugLn(['Note: TDefinePool.CreateFPCSrcTemplate UnitSearchPath empty']);
|
||||||
|
end;
|
||||||
Result:=nil;
|
Result:=nil;
|
||||||
if (FPCSrcDir='') or (not DirPathExists(FPCSrcDir)) then exit;
|
if (FPCSrcDir='') or (not DirPathExists(FPCSrcDir)) then begin
|
||||||
|
DebugLn(['TDefinePool.CreateFPCSrcTemplate FPCSrcDir does not exist: FPCSrcDir="',FPCSrcDir,'"']);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
DS:=PathDelim;
|
DS:=PathDelim;
|
||||||
Dir:=AppendPathDelim(FPCSrcDir);
|
Dir:=AppendPathDelim(FPCSrcDir);
|
||||||
TargetOS:='$('+ExternalMacroStart+'TargetOS)';
|
TargetOS:='$('+ExternalMacroStart+'TargetOS)';
|
||||||
|
@ -743,6 +743,7 @@ begin
|
|||||||
Result:=ifrProceedSearch;
|
Result:=ifrProceedSearch;
|
||||||
|
|
||||||
{$IFDEF ShowFoundIdents}
|
{$IFDEF ShowFoundIdents}
|
||||||
|
if FoundContext.Tool=Self then
|
||||||
DebugLn('::: COLLECT IDENT ',FoundContext.Node.DescAsString,
|
DebugLn('::: COLLECT IDENT ',FoundContext.Node.DescAsString,
|
||||||
' "',StringToPascalConst(copy(FoundContext.Tool.Src,FoundContext.Node.StartPos,50)),'"'
|
' "',StringToPascalConst(copy(FoundContext.Tool.Src,FoundContext.Node.StartPos,50)),'"'
|
||||||
,' '+dbgs(fdfIgnoreUsedUnits in Params.Flags));
|
,' '+dbgs(fdfIgnoreUsedUnits in Params.Flags));
|
||||||
@ -1255,7 +1256,7 @@ begin
|
|||||||
InitCollectIdentifiers(CursorPos,IdentifierList);
|
InitCollectIdentifiers(CursorPos,IdentifierList);
|
||||||
ParseSourceTillCollectionStart(CursorPos,CleanCursorPos,CursorNode,
|
ParseSourceTillCollectionStart(CursorPos,CleanCursorPos,CursorNode,
|
||||||
IdentStartPos,IdentEndPos);
|
IdentStartPos,IdentEndPos);
|
||||||
|
|
||||||
// find context
|
// find context
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
DebugLn('TIdentCompletionTool.GatherIdentifiers B',
|
DebugLn('TIdentCompletionTool.GatherIdentifiers B',
|
||||||
@ -1289,7 +1290,6 @@ begin
|
|||||||
Params.Flags:=[fdfSearchInAncestors,fdfCollect,fdfFindVariable];
|
Params.Flags:=[fdfSearchInAncestors,fdfCollect,fdfFindVariable];
|
||||||
if not StartInSubContext then
|
if not StartInSubContext then
|
||||||
Include(Params.Flags,fdfSearchInParentNodes);
|
Include(Params.Flags,fdfSearchInParentNodes);
|
||||||
|
|
||||||
if Params.ContextNode.Desc in [ctnClass,ctnClassInterface] then
|
if Params.ContextNode.Desc in [ctnClass,ctnClassInterface] then
|
||||||
Exclude(Params.Flags,fdfSearchInParentNodes);
|
Exclude(Params.Flags,fdfSearchInParentNodes);
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
|
@ -544,6 +544,7 @@ begin
|
|||||||
if (not IgnoreErrorAfterValid)
|
if (not IgnoreErrorAfterValid)
|
||||||
or (not IgnoreErrorAfterPositionIsInFrontOfLastErrMessage) then
|
or (not IgnoreErrorAfterPositionIsInFrontOfLastErrMessage) then
|
||||||
raise;
|
raise;
|
||||||
|
FForceUpdateNeeded:=false;
|
||||||
{$IFDEF ShowIgnoreErrorAfter}
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
DebugLn('TPascalParserTool.BuildTree ',MainFilename,' IGNORING ERROR: ',LastErrorMessage);
|
DebugLn('TPascalParserTool.BuildTree ',MainFilename,' IGNORING ERROR: ',LastErrorMessage);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -2628,6 +2629,8 @@ function TPascalParserTool.KeyWordFuncVar: boolean;
|
|||||||
var d:e;
|
var d:e;
|
||||||
f:g=h;
|
f:g=h;
|
||||||
}
|
}
|
||||||
|
var
|
||||||
|
LastIdentifierEnd: LongInt;
|
||||||
begin
|
begin
|
||||||
if not (CurSection in [ctnProgram,ctnLibrary,ctnInterface,ctnImplementation])
|
if not (CurSection in [ctnProgram,ctnLibrary,ctnInterface,ctnImplementation])
|
||||||
then
|
then
|
||||||
@ -2640,15 +2643,16 @@ begin
|
|||||||
if AtomIsIdentifier(false) then begin
|
if AtomIsIdentifier(false) then begin
|
||||||
CreateChildNode;
|
CreateChildNode;
|
||||||
CurNode.Desc:=ctnVarDefinition;
|
CurNode.Desc:=ctnVarDefinition;
|
||||||
CurNode.EndPos:=CurPos.EndPos;
|
LastIdentifierEnd:=CurPos.EndPos;
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
while (CurPos.Flag=cafComma) do begin
|
while (CurPos.Flag=cafComma) do begin
|
||||||
|
CurNode.EndPos:=LastIdentifierEnd;
|
||||||
EndChildNode; // close variable definition
|
EndChildNode; // close variable definition
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
AtomIsIdentifier(true);
|
AtomIsIdentifier(true);
|
||||||
CreateChildNode;
|
CreateChildNode;
|
||||||
CurNode.Desc:=ctnVarDefinition;
|
CurNode.Desc:=ctnVarDefinition;
|
||||||
CurNode.EndPos:=CurPos.EndPos;
|
LastIdentifierEnd:=CurPos.EndPos;
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
end;
|
end;
|
||||||
if (CurPos.Flag<>cafColon) then begin
|
if (CurPos.Flag<>cafColon) then begin
|
||||||
@ -3759,6 +3763,7 @@ var
|
|||||||
CaretType: integer;
|
CaretType: integer;
|
||||||
IgnorePos: TCodePosition;
|
IgnorePos: TCodePosition;
|
||||||
begin
|
begin
|
||||||
|
//DebugLn(['TPascalParserTool.BuildTreeAndGetCleanPos ',MainFilename,' btSetIgnoreErrorPos=',btSetIgnoreErrorPos in BuildTreeFlags,' btKeepIgnoreErrorPos=',btKeepIgnoreErrorPos in BuildTreeFlags,' CursorPos=x=',CursorPos.X,',y=',CursorPos.Y]);
|
||||||
if (btSetIgnoreErrorPos in BuildTreeFlags) then begin
|
if (btSetIgnoreErrorPos in BuildTreeFlags) then begin
|
||||||
// ignore errors after cursor position
|
// ignore errors after cursor position
|
||||||
if (CursorPos.Code<>nil) then begin
|
if (CursorPos.Code<>nil) then begin
|
||||||
|
Loading…
Reference in New Issue
Block a user