fcl-passrc: paswrite: allow to write class variables in classes/records

git-svn-id: trunk@37039 -
This commit is contained in:
maciej-izak 2017-08-22 22:41:10 +00:00
parent 9c6b78f11e
commit ae15dfbc06

View File

@ -35,6 +35,7 @@ type
procedure IncDeclSectionLevel; procedure IncDeclSectionLevel;
procedure DecDeclSectionLevel; procedure DecDeclSectionLevel;
procedure PrepareDeclSection(const ADeclSection: string); procedure PrepareDeclSection(const ADeclSection: string);
procedure PrepareDeclSectionInStruct(const ADeclSection: string);
public public
constructor Create(AStream: TStream); constructor Create(AStream: TStream);
destructor Destroy; override; destructor Destroy; override;
@ -283,6 +284,7 @@ begin
wrtln('['+AClass.InterfaceGUID+']'); wrtln('['+AClass.InterfaceGUID+']');
IncIndent; IncIndent;
IncDeclSectionLevel;
LastVisibility := visDefault; LastVisibility := visDefault;
LastMember := nil; LastMember := nil;
for i := 0 to AClass.Members.Count - 1 do for i := 0 to AClass.Members.Count - 1 do
@ -301,20 +303,31 @@ begin
end; end;
IncIndent; IncIndent;
LastVisibility := CurVisibility; LastVisibility := CurVisibility;
CurDeclSection := '';
end; end;
WriteElement(Member); WriteElement(Member);
LastMember := Member; LastMember := Member;
end; end;
DecDeclSectionLevel;
DecIndent; DecIndent;
wrtln('end;'); wrtln('end;');
wrtln; wrtln;
end; end;
procedure TPasWriter.WriteVariable(AVar: TPasVariable); procedure TPasWriter.WriteVariable(AVar: TPasVariable);
var
LParentIsClassOrRecord: boolean;
begin begin
if (AVar.Parent.ClassType <> TPasClassType) and LParentIsClassOrRecord:= (AVar.Parent.ClassType = TPasClassType) or
(AVar.Parent.ClassType <> TPasRecordType) then (AVar.Parent.ClassType = TPasRecordType);
PrepareDeclSection('var'); if not LParentIsClassOrRecord then
PrepareDeclSection('var')
// handle variables in classes/records
else if vmClass in AVar.VarModifiers then
PrepareDeclSectionInStruct('class var')
else if CurDeclSection<>'' then
PrepareDeclSectionInStruct('var');
wrt(AVar.Name + ': '); wrt(AVar.Name + ': ');
WriteType(AVar.VarType); WriteType(AVar.VarType);
wrtln(';'); wrtln(';');
@ -682,6 +695,19 @@ begin
end; end;
end; end;
procedure TPasWriter.PrepareDeclSectionInStruct(const ADeclSection: string);
begin
if ADeclSection <> CurDeclSection then
begin
if ADeclSection <> '' then
begin
DecIndent;
wrtln(ADeclSection);
IncIndent;
end;
CurDeclSection := ADeclSection;
end;
end;
procedure WritePasFile(AElement: TPasElement; const AFilename: string); procedure WritePasFile(AElement: TPasElement; const AFilename: string);
var var