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

Source position and type cast and brackets #2055

Closed
pvojtechovsky opened this issue Jun 11, 2018 · 4 comments · Fixed by #2115
Closed

Source position and type cast and brackets #2055

pvojtechovsky opened this issue Jun 11, 2018 · 4 comments · Fixed by #2115
Labels

Comments

@pvojtechovsky
Copy link
Collaborator

This problem was found by #1927

In the code like

someFnc(((File) (null)));

The source position of null literal contains only sources "null", but may be there should be type case (File) and may be also brackets. So source position would contain this: ((File) (null)).

But then I would prefer to have more details in source position. So may be we should introduce ExpressionSourcePosition, which would be similar to DeclarationSourcePosition. It means it would have these parts

  • start/end -> "((File) (null))"
  • typeCastStart/End -> "(File)"
  • expressionStart/End -> "(null)"

@tdurieux Do you think it would make sense to introduce new ExpressionSourcePosition or we can use DeclarationSourcePosition instead here too? Or may be we do not need that at all and source position of expressions is just simple SourcePosition for some reason?

And what about brackets? Are they part of expression or not?

@tdurieux
Copy link
Collaborator

Do you think it would make sense to introduce new ExpressionSourcePosition

That is a good question.
What is the difference with the normal SourcePosition?

And what about brackets? Are they part of expression or not?

I would say yes, otherwise there are part of nothing, no?

@pvojtechovsky
Copy link
Collaborator Author

What is the difference with the normal SourcePosition?

normal SourcePosition has only

  • start/end of element

while ExpressionSourcePosition will have

  • start / end of whole expression including type cast
  • typeCastStart/End the type cast part
  • expressionStart/End the pure expression part

And what about brackets? Are they part of expression or not?

I would say yes, otherwise there are part of nothing, no?

I agree that braces should be part of expression too (they are actually not it's part.)

@pvojtechovsky
Copy link
Collaborator Author

May be I will have time this evening to have a look at this issue. But I am still not sure about concept of the solution.

I will probably create new class CompoundSourcePositionImpl extends SourcePositionImpl and will change DeclarationSourcePositionImpl extends CompoundSourcePositionImpl.

Where new class CompoundSourcePositionImpl will contain declarationSourceStart and declarationSourceEnd.
So
CompoundSourcePositionImpl will have these fields:

  • sourceStart/End - start end of whole expression including type cast and brackets
  • declarationSourceStart/End - start end of expression itself excluding type cast or brackets

WDYT?

@tdurieux
Copy link
Collaborator

It seems good for me. Thanks

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

Successfully merging a pull request may close this issue.

2 participants