RomanYankovsky / DelphiAST

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

Bug: Attributes need to be attached to the item succeeding it, not to the item preceding it. #219

Open JBontes opened 6 years ago

JBontes commented 6 years ago

Currently an attribute is listed as follows:

unit PlusIsTest;

interface

type
  [MyAttribute]
  Test2 = class
  end;
implementation
end.
<?xml version="1.0"?>
<UNIT line="1" col="1" name="PlusIsTest">
  <INTERFACE begin_line="3" begin_col="1" end_line="13" end_col="1">
    <TYPESECTION line="5" col="1">
      <ATTRIBUTES line="6" col="3">
        <ATTRIBUTE line="6" col="4">
          <NAME line="6" col="4" value="MyAttribute"/>
        </ATTRIBUTE>
      </ATTRIBUTES>
      <TYPEDECL begin_line="7" begin_col="3" end_line="8" end_col="6" name="Test2">
        <TYPE line="7" col="11" type="class"/>
      </TYPEDECL>
    </TYPESECTION>
  </INTERFACE>
  <IMPLEMENTATION>
  </IMPLEMENTATION>
</UNIT>

This is incorrect, the attribute needs to be listed as a child of the item succeeding it, like so:

<?xml version="1.0"?>
<UNIT line="1" col="1" name="PlusIsTest">
  <INTERFACE begin_line="3" begin_col="1" end_line="13" end_col="1">
    <TYPESECTION line="5" col="1">
      <TYPEDECL begin_line="7" begin_col="3" end_line="8" end_col="6" name="Test2">
        <ATTRIBUTES line="6" col="3">
          <ATTRIBUTE line="6" col="4">
            <NAME line="6" col="4" value="MyAttribute"/>
          </ATTRIBUTE>
        </ATTRIBUTES>
        <TYPE line="7" col="11" type="class"/>
      </TYPEDECL>
    </TYPESECTION>
  </INTERFACE>
  <IMPLEMENTATION>
  </IMPLEMENTATION>
</UNIT>

The current implementation also causes attributes to disappear, e.g.:

  procedure X(const [ref] i: integer); 

Does not have the attribute listed at all!

<METHOD begin_line="15" begin_col="1" end_line="22" end_col="1" kind="procedure" name="X">
      <PARAMETERS line="15" col="17">
        <PARAMETER line="15" col="30" kind="const">
          <NAME line="15" col="30" value="i"/>
          <TYPE line="15" col="35" name="integer"/>
        </PARAMETER>
      </PARAMETERS>