Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add support for __volatile__, and __restrict__ #23

Closed
mhoffma opened this issue Dec 11, 2016 · 2 comments · Fixed by #52
Closed

add support for __volatile__, and __restrict__ #23

mhoffma opened this issue Dec 11, 2016 · 2 comments · Fixed by #52

Comments

@mhoffma
Copy link

mhoffma commented Dec 11, 2016

I added some support to handle Snapdragon processors, header files. Basically, trivial support for volatile I could have used a #define but this seems to be a better method. I think GCC supports both __XXX and XXX for all of those key words so this is really a missing feature.

mhoffman-linux02$ git diff

diff --git a/pycparserext/ext_c_lexer.py b/pycparserext/ext_c_lexer.py
index e501a61..ed7ae67 100644
--- a/pycparserext/ext_c_lexer.py
+++ b/pycparserext/ext_c_lexer.py
@@ -63,8 +63,8 @@ def add_lexer_keywords(cls, keywords):
 add_lexer_keywords(GnuCLexer, [
     '__attribute__', '__asm__', '__asm', '__typeof__',
     '__real__', '__imag__', '__builtin_types_compatible_p',
-    '__const', '__restrict', '__inline', '__inline__',
-    '__extension__', 'asm', '__attribute'])
+    '__const', '__restrict', '__restrict__', '__inline', '__inline__',
+    '__extension__', 'asm', '__attribute', '__volatile__'])

 _CL_KEYWORDS = ['kernel', 'constant', 'global', 'local', 'private',
         "read_only", "write_only", "read_write"]
diff --git a/pycparserext/ext_c_parser.py b/pycparserext/ext_c_parser.py
index c9a014a..218d118 100644
--- a/pycparserext/ext_c_parser.py
+++ b/pycparserext/ext_c_parser.py
@@ -359,6 +359,7 @@ class _AsmMixin(object):

     def p_asm_volatile(self, p):
         """ asm_volatile : VOLATILE
+                         | __VOLATILE__
                          | empty
         """
         p[0] = p[1]
@@ -434,6 +435,7 @@ class GnuCParser(_AsmAndAttributesMixin, CParserBase):
     def p_type_qualifier_gnu(self, p):
         """ type_qualifier  : __CONST
                             | __RESTRICT
+                            | __RESTRICT__
                             | __EXTENSION__
         """
         p[0] = p[1]
@inducer
Copy link
Owner

inducer commented Dec 11, 2016

Merged, thanks!

@inducer inducer closed this as completed Dec 11, 2016
@inducer inducer reopened this Dec 11, 2016
@inducer
Copy link
Owner

inducer commented Dec 11, 2016

Had to revert, because it failed the tests:

_______________________________ test_opencl[int] _______________________________
Traceback (most recent call last):
  File "/var/lib/gitlab-runner/builds/b1b84ce3/0/inducer/pycparserext/test/test_pycparserext.py", line 158, in test_opencl
    p = OpenCLCParser()
  File "/var/lib/gitlab-runner/builds/b1b84ce3/0/inducer/pycparserext/.env/lib/python3.5/site-packages/pycparserext-2016.2-py3.5.egg/pycparserext/ext_c_parser.py", line 47, in __init__
    debug=yacc_debug, write_tables=False)
  File "/var/lib/gitlab-runner/builds/b1b84ce3/0/inducer/pycparserext/.env/lib/python3.5/site-packages/pycparser-2.17-py3.5.egg/pycparser/ply/yacc.py", line 3403, in yacc
    raise YaccError('Unable to build parser')
pycparser.ply.yacc.YaccError: Unable to build parser
----------------------------- Captured stderr call -----------------------------
ERROR: /var/lib/gitlab-runner/builds/b1b84ce3/0/inducer/pycparserext/.env/lib/python3.5/site-packages/pycparserext-2016.2-py3.5.egg/pycparserext/ext_c_parser.py:362: Symbol '__VOLATILE__' used, but not defined as a token or a rule
______________________________ test_opencl[uint] _______________________________
Traceback (most recent call last):
  File "/var/lib/gitlab-runner/builds/b1b84ce3/0/inducer/pycparserext/test/test_pycparserext.py", line 158, in test_opencl
    p = OpenCLCParser()
  File "/var/lib/gitlab-runner/builds/b1b84ce3/0/inducer/pycparserext/.env/lib/python3.5/site-packages/pycparserext-2016.2-py3.5.egg/pycparserext/ext_c_parser.py", line 47, in __init__
    debug=yacc_debug, write_tables=False)
  File "/var/lib/gitlab-runner/builds/b1b84ce3/0/inducer/pycparserext/.env/lib/python3.5/site-packages/pycparser-2.17-py3.5.egg/pycparser/ply/yacc.py", line 3403, in yacc
    raise YaccError('Unable to build parser')
pycparser.ply.yacc.YaccError: Unable to build parser
----------------------------- Captured stderr call -----------------------------
ERROR: /var/lib/gitlab-runner/builds/b1b84ce3/0/inducer/pycparserext/.env/lib/python3.5/site-packages/pycparserext-2016.2-py3.5.egg/pycparserext/ext_c_parser.py:362: Symbol '__VOLATILE__' used, but not defined as a token or a rule

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

Successfully merging a pull request may close this issue.

2 participants