mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 05:19:17 +02:00
* Parse program without program header and with complete header
git-svn-id: trunk@21910 -
This commit is contained in:
parent
f32b9fd572
commit
607b86f582
@ -28,6 +28,8 @@ resourcestring
|
|||||||
SPasTreeElement = 'generic element';
|
SPasTreeElement = 'generic element';
|
||||||
SPasTreeSection = 'unit section';
|
SPasTreeSection = 'unit section';
|
||||||
SPasTreeModule = 'module';
|
SPasTreeModule = 'module';
|
||||||
|
SPasTreeUnit = 'unit';
|
||||||
|
SPasTreeProgram = 'program';
|
||||||
SPasTreePackage = 'package';
|
SPasTreePackage = 'package';
|
||||||
SPasTreeResString = 'resource string';
|
SPasTreeResString = 'resource string';
|
||||||
SPasTreeType = 'generic type';
|
SPasTreeType = 'generic type';
|
||||||
@ -271,7 +273,7 @@ type
|
|||||||
TImplementationSection = class(TPasSection)
|
TImplementationSection = class(TPasSection)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TProgramSection = class(TPasSection)
|
TProgramSection = class(TImplementationSection)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TInitializationSection = class;
|
TInitializationSection = class;
|
||||||
@ -295,7 +297,20 @@ type
|
|||||||
|
|
||||||
{ TPasProgram }
|
{ TPasProgram }
|
||||||
|
|
||||||
TPasProgram = class(TPasModule);
|
{ TPasUnitModule }
|
||||||
|
|
||||||
|
TPasUnitModule = Class(TPasModule)
|
||||||
|
function ElementTypeName: string; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TPasProgram = class(TPasModule)
|
||||||
|
Public
|
||||||
|
destructor Destroy; override;
|
||||||
|
function ElementTypeName: string; override;
|
||||||
|
Public
|
||||||
|
ProgramSection: TInterfaceSection;
|
||||||
|
InputFile,OutPutFile : String;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TPasPackage }
|
{ TPasPackage }
|
||||||
|
|
||||||
@ -1063,6 +1078,26 @@ implementation
|
|||||||
|
|
||||||
uses SysUtils;
|
uses SysUtils;
|
||||||
|
|
||||||
|
{ TPasProgram }
|
||||||
|
|
||||||
|
destructor TPasProgram.Destroy;
|
||||||
|
begin
|
||||||
|
FreeAndNil(ProgramSection);
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TPasProgram.ElementTypeName: string;
|
||||||
|
begin
|
||||||
|
Result:=inherited ElementTypeName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TPasUnitModule }
|
||||||
|
|
||||||
|
function TPasUnitModule.ElementTypeName: string;
|
||||||
|
begin
|
||||||
|
Result:=SPasTreeUnit;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TPasStringType }
|
{ TPasStringType }
|
||||||
|
|
||||||
|
|
||||||
@ -1282,7 +1317,9 @@ begin
|
|||||||
InterfaceSection.Release;
|
InterfaceSection.Release;
|
||||||
if Assigned(ImplementationSection) then
|
if Assigned(ImplementationSection) then
|
||||||
ImplementationSection.Release;
|
ImplementationSection.Release;
|
||||||
inherited Destroy;
|
FreeAndNil(InitializationSection);
|
||||||
|
FreeAndNil(FinalizationSection);
|
||||||
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ type
|
|||||||
// Main scope parsing
|
// Main scope parsing
|
||||||
procedure ParseMain(var Module: TPasModule);
|
procedure ParseMain(var Module: TPasModule);
|
||||||
procedure ParseUnit(var Module: TPasModule);
|
procedure ParseUnit(var Module: TPasModule);
|
||||||
procedure ParseProgram(var Module: TPasModule);
|
procedure ParseProgram(var Module: TPasModule; SkipHeader : Boolean = False);
|
||||||
procedure ParseUsesList(ASection: TPasSection);
|
procedure ParseUsesList(ASection: TPasSection);
|
||||||
procedure ParseInterface;
|
procedure ParseInterface;
|
||||||
procedure ParseImplementation;
|
procedure ParseImplementation;
|
||||||
@ -1630,10 +1630,14 @@ begin
|
|||||||
Module:=nil;
|
Module:=nil;
|
||||||
NextToken;
|
NextToken;
|
||||||
case CurToken of
|
case CurToken of
|
||||||
tkUnit: ParseUnit(Module);
|
tkUnit:
|
||||||
tkProgram: ParseProgram(Module);
|
ParseUnit(Module);
|
||||||
else
|
tkProgram:
|
||||||
ParseExc(Format(SParserExpectTokenError, ['unit']));
|
ParseProgram(Module);
|
||||||
|
else
|
||||||
|
ungettoken;
|
||||||
|
ParseProgram(Module,True);
|
||||||
|
// ParseExc(Format(SParserExpectTokenError, ['unit']));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1662,11 +1666,21 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Starts after the "program" token
|
// Starts after the "program" token
|
||||||
procedure TPasParser.ParseProgram(var Module: TPasModule);
|
procedure TPasParser.ParseProgram(var Module: TPasModule; SkipHeader : Boolean = False);
|
||||||
|
|
||||||
|
Var
|
||||||
|
PP : TPasProgram;
|
||||||
|
Section : TProgramSection;
|
||||||
|
N : String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
if SkipHeader then
|
||||||
|
N:=ChangeFileExt(Scanner.CurFilename,'')
|
||||||
|
else
|
||||||
|
N:=ExpectIdentifier;
|
||||||
Module := nil;
|
Module := nil;
|
||||||
Module := TPasModule(CreateElement(TPasProgram, ExpectIdentifier,
|
PP:=TPasProgram(CreateElement(TPasProgram, N, Engine.Package));
|
||||||
Engine.Package));
|
Module :=PP;
|
||||||
FCurModule:=Module;
|
FCurModule:=Module;
|
||||||
try
|
try
|
||||||
if Assigned(Engine.Package) then
|
if Assigned(Engine.Package) then
|
||||||
@ -1674,8 +1688,26 @@ begin
|
|||||||
Module.PackageName := Engine.Package.Name;
|
Module.PackageName := Engine.Package.Name;
|
||||||
Engine.Package.Modules.Add(Module);
|
Engine.Package.Modules.Add(Module);
|
||||||
end;
|
end;
|
||||||
NextToken;
|
if not SkipHeader then
|
||||||
ParseImplementation;
|
begin
|
||||||
|
NextToken;
|
||||||
|
If (CurToken=tkBraceOpen) then
|
||||||
|
begin
|
||||||
|
PP.InputFile:=ExpectIdentifier;
|
||||||
|
NextToken;
|
||||||
|
if Not (CurToken in [tkBraceClose,tkComma]) then
|
||||||
|
ParseExc(SParserExpectedCommaRBracket);
|
||||||
|
If (CurToken=tkComma) then
|
||||||
|
PP.OutPutFile:=ExpectIdentifier;
|
||||||
|
ExpectToken(tkBraceClose);
|
||||||
|
NextToken;
|
||||||
|
end;
|
||||||
|
if (CurToken<>tkSemicolon) then
|
||||||
|
ParseExc(Format(SParserExpectTokenError,[';']));
|
||||||
|
end;
|
||||||
|
Section := TProgramSection(CreateElement(TProgramSection, '', CurModule));
|
||||||
|
PP.ImplementationSection := Section;
|
||||||
|
ParseDeclarations(Section);
|
||||||
finally
|
finally
|
||||||
FCurModule:=nil;
|
FCurModule:=nil;
|
||||||
end;
|
end;
|
||||||
@ -1803,11 +1835,13 @@ begin
|
|||||||
case CurToken of
|
case CurToken of
|
||||||
tkend:
|
tkend:
|
||||||
begin
|
begin
|
||||||
|
If (CurModule is TPasProgram) and (CurModule.InitializationSection=Nil) then
|
||||||
|
ParseExc(Format(SParserExpectTokenError,['begin']));
|
||||||
ExpectToken(tkDot);
|
ExpectToken(tkDot);
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
tkimplementation:
|
tkimplementation:
|
||||||
if (CurToken = tkImplementation) and (Declarations is TInterfaceSection) then
|
if (Declarations is TInterfaceSection) then
|
||||||
begin
|
begin
|
||||||
If Not Engine.InterfaceOnly then
|
If Not Engine.InterfaceOnly then
|
||||||
begin
|
begin
|
||||||
@ -1819,14 +1853,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
tkinitialization:
|
tkinitialization:
|
||||||
if (Declarations is TInterfaceSection)
|
if (Declarations is TInterfaceSection)
|
||||||
or (Declarations is TImplementationSection) then
|
or ((Declarations is TImplementationSection) and not (Declarations is TProgramSection)) then
|
||||||
begin
|
begin
|
||||||
ParseInitialization;
|
ParseInitialization;
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
tkfinalization:
|
tkfinalization:
|
||||||
if (Declarations is TInterfaceSection)
|
if (Declarations is TInterfaceSection)
|
||||||
or (Declarations is TImplementationSection) then
|
or ((Declarations is TImplementationSection) and not (Declarations is TProgramSection)) then
|
||||||
begin
|
begin
|
||||||
ParseFinalization;
|
ParseFinalization;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user