Skip to content

Old skool Objects do not generate a node and fields of an object are incorrectly classified as ntIndentifier #229

Description

@JBontes

The following code:

type
  O = object(ParentObject)
  end;

Does not generate a node for the object keyword.

Here's the fix for the first part:

procedure TPasSyntaxTreeBuilder.ObjectType; {override}
begin
  FStack.Push(ntType).SetAttribute(anType, AttributeValues[atObject]);
  try
    inherited;
  finally
    MoveMembersToVisibilityNodes(FStack.Pop);
  end;
end;

And the fix for the second part

procedure TmwSimplePasPar.ObjectField;
begin
  if TokenID = ptSquareOpen then
    CustomAttribute;
  FieldNameList;
  Expected(ptColon);
  TypeKind;
  TypeDirective;
end;

procedure TPasSyntaxTreeBuilder.ObjectField;  {override}
var
  Fields, Temp: TSyntaxNode;
  Field, TypeInfo, TypeArgs: TSyntaxNode;
begin
  Fields := TSyntaxNode.Create(ntFields);
  try
    FStack.Push(Fields);
    try
      inherited;
    finally
      FStack.Pop;
    end;

    TypeInfo := Fields.FindNode(ntType);
    TypeArgs := Fields.FindNode(ntTypeArgs);
    for Field in Fields.ChildNodes do
    begin
      if Field.Typ <> ntName then
        Continue;

      Temp := FStack.Push(ntField);
      try
        Temp.AssignPositionFrom(Field);

        FStack.AddChild(Field.Clone);
        TypeInfo := TypeInfo.Clone;
        if Assigned(TypeArgs) then
          TypeInfo.AddChild(TypeArgs.Clone);
        FStack.AddChild(TypeInfo);
      finally
        FStack.Pop;
      end;
    end;
  finally
    Fields.Free;
  end;
end;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions