mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 19:02:31 +02:00
codetools: parse programs without program keyword
git-svn-id: trunk@30035 -
This commit is contained in:
parent
831200c3ff
commit
2af49962ac
@ -2253,16 +2253,20 @@ begin
|
||||
|
||||
NewTool.MoveCursorToNodeStart(IdentNode);
|
||||
NewTool.ReadNextAtom;
|
||||
Result:=Result+NewTool.GetAtom+' ';
|
||||
if (IdentNode.Desc=ctnProgram) and not UpAtomIs('PROGRAM') then begin
|
||||
// program without source name
|
||||
Result:='program '+ExtractFileNameOnly(MainFilename)+' ';
|
||||
end else begin
|
||||
Result:=Result+NewTool.GetAtom+' ';
|
||||
|
||||
if NewNode.Desc = ctnProperty then
|
||||
begin // add class name
|
||||
ClassStr := NewTool.ExtractClassName(NewNode, False, True);
|
||||
if ClassStr <> '' then Result := Result + ClassStr + '.';
|
||||
if NewNode.Desc = ctnProperty then begin // add class name
|
||||
ClassStr := NewTool.ExtractClassName(NewNode, False, True);
|
||||
if ClassStr <> '' then Result := Result + ClassStr + '.';
|
||||
end;
|
||||
|
||||
NewTool.ReadNextAtom;
|
||||
Result:=Result+NewTool.GetAtom+' ';
|
||||
end;
|
||||
|
||||
NewTool.ReadNextAtom;
|
||||
Result:=Result+NewTool.GetAtom+' ';
|
||||
IdentAdded:=true;
|
||||
end;
|
||||
|
||||
@ -2817,6 +2821,7 @@ var
|
||||
Result:=false;
|
||||
MoveCursorToNodeStart(ContextNode);
|
||||
ReadNextAtom; // read keyword
|
||||
if (ContextNode.Desc=ctnProgram) and (not UpAtomIs('PROGRAM')) then exit;
|
||||
ReadNextAtom; // read name
|
||||
if (fdfCollect in Params.Flags)
|
||||
or CompareSrcIdentifiers(CurPos.StartPos,Params.Identifier) then
|
||||
@ -5943,6 +5948,7 @@ begin
|
||||
if Node.Desc in AllSourceTypes then begin
|
||||
MoveCursorToNodeStart(Node);
|
||||
ReadNextAtom;
|
||||
if (Node.Desc=ctnProgram) and not UpAtomIs('PROGRAM') then exit;
|
||||
ReadNextAtom;
|
||||
Result:=CompareSrcIdentifiers(CurPos.StartPos,Params.Identifier);
|
||||
end else if (Node.Desc in AllSimpleIdentifierDefinitions)
|
||||
|
@ -516,6 +516,7 @@ procedure TPascalParserTool.BuildTree(Range: TLinkScannerRange);
|
||||
var
|
||||
Node: TCodeTreeNode;
|
||||
p: PChar;
|
||||
HasSourceType: Boolean;
|
||||
begin
|
||||
{$IFDEF MEM_CHECK}CheckHeap('TPascalParserTool.BuildTree A '+IntToStr(MemCheck_GetMem_Cnt));{$ENDIF}
|
||||
{$IFDEF CTDEBUG}
|
||||
@ -604,6 +605,7 @@ begin
|
||||
end;
|
||||
|
||||
// read source type and name
|
||||
HasSourceType:=true;
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('UNIT') then
|
||||
CurSection:=ctnUnit
|
||||
@ -613,33 +615,47 @@ begin
|
||||
CurSection:=ctnPackage
|
||||
else if UpAtomIs('LIBRARY') then
|
||||
CurSection:=ctnLibrary
|
||||
else
|
||||
SaveRaiseExceptionFmt(ctsNoPascalCodeFound,[GetAtom],true);
|
||||
else begin
|
||||
// the source type is missing
|
||||
// this is allowed for program
|
||||
if UpAtomIs('USES') or UpAtomIs('TYPE') or UpAtomIs('VAR')
|
||||
or UpAtomIs('CONST') or UpAtomIs('RESOURCESTRING')
|
||||
or UpAtomIs('BEGIN') then begin
|
||||
CurSection:=ctnProgram;
|
||||
HasSourceType:=false;
|
||||
CurPos.EndPos:=CurPos.StartPos;
|
||||
end else
|
||||
SaveRaiseExceptionFmt(ctsNoPascalCodeFound,[GetAtom],true);
|
||||
end;
|
||||
if CurNode=nil then
|
||||
CreateChildNode;
|
||||
CurNode.Desc:=CurSection;
|
||||
ScannedRange:=lsrSourceType;
|
||||
if ord(Range)<=ord(ScannedRange) then exit;
|
||||
ReadNextAtom; // read source name
|
||||
AtomIsIdentifier(true);
|
||||
ReadNextAtom; // read ';' (or 'platform;' or 'unimplemented;')
|
||||
if HasSourceType then begin
|
||||
ReadNextAtom; // read source name
|
||||
AtomIsIdentifier(true);
|
||||
ReadNextAtom; // read ';' (or 'platform;' or 'unimplemented;')
|
||||
end;
|
||||
ScannedRange:=lsrSourceName;
|
||||
if ord(Range)<=ord(ScannedRange) then exit;
|
||||
if UpAtomIs('PLATFORM') then
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('UNIMPLEMENTED') then
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('LIBRARY') then
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('EXPERIMENTAL') then
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('DEPRECATED') then begin
|
||||
ReadNextAtom;
|
||||
if CurPos.Flag<>cafSemicolon then
|
||||
ReadConstant(true,false,[]);
|
||||
if HasSourceType then begin
|
||||
if UpAtomIs('PLATFORM') then
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('UNIMPLEMENTED') then
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('LIBRARY') then
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('EXPERIMENTAL') then
|
||||
ReadNextAtom;
|
||||
if UpAtomIs('DEPRECATED') then begin
|
||||
ReadNextAtom;
|
||||
if CurPos.Flag<>cafSemicolon then
|
||||
ReadConstant(true,false,[]);
|
||||
end;
|
||||
if (CurPos.Flag<>cafSemicolon) then
|
||||
RaiseCharExpectedButAtomFound(';');
|
||||
end;
|
||||
if (CurPos.Flag<>cafSemicolon) then
|
||||
RaiseCharExpectedButAtomFound(';');
|
||||
if CurSection=ctnUnit then begin
|
||||
ReadNextAtom;
|
||||
CurNode.EndPos:=CurPos.StartPos;
|
||||
|
@ -1689,6 +1689,7 @@ begin
|
||||
if Tree.Root=nil then exit;
|
||||
MoveCursorToNodeStart(Tree.Root);
|
||||
ReadNextAtom; // read source type 'program', 'unit' ...
|
||||
if (Tree.Root.Desc=ctnProgram) and (not UpAtomIs('PROGRAM')) then exit;
|
||||
ReadNextAtom; // read name
|
||||
NamePos:=CurPos;
|
||||
Result:=(NamePos.StartPos<=SrcLen);
|
||||
@ -1700,6 +1701,7 @@ begin
|
||||
if Tree.Root=nil then exit;
|
||||
MoveCursorToNodeStart(Tree.Root);
|
||||
ReadNextAtom; // read source type 'program', 'unit' ...
|
||||
if (Tree.Root.Desc=ctnProgram) and (not UpAtomIs('PROGRAM')) then exit;
|
||||
ReadNextAtom; // read name
|
||||
Result:=(CleanPos>=CurPos.StartPos) and (CleanPos<CurPos.EndPos);
|
||||
end;
|
||||
@ -1710,6 +1712,8 @@ var
|
||||
begin
|
||||
if GetSourceNamePos(NamePos) then
|
||||
Result:=GetAtom
|
||||
else if Tree.Root.Desc=ctnProgram then
|
||||
Result:=ExtractFileNameOnly(MainFilename)
|
||||
else
|
||||
Result:='';
|
||||
end;
|
||||
@ -2093,13 +2097,11 @@ begin
|
||||
end;
|
||||
|
||||
function TPascalReaderTool.GetSourceName(DoBuildTree: boolean): string;
|
||||
var NamePos: TAtomPosition;
|
||||
begin
|
||||
Result:='';
|
||||
if DoBuildTree then
|
||||
BuildTree(lsrSourceName);
|
||||
if not GetSourceNamePos(NamePos) then exit;
|
||||
CachedSourceName:=copy(Src,NamePos.StartPos,NamePos.EndPos-NamePos.StartPos);
|
||||
CachedSourceName:=ExtractSourceName;
|
||||
Result:=CachedSourceName;
|
||||
end;
|
||||
|
||||
|
@ -374,14 +374,7 @@ end;
|
||||
-------------------------------------------------------------------------------}
|
||||
function TStandardCodeTool.GetCachedSourceName: string;
|
||||
begin
|
||||
if Tree.Root<>nil then begin
|
||||
MoveCursorToNodeStart(Tree.Root);
|
||||
ReadNextAtom; // read source type 'program', 'unit' ...
|
||||
ReadNextAtom; // read name
|
||||
if (CurPos.StartPos<=SrcLen) then
|
||||
CachedSourceName:=GetAtom;
|
||||
end;
|
||||
Result:=CachedSourceName;
|
||||
Result:=GetSourceName(false);
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.RenameSource(const NewName: string;
|
||||
|
Loading…
Reference in New Issue
Block a user