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

parsing(c_parser): Added parsing code to handle the assignment case where character is assigned to integer #18925

Merged
merged 1 commit into from
Mar 24, 2020

Conversation

smitgajjar
Copy link
Contributor

@smitgajjar smitgajjar commented Mar 21, 2020

References to other Issues or PRs

Brief description of what is fixed or changed

Added the case where character is assigned to an integer

  • Added code in the function transform_character_literal() to return appropriate string
  • Handled the AST clang nodes in transform_var_decl()
  • Added tests for the same.

Other comments

Consider the following case :

In [1]: from sympy.parsing.sym_expr import SymPyExpression                      

In [2]: src = """ 
   ...: int a='1', b='d'; 
   ...: """                                                                     

In [3]: a=SymPyExpression(src, 'c')                                             

In [4]: a.return_expr()                                                         
Out[4]: 
[Declaration(Variable(a, type=integer, value=49)), Declaration(Variable(b, typ
e=integer, value=100))]

Before: Raised NotImplementedError
Now: Assigns correct ascii value to the integer value as expected in C and successfully gets parsed to sympy expression as shown above.

Release Notes

  • parsing
    • Added the assignment case where character is assigned to an integer in C parser

@sympy-bot
Copy link

sympy-bot commented Mar 21, 2020

Hi, I am the SymPy bot (v158). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • parsing
    • Added the assignment case where character is assigned to an integer in C parser (#18925 by @smitgajjar)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.6.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->


#### Brief description of what is fixed or changed
Added the case where character is assigned to an integer
- Added code in the function transform_character_literal() to return appropriate string
- Handled the AST clang nodes in transform_var_decl()
-  Added tests for the same.

#### Other comments
Consider the following case :
<pre>
In [1]: from sympy.parsing.sym_expr import SymPyExpression                      

In [2]: src = """ 
   ...: int a='1', b='d'; 
   ...: """                                                                     

In [3]: a=SymPyExpression(src, 'c')                                             

In [4]: a.return_expr()                                                         
Out[4]: 
[Declaration(Variable(a, type=integer, value=49)), Declaration(Variable(b, typ
e=integer, value=100))]

</pre>

Before: Raised NotImplementedError
Now: Assigns correct ascii value to the integer value as expected in C and successfully gets parsed to sympy expression as shown above.

#### Release Notes


<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
- parsing
    - Added the assignment case where character is assigned to an integer in C parser
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@smitgajjar smitgajjar changed the title handled the case where character is assigned to integer parsing(c_parser): Added parsing code to handle the assignment case where character is assigned to integer Mar 21, 2020
@codecov
Copy link

codecov bot commented Mar 22, 2020

Codecov Report

Merging #18925 into master will increase coverage by 0.084%.
The diff coverage is 0%.

@@             Coverage Diff              @@
##           master    #18925       +/-   ##
============================================
+ Coverage   75.65%   75.734%   +0.084%     
============================================
  Files         647       647               
  Lines      168528    168564       +36     
  Branches    39710     39722       +12     
============================================
+ Hits       127492    127661      +169     
+ Misses      35476     35348      -128     
+ Partials     5560      5555        -5

Comment on lines 497 to 498

val : value
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be

val : str
     Its description

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for suggestion! I will change it as requested.

Copy link
Member

@Sc0rpi0n101 Sc0rpi0n101 left a comment

Choose a reason for hiding this comment

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

I've left a few comments.
Otherwise, it looks good.

#return val
pass
value = node.literal
return str(value[1])
Copy link
Member

Choose a reason for hiding this comment

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

why does this have to be value[1]?
Wouldn't value have the character literal that can directly be returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, node.literal returns a str having value '<char>', whereas we only want <char>. So, it is a sort of workaround.

Copy link
Member

Choose a reason for hiding this comment

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

ok

@@ -256,6 +256,16 @@ def transform_var_decl(self, node):
).as_Declaration(
value = val
)
elif (child.kind == cin.CursorKind.CHARACTER_LITERAL
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment here describing when it will be called?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will add it in the next commit.

@Sc0rpi0n101
Copy link
Member

I think the rest looks good.

Can you also squash your commits into one with a description of all the changes?

@smitgajjar
Copy link
Contributor Author

I guess, this longer commit message looks weird! Anyways, did the squash! :)

@smichr
Copy link
Member

smichr commented Mar 23, 2020

commit message looks weird

If you add a blank line between title of commit and commit message it will look better:

title blah blah

comments

@smitgajjar
Copy link
Contributor Author

Alright, thanks for the help, I will do it now!

C parser code could not handle the situation, where a variable which is declared as integer has been assigned with a character literal. For this, the function transform_character_literal() has been completed so as to handle character literals to be used in this case. Then, in transform_var_decl() function, after getting the node value from previous function, this case is handled in a separate elif block along with the comment giving its explanation. Also, corresponding test is added.
@Sc0rpi0n101 Sc0rpi0n101 merged commit ce1e53f into sympy:master Mar 24, 2020
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 this pull request may close these issues.

None yet

6 participants