Menu

#54 Parser is failing on a compiler switch

v1.0 (example)
closed-fixed
None
5
2013-06-28
2013-06-12
bgrupczy
No

Parser is failing on a compiler switch. Can these types of things be accounted for?

CODE:

from CppHeaderParser import CppHeader

code1 = """
enum myEnum1
{
   en1,
   eb2,
   en3,
} __attribute__((packed));
"""

code2 = """
enum myEnum2
{
   en1,
   eb2,
   en3,
}
#if MACRO_TO_PACK
__attribute__((packed));
#else
;
#endif
"""

cppheader = CppHeader(code2, argType="string")
print cppheader

OUTPUT code1:
Traceback (most recent call last):
File "C:\eclipse_wa_python_local\t4\defect01.py", line 10, in <module>
cppheader = CppHeader(code, argType="string")
File "/cygdrive/c/eclipse_wa_python_local/t4/CppHeaderParser/CppHeaderParser.py", line 2197, in init
% (self.headerFileName, tok.lineno, tok.value, " ".join(self.nameStack)))
CppHeaderParser.CppHeaderParser.CppParseError: Not able to parse on line 7 evaluating ";"
Error around: myEnum (

OUTPUT code2:
Traceback (most recent call last):
File "C:\eclipse_wa_python_local\t4\defect01.py", line 26, in <module>
cppheader = CppHeader(code2, argType="string")
File "/cygdrive/c/eclipse_wa_python_local/t4/CppHeaderParser/CppHeaderParser.py", line 2197, in init
% (self.headerFileName, tok.lineno, tok.value, " ".join(self.nameStack)))
CppHeaderParser.CppHeaderParser.CppParseError: Not able to parse on line 9 evaluating ";"
Error around: attribute ( ( packed ) )

1 Attachments

Discussion

  • Jashua Cloutier

    Jashua Cloutier - 2013-06-28

    For code2: CppHeaderParser doesnt handle macros including #if statements. Those statements will break the parser. #defines are too complex to handle, expecially considering that definitions can be environmental or defined in #include files which are in a search path etc.

     
  • Jashua Cloutier

    Jashua Cloutier - 2013-06-28

    Fixed as of commit 112:e76db7fdfb27

     
  • Jashua Cloutier

    Jashua Cloutier - 2013-06-28

    To be clear code1 is fixed, code2 wont be fixed

     
  • bgrupczy

    bgrupczy - 2013-06-28

    Ok. Thanks. I'll see what we can do in the header.

     
  • Jashua Cloutier

    Jashua Cloutier - 2013-06-28
    • status: open --> closed-fixed
     
  • Jashua Cloutier

    Jashua Cloutier - 2013-06-28

    Closing as fixed

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.