RomanYankovsky / DelphiAST

Abstract syntax tree builder for Delphi
Mozilla Public License 2.0
271 stars 116 forks source link

External directives are not correctly recorded #237

Open JBontes opened 6 years ago

JBontes commented 6 years ago

This is a complicated fix. Apparently there is a new keyword 'dependency' that was added at some point.
The fix includes all of the latest changes. Although I did not test the 'index' specifier.

procedure TPasSyntaxTreeBuilder.ExternalDependency;
begin
  FStack.Push(ntDependency);
  try
    inherited;
  finally
    FStack.Pop;
  end;
end;

procedure TPasSyntaxTreeBuilder.ExternalDirective;
begin
  FStack.Push(ntExternal);
  try
    inherited;
  finally
    FStack.Pop;
  end;
end;

procedure TPasSyntaxTreeBuilder.FieldList;
var
  Fields, Temp: TSyntaxNode;
  Field, TypeInfo, TypeArgs: TSyntaxNode;
  IsClassVarSection: boolean;
begin
  IsClassVarSection:= FStack.Peek.HasAttribute(anClass);
  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);
      if (IsClassVarSection) then Temp.Attribute[anClass]:= AttributeValues[atTrue];
      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;

procedure TPasSyntaxTreeBuilder.NameSpecifier;
begin
  FStack.Push(ntExternalName);
  try
    inherited;
  finally
    FStack.Pop;
  end;
end;