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

Option on ArrayTypeNode and ArrayType to get starting and ending array index and range #259

Open
2 tasks done
EduardoVaz06 opened this issue Jun 13, 2024 · 1 comment
Open
2 tasks done
Labels
engine Improvements to the core engine enhancement Improvements to an existing feature

Comments

@EduardoVaz06
Copy link

EduardoVaz06 commented Jun 13, 2024

Prerequisites

  • This improvement has not already been suggested.
  • This improvement would be generally useful, not specific to my code or setup.

Engine area

Rules API

Improvement description

As said in my question issue (#257), It would be a great improvement if those two classes (ArrayTypeNode and ArrayType) could directly get the starting index, ending index and range of the array.
Now, the way of doing this is: acessing ArrayTypeNode, getting the first child of type ArrayIndicesNode, getting the first child of type SubRangeTypeNode, getting lowExpression and highExpression.

It would be good to have something like:

ArrayTypeNode.getStartingIndex();
ArrayTypeNode.getEndingIndex();
ArrayTypeNode.getRange();

ArrayType.getStartingIndex();
ArrayType.getEndingIndex();
ArrayType.getRange();

Rationale

This option could make it easier to create new rules or enhance existing ones for everyone, since it simplifies the way of getting arrays indexes.

One example of usage would be a rule that verifies if a for iteration is done in the correct range. If there is an iteration in an array defined as:
MyArray: array[2..5] of Integer

And the iteration something like:
for Index := 2 to Length(MyArray) -1

That would not work, as the iteration would not be executed in the wanted range. With this improvement, there could be a simple way of verifying the indexes and validate if the iteration is executed the correct range.

@EduardoVaz06 EduardoVaz06 added engine Improvements to the core engine enhancement Improvements to an existing feature triage This needs to be triaged by a maintainer labels Jun 13, 2024
@Cirras Cirras changed the title Option on ArrayTypeNode and ArrayType to get starting end ending array index and range Option on ArrayTypeNode and ArrayType to get starting and ending array index and range Jun 14, 2024
@Cirras Cirras removed the triage This needs to be triaged by a maintainer label Jun 14, 2024
@Cirras
Copy link
Collaborator

Cirras commented Jun 14, 2024

Definitely an area where the API can be fleshed out more.

I'm thinking:

  • ArrayTypeNode::getArrayIndices method
  • ArrayIndicesNode::getTypeNode method (and you can check to see which type it is)
  • ArrayType::indexType method (corresponding to ArrayIndicesNode::getTypeNode)

And then a couple that are blocked by #116:

  • SubRangeType::low method (corresponding to SubRangeTypeNode::getLowExpression)
  • SubRangeType::high method (corresponding to SubRangeTypeNode::getHighExpression)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine Improvements to the core engine enhancement Improvements to an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants