Skip to content

Conversation

@shnewto
Copy link

@shnewto shnewto commented Sep 20, 2017

Prior to this commit this tool's parsing logic made assumptions about
whitespace inside array and sequence definitions. Due to these
assumptions the following scenarios broke the tool's ability
to correctly parse a legal OMG IDL file:

int array1[ 10 ];
int array2[
  10
  ];
sequence< int > seq1;
sequence<
  int
  > seq2;

Logic was added to prepare a file to meet the assumptions of
the parser before parsing. With regular expressions any whitespace
between brackets (including newlines) is eliminated.

Another assumption made by the parser was that arrays were defined
with integer constants. This resulted in the following scenario
breaking the tool's parsing ability:

const MY_CONSTANT = 10;

int array1[ MY_CONSTANT ];

After this commit the tool no longer makes the assumption that the
size of an array is defined by and integer constant. This resulted
in a modification of the code that cast the value to an int as
well as modifications to tests that asserted the value was an int
value. If this change is unacceptable I can revisit the logic and
try another approach.

I was also able to find certain scenarios that challenged the
assumptions I made about the refine_typename function in a
previous commit. Small changes to that function resolved the
issues I encountered.

Thank you for taking the time to review the changes I've proposed.

Prior to this commit this tool's parsing logic made assumptions about
whitespace inside array and sequence definitions. Due to these
assumptions the following scenarios broke the tool's ability
to correctly parse a legal OMG IDL file:

```
int array1[ 10 ];
int array2[
  10
  ];
sequence< int > seq1;
sequence<
  int
  > seq2;
```

Logic was added to prepare a file to meet the assumptions of
the parser before parsing. With regular expressions any whitespace
between brackets (including newlines) is eliminated.

Another assumption made by the parser was that arrays were defined
with integer constants. This resulted in the following scenario
breaking the tool's parsing ability:

```
const MY_CONSTANT = 10;

int array1[ MY_CONSTANT ];

```

After this commit the tool no longer makes the assumption that the
size of an array is defined by and integer constant. This resulted
in a modification of the code that cast the value to an `int` as
well as modifications to tests that asserted the value was an int
value.

I was also able to find certain scenarios that challenged the
assumptions I made about the refine_typename function in a
previous commit. Small changes to that function resolved the
issues I encountered.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 68.999% when pulling c6484c0 on snewt:prepare-file-before-parsing into f9407b1 on sugarsweetrobotics:master.

1 similar comment
@coveralls
Copy link

coveralls commented Sep 20, 2017

Coverage Status

Coverage increased (+0.7%) to 68.999% when pulling c6484c0 on snewt:prepare-file-before-parsing into f9407b1 on sugarsweetrobotics:master.

@sugarsweetrobotics
Copy link
Owner

@Snewt Thank you very much for your great contribution.
The situation when the array size is given as the constant variable was out of my thoughts.

But, actually I do not like this modification. This API forces the users to parse the string (both literal number or name of constant).

Currently, I am very open to modify the API dynamically (or even radically).
Please give me your ideas.
My option is... how about adding the Literal class (like Const class), and both literal number and const number can be accessed the same (or similar) APIs.

Prior to this commit the this branch treated the defined
size of an array as a string. This was problematic as it
forced the user to parse the string to get the literal value
associated with the array size.

This commit adds logic to check whether the size of the array
is defined with a constant value and sets the array value to
an integer value rather than a string.

A little extra validation was added to ensure the specified
size is sensical (if it is not a constant it should be able to
be converted to an integer)

Tests were updated to assure the array sizes are defined as
integers and that the correct constant values are associated
with array size.

Before pushing these changes, I passed the file `basic_module_test.idl`
through the Vortex DDS compiler `idlpp` and some minor details
were addressed to ensure the file compiled sucessfully.
@coveralls
Copy link

coveralls commented Sep 24, 2017

Coverage Status

Coverage increased (+0.8%) to 69.007% when pulling fe96c27 on snewt:prepare-file-before-parsing into f9407b1 on sugarsweetrobotics:master.

@shnewto
Copy link
Author

shnewto commented Sep 24, 2017

@sugarsweetrobotics thank you for your feedback, I agree with your concerns and have attempted to address them. For my uses I do not need the name of the constant used to define the size of an array, only the value. I have revised my approach to retrieve the literal value from the constant's name used to define the array size (see idl_parser/type.py). Please see my most recent commit message.

If the recent changes do not fully address your concern I will revisit the code again. I explored the option of adding a Literal class but my preliminary implementation required other breaking changes and anyone currently using the tool to would have to revise their implementation.

Again, thank you for taking the time to review my changes, I really like this tool and find a lot of value in it.

@shnewto
Copy link
Author

shnewto commented Sep 24, 2017

hmm, the recent changes seems to have issues if there is no module specified. I'll address and push a change. The parser now does not assume there are modules explicitly defined and is able to determine an array's defined size in either case.

@coveralls
Copy link

coveralls commented Sep 25, 2017

Coverage Status

Coverage increased (+0.7%) to 69.002% when pulling 4429143 on snewt:prepare-file-before-parsing into f9407b1 on sugarsweetrobotics:master.

Prior to this commit logic to retrieve the size of an array
defined in an IDL file assumed that one or more modules
we explicitly defined. This resulted in a crash when trying
to access the parser's non-existant list of modules (index out of range).

After this commit the parser does not assume that there are explicit
modules to reference.
@coveralls
Copy link

coveralls commented Sep 25, 2017

Coverage Status

Coverage increased (+0.9%) to 69.126% when pulling cf37c80 on snewt:prepare-file-before-parsing into f9407b1 on sugarsweetrobotics:master.

@sugarsweetrobotics
Copy link
Owner

Thank you very much for your great contribution. This seems familiar to me.

@sugarsweetrobotics sugarsweetrobotics merged commit d2032c3 into sugarsweetrobotics:master Oct 2, 2017
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