Skip to content

procedural types with of object are not recorded correctly #245

Description

@JBontes

The following code does not register the of object part:
In addition, because function and procedure are reserved words, they should not be stored in a anName attribute but in a anType attribute instead.

type
  x = procedure of object;
  y:= function(x: integer): integer of object;

Here's the fix:

type
  TAttributeValue = (atAsm, atTrue, atFunction, atProcedure, atOperator, atClassOf, atClass,
    atConst, atConstructor, atDestructor, atEnum, atInterface, atNil, atNumeric,
    atOut, atPointer, atName, atString, atSubRange, atVar, atType{ExplicitType},
    atObject, atSealed, atAbstract, atBegin, atOf_Object{procedure of object});

var
  AttributeValues: array[TAttributeValue] of string;

procedure InitAttributeValues;
var
  value: TAttributeValue;
  AttributeStr: string;
begin
  for value := Low(TAttributeValue) to High(TAttributeValue) do begin
    AttributeStr:= Copy(LowerCase(GetEnumName(TypeInfo(TAttributeValue), Ord(value))), 3);
    AttributeStr:= StringReplace(AttributeStr, '_', ' ', [rfReplaceAll]);
    AttributeValues[value] := AttributeStr;
  end;
end;

procedure TPasSyntaxTreeBuilder.ProceduralDirectiveOf;
var
  Proc: TSyntaxNode;
begin
  //anType is already used for set/enum/subrange/class/record/interface/object.
  //It could be reused for this data, but it's a directive, not a type as such.
  //And it's to close to `object` proper.
  //It should not be a subnode, because only 'of object' is allowed.
  FStack.Peek.Attribute[anKind]:= AttributeValues[atOf_Object];
  inherited;
end;

Part2 of the fix:

procedure TPasSyntaxTreeBuilder.ProceduralType;
begin
  //procedure/function is a reserved word, so it cannot be the same as an identifier.
  FStack.Push(ntType).Attribute[anType]:= Lexer.Token;
  try
    inherited;
  finally
    FStack.Pop;
  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