Skip to content

[ASTGen] Generalize findSyntaxNodeInSourceFile(wantOutermost:true) #69724

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

Closed
wants to merge 1 commit into from

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Nov 8, 2023

When wantOutermost is true, keep looking the parent nodes as long as the position is the same as the innermost matching node, and return the last matching node found.

@rintaro
Copy link
Member Author

rintaro commented Nov 8, 2023

@swift-ci Please smoke test

@rintaro rintaro force-pushed the astgen-findnode-outermost branch 2 times, most recently from 63db1ac to b7f881f Compare November 8, 2023 19:24
@rintaro
Copy link
Member Author

rintaro commented Nov 8, 2023

@swift-ci Please smoke test

When 'wantOutermost' is true, traverse the parent as long as the
position is the same as the target position.
@rintaro rintaro force-pushed the astgen-findnode-outermost branch from b7f881f to 2e26370 Compare November 8, 2023 19:39
@rintaro
Copy link
Member Author

rintaro commented Nov 8, 2023

@swift-ci Please smoke test

{
while
let parentSyntax = currentSyntax.parent,
parentSyntax.position == resultSyntax.position {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a restriction that the outer nodes must stay in the same position, and it's inconsistent with the innermost node discovery. But in our use cases, this should be enough.

Copy link
Member Author

@rintaro rintaro Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have two separate methods like

// For macro expansion node discovery:
findTokenInSourceFile(in: exporetedSourceFile, at: sourceLoc)?
  .innermostNode(ofType: AttributeSyntax.self)

// For partial ASTGen:
findTokenInSourceFile(in: exporetedSourceFile, at: sourceLoc)?
  .outermostNodeAtSamePosition(ofType: ExprSyntax.self)

@rintaro
Copy link
Member Author

rintaro commented Nov 14, 2023

included in #69761

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.

1 participant