Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class variables have class attribute (Fixed version) #215

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Source/DelphiAST.pas
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ TPasSyntaxTreeBuilder = class(TmwSimplePasPar)
procedure ClassProperty; override;
procedure ClassReferenceType; override;
procedure ClassType; override;
procedure ClassVar; override;
procedure CompoundStatement; override;
procedure ConstParameter; override;
procedure ConstantDeclaration; override;
Expand Down Expand Up @@ -767,9 +768,13 @@ procedure TPasSyntaxTreeBuilder.ClassClass;

procedure TPasSyntaxTreeBuilder.ClassField;
var
Fields, Temp: TSyntaxNode;
Fields, Temp, Parent: TSyntaxNode;
Field, TypeInfo, TypeArgs: TSyntaxNode;
IsClassVar: Boolean;
begin
Parent := FStack.Peek;
IsClassVar := (Parent.Typ = ntVariables) and Parent.HasAttribute(anClass);

Fields := TSyntaxNode.Create(ntFields);
try
FStack.Push(Fields);
Expand All @@ -789,6 +794,8 @@ procedure TPasSyntaxTreeBuilder.ClassField;
Temp := FStack.Push(ntField);
try
Temp.AssignPositionFrom(Field);
if IsClassVar then
Temp.SetAttribute(anClass, AttributeValues[atTrue]);

FStack.AddChild(Field.Clone);
TypeInfo := TypeInfo.Clone;
Expand Down Expand Up @@ -889,6 +896,26 @@ procedure TPasSyntaxTreeBuilder.ClassType;
end;
end;

procedure TPasSyntaxTreeBuilder.ClassVar;
var
FieldNode, Variables: TSyntaxNode;
begin
Variables := FStack.Push(ntVariables);
try
Variables.SetAttribute(anClass, AttributeValues[atTrue]);
inherited;
finally
FStack.Pop;
end;

try
for FieldNode in Variables.ChildNodes do
FStack.AddChild(FieldNode.Clone);
finally
Variables.ParentNode.DeleteChild(Variables);
end;
end;

procedure TPasSyntaxTreeBuilder.MoveMembersToVisibilityNodes(TypeNode: TSyntaxNode);
var
child, vis: TSyntaxNode;
Expand Down
8 changes: 7 additions & 1 deletion Source/SimpleParser/SimpleParser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ TmwSimplePasPar = class(TObject)
procedure ClassReferenceType; virtual;
procedure ClassType; virtual;
procedure ClassTypeEnd; virtual;
procedure ClassVar; virtual;
procedure ClassVisibility; virtual;
procedure CompoundStatement; virtual;
procedure ConstantColon; virtual;
Expand Down Expand Up @@ -3696,6 +3697,11 @@ procedure TmwSimplePasPar.ClassHeritage;
Expected(ptRoundClose);
end;

procedure TmwSimplePasPar.ClassVar;
begin
ClassField;
end;

procedure TmwSimplePasPar.ClassVisibility;
var
IsStrict: boolean;
Expand Down Expand Up @@ -3850,7 +3856,7 @@ procedure TmwSimplePasPar.ClassMethodOrProperty;
NextToken;
while (TokenID = ptIdentifier) and (ExID = ptUnknown) do
begin
ClassField;
ClassVar;
Semicolon;
end;
end;
Expand Down