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

Generic Methods #213

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Generic Methods #213

wants to merge 2 commits into from

Conversation

Wosi
Copy link
Contributor

@Wosi Wosi commented Aug 31, 2017

Generic type parameters are plain text part of method names. With this PR type parameters of methods are part of AST in the same way as they are in type declarations.

Code:

TGen<T> = class
  procedure Generate<T2>;
end;

AST:

<METHOD begin_line="15" begin_col="5" end_line="16" end_col="3" kind="procedure" name="Generate">
    <TYPEPARAMS line="15" col="23">
        <TYPEPARAM line="15" col="24">
            <TYPE line="15" col="24" name="T2"/>
        </TYPEPARAM>
    </TYPEPARAMS>
</METHOD>

We may need to discuss how the implementations of generic methods are shown in AST.

Code:

procedure TGen<T>.Generate<T2>;
begin
  
end;

Currently the method's name attribute contains the entire method name TGen<T>.Generate<T2>. This is not the most elegant solution as someone would need to parse the name in order to get the generic type parameters and the name of the current class.
I didn't want to break existing projects using DelphiAST so I decided to remove only the method's generic parameters from the name and keep the rest of it untouched: The type name including its generic parameters remains still plain text.

AST:

    <METHOD begin_line="170" begin_col="1" end_line="175" end_col="1" name="TGen&lt;T&gt;.Generate" kind="procedure">
      <TYPEPARAMS line="170" col="27">
        <TYPEPARAM line="170" col="28">
          <TYPE line="170" col="28" name="T2"/>
        </TYPEPARAM>
      </TYPEPARAMS>
      <STATEMENTS begin_line="171" begin_col="1" end_line="173" end_col="4"/>
    </METHOD>

@RomanYankovsky
Copy link
Owner

Can we keep both? Full method name as a string and also as a subtree?

@Wosi
Copy link
Contributor Author

Wosi commented Aug 31, 2017

Generally yes. I'd like to know what other people think.

@JBontes
Copy link

JBontes commented Oct 3, 2017

This is implemented in #231. It works pretty much as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants